summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2002-05-15 02:29:23 +0000
committercvs2svn <admin@example.com>2002-05-15 02:29:23 +0000
commitfd9566423b542798f5c8b06e68101a9ea5bb9885 (patch)
treef2cc037857a260afc5aaaaaa6cf62d06923c6273 /src/lib/libssl/src
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.tar.gz
openbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.tar.bz2
openbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.zip
This commit was manufactured by cvs2git to create branch 'openssl'.
Diffstat (limited to 'src/lib/libssl/src')
-rw-r--r--src/lib/libssl/src/CHANGES1624
-rw-r--r--src/lib/libssl/src/CHANGES.SSLeay968
-rw-r--r--src/lib/libssl/src/FAQ130
-rw-r--r--src/lib/libssl/src/INSTALL.MacOS72
-rw-r--r--src/lib/libssl/src/INSTALL.OS222
-rw-r--r--src/lib/libssl/src/INSTALL.VMS245
-rw-r--r--src/lib/libssl/src/INSTALL.W32323
-rw-r--r--src/lib/libssl/src/LICENSE127
-rw-r--r--src/lib/libssl/src/MacOS/GUSI_Init.cpp62
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.cpp2753
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.hpp104
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.cpp170
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.hpp147
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/GetHTTPS.cpp215
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.cpp1607
-rw-r--r--src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.h103
-rw-r--r--src/lib/libssl/src/MacOS/OpenSSL.mcp.hqx4880
-rw-r--r--src/lib/libssl/src/MacOS/Randomizer.cpp476
-rw-r--r--src/lib/libssl/src/MacOS/Randomizer.h43
-rw-r--r--src/lib/libssl/src/MacOS/TODO18
-rw-r--r--src/lib/libssl/src/MacOS/_MWERKS_GUSI_prefix.h9
-rw-r--r--src/lib/libssl/src/MacOS/_MWERKS_prefix.h9
-rw-r--r--src/lib/libssl/src/MacOS/buildinf.h5
-rw-r--r--src/lib/libssl/src/MacOS/mklinks.as.hqx820
-rw-r--r--src/lib/libssl/src/MacOS/opensslconf.h116
-rw-r--r--src/lib/libssl/src/Makefile.org351
-rw-r--r--src/lib/libssl/src/NEWS65
-rw-r--r--src/lib/libssl/src/README.ASN1187
-rw-r--r--src/lib/libssl/src/README.ENGINE63
-rw-r--r--src/lib/libssl/src/VMS/TODO18
-rw-r--r--src/lib/libssl/src/VMS/WISHLIST.TXT4
-rw-r--r--src/lib/libssl/src/VMS/install.com71
-rw-r--r--src/lib/libssl/src/VMS/mkshared.com353
-rw-r--r--src/lib/libssl/src/VMS/multinet_shr.opt1
-rw-r--r--src/lib/libssl/src/VMS/openssl_utils.com38
-rw-r--r--src/lib/libssl/src/VMS/socketshr_shr.opt1
-rw-r--r--src/lib/libssl/src/VMS/test-includes.com28
-rw-r--r--src/lib/libssl/src/VMS/ucx_shr_decc.opt1
-rw-r--r--src/lib/libssl/src/VMS/ucx_shr_decc_log.opt1
-rw-r--r--src/lib/libssl/src/VMS/ucx_shr_vaxc.opt1
-rw-r--r--src/lib/libssl/src/apps/CA.com200
-rw-r--r--src/lib/libssl/src/apps/CA.pl153
-rw-r--r--src/lib/libssl/src/apps/CA.pl.in162
-rw-r--r--src/lib/libssl/src/apps/app_rand.c211
-rw-r--r--src/lib/libssl/src/apps/dh2048.pem12
-rw-r--r--src/lib/libssl/src/apps/dh4096.pem18
-rw-r--r--src/lib/libssl/src/apps/dh512.pem9
-rw-r--r--src/lib/libssl/src/apps/dhparam.c368
-rw-r--r--src/lib/libssl/src/apps/engine.c520
-rw-r--r--src/lib/libssl/src/apps/install.com69
-rw-r--r--src/lib/libssl/src/apps/makeapps.com1138
-rw-r--r--src/lib/libssl/src/apps/nseq.c174
-rw-r--r--src/lib/libssl/src/apps/ocsp.c1211
-rw-r--r--src/lib/libssl/src/apps/oid.cnf6
-rw-r--r--src/lib/libssl/src/apps/openssl-vms.cnf214
-rw-r--r--src/lib/libssl/src/apps/openssl.c373
-rw-r--r--src/lib/libssl/src/apps/openssl.cnf214
-rw-r--r--src/lib/libssl/src/apps/passwd.c475
-rw-r--r--src/lib/libssl/src/apps/pkcs12.c703
-rw-r--r--src/lib/libssl/src/apps/pkcs8.c274
-rw-r--r--src/lib/libssl/src/apps/progs.pl77
-rw-r--r--src/lib/libssl/src/apps/rand.c140
-rw-r--r--src/lib/libssl/src/apps/rsautl.c315
-rw-r--r--src/lib/libssl/src/apps/smime.c646
-rw-r--r--src/lib/libssl/src/apps/spkac.c274
-rw-r--r--src/lib/libssl/src/apps/winrand.c149
-rw-r--r--src/lib/libssl/src/bugs/ultrixcc.c45
-rw-r--r--src/lib/libssl/src/certs/RegTP-5R.pem19
-rw-r--r--src/lib/libssl/src/certs/RegTP-6R.pem19
-rw-r--r--src/lib/libssl/src/certs/expired/ICE-CA.pem59
-rw-r--r--src/lib/libssl/src/certs/expired/ICE-root.pem48
-rw-r--r--src/lib/libssl/src/certs/expired/ICE-user.pem63
-rw-r--r--src/lib/libssl/src/certs/expired/ICE.crl9
-rw-r--r--src/lib/libssl/src/certs/expired/rsa-ssca.pem19
-rw-r--r--src/lib/libssl/src/certs/vsignss.pem17
-rw-r--r--src/lib/libssl/src/crypto/aes/README3
-rw-r--r--src/lib/libssl/src/crypto/aes/aes.h109
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_cbc.c89
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_cfb.c151
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_core.c1251
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_ctr.c117
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_ecb.c67
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_locl.h88
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_misc.c64
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_ofb.c136
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_enum.c326
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_gentm.c224
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_mbstr.c390
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_strex.c533
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_strnid.c247
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_time.c123
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_utf8.c83
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1t.h846
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn_moid.c95
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn_pack.c145
-rw-r--r--src/lib/libssl/src/crypto/asn1/charmap.h15
-rw-r--r--src/lib/libssl/src/crypto/asn1/charmap.pl80
-rw-r--r--src/lib/libssl/src/crypto/asn1/f_enum.c207
-rw-r--r--src/lib/libssl/src/crypto/asn1/nsseq.c118
-rw-r--r--src/lib/libssl/src/crypto/asn1/p5_pbe.c156
-rw-r--r--src/lib/libssl/src/crypto/asn1/p5_pbev2.c274
-rw-r--r--src/lib/libssl/src/crypto/asn1/p8_key.c131
-rw-r--r--src/lib/libssl/src/crypto/asn1/p8_pkey.c129
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_bitst.c99
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_crl.c166
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_spki.c116
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_x509a.c102
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_dec.c958
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_enc.c497
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_fre.c226
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_new.c348
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_prn.c198
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_typ.c133
-rw-r--r--src/lib/libssl/src/crypto/asn1/tasn_utl.c253
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_bignum.c137
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_long.c169
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_x509a.c200
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_locl.h219
-rw-r--r--src/lib/libssl/src/crypto/bio/bf_lbuf.c397
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_bio.c588
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_log.c232
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.s.works533
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/add.pl119
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/div.pl144
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/mul.pl116
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_add.pl120
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.pl213
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.works.pl98
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c8.pl177
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr.pl113
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c4.pl109
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c8.pl132
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.works/sub.pl108
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/add.pl118
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/div.pl144
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/mul.pl104
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/mul_add.pl123
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.pl215
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.works.pl98
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/mul_c8.pl177
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/sqr.pl113
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c4.pl109
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c8.pl132
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha/sub.pl108
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/bn-alpha.pl571
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/ca.pl33
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/co-586.pl286
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/co-alpha.pl116
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/ia64.S1498
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/mips1.s539
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/mips3.s2138
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/pa-risc2W.s1605
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/sparcv8.S1458
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/sparcv8plus.S1535
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/vms.mar6695
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86.pl28
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/add.pl76
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/comba.pl277
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/div.pl15
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/f3
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/mul.pl77
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/mul_add.pl87
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/sqr.pl60
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/x86/sub.pl76
-rw-r--r--src/lib/libssl/src/crypto/bn/bn.h467
-rw-r--r--src/lib/libssl/src/crypto/bn/bn.mul19
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_asm.c802
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_ctx.c144
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_exp2.c195
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_kron.c182
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_sqrt.c387
-rw-r--r--src/lib/libssl/src/crypto/bn/divtest.c41
-rw-r--r--src/lib/libssl/src/crypto/bn/exp.c60
-rw-r--r--src/lib/libssl/src/crypto/bn/todo3
-rw-r--r--src/lib/libssl/src/crypto/bn/vms-helper.c66
-rw-r--r--src/lib/libssl/src/crypto/comp/c_rle.c61
-rw-r--r--src/lib/libssl/src/crypto/comp/c_zlib.c133
-rw-r--r--src/lib/libssl/src/crypto/comp/comp.h60
-rw-r--r--src/lib/libssl/src/crypto/comp/comp_err.c91
-rw-r--r--src/lib/libssl/src/crypto/comp/comp_lib.c78
-rw-r--r--src/lib/libssl/src/crypto/conf/README78
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_api.c289
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_api.h87
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_def.c703
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_def.h145
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_lib.c352
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_mall.c76
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_mod.c616
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_sap.c107
-rw-r--r--src/lib/libssl/src/crypto/crypto-lib.com1218
-rw-r--r--src/lib/libssl/src/crypto/des/des-lib.com1003
-rw-r--r--src/lib/libssl/src/crypto/des/des.h249
-rw-r--r--src/lib/libssl/src/crypto/des/des.pod217
-rw-r--r--src/lib/libssl/src/crypto/des/des_locl.h408
-rw-r--r--src/lib/libssl/src/crypto/des/des_old.c271
-rw-r--r--src/lib/libssl/src/crypto/des/des_old.h437
-rw-r--r--src/lib/libssl/src/crypto/des/des_old2.c82
-rw-r--r--src/lib/libssl/src/crypto/des/ede_cbcm_enc.c197
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_asn1.c87
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_asn1.c96
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_ossl.c321
-rw-r--r--src/lib/libssl/src/crypto/dso/README24
-rw-r--r--src/lib/libssl/src/crypto/dso/dso.h250
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_dl.c251
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_dlfcn.c276
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_err.c128
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_lib.c306
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_null.c86
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_openssl.c81
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_vms.c371
-rw-r--r--src/lib/libssl/src/crypto/dso/dso_win32.c273
-rw-r--r--src/lib/libssl/src/crypto/ebcdic.c217
-rw-r--r--src/lib/libssl/src/crypto/ebcdic.h17
-rw-r--r--src/lib/libssl/src/crypto/ec/ec.h245
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_cvt.c80
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_err.c151
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_lcl.h277
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_lib.c646
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_mult.c473
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_mont.c304
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_nist.c134
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_recp.c133
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_smpl.c1717
-rw-r--r--src/lib/libssl/src/crypto/ec/ectest.c634
-rw-r--r--src/lib/libssl/src/crypto/engine/README278
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_all.c118
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_cnf.c242
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_ctrl.c387
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_dyn.c446
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_err.c165
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_fat.c148
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_init.c158
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_int.h185
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_lib.c321
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_list.c383
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_openssl.c347
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_pkey.c157
-rw-r--r--src/lib/libssl/src/crypto/engine/eng_table.c361
-rw-r--r--src/lib/libssl/src/crypto/engine/engine.h398
-rw-r--r--src/lib/libssl/src/crypto/engine/enginetest.c251
-rw-r--r--src/lib/libssl/src/crypto/engine/hw.ec8
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_4758_cca.c950
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_4758_cca_err.c149
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_4758_cca_err.h93
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_aep.c1101
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_aep_err.c157
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_aep_err.h101
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_atalla.c444
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_atalla_err.c145
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_atalla_err.h89
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_cryptodev.c926
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_cswift.c807
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_cswift_err.c149
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_cswift_err.h93
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ncipher.c1019
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ncipher_err.c156
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ncipher_err.h100
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_nuron.c399
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_nuron_err.c142
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_nuron_err.h86
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_sureware_err.c150
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_sureware_err.h94
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ubsec.c1041
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ubsec_err.c151
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_ubsec_err.h95
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_cipher.c145
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_dh.c120
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_digest.c145
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_dsa.c120
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_rand.c120
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_rsa.c120
-rw-r--r--src/lib/libssl/src/crypto/engine/vendor_defns/aep.h178
-rw-r--r--src/lib/libssl/src/crypto/engine/vendor_defns/atalla.h61
-rw-r--r--src/lib/libssl/src/crypto/engine/vendor_defns/cswift.h213
-rw-r--r--src/lib/libssl/src/crypto/engine/vendor_defns/hw_4758_cca.h149
-rw-r--r--src/lib/libssl/src/crypto/err/openssl.ec71
-rw-r--r--src/lib/libssl/src/crypto/evp/bio_ok.c552
-rw-r--r--src/lib/libssl/src/crypto/evp/c_allc.c149
-rw-r--r--src/lib/libssl/src/crypto/evp/c_alld.c100
-rw-r--r--src/lib/libssl/src/crypto/evp/e_aes.c99
-rw-r--r--src/lib/libssl/src/crypto/evp/e_bf.c80
-rw-r--r--src/lib/libssl/src/crypto/evp/e_cast.c82
-rw-r--r--src/lib/libssl/src/crypto/evp/e_des.c118
-rw-r--r--src/lib/libssl/src/crypto/evp/e_des3.c165
-rw-r--r--src/lib/libssl/src/crypto/evp/e_idea.c112
-rw-r--r--src/lib/libssl/src/crypto/evp/e_rc2.c222
-rw-r--r--src/lib/libssl/src/crypto/evp/e_rc5.c118
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_acnf.c74
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_locl.h168
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_pbe.c134
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_pkey.c298
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_test.c365
-rw-r--r--src/lib/libssl/src/crypto/evp/evptests.txt82
-rw-r--r--src/lib/libssl/src/crypto/evp/m_md4.c83
-rw-r--r--src/lib/libssl/src/crypto/evp/openbsd_hw.c446
-rw-r--r--src/lib/libssl/src/crypto/evp/p5_crpt.c146
-rw-r--r--src/lib/libssl/src/crypto/evp/p5_crpt2.c247
-rw-r--r--src/lib/libssl/src/crypto/idea/idea.h99
-rw-r--r--src/lib/libssl/src/crypto/install.com128
-rw-r--r--src/lib/libssl/src/crypto/krb5/krb5_asn.c167
-rw-r--r--src/lib/libssl/src/crypto/krb5/krb5_asn.h256
-rw-r--r--src/lib/libssl/src/crypto/md2/md2.h91
-rw-r--r--src/lib/libssl/src/crypto/md32_common.h594
-rw-r--r--src/lib/libssl/src/crypto/md4/md4.c127
-rw-r--r--src/lib/libssl/src/crypto/md4/md4.h114
-rw-r--r--src/lib/libssl/src/crypto/md4/md4_dgst.c285
-rw-r--r--src/lib/libssl/src/crypto/md4/md4_locl.h154
-rw-r--r--src/lib/libssl/src/crypto/md4/md4_one.c95
-rw-r--r--src/lib/libssl/src/crypto/md4/md4s.cpp78
-rw-r--r--src/lib/libssl/src/crypto/md4/md4test.c131
-rw-r--r--src/lib/libssl/src/crypto/md5/asm/md5-sparcv9.S1029
-rw-r--r--src/lib/libssl/src/crypto/mem_dbg.c703
-rw-r--r--src/lib/libssl/src/crypto/o_time.c203
-rw-r--r--src/lib/libssl/src/crypto/o_time.h66
-rw-r--r--src/lib/libssl/src/crypto/objects/o_names.c243
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_mac.h1798
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_mac.num392
-rw-r--r--src/lib/libssl/src/crypto/objects/objects.README44
-rw-r--r--src/lib/libssl/src/crypto/objects/objects.pl224
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp.h619
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_asn.c182
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_cl.c370
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_err.c139
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_ext.c528
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_ht.c164
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_lib.c261
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_prn.c291
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_srv.c264
-rw-r--r--src/lib/libssl/src/crypto/ocsp/ocsp_vfy.c444
-rw-r--r--src/lib/libssl/src/crypto/opensslconf.h.in142
-rw-r--r--src/lib/libssl/src/crypto/opensslv.h21
-rw-r--r--src/lib/libssl/src/crypto/ossl_typ.h120
-rw-r--r--src/lib/libssl/src/crypto/pem/pem2.h60
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_oth.c85
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_pk8.c243
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_pkey.c139
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_x509.c69
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_xaux.c68
-rw-r--r--src/lib/libssl/src/crypto/perlasm/alpha.pl434
-rw-r--r--src/lib/libssl/src/crypto/perlasm/x86nasm.pl342
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_add.c214
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_asn.c125
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_attr.c238
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_crpt.c122
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_crt.c159
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_decr.c185
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_init.c98
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_key.c182
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_kiss.c238
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_mutl.c170
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_npas.c212
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_p8d.c68
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_p8e.c97
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_utl.c118
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/pk12err.c136
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/pkcs12.h337
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/bio_ber.c450
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/dec.c246
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/des.pem15
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/es1.pem66
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/example.c327
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/example.h57
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/info.pem57
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/infokey.pem9
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_asn1.c213
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_attr.c85
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_mime.c673
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_smime.c427
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/3des.pem16
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/3dess.pem32
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/c.pem48
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/ff32
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-e20
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-e.pem22
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-enc-0162
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01.pem66
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-enc-0290
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02.pem106
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e91
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e.pem106
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/nav-smime157
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/s.pem57
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/t/server.pem57
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_egd.c110
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_err.c93
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_lcl.h184
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_lib.c98
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_os2.c147
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_unix.c274
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_vms.c135
-rw-r--r--src/lib/libssl/src/crypto/rand/rand_win.c732
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2.h99
-rw-r--r--src/lib/libssl/src/crypto/rc2/tab.c86
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4.h88
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4_locl.h4
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_asn1.c121
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_null.c149
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_oaep.c162
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_test.c314
-rw-r--r--src/lib/libssl/src/crypto/stack/safestack.h129
-rw-r--r--src/lib/libssl/src/crypto/symhacks.h154
-rw-r--r--src/lib/libssl/src/crypto/threads/README14
-rw-r--r--src/lib/libssl/src/crypto/threads/profile.sh4
-rw-r--r--src/lib/libssl/src/crypto/threads/ptest.bat4
-rw-r--r--src/lib/libssl/src/crypto/threads/pthread.sh9
-rw-r--r--src/lib/libssl/src/crypto/threads/pthread2.sh7
-rw-r--r--src/lib/libssl/src/crypto/threads/pthreads-vms.com9
-rw-r--r--src/lib/libssl/src/crypto/threads/purify.sh4
-rw-r--r--src/lib/libssl/src/crypto/threads/solaris.sh4
-rw-r--r--src/lib/libssl/src/crypto/threads/win32.bat4
-rw-r--r--src/lib/libssl/src/crypto/tmdiff.h81
-rw-r--r--src/lib/libssl/src/crypto/ui/ui.h387
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_compat.c67
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_compat.h83
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_err.c111
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_lib.c899
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_locl.h148
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_openssl.c661
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_util.c86
-rw-r--r--src/lib/libssl/src/crypto/uid.c88
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_att.c326
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_trs.c263
-rw-r--r--src/lib/libssl/src/crypto/x509/x509cset.c169
-rw-r--r--src/lib/libssl/src/crypto/x509/x509spki.c121
-rw-r--r--src/lib/libssl/src/crypto/x509v3/ext_dat.h97
-rw-r--r--src/lib/libssl/src/crypto/x509v3/tabtest.c88
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_akey.c249
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_akeya.c72
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_alt.c402
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_bcons.c164
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_bitst.c147
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_conf.c366
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_cpols.c655
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_crld.c283
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_enum.c103
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_extku.c150
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_genn.c237
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_ia5.c116
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_info.c236
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_int.c79
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_lib.c177
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_ocsp.c272
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_pku.c151
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_prn.c135
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_purp.c456
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_skey.c156
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_sxnet.c340
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3_utl.c418
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3conf.c128
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3err.c171
-rw-r--r--src/lib/libssl/src/crypto/x509v3/v3prin.c101
-rw-r--r--src/lib/libssl/src/demos/asn1/README.ASN17
-rw-r--r--src/lib/libssl/src/demos/asn1/ocsp.c366
-rw-r--r--src/lib/libssl/src/demos/bio/Makefile16
-rw-r--r--src/lib/libssl/src/demos/easy_tls/Makefile123
-rw-r--r--src/lib/libssl/src/demos/easy_tls/README65
-rw-r--r--src/lib/libssl/src/demos/easy_tls/cacerts.pem18
-rw-r--r--src/lib/libssl/src/demos/easy_tls/cert.pem31
-rw-r--r--src/lib/libssl/src/demos/easy_tls/easy-tls.c1235
-rw-r--r--src/lib/libssl/src/demos/easy_tls/easy-tls.h57
-rw-r--r--src/lib/libssl/src/demos/easy_tls/test.c244
-rw-r--r--src/lib/libssl/src/demos/easy_tls/test.h11
-rw-r--r--src/lib/libssl/src/demos/eay/Makefile24
-rw-r--r--src/lib/libssl/src/demos/eay/base64.c49
-rw-r--r--src/lib/libssl/src/demos/eay/conn.c105
-rw-r--r--src/lib/libssl/src/demos/eay/loadrsa.c53
-rw-r--r--src/lib/libssl/src/demos/pkcs12/README3
-rw-r--r--src/lib/libssl/src/demos/pkcs12/pkread.c61
-rw-r--r--src/lib/libssl/src/demos/pkcs12/pkwrite.c46
-rw-r--r--src/lib/libssl/src/demos/prime/Makefile20
-rw-r--r--src/lib/libssl/src/demos/sign/Makefile15
-rw-r--r--src/lib/libssl/src/demos/state_machine/Makefile9
-rw-r--r--src/lib/libssl/src/demos/state_machine/state_machine.c416
-rw-r--r--src/lib/libssl/src/demos/tunala/A-client.pem84
-rw-r--r--src/lib/libssl/src/demos/tunala/A-server.pem84
-rw-r--r--src/lib/libssl/src/demos/tunala/CA.pem24
-rw-r--r--src/lib/libssl/src/demos/tunala/INSTALL107
-rw-r--r--src/lib/libssl/src/demos/tunala/Makefile41
-rw-r--r--src/lib/libssl/src/demos/tunala/Makefile.am7
-rw-r--r--src/lib/libssl/src/demos/tunala/README233
-rw-r--r--src/lib/libssl/src/demos/tunala/autogunk.sh25
-rw-r--r--src/lib/libssl/src/demos/tunala/autoungunk.sh18
-rw-r--r--src/lib/libssl/src/demos/tunala/breakage.c66
-rw-r--r--src/lib/libssl/src/demos/tunala/buffer.c205
-rw-r--r--src/lib/libssl/src/demos/tunala/cb.c133
-rw-r--r--src/lib/libssl/src/demos/tunala/configure.in28
-rw-r--r--src/lib/libssl/src/demos/tunala/ip.c146
-rw-r--r--src/lib/libssl/src/demos/tunala/sm.c151
-rw-r--r--src/lib/libssl/src/demos/tunala/tunala.c1093
-rw-r--r--src/lib/libssl/src/demos/tunala/tunala.h214
-rw-r--r--src/lib/libssl/src/demos/x509/README3
-rw-r--r--src/lib/libssl/src/demos/x509/mkcert.c168
-rw-r--r--src/lib/libssl/src/demos/x509/mkreq.c157
-rw-r--r--src/lib/libssl/src/doc/HOWTO/certificates.txt85
-rw-r--r--src/lib/libssl/src/doc/README10
-rw-r--r--src/lib/libssl/src/doc/apps/CA.pl.pod138
-rw-r--r--src/lib/libssl/src/doc/apps/asn1parse.pod129
-rw-r--r--src/lib/libssl/src/doc/apps/ca.pod479
-rw-r--r--src/lib/libssl/src/doc/apps/ciphers.pod342
-rw-r--r--src/lib/libssl/src/doc/apps/config.pod138
-rw-r--r--src/lib/libssl/src/doc/apps/crl.pod117
-rw-r--r--src/lib/libssl/src/doc/apps/crl2pkcs7.pod90
-rw-r--r--src/lib/libssl/src/doc/apps/dgst.pod49
-rw-r--r--src/lib/libssl/src/doc/apps/dhparam.pod115
-rw-r--r--src/lib/libssl/src/doc/apps/dsa.pod150
-rw-r--r--src/lib/libssl/src/doc/apps/dsaparam.pod102
-rw-r--r--src/lib/libssl/src/doc/apps/enc.pod257
-rw-r--r--src/lib/libssl/src/doc/apps/gendsa.pod58
-rw-r--r--src/lib/libssl/src/doc/apps/genrsa.pod85
-rw-r--r--src/lib/libssl/src/doc/apps/nseq.pod70
-rw-r--r--src/lib/libssl/src/doc/apps/ocsp.pod348
-rw-r--r--src/lib/libssl/src/doc/apps/openssl.pod298
-rw-r--r--src/lib/libssl/src/doc/apps/passwd.pod69
-rw-r--r--src/lib/libssl/src/doc/apps/pkcs12.pod310
-rw-r--r--src/lib/libssl/src/doc/apps/pkcs7.pod97
-rw-r--r--src/lib/libssl/src/doc/apps/pkcs8.pod235
-rw-r--r--src/lib/libssl/src/doc/apps/rand.pod50
-rw-r--r--src/lib/libssl/src/doc/apps/req.pod528
-rw-r--r--src/lib/libssl/src/doc/apps/rsa.pod156
-rw-r--r--src/lib/libssl/src/doc/apps/rsautl.pod183
-rw-r--r--src/lib/libssl/src/doc/apps/s_client.pod213
-rw-r--r--src/lib/libssl/src/doc/apps/s_server.pod265
-rw-r--r--src/lib/libssl/src/doc/apps/sess_id.pod151
-rw-r--r--src/lib/libssl/src/doc/apps/smime.pod325
-rw-r--r--src/lib/libssl/src/doc/apps/speed.pod45
-rw-r--r--src/lib/libssl/src/doc/apps/spkac.pod127
-rw-r--r--src/lib/libssl/src/doc/apps/verify.pod273
-rw-r--r--src/lib/libssl/src/doc/apps/version.pod56
-rw-r--r--src/lib/libssl/src/doc/apps/x509.pod543
-rw-r--r--src/lib/libssl/src/doc/c-indentation.el36
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_ctrl.pod128
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_base64.pod82
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_buffer.pod69
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_cipher.pod76
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_md.pod138
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_null.pod32
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_f_ssl.pod313
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_find_type.pod98
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_new.pod65
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_push.pod69
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_read.pod66
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_accept.pod184
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_bio.pod130
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_connect.pod182
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_fd.pod89
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_file.pod144
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_mem.pod115
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_null.pod37
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_s_socket.pod61
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_set_callback.pod108
-rw-r--r--src/lib/libssl/src/doc/crypto/BIO_should_retry.pod114
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_CTX_new.pod53
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_CTX_start.pod51
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_add.pod99
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_add_word.pod57
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_bn2bin.pod95
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_cmp.pod48
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_copy.pod34
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_generate_prime.pod102
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_mod_inverse.pod36
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_mod_mul_montgomery.pod95
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_mod_mul_reciprocal.pod81
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_new.pod53
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_num_bytes.pod37
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_rand.pod45
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_set_bit.pod66
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_swap.pod23
-rw-r--r--src/lib/libssl/src/doc/crypto/BN_zero.pod55
-rw-r--r--src/lib/libssl/src/doc/crypto/CRYPTO_set_ex_data.pod51
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_generate_key.pod50
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_generate_parameters.pod72
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_get_ex_new_index.pod36
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_new.pod40
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_set_method.pod99
-rw-r--r--src/lib/libssl/src/doc/crypto/DH_size.pod33
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_SIG_new.pod39
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_do_sign.pod47
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_dup_DH.pod36
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_generate_key.pod33
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_generate_parameters.pod105
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_get_ex_new_index.pod36
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_new.pod41
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_set_method.pod111
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_sign.pod66
-rw-r--r--src/lib/libssl/src/doc/crypto/DSA_size.pod33
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_GET_LIB.pod51
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_clear_error.pod29
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_error_string.pod65
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_get_error.pod62
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_load_crypto_strings.pod46
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_load_strings.pod54
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_print_errors.pod51
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_put_error.pod44
-rw-r--r--src/lib/libssl/src/doc/crypto/ERR_remove_state.pod34
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_BytesToKey.pod67
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod197
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod224
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_OpenInit.pod51
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_SealInit.pod70
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_SignInit.pod85
-rw-r--r--src/lib/libssl/src/doc/crypto/EVP_VerifyInit.pod71
-rw-r--r--src/lib/libssl/src/doc/crypto/OPENSSL_VERSION_NUMBER.pod46
-rw-r--r--src/lib/libssl/src/doc/crypto/OpenSSL_add_all_algorithms.pod65
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_add.pod68
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_bytes.pod46
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_cleanup.pod29
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_egd.pod38
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_load_file.pod53
-rw-r--r--src/lib/libssl/src/doc/crypto/RAND_set_rand_method.pod57
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_blinding_on.pod43
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_check_key.pod39
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_generate_key.pod68
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_get_ex_new_index.pod122
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_new.pod38
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_padding_add_PKCS1_type_1.pod124
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_print.pod48
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_private_encrypt.pod69
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_public_encrypt.pod86
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_set_method.pod153
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_sign.pod62
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod59
-rw-r--r--src/lib/libssl/src/doc/crypto/RSA_size.pod33
-rw-r--r--src/lib/libssl/src/doc/crypto/bio.pod54
-rw-r--r--src/lib/libssl/src/doc/crypto/blowfish.pod106
-rw-r--r--src/lib/libssl/src/doc/crypto/bn.pod148
-rw-r--r--src/lib/libssl/src/doc/crypto/bn_internal.pod225
-rw-r--r--src/lib/libssl/src/doc/crypto/buffer.pod73
-rw-r--r--src/lib/libssl/src/doc/crypto/crypto.pod67
-rw-r--r--src/lib/libssl/src/doc/crypto/d2i_DHparams.pod30
-rw-r--r--src/lib/libssl/src/doc/crypto/d2i_RSAPublicKey.pod39
-rw-r--r--src/lib/libssl/src/doc/crypto/des.pod376
-rw-r--r--src/lib/libssl/src/doc/crypto/des_modes.pod250
-rw-r--r--src/lib/libssl/src/doc/crypto/dh.pod68
-rw-r--r--src/lib/libssl/src/doc/crypto/dsa.pod104
-rw-r--r--src/lib/libssl/src/doc/crypto/err.pod187
-rw-r--r--src/lib/libssl/src/doc/crypto/evp.pod37
-rw-r--r--src/lib/libssl/src/doc/crypto/hmac.pod75
-rw-r--r--src/lib/libssl/src/doc/crypto/lh_stats.pod60
-rw-r--r--src/lib/libssl/src/doc/crypto/lhash.pod155
-rw-r--r--src/lib/libssl/src/doc/crypto/md5.pod85
-rw-r--r--src/lib/libssl/src/doc/crypto/mdc2.pod64
-rw-r--r--src/lib/libssl/src/doc/crypto/pem.pod476
-rw-r--r--src/lib/libssl/src/doc/crypto/rand.pod158
-rw-r--r--src/lib/libssl/src/doc/crypto/rc4.pod62
-rw-r--r--src/lib/libssl/src/doc/crypto/ripemd.pod66
-rw-r--r--src/lib/libssl/src/doc/crypto/rsa.pod115
-rw-r--r--src/lib/libssl/src/doc/crypto/sha.pod70
-rw-r--r--src/lib/libssl/src/doc/crypto/threads.pod70
-rw-r--r--src/lib/libssl/src/doc/crypto/ui.pod194
-rw-r--r--src/lib/libssl/src/doc/crypto/ui_compat.pod55
-rw-r--r--src/lib/libssl/src/doc/openssl.txt1174
-rw-r--r--src/lib/libssl/src/doc/openssl_button.gifbin0 -> 2063 bytes
-rw-r--r--src/lib/libssl/src/doc/openssl_button.html7
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CIPHER_get_name.pod57
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_COMP_add_compression_method.pod70
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_add_extra_chain_cert.pod38
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_add_session.pod65
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_ctrl.pod34
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_flush_sessions.pod49
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_free.pod29
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_get_ex_new_index.pod53
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_get_verify_mode.pod50
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_load_verify_locations.pod124
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_new.pod93
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_sess_number.pod76
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_cache_size.pod51
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_get_cb.pod81
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_sessions.pod34
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_store.pod57
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_verify_callback.pod75
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_cipher_list.pod52
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_CA_list.pod90
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_cert_cb.pod90
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_default_passwd_cb.pod70
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_generate_session_id.pod150
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_info_callback.pod153
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_max_cert_list.pod77
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_mode.pod78
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_msg_callback.pod97
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_options.pod183
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_quiet_shutdown.pod63
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_cache_mode.pod107
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_id_context.pod82
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_ssl_version.pod60
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_timeout.pod55
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod170
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod166
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_set_verify.pod284
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_CTX_use_certificate.pod154
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_SESSION_free.pod25
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_SESSION_get_ex_new_index.pod61
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_SESSION_get_time.pod63
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_accept.pod72
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_alert_type_string.pod228
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_clear.pod39
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_connect.pod69
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_free.pod33
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_SSL_CTX.pod26
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_ciphers.pod42
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_client_CA_list.pod52
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_current_cipher.pod43
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_default_timeout.pod41
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_error.pod91
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod61
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_ex_new_index.pod59
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_fd.pod44
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_peer_cert_chain.pod52
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_peer_certificate.pod48
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_rbio.pod40
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_session.pod48
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_verify_result.pod57
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_get_version.pod46
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_library_init.pod52
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_load_client_CA_file.pod62
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_new.pod42
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_pending.pod30
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_read.pod77
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_rstate_string.pod59
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_session_reused.pod45
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_bio.pod34
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_connect_state.pod47
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_fd.pod54
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_session.pod45
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_shutdown.pod68
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_set_verify_result.pod38
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_shutdown.pod62
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_state_string.pod45
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_want.pod77
-rw-r--r--src/lib/libssl/src/doc/ssl/SSL_write.pod76
-rw-r--r--src/lib/libssl/src/doc/ssl/d2i_SSL_SESSION.pod56
-rw-r--r--src/lib/libssl/src/doc/ssl/ssl.pod634
-rw-r--r--src/lib/libssl/src/doc/ssleay.txt7014
-rw-r--r--src/lib/libssl/src/doc/standards.txt121
-rw-r--r--src/lib/libssl/src/e_os2.h38
-rw-r--r--src/lib/libssl/src/install.com88
-rw-r--r--src/lib/libssl/src/ms/bcb4.bat6
-rw-r--r--src/lib/libssl/src/ms/do_masm.bat68
-rw-r--r--src/lib/libssl/src/ms/do_nasm.bat69
-rw-r--r--src/lib/libssl/src/ms/do_nt.bat7
-rw-r--r--src/lib/libssl/src/ms/mingw32.bat92
-rw-r--r--src/lib/libssl/src/ms/mw.bat31
-rw-r--r--src/lib/libssl/src/ms/tlhelp32.h136
-rw-r--r--src/lib/libssl/src/ms/x86asm.bat57
-rw-r--r--src/lib/libssl/src/openssl.doxy7
-rw-r--r--src/lib/libssl/src/openssl.spec213
-rw-r--r--src/lib/libssl/src/os2/OS2-EMX.cmd61
-rw-r--r--src/lib/libssl/src/shlib/Makefile.hpux10-cc51
-rw-r--r--src/lib/libssl/src/shlib/hpux10-cc.sh90
-rw-r--r--src/lib/libssl/src/shlib/solaris-sc4.sh42
-rw-r--r--src/lib/libssl/src/shlib/svr5-shared-gcc.sh48
-rw-r--r--src/lib/libssl/src/shlib/svr5-shared-installed28
-rw-r--r--src/lib/libssl/src/shlib/svr5-shared.sh48
-rw-r--r--src/lib/libssl/src/ssl/install.com102
-rw-r--r--src/lib/libssl/src/ssl/kssl.c2195
-rw-r--r--src/lib/libssl/src/ssl/kssl.h173
-rw-r--r--src/lib/libssl/src/ssl/kssl_lcl.h87
-rw-r--r--src/lib/libssl/src/ssl/ssl-lib.com1200
-rw-r--r--src/lib/libssl/src/test/VMSca-response.11
-rw-r--r--src/lib/libssl/src/test/VMSca-response.22
-rw-r--r--src/lib/libssl/src/test/bctest111
-rw-r--r--src/lib/libssl/src/test/maketests.com1053
-rw-r--r--src/lib/libssl/src/test/tcrl.com78
-rw-r--r--src/lib/libssl/src/test/testca.com76
-rw-r--r--src/lib/libssl/src/test/testenc.com50
-rw-r--r--src/lib/libssl/src/test/testgen.com35
-rw-r--r--src/lib/libssl/src/test/tests.com203
-rw-r--r--src/lib/libssl/src/test/testss.com105
-rw-r--r--src/lib/libssl/src/test/testssl.com111
-rw-r--r--src/lib/libssl/src/test/tpkcs7.com49
-rw-r--r--src/lib/libssl/src/test/tpkcs7d.com42
-rw-r--r--src/lib/libssl/src/test/treq.com78
-rw-r--r--src/lib/libssl/src/test/trsa.com78
-rw-r--r--src/lib/libssl/src/test/tsid.com78
-rw-r--r--src/lib/libssl/src/test/tverify.com26
-rw-r--r--src/lib/libssl/src/test/tx509.com78
-rw-r--r--src/lib/libssl/src/times/091/486-50.nt30
-rw-r--r--src/lib/libssl/src/times/091/586-100.lnx32
-rw-r--r--src/lib/libssl/src/times/091/68000.bsd32
-rw-r--r--src/lib/libssl/src/times/091/686-200.lnx32
-rw-r--r--src/lib/libssl/src/times/091/alpha064.osf32
-rw-r--r--src/lib/libssl/src/times/091/alpha164.lnx32
-rw-r--r--src/lib/libssl/src/times/091/alpha164.osf31
-rw-r--r--src/lib/libssl/src/times/091/mips-rel.pl21
-rw-r--r--src/lib/libssl/src/times/091/r10000.irx37
-rw-r--r--src/lib/libssl/src/times/091/r3000.ult32
-rw-r--r--src/lib/libssl/src/times/091/r4400.irx32
-rw-r--r--src/lib/libssl/src/times/x86/md4s.cpp78
-rw-r--r--src/lib/libssl/src/tools/c89.sh15
-rw-r--r--src/lib/libssl/src/tools/c_rehash.in61
-rw-r--r--src/lib/libssl/src/util/clean-depend.pl38
-rw-r--r--src/lib/libssl/src/util/cygwin.sh125
-rw-r--r--src/lib/libssl/src/util/domd11
-rw-r--r--src/lib/libssl/src/util/mkdir-p.pl33
-rw-r--r--src/lib/libssl/src/util/mkerr.pl503
-rw-r--r--src/lib/libssl/src/util/mkfiles.pl110
-rw-r--r--src/lib/libssl/src/util/mklink.pl55
-rw-r--r--src/lib/libssl/src/util/mkstack.pl124
-rw-r--r--src/lib/libssl/src/util/pl/Mingw32.pl79
-rw-r--r--src/lib/libssl/src/util/pl/OS2-EMX.pl96
-rw-r--r--src/lib/libssl/src/util/pl/ultrix.pl38
-rw-r--r--src/lib/libssl/src/util/pod2man.pl1181
-rw-r--r--src/lib/libssl/src/util/selftest.pl174
803 files changed, 170380 insertions, 0 deletions
diff --git a/src/lib/libssl/src/CHANGES b/src/lib/libssl/src/CHANGES
new file mode 100644
index 0000000000..d0db7eaf61
--- /dev/null
+++ b/src/lib/libssl/src/CHANGES
@@ -0,0 +1,1624 @@
1
2 OpenSSL CHANGES
3 _______________
4
5 Changes between 0.9.3a and 0.9.4 [09 Aug 1999]
6
7 *) Install libRSAglue.a when OpenSSL is built with RSAref.
8 [Ralf S. Engelschall]
9
10 *) A few more ``#ifndef NO_FP_API / #endif'' pairs for consistency.
11 [Andrija Antonijevic <TheAntony2@bigfoot.com>]
12
13 *) Fix -startdate and -enddate (which was missing) arguments to 'ca'
14 program.
15 [Steve Henson]
16
17 *) New function DSA_dup_DH, which duplicates DSA parameters/keys as
18 DH parameters/keys (q is lost during that conversion, but the resulting
19 DH parameters contain its length).
20
21 For 1024-bit p, DSA_generate_parameters followed by DSA_dup_DH is
22 much faster than DH_generate_parameters (which creates parameters
23 where p = 2*q + 1), and also the smaller q makes DH computations
24 much more efficient (160-bit exponentiation instead of 1024-bit
25 exponentiation); so this provides a convenient way to support DHE
26 ciphersuites in SSL/TLS servers (see ssl/ssltest.c). It is of
27 utter importance to use
28 SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE);
29 or
30 SSL_set_options(s_ctx, SSL_OP_SINGLE_DH_USE);
31 when such DH parameters are used, because otherwise small subgroup
32 attacks may become possible!
33 [Bodo Moeller]
34
35 *) Avoid memory leak in i2d_DHparams.
36 [Bodo Moeller]
37
38 *) Allow the -k option to be used more than once in the enc program:
39 this allows the same encrypted message to be read by multiple recipients.
40 [Steve Henson]
41
42 *) New function OBJ_obj2txt(buf, buf_len, a, no_name), this converts
43 an ASN1_OBJECT to a text string. If the "no_name" parameter is set then
44 it will always use the numerical form of the OID, even if it has a short
45 or long name.
46 [Steve Henson]
47
48 *) Added an extra RSA flag: RSA_FLAG_EXT_PKEY. Previously the rsa_mod_exp
49 method only got called if p,q,dmp1,dmq1,iqmp components were present,
50 otherwise bn_mod_exp was called. In the case of hardware keys for example
51 no private key components need be present and it might store extra data
52 in the RSA structure, which cannot be accessed from bn_mod_exp. By setting
53 RSA_FLAG_EXT_PKEY rsa_mod_exp will always be called for private key
54 operations.
55 [Steve Henson]
56
57 *) Added support for SPARC Linux.
58 [Andy Polyakov]
59
60 *) pem_password_cb function type incompatibly changed from
61 typedef int pem_password_cb(char *buf, int size, int rwflag);
62 to
63 ....(char *buf, int size, int rwflag, void *userdata);
64 so that applications can pass data to their callbacks:
65 The PEM[_ASN1]_{read,write}... functions and macros now take an
66 additional void * argument, which is just handed through whenever
67 the password callback is called.
68 [Damien Miller <dmiller@ilogic.com.au>, with tiny changes by Bodo Moeller]
69
70 New function SSL_CTX_set_default_passwd_cb_userdata.
71
72 Compatibility note: As many C implementations push function arguments
73 onto the stack in reverse order, the new library version is likely to
74 interoperate with programs that have been compiled with the old
75 pem_password_cb definition (PEM_whatever takes some data that
76 happens to be on the stack as its last argument, and the callback
77 just ignores this garbage); but there is no guarantee whatsoever that
78 this will work.
79
80 *) The -DPLATFORM="\"$(PLATFORM)\"" definition and the similar -DCFLAGS=...
81 (both in crypto/Makefile.ssl for use by crypto/cversion.c) caused
82 problems not only on Windows, but also on some Unix platforms.
83 To avoid problematic command lines, these definitions are now in an
84 auto-generated file crypto/buildinf.h (created by crypto/Makefile.ssl
85 for standard "make" builds, by util/mk1mf.pl for "mk1mf" builds).
86 [Bodo Moeller]
87
88 *) MIPS III/IV assembler module is reimplemented.
89 [Andy Polyakov]
90
91 *) More DES library cleanups: remove references to srand/rand and
92 delete an unused file.
93 [Ulf Möller]
94
95 *) Add support for the the free Netwide assembler (NASM) under Win32,
96 since not many people have MASM (ml) and it can be hard to obtain.
97 This is currently experimental but it seems to work OK and pass all
98 the tests. Check out INSTALL.W32 for info.
99 [Steve Henson]
100
101 *) Fix memory leaks in s3_clnt.c: All non-anonymous SSL3/TLS1 connections
102 without temporary keys kept an extra copy of the server key,
103 and connections with temporary keys did not free everything in case
104 of an error.
105 [Bodo Moeller]
106
107 *) New function RSA_check_key and new openssl rsa option -check
108 for verifying the consistency of RSA keys.
109 [Ulf Moeller, Bodo Moeller]
110
111 *) Various changes to make Win32 compile work:
112 1. Casts to avoid "loss of data" warnings in p5_crpt2.c
113 2. Change unsigned int to int in b_dump.c to avoid "signed/unsigned
114 comparison" warnings.
115 3. Add sk_<TYPE>_sort to DEF file generator and do make update.
116 [Steve Henson]
117
118 *) Add a debugging option to PKCS#5 v2 key generation function: when
119 you #define DEBUG_PKCS5V2 passwords, salts, iteration counts and
120 derived keys are printed to stderr.
121 [Steve Henson]
122
123 *) Copy the flags in ASN1_STRING_dup().
124 [Roman E. Pavlov <pre@mo.msk.ru>]
125
126 *) The x509 application mishandled signing requests containing DSA
127 keys when the signing key was also DSA and the parameters didn't match.
128
129 It was supposed to omit the parameters when they matched the signing key:
130 the verifying software was then supposed to automatically use the CA's
131 parameters if they were absent from the end user certificate.
132
133 Omitting parameters is no longer recommended. The test was also
134 the wrong way round! This was probably due to unusual behaviour in
135 EVP_cmp_parameters() which returns 1 if the parameters match.
136 This meant that parameters were omitted when they *didn't* match and
137 the certificate was useless. Certificates signed with 'ca' didn't have
138 this bug.
139 [Steve Henson, reported by Doug Erickson <Doug.Erickson@Part.NET>]
140
141 *) Memory leak checking (-DCRYPTO_MDEBUG) had some problems.
142 The interface is as follows:
143 Applications can use
144 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) aka MemCheck_start(),
145 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) aka MemCheck_stop();
146 "off" is now the default.
147 The library internally uses
148 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) aka MemCheck_off(),
149 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) aka MemCheck_on()
150 to disable memory-checking temporarily.
151
152 Some inconsistent states that previously were possible (and were
153 even the default) are now avoided.
154
155 -DCRYPTO_MDEBUG_TIME is new and additionally stores the current time
156 with each memory chunk allocated; this is occasionally more helpful
157 than just having a counter.
158
159 -DCRYPTO_MDEBUG_THREAD is also new and adds the thread ID.
160
161 -DCRYPTO_MDEBUG_ALL enables all of the above, plus any future
162 extensions.
163 [Bodo Moeller]
164
165 *) Introduce "mode" for SSL structures (with defaults in SSL_CTX),
166 which largely parallels "options", but is for changing API behaviour,
167 whereas "options" are about protocol behaviour.
168 Initial "mode" flags are:
169
170 SSL_MODE_ENABLE_PARTIAL_WRITE Allow SSL_write to report success when
171 a single record has been written.
172 SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER Don't insist that SSL_write
173 retries use the same buffer location.
174 (But all of the contents must be
175 copied!)
176 [Bodo Moeller]
177
178 *) Bugfix: SSL_set_mode ignored its parameter, only SSL_CTX_set_mode
179 worked.
180
181 *) Fix problems with no-hmac etc.
182 [Ulf Möller, pointed out by Brian Wellington <bwelling@tislabs.com>]
183
184 *) New functions RSA_get_default_method(), RSA_set_method() and
185 RSA_get_method(). These allows replacement of RSA_METHODs without having
186 to mess around with the internals of an RSA structure.
187 [Steve Henson]
188
189 *) Fix memory leaks in DSA_do_sign and DSA_is_prime.
190 Also really enable memory leak checks in openssl.c and in some
191 test programs.
192 [Chad C. Mulligan, Bodo Moeller]
193
194 *) Fix a bug in d2i_ASN1_INTEGER() and i2d_ASN1_INTEGER() which can mess
195 up the length of negative integers. This has now been simplified to just
196 store the length when it is first determined and use it later, rather
197 than trying to keep track of where data is copied and updating it to
198 point to the end.
199 [Steve Henson, reported by Brien Wheeler
200 <bwheeler@authentica-security.com>]
201
202 *) Add a new function PKCS7_signatureVerify. This allows the verification
203 of a PKCS#7 signature but with the signing certificate passed to the
204 function itself. This contrasts with PKCS7_dataVerify which assumes the
205 certificate is present in the PKCS#7 structure. This isn't always the
206 case: certificates can be omitted from a PKCS#7 structure and be
207 distributed by "out of band" means (such as a certificate database).
208 [Steve Henson]
209
210 *) Complete the PEM_* macros with DECLARE_PEM versions to replace the
211 function prototypes in pem.h, also change util/mkdef.pl to add the
212 necessary function names.
213 [Steve Henson]
214
215 *) mk1mf.pl (used by Windows builds) did not properly read the
216 options set by Configure in the top level Makefile, and Configure
217 was not even able to write more than one option correctly.
218 Fixed, now "no-idea no-rc5 -DCRYPTO_MDEBUG" etc. works as intended.
219 [Bodo Moeller]
220
221 *) New functions CONF_load_bio() and CONF_load_fp() to allow a config
222 file to be loaded from a BIO or FILE pointer. The BIO version will
223 for example allow memory BIOs to contain config info.
224 [Steve Henson]
225
226 *) New function "CRYPTO_num_locks" that returns CRYPTO_NUM_LOCKS.
227 Whoever hopes to achieve shared-library compatibility across versions
228 must use this, not the compile-time macro.
229 (Exercise 0.9.4: Which is the minimum library version required by
230 such programs?)
231 Note: All this applies only to multi-threaded programs, others don't
232 need locks.
233 [Bodo Moeller]
234
235 *) Add missing case to s3_clnt.c state machine -- one of the new SSL tests
236 through a BIO pair triggered the default case, i.e.
237 SSLerr(...,SSL_R_UNKNOWN_STATE).
238 [Bodo Moeller]
239
240 *) New "BIO pair" concept (crypto/bio/bss_bio.c) so that applications
241 can use the SSL library even if none of the specific BIOs is
242 appropriate.
243 [Bodo Moeller]
244
245 *) Fix a bug in i2d_DSAPublicKey() which meant it returned the wrong value
246 for the encoded length.
247 [Jeon KyoungHo <khjeon@sds.samsung.co.kr>]
248
249 *) Add initial documentation of the X509V3 functions.
250 [Steve Henson]
251
252 *) Add a new pair of functions PEM_write_PKCS8PrivateKey() and
253 PEM_write_bio_PKCS8PrivateKey() that are equivalent to
254 PEM_write_PrivateKey() and PEM_write_bio_PrivateKey() but use the more
255 secure PKCS#8 private key format with a high iteration count.
256 [Steve Henson]
257
258 *) Fix determination of Perl interpreter: A perl or perl5
259 _directory_ in $PATH was also accepted as the interpreter.
260 [Ralf S. Engelschall]
261
262 *) Fix demos/sign/sign.c: well there wasn't anything strictly speaking
263 wrong with it but it was very old and did things like calling
264 PEM_ASN1_read() directly and used MD5 for the hash not to mention some
265 unusual formatting.
266 [Steve Henson]
267
268 *) Fix demos/selfsign.c: it used obsolete and deleted functions, changed
269 to use the new extension code.
270 [Steve Henson]
271
272 *) Implement the PEM_read/PEM_write functions in crypto/pem/pem_all.c
273 with macros. This should make it easier to change their form, add extra
274 arguments etc. Fix a few PEM prototypes which didn't have cipher as a
275 constant.
276 [Steve Henson]
277
278 *) Add to configuration table a new entry that can specify an alternative
279 name for unistd.h (for pre-POSIX systems); we need this for NeXTstep,
280 according to Mark Crispin <MRC@Panda.COM>.
281 [Bodo Moeller]
282
283#if 0
284 *) DES CBC did not update the IV. Weird.
285 [Ben Laurie]
286#else
287 des_cbc_encrypt does not update the IV, but des_ncbc_encrypt does.
288 Changing the behaviour of the former might break existing programs --
289 where IV updating is needed, des_ncbc_encrypt can be used.
290#endif
291
292 *) When bntest is run from "make test" it drives bc to check its
293 calculations, as well as internally checking them. If an internal check
294 fails, it needs to cause bc to give a non-zero result or make test carries
295 on without noticing the failure. Fixed.
296 [Ben Laurie]
297
298 *) DES library cleanups.
299 [Ulf Möller]
300
301 *) Add support for PKCS#5 v2.0 PBE algorithms. This will permit PKCS#8 to be
302 used with any cipher unlike PKCS#5 v1.5 which can at most handle 64 bit
303 ciphers. NOTE: although the key derivation function has been verified
304 against some published test vectors it has not been extensively tested
305 yet. Added a -v2 "cipher" option to pkcs8 application to allow the use
306 of v2.0.
307 [Steve Henson]
308
309 *) Instead of "mkdir -p", which is not fully portable, use new
310 Perl script "util/mkdir-p.pl".
311 [Bodo Moeller]
312
313 *) Rewrite the way password based encryption (PBE) is handled. It used to
314 assume that the ASN1 AlgorithmIdentifier parameter was a PBEParameter
315 structure. This was true for the PKCS#5 v1.5 and PKCS#12 PBE algorithms
316 but doesn't apply to PKCS#5 v2.0 where it can be something else. Now
317 the 'parameter' field of the AlgorithmIdentifier is passed to the
318 underlying key generation function so it must do its own ASN1 parsing.
319 This has also changed the EVP_PBE_CipherInit() function which now has a
320 'parameter' argument instead of literal salt and iteration count values
321 and the function EVP_PBE_ALGOR_CipherInit() has been deleted.
322 [Steve Henson]
323
324 *) Support for PKCS#5 v1.5 compatible password based encryption algorithms
325 and PKCS#8 functionality. New 'pkcs8' application linked to openssl.
326 Needed to change the PEM_STRING_EVP_PKEY value which was just "PRIVATE
327 KEY" because this clashed with PKCS#8 unencrypted string. Since this
328 value was just used as a "magic string" and not used directly its
329 value doesn't matter.
330 [Steve Henson]
331
332 *) Introduce some semblance of const correctness to BN. Shame C doesn't
333 support mutable.
334 [Ben Laurie]
335
336 *) "linux-sparc64" configuration (ultrapenguin).
337 [Ray Miller <ray.miller@oucs.ox.ac.uk>]
338 "linux-sparc" configuration.
339 [Christian Forster <fo@hawo.stw.uni-erlangen.de>]
340
341 *) config now generates no-xxx options for missing ciphers.
342 [Ulf Möller]
343
344 *) Support the EBCDIC character set (work in progress).
345 File ebcdic.c not yet included because it has a different license.
346 [Martin Kraemer <Martin.Kraemer@MchP.Siemens.De>]
347
348 *) Support BS2000/OSD-POSIX.
349 [Martin Kraemer <Martin.Kraemer@MchP.Siemens.De>]
350
351 *) Make callbacks for key generation use void * instead of char *.
352 [Ben Laurie]
353
354 *) Make S/MIME samples compile (not yet tested).
355 [Ben Laurie]
356
357 *) Additional typesafe stacks.
358 [Ben Laurie]
359
360 *) New configuration variants "bsdi-elf-gcc" (BSD/OS 4.x).
361 [Bodo Moeller]
362
363
364 Changes between 0.9.3 and 0.9.3a [29 May 1999]
365
366 *) New configuration variant "sco5-gcc".
367
368 *) Updated some demos.
369 [Sean O Riordain, Wade Scholine]
370
371 *) Add missing BIO_free at exit of pkcs12 application.
372 [Wu Zhigang]
373
374 *) Fix memory leak in conf.c.
375 [Steve Henson]
376
377 *) Updates for Win32 to assembler version of MD5.
378 [Steve Henson]
379
380 *) Set #! path to perl in apps/der_chop to where we found it
381 instead of using a fixed path.
382 [Bodo Moeller]
383
384 *) SHA library changes for irix64-mips4-cc.
385 [Andy Polyakov]
386
387 *) Improvements for VMS support.
388 [Richard Levitte]
389
390
391 Changes between 0.9.2b and 0.9.3 [24 May 1999]
392
393 *) Bignum library bug fix. IRIX 6 passes "make test" now!
394 This also avoids the problems with SC4.2 and unpatched SC5.
395 [Andy Polyakov <appro@fy.chalmers.se>]
396
397 *) New functions sk_num, sk_value and sk_set to replace the previous macros.
398 These are required because of the typesafe stack would otherwise break
399 existing code. If old code used a structure member which used to be STACK
400 and is now STACK_OF (for example cert in a PKCS7_SIGNED structure) with
401 sk_num or sk_value it would produce an error because the num, data members
402 are not present in STACK_OF. Now it just produces a warning. sk_set
403 replaces the old method of assigning a value to sk_value
404 (e.g. sk_value(x, i) = y) which the library used in a few cases. Any code
405 that does this will no longer work (and should use sk_set instead) but
406 this could be regarded as a "questionable" behaviour anyway.
407 [Steve Henson]
408
409 *) Fix most of the other PKCS#7 bugs. The "experimental" code can now
410 correctly handle encrypted S/MIME data.
411 [Steve Henson]
412
413 *) Change type of various DES function arguments from des_cblock
414 (which means, in function argument declarations, pointer to char)
415 to des_cblock * (meaning pointer to array with 8 char elements),
416 which allows the compiler to do more typechecking; it was like
417 that back in SSLeay, but with lots of ugly casts.
418
419 Introduce new type const_des_cblock.
420 [Bodo Moeller]
421
422 *) Reorganise the PKCS#7 library and get rid of some of the more obvious
423 problems: find RecipientInfo structure that matches recipient certificate
424 and initialise the ASN1 structures properly based on passed cipher.
425 [Steve Henson]
426
427 *) Belatedly make the BN tests actually check the results.
428 [Ben Laurie]
429
430 *) Fix the encoding and decoding of negative ASN1 INTEGERS and conversion
431 to and from BNs: it was completely broken. New compilation option
432 NEG_PUBKEY_BUG to allow for some broken certificates that encode public
433 key elements as negative integers.
434 [Steve Henson]
435
436 *) Reorganize and speed up MD5.
437 [Andy Polyakov <appro@fy.chalmers.se>]
438
439 *) VMS support.
440 [Richard Levitte <richard@levitte.org>]
441
442 *) New option -out to asn1parse to allow the parsed structure to be
443 output to a file. This is most useful when combined with the -strparse
444 option to examine the output of things like OCTET STRINGS.
445 [Steve Henson]
446
447 *) Make SSL library a little more fool-proof by not requiring any longer
448 that SSL_set_{accept,connect}_state be called before
449 SSL_{accept,connect} may be used (SSL_set_..._state is omitted
450 in many applications because usually everything *appeared* to work as
451 intended anyway -- now it really works as intended).
452 [Bodo Moeller]
453
454 *) Move openssl.cnf out of lib/.
455 [Ulf Möller]
456
457 *) Fix various things to let OpenSSL even pass ``egcc -pipe -O2 -Wall
458 -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes
459 -Wmissing-declarations -Wnested-externs -Winline'' with EGCS 1.1.2+
460 [Ralf S. Engelschall]
461
462 *) Various fixes to the EVP and PKCS#7 code. It may now be able to
463 handle PKCS#7 enveloped data properly.
464 [Sebastian Akerman <sak@parallelconsulting.com>, modified by Steve]
465
466 *) Create a duplicate of the SSL_CTX's CERT in SSL_new instead of
467 copying pointers. The cert_st handling is changed by this in
468 various ways (and thus what used to be known as ctx->default_cert
469 is now called ctx->cert, since we don't resort to s->ctx->[default_]cert
470 any longer when s->cert does not give us what we need).
471 ssl_cert_instantiate becomes obsolete by this change.
472 As soon as we've got the new code right (possibly it already is?),
473 we have solved a couple of bugs of the earlier code where s->cert
474 was used as if it could not have been shared with other SSL structures.
475
476 Note that using the SSL API in certain dirty ways now will result
477 in different behaviour than observed with earlier library versions:
478 Changing settings for an SSL_CTX *ctx after having done s = SSL_new(ctx)
479 does not influence s as it used to.
480
481 In order to clean up things more thoroughly, inside SSL_SESSION
482 we don't use CERT any longer, but a new structure SESS_CERT
483 that holds per-session data (if available); currently, this is
484 the peer's certificate chain and, for clients, the server's certificate
485 and temporary key. CERT holds only those values that can have
486 meaningful defaults in an SSL_CTX.
487 [Bodo Moeller]
488
489 *) New function X509V3_EXT_i2d() to create an X509_EXTENSION structure
490 from the internal representation. Various PKCS#7 fixes: remove some
491 evil casts and set the enc_dig_alg field properly based on the signing
492 key type.
493 [Steve Henson]
494
495 *) Allow PKCS#12 password to be set from the command line or the
496 environment. Let 'ca' get its config file name from the environment
497 variables "OPENSSL_CONF" or "SSLEAY_CONF" (for consistency with 'req'
498 and 'x509').
499 [Steve Henson]
500
501 *) Allow certificate policies extension to use an IA5STRING for the
502 organization field. This is contrary to the PKIX definition but
503 VeriSign uses it and IE5 only recognises this form. Document 'x509'
504 extension option.
505 [Steve Henson]
506
507 *) Add PEDANTIC compiler flag to allow compilation with gcc -pedantic,
508 without disallowing inline assembler and the like for non-pedantic builds.
509 [Ben Laurie]
510
511 *) Support Borland C++ builder.
512 [Janez Jere <jj@void.si>, modified by Ulf Möller]
513
514 *) Support Mingw32.
515 [Ulf Möller]
516
517 *) SHA-1 cleanups and performance enhancements.
518 [Andy Polyakov <appro@fy.chalmers.se>]
519
520 *) Sparc v8plus assembler for the bignum library.
521 [Andy Polyakov <appro@fy.chalmers.se>]
522
523 *) Accept any -xxx and +xxx compiler options in Configure.
524 [Ulf Möller]
525
526 *) Update HPUX configuration.
527 [Anonymous]
528
529 *) Add missing sk_<type>_unshift() function to safestack.h
530 [Ralf S. Engelschall]
531
532 *) New function SSL_CTX_use_certificate_chain_file that sets the
533 "extra_cert"s in addition to the certificate. (This makes sense
534 only for "PEM" format files, as chains as a whole are not
535 DER-encoded.)
536 [Bodo Moeller]
537
538 *) Support verify_depth from the SSL API.
539 x509_vfy.c had what can be considered an off-by-one-error:
540 Its depth (which was not part of the external interface)
541 was actually counting the number of certificates in a chain;
542 now it really counts the depth.
543 [Bodo Moeller]
544
545 *) Bugfix in crypto/x509/x509_cmp.c: The SSLerr macro was used
546 instead of X509err, which often resulted in confusing error
547 messages since the error codes are not globally unique
548 (e.g. an alleged error in ssl3_accept when a certificate
549 didn't match the private key).
550
551 *) New function SSL_CTX_set_session_id_context that allows to set a default
552 value (so that you don't need SSL_set_session_id_context for each
553 connection using the SSL_CTX).
554 [Bodo Moeller]
555
556 *) OAEP decoding bug fix.
557 [Ulf Möller]
558
559 *) Support INSTALL_PREFIX for package builders, as proposed by
560 David Harris.
561 [Bodo Moeller]
562
563 *) New Configure options "threads" and "no-threads". For systems
564 where the proper compiler options are known (currently Solaris
565 and Linux), "threads" is the default.
566 [Bodo Moeller]
567
568 *) New script util/mklink.pl as a faster substitute for util/mklink.sh.
569 [Bodo Moeller]
570
571 *) Install various scripts to $(OPENSSLDIR)/misc, not to
572 $(INSTALLTOP)/bin -- they shouldn't clutter directories
573 such as /usr/local/bin.
574 [Bodo Moeller]
575
576 *) "make linux-shared" to build shared libraries.
577 [Niels Poppe <niels@netbox.org>]
578
579 *) New Configure option no-<cipher> (rsa, idea, rc5, ...).
580 [Ulf Möller]
581
582 *) Add the PKCS#12 API documentation to openssl.txt. Preliminary support for
583 extension adding in x509 utility.
584 [Steve Henson]
585
586 *) Remove NOPROTO sections and error code comments.
587 [Ulf Möller]
588
589 *) Partial rewrite of the DEF file generator to now parse the ANSI
590 prototypes.
591 [Steve Henson]
592
593 *) New Configure options --prefix=DIR and --openssldir=DIR.
594 [Ulf Möller]
595
596 *) Complete rewrite of the error code script(s). It is all now handled
597 by one script at the top level which handles error code gathering,
598 header rewriting and C source file generation. It should be much better
599 than the old method: it now uses a modified version of Ulf's parser to
600 read the ANSI prototypes in all header files (thus the old K&R definitions
601 aren't needed for error creation any more) and do a better job of
602 translating function codes into names. The old 'ASN1 error code imbedded
603 in a comment' is no longer necessary and it doesn't use .err files which
604 have now been deleted. Also the error code call doesn't have to appear all
605 on one line (which resulted in some large lines...).
606 [Steve Henson]
607
608 *) Change #include filenames from <foo.h> to <openssl/foo.h>.
609 [Bodo Moeller]
610
611 *) Change behaviour of ssl2_read when facing length-0 packets: Don't return
612 0 (which usually indicates a closed connection), but continue reading.
613 [Bodo Moeller]
614
615 *) Fix some race conditions.
616 [Bodo Moeller]
617
618 *) Add support for CRL distribution points extension. Add Certificate
619 Policies and CRL distribution points documentation.
620 [Steve Henson]
621
622 *) Move the autogenerated header file parts to crypto/opensslconf.h.
623 [Ulf Möller]
624
625 *) Fix new 56-bit DES export ciphersuites: they were using 7 bytes instead of
626 8 of keying material. Merlin has also confirmed interop with this fix
627 between OpenSSL and Baltimore C/SSL 2.0 and J/SSL 2.0.
628 [Merlin Hughes <merlin@baltimore.ie>]
629
630 *) Fix lots of warnings.
631 [Richard Levitte <levitte@stacken.kth.se>]
632
633 *) In add_cert_dir() in crypto/x509/by_dir.c, break out of the loop if
634 the directory spec didn't end with a LIST_SEPARATOR_CHAR.
635 [Richard Levitte <levitte@stacken.kth.se>]
636
637 *) Fix problems with sizeof(long) == 8.
638 [Andy Polyakov <appro@fy.chalmers.se>]
639
640 *) Change functions to ANSI C.
641 [Ulf Möller]
642
643 *) Fix typos in error codes.
644 [Martin Kraemer <Martin.Kraemer@MchP.Siemens.De>, Ulf Möller]
645
646 *) Remove defunct assembler files from Configure.
647 [Ulf Möller]
648
649 *) SPARC v8 assembler BIGNUM implementation.
650 [Andy Polyakov <appro@fy.chalmers.se>]
651
652 *) Support for Certificate Policies extension: both print and set.
653 Various additions to support the r2i method this uses.
654 [Steve Henson]
655
656 *) A lot of constification, and fix a bug in X509_NAME_oneline() that could
657 return a const string when you are expecting an allocated buffer.
658 [Ben Laurie]
659
660 *) Add support for ASN1 types UTF8String and VISIBLESTRING, also the CHOICE
661 types DirectoryString and DisplayText.
662 [Steve Henson]
663
664 *) Add code to allow r2i extensions to access the configuration database,
665 add an LHASH database driver and add several ctx helper functions.
666 [Steve Henson]
667
668 *) Fix an evil bug in bn_expand2() which caused various BN functions to
669 fail when they extended the size of a BIGNUM.
670 [Steve Henson]
671
672 *) Various utility functions to handle SXNet extension. Modify mkdef.pl to
673 support typesafe stack.
674 [Steve Henson]
675
676 *) Fix typo in SSL_[gs]et_options().
677 [Nils Frostberg <nils@medcom.se>]
678
679 *) Delete various functions and files that belonged to the (now obsolete)
680 old X509V3 handling code.
681 [Steve Henson]
682
683 *) New Configure option "rsaref".
684 [Ulf Möller]
685
686 *) Don't auto-generate pem.h.
687 [Bodo Moeller]
688
689 *) Introduce type-safe ASN.1 SETs.
690 [Ben Laurie]
691
692 *) Convert various additional casted stacks to type-safe STACK_OF() variants.
693 [Ben Laurie, Ralf S. Engelschall, Steve Henson]
694
695 *) Introduce type-safe STACKs. This will almost certainly break lots of code
696 that links with OpenSSL (well at least cause lots of warnings), but fear
697 not: the conversion is trivial, and it eliminates loads of evil casts. A
698 few STACKed things have been converted already. Feel free to convert more.
699 In the fullness of time, I'll do away with the STACK type altogether.
700 [Ben Laurie]
701
702 *) Add `openssl ca -revoke <certfile>' facility which revokes a certificate
703 specified in <certfile> by updating the entry in the index.txt file.
704 This way one no longer has to edit the index.txt file manually for
705 revoking a certificate. The -revoke option does the gory details now.
706 [Massimiliano Pala <madwolf@openca.org>, Ralf S. Engelschall]
707
708 *) Fix `openssl crl -noout -text' combination where `-noout' killed the
709 `-text' option at all and this way the `-noout -text' combination was
710 inconsistent in `openssl crl' with the friends in `openssl x509|rsa|dsa'.
711 [Ralf S. Engelschall]
712
713 *) Make sure a corresponding plain text error message exists for the
714 X509_V_ERR_CERT_REVOKED/23 error number which can occur when a
715 verify callback function determined that a certificate was revoked.
716 [Ralf S. Engelschall]
717
718 *) Bugfix: In test/testenc, don't test "openssl <cipher>" for
719 ciphers that were excluded, e.g. by -DNO_IDEA. Also, test
720 all available cipers including rc5, which was forgotten until now.
721 In order to let the testing shell script know which algorithms
722 are available, a new (up to now undocumented) command
723 "openssl list-cipher-commands" is used.
724 [Bodo Moeller]
725
726 *) Bugfix: s_client occasionally would sleep in select() when
727 it should have checked SSL_pending() first.
728 [Bodo Moeller]
729
730 *) New functions DSA_do_sign and DSA_do_verify to provide access to
731 the raw DSA values prior to ASN.1 encoding.
732 [Ulf Möller]
733
734 *) Tweaks to Configure
735 [Niels Poppe <niels@netbox.org>]
736
737 *) Add support for PKCS#5 v2.0 ASN1 PBES2 structures. No other support,
738 yet...
739 [Steve Henson]
740
741 *) New variables $(RANLIB) and $(PERL) in the Makefiles.
742 [Ulf Möller]
743
744 *) New config option to avoid instructions that are illegal on the 80386.
745 The default code is faster, but requires at least a 486.
746 [Ulf Möller]
747
748 *) Got rid of old SSL2_CLIENT_VERSION (inconsistently used) and
749 SSL2_SERVER_VERSION (not used at all) macros, which are now the
750 same as SSL2_VERSION anyway.
751 [Bodo Moeller]
752
753 *) New "-showcerts" option for s_client.
754 [Bodo Moeller]
755
756 *) Still more PKCS#12 integration. Add pkcs12 application to openssl
757 application. Various cleanups and fixes.
758 [Steve Henson]
759
760 *) More PKCS#12 integration. Add new pkcs12 directory with Makefile.ssl and
761 modify error routines to work internally. Add error codes and PBE init
762 to library startup routines.
763 [Steve Henson]
764
765 *) Further PKCS#12 integration. Added password based encryption, PKCS#8 and
766 packing functions to asn1 and evp. Changed function names and error
767 codes along the way.
768 [Steve Henson]
769
770 *) PKCS12 integration: and so it begins... First of several patches to
771 slowly integrate PKCS#12 functionality into OpenSSL. Add PKCS#12
772 objects to objects.h
773 [Steve Henson]
774
775 *) Add a new 'indent' option to some X509V3 extension code. Initial ASN1
776 and display support for Thawte strong extranet extension.
777 [Steve Henson]
778
779 *) Add LinuxPPC support.
780 [Jeff Dubrule <igor@pobox.org>]
781
782 *) Get rid of redundant BN file bn_mulw.c, and rename bn_div64 to
783 bn_div_words in alpha.s.
784 [Hannes Reinecke <H.Reinecke@hw.ac.uk> and Ben Laurie]
785
786 *) Make sure the RSA OAEP test is skipped under -DRSAref because
787 OAEP isn't supported when OpenSSL is built with RSAref.
788 [Ulf Moeller <ulf@fitug.de>]
789
790 *) Move definitions of IS_SET/IS_SEQUENCE inside crypto/asn1/asn1.h
791 so they no longer are missing under -DNOPROTO.
792 [Soren S. Jorvang <soren@t.dk>]
793
794
795 Changes between 0.9.1c and 0.9.2b [22 Mar 1999]
796
797 *) Make SSL_get_peer_cert_chain() work in servers. Unfortunately, it still
798 doesn't work when the session is reused. Coming soon!
799 [Ben Laurie]
800
801 *) Fix a security hole, that allows sessions to be reused in the wrong
802 context thus bypassing client cert protection! All software that uses
803 client certs and session caches in multiple contexts NEEDS PATCHING to
804 allow session reuse! A fuller solution is in the works.
805 [Ben Laurie, problem pointed out by Holger Reif, Bodo Moeller (and ???)]
806
807 *) Some more source tree cleanups (removed obsolete files
808 crypto/bf/asm/bf586.pl, test/test.txt and crypto/sha/asm/f.s; changed
809 permission on "config" script to be executable) and a fix for the INSTALL
810 document.
811 [Ulf Moeller <ulf@fitug.de>]
812
813 *) Remove some legacy and erroneous uses of malloc, free instead of
814 Malloc, Free.
815 [Lennart Bang <lob@netstream.se>, with minor changes by Steve]
816
817 *) Make rsa_oaep_test return non-zero on error.
818 [Ulf Moeller <ulf@fitug.de>]
819
820 *) Add support for native Solaris shared libraries. Configure
821 solaris-sparc-sc4-pic, make, then run shlib/solaris-sc4.sh. It'd be nice
822 if someone would make that last step automatic.
823 [Matthias Loepfe <Matthias.Loepfe@AdNovum.CH>]
824
825 *) ctx_size was not built with the right compiler during "make links". Fixed.
826 [Ben Laurie]
827
828 *) Change the meaning of 'ALL' in the cipher list. It now means "everything
829 except NULL ciphers". This means the default cipher list will no longer
830 enable NULL ciphers. They need to be specifically enabled e.g. with
831 the string "DEFAULT:eNULL".
832 [Steve Henson]
833
834 *) Fix to RSA private encryption routines: if p < q then it would
835 occasionally produce an invalid result. This will only happen with
836 externally generated keys because OpenSSL (and SSLeay) ensure p > q.
837 [Steve Henson]
838
839 *) Be less restrictive and allow also `perl util/perlpath.pl
840 /path/to/bin/perl' in addition to `perl util/perlpath.pl /path/to/bin',
841 because this way one can also use an interpreter named `perl5' (which is
842 usually the name of Perl 5.xxx on platforms where an Perl 4.x is still
843 installed as `perl').
844 [Matthias Loepfe <Matthias.Loepfe@adnovum.ch>]
845
846 *) Let util/clean-depend.pl work also with older Perl 5.00x versions.
847 [Matthias Loepfe <Matthias.Loepfe@adnovum.ch>]
848
849 *) Fix Makefile.org so CC,CFLAG etc are passed to 'make links' add
850 advapi32.lib to Win32 build and change the pem test comparision
851 to fc.exe (thanks to Ulrich Kroener <kroneru@yahoo.com> for the
852 suggestion). Fix misplaced ASNI prototypes and declarations in evp.h
853 and crypto/des/ede_cbcm_enc.c.
854 [Steve Henson]
855
856 *) DES quad checksum was broken on big-endian architectures. Fixed.
857 [Ben Laurie]
858
859 *) Comment out two functions in bio.h that aren't implemented. Fix up the
860 Win32 test batch file so it (might) work again. The Win32 test batch file
861 is horrible: I feel ill....
862 [Steve Henson]
863
864 *) Move various #ifdefs around so NO_SYSLOG, NO_DIRENT etc are now selected
865 in e_os.h. Audit of header files to check ANSI and non ANSI
866 sections: 10 functions were absent from non ANSI section and not exported
867 from Windows DLLs. Fixed up libeay.num for new functions.
868 [Steve Henson]
869
870 *) Make `openssl version' output lines consistent.
871 [Ralf S. Engelschall]
872
873 *) Fix Win32 symbol export lists for BIO functions: Added
874 BIO_get_ex_new_index, BIO_get_ex_num, BIO_get_ex_data and BIO_set_ex_data
875 to ms/libeay{16,32}.def.
876 [Ralf S. Engelschall]
877
878 *) Second round of fixing the OpenSSL perl/ stuff. It now at least compiled
879 fine under Unix and passes some trivial tests I've now added. But the
880 whole stuff is horribly incomplete, so a README.1ST with a disclaimer was
881 added to make sure no one expects that this stuff really works in the
882 OpenSSL 0.9.2 release. Additionally I've started to clean the XS sources
883 up and fixed a few little bugs and inconsistencies in OpenSSL.{pm,xs} and
884 openssl_bio.xs.
885 [Ralf S. Engelschall]
886
887 *) Fix the generation of two part addresses in perl.
888 [Kenji Miyake <kenji@miyake.org>, integrated by Ben Laurie]
889
890 *) Add config entry for Linux on MIPS.
891 [John Tobey <jtobey@channel1.com>]
892
893 *) Make links whenever Configure is run, unless we are on Windoze.
894 [Ben Laurie]
895
896 *) Permit extensions to be added to CRLs using crl_section in openssl.cnf.
897 Currently only issuerAltName and AuthorityKeyIdentifier make any sense
898 in CRLs.
899 [Steve Henson]
900
901 *) Add a useful kludge to allow package maintainers to specify compiler and
902 other platforms details on the command line without having to patch the
903 Configure script everytime: One now can use ``perl Configure
904 <id>:<details>'', i.e. platform ids are allowed to have details appended
905 to them (seperated by colons). This is treated as there would be a static
906 pre-configured entry in Configure's %table under key <id> with value
907 <details> and ``perl Configure <id>'' is called. So, when you want to
908 perform a quick test-compile under FreeBSD 3.1 with pgcc and without
909 assembler stuff you can use ``perl Configure "FreeBSD-elf:pgcc:-O6:::"''
910 now, which overrides the FreeBSD-elf entry on-the-fly.
911 [Ralf S. Engelschall]
912
913 *) Disable new TLS1 ciphersuites by default: they aren't official yet.
914 [Ben Laurie]
915
916 *) Allow DSO flags like -fpic, -fPIC, -KPIC etc. to be specified
917 on the `perl Configure ...' command line. This way one can compile
918 OpenSSL libraries with Position Independent Code (PIC) which is needed
919 for linking it into DSOs.
920 [Ralf S. Engelschall]
921
922 *) Remarkably, export ciphers were totally broken and no-one had noticed!
923 Fixed.
924 [Ben Laurie]
925
926 *) Cleaned up the LICENSE document: The official contact for any license
927 questions now is the OpenSSL core team under openssl-core@openssl.org.
928 And add a paragraph about the dual-license situation to make sure people
929 recognize that _BOTH_ the OpenSSL license _AND_ the SSLeay license apply
930 to the OpenSSL toolkit.
931 [Ralf S. Engelschall]
932
933 *) General source tree makefile cleanups: Made `making xxx in yyy...'
934 display consistent in the source tree and replaced `/bin/rm' by `rm'.
935 Additonally cleaned up the `make links' target: Remove unnecessary
936 semicolons, subsequent redundant removes, inline point.sh into mklink.sh
937 to speed processing and no longer clutter the display with confusing
938 stuff. Instead only the actually done links are displayed.
939 [Ralf S. Engelschall]
940
941 *) Permit null encryption ciphersuites, used for authentication only. It used
942 to be necessary to set the preprocessor define SSL_ALLOW_ENULL to do this.
943 It is now necessary to set SSL_FORBID_ENULL to prevent the use of null
944 encryption.
945 [Ben Laurie]
946
947 *) Add a bunch of fixes to the PKCS#7 stuff. It used to sometimes reorder
948 signed attributes when verifying signatures (this would break them),
949 the detached data encoding was wrong and public keys obtained using
950 X509_get_pubkey() weren't freed.
951 [Steve Henson]
952
953 *) Add text documentation for the BUFFER functions. Also added a work around
954 to a Win95 console bug. This was triggered by the password read stuff: the
955 last character typed gets carried over to the next fread(). If you were
956 generating a new cert request using 'req' for example then the last
957 character of the passphrase would be CR which would then enter the first
958 field as blank.
959 [Steve Henson]
960
961 *) Added the new `Includes OpenSSL Cryptography Software' button as
962 doc/openssl_button.{gif,html} which is similar in style to the old SSLeay
963 button and can be used by applications based on OpenSSL to show the
964 relationship to the OpenSSL project.
965 [Ralf S. Engelschall]
966
967 *) Remove confusing variables in function signatures in files
968 ssl/ssl_lib.c and ssl/ssl.h.
969 [Lennart Bong <lob@kulthea.stacken.kth.se>]
970
971 *) Don't install bss_file.c under PREFIX/include/
972 [Lennart Bong <lob@kulthea.stacken.kth.se>]
973
974 *) Get the Win32 compile working again. Modify mkdef.pl so it can handle
975 functions that return function pointers and has support for NT specific
976 stuff. Fix mk1mf.pl and VC-32.pl to support NT differences also. Various
977 #ifdef WIN32 and WINNTs sprinkled about the place and some changes from
978 unsigned to signed types: this was killing the Win32 compile.
979 [Steve Henson]
980
981 *) Add new certificate file to stack functions,
982 SSL_add_dir_cert_subjects_to_stack() and
983 SSL_add_file_cert_subjects_to_stack(). These largely supplant
984 SSL_load_client_CA_file(), and can be used to add multiple certs easily
985 to a stack (usually this is then handed to SSL_CTX_set_client_CA_list()).
986 This means that Apache-SSL and similar packages don't have to mess around
987 to add as many CAs as they want to the preferred list.
988 [Ben Laurie]
989
990 *) Experiment with doxygen documentation. Currently only partially applied to
991 ssl/ssl_lib.c.
992 See http://www.stack.nl/~dimitri/doxygen/index.html, and run doxygen with
993 openssl.doxy as the configuration file.
994 [Ben Laurie]
995
996 *) Get rid of remaining C++-style comments which strict C compilers hate.
997 [Ralf S. Engelschall, pointed out by Carlos Amengual]
998
999 *) Changed BN_RECURSION in bn_mont.c to BN_RECURSION_MONT so it is not
1000 compiled in by default: it has problems with large keys.
1001 [Steve Henson]
1002
1003 *) Add a bunch of SSL_xxx() functions for configuring the temporary RSA and
1004 DH private keys and/or callback functions which directly correspond to
1005 their SSL_CTX_xxx() counterparts but work on a per-connection basis. This
1006 is needed for applications which have to configure certificates on a
1007 per-connection basis (e.g. Apache+mod_ssl) instead of a per-context basis
1008 (e.g. s_server).
1009 For the RSA certificate situation is makes no difference, but
1010 for the DSA certificate situation this fixes the "no shared cipher"
1011 problem where the OpenSSL cipher selection procedure failed because the
1012 temporary keys were not overtaken from the context and the API provided
1013 no way to reconfigure them.
1014 The new functions now let applications reconfigure the stuff and they
1015 are in detail: SSL_need_tmp_RSA, SSL_set_tmp_rsa, SSL_set_tmp_dh,
1016 SSL_set_tmp_rsa_callback and SSL_set_tmp_dh_callback. Additionally a new
1017 non-public-API function ssl_cert_instantiate() is used as a helper
1018 function and also to reduce code redundancy inside ssl_rsa.c.
1019 [Ralf S. Engelschall]
1020
1021 *) Move s_server -dcert and -dkey options out of the undocumented feature
1022 area because they are useful for the DSA situation and should be
1023 recognized by the users.
1024 [Ralf S. Engelschall]
1025
1026 *) Fix the cipher decision scheme for export ciphers: the export bits are
1027 *not* within SSL_MKEY_MASK or SSL_AUTH_MASK, they are within
1028 SSL_EXP_MASK. So, the original variable has to be used instead of the
1029 already masked variable.
1030 [Richard Levitte <levitte@stacken.kth.se>]
1031
1032 *) Fix 'port' variable from `int' to `unsigned int' in crypto/bio/b_sock.c
1033 [Richard Levitte <levitte@stacken.kth.se>]
1034
1035 *) Change type of another md_len variable in pk7_doit.c:PKCS7_dataFinal()
1036 from `int' to `unsigned int' because it's a length and initialized by
1037 EVP_DigestFinal() which expects an `unsigned int *'.
1038 [Richard Levitte <levitte@stacken.kth.se>]
1039
1040 *) Don't hard-code path to Perl interpreter on shebang line of Configure
1041 script. Instead use the usual Shell->Perl transition trick.
1042 [Ralf S. Engelschall]
1043
1044 *) Make `openssl x509 -noout -modulus' functional also for DSA certificates
1045 (in addition to RSA certificates) to match the behaviour of `openssl dsa
1046 -noout -modulus' as it's already the case for `openssl rsa -noout
1047 -modulus'. For RSA the -modulus is the real "modulus" while for DSA
1048 currently the public key is printed (a decision which was already done by
1049 `openssl dsa -modulus' in the past) which serves a similar purpose.
1050 Additionally the NO_RSA no longer completely removes the whole -modulus
1051 option; it now only avoids using the RSA stuff. Same applies to NO_DSA
1052 now, too.
1053 [Ralf S. Engelschall]
1054
1055 *) Add Arne Ansper's reliable BIO - this is an encrypted, block-digested
1056 BIO. See the source (crypto/evp/bio_ok.c) for more info.
1057 [Arne Ansper <arne@ats.cyber.ee>]
1058
1059 *) Dump the old yucky req code that tried (and failed) to allow raw OIDs
1060 to be added. Now both 'req' and 'ca' can use new objects defined in the
1061 config file.
1062 [Steve Henson]
1063
1064 *) Add cool BIO that does syslog (or event log on NT).
1065 [Arne Ansper <arne@ats.cyber.ee>, integrated by Ben Laurie]
1066
1067 *) Add support for new TLS ciphersuites, TLS_RSA_EXPORT56_WITH_RC4_56_MD5,
1068 TLS_RSA_EXPORT56_WITH_RC2_CBC_56_MD5 and
1069 TLS_RSA_EXPORT56_WITH_DES_CBC_SHA, as specified in "56-bit Export Cipher
1070 Suites For TLS", draft-ietf-tls-56-bit-ciphersuites-00.txt.
1071 [Ben Laurie]
1072
1073 *) Add preliminary config info for new extension code.
1074 [Steve Henson]
1075
1076 *) Make RSA_NO_PADDING really use no padding.
1077 [Ulf Moeller <ulf@fitug.de>]
1078
1079 *) Generate errors when private/public key check is done.
1080 [Ben Laurie]
1081
1082 *) Overhaul for 'crl' utility. New function X509_CRL_print. Partial support
1083 for some CRL extensions and new objects added.
1084 [Steve Henson]
1085
1086 *) Really fix the ASN1 IMPLICIT bug this time... Partial support for private
1087 key usage extension and fuller support for authority key id.
1088 [Steve Henson]
1089
1090 *) Add OAEP encryption for the OpenSSL crypto library. OAEP is the improved
1091 padding method for RSA, which is recommended for new applications in PKCS
1092 #1 v2.0 (RFC 2437, October 1998).
1093 OAEP (Optimal Asymmetric Encryption Padding) has better theoretical
1094 foundations than the ad-hoc padding used in PKCS #1 v1.5. It is secure
1095 against Bleichbacher's attack on RSA.
1096 [Ulf Moeller <ulf@fitug.de>, reformatted, corrected and integrated by
1097 Ben Laurie]
1098
1099 *) Updates to the new SSL compression code
1100 [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
1101
1102 *) Fix so that the version number in the master secret, when passed
1103 via RSA, checks that if TLS was proposed, but we roll back to SSLv3
1104 (because the server will not accept higher), that the version number
1105 is 0x03,0x01, not 0x03,0x00
1106 [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
1107
1108 *) Run extensive memory leak checks on SSL apps. Fixed *lots* of memory
1109 leaks in ssl/ relating to new X509_get_pubkey() behaviour. Also fixes
1110 in apps/ and an unrelated leak in crypto/dsa/dsa_vrf.c
1111 [Steve Henson]
1112
1113 *) Support for RAW extensions where an arbitrary extension can be
1114 created by including its DER encoding. See apps/openssl.cnf for
1115 an example.
1116 [Steve Henson]
1117
1118 *) Make sure latest Perl versions don't interpret some generated C array
1119 code as Perl array code in the crypto/err/err_genc.pl script.
1120 [Lars Weber <3weber@informatik.uni-hamburg.de>]
1121
1122 *) Modify ms/do_ms.bat to not generate assembly language makefiles since
1123 not many people have the assembler. Various Win32 compilation fixes and
1124 update to the INSTALL.W32 file with (hopefully) more accurate Win32
1125 build instructions.
1126 [Steve Henson]
1127
1128 *) Modify configure script 'Configure' to automatically create crypto/date.h
1129 file under Win32 and also build pem.h from pem.org. New script
1130 util/mkfiles.pl to create the MINFO file on environments that can't do a
1131 'make files': perl util/mkfiles.pl >MINFO should work.
1132 [Steve Henson]
1133
1134 *) Major rework of DES function declarations, in the pursuit of correctness
1135 and purity. As a result, many evil casts evaporated, and some weirdness,
1136 too. You may find this causes warnings in your code. Zapping your evil
1137 casts will probably fix them. Mostly.
1138 [Ben Laurie]
1139
1140 *) Fix for a typo in asn1.h. Bug fix to object creation script
1141 obj_dat.pl. It considered a zero in an object definition to mean
1142 "end of object": none of the objects in objects.h have any zeros
1143 so it wasn't spotted.
1144 [Steve Henson, reported by Erwann ABALEA <eabalea@certplus.com>]
1145
1146 *) Add support for Triple DES Cipher Block Chaining with Output Feedback
1147 Masking (CBCM). In the absence of test vectors, the best I have been able
1148 to do is check that the decrypt undoes the encrypt, so far. Send me test
1149 vectors if you have them.
1150 [Ben Laurie]
1151
1152 *) Correct calculation of key length for export ciphers (too much space was
1153 allocated for null ciphers). This has not been tested!
1154 [Ben Laurie]
1155
1156 *) Modifications to the mkdef.pl for Win32 DEF file creation. The usage
1157 message is now correct (it understands "crypto" and "ssl" on its
1158 command line). There is also now an "update" option. This will update
1159 the util/ssleay.num and util/libeay.num files with any new functions.
1160 If you do a:
1161 perl util/mkdef.pl crypto ssl update
1162 it will update them.
1163 [Steve Henson]
1164
1165 *) Overhauled the Perl interface (perl/*):
1166 - ported BN stuff to OpenSSL's different BN library
1167 - made the perl/ source tree CVS-aware
1168 - renamed the package from SSLeay to OpenSSL (the files still contain
1169 their history because I've copied them in the repository)
1170 - removed obsolete files (the test scripts will be replaced
1171 by better Test::Harness variants in the future)
1172 [Ralf S. Engelschall]
1173
1174 *) First cut for a very conservative source tree cleanup:
1175 1. merge various obsolete readme texts into doc/ssleay.txt
1176 where we collect the old documents and readme texts.
1177 2. remove the first part of files where I'm already sure that we no
1178 longer need them because of three reasons: either they are just temporary
1179 files which were left by Eric or they are preserved original files where
1180 I've verified that the diff is also available in the CVS via "cvs diff
1181 -rSSLeay_0_8_1b" or they were renamed (as it was definitely the case for
1182 the crypto/md/ stuff).
1183 [Ralf S. Engelschall]
1184
1185 *) More extension code. Incomplete support for subject and issuer alt
1186 name, issuer and authority key id. Change the i2v function parameters
1187 and add an extra 'crl' parameter in the X509V3_CTX structure: guess
1188 what that's for :-) Fix to ASN1 macro which messed up
1189 IMPLICIT tag and add f_enum.c which adds a2i, i2a for ENUMERATED.
1190 [Steve Henson]
1191
1192 *) Preliminary support for ENUMERATED type. This is largely copied from the
1193 INTEGER code.
1194 [Steve Henson]
1195
1196 *) Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy.
1197 [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
1198
1199 *) Make sure `make rehash' target really finds the `openssl' program.
1200 [Ralf S. Engelschall, Matthias Loepfe <Matthias.Loepfe@adnovum.ch>]
1201
1202 *) Squeeze another 7% of speed out of MD5 assembler, at least on a P2. I'd
1203 like to hear about it if this slows down other processors.
1204 [Ben Laurie]
1205
1206 *) Add CygWin32 platform information to Configure script.
1207 [Alan Batie <batie@aahz.jf.intel.com>]
1208
1209 *) Fixed ms/32all.bat script: `no_asm' -> `no-asm'
1210 [Rainer W. Gerling <gerling@mpg-gv.mpg.de>]
1211
1212 *) New program nseq to manipulate netscape certificate sequences
1213 [Steve Henson]
1214
1215 *) Modify crl2pkcs7 so it supports multiple -certfile arguments. Fix a
1216 few typos.
1217 [Steve Henson]
1218
1219 *) Fixes to BN code. Previously the default was to define BN_RECURSION
1220 but the BN code had some problems that would cause failures when
1221 doing certificate verification and some other functions.
1222 [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
1223
1224 *) Add ASN1 and PEM code to support netscape certificate sequences.
1225 [Steve Henson]
1226
1227 *) Add ASN1 and PEM code to support netscape certificate sequences.
1228 [Steve Henson]
1229
1230 *) Add several PKIX and private extended key usage OIDs.
1231 [Steve Henson]
1232
1233 *) Modify the 'ca' program to handle the new extension code. Modify
1234 openssl.cnf for new extension format, add comments.
1235 [Steve Henson]
1236
1237 *) More X509 V3 changes. Fix typo in v3_bitstr.c. Add support to 'req'
1238 and add a sample to openssl.cnf so req -x509 now adds appropriate
1239 CA extensions.
1240 [Steve Henson]
1241
1242 *) Continued X509 V3 changes. Add to other makefiles, integrate with the
1243 error code, add initial support to X509_print() and x509 application.
1244 [Steve Henson]
1245
1246 *) Takes a deep breath and start addding X509 V3 extension support code. Add
1247 files in crypto/x509v3. Move original stuff to crypto/x509v3/old. All this
1248 stuff is currently isolated and isn't even compiled yet.
1249 [Steve Henson]
1250
1251 *) Continuing patches for GeneralizedTime. Fix up certificate and CRL
1252 ASN1 to use ASN1_TIME and modify print routines to use ASN1_TIME_print.
1253 Removed the versions check from X509 routines when loading extensions:
1254 this allows certain broken certificates that don't set the version
1255 properly to be processed.
1256 [Steve Henson]
1257
1258 *) Deal with irritating shit to do with dependencies, in YAAHW (Yet Another
1259 Ad Hoc Way) - Makefile.ssls now all contain local dependencies, which
1260 can still be regenerated with "make depend".
1261 [Ben Laurie]
1262
1263 *) Spelling mistake in C version of CAST-128.
1264 [Ben Laurie, reported by Jeremy Hylton <jeremy@cnri.reston.va.us>]
1265
1266 *) Changes to the error generation code. The perl script err-code.pl
1267 now reads in the old error codes and retains the old numbers, only
1268 adding new ones if necessary. It also only changes the .err files if new
1269 codes are added. The makefiles have been modified to only insert errors
1270 when needed (to avoid needlessly modifying header files). This is done
1271 by only inserting errors if the .err file is newer than the auto generated
1272 C file. To rebuild all the error codes from scratch (the old behaviour)
1273 either modify crypto/Makefile.ssl to pass the -regen flag to err_code.pl
1274 or delete all the .err files.
1275 [Steve Henson]
1276
1277 *) CAST-128 was incorrectly implemented for short keys. The C version has
1278 been fixed, but is untested. The assembler versions are also fixed, but
1279 new assembler HAS NOT BEEN GENERATED FOR WIN32 - the Makefile needs fixing
1280 to regenerate it if needed.
1281 [Ben Laurie, reported (with fix for C version) by Jun-ichiro itojun
1282 Hagino <itojun@kame.net>]
1283
1284 *) File was opened incorrectly in randfile.c.
1285 [Ulf Möller <ulf@fitug.de>]
1286
1287 *) Beginning of support for GeneralizedTime. d2i, i2d, check and print
1288 functions. Also ASN1_TIME suite which is a CHOICE of UTCTime or
1289 GeneralizedTime. ASN1_TIME is the proper type used in certificates et
1290 al: it's just almost always a UTCTime. Note this patch adds new error
1291 codes so do a "make errors" if there are problems.
1292 [Steve Henson]
1293
1294 *) Correct Linux 1 recognition in config.
1295 [Ulf Möller <ulf@fitug.de>]
1296
1297 *) Remove pointless MD5 hash when using DSA keys in ca.
1298 [Anonymous <nobody@replay.com>]
1299
1300 *) Generate an error if given an empty string as a cert directory. Also
1301 generate an error if handed NULL (previously returned 0 to indicate an
1302 error, but didn't set one).
1303 [Ben Laurie, reported by Anonymous <nobody@replay.com>]
1304
1305 *) Add prototypes to SSL methods. Make SSL_write's buffer const, at last.
1306 [Ben Laurie]
1307
1308 *) Fix the dummy function BN_ref_mod_exp() in rsaref.c to have the correct
1309 parameters. This was causing a warning which killed off the Win32 compile.
1310 [Steve Henson]
1311
1312 *) Remove C++ style comments from crypto/bn/bn_local.h.
1313 [Neil Costigan <neil.costigan@celocom.com>]
1314
1315 *) The function OBJ_txt2nid was broken. It was supposed to return a nid
1316 based on a text string, looking up short and long names and finally
1317 "dot" format. The "dot" format stuff didn't work. Added new function
1318 OBJ_txt2obj to do the same but return an ASN1_OBJECT and rewrote
1319 OBJ_txt2nid to use it. OBJ_txt2obj can also return objects even if the
1320 OID is not part of the table.
1321 [Steve Henson]
1322
1323 *) Add prototypes to X509 lookup/verify methods, fixing a bug in
1324 X509_LOOKUP_by_alias().
1325 [Ben Laurie]
1326
1327 *) Sort openssl functions by name.
1328 [Ben Laurie]
1329
1330 *) Get the gendsa program working (hopefully) and add it to app list. Remove
1331 encryption from sample DSA keys (in case anyone is interested the password
1332 was "1234").
1333 [Steve Henson]
1334
1335 *) Make _all_ *_free functions accept a NULL pointer.
1336 [Frans Heymans <fheymans@isaserver.be>]
1337
1338 *) If a DH key is generated in s3_srvr.c, don't blow it by trying to use
1339 NULL pointers.
1340 [Anonymous <nobody@replay.com>]
1341
1342 *) s_server should send the CAfile as acceptable CAs, not its own cert.
1343 [Bodo Moeller <3moeller@informatik.uni-hamburg.de>]
1344
1345 *) Don't blow it for numeric -newkey arguments to apps/req.
1346 [Bodo Moeller <3moeller@informatik.uni-hamburg.de>]
1347
1348 *) Temp key "for export" tests were wrong in s3_srvr.c.
1349 [Anonymous <nobody@replay.com>]
1350
1351 *) Add prototype for temp key callback functions
1352 SSL_CTX_set_tmp_{rsa,dh}_callback().
1353 [Ben Laurie]
1354
1355 *) Make DH_free() tolerate being passed a NULL pointer (like RSA_free() and
1356 DSA_free()). Make X509_PUBKEY_set() check for errors in d2i_PublicKey().
1357 [Steve Henson]
1358
1359 *) X509_name_add_entry() freed the wrong thing after an error.
1360 [Arne Ansper <arne@ats.cyber.ee>]
1361
1362 *) rsa_eay.c would attempt to free a NULL context.
1363 [Arne Ansper <arne@ats.cyber.ee>]
1364
1365 *) BIO_s_socket() had a broken should_retry() on Windoze.
1366 [Arne Ansper <arne@ats.cyber.ee>]
1367
1368 *) BIO_f_buffer() didn't pass on BIO_CTRL_FLUSH.
1369 [Arne Ansper <arne@ats.cyber.ee>]
1370
1371 *) Make sure the already existing X509_STORE->depth variable is initialized
1372 in X509_STORE_new(), but document the fact that this variable is still
1373 unused in the certificate verification process.
1374 [Ralf S. Engelschall]
1375
1376 *) Fix the various library and apps files to free up pkeys obtained from
1377 X509_PUBKEY_get() et al. Also allow x509.c to handle netscape extensions.
1378 [Steve Henson]
1379
1380 *) Fix reference counting in X509_PUBKEY_get(). This makes
1381 demos/maurice/example2.c work, amongst others, probably.
1382 [Steve Henson and Ben Laurie]
1383
1384 *) First cut of a cleanup for apps/. First the `ssleay' program is now named
1385 `openssl' and second, the shortcut symlinks for the `openssl <command>'
1386 are no longer created. This way we have a single and consistent command
1387 line interface `openssl <command>', similar to `cvs <command>'.
1388 [Ralf S. Engelschall, Paul Sutton and Ben Laurie]
1389
1390 *) ca.c: move test for DSA keys inside #ifndef NO_DSA. Make pubkey
1391 BIT STRING wrapper always have zero unused bits.
1392 [Steve Henson]
1393
1394 *) Add CA.pl, perl version of CA.sh, add extended key usage OID.
1395 [Steve Henson]
1396
1397 *) Make the top-level INSTALL documentation easier to understand.
1398 [Paul Sutton]
1399
1400 *) Makefiles updated to exit if an error occurs in a sub-directory
1401 make (including if user presses ^C) [Paul Sutton]
1402
1403 *) Make Montgomery context stuff explicit in RSA data structure.
1404 [Ben Laurie]
1405
1406 *) Fix build order of pem and err to allow for generated pem.h.
1407 [Ben Laurie]
1408
1409 *) Fix renumbering bug in X509_NAME_delete_entry().
1410 [Ben Laurie]
1411
1412 *) Enhanced the err-ins.pl script so it makes the error library number
1413 global and can add a library name. This is needed for external ASN1 and
1414 other error libraries.
1415 [Steve Henson]
1416
1417 *) Fixed sk_insert which never worked properly.
1418 [Steve Henson]
1419
1420 *) Fix ASN1 macros so they can handle indefinite length construted
1421 EXPLICIT tags. Some non standard certificates use these: they can now
1422 be read in.
1423 [Steve Henson]
1424
1425 *) Merged the various old/obsolete SSLeay documentation files (doc/xxx.doc)
1426 into a single doc/ssleay.txt bundle. This way the information is still
1427 preserved but no longer messes up this directory. Now it's new room for
1428 the new set of documenation files.
1429 [Ralf S. Engelschall]
1430
1431 *) SETs were incorrectly DER encoded. This was a major pain, because they
1432 shared code with SEQUENCEs, which aren't coded the same. This means that
1433 almost everything to do with SETs or SEQUENCEs has either changed name or
1434 number of arguments.
1435 [Ben Laurie, based on a partial fix by GP Jayan <gp@nsj.co.jp>]
1436
1437 *) Fix test data to work with the above.
1438 [Ben Laurie]
1439
1440 *) Fix the RSA header declarations that hid a bug I fixed in 0.9.0b but
1441 was already fixed by Eric for 0.9.1 it seems.
1442 [Ben Laurie - pointed out by Ulf Möller <ulf@fitug.de>]
1443
1444 *) Autodetect FreeBSD3.
1445 [Ben Laurie]
1446
1447 *) Fix various bugs in Configure. This affects the following platforms:
1448 nextstep
1449 ncr-scde
1450 unixware-2.0
1451 unixware-2.0-pentium
1452 sco5-cc.
1453 [Ben Laurie]
1454
1455 *) Eliminate generated files from CVS. Reorder tests to regenerate files
1456 before they are needed.
1457 [Ben Laurie]
1458
1459 *) Generate Makefile.ssl from Makefile.org (to keep CVS happy).
1460 [Ben Laurie]
1461
1462
1463 Changes between 0.9.1b and 0.9.1c [23-Dec-1998]
1464
1465 *) Added OPENSSL_VERSION_NUMBER to crypto/crypto.h and
1466 changed SSLeay to OpenSSL in version strings.
1467 [Ralf S. Engelschall]
1468
1469 *) Some fixups to the top-level documents.
1470 [Paul Sutton]
1471
1472 *) Fixed the nasty bug where rsaref.h was not found under compile-time
1473 because the symlink to include/ was missing.
1474 [Ralf S. Engelschall]
1475
1476 *) Incorporated the popular no-RSA/DSA-only patches
1477 which allow to compile a RSA-free SSLeay.
1478 [Andrew Cooke / Interrader Ldt., Ralf S. Engelschall]
1479
1480 *) Fixed nasty rehash problem under `make -f Makefile.ssl links'
1481 when "ssleay" is still not found.
1482 [Ralf S. Engelschall]
1483
1484 *) Added more platforms to Configure: Cray T3E, HPUX 11,
1485 [Ralf S. Engelschall, Beckmann <beckman@acl.lanl.gov>]
1486
1487 *) Updated the README file.
1488 [Ralf S. Engelschall]
1489
1490 *) Added various .cvsignore files in the CVS repository subdirs
1491 to make a "cvs update" really silent.
1492 [Ralf S. Engelschall]
1493
1494 *) Recompiled the error-definition header files and added
1495 missing symbols to the Win32 linker tables.
1496 [Ralf S. Engelschall]
1497
1498 *) Cleaned up the top-level documents;
1499 o new files: CHANGES and LICENSE
1500 o merged VERSION, HISTORY* and README* files a CHANGES.SSLeay
1501 o merged COPYRIGHT into LICENSE
1502 o removed obsolete TODO file
1503 o renamed MICROSOFT to INSTALL.W32
1504 [Ralf S. Engelschall]
1505
1506 *) Removed dummy files from the 0.9.1b source tree:
1507 crypto/asn1/x crypto/bio/cd crypto/bio/fg crypto/bio/grep crypto/bio/vi
1508 crypto/bn/asm/......add.c crypto/bn/asm/a.out crypto/dsa/f crypto/md5/f
1509 crypto/pem/gmon.out crypto/perlasm/f crypto/pkcs7/build crypto/rsa/f
1510 crypto/sha/asm/f crypto/threads/f ms/zzz ssl/f ssl/f.mak test/f
1511 util/f.mak util/pl/f util/pl/f.mak crypto/bf/bf_locl.old apps/f
1512 [Ralf S. Engelschall]
1513
1514 *) Added various platform portability fixes.
1515 [Mark J. Cox]
1516
1517 *) The Genesis of the OpenSSL rpject:
1518 We start with the latest (unreleased) SSLeay version 0.9.1b which Eric A.
1519 Young and Tim J. Hudson created while they were working for C2Net until
1520 summer 1998.
1521 [The OpenSSL Project]
1522
1523
1524 Changes between 0.9.0b and 0.9.1b [not released]
1525
1526 *) Updated a few CA certificates under certs/
1527 [Eric A. Young]
1528
1529 *) Changed some BIGNUM api stuff.
1530 [Eric A. Young]
1531
1532 *) Various platform ports: OpenBSD, Ultrix, IRIX 64bit, NetBSD,
1533 DGUX x86, Linux Alpha, etc.
1534 [Eric A. Young]
1535
1536 *) New COMP library [crypto/comp/] for SSL Record Layer Compression:
1537 RLE (dummy implemented) and ZLIB (really implemented when ZLIB is
1538 available).
1539 [Eric A. Young]
1540
1541 *) Add -strparse option to asn1pars program which parses nested
1542 binary structures
1543 [Dr Stephen Henson <shenson@bigfoot.com>]
1544
1545 *) Added "oid_file" to ssleay.cnf for "ca" and "req" programs.
1546 [Eric A. Young]
1547
1548 *) DSA fix for "ca" program.
1549 [Eric A. Young]
1550
1551 *) Added "-genkey" option to "dsaparam" program.
1552 [Eric A. Young]
1553
1554 *) Added RIPE MD160 (rmd160) message digest.
1555 [Eric A. Young]
1556
1557 *) Added -a (all) option to "ssleay version" command.
1558 [Eric A. Young]
1559
1560 *) Added PLATFORM define which is the id given to Configure.
1561 [Eric A. Young]
1562
1563 *) Added MemCheck_XXXX functions to crypto/mem.c for memory checking.
1564 [Eric A. Young]
1565
1566 *) Extended the ASN.1 parser routines.
1567 [Eric A. Young]
1568
1569 *) Extended BIO routines to support REUSEADDR, seek, tell, etc.
1570 [Eric A. Young]
1571
1572 *) Added a BN_CTX to the BN library.
1573 [Eric A. Young]
1574
1575 *) Fixed the weak key values in DES library
1576 [Eric A. Young]
1577
1578 *) Changed API in EVP library for cipher aliases.
1579 [Eric A. Young]
1580
1581 *) Added support for RC2/64bit cipher.
1582 [Eric A. Young]
1583
1584 *) Converted the lhash library to the crypto/mem.c functions.
1585 [Eric A. Young]
1586
1587 *) Added more recognized ASN.1 object ids.
1588 [Eric A. Young]
1589
1590 *) Added more RSA padding checks for SSL/TLS.
1591 [Eric A. Young]
1592
1593 *) Added BIO proxy/filter functionality.
1594 [Eric A. Young]
1595
1596 *) Added extra_certs to SSL_CTX which can be used
1597 send extra CA certificates to the client in the CA cert chain sending
1598 process. It can be configured with SSL_CTX_add_extra_chain_cert().
1599 [Eric A. Young]
1600
1601 *) Now Fortezza is denied in the authentication phase because
1602 this is key exchange mechanism is not supported by SSLeay at all.
1603 [Eric A. Young]
1604
1605 *) Additional PKCS1 checks.
1606 [Eric A. Young]
1607
1608 *) Support the string "TLSv1" for all TLS v1 ciphers.
1609 [Eric A. Young]
1610
1611 *) Added function SSL_get_ex_data_X509_STORE_CTX_idx() which gives the
1612 ex_data index of the SSL context in the X509_STORE_CTX ex_data.
1613 [Eric A. Young]
1614
1615 *) Fixed a few memory leaks.
1616 [Eric A. Young]
1617
1618 *) Fixed various code and comment typos.
1619 [Eric A. Young]
1620
1621 *) A minor bug in ssl/s3_clnt.c where there would always be 4 0
1622 bytes sent in the client random.
1623 [Edward Bishop <ebishop@spyglass.com>]
1624
diff --git a/src/lib/libssl/src/CHANGES.SSLeay b/src/lib/libssl/src/CHANGES.SSLeay
new file mode 100644
index 0000000000..dbb80b003d
--- /dev/null
+++ b/src/lib/libssl/src/CHANGES.SSLeay
@@ -0,0 +1,968 @@
1This file contains the changes for the SSLeay library up to version
20.9.0b. For later changes, see the file "CHANGES".
3
4 SSLeay CHANGES
5 ______________
6
7Changes between 0.8.x and 0.9.0b
8
910-Apr-1998
10
11I said the next version would go out at easter, and so it shall.
12I expect a 0.9.1 will follow with portability fixes in the next few weeks.
13
14This is a quick, meet the deadline. Look to ssl-users for comments on what
15is new etc.
16
17eric (about to go bushwalking for the 4 day easter break :-)
18
1916-Mar-98
20 - Patch for Cray T90 from Wayne Schroeder <schroede@SDSC.EDU>
21 - Lots and lots of changes
22
2329-Jan-98
24 - ASN1_BIT_STRING_set_bit()/ASN1_BIT_STRING_get_bit() from
25 Goetz Babin-Ebell <babinebell@trustcenter.de>.
26 - SSL_version() now returns SSL2_VERSION, SSL3_VERSION or
27 TLS1_VERSION.
28
297-Jan-98
30 - Finally reworked the cipher string to ciphers again, so it
31 works correctly
32 - All the app_data stuff is now ex_data with funcion calls to access.
33 The index is supplied by a function and 'methods' can be setup
34 for the types that are called on XXX_new/XXX_free. This lets
35 applications get notified on creation and destruction. Some of
36 the RSA methods could be implemented this way and I may do so.
37 - Oh yes, SSL under perl5 is working at the basic level.
38
3915-Dec-97
40 - Warning - the gethostbyname cache is not fully thread safe,
41 but it should work well enough.
42 - Major internal reworking of the app_data stuff. More functions
43 but if you were accessing ->app_data directly, things will
44 stop working.
45 - The perlv5 stuff is working. Currently on message digests,
46 ciphers and the bignum library.
47
489-Dec-97
49 - Modified re-negotiation so that server initated re-neg
50 will cause a SSL_read() to return -1 should retry.
51 The danger otherwise was that the server and the
52 client could end up both trying to read when using non-blocking
53 sockets.
54
554-Dec-97
56 - Lots of small changes
57 - Fix for binaray mode in Windows for the FILE BIO, thanks to
58 Bob Denny <rdenny@dc3.com>
59
6017-Nov-97
61 - Quite a few internal cleanups, (removal of errno, and using macros
62 defined in e_os.h).
63 - A bug in ca.c, pointed out by yasuyuki-ito@d-cruise.co.jp, where
64 the automactic naming out output files was being stuffed up.
65
6629-Oct-97
67 - The Cast5 cipher has been added. MD5 and SHA-1 are now in assember
68 for x86.
69
7021-Oct-97
71 - Fixed a bug in the BIO_gethostbyname() cache.
72
7315-Oct-97
74 - cbc mode for blowfish/des/3des is now in assember. Blowfish asm
75 has also been improved. At this point in time, on the pentium,
76 md5 is %80 faster, the unoptimesed sha-1 is %79 faster,
77 des-cbc is %28 faster, des-ede3-cbc is %9 faster and blowfish-cbc
78 is %62 faster.
79
8012-Oct-97
81 - MEM_BUF_grow() has been fixed so that it always sets the buf->length
82 to the value we are 'growing' to. Think of MEM_BUF_grow() as the
83 way to set the length value correctly.
84
8510-Oct-97
86 - I now hash for certificate lookup on the raw DER encoded RDN (md5).
87 This breaks things again :-(. This is efficent since I cache
88 the DER encoding of the RDN.
89 - The text DN now puts in the numeric OID instead of UNKNOWN.
90 - req can now process arbitary OIDs in the config file.
91 - I've been implementing md5 in x86 asm, much faster :-).
92 - Started sha1 in x86 asm, needs more work.
93 - Quite a few speedups in the BN stuff. RSA public operation
94 has been made faster by caching the BN_MONT_CTX structure.
95 The calulating of the Ai where A*Ai === 1 mod m was rather
96 expensive. Basically a 40-50% speedup on public operations.
97 The RSA speedup is now 15% on pentiums and %20 on pentium
98 pro.
99
10030-Sep-97
101 - After doing some profiling, I added x86 adm for bn_add_words(),
102 which just adds 2 arrays of longs together. A %10 speedup
103 for 512 and 1024 bit RSA on the pentium pro.
104
10529-Sep-97
106 - Converted the x86 bignum assembler to us the perl scripts
107 for generation.
108
10923-Sep-97
110 - If SSL_set_session() is passed a NULL session, it now clears the
111 current session-id.
112
11322-Sep-97
114 - Added a '-ss_cert file' to apps/ca.c. This will sign selfsigned
115 certificates.
116 - Bug in crypto/evp/encode.c where by decoding of 65 base64
117 encoded lines, one line at a time (via a memory BIO) would report
118 EOF after the first line was decoded.
119 - Fix in X509_find_by_issuer_and_serial() from
120 Dr Stephen Henson <shenson@bigfoot.com>
121
12219-Sep-97
123 - NO_FP_API and NO_STDIO added.
124 - Put in sh config command. It auto runs Configure with the correct
125 parameters.
126
12718-Sep-97
128 - Fix x509.c so if a DSA cert has different parameters to its parent,
129 they are left in place. Not tested yet.
130
13116-Sep-97
132 - ssl_create_cipher_list() had some bugs, fixes from
133 Patrick Eisenacher <eisenach@stud.uni-frankfurt.de>
134 - Fixed a bug in the Base64 BIO, where it would return 1 instead
135 of -1 when end of input was encountered but should retry.
136 Basically a Base64/Memory BIO interaction problem.
137 - Added a HMAC set of functions in preporarion for TLS work.
138
13915-Sep-97
140 - Top level makefile tweak - Cameron Simpson <cs@zip.com.au>
141 - Prime generation spead up %25 (512 bit prime, pentium pro linux)
142 by using montgomery multiplication in the prime number test.
143
14411-Sep-97
145 - Ugly bug in ssl3_write_bytes(). Basically if application land
146 does a SSL_write(ssl,buf,len) where len > 16k, the SSLv3 write code
147 did not check the size and tried to copy the entire buffer.
148 This would tend to cause memory overwrites since SSLv3 has
149 a maximum packet size of 16k. If your program uses
150 buffers <= 16k, you would probably never see this problem.
151 - Fixed a new errors that were cause by malloc() not returning
152 0 initialised memory..
153 - SSL_OP_NETSCAPE_CA_DN_BUG was being switched on when using
154 SSL_CTX_set_options(ssl_ctx,SSL_OP_ALL); which was a bad thing
155 since this flags stops SSLeay being able to handle client
156 cert requests correctly.
157
15808-Sep-97
159 - SSL_SESS_CACHE_NO_INTERNAL_LOOKUP option added. When switched
160 on, the SSL server routines will not use a SSL_SESSION that is
161 held in it's cache. This in intended to be used with the session-id
162 callbacks so that while the session-ids are still stored in the
163 cache, the decision to use them and how to look them up can be
164 done by the callbacks. The are the 'new', 'get' and 'remove'
165 callbacks. This can be used to determine the session-id
166 to use depending on information like which port/host the connection
167 is coming from. Since the are also SSL_SESSION_set_app_data() and
168 SSL_SESSION_get_app_data() functions, the application can hold
169 information against the session-id as well.
170
17103-Sep-97
172 - Added lookup of CRLs to the by_dir method,
173 X509_load_crl_file() also added. Basically it means you can
174 lookup CRLs via the same system used to lookup certificates.
175 - Changed things so that the X509_NAME structure can contain
176 ASN.1 BIT_STRINGS which is required for the unique
177 identifier OID.
178 - Fixed some problems with the auto flushing of the session-id
179 cache. It was not occuring on the server side.
180
18102-Sep-97
182 - Added SSL_CTX_sess_cache_size(SSL_CTX *ctx,unsigned long size)
183 which is the maximum number of entries allowed in the
184 session-id cache. This is enforced with a simple FIFO list.
185 The default size is 20*1024 entries which is rather large :-).
186 The Timeout code is still always operating.
187
18801-Sep-97
189 - Added an argument to all the 'generate private key/prime`
190 callbacks. It is the last parameter so this should not
191 break existing code but it is needed for C++.
192 - Added the BIO_FLAGS_BASE64_NO_NL flag for the BIO_f_base64()
193 BIO. This lets the BIO read and write base64 encoded data
194 without inserting or looking for '\n' characters. The '-A'
195 flag turns this on when using apps/enc.c.
196 - RSA_NO_PADDING added to help BSAFE functionality. This is a
197 very dangerous thing to use, since RSA private key
198 operations without random padding bytes (as PKCS#1 adds) can
199 be attacked such that the private key can be revealed.
200 - ASN.1 bug and rc2-40-cbc and rc4-40 added by
201 Dr Stephen Henson <shenson@bigfoot.com>
202
20331-Aug-97 (stuff added while I was away)
204 - Linux pthreads by Tim Hudson (tjh@cryptsoft.com).
205 - RSA_flags() added allowing bypass of pub/priv match check
206 in ssl/ssl_rsa.c - Tim Hudson.
207 - A few minor bugs.
208
209SSLeay 0.8.1 released.
210
21119-Jul-97
212 - Server side initated dynamic renegotiation is broken. I will fix
213 it when I get back from holidays.
214
21515-Jul-97
216 - Quite a few small changes.
217 - INVALID_SOCKET usage cleanups from Alex Kiernan <alex@hisoft.co.uk>
218
21909-Jul-97
220 - Added 2 new values to the SSL info callback.
221 SSL_CB_START which is passed when the SSL protocol is started
222 and SSL_CB_DONE when it has finished sucsessfully.
223
22408-Jul-97
225 - Fixed a few bugs problems in apps/req.c and crypto/asn1/x_pkey.c
226 that related to DSA public/private keys.
227 - Added all the relevent PEM and normal IO functions to support
228 reading and writing RSAPublic keys.
229 - Changed makefiles to use ${AR} instead of 'ar r'
230
23107-Jul-97
232 - Error in ERR_remove_state() that would leave a dangling reference
233 to a free()ed location - thanks to Alex Kiernan <alex@hisoft.co.uk>
234 - s_client now prints the X509_NAMEs passed from the server
235 when requesting a client cert.
236 - Added a ssl->type, which is one of SSL_ST_CONNECT or
237 SSL_ST_ACCEPT. I had to add it so I could tell if I was
238 a connect or an accept after the handshake had finished.
239 - SSL_get_client_CA_list(SSL *s) now returns the CA names
240 passed by the server if called by a client side SSL.
241
24205-Jul-97
243 - Bug in X509_NAME_get_text_by_OBJ(), looking starting at index
244 0, not -1 :-( Fix from Tim Hudson (tjh@cryptsoft.com).
245
24604-Jul-97
247 - Fixed some things in X509_NAME_add_entry(), thanks to
248 Matthew Donald <matthew@world.net>.
249 - I had a look at the cipher section and though that it was a
250 bit confused, so I've changed it.
251 - I was not setting up the RC4-64-MD5 cipher correctly. It is
252 a MS special that appears in exported MS Money.
253 - Error in all my DH ciphers. Section 7.6.7.3 of the SSLv3
254 spec. I was missing the two byte length header for the
255 ClientDiffieHellmanPublic value. This is a packet sent from
256 the client to the server. The SSL_OP_SSLEAY_080_CLIENT_DH_BUG
257 option will enable SSLeay server side SSLv3 accept either
258 the correct or my 080 packet format.
259 - Fixed a few typos in crypto/pem.org.
260
26102-Jul-97
262 - Alias mapping for EVP_get_(digest|cipher)byname is now
263 performed before a lookup for actual cipher. This means
264 that an alias can be used to 're-direct' a cipher or a
265 digest.
266 - ASN1_read_bio() had a bug that only showed up when using a
267 memory BIO. When EOF is reached in the memory BIO, it is
268 reported as a -1 with BIO_should_retry() set to true.
269
27001-Jul-97
271 - Fixed an error in X509_verify_cert() caused by my
272 miss-understanding how 'do { contine } while(0);' works.
273 Thanks to Emil Sit <sit@mit.edu> for educating me :-)
274
27530-Jun-97
276 - Base64 decoding error. If the last data line did not end with
277 a '=', sometimes extra data would be returned.
278 - Another 'cut and paste' bug in x509.c related to setting up the
279 STDout BIO.
280
28127-Jun-97
282 - apps/ciphers.c was not printing due to an editing error.
283 - Alex Kiernan <alex@hisoft.co.uk> send in a nice fix for
284 a library build error in util/mk1mf.pl
285
28626-Jun-97
287 - Still did not have the auto 'experimental' code removal
288 script correct.
289 - A few header tweaks for Watcom 11.0 under Win32 from
290 Rolf Lindemann <Lindemann@maz-hh.de>
291 - 0 length OCTET_STRING bug in asn1_parse
292 - A minor fix with an non-existent function in the MS .def files.
293 - A few changes to the PKCS7 stuff.
294
29525-Jun-97
296 SSLeay 0.8.0 finally it gets released.
297
29824-Jun-97
299 Added a SSL_OP_EPHEMERAL_RSA option which causes all SSLv3 RSA keys to
300 use a temporary RSA key. This is experimental and needs some more work.
301 Fixed a few Win16 build problems.
302
30323-Jun-97
304 SSLv3 bug. I was not doing the 'lookup' of the CERT structure
305 correctly. I was taking the SSL->ctx->default_cert when I should
306 have been using SSL->cert. The bug was in ssl/s3_srvr.c
307
30820-Jun-97
309 X509_ATTRIBUTES were being encoded wrongly by apps/reg.c and the
310 rest of the library. Even though I had the code required to do
311 it correctly, apps/req.c was doing the wrong thing. I have fixed
312 and tested everything.
313
314 Missing a few #ifdef FIONBIO sections in crypto/bio/bss_acpt.c.
315
31619-Jun-97
317 Fixed a bug in the SSLv2 server side first packet handling. When
318 using the non-blocking test BIO, the ssl->s2->first_packet flag
319 was being reset when a would-block failure occurred when reading
320 the first 5 bytes of the first packet. This caused the checking
321 logic to run at the wrong time and cause an error.
322
323 Fixed a problem with specifying cipher. If RC4-MD5 were used,
324 only the SSLv3 version would be picked up. Now this will pick
325 up both SSLv2 and SSLv3 versions. This required changing the
326 SSL_CIPHER->mask values so that they only mask the ciphers,
327 digests, authentication, export type and key-exchange algorithms.
328
329 I found that when a SSLv23 session is established, a reused
330 session, of type SSLv3 was attempting to write the SSLv2
331 ciphers, which were invalid. The SSL_METHOD->put_cipher_by_char
332 method has been modified so it will only write out cipher which
333 that method knows about.
334
335
336 Changes between 0.8.0 and 0.8.1
337
338 *) Mostly bug fixes.
339 There is an Ephemeral DH cipher problem which is fixed.
340
341 SSLeay 0.8.0
342
343This version of SSLeay has quite a lot of things different from the
344previous version.
345
346Basically check all callback parameters, I will be producing documentation
347about how to use things in th future. Currently I'm just getting 080 out
348the door. Please not that there are several ways to do everything, and
349most of the applications in the apps directory are hybrids, some using old
350methods and some using new methods.
351
352Have a look in demos/bio for some very simple programs and
353apps/s_client.c and apps/s_server.c for some more advanced versions.
354Notes are definitly needed but they are a week or so away.
355
356Anyway, some quick nots from Tim Hudson (tjh@cryptsoft.com)
357---
358Quick porting notes for moving from SSLeay-0.6.x to SSLeay-0.8.x to
359get those people that want to move to using the new code base off to
360a quick start.
361
362Note that Eric has tidied up a lot of the areas of the API that were
363less than desirable and renamed quite a few things (as he had to break
364the API in lots of places anyrate). There are a whole pile of additional
365functions for making dealing with (and creating) certificates a lot
366cleaner.
367
36801-Jul-97
369Tim Hudson
370tjh@cryptsoft.com
371
372---8<---
373
374To maintain code that uses both SSLeay-0.6.x and SSLeay-0.8.x you could
375use something like the following (assuming you #include "crypto.h" which
376is something that you really should be doing).
377
378#if SSLEAY_VERSION_NUMBER >= 0x0800
379#define SSLEAY8
380#endif
381
382buffer.h -> splits into buffer.h and bio.h so you need to include bio.h
383 too if you are working with BIO internal stuff (as distinct
384 from simply using the interface in an opaque manner)
385
386#include "bio.h" - required along with "buffer.h" if you write
387 your own BIO routines as the buffer and bio
388 stuff that was intermixed has been separated
389 out
390
391envelope.h -> evp.h (which should have been done ages ago)
392
393Initialisation ... don't forget these or you end up with code that
394is missing the bits required to do useful things (like ciphers):
395
396SSLeay_add_ssl_algorithms()
397(probably also want SSL_load_error_strings() too but you should have
398 already had that call in place)
399
400SSL_CTX_new() - requires an extra method parameter
401 SSL_CTX_new(SSLv23_method())
402 SSL_CTX_new(SSLv2_method())
403 SSL_CTX_new(SSLv3_method())
404
405 OR to only have the server or the client code
406 SSL_CTX_new(SSLv23_server_method())
407 SSL_CTX_new(SSLv2_server_method())
408 SSL_CTX_new(SSLv3_server_method())
409 or
410 SSL_CTX_new(SSLv23_client_method())
411 SSL_CTX_new(SSLv2_client_method())
412 SSL_CTX_new(SSLv3_client_method())
413
414SSL_set_default_verify_paths() ... renamed to the more appropriate
415SSL_CTX_set_default_verify_paths()
416
417If you want to use client certificates then you have to add in a bit
418of extra stuff in that a SSLv3 server sends a list of those CAs that
419it will accept certificates from ... so you have to provide a list to
420SSLeay otherwise certain browsers will not send client certs.
421
422SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(s_cert_file));
423
424
425X509_NAME_oneline(X) -> X509_NAME_oneline(X,NULL,0)
426 or provide a buffer and size to copy the
427 result into
428
429X509_add_cert -> X509_STORE_add_cert (and you might want to read the
430 notes on X509_NAME structure changes too)
431
432
433VERIFICATION CODE
434=================
435
436The codes have all be renamed from VERIFY_ERR_* to X509_V_ERR_* to
437more accurately reflect things.
438
439The verification callback args are now packaged differently so that
440extra fields for verification can be added easily in future without
441having to break things by adding extra parameters each release :-)
442
443X509_cert_verify_error_string -> X509_verify_cert_error_string
444
445
446BIO INTERNALS
447=============
448
449Eric has fixed things so that extra flags can be introduced in
450the BIO layer in future without having to play with all the BIO
451modules by adding in some macros.
452
453The ugly stuff using
454 b->flags ~= (BIO_FLAGS_RW|BIO_FLAGS_SHOULD_RETRY)
455becomes
456 BIO_clear_retry_flags(b)
457
458 b->flags |= (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)
459becomes
460 BIO_set_retry_read(b)
461
462Also ... BIO_get_retry_flags(b), BIO_set_flags(b)
463
464
465
466OTHER THINGS
467============
468
469X509_NAME has been altered so that it isn't just a STACK ... the STACK
470is now in the "entries" field ... and there are a pile of nice functions
471for getting at the details in a much cleaner manner.
472
473SSL_CTX has been altered ... "cert" is no longer a direct member of this
474structure ... things are now down under "cert_store" (see x509_vfy.h) and
475things are no longer in a CERTIFICATE_CTX but instead in a X509_STORE.
476If your code "knows" about this level of detail then it will need some
477surgery.
478
479If you depending on the incorrect spelling of a number of the error codes
480then you will have to change your code as these have been fixed.
481
482ENV_CIPHER "type" got renamed to "nid" and as that is what it actually
483has been all along so this makes things clearer.
484ify_cert_error_string(ctx->error));
485
486SSL_R_NO_CIPHER_WE_TRUST -> SSL_R_NO_CIPHER_LIST
487 and SSL_R_REUSE_CIPHER_LIST_NOT_ZERO
488
489
490
491 Changes between 0.7.x and 0.8.0
492
493 *) There have been lots of changes, mostly the addition of SSLv3.
494 There have been many additions from people and amongst
495 others, C2Net has assisted greatly.
496
497 Changes between 0.7.x and 0.7.x
498
499 *) Internal development version only
500
501SSLeay 0.6.6 13-Jan-1997
502
503The main additions are
504
505- assember for x86 DES improvments.
506 From 191,000 per second on a pentium 100, I now get 281,000. The inner
507 loop and the IP/FP modifications are from
508 Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. Many thanks for his
509 contribution.
510- The 'DES macros' introduced in 0.6.5 now have 3 types.
511 DES_PTR1, DES_PTR2 and 'normal'. As per before, des_opts reports which
512 is best and there is a summery of mine in crypto/des/options.txt
513- A few bug fixes.
514- Added blowfish. It is not used by SSL but all the other stuff that
515 deals with ciphers can use it in either ecb, cbc, cfb64 or ofb64 modes.
516 There are 3 options for optimising Blowfish. BF_PTR, BF_PTR2 and 'normal'.
517 BF_PTR2 is pentium/x86 specific. The correct option is setup in
518 the 'Configure' script.
519- There is now a 'get client certificate' callback which can be
520 'non-blocking'. If more details are required, let me know. It will
521 documented more in SSLv3 when I finish it.
522- Bug fixes from 0.6.5 including the infamous 'ca' bug. The 'make test'
523 now tests the ca program.
524- Lots of little things modified and tweaked.
525
526 SSLeay 0.6.5
527
528After quite some time (3 months), the new release. I have been very busy
529for the last few months and so this is mostly bug fixes and improvments.
530
531The main additions are
532
533- assember for x86 DES. For all those gcc based systems, this is a big
534 improvement. From 117,000 DES operation a second on a pentium 100,
535 I now get 191,000. I have also reworked the C version so it
536 now gives 148,000 DESs per second.
537- As mentioned above, the inner DES macros now have some more variant that
538 sometimes help, sometimes hinder performance. There are now 3 options
539 DES_PTR (ptr vs array lookup), DES_UNROLL (full vs partial loop unrolling)
540 and DES_RISC (a more register intensive version of the inner macro).
541 The crypto/des/des_opts.c program, when compiled and run, will give
542 an indication of the correct options to use.
543- The BIO stuff has been improved. Read doc/bio.doc. There are now
544 modules for encryption and base64 encoding and a BIO_printf() function.
545- The CA program will accept simple one line X509v3 extensions in the
546 ssleay.cnf file. Have a look at the example. Currently this just
547 puts the text into the certificate as an OCTET_STRING so currently
548 the more advanced X509v3 data types are not handled but this is enough
549 for the netscape extensions.
550- There is the start of a nicer higher level interface to the X509
551 strucutre.
552- Quite a lot of bug fixes.
553- CRYPTO_malloc_init() (or CRYPTO_set_mem_functions()) can be used
554 to define the malloc(), free() and realloc() routines to use
555 (look in crypto/crypto.h). This is mostly needed for Windows NT/95 when
556 using DLLs and mixing CRT libraries.
557
558In general, read the 'VERSION' file for changes and be aware that some of
559the new stuff may not have been tested quite enough yet, so don't just plonk
560in SSLeay 0.6.5 when 0.6.4 used to work and expect nothing to break.
561
562SSLeay 0.6.4 30/08/96 eay
563
564I've just finished some test builds on Windows NT, Windows 3.1, Solaris 2.3,
565Solaris 2.5, Linux, IRIX, HPUX 10 and everthing seems to work :-).
566
567The main changes in this release
568
569- Thread safe. have a read of doc/threads.doc and play in the mt directory.
570 For anyone using 0.6.3 with threads, I found 2 major errors so consider
571 moving to 0.6.4. I have a test program that builds under NT and
572 solaris.
573- The get session-id callback has changed. Have a read of doc/callback.doc.
574- The X509_cert_verify callback (the SSL_verify callback) now
575 has another argument. Have a read of doc/callback.doc
576- 'ca -preserve', sign without re-ordering the DN. Not tested much.
577- VMS support.
578- Compile time memory leak detection can now be built into SSLeay.
579 Read doc/memory.doc
580- CONF routines now understand '\', '\n', '\r' etc. What this means is that
581 the SPKAC object mentioned in doc/ns-ca.doc can be on multiple lines.
582- 'ssleay ciphers' added, lists the default cipher list for SSLeay.
583- RC2 key setup is now compatable with Netscape.
584- Modifed server side of SSL implementation, big performance difference when
585 using session-id reuse.
586
5870.6.3
588
589Bug fixes and the addition of some nice stuff to the 'ca' program.
590Have a read of doc/ns-ca.doc for how hit has been modified so
591it can be driven from a CGI script. The CGI script is not provided,
592but that is just being left as an excersize for the reader :-).
593
5940.6.2
595
596This is most bug fixes and functionality improvements.
597
598Additions are
599- More thread debugging patches, the thread stuff is still being
600 tested, but for those keep to play with stuff, have a look in
601 crypto/cryptlib.c. The application needs to define 1 (or optionaly
602 a second) callback that is used to implement locking. Compiling
603 with LOCK_DEBUG spits out lots of locking crud :-).
604 This is what I'm currently working on.
605- SSL_CTX_set_default_passwd_cb() can be used to define the callback
606 function used in the SSL*_file() functions used to load keys. I was
607 always of the opinion that people should call
608 PEM_read_RSAPrivateKey() and pass the callback they want to use, but
609 it appears they just want to use the SSL_*_file() function() :-(.
610- 'enc' now has a -kfile so a key can be read from a file. This is
611 mostly used so that the passwd does not appear when using 'ps',
612 which appears imposible to stop under solaris.
613- X509v3 certificates now work correctly. I even have more examples
614 in my tests :-). There is now a X509_EXTENSION type that is used in
615 X509v3 certificates and CRLv2.
616- Fixed that signature type error :-(
617- Fixed quite a few potential memory leaks and problems when reusing
618 X509, CRL and REQ structures.
619- EVP_set_pw_prompt() now sets the library wide default password
620 prompt.
621- The 'pkcs7' command will now, given the -print_certs flag, output in
622 pem format, all certificates and CRL contained within. This is more
623 of a pre-emtive thing for the new verisign distribution method. I
624 should also note, that this also gives and example in code, of how
625 to do this :-), or for that matter, what is involved in going the
626 other way (list of certs and crl -> pkcs7).
627- Added RSA's DESX to the DES library. It is also available via the
628 EVP_desx_cbc() method and via 'enc desx'.
629
630SSLeay 0.6.1
631
632The main functional changes since 0.6.0 are as follows
633- Bad news, the Microsoft 060 DLL's are not compatable, but the good news is
634 that from now on, I'll keep the .def numbers the same so they will be.
635- RSA private key operations are about 2 times faster that 0.6.0
636- The SSL_CTX now has more fields so default values can be put against
637 it. When an SSL structure is created, these default values are used
638 but can be overwritten. There are defaults for cipher, certificate,
639 private key, verify mode and callback. This means SSL session
640 creation can now be
641 ssl=SSL_new()
642 SSL_set_fd(ssl,sock);
643 SSL_accept(ssl)
644 ....
645 All the other uglyness with having to keep a global copy of the
646 private key and certificate/verify mode in the server is now gone.
647- ssl/ssltest.c - one process talking SSL to its self for testing.
648- Storage of Session-id's can be controled via a session_cache_mode
649 flag. There is also now an automatic default flushing of
650 old session-id's.
651- The X509_cert_verify() function now has another parameter, this
652 should not effect most people but it now means that the reason for
653 the failure to verify is now available via SSL_get_verify_result(ssl).
654 You don't have to use a global variable.
655- SSL_get_app_data() and SSL_set_app_data() can be used to keep some
656 application data against the SSL structure. It is upto the application
657 to free the data. I don't use it, but it is available.
658- SSL_CTX_set_cert_verify_callback() can be used to specify a
659 verify callback function that completly replaces my certificate
660 verification code. Xcert should be able to use this :-).
661 The callback is of the form int app_verify_callback(arg,ssl,cert).
662 This needs to be documented more.
663- I have started playing with shared library builds, have a look in
664 the shlib directory. It is very simple. If you need a numbered
665 list of functions, have a look at misc/crypto.num and misc/ssl.num.
666- There is some stuff to do locking to make the library thread safe.
667 I have only started this stuff and have not finished. If anyone is
668 keen to do so, please send me the patches when finished.
669
670So I have finally made most of the additions to the SSL interface that
671I thought were needed.
672
673There will probably be a pause before I make any non-bug/documentation
674related changes to SSLeay since I'm feeling like a bit of a break.
675
676eric - 12 Jul 1996
677I saw recently a comment by some-one that we now seem to be entering
678the age of perpetual Beta software.
679Pioneered by packages like linux but refined to an art form by
680netscape.
681
682I too wish to join this trend with the anouncement of SSLeay 0.6.0 :-).
683
684There are quite a large number of sections that are 'works in
685progress' in this package. I will also list the major changes and
686what files you should read.
687
688BIO - this is the new IO structure being used everywhere in SSLeay. I
689started out developing this because of microsoft, I wanted a mechanism
690to callback to the application for all IO, so Windows 3.1 DLL
691perversion could be hidden from me and the 15 different ways to write
692to a file under NT would also not be dictated by me at library build
693time. What the 'package' is is an API for a data structure containing
694functions. IO interfaces can be written to conform to the
695specification. This in not intended to hide the underlying data type
696from the application, but to hide it from SSLeay :-).
697I have only really finished testing the FILE * and socket/fd modules.
698There are also 'filter' BIO's. Currently I have only implemented
699message digests, and it is in use in the dgst application. This
700functionality will allow base64/encrypto/buffering modules to be
701'push' into a BIO without it affecting the semantics. I'm also
702working on an SSL BIO which will hide the SSL_accept()/SLL_connet()
703from an event loop which uses the interface.
704It is also possible to 'attach' callbacks to a BIO so they get called
705before and after each operation, alowing extensive debug output
706to be generated (try running dgst with -d).
707
708Unfortunaly in the conversion from 0.5.x to 0.6.0, quite a few
709functions that used to take FILE *, now take BIO *.
710The wrappers are easy to write
711
712function_fp(fp,x)
713FILE *fp;
714 {
715 BIO *b;
716 int ret;
717
718 if ((b=BIO_new(BIO_s_file())) == NULL) error.....
719 BIO_set_fp(b,fp,BIO_NOCLOSE);
720 ret=function_bio(b,x);
721 BIO_free(b);
722 return(ret);
723 }
724Remember, there are no functions that take FILE * in SSLeay when
725compiled for Windows 3.1 DLL's.
726
727--
728I have added a general EVP_PKEY type that can hold a public/private
729key. This is now what is used by the EVP_ functions and is passed
730around internally. I still have not done the PKCS#8 stuff, but
731X509_PKEY is defined and waiting :-)
732
733--
734For a full function name listings, have a look at ms/crypt32.def and
735ms/ssl32.def. These are auto-generated but are complete.
736Things like ASN1_INTEGER_get() have been added and are in here if you
737look. I have renamed a few things, again, have a look through the
738function list and you will probably find what you are after. I intend
739to at least put a one line descrition for each one.....
740
741--
742Microsoft - thats what this release is about, read the MICROSOFT file.
743
744--
745Multi-threading support. I have started hunting through the code and
746flaging where things need to be done. In a state of work but high on
747the list.
748
749--
750For random numbers, edit e_os.h and set DEVRANDOM (it's near the top)
751be be you random data device, otherwise 'RFILE' in e_os.h
752will be used, in your home directory. It will be updated
753periodically. The environment variable RANDFILE will override this
754choice and read/write to that file instead. DEVRANDOM is used in
755conjunction to the RFILE/RANDFILE. If you wish to 'seed' the random
756number generator, pick on one of these files.
757
758--
759
760The list of things to read and do
761
762dgst -d
763s_client -state (this uses a callback placed in the SSL state loop and
764 will be used else-where to help debug/monitor what
765 is happening.)
766
767doc/why.doc
768doc/bio.doc <- hmmm, needs lots of work.
769doc/bss_file.doc <- one that is working :-)
770doc/session.doc <- it has changed
771doc/speed.doc
772 also play with ssleay version -a. I have now added a SSLeay()
773 function that returns a version number, eg 0600 for this release
774 which is primarily to be used to check DLL version against the
775 application.
776util/* Quite a few will not interest people, but some may, like
777 mk1mf.pl, mkdef.pl,
778util/do_ms.sh
779
780try
781cc -Iinclude -Icrypto -c crypto/crypto.c
782cc -Iinclude -Issl -c ssl/ssl.c
783You have just built the SSLeay libraries as 2 object files :-)
784
785Have a general rummage around in the bin stall directory and look at
786what is in there, like CA.sh and c_rehash
787
788There are lots more things but it is 12:30am on a Friday night and I'm
789heading home :-).
790
791eric 22-Jun-1996
792This version has quite a few major bug fixes and improvements. It DOES NOT
793do SSLv3 yet.
794
795The main things changed
796- A Few days ago I added the s_mult application to ssleay which is
797 a demo of an SSL server running in an event loop type thing.
798 It supports non-blocking IO, I have finally gotten it right, SSL_accept()
799 can operate in non-blocking IO mode, look at the code to see how :-).
800 Have a read of doc/s_mult as well. This program leaks memory and
801 file descriptors everywhere but I have not cleaned it up yet.
802 This is a demo of how to do non-blocking IO.
803- The SSL session management has been 'worked over' and there is now
804 quite an expansive set of functions to manipulate them. Have a read of
805 doc/session.doc for some-things I quickly whipped up about how it now works.
806 This assume you know the SSLv2 protocol :-)
807- I can now read/write the netscape certificate format, use the
808 -inform/-outform 'net' options to the x509 command. I have not put support
809 for this type in the other demo programs, but it would be easy to add.
810- asn1parse and 'enc' have been modified so that when reading base64
811 encoded files (pem format), they do not require '-----BEGIN' header lines.
812 The 'enc' program had a buffering bug fixed, it can be used as a general
813 base64 -> binary -> base64 filter by doing 'enc -a -e' and 'enc -a -d'
814 respecivly. Leaving out the '-a' flag in this case makes the 'enc' command
815 into a form of 'cat'.
816- The 'x509' and 'req' programs have been fixed and modified a little so
817 that they generate self-signed certificates correctly. The test
818 script actually generates a 'CA' certificate and then 'signs' a
819 'user' certificate. Have a look at this shell script (test/sstest)
820 to see how things work, it tests most possible combinations of what can
821 be done.
822- The 'SSL_set_pref_cipher()' function has been 'fixed' and the prefered name
823 of SSL_set_cipher_list() is now the correct API (stops confusion :-).
824 If this function is used in the client, only the specified ciphers can
825 be used, with preference given to the order the ciphers were listed.
826 For the server, if this is used, only the specified ciphers will be used
827 to accept connections. If this 'option' is not used, a default set of
828 ciphers will be used. The SSL_CTX_set_cipher_list(SSL_CTX *ctx) sets this
829 list for all ciphers started against the SSL_CTX. So the order is
830 SSL cipher_list, if not present, SSL_CTX cipher list, if not
831 present, then the library default.
832 What this means is that normally ciphers like
833 NULL-MD5 will never be used. The only way this cipher can be used
834 for both ends to specify to use it.
835 To enable or disable ciphers in the library at build time, modify the
836 first field for the cipher in the ssl_ciphers array in ssl/ssl_lib.c.
837 This file also contains the 'pref_cipher' list which is the default
838 cipher preference order.
839- I'm not currently sure if the 'rsa -inform net' and the 'rsa -outform net'
840 options work. They should, and they enable loading and writing the
841 netscape rsa private key format. I will be re-working this section of
842 SSLeay for the next version. What is currently in place is a quick and
843 dirty hack.
844- I've re-written parts of the bignum library. This gives speedups
845 for all platforms. I now provide assembler for use under Windows NT.
846 I have not tested the Windows 3.1 assembler but it is quite simple code.
847 This gives RSAprivate_key operation encryption times of 0.047s (512bit key)
848 and 0.230s (1024bit key) on a pentium 100 which I consider reasonable.
849 Basically the times available under linux/solaris x86 can be achieve under
850 Windows NT. I still don't know how these times compare to RSA's BSAFE
851 library but I have been emailing with people and with their help, I should
852 be able to get my library's quite a bit faster still (more algorithm changes).
853 The object file crypto/bn/asm/x86-32.obj should be used when linking
854 under NT.
855- 'make makefile.one' in the top directory will generate a single makefile
856 called 'makefile.one' This makefile contains no perl references and
857 will build the SSLeay library into the 'tmp' and 'out' directories.
858 util/mk1mf.pl >makefile.one is how this makefile is
859 generated. The mk1mf.pl command take several option to generate the
860 makefile for use with cc, gcc, Visual C++ and Borland C++. This is
861 still under development. I have only build .lib's for NT and MSDOS
862 I will be working on this more. I still need to play with the
863 correct compiler setups for these compilers and add some more stuff but
864 basically if you just want to compile the library
865 on a 'non-unix' platform, this is a very very good file to start with :-).
866 Have a look in the 'microsoft' directory for my current makefiles.
867 I have not yet modified things to link with sockets under Windows NT.
868 You guys should be able to do this since this is actually outside of the
869 SSLeay scope :-). I will be doing it for myself soon.
870 util/mk1mf.pl takes quite a few options including no-rc, rsaref and no-sock
871 to build without RC2/RC4, to require RSAref for linking, and to
872 build with no socket code.
873
874- Oh yes, the cipher that was reported to be compatible with RSA's RC2 cipher
875 that was posted to sci.crypt has been added to the library and SSL.
876 I take the view that if RC2 is going to be included in a standard,
877 I'll include the cipher to make my package complete.
878 There are NO_RC2, NO_RC4 and NO_IDEA macros to remove these ciphers
879 at compile time. I have not tested this recently but it should all work
880 and if you are in the USA and don't want RSA threatening to sue you,
881 you could probably remove the RC4/RC2 code inside these sections.
882 I may in the future include a perl script that does this code
883 removal automatically for those in the USA :-).
884- I have removed all references to sed in the makefiles. So basically,
885 the development environment requires perl and sh. The build environment
886 does not (use the makefile.one makefile).
887 The Configure script still requires perl, this will probably stay that way
888 since I have perl for Windows NT :-).
889
890eric (03-May-1996)
891
892PS Have a look in the VERSION file for more details on the changes and
893 bug fixes.
894I have fixed a few bugs, added alpha and x86 assembler and generally cleaned
895things up. This version will be quite stable, mostly because I'm on
896holidays until 10-March-1996. For any problems in the interum, send email
897to Tim Hudson <tjh@mincom.oz.au>.
898
899SSLeay 0.5.0
900
90112-12-95
902This is going out before it should really be released.
903
904I leave for 11 weeks holidays on the 22-12-95 and so I either sit on
905this for 11 weeks or get things out. It is still going to change a
906lot in the next week so if you do grab this version, please test and
907give me feed back ASAP, inculuding questions on how to do things with
908the library. This will prompt me to write documentation so I don't
909have to answer the same question again :-).
910
911This 'pre' release version is for people who are interested in the
912library. The applications will have to be changed to use
913the new version of the SSL interface. I intend to finish more
914documentation before I leave but until then, look at the programs in
915the apps directory. As far as code goes, it is much much nicer than
916the old version.
917
918The current library works, has no memory leaks (as far as I can tell)
919and is far more bug free that 0.4.5d. There are no global variable of
920consequence (I believe) and I will produce some documentation that
921tell where to look for those people that do want to do multi-threaded
922stuff.
923
924There should be more documentation. Have a look in the
925doc directory. I'll be adding more before I leave, it is a start
926by mostly documents the crypto library. Tim Hudson will update
927the web page ASAP. The spelling and grammar are crap but
928it is better than nothing :-)
929
930Reasons to start playing with version 0.5.0
931- All the programs in the apps directory build into one ssleay binary.
932- There is a new version of the 'req' program that generates certificate
933 requests, there is even documentation for this one :-)
934- There is a demo certification authorithy program. Currently it will
935 look at the simple database and update it. It will generate CRL from
936 the data base. You need to edit the database by hand to revoke a
937 certificate, it is my aim to use perl5/Tk but I don't have time to do
938 this right now. It will generate the certificates but the management
939 scripts still need to be written. This is not a hard task.
940- Things have been cleaned up alot.
941- Have a look at the enc and dgst programs in the apps directory.
942- It supports v3 of x509 certiticates.
943
944
945Major things missing.
946- I have been working on (and thinging about) the distributed x509
947 hierachy problem. I have not had time to put my solution in place.
948 It will have to wait until I come back.
949- I have not put in CRL checking in the certificate verification but
950 it would not be hard to do. I was waiting until I could generate my
951 own CRL (which has only been in the last week) and I don't have time
952 to put it in correctly.
953- Montgomery multiplication need to be implemented. I know the
954 algorithm, just ran out of time.
955- PKCS#7. I can load and write the DER version. I need to re-work
956 things to support BER (if that means nothing, read the ASN1 spec :-).
957- Testing of the higher level digital envelope routines. I have not
958 played with the *_seal() and *_open() type functions. They are
959 written but need testing. The *_sign() and *_verify() functions are
960 rock solid.
961- PEM. Doing this and PKCS#7 have been dependant on the distributed
962 x509 heirachy problem. I started implementing my ideas, got
963 distracted writing a CA program and then ran out of time. I provide
964 the functionality of RSAref at least.
965- Re work the asm. code for the x86. I've changed by low level bignum
966 interface again, so I really need to tweak the x86 stuff. gcc is
967 good enough for the other boxes.
968
diff --git a/src/lib/libssl/src/FAQ b/src/lib/libssl/src/FAQ
new file mode 100644
index 0000000000..ab84a3f9e8
--- /dev/null
+++ b/src/lib/libssl/src/FAQ
@@ -0,0 +1,130 @@
1OpenSSL - Frequently Asked Questions
2--------------------------------------
3
4* Which is the current version of OpenSSL?
5* Where is the documentation?
6* How can I contact the OpenSSL developers?
7* Do I need patent licenses to use OpenSSL?
8* Is OpenSSL thread-safe?
9* Why do I get a "PRNG not seeded" error message?
10* Why does the linker complain about undefined symbols?
11* Where can I get a compiled version of OpenSSL?
12
13
14* Which is the current version of OpenSSL?
15
16The current version is available from <URL: http://www.openssl.org>.
17OpenSSL 0.9.5 was released on February 28th, 2000.
18
19In addition to the current stable release, you can also access daily
20snapshots of the OpenSSL development version at <URL:
21ftp://ftp.openssl.org/snapshot/>, or get it by anonymous CVS access.
22
23
24* Where is the documentation?
25
26OpenSSL is a library that provides cryptographic functionality to
27applications such as secure web servers. Be sure to read the
28documentation of the application you want to use. The INSTALL file
29explains how to install this library.
30
31OpenSSL includes a command line utility that can be used to perform a
32variety of cryptographic functions. It is described in the openssl(1)
33manpage. Documentation for developers is currently being written. A
34few manual pages already are available; overviews over libcrypto and
35libssl are given in the crypto(3) and ssl(3) manpages.
36
37The OpenSSL manpages are installed in /usr/local/ssl/man/ (or a
38different directory if you specified one as described in INSTALL).
39In addition, you can read the most current versions at
40<URL: http://www.openssl.org/docs/>.
41
42For information on parts of libcrypto that are not yet documented, you
43might want to read Ariel Glenn's documentation on SSLeay 0.9, OpenSSL's
44predecessor, at <URL: http://www.columbia.edu/~ariel/ssleay/>. Much
45of this still applies to OpenSSL.
46
47There is some documentation about certificate extensions and PKCS#12
48in doc/openssl.txt
49
50The original SSLeay documentation is included in OpenSSL as
51doc/ssleay.txt. It may be useful when none of the other resources
52help, but please note that it reflects the obsolete version SSLeay
530.6.6.
54
55
56* How can I contact the OpenSSL developers?
57
58The README file describes how to submit bug reports and patches to
59OpenSSL. Information on the OpenSSL mailing lists is available from
60<URL: http://www.openssl.org>.
61
62
63* Do I need patent licenses to use OpenSSL?
64
65The patents section of the README file lists patents that may apply to
66you if you want to use OpenSSL. For information on intellectual
67property rights, please consult a lawyer. The OpenSSL team does not
68offer legal advice.
69
70You can configure OpenSSL so as not to use RC5 and IDEA by using
71 ./config no-rc5 no-idea
72
73Until the RSA patent expires, U.S. users may want to use
74 ./config no-rc5 no-idea no-rsa
75
76Please note that you will *not* be able to communicate with most of
77the popular web browsers without RSA support.
78
79
80* Is OpenSSL thread-safe?
81
82Yes. On Windows and many Unix systems, OpenSSL automatically uses the
83multi-threaded versions of the standard libraries. If your platform
84is not one of these, consult the INSTALL file.
85
86Multi-threaded applications must provide two callback functions to
87OpenSSL. This is described in the threads(3) manpage.
88
89
90* Why do I get a "PRNG not seeded" error message?
91
92Cryptographic software needs a source of unpredictable data to work
93correctly. Many open source operating systems provide a "randomness
94device" that serves this purpose. On other systems, applications have
95to call the RAND_add() or RAND_seed() function with appropriate data
96before generating keys or performing public key encryption.
97
98Some broken applications do not do this. As of version 0.9.5, the
99OpenSSL functions that need randomness report an error if the random
100number generator has not been seeded with at least 128 bits of
101randomness. If this error occurs, please contact the author of the
102application you are using. It is likely that it never worked
103correctly. OpenSSL 0.9.5 makes the error visible by refusing to
104perform potentially insecure encryption.
105
106
107* Why does the linker complain about undefined symbols?
108
109Maybe the compilation was interrupted, and make doesn't notice that
110something is missing. Run "make clean; make".
111
112If you used ./Configure instead of ./config, make sure that you
113selected the right target. File formats may differ slightly between
114OS versions (for example sparcv8/sparcv9, or a.out/elf).
115
116If that doesn't help, you may want to try using the current snapshot.
117If the problem persists, please submit a bug report.
118
119
120* Where can I get a compiled version of OpenSSL?
121
122Some applications that use OpenSSL are distributed in binary form.
123When using such an application, you don't need to install OpenSSL
124yourself; the application will include the required parts (e.g. DLLs).
125
126If you want to install OpenSSL on a Windows system and you don't have
127a C compiler, read the "Mingw32" section of INSTALL.W32 for information
128on how to obtain and install the free GNU C compiler.
129
130A number of Linux and *BSD distributions include OpenSSL.
diff --git a/src/lib/libssl/src/INSTALL.MacOS b/src/lib/libssl/src/INSTALL.MacOS
new file mode 100644
index 0000000000..a8c4f7f1da
--- /dev/null
+++ b/src/lib/libssl/src/INSTALL.MacOS
@@ -0,0 +1,72 @@
1OpenSSL - Port To The Macintosh
2===============================
3
4Thanks to Roy Wood <roy@centricsystems.ca> initial support for MacOS (pre
5X) is now provided. "Initial" means that unlike other platforms where you
6get an SDK and a "swiss army" openssl application, on Macintosh you only
7get one sample application which fetches a page over HTTPS(*) and dumps it
8in a window. We don't even build the test applications so that we can't
9guarantee that all algorithms are operational.
10
11Required software:
12
13- StuffIt Expander 5.5 or later, alternatively MacGzip and SUNtar;
14- Scriptable Finder;
15- CodeWarrior Pro 5;
16
17Installation procedure:
18
19- fetch the source at ftp://ftp.openssl.org/ (well, you probably already
20 did, huh?)
21- unpack the .tar.gz file:
22 - if you have StuffIt Expander then just drag it over it;
23 - otherwise uncompress it with MacGzip and then unpack with SUNtar;
24- locate MacOS folder in OpenSSL source tree and open it;
25- unbinhex mklinks.as.hqx and OpenSSL.mcp.hqx if present (**), do it
26 "in-place", i.e. unpacked files should end-up in the very same folder;
27- execute mklinks.as;
28- open OpenSSL.mcp(***) and build 'GetHTTPS PPC' target(****);
29- that's it for now;
30
31(*) URL is hardcoded into ./MacOS/GetHTTPS.src/GetHTTPS.cpp, lines 40
32 to 42, change appropriately.
33(**) If you use SUNtar, then it might have already unbinhexed the files
34 in question.
35(***) The project file was saved with CW Pro 5.3. If you have earlier
36 version and it refuses to open it, then download
37 http://www.openssl.org/~appro/OpenSSL.mcp.xml and import it
38 overwriting the original OpenSSL.mcp.
39(****) Other targets are work in progress. If you feel like giving 'em a
40 shot, then you should know that OpenSSL* and Lib* targets are
41 supposed to be built with the GUSI, MacOS library which mimics
42 BSD sockets and some other POSIX APIs. The GUSI distribution is
43 expected to be found in the same directory as openssl source tree,
44 i.e. in the parent directory to the one where this very file,
45 namely INSTALL.MacOS. For more informations about GUSI, see
46 http://www.iis.ee.ethz.ch/~neeri/macintosh/gusi-qa.html
47
48Finally some essential comments from our generous contributor:-)
49
50"I've gotten OpenSSL working on the Macintosh. It's probably a bit of a
51hack, but it works for what I'm doing. If you don't like the way I've done
52it, then feel free to change what I've done. I freely admit that I've done
53some less-than-ideal things in my port, and if you don't like the way I've
54done something, then feel free to change it-- I won't be offended!
55
56... I've tweaked "bss_sock.c" a little to call routines in a "MacSocket"
57library I wrote. My MacSocket library is a wrapper around OpenTransport,
58handling stuff like endpoint creation, reading, writing, etc. It is not
59designed as a high-performance package such as you'd use in a webserver,
60but is fine for lots of other applications. MacSocket also uses some other
61code libraries I've written to deal with string manipulations and error
62handling. Feel free to use these things in your own code, but give me
63credit and/or send me free stuff in appreciation! :-)
64
65...
66
67If you have any questions, feel free to email me as the following:
68
69roy@centricsystems.ca
70
71-Roy Wood"
72
diff --git a/src/lib/libssl/src/INSTALL.OS2 b/src/lib/libssl/src/INSTALL.OS2
new file mode 100644
index 0000000000..d4cc0e319b
--- /dev/null
+++ b/src/lib/libssl/src/INSTALL.OS2
@@ -0,0 +1,22 @@
1
2 Installation on OS/2
3 --------------------
4
5 You need to have the following tools installed:
6
7 * EMX GCC
8 * PERL
9 * GNU make
10
11
12 To build the makefile, run
13
14 > os2\os2-emx
15
16 This will configure OpenSSL and create OS2-EMX.mak which you then use to
17 build the OpenSSL libraries & programs by running
18
19 > make -f os2-emx.mak
20
21 If that finishes successfully you will find the libraries and programs in the
22 "out" directory.
diff --git a/src/lib/libssl/src/INSTALL.VMS b/src/lib/libssl/src/INSTALL.VMS
new file mode 100644
index 0000000000..4c01560d3d
--- /dev/null
+++ b/src/lib/libssl/src/INSTALL.VMS
@@ -0,0 +1,245 @@
1 VMS Installation instructions
2 written by Richard Levitte
3 <richard@levitte.org>
4
5
6Intro:
7======
8
9This file is divided in the following parts:
10
11 Compilation - Mandatory reading.
12 Test - Mandatory reading.
13 Installation - Mandatory reading.
14 Backward portability - Read if it's an issue.
15 Possible bugs or quirks - A few warnings on things that
16 may go wrong or may surprise you.
17 Report - How to get in touch with me.
18
19Compilation:
20============
21
22I've used the very good command procedures written by Robert Byer
23<byer@mail.all-net.net>, and just slightly modified them, making
24them slightly more general and easier to maintain.
25
26You can actually compile in almost any directory separately. Look
27for a command procedure name xxx-LIB.COM (in the library directories)
28or MAKExxx.COM (in the program directories) and read the comments at
29the top to understand how to use them. However, if you want to
30compile all you can get, the simplest is to use MAKEVMS.COM in the top
31directory. The syntax is trhe following:
32
33 @MAKEVMS <option> <rsaref-p> <debug-p> [<compiler>]
34
35<option> must be one of the following:
36
37 ALL Just build "everything".
38 DATE Just build the "[.INCLUDE]DATE.H" file.
39 SOFTLINKS Just copies some files, to simulate Unix soft links.
40 RSAREF Just build the "[.xxx.EXE.RSAREF]LIBRSAGLUE.OLB" library.
41 CRYPTO Just build the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" library.
42 SSL Just build the "[.xxx.EXE.SSL]LIBSSL.OLB" library.
43 SSL_TASK Just build the "[.xxx.EXE.SSL]SSL_TASK.EXE" program.
44 TEST Just build the "test" programs for OpenSSL.
45 APPS Just build the "application" programs for OpenSSL.
46
47<rsaref-p> must be one of the following:
48
49 RSAREF compile using the RSAREF Library
50 NORSAREF compile without using RSAREF
51
52Note: The RSAREF libraries are NOT INCLUDED and you have to
53 download it from "ftp://ftp.rsa.com/rsaref". You have to
54 get the ".tar-Z" file as the ".zip" file dosen't have the
55 directory structure stored. You have to extract the file
56 into the [.RSAREF] directory as that is where the scripts
57 will look for the files.
58
59Note 2: I have never done this, so I've no idea if it works or not.
60
61<debug-p> must be one of the following:
62
63 DEBUG compile with debugging info (will not optimize)
64 NODEBUG compile without debugging info (will optimize)
65
66<compiler> must be one of the following:
67
68 VAXC For VAX C.
69 DECC For DEC C.
70 GNUC For GNU C.
71
72
73You will find the crypto library in [.xxx.EXE.CRYPTO], called LIBCRYPTO.OLB,
74where xxx is VAX or AXP. You will find the SSL library in [.xxx.EXE.SSL],
75named LIBSSL.OLB, and you will find a bunch of useful programs in
76[.xxx.EXE.APPS]. However, these shouldn't be used right off unless it's
77just to test them. For production use, make sure you install first, see
78Installation below.
79
80Note: Some programs in this package require a TCP/IP library.
81
82Note 2: if you want to compile the crypto library only, please make sure
83 you have at least done a @MAKEVMS DATE and a @MAKEVMS SOFTLINKS.
84 A lot of things will break if you don't.
85
86Note 3: Alpha users will get a number of informational messages when
87 compiling the [.asm]vms.mar file in the BN (bignum) part of
88 the crypto library. These can be safely ignored.
89
90Test:
91=====
92
93Testing is very simple, just do the following:
94
95 @[.TEST]TESTS
96
97If a test fails, try with defining the logical name OPENSSL_NO_ASM (yes,
98it's an ugly hack!) and rebuild. Please send a bug report to
99<openssl-bugs@openssl.org>, including the output of "openssl version -a"
100and of the failed test.
101
102Installation:
103=============
104
105Installation is easy, just do the following:
106
107 @INSTALL <root>
108
109<root> is the directory in which everything will be installed,
110subdirectories, libraries, header files, programs and startup command
111procedures.
112
113N.B.: INSTALL.COM builds a new directory structure, different from
114the directory tree where you have now build OpenSSL.
115
116In the [.VMS] subdirectory of the installation, you will find the
117following command procedures:
118
119 OPENSSL_STARTUP.COM
120
121 defines all needed logical names. Takes one argument that
122 tells it in what logical name table to insert the logical
123 names. If you insert if it SYS$MANAGER:SYSTARTUP_VMS.COM, the
124 call should look like this:
125
126 @openssldev:[openssldir.VMS]OPENSSL_STARTUP "/SYSTEM"
127
128 OPENSSL_UTILS.COM
129
130 sets up the symbols to the applications. Should be called
131 from for example SYS$MANAGER:SYLOGIN.COM
132
133The logical names that are set up are the following:
134
135 SSLROOT a dotted concealed logical name pointing at the
136 root directory.
137
138 SSLCERTS Initially an empty directory, this is the default
139 location for certificate files.
140 SSLMISC Various scripts.
141 SSLPRIVATE Initially an empty directory, this is the default
142 location for private key files.
143
144 SSLEXE Contains the openssl binary and a few other utility
145 programs.
146 SSLINCLUDE Contains the header files needed if you want to
147 compile programs with libcrypto or libssl.
148 SSLLIB Contains the OpenSSL library files (LIBCRYPTO.OLB
149 and LIBSSL.OLB) themselves.
150
151 OPENSSL Same as SSLINCLUDE. This is because the standard
152 way to include OpenSSL header files from version
153 0.9.3 and on is:
154
155 #include <openssl/header.h>
156
157 For more info on this issue, see the INSTALL. file
158 (the NOTE in section 4 of "Installation in Detail").
159 You don't need to "deleting old header files"!!!
160
161Backward portability:
162=====================
163
164One great problem when you build a library is making sure it will work
165on as many versions of VMS as possible. Especially, code compiled on
166OpenVMS version 7.x and above tend to be unusable in version 6.x or
167lower, because some C library routines have changed names internally
168(the C programmer won't usually see it, because the old name is
169maintained through C macros). One obvious solution is to make sure
170you have a development machine with an old enough version of OpenVMS.
171However, if you are stuck with a bunch of Alphas running OpenVMS version
1727.1, you seem to be out of luck. Fortunately, the DEC C header files
173are cluttered with conditionals that make some declarations and definitions
174dependent on the OpenVMS version or the C library version, *and* you
175can use those macros to simulate older OpenVMS or C library versions,
176by defining the macros _VMS_V6_SOURCE, __VMS_VER and __CTRL_VER with
177correct values. In the compilation scripts, I've provided the possibility
178for the user to influense the creation of such macros, through a bunch of
179symbols, all having names starting with USER_. Here's the list of them:
180
181 USER_CCFLAGS - Used to give additional qualifiers to the
182 compiler. It can't be used to define macros
183 since the scripts will do such things as well.
184 To do such things, use USER_CCDEFS.
185 USER_CCDEFS - Used to define macros on the command line. The
186 value of this symbol will be inserted inside a
187 /DEFINE=(...).
188 USER_CCDISABLEWARNINGS - Used to disable some warnings. The value is
189 inserted inside a /DISABLE=WARNING=(...).
190
191So, to maintain backward compatibility with older VMS versions, do the
192following before you start compiling:
193
194 $ USER_CCDEFS := _VMS_V6_SOURCE=1,__VMS_VER=60000000,__CRTL_VER=60000000
195 $ USER_CCDISABLEWARNINGS := PREOPTW
196
197The USER_CCDISABLEWARNINGS is there because otherwise, DEC C will complain
198that those macros have been changed.
199
200Note: Currently, this is only usefull for library compilation. The
201 programs will still be linked with the current version of the
202 C library shareable image, and will thus complain if they are
203 faced with an older version of the same C library shareable image.
204 This will probably be fixed in a future revision of OpenSSL.
205
206
207Possible bugs or quirks:
208========================
209
210I'm not perfectly sure all the programs will use the SSLCERTS:
211directory by default, it may very well be that you have to give them
212extra arguments. Please experiment.
213
214
215Report:
216=======
217
218I maintain a few mailinglists for bug reports and such on software that
219I develop/port/enhance/destroy. Please look at http://www.free.lp.se/
220for further info.
221
222
223--
224Richard Levitte <richard@levitte.org>
2251999-03-09
226
227
228TODO:
229=====
230
231There are a few things that need to be worked out in the VMS version of
232OpenSSL, still:
233
234- Description files. ("Makefile's" :-))
235- Script code to link an already compiled build tree.
236- A VMSINSTALlable version (way in the future, unless someone else hacks).
237- shareable images (DLL for you Windows folks).
238
239There may be other things that I have missed and that may be desirable.
240Please send mail to <openssl-users@openssl.org> or to me directly if you
241have any ideas.
242
243--
244Richard Levitte <richard@levitte.org>
2451999-05-24
diff --git a/src/lib/libssl/src/INSTALL.W32 b/src/lib/libssl/src/INSTALL.W32
new file mode 100644
index 0000000000..4550aa0621
--- /dev/null
+++ b/src/lib/libssl/src/INSTALL.W32
@@ -0,0 +1,323 @@
1
2 INSTALLATION ON THE WIN32 PLATFORM
3 ----------------------------------
4
5 Heres a few comments about building OpenSSL in Windows environments. Most of
6 this is tested on Win32 but it may also work in Win 3.1 with some
7 modification. See the end of this file for Eric's original comments.
8
9 You need Perl for Win32 (available from http://www.activestate.com/ActivePerl)
10 and one of the following C compilers:
11
12 * Visual C++
13 * Borland C
14 * GNU C (Mingw32 or Cygwin32)
15
16 If you want to compile in the assembly language routines with Visual C++ then
17 you will need an assembler. This is worth doing because it will result in
18 faster code: for example it will typically result in a 2 times speedup in the
19 RSA routines. Currently the following assemblers are supported:
20
21 * Microsoft MASM (aka "ml")
22 * Free Netwide Assembler NASM.
23
24 MASM was I believe distributed in the past with VC++ and it is also part of
25 the MSDN SDKs. It is no longer distributed as part of VC++ and can be hard
26 to get hold of. It can be purchased: see Microsoft's site for details at:
27 http://www.microsoft.com/
28
29 NASM is freely available. Version 0.98 was used during testing: other versions
30 may also work. It is available from many places, see for example:
31 http://www.kernel.org/pub/software/devel/nasm/binaries/win32/
32 The NASM binary nasmw.exe needs to be installed anywhere on your PATH.
33
34 If you are compiling from a tarball or a CVS snapshot then the Win32 files
35 may well be not up to date. This may mean that some "tweaking" is required to
36 get it all to work. See the trouble shooting section later on for if (when?)
37 it goes wrong.
38
39 Visual C++
40 ----------
41
42 Firstly you should run Configure:
43
44 > perl Configure VC-WIN32
45
46 Next you need to build the Makefiles and optionally the assembly language
47 files:
48
49 - If you are using MASM then run:
50
51 > ms\do_masm
52
53 - If you are using NASM then run:
54
55 > ms\do_nasm
56
57 - If you don't want to use the assembly language files at all then run:
58
59 > ms\do_ms
60
61 If you get errors about things not having numbers assigned then check the
62 troubleshooting section: you probably wont be able to compile it as it
63 stands.
64
65 Then from the VC++ environment at a prompt do:
66
67 > nmake -f ms\ntdll.mak
68
69 If all is well it should compile and you will have some DLLs and executables
70 in out32dll. If you want to try the tests then do:
71
72 > cd out32dll
73 > ..\ms\test
74
75 Tweaks:
76
77 There are various changes you can make to the Win32 compile environment. By
78 default the library is not compiled with debugging symbols. If you add 'debug'
79 to the mk1mk.pl lines in the do_* batch file then debugging symbols will be
80 compiled in.
81
82 The default Win32 environment is to leave out any Windows NT specific
83 features.
84
85 If you want to enable the NT specific features of OpenSSL (currently only the
86 logging BIO) follow the instructions above but call the batch file do_nt.bat
87 instead of do_ms.bat.
88
89 You can also build a static version of the library using the Makefile
90 ms\nt.mak
91
92 Borland C++ builder 3 and 4
93 ---------------------------
94
95 * Setup PATH. First must be GNU make then bcb4/bin
96
97 * Run ms\bcb4.bat
98
99 * Run make:
100 > make -f bcb.mak
101
102 GNU C (Mingw32)
103 ---------------
104
105 To build OpenSSL, you need the Mingw32 package and GNU make.
106
107 * Compiler installation:
108
109 Mingw32 is available from <ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/
110 mingw32/egcs-1.1.2/egcs-1.1.2-mingw32.zip>. GNU make is at
111 <ftp://agnes.dida.physik.uni-essen.de/home/janjaap/mingw32/binaries/
112 make-3.76.1.zip>. Install both of them in C:\egcs-1.1.2 and run
113 C:\egcs-1.1.2\mingw32.bat to set the PATH.
114
115 * Compile OpenSSL:
116
117 > perl Configure Mingw32
118 > ms\mw.bat
119
120 This will create the library and binaries in out.
121
122 libcrypto.a and libssl.a are the static libraries. To use the DLLs,
123 link with libeay32.a and libssl32.a instead.
124
125 See troubleshooting if you get error messages about functions not having
126 a number assigned.
127
128 * You can now try the tests:
129
130 > cd out
131 > ..\ms\test
132
133 Troubleshooting
134 ---------------
135
136 Since the Win32 build is only occasionally tested it may not always compile
137 cleanly. If you get an error about functions not having numbers assigned
138 when you run ms\do_ms then this means the Win32 ordinal files are not up to
139 date. You can do:
140
141 > perl util\mkdef.pl crypto ssl update
142
143 then ms\do_XXX should not give a warning any more. However the numbers that
144 get assigned by this technique may not match those that eventually get
145 assigned in the CVS tree: so anything linked against this version of the
146 library may need to be recompiled.
147
148 If you get errors about unresolved externals then this means that either you
149 didn't read the note above about functions not having numbers assigned or
150 someone forgot to add a function to the header file.
151
152 In this latter case check out the header file to see if the function is
153 defined in the header file.
154
155 If you get warnings in the code then the compilation will halt.
156
157 The default Makefile for Win32 halts whenever any warnings occur. Since VC++
158 has its own ideas about warnings which don't always match up to other
159 environments this can happen. The best fix is to edit the file with the
160 warning in and fix it. Alternatively you can turn off the halt on warnings by
161 editing the CFLAG line in the Makefile and deleting the /WX option.
162
163 You might get compilation errors. Again you will have to fix these or report
164 them.
165
166 One final comment about compiling applications linked to the OpenSSL library.
167 If you don't use the multithreaded DLL runtime library (/MD option) your
168 program will almost certainly crash: see the original SSLeay description
169 below for more details.
170
171--------------------------------------------------------------------------------
172The orignal Windows build instructions from SSLeay follow.
173Note: some of this may be out of date and no longer applicable. In particular
174the Crypto_malloc_init() comment appears to be wrong: you always need to use
175the same runtime library as the DLL itself.
176--------------------------------------------------------------------------------
177
178The Microsoft World.
179
180The good news, to build SSLeay for the Microsft World
181
182Windows 3.1 DLL's
183perl Configure VC-WIN16
184nmake -f ms\w31dll.mak
185
186Windows NT/95 DLL's
187perl Configure VC-WIN32
188nmake -f ms\ntdll.mak
189
190Now the bad news
191All builds were done using Microsofts Visual C++ 1.52c and [45].x.
192If you are a borland person, you are probably going to have to help me
193finish the stuff in util/pl/BC*pl
194
195All builds were made under Windows NT - this means long filenames, so
196you may have problems under Windows 3.1 but probably not under 95.
197
198Because file pointers don't work in DLL's under Windows 3.1 (well at
199least stdin/stdout don't and I don't like having to differentiate
200between these and other file pointers), I now use the BIO file-pointer
201module, which needs to be linked into your application. You can either
202use the memory buffer BIO for IO, or compile bss_file.c into your
203application, it is in the apps directory and is just a copy of
204crypto/buffer/bss_file.c with #define APPS_WIN16 added.
205I have not yet automated the makefile to automatically copy it into 'out'
206for a win 3.1 build....
207
208All callbacks passed into SSLeay for Windows 3.1 need to be of type
209_far _loadds.
210
211I don't support building with the pascal calling convention.
212
213The DLL and static builds are large memory model.
214
215To build static libraries for NT/95 or win 3.1
216
217perl util/mk1mf.pl VC-WIN32 > mf-stat.nt
218perl util/mk1mf.pl VC-WIN16 > mf-stat.w31
219for DLL's
220perl util/mk1mf.pl dll VC-WIN32 > mf-dll.nt
221perl util/mk1mf.pl dll VC-WIN16 > mf-dll.w31
222
223Again you will notice that if you dont have perl, you cannot do this.
224
225Now the next importaint issue. Running Configure!
226I have small assember code files for critical big number library operation
227in crypto/bn/asm. There is, asm code, object files and uuencode
228object files. They are
229x86nt32.asm - 32bit flat memory model assember - suitable Win32
230x86w16.asm - 16bit assember - used in the msdos build.
231x86w32.asm - 32bit assember, win 3.1 segments, used for win16 build.
232
233If you feel compelled to build the 16bit maths routines in the windows 3.1
234build,
235perl Configure VC-W31-16
236perl util/mk1mf.pl dll VC-W31-16 > mf-dll.w31
237
238If you hate assember and don't want anything to do with it,
239perl util/mk1mf.pl no-asm VC-WIN16 > mf-dll.w31
240will work for any of the makefile generations.
241
242There are more options to mk1mf.pl but these all leave the temporary
243files in 'tmp' and the output files in 'out' by default.
244
245The NT build is done for console mode.
246
247The Windows 3.1 version of SSLeay uses quickwin, the interface is ugly
248but it is better than nothing. If you want ugly, try doing anything
249that involves getting a password. I decided to be ugly instead of
250echoing characters. For Windows 3.1 I would just sugest using the
251msdos version of the ssleay application for command line work.
252The QuickWin build is primarily for testing.
253
254For both NT and Windows 3.1, I have not written the code so that
255s_client, s_server can take input from the keyboard. You can happily
256start applications up in separate windows, watch them handshake, and then sit
257there for-ever. I have not had the time to get this working, and I've
258been able to test things from a unix box to the NT box :-).
259Try running ssleay s_server on the windows box
260(with either -cert ../apps/server.pem -www)
261and run ssleay s_time from another window.
262This often stuffs up on Windows 3.1, but I'm not worried since this is
263probably a problem with my demo applications, not the libraries.
264
265After a build of one of the version of microsoft SSLeay,
266'cd ms' and then run 'test'. This should check everything out and
267even does a trial run of generating certificates.
268'test.bat' requires that perl be install, you be in the ms directory
269(not the test directory, thats for unix so stay out :-) and that the
270build output directory be ../out
271
272On a last note, you will probably get division by zero errors and
273stuff after a build. This is due to your own inability to follow
274instructions :-).
275
276The reasons for the problem is probably one of the following.
277
2781) You did not run Configure. This is critical for windows 3.1 when
279 using assember. The values in crypto/bn/bn.h must match the
280 ones requred for the assember code. (remember that if you
281 edit crypto/bn/bn.h by hand, it will be clobered the next time
282 you run Configure by the contents of crypto/bn/bn.org).
283 SSLeay version -o will list the compile options.
284 For VC-WIN32 you need bn(64,32) or bn(32,32)
285 For VC-W31-32/VC-WIN16 you need bn(32,32)
286 For VC-W31-16 you need bn(32,16) or bn(16,16)
287 For VC-MSDOS you need bn(32,16) or bn(16,16).
288
289 The first number will be 2 times bigger than the second if
290 BN_LLONG is defined in bn.h and the size of the second number
291 depends on the 'bits' defined at the start of bn.h. Have a
292 look, it's all reasonably clear.
293 If you want to start messing with 8 bit builds and things like
294 that, build without the assember by re-generating a makefile
295 via 'perl util/mk1mf.pl no-asm'.
2962) You tried to build under MS-DOS or Windows 3.1 using the /G3
297 option. Don't. It is buggy (thats why you just got that
298 error) and unless you want to work out which optimising flag
299 to turn off, I'm not going to help you :-). I also noticed
300 that code often ran slower when compiled with /G3.
3013) Under NT/95, malloc goes stupid. You are probably linking with
302 the wrong library, there are problems if you mix the threaded
303 and non-threaded libraries (due to the DLL being staticly
304 linked with one and the applicaion using another.
305
306Well hopefully thats most of the MS issues handled, see you in ssl-users :-).
307
308eric 30-Aug-1996
309
310SSLeay 0.6.5
311For Windows 95/NT, add CRYPTO_malloc_init() to your program before any
312calls to the SSLeay libraries. This function will insert callbacks so that
313the SSLeay libraries will use the same malloc(), free() and realloc() as
314your application so 'problem 3)' mentioned above will go away.
315
316There is now DES assember for Windows NT/95. The file is
317crypto/des/asm/win32.asm and replaces crypto/des/des_enc.c in the build.
318
319There is also Blowfish assember for Windows NT/95. The file is
320crypto/bf/asm/win32.asm and replaces crypto/bf/bf_enc.c in the build.
321
322eric 25-Jun-1997
323
diff --git a/src/lib/libssl/src/LICENSE b/src/lib/libssl/src/LICENSE
new file mode 100644
index 0000000000..b9e18d5e7b
--- /dev/null
+++ b/src/lib/libssl/src/LICENSE
@@ -0,0 +1,127 @@
1
2 LICENSE ISSUES
3 ==============
4
5 The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
6 the OpenSSL License and the original SSLeay license apply to the toolkit.
7 See below for the actual license texts. Actually both licenses are BSD-style
8 Open Source licenses. In case of any license issues related to OpenSSL
9 please contact openssl-core@openssl.org.
10
11 OpenSSL License
12 ---------------
13
14/* ====================================================================
15 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 *
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 *
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in
26 * the documentation and/or other materials provided with the
27 * distribution.
28 *
29 * 3. All advertising materials mentioning features or use of this
30 * software must display the following acknowledgment:
31 * "This product includes software developed by the OpenSSL Project
32 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
33 *
34 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
35 * endorse or promote products derived from this software without
36 * prior written permission. For written permission, please contact
37 * openssl-core@openssl.org.
38 *
39 * 5. Products derived from this software may not be called "OpenSSL"
40 * nor may "OpenSSL" appear in their names without prior written
41 * permission of the OpenSSL Project.
42 *
43 * 6. Redistributions of any form whatsoever must retain the following
44 * acknowledgment:
45 * "This product includes software developed by the OpenSSL Project
46 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
49 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
52 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
57 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 * ====================================================================
61 *
62 * This product includes cryptographic software written by Eric Young
63 * (eay@cryptsoft.com). This product includes software written by Tim
64 * Hudson (tjh@cryptsoft.com).
65 *
66 */
67
68 Original SSLeay License
69 -----------------------
70
71/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
72 * All rights reserved.
73 *
74 * This package is an SSL implementation written
75 * by Eric Young (eay@cryptsoft.com).
76 * The implementation was written so as to conform with Netscapes SSL.
77 *
78 * This library is free for commercial and non-commercial use as long as
79 * the following conditions are aheared to. The following conditions
80 * apply to all code found in this distribution, be it the RC4, RSA,
81 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
82 * included with this distribution is covered by the same copyright terms
83 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
84 *
85 * Copyright remains Eric Young's, and as such any Copyright notices in
86 * the code are not to be removed.
87 * If this package is used in a product, Eric Young should be given attribution
88 * as the author of the parts of the library used.
89 * This can be in the form of a textual message at program startup or
90 * in documentation (online or textual) provided with the package.
91 *
92 * Redistribution and use in source and binary forms, with or without
93 * modification, are permitted provided that the following conditions
94 * are met:
95 * 1. Redistributions of source code must retain the copyright
96 * notice, this list of conditions and the following disclaimer.
97 * 2. Redistributions in binary form must reproduce the above copyright
98 * notice, this list of conditions and the following disclaimer in the
99 * documentation and/or other materials provided with the distribution.
100 * 3. All advertising materials mentioning features or use of this software
101 * must display the following acknowledgement:
102 * "This product includes cryptographic software written by
103 * Eric Young (eay@cryptsoft.com)"
104 * The word 'cryptographic' can be left out if the rouines from the library
105 * being used are not cryptographic related :-).
106 * 4. If you include any Windows specific code (or a derivative thereof) from
107 * the apps directory (application code) you must include an acknowledgement:
108 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
109 *
110 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
111 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
113 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
116 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
117 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
118 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
119 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
120 * SUCH DAMAGE.
121 *
122 * The licence and distribution terms for any publically available version or
123 * derivative of this code cannot be changed. i.e. this code cannot simply be
124 * copied and put under another distribution licence
125 * [including the GNU Public Licence.]
126 */
127
diff --git a/src/lib/libssl/src/MacOS/GUSI_Init.cpp b/src/lib/libssl/src/MacOS/GUSI_Init.cpp
new file mode 100644
index 0000000000..d8223dba2c
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GUSI_Init.cpp
@@ -0,0 +1,62 @@
1/**************** BEGIN GUSI CONFIGURATION ****************************
2 *
3 * GUSI Configuration section generated by GUSI Configurator
4 * last modified: Wed Jan 5 20:33:51 2000
5 *
6 * This section will be overwritten by the next run of Configurator.
7 */
8
9#define GUSI_SOURCE
10#include <GUSIConfig.h>
11#include <sys/cdefs.h>
12
13/* Declarations of Socket Factories */
14
15__BEGIN_DECLS
16void GUSIwithInetSockets();
17void GUSIwithLocalSockets();
18void GUSIwithMTInetSockets();
19void GUSIwithMTTcpSockets();
20void GUSIwithMTUdpSockets();
21void GUSIwithOTInetSockets();
22void GUSIwithOTTcpSockets();
23void GUSIwithOTUdpSockets();
24void GUSIwithPPCSockets();
25void GUSISetupFactories();
26__END_DECLS
27
28/* Configure Socket Factories */
29
30void GUSISetupFactories()
31{
32#ifdef GUSISetupFactories_BeginHook
33 GUSISetupFactories_BeginHook
34#endif
35 GUSIwithInetSockets();
36#ifdef GUSISetupFactories_EndHook
37 GUSISetupFactories_EndHook
38#endif
39}
40
41/* Declarations of File Devices */
42
43__BEGIN_DECLS
44void GUSIwithDConSockets();
45void GUSIwithNullSockets();
46void GUSISetupDevices();
47__END_DECLS
48
49/* Configure File Devices */
50
51void GUSISetupDevices()
52{
53#ifdef GUSISetupDevices_BeginHook
54 GUSISetupDevices_BeginHook
55#endif
56 GUSIwithNullSockets();
57#ifdef GUSISetupDevices_EndHook
58 GUSISetupDevices_EndHook
59#endif
60}
61
62/**************** END GUSI CONFIGURATION *************************/
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.cpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.cpp
new file mode 100644
index 0000000000..617aae2c70
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.cpp
@@ -0,0 +1,2753 @@
1/* ====================================================================
2 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55
56
57 #include "CPStringUtils.hpp"
58#include "ErrorHandling.hpp"
59
60
61
62#define kNumberFormatString "\p########0.00#######;-########0.00#######"
63
64
65
66// Useful utility functions which could be optimized a whole lot
67
68
69void CopyPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
70{
71int i,numPChars;
72
73
74 if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
75 {
76 numPChars = thePStr[0];
77
78 for (i = 0;;i++)
79 {
80 if (i >= numPChars || i >= maxCStrLength - 1)
81 {
82 theCStr[i] = 0;
83
84 break;
85 }
86
87 else
88 {
89 theCStr[i] = thePStr[i + 1];
90 }
91 }
92 }
93}
94
95
96void CopyPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
97{
98int theMaxDstStrLength;
99
100
101 theMaxDstStrLength = maxDstStrLength;
102
103
104 if (theDstPStr != nil && theSrcPStr != nil && theMaxDstStrLength > 0)
105 {
106 if (theMaxDstStrLength > 255)
107 {
108 theMaxDstStrLength = 255;
109 }
110
111
112 if (theMaxDstStrLength - 1 < theSrcPStr[0])
113 {
114 BlockMove(theSrcPStr + 1,theDstPStr + 1,theMaxDstStrLength - 1);
115
116 theDstPStr[0] = theMaxDstStrLength - 1;
117 }
118
119 else
120 {
121 BlockMove(theSrcPStr,theDstPStr,theSrcPStr[0] + 1);
122 }
123 }
124}
125
126
127void CopyCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxDstStrLength)
128{
129int i;
130
131
132 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
133 {
134 for (i = 0;;i++)
135 {
136 if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1)
137 {
138 theDstCStr[i] = 0;
139
140 break;
141 }
142
143 else
144 {
145 theDstCStr[i] = theSrcCStr[i];
146 }
147 }
148 }
149}
150
151
152
153void CopyCSubstrToCStr(const char *theSrcCStr,const int maxCharsToCopy,char *theDstCStr,const int maxDstStrLength)
154{
155int i;
156
157
158 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
159 {
160 for (i = 0;;i++)
161 {
162 if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1 || i >= maxCharsToCopy)
163 {
164 theDstCStr[i] = 0;
165
166 break;
167 }
168
169 else
170 {
171 theDstCStr[i] = theSrcCStr[i];
172 }
173 }
174 }
175}
176
177
178
179void CopyCSubstrToPStr(const char *theSrcCStr,const int maxCharsToCopy,unsigned char *theDstPStr,const int maxDstStrLength)
180{
181int i;
182int theMaxDstStrLength;
183
184
185 theMaxDstStrLength = maxDstStrLength;
186
187 if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
188 {
189 if (theMaxDstStrLength > 255)
190 {
191 theMaxDstStrLength = 255;
192 }
193
194
195 for (i = 0;;i++)
196 {
197 if (theSrcCStr[i] == 0 || i >= theMaxDstStrLength - 1 || i >= maxCharsToCopy)
198 {
199 theDstPStr[0] = i;
200
201 break;
202 }
203
204 else
205 {
206 theDstPStr[i + 1] = theSrcCStr[i];
207 }
208 }
209 }
210}
211
212
213
214void CopyCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
215{
216int i;
217int theMaxDstStrLength;
218
219
220 theMaxDstStrLength = maxDstStrLength;
221
222 if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
223 {
224 if (theMaxDstStrLength > 255)
225 {
226 theMaxDstStrLength = 255;
227 }
228
229
230 for (i = 0;;i++)
231 {
232 if (i >= theMaxDstStrLength - 1 || theSrcCStr[i] == 0)
233 {
234 theDstPStr[0] = i;
235
236 break;
237 }
238
239 else
240 {
241 theDstPStr[i + 1] = theSrcCStr[i];
242 }
243 }
244 }
245}
246
247
248void ConcatPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
249{
250int i,numPChars,cStrLength;
251
252
253 if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
254 {
255 for (cStrLength = 0;theCStr[cStrLength] != 0;cStrLength++)
256 {
257
258 }
259
260
261 numPChars = thePStr[0];
262
263
264 for (i = 0;;i++)
265 {
266 if (i >= numPChars || cStrLength >= maxCStrLength - 1)
267 {
268 theCStr[cStrLength++] = 0;
269
270 break;
271 }
272
273 else
274 {
275 theCStr[cStrLength++] = thePStr[i + 1];
276 }
277 }
278 }
279}
280
281
282
283void ConcatPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
284{
285int theMaxDstStrLength;
286
287
288 theMaxDstStrLength = maxDstStrLength;
289
290 if (theSrcPStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
291 {
292 if (theMaxDstStrLength > 255)
293 {
294 theMaxDstStrLength = 255;
295 }
296
297
298 if (theMaxDstStrLength - theDstPStr[0] - 1 < theSrcPStr[0])
299 {
300 BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theMaxDstStrLength - 1 - theDstPStr[0]);
301
302 theDstPStr[0] = theMaxDstStrLength - 1;
303 }
304
305 else
306 {
307 BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theSrcPStr[0]);
308
309 theDstPStr[0] += theSrcPStr[0];
310 }
311 }
312}
313
314
315
316void ConcatCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
317{
318int i,thePStrLength;
319int theMaxDstStrLength;
320
321
322 theMaxDstStrLength = maxDstStrLength;
323
324 if (theSrcCStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
325 {
326 if (theMaxDstStrLength > 255)
327 {
328 theMaxDstStrLength = 255;
329 }
330
331
332 thePStrLength = theDstPStr[0];
333
334 for (i = 0;;i++)
335 {
336 if (theSrcCStr[i] == 0 || thePStrLength >= theMaxDstStrLength - 1)
337 {
338 theDstPStr[0] = thePStrLength;
339
340 break;
341 }
342
343 else
344 {
345 theDstPStr[thePStrLength + 1] = theSrcCStr[i];
346
347 thePStrLength++;
348 }
349 }
350 }
351}
352
353
354
355void ConcatCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxCStrLength)
356{
357int cStrLength;
358
359
360 if (theSrcCStr != nil && theDstCStr != nil && maxCStrLength > 0)
361 {
362 for (cStrLength = 0;theDstCStr[cStrLength] != 0;cStrLength++)
363 {
364
365 }
366
367
368 for (;;)
369 {
370 if (*theSrcCStr == 0 || cStrLength >= maxCStrLength - 1)
371 {
372 theDstCStr[cStrLength++] = 0;
373
374 break;
375 }
376
377 else
378 {
379 theDstCStr[cStrLength++] = *theSrcCStr++;
380 }
381 }
382 }
383}
384
385
386
387void ConcatCharToCStr(const char theChar,char *theDstCStr,const int maxCStrLength)
388{
389int cStrLength;
390
391
392 if (theDstCStr != nil && maxCStrLength > 0)
393 {
394 cStrLength = CStrLength(theDstCStr);
395
396 if (cStrLength < maxCStrLength - 1)
397 {
398 theDstCStr[cStrLength++] = theChar;
399 theDstCStr[cStrLength++] = '\0';
400 }
401 }
402}
403
404
405
406void ConcatCharToPStr(const char theChar,unsigned char *theDstPStr,const int maxPStrLength)
407{
408int pStrLength;
409
410
411 if (theDstPStr != nil && maxPStrLength > 0)
412 {
413 pStrLength = PStrLength(theDstPStr);
414
415 if (pStrLength < maxPStrLength - 1 && pStrLength < 255)
416 {
417 theDstPStr[pStrLength + 1] = theChar;
418 theDstPStr[0] += 1;
419 }
420 }
421}
422
423
424
425
426int CompareCStrs(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
427{
428int returnValue;
429char firstChar,secondChar;
430
431
432 returnValue = 0;
433
434
435 if (theFirstCStr != nil && theSecondCStr != nil)
436 {
437 for (;;)
438 {
439 firstChar = *theFirstCStr;
440 secondChar = *theSecondCStr;
441
442 if (ignoreCase == true)
443 {
444 if (firstChar >= 'A' && firstChar <= 'Z')
445 {
446 firstChar = 'a' + (firstChar - 'A');
447 }
448
449 if (secondChar >= 'A' && secondChar <= 'Z')
450 {
451 secondChar = 'a' + (secondChar - 'A');
452 }
453 }
454
455
456 if (firstChar == 0 && secondChar != 0)
457 {
458 returnValue = -1;
459
460 break;
461 }
462
463 else if (firstChar != 0 && secondChar == 0)
464 {
465 returnValue = 1;
466
467 break;
468 }
469
470 else if (firstChar == 0 && secondChar == 0)
471 {
472 returnValue = 0;
473
474 break;
475 }
476
477 else if (firstChar < secondChar)
478 {
479 returnValue = -1;
480
481 break;
482 }
483
484 else if (firstChar > secondChar)
485 {
486 returnValue = 1;
487
488 break;
489 }
490
491 theFirstCStr++;
492 theSecondCStr++;
493 }
494 }
495
496
497 return(returnValue);
498}
499
500
501
502Boolean CStrsAreEqual(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
503{
504 if (CompareCStrs(theFirstCStr,theSecondCStr,ignoreCase) == 0)
505 {
506 return true;
507 }
508
509 else
510 {
511 return false;
512 }
513}
514
515
516Boolean PStrsAreEqual(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
517{
518 if (ComparePStrs(theFirstPStr,theSecondPStr,ignoreCase) == 0)
519 {
520 return true;
521 }
522
523 else
524 {
525 return false;
526 }
527}
528
529
530
531int ComparePStrs(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
532{
533int i,returnValue;
534char firstChar,secondChar;
535
536
537 returnValue = 0;
538
539
540 if (theFirstPStr != nil && theSecondPStr != nil)
541 {
542 for (i = 1;;i++)
543 {
544 firstChar = theFirstPStr[i];
545 secondChar = theSecondPStr[i];
546
547 if (ignoreCase == true)
548 {
549 if (firstChar >= 'A' && firstChar <= 'Z')
550 {
551 firstChar = 'a' + (firstChar - 'A');
552 }
553
554 if (secondChar >= 'A' && secondChar <= 'Z')
555 {
556 secondChar = 'a' + (secondChar - 'A');
557 }
558 }
559
560
561 if (theFirstPStr[0] < i && theSecondPStr[0] >= i)
562 {
563 returnValue = -1;
564
565 break;
566 }
567
568 else if (theFirstPStr[0] >= i && theSecondPStr[0] < i)
569 {
570 returnValue = 1;
571
572 break;
573 }
574
575 else if (theFirstPStr[0] < i && theSecondPStr[0] < i)
576 {
577 returnValue = 0;
578
579 break;
580 }
581
582 else if (firstChar < secondChar)
583 {
584 returnValue = -1;
585
586 break;
587 }
588
589 else if (firstChar > secondChar)
590 {
591 returnValue = 1;
592
593 break;
594 }
595 }
596 }
597
598
599 return(returnValue);
600}
601
602
603
604int CompareCStrToPStr(const char *theCStr,const unsigned char *thePStr,const Boolean ignoreCase)
605{
606int returnValue;
607char tempString[256];
608
609
610 returnValue = 0;
611
612 if (theCStr != nil && thePStr != nil)
613 {
614 CopyPStrToCStr(thePStr,tempString,sizeof(tempString));
615
616 returnValue = CompareCStrs(theCStr,tempString,ignoreCase);
617 }
618
619
620 return(returnValue);
621}
622
623
624
625void ConcatLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
626{
627Str255 theStr255;
628
629
630 NumToString(theNum,theStr255);
631
632
633 if (numDigits > 0)
634 {
635 int charsToInsert;
636
637
638 charsToInsert = numDigits - PStrLength(theStr255);
639
640 if (charsToInsert > 0)
641 {
642 char tempString[256];
643
644 CopyCStrToCStr("",tempString,sizeof(tempString));
645
646 for (;charsToInsert > 0;charsToInsert--)
647 {
648 ConcatCStrToCStr("0",tempString,sizeof(tempString));
649 }
650
651 ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
652
653 CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
654 }
655 }
656
657
658 ConcatPStrToCStr(theStr255,theCStr,maxCStrLength);
659}
660
661
662
663
664void ConcatLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
665{
666Str255 theStr255;
667
668
669 NumToString(theNum,theStr255);
670
671
672 if (numDigits > 0)
673 {
674 int charsToInsert;
675
676
677 charsToInsert = numDigits - PStrLength(theStr255);
678
679 if (charsToInsert > 0)
680 {
681 char tempString[256];
682
683 CopyCStrToCStr("",tempString,sizeof(tempString));
684
685 for (;charsToInsert > 0;charsToInsert--)
686 {
687 ConcatCStrToCStr("0",tempString,sizeof(tempString));
688 }
689
690 ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
691
692 CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
693 }
694 }
695
696
697 ConcatPStrToPStr(theStr255,thePStr,maxPStrLength);
698}
699
700
701
702void CopyCStrAndConcatLongIntToCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
703{
704 CopyCStrToCStr(theSrcCStr,theDstCStr,maxDstStrLength);
705
706 ConcatLongIntToCStr(theNum,theDstCStr,maxDstStrLength);
707}
708
709
710
711void CopyLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
712{
713Str255 theStr255;
714
715
716 NumToString(theNum,theStr255);
717
718
719 if (numDigits > 0)
720 {
721 int charsToInsert;
722
723
724 charsToInsert = numDigits - PStrLength(theStr255);
725
726 if (charsToInsert > 0)
727 {
728 char tempString[256];
729
730 CopyCStrToCStr("",tempString,sizeof(tempString));
731
732 for (;charsToInsert > 0;charsToInsert--)
733 {
734 ConcatCStrToCStr("0",tempString,sizeof(tempString));
735 }
736
737 ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
738
739 CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
740 }
741 }
742
743
744 CopyPStrToCStr(theStr255,theCStr,maxCStrLength);
745}
746
747
748
749
750
751void CopyUnsignedLongIntToCStr(const unsigned long theNum,char *theCStr,const int maxCStrLength)
752{
753char tempString[256];
754int srcCharIndex,dstCharIndex;
755unsigned long tempNum,quotient,remainder;
756
757
758 if (theNum == 0)
759 {
760 CopyCStrToCStr("0",theCStr,maxCStrLength);
761 }
762
763 else
764 {
765 srcCharIndex = 0;
766
767 tempNum = theNum;
768
769 for (;;)
770 {
771 if (srcCharIndex >= sizeof(tempString) - 1 || tempNum == 0)
772 {
773 for (dstCharIndex = 0;;)
774 {
775 if (dstCharIndex >= maxCStrLength - 1 || srcCharIndex <= 0)
776 {
777 theCStr[dstCharIndex] = 0;
778
779 break;
780 }
781
782 theCStr[dstCharIndex++] = tempString[--srcCharIndex];
783 }
784
785 break;
786 }
787
788
789 quotient = tempNum / 10;
790
791 remainder = tempNum - (quotient * 10);
792
793 tempString[srcCharIndex] = '0' + remainder;
794
795 srcCharIndex++;
796
797 tempNum = quotient;
798 }
799 }
800}
801
802
803
804
805void CopyLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
806{
807char tempString[256];
808
809
810 CopyLongIntToCStr(theNum,tempString,sizeof(tempString),numDigits);
811
812 CopyCStrToPStr(tempString,thePStr,maxPStrLength);
813}
814
815
816
817OSErr CopyLongIntToNewHandle(const long inTheLongInt,Handle *theHandle)
818{
819OSErr errCode = noErr;
820char tempString[32];
821
822
823 CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
824
825 errCode = CopyCStrToNewHandle(tempString,theHandle);
826
827 return(errCode);
828}
829
830
831OSErr CopyLongIntToExistingHandle(const long inTheLongInt,Handle theHandle)
832{
833OSErr errCode = noErr;
834char tempString[32];
835
836
837 CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
838
839 errCode = CopyCStrToExistingHandle(tempString,theHandle);
840
841 return(errCode);
842}
843
844
845
846
847OSErr CopyCStrToExistingHandle(const char *theCString,Handle theHandle)
848{
849OSErr errCode = noErr;
850long stringLength;
851
852
853 if (theCString == nil)
854 {
855 SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theCString == nil"));
856 }
857
858 if (theHandle == nil)
859 {
860 SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theHandle == nil"));
861 }
862
863 if (*theHandle == nil)
864 {
865 SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, *theHandle == nil"));
866 }
867
868
869
870 stringLength = CStrLength(theCString) + 1;
871
872 SetHandleSize(theHandle,stringLength);
873
874 if (GetHandleSize(theHandle) < stringLength)
875 {
876 SetErrorMessageAndLongIntAndBail("CopyCStrToExistingHandle: Can't set Handle size, MemError() = ",MemError());
877 }
878
879
880 ::BlockMove(theCString,*theHandle,stringLength);
881
882
883EXITPOINT:
884
885 return(errCode);
886}
887
888
889
890
891
892OSErr CopyCStrToNewHandle(const char *theCString,Handle *theHandle)
893{
894OSErr errCode = noErr;
895long stringLength;
896
897
898 if (theCString == nil)
899 {
900 SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theCString == nil"));
901 }
902
903 if (theHandle == nil)
904 {
905 SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theHandle == nil"));
906 }
907
908
909
910 stringLength = CStrLength(theCString) + 1;
911
912 *theHandle = NewHandle(stringLength);
913
914 if (*theHandle == nil)
915 {
916 SetErrorMessageAndLongIntAndBail("CopyCStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
917 }
918
919
920 ::BlockMove(theCString,**theHandle,stringLength);
921
922
923EXITPOINT:
924
925 return(errCode);
926}
927
928
929
930OSErr CopyPStrToNewHandle(const unsigned char *thePString,Handle *theHandle)
931{
932OSErr errCode = noErr;
933long stringLength;
934
935
936 if (thePString == nil)
937 {
938 SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, thePString == nil"));
939 }
940
941 if (theHandle == nil)
942 {
943 SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, theHandle == nil"));
944 }
945
946
947
948 stringLength = PStrLength(thePString) + 1;
949
950 *theHandle = NewHandle(stringLength);
951
952 if (*theHandle == nil)
953 {
954 SetErrorMessageAndLongIntAndBail("CopyPStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
955 }
956
957
958 if (stringLength > 1)
959 {
960 BlockMove(thePString + 1,**theHandle,stringLength - 1);
961 }
962
963 (**theHandle)[stringLength - 1] = 0;
964
965
966EXITPOINT:
967
968 return(errCode);
969}
970
971
972OSErr AppendPStrToHandle(const unsigned char *thePString,Handle theHandle,long *currentLength)
973{
974OSErr errCode = noErr;
975char tempString[256];
976
977
978 CopyPStrToCStr(thePString,tempString,sizeof(tempString));
979
980 errCode = AppendCStrToHandle(tempString,theHandle,currentLength);
981
982
983EXITPOINT:
984
985 return(errCode);
986}
987
988
989
990OSErr AppendCStrToHandle(const char *theCString,Handle theHandle,long *currentLength,long *maxLength)
991{
992OSErr errCode = noErr;
993long handleMaxLength,handleCurrentLength,stringLength,byteCount;
994
995
996 if (theCString == nil)
997 {
998 SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theCString == nil"));
999 }
1000
1001 if (theHandle == nil)
1002 {
1003 SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theHandle == nil"));
1004 }
1005
1006
1007 if (maxLength != nil)
1008 {
1009 handleMaxLength = *maxLength;
1010 }
1011
1012 else
1013 {
1014 handleMaxLength = GetHandleSize(theHandle);
1015 }
1016
1017
1018 if (currentLength != nil && *currentLength >= 0)
1019 {
1020 handleCurrentLength = *currentLength;
1021 }
1022
1023 else
1024 {
1025 handleCurrentLength = CStrLength(*theHandle);
1026 }
1027
1028
1029 stringLength = CStrLength(theCString);
1030
1031 byteCount = handleCurrentLength + stringLength + 1;
1032
1033 if (byteCount > handleMaxLength)
1034 {
1035 SetHandleSize(theHandle,handleCurrentLength + stringLength + 1);
1036
1037 if (maxLength != nil)
1038 {
1039 *maxLength = GetHandleSize(theHandle);
1040
1041 handleMaxLength = *maxLength;
1042 }
1043
1044 else
1045 {
1046 handleMaxLength = GetHandleSize(theHandle);
1047 }
1048
1049 if (byteCount > handleMaxLength)
1050 {
1051 SetErrorMessageAndLongIntAndBail("AppendCStrToHandle: Can't increase Handle allocation, MemError() = ",MemError());
1052 }
1053 }
1054
1055
1056 BlockMove(theCString,*theHandle + handleCurrentLength,stringLength + 1);
1057
1058
1059 if (currentLength != nil)
1060 {
1061 *currentLength += stringLength;
1062 }
1063
1064
1065 errCode = noErr;
1066
1067
1068EXITPOINT:
1069
1070 return(errCode);
1071}
1072
1073
1074
1075OSErr AppendCharsToHandle(const char *theChars,const int numChars,Handle theHandle,long *currentLength,long *maxLength)
1076{
1077OSErr errCode = noErr;
1078long handleMaxLength,handleCurrentLength,byteCount;
1079
1080
1081 if (theChars == nil)
1082 {
1083 SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theChars == nil"));
1084 }
1085
1086 if (theHandle == nil)
1087 {
1088 SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theHandle == nil"));
1089 }
1090
1091
1092 if (maxLength != nil)
1093 {
1094 handleMaxLength = *maxLength;
1095 }
1096
1097 else
1098 {
1099 handleMaxLength = GetHandleSize(theHandle);
1100 }
1101
1102
1103 if (currentLength != nil && *currentLength >= 0)
1104 {
1105 handleCurrentLength = *currentLength;
1106 }
1107
1108 else
1109 {
1110 handleCurrentLength = CStrLength(*theHandle);
1111 }
1112
1113
1114 byteCount = handleCurrentLength + numChars + 1;
1115
1116 if (byteCount > handleMaxLength)
1117 {
1118 SetHandleSize(theHandle,handleCurrentLength + numChars + 1);
1119
1120 if (maxLength != nil)
1121 {
1122 *maxLength = GetHandleSize(theHandle);
1123
1124 handleMaxLength = *maxLength;
1125 }
1126
1127 else
1128 {
1129 handleMaxLength = GetHandleSize(theHandle);
1130 }
1131
1132 if (byteCount > handleMaxLength)
1133 {
1134 SetErrorMessageAndLongIntAndBail("AppendCharsToHandle: Can't increase Handle allocation, MemError() = ",MemError());
1135 }
1136 }
1137
1138
1139 BlockMove(theChars,*theHandle + handleCurrentLength,numChars);
1140
1141 (*theHandle)[handleCurrentLength + numChars] = '\0';
1142
1143 if (currentLength != nil)
1144 {
1145 *currentLength += numChars;
1146 }
1147
1148
1149 errCode = noErr;
1150
1151
1152EXITPOINT:
1153
1154 return(errCode);
1155}
1156
1157
1158
1159OSErr AppendLongIntToHandle(const long inTheLongInt,Handle theHandle,long *currentLength)
1160{
1161OSErr errCode = noErr;
1162char tempString[32];
1163
1164
1165 CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
1166
1167 errCode = AppendCStrToHandle(tempString,theHandle,currentLength);
1168
1169 return(errCode);
1170}
1171
1172
1173
1174
1175long CStrLength(const char *theCString)
1176{
1177long cStrLength = 0;
1178
1179
1180 if (theCString != nil)
1181 {
1182 for (cStrLength = 0;theCString[cStrLength] != 0;cStrLength++)
1183 {
1184
1185 }
1186 }
1187
1188
1189 return(cStrLength);
1190}
1191
1192
1193
1194long PStrLength(const unsigned char *thePString)
1195{
1196long pStrLength = 0;
1197
1198
1199 if (thePString != nil)
1200 {
1201 pStrLength = thePString[0];
1202 }
1203
1204
1205 return(pStrLength);
1206}
1207
1208
1209
1210
1211
1212void ZeroMem(void *theMemPtr,const unsigned long numBytes)
1213{
1214unsigned char *theBytePtr;
1215unsigned long *theLongPtr;
1216unsigned long numSingleBytes;
1217unsigned long theNumBytes;
1218
1219
1220 theNumBytes = numBytes;
1221
1222 if (theMemPtr != nil && theNumBytes > 0)
1223 {
1224 theBytePtr = (unsigned char *) theMemPtr;
1225
1226 numSingleBytes = (unsigned long) theBytePtr & 0x0003;
1227
1228 while (numSingleBytes > 0)
1229 {
1230 *theBytePtr++ = 0;
1231
1232 theNumBytes--;
1233 numSingleBytes--;
1234 }
1235
1236
1237 theLongPtr = (unsigned long *) theBytePtr;
1238
1239 while (theNumBytes >= 4)
1240 {
1241 *theLongPtr++ = 0;
1242
1243 theNumBytes -= 4;
1244 }
1245
1246
1247 theBytePtr = (unsigned char *) theLongPtr;
1248
1249 while (theNumBytes > 0)
1250 {
1251 *theBytePtr++ = 0;
1252
1253 theNumBytes--;
1254 }
1255 }
1256}
1257
1258
1259
1260
1261char *FindCharInCStr(const char theChar,const char *theCString)
1262{
1263char *theStringSearchPtr;
1264
1265
1266 theStringSearchPtr = (char *) theCString;
1267
1268 if (theStringSearchPtr != nil)
1269 {
1270 while (*theStringSearchPtr != '\0' && *theStringSearchPtr != theChar)
1271 {
1272 theStringSearchPtr++;
1273 }
1274
1275 if (*theStringSearchPtr == '\0')
1276 {
1277 theStringSearchPtr = nil;
1278 }
1279 }
1280
1281 return(theStringSearchPtr);
1282}
1283
1284
1285
1286long FindCharOffsetInCStr(const char theChar,const char *theCString,const Boolean inIgnoreCase)
1287{
1288long theOffset = -1;
1289
1290
1291 if (theCString != nil)
1292 {
1293 theOffset = 0;
1294
1295
1296 if (inIgnoreCase)
1297 {
1298 char searchChar = theChar;
1299
1300 if (searchChar >= 'a' && searchChar <= 'z')
1301 {
1302 searchChar = searchChar - 'a' + 'A';
1303 }
1304
1305
1306 while (*theCString != 0)
1307 {
1308 char currentChar = *theCString;
1309
1310 if (currentChar >= 'a' && currentChar <= 'z')
1311 {
1312 currentChar = currentChar - 'a' + 'A';
1313 }
1314
1315 if (currentChar == searchChar)
1316 {
1317 break;
1318 }
1319
1320 theCString++;
1321 theOffset++;
1322 }
1323 }
1324
1325 else
1326 {
1327 while (*theCString != 0 && *theCString != theChar)
1328 {
1329 theCString++;
1330 theOffset++;
1331 }
1332 }
1333
1334 if (*theCString == 0)
1335 {
1336 theOffset = -1;
1337 }
1338 }
1339
1340 return(theOffset);
1341}
1342
1343
1344long FindCStrOffsetInCStr(const char *theCSubstring,const char *theCString,const Boolean inIgnoreCase)
1345{
1346long theOffset = -1;
1347
1348
1349 if (theCSubstring != nil && theCString != nil)
1350 {
1351 for (theOffset = 0;;theOffset++)
1352 {
1353 if (theCString[theOffset] == 0)
1354 {
1355 theOffset = -1;
1356
1357 goto EXITPOINT;
1358 }
1359
1360
1361 for (const char *tempSubstringPtr = theCSubstring,*tempCStringPtr = theCString + theOffset;;tempSubstringPtr++,tempCStringPtr++)
1362 {
1363 if (*tempSubstringPtr == 0)
1364 {
1365 goto EXITPOINT;
1366 }
1367
1368 else if (*tempCStringPtr == 0)
1369 {
1370 break;
1371 }
1372
1373 char searchChar = *tempSubstringPtr;
1374 char currentChar = *tempCStringPtr;
1375
1376 if (inIgnoreCase && searchChar >= 'a' && searchChar <= 'z')
1377 {
1378 searchChar = searchChar - 'a' + 'A';
1379 }
1380
1381 if (inIgnoreCase && currentChar >= 'a' && currentChar <= 'z')
1382 {
1383 currentChar = currentChar - 'a' + 'A';
1384 }
1385
1386 if (currentChar != searchChar)
1387 {
1388 break;
1389 }
1390 }
1391 }
1392
1393 theOffset = -1;
1394 }
1395
1396
1397EXITPOINT:
1398
1399 return(theOffset);
1400}
1401
1402
1403
1404void InsertCStrIntoCStr(const char *theSrcCStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength)
1405{
1406int currentLength;
1407int insertLength;
1408int numCharsToInsert;
1409int numCharsToShift;
1410
1411
1412 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
1413 {
1414 currentLength = CStrLength(theDstCStr);
1415
1416 insertLength = CStrLength(theSrcCStr);
1417
1418
1419 if (theInsertionOffset + insertLength < maxDstStrLength - 1)
1420 {
1421 numCharsToInsert = insertLength;
1422 }
1423
1424 else
1425 {
1426 numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
1427 }
1428
1429
1430 if (numCharsToInsert + currentLength < maxDstStrLength - 1)
1431 {
1432 numCharsToShift = currentLength - theInsertionOffset;
1433 }
1434
1435 else
1436 {
1437 numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
1438 }
1439
1440
1441 if (numCharsToShift > 0)
1442 {
1443 BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
1444 }
1445
1446 if (numCharsToInsert > 0)
1447 {
1448 BlockMove(theSrcCStr,theDstCStr + theInsertionOffset,numCharsToInsert);
1449 }
1450
1451 theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
1452 }
1453}
1454
1455
1456
1457void InsertPStrIntoCStr(const unsigned char *theSrcPStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength)
1458{
1459int currentLength;
1460int insertLength;
1461int numCharsToInsert;
1462int numCharsToShift;
1463
1464
1465 if (theDstCStr != nil && theSrcPStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
1466 {
1467 currentLength = CStrLength(theDstCStr);
1468
1469 insertLength = PStrLength(theSrcPStr);
1470
1471
1472 if (theInsertionOffset + insertLength < maxDstStrLength - 1)
1473 {
1474 numCharsToInsert = insertLength;
1475 }
1476
1477 else
1478 {
1479 numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
1480 }
1481
1482
1483 if (numCharsToInsert + currentLength < maxDstStrLength - 1)
1484 {
1485 numCharsToShift = currentLength - theInsertionOffset;
1486 }
1487
1488 else
1489 {
1490 numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
1491 }
1492
1493
1494 if (numCharsToShift > 0)
1495 {
1496 BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
1497 }
1498
1499 if (numCharsToInsert > 0)
1500 {
1501 BlockMove(theSrcPStr + 1,theDstCStr + theInsertionOffset,numCharsToInsert);
1502 }
1503
1504 theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
1505 }
1506}
1507
1508
1509
1510OSErr InsertCStrIntoHandle(const char *theCString,Handle theHandle,const long inInsertOffset)
1511{
1512OSErr errCode;
1513int currentLength;
1514int insertLength;
1515
1516
1517 SetErrorMessageAndBailIfNil(theCString,"InsertCStrIntoHandle: Bad parameter, theCString == nil");
1518
1519 SetErrorMessageAndBailIfNil(theHandle,"InsertCStrIntoHandle: Bad parameter, theHandle == nil");
1520
1521 currentLength = CStrLength(*theHandle);
1522
1523 if (currentLength + 1 > ::GetHandleSize(theHandle))
1524 {
1525 SetErrorMessageAndBail("InsertCStrIntoHandle: Handle has been overflowed");
1526 }
1527
1528 if (inInsertOffset > currentLength)
1529 {
1530 SetErrorMessageAndBail("InsertCStrIntoHandle: Insertion offset is greater than string length");
1531 }
1532
1533 insertLength = CStrLength(theCString);
1534
1535 ::SetHandleSize(theHandle,currentLength + 1 + insertLength);
1536
1537 if (::GetHandleSize(theHandle) < currentLength + 1 + insertLength)
1538 {
1539 SetErrorMessageAndLongIntAndBail("InsertCStrIntoHandle: Can't expand storage for Handle, MemError() = ",MemError());
1540 }
1541
1542 ::BlockMove(*theHandle + inInsertOffset,*theHandle + inInsertOffset + insertLength,currentLength - inInsertOffset + 1);
1543
1544 ::BlockMove(theCString,*theHandle + inInsertOffset,insertLength);
1545
1546
1547 errCode = noErr;
1548
1549
1550EXITPOINT:
1551
1552 return(errCode);
1553}
1554
1555
1556
1557
1558void CopyCStrAndInsert1LongIntIntoCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
1559{
1560 CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,nil,theNum,theDstCStr,maxDstStrLength);
1561}
1562
1563
1564void CopyCStrAndInsert2LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,char *theDstCStr,const int maxDstStrLength)
1565{
1566const long theLongInts[] = { long1,long2 };
1567
1568 CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);
1569}
1570
1571
1572void CopyCStrAndInsert3LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,const long long3,char *theDstCStr,const int maxDstStrLength)
1573{
1574const long theLongInts[] = { long1,long2,long3 };
1575
1576 CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);
1577}
1578
1579
1580void CopyCStrAndInsertCStrIntoCStr(const char *theSrcCStr,const char *theInsertCStr,char *theDstCStr,const int maxDstStrLength)
1581{
1582const char *theCStrs[2] = { theInsertCStr,nil };
1583
1584 CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,nil,theDstCStr,maxDstStrLength);
1585}
1586
1587
1588
1589void CopyCStrAndInsertCStrLongIntIntoCStr(const char *theSrcCStr,const char *theInsertCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
1590{
1591const char *theCStrs[2] = { theInsertCStr,nil };
1592const long theLongInts[1] = { theNum };
1593
1594 CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,theLongInts,theDstCStr,maxDstStrLength);
1595}
1596
1597
1598
1599void CopyCStrAndInsertCStrsLongIntsIntoCStr(const char *theSrcCStr,const char **theInsertCStrs,const long *theLongInts,char *theDstCStr,const int maxDstStrLength)
1600{
1601int dstCharIndex,srcCharIndex,theMaxDstStrLength;
1602int theCStrIndex = 0;
1603int theLongIntIndex = 0;
1604
1605
1606 theMaxDstStrLength = maxDstStrLength;
1607
1608 if (theDstCStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
1609 {
1610 dstCharIndex = 0;
1611
1612 srcCharIndex = 0;
1613
1614
1615 // Allow room for NULL at end of string
1616
1617 theMaxDstStrLength--;
1618
1619
1620 for (;;)
1621 {
1622 // Hit end of buffer?
1623
1624 if (dstCharIndex >= theMaxDstStrLength)
1625 {
1626 theDstCStr[dstCharIndex++] = 0;
1627
1628 goto EXITPOINT;
1629 }
1630
1631 // End of source string?
1632
1633 else if (theSrcCStr[srcCharIndex] == 0)
1634 {
1635 theDstCStr[dstCharIndex++] = 0;
1636
1637 goto EXITPOINT;
1638 }
1639
1640 // Did we find a '%s'?
1641
1642 else if (theInsertCStrs != nil && theInsertCStrs[theCStrIndex] != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 's')
1643 {
1644 // Skip over the '%s'
1645
1646 srcCharIndex += 2;
1647
1648
1649 // Terminate the dest string and then concat the string
1650
1651 theDstCStr[dstCharIndex] = 0;
1652
1653 ConcatCStrToCStr(theInsertCStrs[theCStrIndex],theDstCStr,theMaxDstStrLength);
1654
1655 dstCharIndex = CStrLength(theDstCStr);
1656
1657 theCStrIndex++;
1658 }
1659
1660 // Did we find a '%ld'?
1661
1662 else if (theLongInts != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 'l' && theSrcCStr[srcCharIndex + 2] == 'd')
1663 {
1664 // Skip over the '%ld'
1665
1666 srcCharIndex += 3;
1667
1668
1669 // Terminate the dest string and then concat the number
1670
1671 theDstCStr[dstCharIndex] = 0;
1672
1673 ConcatLongIntToCStr(theLongInts[theLongIntIndex],theDstCStr,theMaxDstStrLength);
1674
1675 theLongIntIndex++;
1676
1677 dstCharIndex = CStrLength(theDstCStr);
1678 }
1679
1680 else
1681 {
1682 theDstCStr[dstCharIndex++] = theSrcCStr[srcCharIndex++];
1683 }
1684 }
1685 }
1686
1687
1688
1689EXITPOINT:
1690
1691 return;
1692}
1693
1694
1695
1696
1697
1698OSErr CopyCStrAndInsertCStrLongIntIntoHandle(const char *theSrcCStr,const char *theInsertCStr,const long theNum,Handle *theHandle)
1699{
1700OSErr errCode;
1701long byteCount;
1702
1703
1704 if (theHandle != nil)
1705 {
1706 byteCount = CStrLength(theSrcCStr) + CStrLength(theInsertCStr) + 32;
1707
1708 *theHandle = NewHandle(byteCount);
1709
1710 if (*theHandle == nil)
1711 {
1712 SetErrorMessageAndLongIntAndBail("CopyCStrAndInsertCStrLongIntIntoHandle: Can't allocate Handle, MemError() = ",MemError());
1713 }
1714
1715
1716 HLock(*theHandle);
1717
1718 CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,theInsertCStr,theNum,**theHandle,byteCount);
1719
1720 HUnlock(*theHandle);
1721 }
1722
1723 errCode = noErr;
1724
1725
1726EXITPOINT:
1727
1728 return(errCode);
1729}
1730
1731
1732
1733
1734
1735OSErr CopyIndexedWordToCStr(char *theSrcCStr,int whichWord,char *theDstCStr,int maxDstCStrLength)
1736{
1737OSErr errCode;
1738char *srcCharPtr,*dstCharPtr;
1739int wordCount;
1740int byteCount;
1741
1742
1743 if (theSrcCStr == nil)
1744 {
1745 SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theSrcCStr == nil"));
1746 }
1747
1748 if (theDstCStr == nil)
1749 {
1750 SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theDstCStr == nil"));
1751 }
1752
1753 if (whichWord < 0)
1754 {
1755 SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, whichWord < 0"));
1756 }
1757
1758 if (maxDstCStrLength <= 0)
1759 {
1760 SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, maxDstCStrLength <= 0"));
1761 }
1762
1763
1764 *theDstCStr = '\0';
1765
1766 srcCharPtr = theSrcCStr;
1767
1768 while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
1769 {
1770 srcCharPtr++;
1771 }
1772
1773
1774 for (wordCount = 0;wordCount < whichWord;wordCount++)
1775 {
1776 while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')
1777 {
1778 srcCharPtr++;
1779 }
1780
1781 if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
1782 {
1783 errCode = noErr;
1784
1785 goto EXITPOINT;
1786 }
1787
1788 while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
1789 {
1790 srcCharPtr++;
1791 }
1792
1793 if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
1794 {
1795 errCode = noErr;
1796
1797 goto EXITPOINT;
1798 }
1799 }
1800
1801
1802 dstCharPtr = theDstCStr;
1803 byteCount = 0;
1804
1805
1806 for(;;)
1807 {
1808 if (byteCount >= maxDstCStrLength - 1 || *srcCharPtr == '\0' || *srcCharPtr == ' ' || *srcCharPtr == '\t' || *srcCharPtr == '\r' || *srcCharPtr == '\n')
1809 {
1810 *dstCharPtr = '\0';
1811 break;
1812 }
1813
1814 *dstCharPtr++ = *srcCharPtr++;
1815
1816 byteCount++;
1817 }
1818
1819
1820 errCode = noErr;
1821
1822
1823EXITPOINT:
1824
1825 return(errCode);
1826}
1827
1828
1829
1830
1831
1832OSErr CopyIndexedWordToNewHandle(char *theSrcCStr,int whichWord,Handle *outTheHandle)
1833{
1834OSErr errCode;
1835char *srcCharPtr;
1836int wordCount;
1837int byteCount;
1838
1839
1840 if (theSrcCStr == nil)
1841 {
1842 SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, theSrcCStr == nil"));
1843 }
1844
1845 if (outTheHandle == nil)
1846 {
1847 SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, outTheHandle == nil"));
1848 }
1849
1850 if (whichWord < 0)
1851 {
1852 SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, whichWord < 0"));
1853 }
1854
1855
1856 *outTheHandle = nil;
1857
1858
1859 srcCharPtr = theSrcCStr;
1860
1861 while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
1862 {
1863 srcCharPtr++;
1864 }
1865
1866
1867 for (wordCount = 0;wordCount < whichWord;wordCount++)
1868 {
1869 while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')
1870 {
1871 srcCharPtr++;
1872 }
1873
1874 if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
1875 {
1876 break;
1877 }
1878
1879 while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
1880 {
1881 srcCharPtr++;
1882 }
1883
1884 if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
1885 {
1886 break;
1887 }
1888 }
1889
1890
1891 for (byteCount = 0;;byteCount++)
1892 {
1893 if (srcCharPtr[byteCount] == ' ' || srcCharPtr[byteCount] == '\t' || srcCharPtr[byteCount] == '\r' || srcCharPtr[byteCount] == '\n' || srcCharPtr[byteCount] == '\0')
1894 {
1895 break;
1896 }
1897 }
1898
1899
1900 *outTheHandle = NewHandle(byteCount + 1);
1901
1902 if (*outTheHandle == nil)
1903 {
1904 SetErrorMessageAndLongIntAndBail("CopyIndexedWordToNewHandle: Can't allocate Handle, MemError() = ",MemError());
1905 }
1906
1907
1908 ::BlockMove(srcCharPtr,**outTheHandle,byteCount);
1909
1910 (**outTheHandle)[byteCount] = '\0';
1911
1912 errCode = noErr;
1913
1914
1915EXITPOINT:
1916
1917 return(errCode);
1918}
1919
1920
1921
1922OSErr CopyIndexedLineToCStr(const char *theSrcCStr,int inWhichLine,int *lineEndIndex,Boolean *gotLastLine,char *theDstCStr,const int maxDstCStrLength)
1923{
1924OSErr errCode;
1925int theCurrentLine;
1926int theCurrentLineOffset;
1927int theEOSOffset;
1928
1929
1930 if (theSrcCStr == nil)
1931 {
1932 SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theSrcCStr == nil"));
1933 }
1934
1935 if (theDstCStr == nil)
1936 {
1937 SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theDstCStr == nil"));
1938 }
1939
1940 if (inWhichLine < 0)
1941 {
1942 SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, inWhichLine < 0"));
1943 }
1944
1945 if (maxDstCStrLength <= 0)
1946 {
1947 SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, maxDstCStrLength <= 0"));
1948 }
1949
1950
1951 if (gotLastLine != nil)
1952 {
1953 *gotLastLine = false;
1954 }
1955
1956
1957 *theDstCStr = 0;
1958
1959 theCurrentLineOffset = 0;
1960
1961 theCurrentLine = 0;
1962
1963
1964 while (theCurrentLine < inWhichLine)
1965 {
1966 while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != 0)
1967 {
1968 theCurrentLineOffset++;
1969 }
1970
1971 if (theSrcCStr[theCurrentLineOffset] == 0)
1972 {
1973 break;
1974 }
1975
1976 theCurrentLineOffset++;
1977 theCurrentLine++;
1978 }
1979
1980 if (theSrcCStr[theCurrentLineOffset] == 0)
1981 {
1982 SetErrorMessageAndLongIntAndBail("CopyIndexedLineToCStr: Too few lines in source text, can't get line ",inWhichLine);
1983 }
1984
1985
1986 theEOSOffset = FindCharOffsetInCStr('\r',theSrcCStr + theCurrentLineOffset);
1987
1988 if (theEOSOffset >= 0)
1989 {
1990 CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
1991
1992 if (gotLastLine != nil)
1993 {
1994 *gotLastLine = false;
1995 }
1996
1997 if (lineEndIndex != nil)
1998 {
1999 *lineEndIndex = theEOSOffset;
2000 }
2001 }
2002
2003 else
2004 {
2005 theEOSOffset = CStrLength(theSrcCStr + theCurrentLineOffset);
2006
2007 CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
2008
2009 if (gotLastLine != nil)
2010 {
2011 *gotLastLine = true;
2012 }
2013
2014 if (lineEndIndex != nil)
2015 {
2016 *lineEndIndex = theEOSOffset;
2017 }
2018 }
2019
2020
2021 errCode = noErr;
2022
2023
2024EXITPOINT:
2025
2026 return(errCode);
2027}
2028
2029
2030
2031OSErr CopyIndexedLineToNewHandle(const char *theSrcCStr,int inWhichLine,Handle *outNewHandle)
2032{
2033OSErr errCode;
2034int theCurrentLine;
2035int theCurrentLineOffset;
2036int byteCount;
2037
2038
2039 SetErrorMessageAndBailIfNil(theSrcCStr,"CopyIndexedLineToNewHandle: Bad parameter, theSrcCStr == nil");
2040 SetErrorMessageAndBailIfNil(outNewHandle,"CopyIndexedLineToNewHandle: Bad parameter, outNewHandle == nil");
2041
2042 if (inWhichLine < 0)
2043 {
2044 SetErrorMessageAndBail(("CopyIndexedLineToNewHandle: Bad parameter, inWhichLine < 0"));
2045 }
2046
2047
2048 theCurrentLineOffset = 0;
2049
2050 theCurrentLine = 0;
2051
2052
2053 while (theCurrentLine < inWhichLine)
2054 {
2055 while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != '\0')
2056 {
2057 theCurrentLineOffset++;
2058 }
2059
2060 if (theSrcCStr[theCurrentLineOffset] == '\0')
2061 {
2062 break;
2063 }
2064
2065 theCurrentLineOffset++;
2066 theCurrentLine++;
2067 }
2068
2069 if (theSrcCStr[theCurrentLineOffset] == '\0')
2070 {
2071 SetErrorMessageAndLongIntAndBail("CopyIndexedLineToNewHandle: Too few lines in source text, can't get line #",inWhichLine);
2072 }
2073
2074
2075 byteCount = 0;
2076
2077 while (theSrcCStr[theCurrentLineOffset + byteCount] != '\r' && theSrcCStr[theCurrentLineOffset + byteCount] != '\0')
2078 {
2079 byteCount++;
2080 }
2081
2082
2083 *outNewHandle = NewHandle(byteCount + 1);
2084
2085 if (*outNewHandle == nil)
2086 {
2087 SetErrorMessageAndLongIntAndBail("CopyIndexedLineToNewHandle: Can't allocate Handle, MemError() = ",MemError());
2088 }
2089
2090 ::BlockMove(theSrcCStr + theCurrentLineOffset,**outNewHandle,byteCount);
2091
2092 (**outNewHandle)[byteCount] = '\0';
2093
2094 errCode = noErr;
2095
2096
2097EXITPOINT:
2098
2099 return(errCode);
2100}
2101
2102
2103
2104
2105OSErr CountDigits(const char *inCStr,int *outNumIntegerDigits,int *outNumFractDigits)
2106{
2107OSErr errCode = noErr;
2108int numIntDigits = 0;
2109int numFractDigits = 0;
2110int digitIndex = 0;
2111
2112
2113 SetErrorMessageAndBailIfNil(inCStr,"CountDigits: Bad parameter, theSrcCStr == nil");
2114 SetErrorMessageAndBailIfNil(outNumIntegerDigits,"CountDigits: Bad parameter, outNumIntegerDigits == nil");
2115 SetErrorMessageAndBailIfNil(outNumFractDigits,"CountDigits: Bad parameter, outNumFractDigits == nil");
2116
2117 digitIndex = 0;
2118
2119 while (inCStr[digitIndex] >= '0' && inCStr[digitIndex] <= '9')
2120 {
2121 digitIndex++;
2122 numIntDigits++;
2123 }
2124
2125 if (inCStr[digitIndex] == '.')
2126 {
2127 digitIndex++;
2128
2129 while (inCStr[digitIndex] >= '0' && inCStr[digitIndex] <= '9')
2130 {
2131 digitIndex++;
2132 numFractDigits++;
2133 }
2134 }
2135
2136 *outNumIntegerDigits = numIntDigits;
2137
2138 *outNumFractDigits = numFractDigits;
2139
2140 errCode = noErr;
2141
2142EXITPOINT:
2143
2144 return(errCode);
2145}
2146
2147
2148
2149OSErr ExtractIntFromCStr(const char *theSrcCStr,int *outInt,Boolean skipLeadingSpaces)
2150{
2151OSErr errCode;
2152int theCharIndex;
2153
2154
2155 if (theSrcCStr == nil)
2156 {
2157 SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, theSrcCStr == nil"));
2158 }
2159
2160 if (outInt == nil)
2161 {
2162 SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, outInt == nil"));
2163 }
2164
2165
2166 *outInt = 0;
2167
2168 theCharIndex = 0;
2169
2170 if (skipLeadingSpaces == true)
2171 {
2172 while (theSrcCStr[theCharIndex] == ' ')
2173 {
2174 theCharIndex++;
2175 }
2176 }
2177
2178 if (theSrcCStr[theCharIndex] < '0' || theSrcCStr[theCharIndex] > '9')
2179 {
2180 SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, theSrcCStr contains a bogus numeric representation"));
2181 }
2182
2183
2184 while (theSrcCStr[theCharIndex] >= '0' && theSrcCStr[theCharIndex] <= '9')
2185 {
2186 *outInt = (*outInt * 10) + (theSrcCStr[theCharIndex] - '0');
2187
2188 theCharIndex++;
2189 }
2190
2191
2192 errCode = noErr;
2193
2194
2195EXITPOINT:
2196
2197 return(errCode);
2198}
2199
2200
2201
2202OSErr ExtractIntFromPStr(const unsigned char *theSrcPStr,int *outInt,Boolean skipLeadingSpaces)
2203{
2204OSErr errCode;
2205char theCStr[256];
2206
2207
2208 if (theSrcPStr == nil)
2209 {
2210 SetErrorMessageAndBail(("ExtractIntFromPStr: Bad parameter, theSrcPStr == nil"));
2211 }
2212
2213 if (outInt == nil)
2214 {
2215 SetErrorMessageAndBail(("ExtractIntFromPStr: Bad parameter, outInt == nil"));
2216 }
2217
2218
2219 CopyPStrToCStr(theSrcPStr,theCStr,sizeof(theCStr));
2220
2221
2222 errCode = ExtractIntFromCStr(theCStr,outInt,skipLeadingSpaces);
2223
2224
2225EXITPOINT:
2226
2227 return(errCode);
2228}
2229
2230
2231
2232int CountOccurencesOfCharInCStr(const char inChar,const char *inSrcCStr)
2233{
2234int theSrcCharIndex;
2235int numOccurrences = -1;
2236
2237
2238 if (inSrcCStr != nil && inChar != '\0')
2239 {
2240 numOccurrences = 0;
2241
2242 for (theSrcCharIndex = 0;inSrcCStr[theSrcCharIndex] != '\0';theSrcCharIndex++)
2243 {
2244 if (inSrcCStr[theSrcCharIndex] == inChar)
2245 {
2246 numOccurrences++;
2247 }
2248 }
2249 }
2250
2251 return(numOccurrences);
2252}
2253
2254
2255int CountWordsInCStr(const char *inSrcCStr)
2256{
2257int numWords = -1;
2258
2259
2260 if (inSrcCStr != nil)
2261 {
2262 numWords = 0;
2263
2264 // Skip lead spaces
2265
2266 while (*inSrcCStr == ' ')
2267 {
2268 inSrcCStr++;
2269 }
2270
2271 while (*inSrcCStr != '\0')
2272 {
2273 numWords++;
2274
2275 while (*inSrcCStr != ' ' && *inSrcCStr != '\0')
2276 {
2277 inSrcCStr++;
2278 }
2279
2280 while (*inSrcCStr == ' ')
2281 {
2282 inSrcCStr++;
2283 }
2284 }
2285 }
2286
2287 return(numWords);
2288}
2289
2290
2291
2292
2293void ConvertCStrToUpperCase(char *theSrcCStr)
2294{
2295char *theCharPtr;
2296
2297
2298 if (theSrcCStr != nil)
2299 {
2300 theCharPtr = theSrcCStr;
2301
2302 while (*theCharPtr != 0)
2303 {
2304 if (*theCharPtr >= 'a' && *theCharPtr <= 'z')
2305 {
2306 *theCharPtr = *theCharPtr - 'a' + 'A';
2307 }
2308
2309 theCharPtr++;
2310 }
2311 }
2312}
2313
2314
2315
2316
2317
2318
2319
2320void ExtractCStrItemFromCStr(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,char *outDstCharPtr,const int inDstCharPtrMaxLength,const Boolean inTreatMultipleDelimsAsSingleDelim)
2321{
2322int theItem;
2323int theSrcCharIndex;
2324int theDstCharIndex;
2325
2326
2327 if (foundItem != nil)
2328 {
2329 *foundItem = false;
2330 }
2331
2332
2333 if (outDstCharPtr != nil && inDstCharPtrMaxLength > 0 && inItemNumber >= 0 && inItemDelimiter != 0)
2334 {
2335 *outDstCharPtr = 0;
2336
2337
2338 theSrcCharIndex = 0;
2339
2340 for (theItem = 0;theItem < inItemNumber;theItem++)
2341 {
2342 while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] != '\0')
2343 {
2344 theSrcCharIndex++;
2345 }
2346
2347 if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2348 {
2349 theSrcCharIndex++;
2350
2351 if (inTreatMultipleDelimsAsSingleDelim)
2352 {
2353 while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2354 {
2355 theSrcCharIndex++;
2356 }
2357 }
2358 }
2359
2360
2361 if (inSrcCStr[theSrcCharIndex] == '\0')
2362 {
2363 goto EXITPOINT;
2364 }
2365 }
2366
2367
2368 if (foundItem != nil)
2369 {
2370 *foundItem = true;
2371 }
2372
2373
2374 theDstCharIndex = 0;
2375
2376 for (;;)
2377 {
2378 if (inSrcCStr[theSrcCharIndex] == 0 || inSrcCStr[theSrcCharIndex] == inItemDelimiter || theDstCharIndex >= inDstCharPtrMaxLength - 1)
2379 {
2380 outDstCharPtr[theDstCharIndex] = 0;
2381
2382 break;
2383 }
2384
2385 outDstCharPtr[theDstCharIndex++] = inSrcCStr[theSrcCharIndex++];
2386 }
2387 }
2388
2389
2390EXITPOINT:
2391
2392 return;
2393}
2394
2395
2396
2397OSErr ExtractCStrItemFromCStrIntoNewHandle(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,Handle *outNewHandle,const Boolean inTreatMultipleDelimsAsSingleDelim)
2398{
2399OSErr errCode;
2400int theItem;
2401int theSrcCharIndex;
2402int theItemLength;
2403
2404
2405 if (inSrcCStr == nil)
2406 {
2407 SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inSrcCStr == nil");
2408 errCode = kGenericError;
2409 goto EXITPOINT;
2410 }
2411
2412 if (outNewHandle == nil)
2413 {
2414 SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, outNewHandle == nil");
2415 errCode = kGenericError;
2416 goto EXITPOINT;
2417 }
2418
2419 if (foundItem == nil)
2420 {
2421 SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, foundItem == nil");
2422 errCode = kGenericError;
2423 goto EXITPOINT;
2424 }
2425
2426 if (inItemNumber < 0)
2427 {
2428 SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemNumber < 0");
2429 errCode = kGenericError;
2430 goto EXITPOINT;
2431 }
2432
2433 if (inItemDelimiter == 0)
2434 {
2435 SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemDelimiter == 0");
2436 errCode = kGenericError;
2437 goto EXITPOINT;
2438 }
2439
2440
2441 *foundItem = false;
2442
2443 theSrcCharIndex = 0;
2444
2445 for (theItem = 0;theItem < inItemNumber;theItem++)
2446 {
2447 while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] != '\0')
2448 {
2449 theSrcCharIndex++;
2450 }
2451
2452 if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2453 {
2454 theSrcCharIndex++;
2455
2456 if (inTreatMultipleDelimsAsSingleDelim)
2457 {
2458 while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2459 {
2460 theSrcCharIndex++;
2461 }
2462 }
2463 }
2464
2465
2466 if (inSrcCStr[theSrcCharIndex] == '\0')
2467 {
2468 errCode = noErr;
2469
2470 goto EXITPOINT;
2471 }
2472 }
2473
2474
2475 *foundItem = true;
2476
2477
2478 for (theItemLength = 0;;theItemLength++)
2479 {
2480 if (inSrcCStr[theSrcCharIndex + theItemLength] == 0 || inSrcCStr[theSrcCharIndex + theItemLength] == inItemDelimiter)
2481 {
2482 break;
2483 }
2484 }
2485
2486
2487 *outNewHandle = NewHandle(theItemLength + 1);
2488
2489 if (*outNewHandle == nil)
2490 {
2491 SetErrorMessageAndLongIntAndBail("ExtractCStrItemFromCStrIntoNewHandle: Can't allocate Handle, MemError() = ",MemError());
2492 }
2493
2494
2495 BlockMove(inSrcCStr + theSrcCharIndex,**outNewHandle,theItemLength);
2496
2497 (**outNewHandle)[theItemLength] = 0;
2498
2499 errCode = noErr;
2500
2501
2502EXITPOINT:
2503
2504 return(errCode);
2505}
2506
2507
2508
2509
2510
2511
2512OSErr ExtractFloatFromCStr(const char *inCString,extended80 *outFloat)
2513{
2514OSErr errCode;
2515Str255 theStr255;
2516Handle theNumberPartsTableHandle = nil;
2517long theNumberPartsOffset,theNumberPartsLength;
2518FormatResultType theFormatResultType;
2519NumberParts theNumberPartsTable;
2520NumFormatStringRec theNumFormatStringRec;
2521
2522
2523 if (inCString == nil)
2524 {
2525 SetErrorMessage("ExtractFloatFromCStr: Bad parameter, inCString == nil");
2526 errCode = kGenericError;
2527 goto EXITPOINT;
2528 }
2529
2530 if (outFloat == nil)
2531 {
2532 SetErrorMessage("ExtractFloatFromCStr: Bad parameter, outFloat == nil");
2533 errCode = kGenericError;
2534 goto EXITPOINT;
2535 }
2536
2537
2538// GetIntlResourceTable(smRoman,smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2539
2540 GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2541
2542 if (theNumberPartsTableHandle == nil)
2543 {
2544 SetErrorMessage("ExtractFloatFromCStr: Can't get number parts table for converting string representations to/from numeric representations");
2545 errCode = kGenericError;
2546 goto EXITPOINT;
2547 }
2548
2549 if (theNumberPartsLength > sizeof(theNumberPartsTable))
2550 {
2551 SetErrorMessage("ExtractFloatFromCStr: Number parts table has bad length");
2552 errCode = kGenericError;
2553 goto EXITPOINT;
2554 }
2555
2556
2557 BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
2558
2559
2560 theFormatResultType = (FormatResultType) StringToFormatRec(kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
2561
2562 if (theFormatResultType != fFormatOK)
2563 {
2564 SetErrorMessage("ExtractFloatFromCStr: StringToFormatRec() != fFormatOK");
2565 errCode = kGenericError;
2566 goto EXITPOINT;
2567 }
2568
2569
2570 CopyCStrToPStr(inCString,theStr255,sizeof(theStr255));
2571
2572
2573 theFormatResultType = (FormatResultType) StringToExtended(theStr255,&theNumFormatStringRec,&theNumberPartsTable,outFloat);
2574
2575 if (theFormatResultType != fFormatOK && theFormatResultType != fBestGuess)
2576 {
2577 SetErrorMessageAndLongIntAndBail("ExtractFloatFromCStr: StringToExtended() = ",theFormatResultType);
2578 }
2579
2580
2581 errCode = noErr;
2582
2583
2584EXITPOINT:
2585
2586 return(errCode);
2587}
2588
2589
2590
2591OSErr CopyFloatToCStr(const extended80 *theFloat,char *theCStr,const int maxCStrLength,const int inMaxNumIntDigits,const int inMaxNumFractDigits)
2592{
2593OSErr errCode;
2594Str255 theStr255;
2595Handle theNumberPartsTableHandle = nil;
2596long theNumberPartsOffset,theNumberPartsLength;
2597FormatResultType theFormatResultType;
2598NumberParts theNumberPartsTable;
2599NumFormatStringRec theNumFormatStringRec;
2600
2601
2602 if (theCStr == nil)
2603 {
2604 SetErrorMessage("CopyFloatToCStr: Bad parameter, theCStr == nil");
2605 errCode = kGenericError;
2606 goto EXITPOINT;
2607 }
2608
2609 if (theFloat == nil)
2610 {
2611 SetErrorMessage("CopyFloatToCStr: Bad parameter, theFloat == nil");
2612 errCode = kGenericError;
2613 goto EXITPOINT;
2614 }
2615
2616
2617// GetIntlResourceTable(smRoman,smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2618
2619 GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2620
2621 if (theNumberPartsTableHandle == nil)
2622 {
2623 SetErrorMessage("CopyFloatToCStr: Can't get number parts table for converting string representations to/from numeric representations");
2624 errCode = kGenericError;
2625 goto EXITPOINT;
2626 }
2627
2628 if (theNumberPartsLength > sizeof(theNumberPartsTable))
2629 {
2630 SetErrorMessage("CopyFloatToCStr: Number parts table has bad length");
2631 errCode = kGenericError;
2632 goto EXITPOINT;
2633 }
2634
2635
2636 BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
2637
2638
2639 if (inMaxNumIntDigits >= 0 || inMaxNumFractDigits >= 0)
2640 {
2641 char numberFormat[64];
2642 int numberFormatLength = 0;
2643
2644 for (int i = 0;i < inMaxNumIntDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
2645 {
2646 numberFormat[numberFormatLength++] = '0';
2647 }
2648
2649 if (inMaxNumFractDigits > 0 && numberFormatLength < sizeof(numberFormat) - 1)
2650 {
2651 numberFormat[numberFormatLength++] = '.';
2652
2653 for (int i = 0;i < inMaxNumFractDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
2654 {
2655 numberFormat[numberFormatLength++] = '0';
2656 }
2657 }
2658
2659
2660 if (numberFormatLength < sizeof(numberFormat) - 1)
2661 {
2662 numberFormat[numberFormatLength++] = ';';
2663 }
2664
2665 if (numberFormatLength < sizeof(numberFormat) - 1)
2666 {
2667 numberFormat[numberFormatLength++] = '-';
2668 }
2669
2670
2671 for (int i = 0;i < inMaxNumIntDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
2672 {
2673 numberFormat[numberFormatLength++] = '0';
2674 }
2675
2676 if (inMaxNumFractDigits > 0 && numberFormatLength < sizeof(numberFormat) - 1)
2677 {
2678 numberFormat[numberFormatLength++] = '.';
2679
2680 for (int i = 0;i < inMaxNumFractDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
2681 {
2682 numberFormat[numberFormatLength++] = '0';
2683 }
2684 }
2685
2686 numberFormat[numberFormatLength] = '\0';
2687
2688
2689 Str255 tempStr255;
2690
2691 CopyCStrToPStr(numberFormat,tempStr255,sizeof(tempStr255));
2692
2693 theFormatResultType = (FormatResultType) StringToFormatRec(tempStr255,&theNumberPartsTable,&theNumFormatStringRec);
2694 }
2695
2696 else
2697 {
2698 theFormatResultType = (FormatResultType) StringToFormatRec(kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
2699 }
2700
2701 if (theFormatResultType != fFormatOK)
2702 {
2703 SetErrorMessage("CopyFloatToCStr: StringToFormatRec() != fFormatOK");
2704 errCode = kGenericError;
2705 goto EXITPOINT;
2706 }
2707
2708
2709 theFormatResultType = (FormatResultType) ExtendedToString(theFloat,&theNumFormatStringRec,&theNumberPartsTable,theStr255);
2710
2711 if (theFormatResultType != fFormatOK)
2712 {
2713 SetErrorMessage("CopyFloatToCStr: ExtendedToString() != fFormatOK");
2714 errCode = kGenericError;
2715 goto EXITPOINT;
2716 }
2717
2718
2719 CopyPStrToCStr(theStr255,theCStr,maxCStrLength);
2720
2721 errCode = noErr;
2722
2723
2724EXITPOINT:
2725
2726 return(errCode);
2727}
2728
2729
2730
2731
2732
2733void SkipWhiteSpace(char **ioSrcCharPtr,const Boolean inStopAtEOL)
2734{
2735 if (ioSrcCharPtr != nil && *ioSrcCharPtr != nil)
2736 {
2737 if (inStopAtEOL)
2738 {
2739 while ((**ioSrcCharPtr == ' ' || **ioSrcCharPtr == '\t') && **ioSrcCharPtr != '\r' && **ioSrcCharPtr != '\n')
2740 {
2741 *ioSrcCharPtr++;
2742 }
2743 }
2744
2745 else
2746 {
2747 while (**ioSrcCharPtr == ' ' || **ioSrcCharPtr == '\t')
2748 {
2749 *ioSrcCharPtr++;
2750 }
2751 }
2752 }
2753}
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.hpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.hpp
new file mode 100644
index 0000000000..5045c41019
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/CPStringUtils.hpp
@@ -0,0 +1,104 @@
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7void CopyPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength);
8void CopyPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength);
9void CopyCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxDstStrLength);
10void CopyCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength);
11void ConcatPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength);
12void ConcatPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength);
13void ConcatCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength);
14void ConcatCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxCStrLength);
15
16void ConcatCharToCStr(const char theChar,char *theDstCStr,const int maxCStrLength);
17void ConcatCharToPStr(const char theChar,unsigned char *theDstPStr,const int maxPStrLength);
18
19int ComparePStrs(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase = true);
20int CompareCStrs(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase = true);
21int CompareCStrToPStr(const char *theCStr,const unsigned char *thePStr,const Boolean ignoreCase = true);
22
23Boolean CStrsAreEqual(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase = true);
24Boolean PStrsAreEqual(const unsigned char *theFirstCStr,const unsigned char *theSecondCStr,const Boolean ignoreCase = true);
25
26void CopyLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits = -1);
27void CopyUnsignedLongIntToCStr(const unsigned long theNum,char *theCStr,const int maxCStrLength);
28void ConcatLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits = -1);
29void CopyCStrAndConcatLongIntToCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength);
30
31void CopyLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits = -1);
32void ConcatLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits = -1);
33
34long CStrLength(const char *theCString);
35long PStrLength(const unsigned char *thePString);
36
37OSErr CopyCStrToExistingHandle(const char *theCString,Handle theHandle);
38OSErr CopyLongIntToExistingHandle(const long inTheLongInt,Handle theHandle);
39
40OSErr CopyCStrToNewHandle(const char *theCString,Handle *theHandle);
41OSErr CopyPStrToNewHandle(const unsigned char *thePString,Handle *theHandle);
42OSErr CopyLongIntToNewHandle(const long inTheLongInt,Handle *theHandle);
43
44OSErr AppendCStrToHandle(const char *theCString,Handle theHandle,long *currentLength = nil,long *maxLength = nil);
45OSErr AppendCharsToHandle(const char *theChars,const int numChars,Handle theHandle,long *currentLength = nil,long *maxLength = nil);
46OSErr AppendPStrToHandle(const unsigned char *thePString,Handle theHandle,long *currentLength = nil);
47OSErr AppendLongIntToHandle(const long inTheLongInt,Handle theHandle,long *currentLength = nil);
48
49void ZeroMem(void *theMemPtr,const unsigned long numBytes);
50
51char *FindCharInCStr(const char theChar,const char *theCString);
52long FindCharOffsetInCStr(const char theChar,const char *theCString,const Boolean inIgnoreCase = false);
53long FindCStrOffsetInCStr(const char *theCSubstring,const char *theCString,const Boolean inIgnoreCase = false);
54
55void CopyCSubstrToCStr(const char *theSrcCStr,const int maxCharsToCopy,char *theDstCStr,const int maxDstStrLength);
56void CopyCSubstrToPStr(const char *theSrcCStr,const int maxCharsToCopy,unsigned char *theDstPStr,const int maxDstStrLength);
57
58void InsertCStrIntoCStr(const char *theSrcCStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength);
59void InsertPStrIntoCStr(const unsigned char *theSrcPStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength);
60OSErr InsertCStrIntoHandle(const char *theCString,Handle theHandle,const long inInsertOffset);
61
62void CopyCStrAndInsertCStrIntoCStr(const char *theSrcCStr,const char *theInsertCStr,char *theDstCStr,const int maxDstStrLength);
63
64void CopyCStrAndInsertCStrsLongIntsIntoCStr(const char *theSrcCStr,const char **theInsertCStrs,const long *theLongInts,char *theDstCStr,const int maxDstStrLength);
65
66void CopyCStrAndInsert1LongIntIntoCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength);
67void CopyCStrAndInsert2LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,char *theDstCStr,const int maxDstStrLength);
68void CopyCStrAndInsert3LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,const long long3,char *theDstCStr,const int maxDstStrLength);
69
70void CopyCStrAndInsertCStrLongIntIntoCStr(const char *theSrcCStr,const char *theInsertCStr,const long theNum,char *theDstCStr,const int maxDstStrLength);
71OSErr CopyCStrAndInsertCStrLongIntIntoHandle(const char *theSrcCStr,const char *theInsertCStr,const long theNum,Handle *theHandle);
72
73
74OSErr CopyIndexedWordToCStr(char *theSrcCStr,int whichWord,char *theDstCStr,int maxDstCStrLength);
75OSErr CopyIndexedWordToNewHandle(char *theSrcCStr,int whichWord,Handle *outTheHandle);
76
77OSErr CopyIndexedLineToCStr(const char *theSrcCStr,int inWhichLine,int *lineEndIndex,Boolean *gotLastLine,char *theDstCStr,const int maxDstCStrLength);
78OSErr CopyIndexedLineToNewHandle(const char *theSrcCStr,int inWhichLine,Handle *outNewHandle);
79
80OSErr ExtractIntFromCStr(const char *theSrcCStr,int *outInt,Boolean skipLeadingSpaces = true);
81OSErr ExtractIntFromPStr(const unsigned char *theSrcPStr,int *outInt,Boolean skipLeadingSpaces = true);
82
83
84void ConvertCStrToUpperCase(char *theSrcCStr);
85
86
87int CountOccurencesOfCharInCStr(const char inChar,const char *inSrcCStr);
88int CountWordsInCStr(const char *inSrcCStr);
89
90OSErr CountDigits(const char *inCStr,int *outNumIntegerDigits,int *outNumFractDigits);
91
92void ExtractCStrItemFromCStr(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,char *outDstCharPtr,const int inDstCharPtrMaxLength,const Boolean inTreatMultipleDelimsAsSingleDelim = false);
93OSErr ExtractCStrItemFromCStrIntoNewHandle(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,Handle *outNewHandle,const Boolean inTreatMultipleDelimsAsSingleDelim = false);
94
95
96OSErr ExtractFloatFromCStr(const char *inCString,extended80 *outFloat);
97OSErr CopyFloatToCStr(const extended80 *theFloat,char *theCStr,const int maxCStrLength,const int inMaxNumIntDigits = -1,const int inMaxNumFractDigits = -1);
98
99void SkipWhiteSpace(char **ioSrcCharPtr,const Boolean inStopAtEOL = false);
100
101
102#ifdef __cplusplus
103}
104#endif
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.cpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.cpp
new file mode 100644
index 0000000000..80b6a675f4
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.cpp
@@ -0,0 +1,170 @@
1/* ====================================================================
2 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55
56
57 #include "ErrorHandling.hpp"
58#include "CPStringUtils.hpp"
59
60#ifdef __EXCEPTIONS_ENABLED__
61 #include "CMyException.hpp"
62#endif
63
64
65static char gErrorMessageBuffer[512];
66
67char *gErrorMessage = gErrorMessageBuffer;
68int gErrorMessageMaxLength = sizeof(gErrorMessageBuffer);
69
70
71
72void SetErrorMessage(const char *theErrorMessage)
73{
74 if (theErrorMessage != nil)
75 {
76 CopyCStrToCStr(theErrorMessage,gErrorMessage,gErrorMessageMaxLength);
77 }
78}
79
80
81void SetErrorMessageAndAppendLongInt(const char *theErrorMessage,const long theLongInt)
82{
83 if (theErrorMessage != nil)
84 {
85 CopyCStrAndConcatLongIntToCStr(theErrorMessage,theLongInt,gErrorMessage,gErrorMessageMaxLength);
86 }
87}
88
89void SetErrorMessageAndCStrAndLongInt(const char *theErrorMessage,const char * theCStr,const long theLongInt)
90{
91 if (theErrorMessage != nil)
92 {
93 CopyCStrAndInsertCStrLongIntIntoCStr(theErrorMessage,theCStr,theLongInt,gErrorMessage,gErrorMessageMaxLength);
94 }
95
96}
97
98void SetErrorMessageAndCStr(const char *theErrorMessage,const char * theCStr)
99{
100 if (theErrorMessage != nil)
101 {
102 CopyCStrAndInsertCStrLongIntIntoCStr(theErrorMessage,theCStr,-1,gErrorMessage,gErrorMessageMaxLength);
103 }
104}
105
106
107void AppendCStrToErrorMessage(const char *theErrorMessage)
108{
109 if (theErrorMessage != nil)
110 {
111 ConcatCStrToCStr(theErrorMessage,gErrorMessage,gErrorMessageMaxLength);
112 }
113}
114
115
116void AppendLongIntToErrorMessage(const long theLongInt)
117{
118 ConcatLongIntToCStr(theLongInt,gErrorMessage,gErrorMessageMaxLength);
119}
120
121
122
123char *GetErrorMessage(void)
124{
125 return gErrorMessage;
126}
127
128
129OSErr GetErrorMessageInNewHandle(Handle *inoutHandle)
130{
131OSErr errCode;
132
133
134 errCode = CopyCStrToNewHandle(gErrorMessage,inoutHandle);
135
136 return(errCode);
137}
138
139
140OSErr GetErrorMessageInExistingHandle(Handle inoutHandle)
141{
142OSErr errCode;
143
144
145 errCode = CopyCStrToExistingHandle(gErrorMessage,inoutHandle);
146
147 return(errCode);
148}
149
150
151
152OSErr AppendErrorMessageToHandle(Handle inoutHandle)
153{
154OSErr errCode;
155
156
157 errCode = AppendCStrToHandle(gErrorMessage,inoutHandle,nil);
158
159 return(errCode);
160}
161
162
163#ifdef __EXCEPTIONS_ENABLED__
164
165void ThrowErrorMessageException(void)
166{
167 ThrowDescriptiveException(gErrorMessage);
168}
169
170#endif
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.hpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.hpp
new file mode 100644
index 0000000000..3036df7ee0
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/ErrorHandling.hpp
@@ -0,0 +1,147 @@
1#ifdef __cplusplus
2extern "C" {
3#endif
4
5#ifndef kGenericError
6 #define kGenericError -1
7#endif
8
9extern char *gErrorMessage;
10
11
12void SetErrorMessage(const char *theErrorMessage);
13void SetErrorMessageAndAppendLongInt(const char *theErrorMessage,const long theLongInt);
14void SetErrorMessageAndCStrAndLongInt(const char *theErrorMessage,const char * theCStr,const long theLongInt);
15void SetErrorMessageAndCStr(const char *theErrorMessage,const char * theCStr);
16void AppendCStrToErrorMessage(const char *theErrorMessage);
17void AppendLongIntToErrorMessage(const long theLongInt);
18
19
20char *GetErrorMessage(void);
21OSErr GetErrorMessageInNewHandle(Handle *inoutHandle);
22OSErr GetErrorMessageInExistingHandle(Handle inoutHandle);
23OSErr AppendErrorMessageToHandle(Handle inoutHandle);
24
25
26#ifdef __EXCEPTIONS_ENABLED__
27 void ThrowErrorMessageException(void);
28#endif
29
30
31
32// A bunch of evil macros that would be uneccessary if I were always using C++ !
33
34#define SetErrorMessageAndBailIfNil(theArg,theMessage) \
35{ \
36 if (theArg == nil) \
37 { \
38 SetErrorMessage(theMessage); \
39 errCode = kGenericError; \
40 goto EXITPOINT; \
41 } \
42}
43
44
45#define SetErrorMessageAndBail(theMessage) \
46{ \
47 SetErrorMessage(theMessage); \
48 errCode = kGenericError; \
49 goto EXITPOINT; \
50}
51
52
53#define SetErrorMessageAndLongIntAndBail(theMessage,theLongInt) \
54{ \
55 SetErrorMessageAndAppendLongInt(theMessage,theLongInt); \
56 errCode = kGenericError; \
57 goto EXITPOINT; \
58}
59
60
61#define SetErrorMessageAndLongIntAndBailIfError(theErrCode,theMessage,theLongInt) \
62{ \
63 if (theErrCode != noErr) \
64 { \
65 SetErrorMessageAndAppendLongInt(theMessage,theLongInt); \
66 errCode = theErrCode; \
67 goto EXITPOINT; \
68 } \
69}
70
71
72#define SetErrorMessageCStrLongIntAndBailIfError(theErrCode,theMessage,theCStr,theLongInt) \
73{ \
74 if (theErrCode != noErr) \
75 { \
76 SetErrorMessageAndCStrAndLongInt(theMessage,theCStr,theLongInt); \
77 errCode = theErrCode; \
78 goto EXITPOINT; \
79 } \
80}
81
82
83#define SetErrorMessageAndCStrAndBail(theMessage,theCStr) \
84{ \
85 SetErrorMessageAndCStr(theMessage,theCStr); \
86 errCode = kGenericError; \
87 goto EXITPOINT; \
88}
89
90
91#define SetErrorMessageAndBailIfError(theErrCode,theMessage) \
92{ \
93 if (theErrCode != noErr) \
94 { \
95 SetErrorMessage(theMessage); \
96 errCode = theErrCode; \
97 goto EXITPOINT; \
98 } \
99}
100
101
102#define SetErrorMessageAndLongIntAndBailIfNil(theArg,theMessage,theLongInt) \
103{ \
104 if (theArg == nil) \
105 { \
106 SetErrorMessageAndAppendLongInt(theMessage,theLongInt); \
107 errCode = kGenericError; \
108 goto EXITPOINT; \
109 } \
110}
111
112
113#define BailIfError(theErrCode) \
114{ \
115 if ((theErrCode) != noErr) \
116 { \
117 goto EXITPOINT; \
118 } \
119}
120
121
122#define SetErrCodeAndBail(theErrCode) \
123{ \
124 errCode = theErrCode; \
125 \
126 goto EXITPOINT; \
127}
128
129
130#define SetErrorCodeAndMessageAndBail(theErrCode,theMessage) \
131{ \
132 SetErrorMessage(theMessage); \
133 errCode = theErrCode; \
134 goto EXITPOINT; \
135}
136
137
138#define BailNow() \
139{ \
140 errCode = kGenericError; \
141 goto EXITPOINT; \
142}
143
144
145#ifdef __cplusplus
146}
147#endif
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/GetHTTPS.cpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/GetHTTPS.cpp
new file mode 100644
index 0000000000..ed8e1cc962
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/GetHTTPS.cpp
@@ -0,0 +1,215 @@
1/*
2 * An demo illustrating how to retrieve a URI from a secure HTTP server.
3 *
4 * Author: Roy Wood
5 * Date: September 7, 1999
6 * Comments: This relies heavily on my MacSockets library.
7 * This project is also set up so that it expects the OpenSSL source folder (0.9.4 as I write this)
8 * to live in a folder called "OpenSSL-0.9.4" in this project's parent folder. For example:
9 *
10 * Macintosh HD:
11 * Development:
12 * OpenSSL-0.9.4:
13 * (OpenSSL sources here)
14 * OpenSSL Example:
15 * (OpenSSL example junk here)
16 *
17 *
18 * Also-- before attempting to compile this, make sure the aliases in "OpenSSL-0.9.4:include:openssl"
19 * are installed! Use the AppleScript applet in the "openssl-0.9.4" folder to do this!
20 */
21/* modified to seed the PRNG */
22
23
24// Include some funky libs I've developed over time
25
26#include "CPStringUtils.hpp"
27#include "ErrorHandling.hpp"
28#include "MacSocket.h"
29
30
31// We use the OpenSSL implementation of SSL....
32// This was a lot of work to finally get going, though you wouldn't know it by the results!
33
34#include <openssl/ssl.h>
35#include <openssl/err.h>
36#include <openssl/rand.h>
37
38#include <timer.h>
39
40// Let's try grabbing some data from here:
41
42#define kHTTPS_DNS "www.apache-ssl.org"
43#define kHTTPS_Port 443
44#define kHTTPS_URI "/"
45
46
47// Forward-declare this
48
49OSErr MyMacSocket_IdleWaitCallback(void *inUserRefPtr);
50
51
52
53
54
55// My idle-wait callback. Doesn't do much, does it? Silly cooperative multitasking.
56
57OSErr MyMacSocket_IdleWaitCallback(void *inUserRefPtr)
58{
59#pragma unused(inUserRefPtr)
60
61EventRecord theEvent;
62
63 ::EventAvail(everyEvent,&theEvent);
64
65 return(noErr);
66}
67
68
69
70// Finally!
71
72void main(void)
73{
74OSErr errCode;
75int theSocket = -1;
76int theTimeout = 30;
77
78SSL_CTX *ssl_ctx = nil;
79SSL *ssl = nil;
80
81char tempString[256];
82UnsignedWide microTickCount;
83
84#warning -- USE A TRUE RANDOM SEED, AND ADD ENTROPY WHENEVER POSSIBLE. --
85const char seed[] = "uyq9,7-b(VHGT^%$&^F/,876;,;./lkJHGFUY{PO*"; // Just gobbledygook
86
87 printf("OpenSSL Demo by Roy Wood, roy@centricsystems.ca\n\n");
88
89 BailIfError(errCode = MacSocket_Startup());
90
91
92
93 // Create a socket-like object
94
95 BailIfError(errCode = MacSocket_socket(&theSocket,false,theTimeout * 60,MyMacSocket_IdleWaitCallback,nil));
96
97
98 // Set up the connect string and try to connect
99
100 CopyCStrAndInsertCStrLongIntIntoCStr("%s:%ld",kHTTPS_DNS,kHTTPS_Port,tempString,sizeof(tempString));
101
102 printf("Connecting to %s....\n",tempString);
103
104 BailIfError(errCode = MacSocket_connect(theSocket,tempString));
105
106
107 // Init SSL stuff
108
109 SSL_load_error_strings();
110
111 SSLeay_add_ssl_algorithms();
112
113
114 // Pick the SSL method
115
116// ssl_ctx = SSL_CTX_new(SSLv2_client_method());
117 ssl_ctx = SSL_CTX_new(SSLv23_client_method());
118// ssl_ctx = SSL_CTX_new(SSLv3_client_method());
119
120
121 RAND_seed (seed, sizeof (seed));
122 Microseconds (&microTickCount);
123 RAND_add (&microTickCount, sizeof (microTickCount), 0); // Entropy is actually > 0, needs an estimate
124
125 // Create an SSL thingey and try to negotiate the connection
126
127 ssl = SSL_new(ssl_ctx);
128
129 SSL_set_fd(ssl,theSocket);
130
131 errCode = SSL_connect(ssl);
132
133 if (errCode < 0)
134 {
135 SetErrorMessageAndLongIntAndBail("OpenSSL: Can't initiate SSL connection, SSL_connect() = ",errCode);
136 }
137
138 // Request the URI from the host
139
140 CopyCStrToCStr("GET ",tempString,sizeof(tempString));
141 ConcatCStrToCStr(kHTTPS_URI,tempString,sizeof(tempString));
142 ConcatCStrToCStr(" HTTP/1.0\r\n\r\n",tempString,sizeof(tempString));
143
144
145 errCode = SSL_write(ssl,tempString,CStrLength(tempString));
146
147 if (errCode < 0)
148 {
149 SetErrorMessageAndLongIntAndBail("OpenSSL: Error writing data via ssl, SSL_write() = ",errCode);
150 }
151
152
153 for (;;)
154 {
155 char tempString[256];
156 int bytesRead;
157
158
159 // Read some bytes and dump them to the console
160
161 bytesRead = SSL_read(ssl,tempString,sizeof(tempString) - 1);
162
163 if (bytesRead == 0 && MacSocket_RemoteEndIsClosing(theSocket))
164 {
165 break;
166 }
167
168 else if (bytesRead < 0)
169 {
170 SetErrorMessageAndLongIntAndBail("OpenSSL: Error reading data via ssl, SSL_read() = ",bytesRead);
171 }
172
173
174 tempString[bytesRead] = '\0';
175
176 printf(tempString);
177 }
178
179 printf("\n\n\n");
180
181 // All done!
182
183 errCode = noErr;
184
185
186EXITPOINT:
187
188 // Clean up and go home
189
190 if (theSocket >= 0)
191 {
192 MacSocket_close(theSocket);
193 }
194
195 if (ssl != nil)
196 {
197 SSL_free(ssl);
198 }
199
200 if (ssl_ctx != nil)
201 {
202 SSL_CTX_free(ssl_ctx);
203 }
204
205
206 if (errCode != noErr)
207 {
208 printf("An error occurred:\n");
209
210 printf(GetErrorMessage());
211 }
212
213
214 MacSocket_Shutdown();
215}
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.cpp b/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.cpp
new file mode 100644
index 0000000000..aaf2a68ca9
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.cpp
@@ -0,0 +1,1607 @@
1/*
2 * A simple socket-like package.
3 * This could undoubtedly be improved, since it does polling and busy-waiting.
4 * At least it uses asynch I/O and implements timeouts!
5 *
6 * Other funkiness includes the use of my own (possibly brain-damaged) error-handling infrastructure.
7 *
8 * -Roy Wood (roy@centricsystems.ca)
9 *
10 */
11
12
13/* ====================================================================
14 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 *
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 *
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 *
28 * 3. All advertising materials mentioning features or use of this
29 * software must display the following acknowledgment:
30 * "This product includes software developed by the OpenSSL Project
31 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
32 *
33 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
34 * endorse or promote products derived from this software without
35 * prior written permission. For written permission, please contact
36 * openssl-core@openssl.org.
37 *
38 * 5. Products derived from this software may not be called "OpenSSL"
39 * nor may "OpenSSL" appear in their names without prior written
40 * permission of the OpenSSL Project.
41 *
42 * 6. Redistributions of any form whatsoever must retain the following
43 * acknowledgment:
44 * "This product includes software developed by the OpenSSL Project
45 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
48 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
51 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
56 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58 * OF THE POSSIBILITY OF SUCH DAMAGE.
59 * ====================================================================
60 *
61 * This product includes cryptographic software written by Eric Young
62 * (eay@cryptsoft.com). This product includes software written by Tim
63 * Hudson (tjh@cryptsoft.com).
64 *
65 */
66
67
68
69
70
71#include "MacSocket.h"
72
73#include <Threads.h>
74
75#include <OpenTransport.h>
76#include <OpenTpTInternet.h>
77#include <OpenTptClient.h>
78
79
80
81#include "CPStringUtils.hpp"
82#include "ErrorHandling.hpp"
83
84
85// #define MACSOCKET_DEBUG 1
86
87#ifdef MACSOCKET_DEBUG
88 #include <stdio.h>
89#endif
90
91
92
93extern int errno;
94
95
96#define kMaxNumSockets 4
97
98
99struct SocketStruct
100{
101 Boolean mIsInUse;
102
103 Boolean mEndpointIsBound;
104
105 Boolean mLocalEndIsConnected;
106 Boolean mRemoteEndIsConnected;
107
108 Boolean mReceivedTOpenComplete;
109 Boolean mReceivedTBindComplete;
110 Boolean mReceivedTConnect;
111 Boolean mReceivedTListen;
112 Boolean mReceivedTPassCon;
113 Boolean mReceivedTDisconnect;
114 Boolean mReceivedTOrdRel;
115 Boolean mReceivedTDisconnectComplete;
116
117 long mTimeoutTicks;
118 long mOperationStartTicks;
119
120 MacSocket_IdleWaitCallback mIdleWaitCallback;
121 void *mUserRefPtr;
122
123 OTEventCode mExpectedCode;
124 OTResult mAsyncOperationResult;
125
126 EndpointRef mEndPointRef;
127 TBind *mBindRequestedAddrInfo;
128 TBind *mAssignedAddrInfo;
129 TCall *mRemoteAddrInfo;
130
131 Boolean mReadyToReadData;
132 Boolean mReadyToWriteData;
133
134 Ptr mReadBuffer;
135 Ptr mWriteBuffer;
136
137 int mLastError;
138 char mErrMessage[256];
139};
140
141typedef struct SocketStruct SocketStruct;
142
143
144static SocketStruct sSockets[kMaxNumSockets];
145static Boolean sSocketsSetup = false;
146
147
148
149
150static OSErr MyBusyWait(SocketStruct *ioSocket,Boolean returnImmediatelyOnError,OTResult *outOTResult,Boolean *inAsyncOperationCompleteFlag);
151
152static pascal void OTNonYieldingNotifier(void *contextPtr,OTEventCode code,OTResult result,void *cookie);
153
154static Boolean SocketIndexIsValid(const int inSocketNum);
155
156static void InitSocket(SocketStruct *ioSocket);
157
158static void PrepareForAsyncOperation(SocketStruct *ioSocket,const OTEventCode inExpectedCode);
159
160static Boolean TimeoutElapsed(const SocketStruct *inSocket);
161
162static OSStatus NegotiateIPReuseAddrOption(EndpointRef inEndpoint,const Boolean inEnableReuseIP);
163
164
165
166void MacSocket_GetSocketErrorInfo(const int inSocketNum,int *outSocketErrCode,char *outSocketErrString,const int inSocketErrStringMaxLength)
167{
168 if (outSocketErrCode != nil)
169 {
170 *outSocketErrCode = -1;
171 }
172
173 if (outSocketErrString != nil)
174 {
175 CopyCStrToCStr("",outSocketErrString,inSocketErrStringMaxLength);
176 }
177
178
179 if (SocketIndexIsValid(inSocketNum))
180 {
181 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
182
183
184 if (outSocketErrCode != nil)
185 {
186 *outSocketErrCode = theSocketStruct->mLastError;
187 }
188
189 if (outSocketErrString != nil)
190 {
191 CopyCStrToCStr(theSocketStruct->mErrMessage,outSocketErrString,inSocketErrStringMaxLength);
192 }
193 }
194}
195
196
197void MacSocket_SetUserRefPtr(const int inSocketNum,void *inNewRefPtr)
198{
199 if (SocketIndexIsValid(inSocketNum))
200 {
201 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
202
203 theSocketStruct->mUserRefPtr = inNewRefPtr;
204 }
205}
206
207
208
209void MacSocket_GetLocalIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength)
210{
211 if (outIPAndPort != nil && SocketIndexIsValid(inSocketNum))
212 {
213 char tempString[256];
214 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
215
216
217 CopyCStrToCStr("",tempString,sizeof(tempString));
218
219 if (theSocketStruct->mAssignedAddrInfo != nil)
220 {
221 InetAddress *theInetAddress = (InetAddress *) theSocketStruct->mAssignedAddrInfo->addr.buf;
222 InetHost theInetHost = theInetAddress->fHost;
223
224 if (theInetHost == 0)
225 {
226 InetInterfaceInfo theInetInterfaceInfo;
227
228 if (::OTInetGetInterfaceInfo(&theInetInterfaceInfo,kDefaultInetInterface) == noErr)
229 {
230 theInetHost = theInetInterfaceInfo.fAddress;
231 }
232 }
233
234 ::OTInetHostToString(theInetHost,tempString);
235
236 ConcatCStrToCStr(":",tempString,sizeof(tempString));
237 ConcatLongIntToCStr(theInetAddress->fPort,tempString,sizeof(tempString));
238 }
239
240 CopyCStrToCStr(tempString,outIPAndPort,inIPAndPortLength);
241 }
242}
243
244
245
246void MacSocket_GetRemoteIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength)
247{
248 if (outIPAndPort != nil && SocketIndexIsValid(inSocketNum))
249 {
250 char tempString[256];
251 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
252
253
254 CopyCStrToCStr("",tempString,sizeof(tempString));
255
256 if (theSocketStruct->mRemoteAddrInfo != nil)
257 {
258 InetAddress *theInetAddress = (InetAddress *) theSocketStruct->mRemoteAddrInfo->addr.buf;
259 InetHost theInetHost = theInetAddress->fHost;
260
261 if (theInetHost == 0)
262 {
263 InetInterfaceInfo theInetInterfaceInfo;
264
265 if (::OTInetGetInterfaceInfo(&theInetInterfaceInfo,kDefaultInetInterface) == noErr)
266 {
267 theInetHost = theInetInterfaceInfo.fAddress;
268 }
269 }
270
271 ::OTInetHostToString(theInetHost,tempString);
272
273 ConcatCStrToCStr(":",tempString,sizeof(tempString));
274 ConcatLongIntToCStr(theInetAddress->fPort,tempString,sizeof(tempString));
275 }
276
277 CopyCStrToCStr(tempString,outIPAndPort,inIPAndPortLength);
278 }
279}
280
281
282
283Boolean MacSocket_RemoteEndIsClosing(const int inSocketNum)
284{
285Boolean theResult = false;
286
287 if (SocketIndexIsValid(inSocketNum))
288 {
289 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
290
291 theResult = theSocketStruct->mReceivedTOrdRel;
292 }
293
294 return(theResult);
295}
296
297
298
299Boolean MacSocket_ListenCompleted(const int inSocketNum)
300{
301Boolean theResult = false;
302
303 if (SocketIndexIsValid(inSocketNum))
304 {
305 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
306
307 theResult = theSocketStruct->mReceivedTPassCon;
308 }
309
310 return(theResult);
311}
312
313
314
315Boolean MacSocket_RemoteEndIsOpen(const int inSocketNum)
316{
317 if (SocketIndexIsValid(inSocketNum))
318 {
319 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
320
321 return(theSocketStruct->mRemoteEndIsConnected);
322 }
323
324 else
325 {
326 return(false);
327 }
328}
329
330
331
332Boolean MacSocket_LocalEndIsOpen(const int inSocketNum)
333{
334 if (SocketIndexIsValid(inSocketNum))
335 {
336 SocketStruct *theSocketStruct = &(sSockets[inSocketNum]);
337
338 return(theSocketStruct->mLocalEndIsConnected);
339 }
340
341 else
342 {
343 return(false);
344 }
345}
346
347
348
349static Boolean TimeoutElapsed(const SocketStruct *inSocket)
350{
351Boolean timeIsUp = false;
352
353 if (inSocket != nil && inSocket->mTimeoutTicks > 0 && ::TickCount() > inSocket->mOperationStartTicks + inSocket->mTimeoutTicks)
354 {
355 timeIsUp = true;
356 }
357
358
359 return(timeIsUp);
360}
361
362
363
364static Boolean SocketIndexIsValid(const int inSocketNum)
365{
366 if (inSocketNum >= 0 && inSocketNum < kMaxNumSockets && sSockets[inSocketNum].mEndPointRef != kOTInvalidEndpointRef)
367 {
368 return(true);
369 }
370
371 else
372 {
373 return(false);
374 }
375}
376
377
378
379static void InitSocket(SocketStruct *ioSocket)
380{
381 ioSocket->mIsInUse = false;
382
383 ioSocket->mEndpointIsBound = false;
384
385 ioSocket->mLocalEndIsConnected = false;
386 ioSocket->mRemoteEndIsConnected = false;
387
388 ioSocket->mReceivedTOpenComplete = false;
389 ioSocket->mReceivedTBindComplete = false;
390 ioSocket->mReceivedTConnect = false;
391 ioSocket->mReceivedTListen = false;
392 ioSocket->mReceivedTPassCon = false;
393 ioSocket->mReceivedTDisconnect = false;
394 ioSocket->mReceivedTOrdRel = false;
395 ioSocket->mReceivedTDisconnectComplete = false;
396
397 ioSocket->mTimeoutTicks = 30 * 60;
398 ioSocket->mOperationStartTicks = -1;
399
400 ioSocket->mIdleWaitCallback = nil;
401 ioSocket->mUserRefPtr = nil;
402
403 ioSocket->mExpectedCode = 0;
404 ioSocket->mAsyncOperationResult = noErr;
405
406 ioSocket->mEndPointRef = kOTInvalidEndpointRef;
407
408 ioSocket->mBindRequestedAddrInfo = nil;
409 ioSocket->mAssignedAddrInfo = nil;
410 ioSocket->mRemoteAddrInfo = nil;
411
412 ioSocket->mReadyToReadData = false;
413 ioSocket->mReadyToWriteData = true;
414
415 ioSocket->mReadBuffer = nil;
416 ioSocket->mWriteBuffer = nil;
417
418 ioSocket->mLastError = noErr;
419 CopyCStrToCStr("",ioSocket->mErrMessage,sizeof(ioSocket->mErrMessage));
420}
421
422
423
424static void PrepareForAsyncOperation(SocketStruct *ioSocket,const OTEventCode inExpectedCode)
425{
426 ioSocket->mOperationStartTicks = ::TickCount();
427
428 ioSocket->mAsyncOperationResult = noErr;
429
430 ioSocket->mExpectedCode = inExpectedCode;
431}
432
433
434// The wait function....
435
436static OSErr MyBusyWait(SocketStruct *ioSocket,Boolean returnImmediatelyOnError,OTResult *outOTResult,Boolean *inAsyncOperationCompleteFlag)
437{
438OSErr errCode = noErr;
439OTResult theOTResult = noErr;
440
441
442 SetErrorMessageAndBailIfNil(ioSocket,"MyBusyWait: Bad parameter, ioSocket = nil");
443 SetErrorMessageAndBailIfNil(inAsyncOperationCompleteFlag,"MyBusyWait: Bad parameter, inAsyncOperationCompleteFlag = nil");
444
445 for (;;)
446 {
447 if (*inAsyncOperationCompleteFlag)
448 {
449 theOTResult = ioSocket->mAsyncOperationResult;
450
451 break;
452 }
453
454 if (ioSocket->mIdleWaitCallback != nil)
455 {
456 theOTResult = (*(ioSocket->mIdleWaitCallback))(ioSocket->mUserRefPtr);
457
458 if (theOTResult != noErr && returnImmediatelyOnError)
459 {
460 break;
461 }
462 }
463
464 if (TimeoutElapsed(ioSocket))
465 {
466 theOTResult = kMacSocket_TimeoutErr;
467
468 break;
469 }
470 }
471
472
473EXITPOINT:
474
475 if (outOTResult != nil)
476 {
477 *outOTResult = theOTResult;
478 }
479
480 return(errCode);
481}
482
483
484
485// I used to do thread switching, but stopped. It could easily be rolled back in though....
486
487static pascal void OTNonYieldingNotifier(void *contextPtr,OTEventCode code,OTResult result,void *cookie)
488{
489SocketStruct *theSocketStruct = (SocketStruct *) contextPtr;
490
491 if (theSocketStruct != nil)
492 {
493 if (theSocketStruct->mExpectedCode != 0 && code == theSocketStruct->mExpectedCode)
494 {
495 theSocketStruct->mAsyncOperationResult = result;
496
497 theSocketStruct->mExpectedCode = 0;
498 }
499
500
501 switch (code)
502 {
503 case T_OPENCOMPLETE:
504 {
505 theSocketStruct->mReceivedTOpenComplete = true;
506
507 theSocketStruct->mEndPointRef = (EndpointRef) cookie;
508
509 break;
510 }
511
512
513 case T_BINDCOMPLETE:
514 {
515 theSocketStruct->mReceivedTBindComplete = true;
516
517 break;
518 }
519
520
521 case T_CONNECT:
522 {
523 theSocketStruct->mReceivedTConnect = true;
524
525 theSocketStruct->mLocalEndIsConnected = true;
526
527 theSocketStruct->mRemoteEndIsConnected = true;
528
529 break;
530 }
531
532
533 case T_LISTEN:
534 {
535 theSocketStruct->mReceivedTListen = true;
536
537 break;
538 }
539
540
541 case T_PASSCON:
542 {
543 theSocketStruct->mReceivedTPassCon = true;
544
545 theSocketStruct->mLocalEndIsConnected = true;
546
547 theSocketStruct->mRemoteEndIsConnected = true;
548
549 break;
550 }
551
552
553 case T_DATA:
554 {
555 theSocketStruct->mReadyToReadData = true;
556
557 break;
558 }
559
560 case T_GODATA:
561 {
562 theSocketStruct->mReadyToWriteData = true;
563
564 break;
565 }
566
567 case T_DISCONNECT:
568 {
569 theSocketStruct->mReceivedTDisconnect = true;
570
571 theSocketStruct->mRemoteEndIsConnected = false;
572
573 theSocketStruct->mLocalEndIsConnected = false;
574
575 ::OTRcvDisconnect(theSocketStruct->mEndPointRef,nil);
576
577 break;
578 }
579
580 case T_ORDREL:
581 {
582 theSocketStruct->mReceivedTOrdRel = true;
583
584 // We can still write data, so don't clear mRemoteEndIsConnected
585
586 ::OTRcvOrderlyDisconnect(theSocketStruct->mEndPointRef);
587
588 break;
589 }
590
591 case T_DISCONNECTCOMPLETE:
592 {
593 theSocketStruct->mReceivedTDisconnectComplete = true;
594
595 theSocketStruct->mRemoteEndIsConnected = false;
596
597 theSocketStruct->mLocalEndIsConnected = false;
598
599 break;
600 }
601 }
602 }
603/*
604T_LISTEN OTListen
605T_CONNECT OTRcvConnect
606T_DATA OTRcv, OTRcvUData
607T_DISCONNECT OTRcvDisconnect
608T_ORDREL OTRcvOrderlyDisconnect
609T_GODATA OTSnd, OTSndUData, OTLook
610T_PASSCON none
611
612T_EXDATA OTRcv
613T_GOEXDATA OTSnd, OTLook
614T_UDERR OTRcvUDErr
615*/
616}
617
618
619
620// Initialize the main socket data structure
621
622OSErr MacSocket_Startup(void)
623{
624 if (!sSocketsSetup)
625 {
626 for (int i = 0;i < kMaxNumSockets;i++)
627 {
628 InitSocket(&(sSockets[i]));
629 }
630
631 ::InitOpenTransport();
632
633 sSocketsSetup = true;
634 }
635
636
637 return(noErr);
638}
639
640
641
642// Cleanup before exiting
643
644OSErr MacSocket_Shutdown(void)
645{
646 if (sSocketsSetup)
647 {
648 for (int i = 0;i < kMaxNumSockets;i++)
649 {
650 SocketStruct *theSocketStruct = &(sSockets[i]);
651
652 if (theSocketStruct->mIsInUse)
653 {
654 if (theSocketStruct->mEndPointRef != kOTInvalidEndpointRef)
655 {
656 OTResult theOTResult;
657
658
659 // Since we're killing the endpoint, I don't bother to send the disconnect (sorry!)
660
661/*
662 if (theSocketStruct->mLocalEndIsConnected)
663 {
664 // This is an abortive action, so we do a hard disconnect instead of an OTSndOrderlyDisconnect
665
666 theOTResult = ::OTSndDisconnect(theSocketStruct->mEndPointRef, nil);
667
668 // Now we have to watch for T_DISCONNECTCOMPLETE event
669
670 theSocketStruct->mLocalEndIsConnected = false;
671 }
672*/
673
674 theOTResult = ::OTCloseProvider(theSocketStruct->mEndPointRef);
675
676
677 theSocketStruct->mEndPointRef = kOTInvalidEndpointRef;
678 }
679
680 if (theSocketStruct->mBindRequestedAddrInfo != nil)
681 {
682 ::OTFree((void *) theSocketStruct->mBindRequestedAddrInfo,T_BIND);
683
684 theSocketStruct->mBindRequestedAddrInfo = nil;
685 }
686
687 if (theSocketStruct->mAssignedAddrInfo != nil)
688 {
689 ::OTFree((void *) theSocketStruct->mAssignedAddrInfo,T_BIND);
690
691 theSocketStruct->mAssignedAddrInfo = nil;
692 }
693
694 if (theSocketStruct->mRemoteAddrInfo != nil)
695 {
696 ::OTFree((void *) theSocketStruct->mRemoteAddrInfo,T_CALL);
697
698 theSocketStruct->mRemoteAddrInfo = nil;
699 }
700
701
702 }
703 }
704
705 ::CloseOpenTransport();
706
707 sSocketsSetup = false;
708 }
709
710 return(noErr);
711}
712
713
714
715
716
717
718// Allocate a socket
719
720OSErr MacSocket_socket(int *outSocketNum,const Boolean inDoThreadSwitching,const long inTimeoutTicks,MacSocket_IdleWaitCallback inIdleWaitCallback,void *inUserRefPtr)
721{
722// Gotta roll support back in for threads eventually.....
723
724#pragma unused(inDoThreadSwitching)
725
726
727OSErr errCode = noErr;
728
729
730 SetErrorMessageAndBailIfNil(outSocketNum,"MacSocket_socket: Bad parameter, outSocketNum == nil");
731
732 *outSocketNum = -1;
733
734
735 // Find an unused socket
736
737 for (int i = 0;i < kMaxNumSockets;i++)
738 {
739 if (sSockets[i].mIsInUse == false)
740 {
741 OTResult theOTResult;
742 SocketStruct *theSocketStruct = &(sSockets[i]);
743
744
745 InitSocket(theSocketStruct);
746
747 theSocketStruct->mIdleWaitCallback = inIdleWaitCallback;
748 theSocketStruct->mUserRefPtr = inUserRefPtr;
749
750 theSocketStruct->mTimeoutTicks = inTimeoutTicks;
751
752
753 // Set up OT endpoint
754
755 PrepareForAsyncOperation(theSocketStruct,T_OPENCOMPLETE);
756
757 theOTResult = ::OTAsyncOpenEndpoint(OTCreateConfiguration(kTCPName),0,nil,OTNonYieldingNotifier,(void *) theSocketStruct);
758
759 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_socket: Can't create OT endpoint, OTAsyncOpenEndpoint() = ",theOTResult);
760
761 BailIfError(MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTOpenComplete)));
762
763 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_socket: Can't create OT endpoint, OTAsyncOpenEndpoint() = ",theOTResult);
764
765
766 *outSocketNum = i;
767
768 errCode = noErr;
769
770 theSocketStruct->mIsInUse = true;
771
772 break;
773 }
774
775 else if (i == kMaxNumSockets - 1)
776 {
777 SetErrorMessageAndBail("MacSocket_socket: No sockets available");
778 }
779 }
780
781
782EXITPOINT:
783
784 errno = errCode;
785
786 return(errCode);
787}
788
789
790
791
792OSErr MacSocket_listen(const int inSocketNum,const int inPortNum)
793{
794OSErr errCode = noErr;
795SocketStruct *theSocketStruct = nil;
796
797
798 if (!SocketIndexIsValid(inSocketNum))
799 {
800 SetErrorMessageAndBail("MacSocket_listen: Invalid socket number specified");
801 }
802
803
804 theSocketStruct = &(sSockets[inSocketNum]);
805
806
807OTResult theOTResult;
808
809
810 if (theSocketStruct->mBindRequestedAddrInfo == nil)
811 {
812 theSocketStruct->mBindRequestedAddrInfo = (TBind *) ::OTAlloc(theSocketStruct->mEndPointRef,T_BIND,T_ADDR,&theOTResult);
813
814 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't allocate OT T_BIND structure, OTAlloc() = ",theOTResult);
815 SetErrorMessageAndBailIfNil(theSocketStruct->mBindRequestedAddrInfo,"MacSocket_listen: Can't allocate OT T_BIND structure, OTAlloc() returned nil");
816 }
817
818 if (theSocketStruct->mAssignedAddrInfo == nil)
819 {
820 theSocketStruct->mAssignedAddrInfo = (TBind *) ::OTAlloc(theSocketStruct->mEndPointRef,T_BIND,T_ADDR,&theOTResult);
821
822 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't allocate OT T_BIND structure, OTAlloc() = ",theOTResult);
823 SetErrorMessageAndBailIfNil(theSocketStruct->mAssignedAddrInfo,"MacSocket_listen: Can't allocate OT T_BIND structure, OTAlloc() returned nil");
824 }
825
826 if (theSocketStruct->mRemoteAddrInfo == nil)
827 {
828 theSocketStruct->mRemoteAddrInfo = (TCall *) ::OTAlloc(theSocketStruct->mEndPointRef,T_CALL,T_ADDR,&theOTResult);
829
830 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't allocate OT T_CALL structure, OTAlloc() = ",theOTResult);
831 SetErrorMessageAndBailIfNil(theSocketStruct->mRemoteAddrInfo,"MacSocket_listen: Can't allocate OT T_CALL structure, OTAlloc() returned nil");
832 }
833
834
835 if (!theSocketStruct->mEndpointIsBound)
836 {
837 InetInterfaceInfo theInetInterfaceInfo;
838
839 theOTResult = ::OTInetGetInterfaceInfo(&theInetInterfaceInfo,kDefaultInetInterface);
840
841 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't determine OT interface info, OTInetGetInterfaceInfo() = ",theOTResult);
842
843
844 InetAddress *theInetAddress = (InetAddress *) theSocketStruct->mBindRequestedAddrInfo->addr.buf;
845
846// theInetAddress->fAddressType = AF_INET;
847// theInetAddress->fPort = inPortNum;
848// theInetAddress->fHost = theInetInterfaceInfo.fAddress;
849
850 ::OTInitInetAddress(theInetAddress,inPortNum,theInetInterfaceInfo.fAddress);
851
852 theSocketStruct->mBindRequestedAddrInfo->addr.len = sizeof(InetAddress);
853
854 theSocketStruct->mBindRequestedAddrInfo->qlen = 1;
855
856
857 theOTResult = ::OTSetSynchronous(theSocketStruct->mEndPointRef);
858
859 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't set OT endpoint mode, OTSetSynchronous() = ",theOTResult);
860
861 theOTResult = NegotiateIPReuseAddrOption(theSocketStruct->mEndPointRef,true);
862
863 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't set OT IP address reuse flag, NegotiateIPReuseAddrOption() = ",theOTResult);
864
865 theOTResult = ::OTSetAsynchronous(theSocketStruct->mEndPointRef);
866
867 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't set OT endpoint mode, OTSetAsynchronous() = ",theOTResult);
868
869
870 PrepareForAsyncOperation(theSocketStruct,T_BINDCOMPLETE);
871
872 theOTResult = ::OTBind(theSocketStruct->mEndPointRef,theSocketStruct->mBindRequestedAddrInfo,theSocketStruct->mAssignedAddrInfo);
873
874 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't bind OT endpoint, OTBind() = ",theOTResult);
875
876 BailIfError(MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTBindComplete)));
877
878 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't bind OT endpoint, OTBind() = ",theOTResult);
879
880
881 theSocketStruct->mEndpointIsBound = true;
882 }
883
884
885 PrepareForAsyncOperation(theSocketStruct,T_LISTEN);
886
887 theOTResult = ::OTListen(theSocketStruct->mEndPointRef,theSocketStruct->mRemoteAddrInfo);
888
889 if (theOTResult == noErr)
890 {
891 PrepareForAsyncOperation(theSocketStruct,T_PASSCON);
892
893 theOTResult = ::OTAccept(theSocketStruct->mEndPointRef,theSocketStruct->mEndPointRef,theSocketStruct->mRemoteAddrInfo);
894
895 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't begin OT accept, OTAccept() = ",theOTResult);
896
897 BailIfError(MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTPassCon)));
898
899 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_listen: Can't accept OT connection, OTAccept() = ",theOTResult);
900 }
901
902 else if (theOTResult == kOTNoDataErr)
903 {
904 theOTResult = noErr;
905 }
906
907 else
908 {
909 SetErrorMessageAndLongIntAndBail("MacSocket_listen: Can't begin OT listen, OTListen() = ",theOTResult);
910 }
911
912
913 errCode = noErr;
914
915
916EXITPOINT:
917
918 if (theSocketStruct != nil)
919 {
920 theSocketStruct->mLastError = noErr;
921
922 CopyCStrToCStr("",theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
923
924 if (errCode != noErr)
925 {
926 theSocketStruct->mLastError = errCode;
927
928 CopyCStrToCStr(GetErrorMessage(),theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
929 }
930 }
931
932 errno = errCode;
933
934 return(errCode);
935}
936
937
938
939
940OSErr MacSocket_connect(const int inSocketNum,char *inTargetAddressAndPort)
941{
942OSErr errCode = noErr;
943SocketStruct *theSocketStruct = nil;
944
945
946 if (!SocketIndexIsValid(inSocketNum))
947 {
948 SetErrorMessageAndBail("MacSocket_connect: Invalid socket number specified");
949 }
950
951 theSocketStruct = &(sSockets[inSocketNum]);
952
953 if (theSocketStruct->mEndpointIsBound)
954 {
955 SetErrorMessageAndBail("MacSocket_connect: Socket previously bound");
956 }
957
958
959OTResult theOTResult;
960
961 theSocketStruct->mBindRequestedAddrInfo = (TBind *) ::OTAlloc(theSocketStruct->mEndPointRef,T_BIND,T_ADDR,&theOTResult);
962
963 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't allocate OT T_BIND structure, OTAlloc() = ",theOTResult);
964 SetErrorMessageAndBailIfNil(theSocketStruct->mBindRequestedAddrInfo,"MacSocket_connect: Can't allocate OT T_BIND structure, OTAlloc() returned nil");
965
966
967 theSocketStruct->mAssignedAddrInfo = (TBind *) ::OTAlloc(theSocketStruct->mEndPointRef,T_BIND,T_ADDR,&theOTResult);
968
969 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't allocate OT T_BIND structure, OTAlloc() = ",theOTResult);
970 SetErrorMessageAndBailIfNil(theSocketStruct->mAssignedAddrInfo,"MacSocket_connect: Can't allocate OT T_BIND structure, OTAlloc() returned nil");
971
972
973 theSocketStruct->mRemoteAddrInfo = (TCall *) ::OTAlloc(theSocketStruct->mEndPointRef,T_CALL,T_ADDR,&theOTResult);
974
975 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't allocate OT T_CALL structure, OTAlloc() = ",theOTResult);
976 SetErrorMessageAndBailIfNil(theSocketStruct->mRemoteAddrInfo,"MacSocket_connect: Can't allocate OT T_CALL structure, OTAlloc() returned nil");
977
978
979 PrepareForAsyncOperation(theSocketStruct,T_BINDCOMPLETE);
980
981 theOTResult = ::OTBind(theSocketStruct->mEndPointRef,nil,theSocketStruct->mAssignedAddrInfo);
982
983 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't bind OT endpoint, OTBind() = ",theOTResult);
984
985 BailIfError(MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTBindComplete)));
986
987 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't bind OT endpoint, OTBind() = ",theOTResult);
988
989 theSocketStruct->mEndpointIsBound = true;
990
991
992TCall sndCall;
993DNSAddress hostDNSAddress;
994
995 // Set up target address
996
997 sndCall.addr.buf = (UInt8 *) &hostDNSAddress;
998 sndCall.addr.len = ::OTInitDNSAddress(&hostDNSAddress,inTargetAddressAndPort);
999 sndCall.opt.buf = nil;
1000 sndCall.opt.len = 0;
1001 sndCall.udata.buf = nil;
1002 sndCall.udata.len = 0;
1003 sndCall.sequence = 0;
1004
1005 // Connect!
1006
1007 PrepareForAsyncOperation(theSocketStruct,T_CONNECT);
1008
1009 theOTResult = ::OTConnect(theSocketStruct->mEndPointRef,&sndCall,nil);
1010
1011 if (theOTResult == kOTNoDataErr)
1012 {
1013 theOTResult = noErr;
1014 }
1015
1016 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't connect OT endpoint, OTConnect() = ",theOTResult);
1017
1018 BailIfError(MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTConnect)));
1019
1020 if (theOTResult == kMacSocket_TimeoutErr)
1021 {
1022 SetErrorMessageAndBail("MacSocket_connect: Can't connect OT endpoint, OTConnect() = kMacSocket_TimeoutErr");
1023 }
1024
1025 else
1026 {
1027 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't connect OT endpoint, OTConnect() = ",theOTResult);
1028 }
1029
1030 theOTResult = ::OTRcvConnect(theSocketStruct->mEndPointRef,nil);
1031
1032 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_connect: Can't complete connect on OT endpoint, OTRcvConnect() = ",theOTResult);
1033
1034
1035 errCode = noErr;
1036
1037
1038#ifdef MACSOCKET_DEBUG
1039 printf("MacSocket_connect: connect completed\n");
1040#endif
1041
1042EXITPOINT:
1043
1044 if (theSocketStruct != nil)
1045 {
1046 theSocketStruct->mLastError = noErr;
1047
1048 CopyCStrToCStr("",theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1049
1050 if (errCode != noErr)
1051 {
1052 theSocketStruct->mLastError = errCode;
1053
1054 CopyCStrToCStr(GetErrorMessage(),theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1055 }
1056 }
1057
1058 errno = errCode;
1059
1060 return(errCode);
1061}
1062
1063
1064
1065
1066// Close a connection
1067
1068OSErr MacSocket_close(const int inSocketNum)
1069{
1070OSErr errCode = noErr;
1071SocketStruct *theSocketStruct = nil;
1072
1073
1074 if (!SocketIndexIsValid(inSocketNum))
1075 {
1076 SetErrorMessageAndBail("MacSocket_close: Invalid socket number specified");
1077 }
1078
1079
1080 theSocketStruct = &(sSockets[inSocketNum]);
1081
1082 if (theSocketStruct->mEndPointRef != kOTInvalidEndpointRef)
1083 {
1084 OTResult theOTResult = noErr;
1085
1086 // Try to play nice
1087
1088 if (theSocketStruct->mReceivedTOrdRel)
1089 {
1090 // Already did an OTRcvOrderlyDisconnect() in the notifier
1091
1092 if (theSocketStruct->mLocalEndIsConnected)
1093 {
1094 theOTResult = ::OTSndOrderlyDisconnect(theSocketStruct->mEndPointRef);
1095
1096 theSocketStruct->mLocalEndIsConnected = false;
1097 }
1098 }
1099
1100 else if (theSocketStruct->mLocalEndIsConnected)
1101 {
1102 theOTResult = ::OTSndOrderlyDisconnect(theSocketStruct->mEndPointRef);
1103
1104 theSocketStruct->mLocalEndIsConnected = false;
1105
1106 // Wait for other end to hang up too!
1107
1108// PrepareForAsyncOperation(theSocketStruct,T_ORDREL);
1109//
1110// errCode = MyBusyWait(theSocketStruct,false,&theOTResult,&(theSocketStruct->mReceivedTOrdRel));
1111 }
1112
1113
1114 if (theOTResult != noErr)
1115 {
1116 ::OTCloseProvider(theSocketStruct->mEndPointRef);
1117 }
1118
1119 else
1120 {
1121 theOTResult = ::OTCloseProvider(theSocketStruct->mEndPointRef);
1122 }
1123
1124 theSocketStruct->mEndPointRef = kOTInvalidEndpointRef;
1125
1126 errCode = theOTResult;
1127 }
1128
1129
1130 theSocketStruct->mIsInUse = false;
1131
1132
1133EXITPOINT:
1134
1135 if (theSocketStruct != nil)
1136 {
1137 theSocketStruct->mLastError = noErr;
1138
1139 CopyCStrToCStr("",theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1140
1141 if (errCode != noErr)
1142 {
1143 theSocketStruct->mLastError = errCode;
1144
1145 CopyCStrToCStr(GetErrorMessage(),theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1146 }
1147 }
1148
1149 errno = errCode;
1150
1151 return(errCode);
1152}
1153
1154
1155
1156
1157// Receive some bytes
1158
1159int MacSocket_recv(const int inSocketNum,void *outBuff,int outBuffLength,const Boolean inBlock)
1160{
1161OSErr errCode = noErr;
1162int totalBytesRead = 0;
1163SocketStruct *theSocketStruct = nil;
1164
1165
1166 SetErrorMessageAndBailIfNil(outBuff,"MacSocket_recv: Bad parameter, outBuff = nil");
1167
1168 if (outBuffLength <= 0)
1169 {
1170 SetErrorMessageAndBail("MacSocket_recv: Bad parameter, outBuffLength <= 0");
1171 }
1172
1173 if (!SocketIndexIsValid(inSocketNum))
1174 {
1175 SetErrorMessageAndBail("MacSocket_recv: Invalid socket number specified");
1176 }
1177
1178 theSocketStruct = &(sSockets[inSocketNum]);
1179
1180 if (!theSocketStruct->mLocalEndIsConnected)
1181 {
1182 SetErrorMessageAndBail("MacSocket_recv: Socket not connected");
1183 }
1184
1185 if (theSocketStruct->mReceivedTOrdRel)
1186 {
1187 totalBytesRead = 0;
1188
1189 goto EXITPOINT;
1190 }
1191
1192
1193 PrepareForAsyncOperation(theSocketStruct,0);
1194
1195 for (;;)
1196 {
1197 int bytesRead;
1198 OTResult theOTResult;
1199
1200
1201 theOTResult = ::OTRcv(theSocketStruct->mEndPointRef,(void *) ((unsigned long) outBuff + (unsigned long) totalBytesRead),outBuffLength - totalBytesRead,nil);
1202
1203 if (theOTResult >= 0)
1204 {
1205 bytesRead = theOTResult;
1206
1207#ifdef MACSOCKET_DEBUG
1208 printf("MacSocket_recv: read %d bytes in part\n",bytesRead);
1209#endif
1210 }
1211
1212 else if (theOTResult == kOTNoDataErr)
1213 {
1214 bytesRead = 0;
1215 }
1216
1217 else
1218 {
1219 SetErrorMessageAndLongIntAndBail("MacSocket_recv: Can't receive OT data, OTRcv() = ",theOTResult);
1220 }
1221
1222
1223 totalBytesRead += bytesRead;
1224
1225
1226 if (totalBytesRead <= 0)
1227 {
1228 if (theSocketStruct->mReceivedTOrdRel)
1229 {
1230 break;
1231 }
1232
1233 // This seems pretty stupid to me now. Maybe I'll delete this blocking garbage.
1234
1235 if (inBlock)
1236 {
1237 if (TimeoutElapsed(theSocketStruct))
1238 {
1239 SetErrorCodeAndMessageAndBail(kMacSocket_TimeoutErr,"MacSocket_recv: Receive operation timed-out");
1240 }
1241
1242 if (theSocketStruct->mIdleWaitCallback != nil)
1243 {
1244 theOTResult = (*(theSocketStruct->mIdleWaitCallback))(theSocketStruct->mUserRefPtr);
1245
1246 SetErrorMessageAndBailIfError(theOTResult,"MacSocket_recv: User cancelled operation");
1247 }
1248
1249 continue;
1250 }
1251 }
1252
1253
1254 break;
1255 }
1256
1257 errCode = noErr;
1258
1259
1260#ifdef MACSOCKET_DEBUG
1261 printf("MacSocket_recv: read %d bytes in total\n",totalBytesRead);
1262#endif
1263
1264
1265EXITPOINT:
1266
1267 if (theSocketStruct != nil)
1268 {
1269 theSocketStruct->mLastError = noErr;
1270
1271 CopyCStrToCStr("",theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1272
1273 if (errCode != noErr)
1274 {
1275 theSocketStruct->mLastError = errCode;
1276
1277 CopyCStrToCStr(GetErrorMessage(),theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1278 }
1279 }
1280
1281 errno = errCode;
1282
1283 return(totalBytesRead);
1284}
1285
1286
1287
1288// Send some bytes
1289
1290int MacSocket_send(const int inSocketNum,void *inBuff,int inBuffLength)
1291{
1292OSErr errCode = noErr;
1293int bytesSent = 0;
1294SocketStruct *theSocketStruct = nil;
1295
1296
1297 SetErrorMessageAndBailIfNil(inBuff,"MacSocket_send: Bad parameter, inBuff = nil");
1298
1299 if (inBuffLength <= 0)
1300 {
1301 SetErrorMessageAndBail("MacSocket_send: Bad parameter, inBuffLength <= 0");
1302 }
1303
1304 if (!SocketIndexIsValid(inSocketNum))
1305 {
1306 SetErrorMessageAndBail("MacSocket_send: Invalid socket number specified");
1307 }
1308
1309
1310 theSocketStruct = &(sSockets[inSocketNum]);
1311
1312 if (!theSocketStruct->mLocalEndIsConnected)
1313 {
1314 SetErrorMessageAndBail("MacSocket_send: Socket not connected");
1315 }
1316
1317
1318OTResult theOTResult;
1319
1320
1321 PrepareForAsyncOperation(theSocketStruct,0);
1322
1323 while (bytesSent < inBuffLength)
1324 {
1325 if (theSocketStruct->mIdleWaitCallback != nil)
1326 {
1327 theOTResult = (*(theSocketStruct->mIdleWaitCallback))(theSocketStruct->mUserRefPtr);
1328
1329 SetErrorMessageAndBailIfError(theOTResult,"MacSocket_send: User cancelled");
1330 }
1331
1332
1333 theOTResult = ::OTSnd(theSocketStruct->mEndPointRef,(void *) ((unsigned long) inBuff + bytesSent),inBuffLength - bytesSent,0);
1334
1335 if (theOTResult >= 0)
1336 {
1337 bytesSent += theOTResult;
1338
1339 theOTResult = noErr;
1340
1341 // Reset timer....
1342
1343 PrepareForAsyncOperation(theSocketStruct,0);
1344 }
1345
1346 if (theOTResult == kOTFlowErr)
1347 {
1348 if (TimeoutElapsed(theSocketStruct))
1349 {
1350 SetErrorCodeAndMessageAndBail(kMacSocket_TimeoutErr,"MacSocket_send: Send timed-out")
1351 }
1352
1353 theOTResult = noErr;
1354 }
1355
1356 SetErrorMessageAndLongIntAndBailIfError(theOTResult,"MacSocket_send: Can't send OT data, OTSnd() = ",theOTResult);
1357 }
1358
1359
1360 errCode = noErr;
1361
1362#ifdef MACSOCKET_DEBUG
1363 printf("MacSocket_send: sent %d bytes\n",bytesSent);
1364#endif
1365
1366
1367EXITPOINT:
1368
1369 if (theSocketStruct != nil)
1370 {
1371 theSocketStruct->mLastError = noErr;
1372
1373 CopyCStrToCStr("",theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1374
1375 if (errCode != noErr)
1376 {
1377 theSocketStruct->mLastError = errCode;
1378
1379 CopyCStrToCStr(GetErrorMessage(),theSocketStruct->mErrMessage,sizeof(theSocketStruct->mErrMessage));
1380 }
1381 }
1382
1383 if (errCode != noErr)
1384 {
1385 ::SysBeep(1);
1386 }
1387
1388 errno = errCode;
1389
1390 return(bytesSent);
1391}
1392
1393
1394
1395
1396
1397static OSStatus NegotiateIPReuseAddrOption(EndpointRef inEndpoint,const Boolean inEnableReuseIP)
1398{
1399OSStatus errCode;
1400UInt8 buf[kOTFourByteOptionSize];
1401TOption* theOTOption;
1402TOptMgmt theOTRequest;
1403TOptMgmt theOTResult;
1404
1405
1406 if (!OTIsSynchronous(inEndpoint))
1407 {
1408 SetErrorMessageAndBail("NegotiateIPReuseAddrOption: Open Transport endpoint is not synchronous");
1409 }
1410
1411 theOTRequest.opt.buf = buf;
1412 theOTRequest.opt.len = sizeof(buf);
1413 theOTRequest.flags = T_NEGOTIATE;
1414
1415 theOTResult.opt.buf = buf;
1416 theOTResult.opt.maxlen = kOTFourByteOptionSize;
1417
1418
1419 theOTOption = (TOption *) buf;
1420
1421 theOTOption->level = INET_IP;
1422 theOTOption->name = IP_REUSEADDR;
1423 theOTOption->len = kOTFourByteOptionSize;
1424 theOTOption->status = 0;
1425 *((UInt32 *) (theOTOption->value)) = inEnableReuseIP;
1426
1427 errCode = ::OTOptionManagement(inEndpoint,&theOTRequest,&theOTResult);
1428
1429 if (errCode == kOTNoError)
1430 {
1431 if (theOTOption->status != T_SUCCESS)
1432 {
1433 errCode = theOTOption->status;
1434 }
1435
1436 else
1437 {
1438 errCode = kOTNoError;
1439 }
1440 }
1441
1442
1443EXITPOINT:
1444
1445 errno = errCode;
1446
1447 return(errCode);
1448}
1449
1450
1451
1452
1453
1454// Some rough notes....
1455
1456
1457
1458// OTAckSends(ep);
1459// OTAckSends(ep) // enable AckSend option
1460// ......
1461// buf = OTAllocMem( nbytes); // Allocate nbytes of memory from OT
1462// OTSnd(ep, buf, nbytes, 0); // send a packet
1463// ......
1464// NotifyProc( .... void* theParam) // Notifier Proc
1465// case T_MEMORYRELEASED: // process event
1466// OTFreeMem( theParam); // free up memory
1467// break;
1468
1469
1470
1471/*
1472struct InetInterfaceInfo
1473{
1474 InetHost fAddress;
1475 InetHost fNetmask;
1476 InetHost fBroadcastAddr;
1477 InetHost fDefaultGatewayAddr;
1478 InetHost fDNSAddr;
1479 UInt16 fVersion;
1480 UInt16 fHWAddrLen;
1481 UInt8* fHWAddr;
1482 UInt32 fIfMTU;
1483 UInt8* fReservedPtrs[2];
1484 InetDomainName fDomainName;
1485 UInt32 fIPSecondaryCount;
1486 UInt8 fReserved[252];
1487};
1488typedef struct InetInterfaceInfo InetInterfaceInfo;
1489
1490
1491
1492((InetAddress *) addr.buf)->fHost
1493
1494struct TBind
1495{
1496 TNetbuf addr;
1497 OTQLen qlen;
1498};
1499
1500typedef struct TBind TBind;
1501
1502struct TNetbuf
1503{
1504 size_t maxlen;
1505 size_t len;
1506 UInt8* buf;
1507};
1508
1509typedef struct TNetbuf TNetbuf;
1510
1511
1512 struct InetAddress
1513{
1514 OTAddressType fAddressType; // always AF_INET
1515 InetPort fPort; // Port number
1516 InetHost fHost; // Host address in net byte order
1517 UInt8 fUnused[8]; // Traditional unused bytes
1518};
1519typedef struct InetAddress InetAddress;
1520*/
1521
1522
1523
1524/*
1525static pascal void Notifier(void* context, OTEventCode event, OTResult result, void* cookie)
1526{
1527EPInfo* epi = (EPInfo*) context;
1528
1529 switch (event)
1530 {
1531 case T_LISTEN:
1532 {
1533 DoListenAccept();
1534 return;
1535 }
1536
1537 case T_ACCEPTCOMPLETE:
1538 {
1539 if (result != kOTNoError)
1540 DBAlert1("Notifier: T_ACCEPTCOMPLETE - result %d",result);
1541 return;
1542 }
1543
1544 case T_PASSCON:
1545 {
1546 if (result != kOTNoError)
1547 {
1548 DBAlert1("Notifier: T_PASSCON result %d", result);
1549 return;
1550 }
1551
1552 OTAtomicAdd32(1, &gCntrConnections);
1553 OTAtomicAdd32(1, &gCntrTotalConnections);
1554 OTAtomicAdd32(1, &gCntrIntervalConnects);
1555
1556 if ( OTAtomicSetBit(&epi->stateFlags, kPassconBit) != 0 )
1557 {
1558 ReadData(epi);
1559 }
1560
1561 return;
1562 }
1563
1564 case T_DATA:
1565 {
1566 if ( OTAtomicSetBit(&epi->stateFlags, kPassconBit) != 0 )
1567 {
1568 ReadData(epi);
1569 }
1570
1571 return;
1572 }
1573
1574 case T_GODATA:
1575 {
1576 SendData(epi);
1577 return;
1578 }
1579
1580 case T_DISCONNECT:
1581 {
1582 DoRcvDisconnect(epi);
1583 return;
1584 }
1585
1586 case T_DISCONNECTCOMPLETE:
1587 {
1588 if (result != kOTNoError)
1589 DBAlert1("Notifier: T_DISCONNECT_COMPLETE result %d",result);
1590
1591 return;
1592 }
1593
1594 case T_MEMORYRELEASED:
1595 {
1596 OTAtomicAdd32(-1, &epi->outstandingSends);
1597 return;
1598 }
1599
1600 default:
1601 {
1602 DBAlert1("Notifier: unknown event <%x>", event);
1603 return;
1604 }
1605 }
1606}
1607*/
diff --git a/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.h b/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.h
new file mode 100644
index 0000000000..6e90a5bb44
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/GetHTTPS.src/MacSocket.h
@@ -0,0 +1,103 @@
1#pragma once
2
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8
9
10enum
11{
12 kMacSocket_TimeoutErr = -2
13};
14
15
16// Since MacSocket does busy waiting, I do a callback while waiting
17
18typedef OSErr (*MacSocket_IdleWaitCallback)(void *);
19
20
21// Call this before anything else!
22
23OSErr MacSocket_Startup(void);
24
25
26// Call this to cleanup before quitting
27
28OSErr MacSocket_Shutdown(void);
29
30
31// Call this to allocate a "socket" (reference number is returned in outSocketNum)
32// Note that inDoThreadSwitching is pretty much irrelevant right now, since I ignore it
33// The inTimeoutTicks parameter is applied during reads/writes of data
34// The inIdleWaitCallback parameter specifies a callback which is called during busy-waiting periods
35// The inUserRefPtr parameter is passed back to the idle-wait callback
36
37OSErr MacSocket_socket(int *outSocketNum,const Boolean inDoThreadSwitching,const long inTimeoutTicks,MacSocket_IdleWaitCallback inIdleWaitCallback,void *inUserRefPtr);
38
39
40// Call this to connect to an IP/DNS address
41// Note that inTargetAddressAndPort is in "IP:port" format-- e.g. 10.1.1.1:123
42
43OSErr MacSocket_connect(const int inSocketNum,char *inTargetAddressAndPort);
44
45
46// Call this to listen on a port
47// Since this a low-performance implementation, I allow a maximum of 1 (one!) incoming request when I listen
48
49OSErr MacSocket_listen(const int inSocketNum,const int inPortNum);
50
51
52// Call this to close a socket
53
54OSErr MacSocket_close(const int inSocketNum);
55
56
57// Call this to receive data on a socket
58// Most parameters' purpose are obvious-- except maybe "inBlock" which controls whether I wait for data or return immediately
59
60int MacSocket_recv(const int inSocketNum,void *outBuff,int outBuffLength,const Boolean inBlock);
61
62
63// Call this to send data on a socket
64
65int MacSocket_send(const int inSocketNum,void *inBuff,int inBuffLength);
66
67
68// If zero bytes were read in a call to MacSocket_recv(), it may be that the remote end has done a half-close
69// This function will let you check whether that's true or not
70
71Boolean MacSocket_RemoteEndIsClosing(const int inSocketNum);
72
73
74// Call this to see if the listen has completed after a call to MacSocket_listen()
75
76Boolean MacSocket_ListenCompleted(const int inSocketNum);
77
78
79// These really aren't very useful anymore
80
81Boolean MacSocket_LocalEndIsOpen(const int inSocketNum);
82Boolean MacSocket_RemoteEndIsOpen(const int inSocketNum);
83
84
85// You may wish to change the userRefPtr for a socket callback-- use this to do it
86
87void MacSocket_SetUserRefPtr(const int inSocketNum,void *inNewRefPtr);
88
89
90// Call these to get the socket's IP:port descriptor
91
92void MacSocket_GetLocalIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength);
93void MacSocket_GetRemoteIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength);
94
95
96// Call this to get error info from a socket
97
98void MacSocket_GetSocketErrorInfo(const int inSocketNum,int *outSocketErrCode,char *outSocketErrString,const int inSocketErrStringMaxLength);
99
100
101#ifdef __cplusplus
102}
103#endif
diff --git a/src/lib/libssl/src/MacOS/OpenSSL.mcp.hqx b/src/lib/libssl/src/MacOS/OpenSSL.mcp.hqx
new file mode 100644
index 0000000000..2efa49ac01
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/OpenSSL.mcp.hqx
@@ -0,0 +1,4880 @@
1(This file must be converted with BinHex 4.0)
2
3:#dp`C@j68d`ZE@0`!%e08(*$9dP&!!!!!j)H!!!!!)X-Bfp[E!!!!!-!!!%S!!0
4ipJ!$HKi!!"J!!!!"!!%#!3!!!!!!!!!!!%0[C'9ABA*bD@pb)&"bEfTPBh3!!!!
5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"(CA4)9&4
1038b"38%-k4'9LG@GRCA)J8R9ZG'PYC3"(CA4)9&438b"38%-k8fpeFQ0P)&4bC@9
11c!%GPG%K89&"6)&"33cT$GA0dEfdJ5f9jGfpbC(-!4f9d5&488&-J8&"$1N&MBf9
12cFb"3BA4SF`"(CA4)9&438b"38%-k9'&bCf9d)&0PG(4TEQGc!%GPG%K89&"6)&"
1333cT'D@aP)%eKF("TEQGc!%GPG%K89&"6)&"33cT#G@PXC#"&H(4bBA-!4f9d5&4
1488&-J8&"$1N4PBR9RCf9b)&4KFQGPG!"(CA4)9&438b"38%-k0MK,)%0[C'9(C@i
15!4f9d5&488&-J8&"$1MBi5b"%DA0KFh0PE@*XCA)!4f9d5&488&-J8&"$1MBi5b"
16(E'pLB@`J6h"dD@eTHQ9b!%GPG%K89&"6)&"33cSf1%XJ6'PZDf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3!!r8C*6%8"!!$r4NP-43%!!3C'58a&!3!""dC*6%8"!!%
4601)4NP-43%!!3P'58a&!3!""8C*6%8"!!%%4NP-43%!!30'58a&!3!!cdC*6%8"!!$
460204NP-43%!!-j'58a&!3!!e8C*6%8"!!$[4NP-43%!!0&'58a&!3!!edC*6%8"!!$
460334NP-43%!!0P'58a&!3!!f%C*6%8"!!'A4NP-43%!!CK(8P93!!!!!!!!!"3%D'e
4604KB`!!!!&'58a&!3!"#NG599!!!!!!!!!!&34TC'9K!!!!"8C*6%8"!!%,4NP-43%
4605!!3a'58a&!3!"$NC*6%8"!!%04NP-43%!!3p(8P93!!!!!!!!!"B&E'KKFfJ!!!!
4606#4NP-43%!!4"'58a&!3!"%8G599!!!!!!!!!!&`0YC$)!!!!#4NP-43%!!4*'58a
4607&!3!"%dG599!!!!!!!!!!'!0YC$8!!!!#4NP-43%!!44'58a&!3!"&8G599!!!!!
4608!!!!!'34YC'-b!!!!!NC*6%8"!!%@4NP-43%!!4G(8P93!!!!!!!!!"S(Ef*UC@0
4609dF`!!!!4'58a&!3!"'dC*6%8"!!%B4NP-43%!!4T'58a&!3!"'8G599!!!!!!!!!
4610!'`0`C@d!!!!'4NP-43%!!5&'58a&!3!")%C*6%8"!!%H4NP-43%!!4p'58a&!3!
4611"(%C*6%8"!!%G4e*98!!!!!!!!!!F"R"VBh-a-J!!!""'58a&!3!")NC*6%8"!!%
4612M4NP-43%!!54'58a&!3!"*8C*6%8"!!%Q4NP-43%!!5G'58a&!3!"+%C*6%8"!!%
4613T4NP-43%!!5T'58a&!3!"+dC*6%8"!!%X4NP-43%!!5e'58a&!3!",NC*6%8"!!%
4614[4NP-43%!!CP'58a&!3!"-%G599!!!!!!!!!!(39`Df0c0`!!!!C'58a&!3!"-NC
4615*6%8"!!%c4NP-43%!!6&'58a&!3!"R%C*6%8"!!'D4NP-43%!!CY(8P93!!!!!!!
4616!!"i%FQ&ZC!!!!!4'58a&!3!"0%C*6%8"!!%e4NP-43%!!6C'58a&!3!"TdG599!
4617!!!!!!!!!(`0bBc)!!!!&4NP-43%!!6T'58a&!3!"1dC*6%8"!!%j4NP-43%!!6G
4618'58a&!3!"1%G599!!!!!!!!!!)!0bBc3!!!!#4NP-43%!!6e'58a&!3!"2%G599!
4619!!!!!!!!!)30bBc8!!!!&4NP-43%!!8*'58a&!3!"3%C*6%8"!!&"4NP-43%!!6j
4620'58a&!3!"2dG599!!!!!!!!!!)JCbDA"PE@3!!!!#4NP-43%!!80'58a&!3!"4%G
4621599!!!!!!!!!!)`0bFf%!!!!-4NP-43%!!89'58a&!3!"4dC*6%8"!!&)4NP-43%
4622!!8e'58a&!3!"6%C*6%8"!!&'4NP-43%!!8Y'58a&!3!"6NC*6%8"!!&*4NP-43%
4623!!8T'58a&!3!"R8C*6%8"!!'H4e*98!!!!!!!!!!N!h0SB3!!!!4'58a&!3!"88C
4624*6%8"!!&24NP-43%!!9*'58a&!3!"8%G599!!!!!!!!!!*39cG'&MD`!!!!&'58a
4625&!3!"8dG599!!!!!!!!!!*JCdH(4IC')!!!!"4NP-43%!!94(8P93!!!!!!!!!#F
4626%H$8`13!!!"9'58a&!3!"A%C*6%8"!!&E4NP-43%!!@&'58a&!3!"@NC*6%8"!!&
4627J4NP-43%!!@*'58a&!3!"JdC*6%8"!!&Q4NP-43%!!@0'58a&!3!"@%C*6%8"!!&
4628G4NP-43%!!9G'58a&!3!"C8C*6%8"!!&H4NP-43%!!9P'58a&!3!"AdC*6%8"!!&
4629R4NP-43%!!@4'58a&!3!"K%C*6%8"!!&94NP-43%!!9C(8P93!!!!!!!!!#J'H$8
4630`1ABc!!!!&8C*6%8"!!&V4NP-43%!!@a'58a&!3!"E8C*6%8"!!&a4NP-43%!!A0
4631'58a&!3!"G8C*6%8"!!&h4NP-43%!!AT'58a&!3!"D%C*6%8"!!&b4NP-43%!!@T
4632'58a&!3!"H%C*6%8"!!&T4NP-43%!!AC'58a&!3!"G%C*6%8"!!&`4NP-43%!!AP
4633'58a&!3!"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!!!$2(J!!!!3EA4`D3!!!!J
4874!!!!!!!!!!!!$2)J!!!!JEA4cE!!!!!J!!!!!!!!!!!!$2+J!!!A8EA4XE`!!!!J
4875!!!!!!!!!!!!$D9S!!"$%EA4RE!!!!qJ!!!!!!!!!!!!$8d!!!!!XE@pdD3!!!!!
4876!!!!!!!!!!!!$8f`!!"1!8%acG!!19TJ!!!$*!!!!!!!"&P)!!!)XEA"cD3!!!qJ
4877!!!!!!!!!!!!$D1S!!!!3EA0dF!!!!!)!!!!!!!!!!!!$D2S!!!!3EA0dF!!!!!8
4878!!!!!!!!!!!!!@NJ!!!!SEA0dD3!!!qJ!!!!!!!!!!!!$D6)!!!!SEA0dD3!!!!!
4879!!!!!!!!!!!!!@R!!!!!-E@&XE!!!!!!!!!!!!!!!!!!$6(`!!!$%E@&`E!!!!!!
4880!!!!!!!!!!-eY!!!:
diff --git a/src/lib/libssl/src/MacOS/Randomizer.cpp b/src/lib/libssl/src/MacOS/Randomizer.cpp
new file mode 100644
index 0000000000..cceb6bde44
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/Randomizer.cpp
@@ -0,0 +1,476 @@
1/*
2------- Strong random data generation on a Macintosh (pre - OS X) ------
3
4-- GENERAL: We aim to generate unpredictable bits without explicit
5 user interaction. A general review of the problem may be found
6 in RFC 1750, "Randomness Recommendations for Security", and some
7 more discussion, of general and Mac-specific issues has appeared
8 in "Using and Creating Cryptographic- Quality Random Numbers" by
9 Jon Callas (www.merrymeet.com/jon/usingrandom.html).
10
11 The data and entropy estimates provided below are based on my
12 limited experimentation and estimates, rather than by any
13 rigorous study, and the entropy estimates tend to be optimistic.
14 They should not be considered absolute.
15
16 Some of the information being collected may be correlated in
17 subtle ways. That includes mouse positions, timings, and disk
18 size measurements. Some obvious correlations will be eliminated
19 by the programmer, but other, weaker ones may remain. The
20 reliability of the code depends on such correlations being
21 poorly understood, both by us and by potential interceptors.
22
23 This package has been planned to be used with OpenSSL, v. 0.9.5.
24 It requires the OpenSSL function RAND_add.
25
26-- OTHER WORK: Some source code and other details have been
27 published elsewhere, but I haven't found any to be satisfactory
28 for the Mac per se:
29
30 * The Linux random number generator (by Theodore Ts'o, in
31 drivers/char/random.c), is a carefully designed open-source
32 crypto random number package. It collects data from a variety
33 of sources, including mouse, keyboard and other interrupts.
34 One nice feature is that it explicitly estimates the entropy
35 of the data it collects. Some of its features (e.g. interrupt
36 timing) cannot be reliably exported to the Mac without using
37 undocumented APIs.
38
39 * Truerand by Don P. Mitchell and Matt Blaze uses variations
40 between different timing mechanisms on the same system. This
41 has not been tested on the Mac, but requires preemptive
42 multitasking, and is hardware-dependent, and can't be relied
43 on to work well if only one oscillator is present.
44
45 * Cryptlib's RNG for the Mac (RNDMAC.C by Peter Gutmann),
46 gathers a lot of information about the machine and system
47 environment. Unfortunately, much of it is constant from one
48 startup to the next. In other words, the random seed could be
49 the same from one day to the next. Some of the APIs are
50 hardware-dependent, and not all are compatible with Carbon (OS
51 X). Incidentally, the EGD library is based on the UNIX entropy
52 gathering methods in cryptlib, and isn't suitable for MacOS
53 either.
54
55 * Mozilla (and perhaps earlier versions of Netscape) uses the
56 time of day (in seconds) and an uninitialized local variable
57 to seed the random number generator. The time of day is known
58 to an outside interceptor (to within the accuracy of the
59 system clock). The uninitialized variable could easily be
60 identical between subsequent launches of an application, if it
61 is reached through the same path.
62
63 * OpenSSL provides the function RAND_screen(), by G. van
64 Oosten, which hashes the contents of the screen to generate a
65 seed. This is not useful for an extension or for an
66 application which launches at startup time, since the screen
67 is likely to look identical from one launch to the next. This
68 method is also rather slow.
69
70 * Using variations in disk drive seek times has been proposed
71 (Davis, Ihaka and Fenstermacher, world.std.com/~dtd/;
72 Jakobsson, Shriver, Hillyer and Juels,
73 www.bell-labs.com/user/shriver/random.html). These variations
74 appear to be due to air turbulence inside the disk drive
75 mechanism, and are very strongly unpredictable. Unfortunately
76 this technique is slow, and some implementations of it may be
77 patented (see Shriver's page above.) It of course cannot be
78 used with a RAM disk.
79
80-- TIMING: On the 601 PowerPC the time base register is guaranteed
81 to change at least once every 10 addi instructions, i.e. 10
82 cycles. On a 60 MHz machine (slowest PowerPC) this translates to
83 a resolution of 1/6 usec. Newer machines seem to be using a 10
84 cycle resolution as well.
85
86 For 68K Macs, the Microseconds() call may be used. See Develop
87 issue 29 on the Apple developer site
88 (developer.apple.com/dev/techsupport/develop/issue29/minow.html)
89 for information on its accuracy and resolution. The code below
90 has been tested only on PowerPC based machines.
91
92 The time from machine startup to the launch of an application in
93 the startup folder has a variance of about 1.6 msec on a new G4
94 machine with a defragmented and optimized disk, most extensions
95 off and no icons on the desktop. This can be reasonably taken as
96 a lower bound on the variance. Most of this variation is likely
97 due to disk seek time variability. The distribution of startup
98 times is probably not entirely even or uncorrelated. This needs
99 to be investigated, but I am guessing that it not a majpor
100 problem. Entropy = log2 (1600/0.166) ~= 13 bits on a 60 MHz
101 machine, ~16 bits for a 450 MHz machine.
102
103 User-launched application startup times will have a variance of
104 a second or more relative to machine startup time. Entropy >~22
105 bits.
106
107 Machine startup time is available with a 1-second resolution. It
108 is predictable to no better a minute or two, in the case of
109 people who show up punctually to work at the same time and
110 immediately start their computer. Using the scheduled startup
111 feature (when available) will cause the machine to start up at
112 the same time every day, making the value predictable. Entropy
113 >~7 bits, or 0 bits with scheduled startup.
114
115 The time of day is of course known to an outsider and thus has 0
116 entropy if the system clock is regularly calibrated.
117
118-- KEY TIMING: A very fast typist (120 wpm) will have a typical
119 inter-key timing interval of 100 msec. We can assume a variance
120 of no less than 2 msec -- maybe. Do good typists have a constant
121 rhythm, like drummers? Since what we measure is not the
122 key-generated interrupt but the time at which the key event was
123 taken off the event queue, our resolution is roughly the time
124 between process switches, at best 1 tick (17 msec). I therefore
125 consider this technique questionable and not very useful for
126 obtaining high entropy data on the Mac.
127
128-- MOUSE POSITION AND TIMING: The high bits of the mouse position
129 are far from arbitrary, since the mouse tends to stay in a few
130 limited areas of the screen. I am guessing that the position of
131 the mouse is arbitrary within a 6 pixel square. Since the mouse
132 stays still for long periods of time, it should be sampled only
133 after it was moved, to avoid correlated data. This gives an
134 entropy of log2(6*6) ~= 5 bits per measurement.
135
136 The time during which the mouse stays still can vary from zero
137 to, say, 5 seconds (occasionally longer). If the still time is
138 measured by sampling the mouse during null events, and null
139 events are received once per tick, its resolution is 1/60th of a
140 second, giving an entropy of log2 (60*5) ~= 8 bits per
141 measurement. Since the distribution of still times is uneven,
142 this estimate is on the high side.
143
144 For simplicity and compatibility across system versions, the
145 mouse is to be sampled explicitly (e.g. in the event loop),
146 rather than in a time manager task.
147
148-- STARTUP DISK TOTAL FILE SIZE: Varies typically by at least 20k
149 from one startup to the next, with 'minimal' computer use. Won't
150 vary at all if machine is started again immediately after
151 startup (unless virtual memory is on), but any application which
152 uses the web and caches information to disk is likely to cause
153 this much variation or more. The variation is probably not
154 random, but I don't know in what way. File sizes tend to be
155 divisible by 4 bytes since file format fields are often
156 long-aligned. Entropy > log2 (20000/4) ~= 12 bits.
157
158-- STARTUP DISK FIRST AVAILABLE ALLOCATION BLOCK: As the volume
159 gets fragmented this could be anywhere in principle. In a
160 perfectly unfragmented volume this will be strongly correlated
161 with the total file size on the disk. With more fragmentation
162 comes less certainty. I took the variation in this value to be
163 1/8 of the total file size on the volume.
164
165-- SYSTEM REQUIREMENTS: The code here requires System 7.0 and above
166 (for Gestalt and Microseconds calls). All the calls used are
167 Carbon-compatible.
168*/
169
170/*------------------------------ Includes ----------------------------*/
171
172#include "Randomizer.h"
173
174// Mac OS API
175#include <Files.h>
176#include <Folders.h>
177#include <Events.h>
178#include <Processes.h>
179#include <Gestalt.h>
180#include <Resources.h>
181#include <LowMem.h>
182
183// Standard C library
184#include <stdlib.h>
185#include <math.h>
186
187/*---------------------- Function declarations -----------------------*/
188
189// declared in OpenSSL/crypto/rand/rand.h
190extern "C" void RAND_add (const void *buf, int num, double entropy);
191
192unsigned long GetPPCTimer (bool is601); // Make it global if needed
193 // elsewhere
194
195/*---------------------------- Constants -----------------------------*/
196
197#define kMouseResolution 6 // Mouse position has to differ
198 // from the last one by this
199 // much to be entered
200#define kMousePositionEntropy 5.16 // log2 (kMouseResolution**2)
201#define kTypicalMouseIdleTicks 300.0 // I am guessing that a typical
202 // amount of time between mouse
203 // moves is 5 seconds
204#define kVolumeBytesEntropy 12.0 // about log2 (20000/4),
205 // assuming a variation of 20K
206 // in total file size and
207 // long-aligned file formats.
208#define kApplicationUpTimeEntropy 6.0 // Variance > 1 second, uptime
209 // in ticks
210#define kSysStartupEntropy 7.0 // Entropy for machine startup
211 // time
212
213
214/*------------------------ Function definitions ----------------------*/
215
216CRandomizer::CRandomizer (void)
217{
218 long result;
219
220 mSupportsLargeVolumes =
221 (Gestalt(gestaltFSAttr, &result) == noErr) &&
222 ((result & (1L << gestaltFSSupports2TBVols)) != 0);
223
224 if (Gestalt (gestaltNativeCPUtype, &result) != noErr)
225 {
226 mIsPowerPC = false;
227 mIs601 = false;
228 }
229 else
230 {
231 mIs601 = (result == gestaltCPU601);
232 mIsPowerPC = (result >= gestaltCPU601);
233 }
234 mLastMouse.h = mLastMouse.v = -10; // First mouse will
235 // always be recorded
236 mLastPeriodicTicks = TickCount();
237 GetTimeBaseResolution ();
238
239 // Add initial entropy
240 AddTimeSinceMachineStartup ();
241 AddAbsoluteSystemStartupTime ();
242 AddStartupVolumeInfo ();
243 AddFiller ();
244}
245
246void CRandomizer::PeriodicAction (void)
247{
248 AddCurrentMouse ();
249 AddNow (0.0); // Should have a better entropy estimate here
250 mLastPeriodicTicks = TickCount();
251}
252
253/*------------------------- Private Methods --------------------------*/
254
255void CRandomizer::AddCurrentMouse (void)
256{
257 Point mouseLoc;
258 unsigned long lastCheck; // Ticks since mouse was last
259 // sampled
260
261#if TARGET_API_MAC_CARBON
262 GetGlobalMouse (&mouseLoc);
263#else
264 mouseLoc = LMGetMouseLocation();
265#endif
266
267 if (labs (mLastMouse.h - mouseLoc.h) > kMouseResolution/2 &&
268 labs (mLastMouse.v - mouseLoc.v) > kMouseResolution/2)
269 AddBytes (&mouseLoc, sizeof (mouseLoc),
270 kMousePositionEntropy);
271
272 if (mLastMouse.h == mouseLoc.h && mLastMouse.v == mouseLoc.v)
273 mMouseStill ++;
274 else
275 {
276 double entropy;
277
278 // Mouse has moved. Add the number of measurements for
279 // which it's been still. If the resolution is too
280 // coarse, assume the entropy is 0.
281
282 lastCheck = TickCount() - mLastPeriodicTicks;
283 if (lastCheck <= 0)
284 lastCheck = 1;
285 entropy = log2l
286 (kTypicalMouseIdleTicks/(double)lastCheck);
287 if (entropy < 0.0)
288 entropy = 0.0;
289 AddBytes (&mMouseStill, sizeof (mMouseStill), entropy);
290 mMouseStill = 0;
291 }
292 mLastMouse = mouseLoc;
293}
294
295void CRandomizer::AddAbsoluteSystemStartupTime (void)
296{
297 unsigned long now; // Time in seconds since
298 // 1/1/1904
299 GetDateTime (&now);
300 now -= TickCount() / 60; // Time in ticks since machine
301 // startup
302 AddBytes (&now, sizeof (now), kSysStartupEntropy);
303}
304
305void CRandomizer::AddTimeSinceMachineStartup (void)
306{
307 AddNow (1.5); // Uncertainty in app startup
308 // time is > 1.5 msec (for
309 // automated app startup).
310}
311
312void CRandomizer::AddAppRunningTime (void)
313{
314 ProcessSerialNumber PSN;
315 ProcessInfoRec ProcessInfo;
316
317 ProcessInfo.processInfoLength = sizeof (ProcessInfoRec);
318 ProcessInfo.processName = nil;
319 ProcessInfo.processAppSpec = nil;
320
321 GetCurrentProcess (&PSN);
322 GetProcessInformation (&PSN, &ProcessInfo);
323
324 // Now add the amount of time in ticks that the current process
325 // has been active
326
327 AddBytes (&ProcessInfo, sizeof (ProcessInfoRec),
328 kApplicationUpTimeEntropy);
329}
330
331void CRandomizer::AddStartupVolumeInfo (void)
332{
333 short vRefNum;
334 long dirID;
335 XVolumeParam pb;
336 OSErr err;
337
338 if (!mSupportsLargeVolumes)
339 return;
340
341 FindFolder (kOnSystemDisk, kSystemFolderType, kDontCreateFolder,
342 &vRefNum, &dirID);
343 pb.ioVRefNum = vRefNum;
344 pb.ioCompletion = 0;
345 pb.ioNamePtr = 0;
346 pb.ioVolIndex = 0;
347 err = PBXGetVolInfoSync (&pb);
348 if (err != noErr)
349 return;
350
351 // Base the entropy on the amount of space used on the disk and
352 // on the next available allocation block. A lot else might be
353 // unpredictable, so might as well toss the whole block in. See
354 // comments for entropy estimate justifications.
355
356 AddBytes (&pb, sizeof (pb),
357 kVolumeBytesEntropy +
358 log2l (((pb.ioVTotalBytes.hi - pb.ioVFreeBytes.hi)
359 * 4294967296.0D +
360 (pb.ioVTotalBytes.lo - pb.ioVFreeBytes.lo))
361 / pb.ioVAlBlkSiz - 3.0));
362}
363
364/*
365 On a typical startup CRandomizer will come up with about 60
366 bits of good, unpredictable data. Assuming no more input will
367 be available, we'll need some more lower-quality data to give
368 OpenSSL the 128 bits of entropy it desires. AddFiller adds some
369 relatively predictable data into the soup.
370*/
371
372void CRandomizer::AddFiller (void)
373{
374 struct
375 {
376 ProcessSerialNumber psn; // Front process serial
377 // number
378 RGBColor hiliteRGBValue; // User-selected
379 // highlight color
380 long processCount; // Number of active
381 // processes
382 long cpuSpeed; // Processor speed
383 long totalMemory; // Total logical memory
384 // (incl. virtual one)
385 long systemVersion; // OS version
386 short resFile; // Current resource file
387 } data;
388
389 GetNextProcess ((ProcessSerialNumber*) kNoProcess);
390 while (GetNextProcess (&data.psn) == noErr)
391 data.processCount++;
392 GetFrontProcess (&data.psn);
393 LMGetHiliteRGB (&data.hiliteRGBValue);
394 Gestalt (gestaltProcClkSpeed, &data.cpuSpeed);
395 Gestalt (gestaltLogicalRAMSize, &data.totalMemory);
396 Gestalt (gestaltSystemVersion, &data.systemVersion);
397 data.resFile = CurResFile ();
398
399 // Here we pretend to feed the PRNG completely random data. This
400 // is of course false, as much of the above data is predictable
401 // by an outsider. At this point we don't have any more
402 // randomness to add, but with OpenSSL we must have a 128 bit
403 // seed before we can start. We just add what we can, without a
404 // real entropy estimate, and hope for the best.
405
406 AddBytes (&data, sizeof(data), 8.0 * sizeof(data));
407 AddCurrentMouse ();
408 AddNow (1.0);
409}
410
411//------------------- LOW LEVEL ---------------------
412
413void CRandomizer::AddBytes (void *data, long size, double entropy)
414{
415 RAND_add (data, size, entropy * 0.125); // Convert entropy bits
416 // to bytes
417}
418
419void CRandomizer::AddNow (double millisecondUncertainty)
420{
421 long time = SysTimer();
422 AddBytes (&time, sizeof (time), log2l (millisecondUncertainty *
423 mTimebaseTicksPerMillisec));
424}
425
426//----------------- TIMING SUPPORT ------------------
427
428void CRandomizer::GetTimeBaseResolution (void)
429{
430#ifdef __powerc
431 long speed;
432
433 // gestaltProcClkSpeed available on System 7.5.2 and above
434 if (Gestalt (gestaltProcClkSpeed, &speed) != noErr)
435 // Only PowerPCs running pre-7.5.2 are 60-80 MHz
436 // machines.
437 mTimebaseTicksPerMillisec = 6000.0D;
438 // Assume 10 cycles per clock update, as in 601 spec. Seems true
439 // for later chips as well.
440 mTimebaseTicksPerMillisec = speed / 1.0e4D;
441#else
442 // 68K VIA-based machines (see Develop Magazine no. 29)
443 mTimebaseTicksPerMillisec = 783.360D;
444#endif
445}
446
447unsigned long CRandomizer::SysTimer (void) // returns the lower 32
448 // bit of the chip timer
449{
450#ifdef __powerc
451 return GetPPCTimer (mIs601);
452#else
453 UnsignedWide usec;
454 Microseconds (&usec);
455 return usec.lo;
456#endif
457}
458
459#ifdef __powerc
460// The timebase is available through mfspr on 601, mftb on later chips.
461// Motorola recommends that an 601 implementation map mftb to mfspr
462// through an exception, but I haven't tested to see if MacOS actually
463// does this. We only sample the lower 32 bits of the timer (i.e. a
464// few minutes of resolution)
465
466asm unsigned long GetPPCTimer (register bool is601)
467{
468 cmplwi is601, 0 // Check if 601
469 bne _601 // if non-zero goto _601
470 mftb r3 // Available on 603 and later.
471 blr // return with result in r3
472_601:
473 mfspr r3, spr5 // Available on 601 only.
474 // blr inserted automatically
475}
476#endif
diff --git a/src/lib/libssl/src/MacOS/Randomizer.h b/src/lib/libssl/src/MacOS/Randomizer.h
new file mode 100644
index 0000000000..565537b15d
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/Randomizer.h
@@ -0,0 +1,43 @@
1
2// Gathers unpredictable system data to be used for generating
3// random bits
4
5#include <MacTypes.h>
6
7class CRandomizer
8{
9public:
10 CRandomizer (void);
11 void PeriodicAction (void);
12
13private:
14
15 // Private calls
16
17 void AddTimeSinceMachineStartup (void);
18 void AddAbsoluteSystemStartupTime (void);
19 void AddAppRunningTime (void);
20 void AddStartupVolumeInfo (void);
21 void AddFiller (void);
22
23 void AddCurrentMouse (void);
24 void AddNow (double millisecondUncertainty);
25 void AddBytes (void *data, long size, double entropy);
26
27 void GetTimeBaseResolution (void);
28 unsigned long SysTimer (void);
29
30 // System Info
31 bool mSupportsLargeVolumes;
32 bool mIsPowerPC;
33 bool mIs601;
34
35 // Time info
36 double mTimebaseTicksPerMillisec;
37 unsigned long mLastPeriodicTicks;
38
39 // Mouse info
40 long mSamplePeriod;
41 Point mLastMouse;
42 long mMouseStill;
43};
diff --git a/src/lib/libssl/src/MacOS/TODO b/src/lib/libssl/src/MacOS/TODO
new file mode 100644
index 0000000000..903eb133de
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/TODO
@@ -0,0 +1,18 @@
1-------------------------------------------------------------------
2Verify server certificate
3-------------------------------------------------------------------
4Currently omitted from the project:
5
6 crypto/tmdiff.c
7 crypto/bio/bss_conn.c
8 crypto/bio/b_sock.c
9 crypto/bio/bss_acpt.c
10 crypto/bio/bss_log.h
11
12-------------------------------------------------------------------
13Build libraries to link with...
14-------------------------------------------------------------------
15Port openssl application.
16-------------------------------------------------------------------
17BN optimizations (currently PPC version is compiled with BN_LLONG)
18-------------------------------------------------------------------
diff --git a/src/lib/libssl/src/MacOS/_MWERKS_GUSI_prefix.h b/src/lib/libssl/src/MacOS/_MWERKS_GUSI_prefix.h
new file mode 100644
index 0000000000..fe6b5387d6
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/_MWERKS_GUSI_prefix.h
@@ -0,0 +1,9 @@
1#include <MacHeaders.h>
2#define B_ENDIAN
3#ifdef __POWERPC__
4#pragma longlong on
5#endif
6#if 1
7#define MAC_OS_GUSI_SOURCE
8#endif
9#define MONOLITH
diff --git a/src/lib/libssl/src/MacOS/_MWERKS_prefix.h b/src/lib/libssl/src/MacOS/_MWERKS_prefix.h
new file mode 100644
index 0000000000..2189da753b
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/_MWERKS_prefix.h
@@ -0,0 +1,9 @@
1#include <MacHeaders.h>
2#define B_ENDIAN
3#ifdef __POWERPC__
4#pragma longlong on
5#endif
6#if 0
7#define MAC_OS_GUSI_SOURCE
8#endif
9#define MONOLITH
diff --git a/src/lib/libssl/src/MacOS/buildinf.h b/src/lib/libssl/src/MacOS/buildinf.h
new file mode 100644
index 0000000000..90875b6e2f
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/buildinf.h
@@ -0,0 +1,5 @@
1#ifndef MK1MF_BUILD
2# define CFLAGS "-DB_ENDIAN"
3# define PLATFORM "macos"
4# define DATE "Sun Feb 27 19:44:16 MET 2000"
5#endif
diff --git a/src/lib/libssl/src/MacOS/mklinks.as.hqx b/src/lib/libssl/src/MacOS/mklinks.as.hqx
new file mode 100644
index 0000000000..fe3e7d53da
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/mklinks.as.hqx
@@ -0,0 +1,820 @@
1(This file must be converted with BinHex 4.0)
2
3:#QeVE'PZDh-ZBA-!39"36'&`E(3J!!!!!!!!!*LiI6m!!!!!!3!!!*G#!!#@3J!
4!!AChFQPd!!!!K3)"!3m(Fh9`F'pbG!!!!)B#!3%$"(0eFQ8!!!#(!J-%"!3("3C
5cGfPdBfJ!!!#)!J%"#39cH@jMD!!!!)N#"J%$!`-&"3-'FhPcG'9Y!!!!LJ)&"3)
6%!J8("!-#!`4dB@*X!!!!L`))!3-$!`-$!`-$"(4PE'`!!!#-!J)"#38$G'KP!!!
7!M3))(J)@!Ki#!J))!K)#!`)B!Kd%G'KPE3!!!)i#!J%&#`4dD'9j!!!!M`)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C'8
809!!J!!#[aZ!!3+BfC[E!`%aJ!9!!peER4TG'aPC#"QEfaNCA)!!J!!$!5h!%i!5%e
810KBfPZG'pcD#")4$T%CA0VG'p`)%C[E'4PFMT*EQ0[E@PZCcT[F'9ZFh0X,90139!
811Y-6Nj16%b-6%kBh*jF(4[1RJe-$Pf-`!#!!!"r,%!!!(mX!!!!Ib[!!!"r+i!!'&
812cBh)!!3!-qYlHV3!!!3!!!*G#!!#@3J!!!AB!!$-8-0J!!!!F!AB!$h0MFhS!!!#
813#6Np853!!!)jcBh"d!!!!QP4&@&3!!3#QFh4jE!!!!,j$6d4&!!%!bN*14%`!!!$
814LBA"XG!!!!1j'8N9'!!!!qNP$6L-!!!%'D@0X0!!!!4*TBh-M!!!"(QPMFc3!!!%
815UD'CNFJ!!!6C659T&!!!"3PG3Eh-!!!&1!!$rr`!!!!!!!!!!!)$rre!!!"i!!!!
816!!)$rr`!!"cJ#DH#m"'Mrr`!!!*S!!!!!%iRrr`!!"Pi!!!!!"'Mrr`!!!53!!!!
817!!!$rrb!!!9)!!!!!!!(rra3!!@i#DG`%!)$rr`!!!Pi#DH"X!!$rr`!!!Ri!!!!
818!!)$rr`!!!S-#DH"d!*Err`!!!Si!!!!!!*Err`!!!j)!!!!!!*Err`!!"CB#DH%
819i!*Err`!!"GS#DH%dkF$rr`!!"[`!!!!!rrrrr`!!"a)!!!!!!)$rr`!!"b!!!!!
820!*4S:
diff --git a/src/lib/libssl/src/MacOS/opensslconf.h b/src/lib/libssl/src/MacOS/opensslconf.h
new file mode 100644
index 0000000000..ad557cc06a
--- /dev/null
+++ b/src/lib/libssl/src/MacOS/opensslconf.h
@@ -0,0 +1,116 @@
1/* MacOS/opensslconf.h */
2
3#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
4#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
5#define OPENSSLDIR "/usr/local/ssl"
6#endif
7#endif
8
9#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
10#define IDEA_INT unsigned int
11#endif
12
13#if defined(HEADER_MD2_H) && !defined(MD2_INT)
14#define MD2_INT unsigned int
15#endif
16
17#if defined(HEADER_RC2_H) && !defined(RC2_INT)
18/* I need to put in a mod for the alpha - eay */
19#define RC2_INT unsigned int
20#endif
21
22#if defined(HEADER_RC4_H)
23#if !defined(RC4_INT)
24/* using int types make the structure larger but make the code faster
25 * on most boxes I have tested - up to %20 faster. */
26/*
27 * I don't know what does "most" mean, but declaring "int" is a must on:
28 * - Intel P6 because partial register stalls are very expensive;
29 * - elder Alpha because it lacks byte load/store instructions;
30 */
31#define RC4_INT unsigned char
32#endif
33#if !defined(RC4_CHUNK)
34/*
35 * This enables code handling data aligned at natural CPU word
36 * boundary. See crypto/rc4/rc4_enc.c for further details.
37 */
38#define RC4_CHUNK unsigned long
39#endif
40#endif
41
42#if defined(HEADER_DES_H) && !defined(DES_LONG)
43/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
44 * %20 speed up (longs are 8 bytes, int's are 4). */
45#ifndef DES_LONG
46#define DES_LONG unsigned long
47#endif
48#endif
49
50#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
51#define CONFIG_HEADER_BN_H
52#if __option(longlong)
53# define BN_LLONG
54#else
55# undef BN_LLONG
56#endif
57
58/* Should we define BN_DIV2W here? */
59
60/* Only one for the following should be defined */
61/* The prime number generation stuff may not work when
62 * EIGHT_BIT but I don't care since I've only used this mode
63 * for debuging the bignum libraries */
64#undef SIXTY_FOUR_BIT_LONG
65#undef SIXTY_FOUR_BIT
66#define THIRTY_TWO_BIT
67#undef SIXTEEN_BIT
68#undef EIGHT_BIT
69#endif
70
71#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
72#define CONFIG_HEADER_RC4_LOCL_H
73/* if this is defined data[i] is used instead of *data, this is a %20
74 * speedup on x86 */
75#undef RC4_INDEX
76#endif
77
78#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
79#define CONFIG_HEADER_BF_LOCL_H
80#define BF_PTR
81#endif /* HEADER_BF_LOCL_H */
82
83#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
84#define CONFIG_HEADER_DES_LOCL_H
85/* the following is tweaked from a config script, that is why it is a
86 * protected undef/define */
87#ifndef DES_PTR
88#define DES_PTR
89#endif
90
91/* This helps C compiler generate the correct code for multiple functional
92 * units. It reduces register dependancies at the expense of 2 more
93 * registers */
94#ifndef DES_RISC1
95#define DES_RISC1
96#endif
97
98#ifndef DES_RISC2
99#undef DES_RISC2
100#endif
101
102#if defined(DES_RISC1) && defined(DES_RISC2)
103YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
104#endif
105
106/* Unroll the inner loop, this sometimes helps, sometimes hinders.
107 * Very mucy CPU dependant */
108#ifndef DES_UNROLL
109#define DES_UNROLL
110#endif
111
112#endif /* HEADER_DES_LOCL_H */
113
114#ifndef __POWERPC__
115#define MD32_XARRAY
116#endif
diff --git a/src/lib/libssl/src/Makefile.org b/src/lib/libssl/src/Makefile.org
new file mode 100644
index 0000000000..2def579c26
--- /dev/null
+++ b/src/lib/libssl/src/Makefile.org
@@ -0,0 +1,351 @@
1##
2## Makefile for OpenSSL
3##
4
5VERSION=
6MAJOR=
7MINOR=
8PLATFORM=dist
9OPTIONS=
10# INSTALL_PREFIX is for package builders so that they can configure
11# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
12# Normally it is left empty.
13INSTALL_PREFIX=
14INSTALLTOP=/usr/local/ssl
15
16# Do not edit this manually. Use Configure --openssldir=DIR do change this!
17OPENSSLDIR=/usr/local/ssl
18
19# RSAref - Define if we are to link with RSAref.
20# NO_IDEA - Define to build without the IDEA algorithm
21# NO_RC4 - Define to build without the RC4 algorithm
22# NO_RC2 - Define to build without the RC2 algorithm
23# THREADS - Define when building with threads, you will probably also need any
24# system defines as well, i.e. _REENTERANT for Solaris 2.[34]
25# TERMIO - Define the termio terminal subsystem, needed if sgtty is missing.
26# TERMIOS - Define the termios terminal subsystem, Silicon Graphics.
27# LONGCRYPT - Define to use HPUX 10.x's long password modification to crypt(3).
28# DEVRANDOM - Give this the value of the 'random device' if your OS supports
29# one. 32 bytes will be read from this when the random
30# number generator is initalised.
31# SSL_ALLOW_ADH - define if you want the server to be able to use the
32# SSLv3 anon-DH ciphers.
33# SSL_FORBID_ENULL - define if you want the server to be not able to use the
34# NULL encryption ciphers.
35#
36# LOCK_DEBUG - turns on lots of lock debug output :-)
37# REF_CHECK - turn on some xyz_free() assertions.
38# REF_PRINT - prints some stuff on structure free.
39# CRYPTO_MDEBUG - turns on my 'memory leak' detecting stuff
40# MFUNC - Make all Malloc/Free/Realloc calls call
41# CRYPTO_malloc/CRYPTO_free/CRYPTO_realloc which can be setup to
42# call application defined callbacks via CRYPTO_set_mem_functions()
43# MD5_ASM needs to be defined to use the x86 assembler for MD5
44# SHA1_ASM needs to be defined to use the x86 assembler for SHA1
45# RMD160_ASM needs to be defined to use the x86 assembler for RIPEMD160
46# Do not define B_ENDIAN or L_ENDIAN if 'unsigned long' == 8. It must
47# equal 4.
48# PKCS1_CHECK - pkcs1 tests.
49
50CC= gcc
51#CFLAG= -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
52CFLAG= -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
53DEPFLAG=
54PEX_LIBS= -L. -L.. -L../.. -L../../..
55EX_LIBS=
56AR=ar r
57RANLIB= ranlib
58PERL= perl
59
60# Set BN_ASM to bn_asm.o if you want to use the C version
61BN_ASM= bn_asm.o
62#BN_ASM= bn_asm.o
63#BN_ASM= asm/bn86-elf.o # elf, linux-elf
64#BN_ASM= asm/bn86-sol.o # solaris
65#BN_ASM= asm/bn86-out.o # a.out, FreeBSD
66#BN_ASM= asm/bn86bsdi.o # bsdi
67#BN_ASM= asm/alpha.o # DEC Alpha
68#BN_ASM= asm/pa-risc2.o # HP-UX PA-RISC
69#BN_ASM= asm/r3000.o # SGI MIPS cpu
70#BN_ASM= asm/sparc.o # Sun solaris/SunOS
71#BN_ASM= asm/bn-win32.o # Windows 95/NT
72#BN_ASM= asm/x86w16.o # 16 bit code for Windows 3.1/DOS
73#BN_ASM= asm/x86w32.o # 32 bit code for Windows 3.1
74
75# For x86 assembler: Set PROCESSOR to 386 if you want to support
76# the 80386.
77PROCESSOR=
78
79# Set DES_ENC to des_enc.o if you want to use the C version
80#There are 4 x86 assember options.
81DES_ENC= asm/dx86-out.o asm/yx86-out.o
82#DES_ENC= des_enc.o fcrypt_b.o # C
83#DES_ENC= asm/dx86-elf.o asm/yx86-elf.o # elf
84#DES_ENC= asm/dx86-sol.o asm/yx86-sol.o # solaris
85#DES_ENC= asm/dx86-out.o asm/yx86-out.o # a.out, FreeBSD
86#DES_ENC= asm/dx86bsdi.o asm/yx86bsdi.o # bsdi
87
88# Set BF_ENC to bf_enc.o if you want to use the C version
89#There are 4 x86 assember options.
90BF_ENC= asm/bx86-out.o
91#BF_ENC= bf_enc.o
92#BF_ENC= asm/bx86-elf.o # elf
93#BF_ENC= asm/bx86-sol.o # solaris
94#BF_ENC= asm/bx86-out.o # a.out, FreeBSD
95#BF_ENC= asm/bx86bsdi.o # bsdi
96
97# Set CAST_ENC to c_enc.o if you want to use the C version
98#There are 4 x86 assember options.
99CAST_ENC= asm/cx86-out.o
100#CAST_ENC= c_enc.o
101#CAST_ENC= asm/cx86-elf.o # elf
102#CAST_ENC= asm/cx86-sol.o # solaris
103#CAST_ENC= asm/cx86-out.o # a.out, FreeBSD
104#CAST_ENC= asm/cx86bsdi.o # bsdi
105
106# Set RC4_ENC to rc4_enc.o if you want to use the C version
107#There are 4 x86 assember options.
108RC4_ENC= asm/rx86-out.o
109#RC4_ENC= rc4_enc.o
110#RC4_ENC= asm/rx86-elf.o # elf
111#RC4_ENC= asm/rx86-sol.o # solaris
112#RC4_ENC= asm/rx86-out.o # a.out, FreeBSD
113#RC4_ENC= asm/rx86bsdi.o # bsdi
114
115# Set RC5_ENC to rc5_enc.o if you want to use the C version
116#There are 4 x86 assember options.
117RC5_ENC= asm/r586-out.o
118#RC5_ENC= rc5_enc.o
119#RC5_ENC= asm/r586-elf.o # elf
120#RC5_ENC= asm/r586-sol.o # solaris
121#RC5_ENC= asm/r586-out.o # a.out, FreeBSD
122#RC5_ENC= asm/r586bsdi.o # bsdi
123
124# Also need MD5_ASM defined
125MD5_ASM_OBJ= asm/mx86-out.o
126#MD5_ASM_OBJ= asm/mx86-elf.o # elf
127#MD5_ASM_OBJ= asm/mx86-sol.o # solaris
128#MD5_ASM_OBJ= asm/mx86-out.o # a.out, FreeBSD
129#MD5_ASM_OBJ= asm/mx86bsdi.o # bsdi
130
131# Also need SHA1_ASM defined
132SHA1_ASM_OBJ= asm/sx86-out.o
133#SHA1_ASM_OBJ= asm/sx86-elf.o # elf
134#SHA1_ASM_OBJ= asm/sx86-sol.o # solaris
135#SHA1_ASM_OBJ= asm/sx86-out.o # a.out, FreeBSD
136#SHA1_ASM_OBJ= asm/sx86bsdi.o # bsdi
137
138# Also need RMD160_ASM defined
139RMD160_ASM_OBJ= asm/rm86-out.o
140#RMD160_ASM_OBJ= asm/rm86-elf.o # elf
141#RMD160_ASM_OBJ= asm/rm86-sol.o # solaris
142#RMD160_ASM_OBJ= asm/rm86-out.o # a.out, FreeBSD
143#RMD160_ASM_OBJ= asm/rm86bsdi.o # bsdi
144
145DIRS= crypto ssl rsaref apps test tools
146SHLIBDIRS= crypto ssl
147
148# dirs in crypto to build
149SDIRS= \
150 md2 md5 sha mdc2 hmac ripemd \
151 des rc2 rc4 rc5 idea bf cast \
152 bn rsa dsa dh \
153 buffer bio stack lhash rand err objects \
154 evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp
155
156MAKEFILE= Makefile.ssl
157MAKE= make -f Makefile.ssl
158
159MAN1=1
160MAN3=3
161SHELL=/bin/sh
162
163TOP= .
164ONEDIRS=out tmp
165EDIRS= times doc bugs util include certs ms shlib mt demos perl sf dep VMS
166WDIRS= windows
167LIBS= libcrypto.a libssl.a
168
169GENERAL= Makefile
170BASENAME= openssl
171NAME= $(BASENAME)-$(VERSION)
172TARFILE= $(NAME).tar
173WTARFILE= $(NAME)-win.tar
174EXHEADER= e_os.h e_os2.h
175HEADER= e_os.h
176
177all: Makefile.ssl
178 @for i in $(DIRS) ;\
179 do \
180 (cd $$i && echo "making all in $$i..." && \
181 $(MAKE) CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_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}' SDIRS='${SDIRS}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' all ) || exit 1; \
182 done
183 -@# cd perl; $(PERL) Makefile.PL; make
184
185sub_all:
186 @for i in $(DIRS) ;\
187 do \
188 (cd $$i && echo "making all in $$i..." && \
189 $(MAKE) CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_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}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' all ) || exit 1; \
190 done;
191
192linux-shared:
193 for i in ${SHLIBDIRS}; do \
194 rm -f lib$$i.a lib$$i.so \
195 lib$$i.so.${MAJOR} lib$$i.so.${MAJOR}.${MINOR}; \
196 ${MAKE} CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='-fPIC ${CFLAG}' SDIRS='${SDIRS}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_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}' AR='${AR}' DIRS=$$i clean all || exit 1; \
197 ( set -x; ${CC} -shared -o lib$$i.so.${MAJOR}.${MINOR} \
198 -Wl,-S,-soname=lib$$i.so.${MAJOR} \
199 -Wl,--whole-archive lib$$i.a \
200 -Wl,--no-whole-archive -lc ) || exit 1; \
201 rm -f lib$$i.a; make -C $$i clean || exit 1 ;\
202 done;
203 @set -x; \
204 for i in ${SHLIBDIRS}; do \
205 ln -s lib$$i.so.${MAJOR}.${MINOR} lib$$i.so.${MAJOR}; \
206 ln -s lib$$i.so.${MAJOR} lib$$i.so; \
207 done;
208
209Makefile.ssl: Makefile.org
210 @echo "Makefile.ssl is older than Makefile.org."
211 @echo "Reconfigure the source tree (via './config' or 'perl Configure'), please."
212 @false
213
214libclean:
215 rm -f *.a */lib */*/lib
216
217clean:
218 rm -f shlib/*.o *.o core a.out fluff *.map
219 @for i in $(DIRS) ;\
220 do \
221 (cd $$i && echo "making clean in $$i..." && \
222 $(MAKE) SDIRS='${SDIRS}' clean ) || exit 1; \
223 rm -f $(LIBS); \
224 done;
225 rm -f *.a *.o speed.* *.map *.so .pure core
226 rm -f $(TARFILE)
227 @for i in $(ONEDIRS) ;\
228 do \
229 rm -fr $$i/*; \
230 done
231
232makefile.one: files
233 $(PERL) util/mk1mf.pl >makefile.one; \
234 sh util/do_ms.sh
235
236files:
237 $(PERL) $(TOP)/util/files.pl Makefile.ssl > $(TOP)/MINFO
238 @for i in $(DIRS) ;\
239 do \
240 (cd $$i && echo "making 'files' in $$i..." && \
241 $(MAKE) SDIRS='${SDIRS}' PERL='${PERL}' files ) || exit 1; \
242 done;
243
244links:
245 @$(TOP)/util/point.sh Makefile.ssl Makefile
246 @$(PERL) $(TOP)/util/mkdir-p.pl include/openssl
247 @$(PERL) $(TOP)/util/mklink.pl include/openssl $(EXHEADER)
248 @for i in $(DIRS); do \
249 (cd $$i && echo "making links in $$i..." && \
250 $(MAKE) CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_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}' AR='${AR}' PERL='${PERL}' links ) || exit 1; \
251 done;
252
253dclean:
254 rm -f *.bak
255 @for i in $(DIRS) ;\
256 do \
257 (cd $$i && echo "making dclean in $$i..." && \
258 $(MAKE) SDIRS='${SDIRS}' PERL='${PERL}' dclean ) || exit 1; \
259 done;
260
261rehash:
262 @(OPENSSL="`pwd`/apps/openssl"; export OPENSSL; sh tools/c_rehash certs)
263
264test: tests
265
266tests: rehash
267 @(cd test && echo "testing..." && \
268 $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SDIRS='${SDIRS}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' tests );
269 @apps/openssl version -a
270
271depend:
272 @for i in $(DIRS) ;\
273 do \
274 (cd $$i && echo "making dependencies $$i..." && \
275 $(MAKE) SDIRS='${SDIRS}' DEPFLAG='${DEPFLAG}' depend ) || exit 1; \
276 done;
277
278lint:
279 @for i in $(DIRS) ;\
280 do \
281 (cd $$i && echo "making lint $$i..." && \
282 $(MAKE) SDIRS='${SDIRS}' lint ) || exit 1; \
283 done;
284
285tags:
286 @for i in $(DIRS) ;\
287 do \
288 (cd $$i && echo "making tags $$i..." && \
289 $(MAKE) SDIRS='${SDIRS}' tags ) || exit 1; \
290 done;
291
292errors:
293 perl util/mkerr.pl -recurse -write
294
295util/libeay.num::
296 perl util/mkdef.pl crypto update
297
298util/ssleay.num::
299 perl util/mkdef.pl ssl update
300
301TABLE: Configure
302 (echo 'Output of `Configure TABLE'"':"; \
303 perl Configure TABLE) > TABLE
304
305update: depend errors util/libeay.num util/ssleay.num TABLE
306
307tar:
308 @tar --norecurse -cvf - \
309 `find * \! -path CVS/\* \! -path \*/CVS/\* \! -name CVS \! -name .cvsignore \! -name STATUS \! -name TABLE | sort` |\
310 tardy --user_number=0 --user_name=openssl \
311 --group_number=0 --group_name=openssl \
312 --prefix=openssl-$(VERSION) - |\
313 gzip --best >../$(TARFILE).gz; \
314 ls -l ../$(TARFILE).gz
315
316dist:
317 $(PERL) Configure dist
318 @$(MAKE) dist_pem_h
319 @$(MAKE) SDIRS='${SDIRS}' clean
320 @$(MAKE) tar
321
322dist_pem_h:
323 (cd crypto/pem; $(MAKE) CC='${CC}' SDIRS='${SDIRS}' CFLAG='${CFLAG}' pem.h; $(MAKE) clean)
324
325install: all
326 @$(PERL) $(TOP)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/bin \
327 $(INSTALL_PREFIX)$(INSTALLTOP)/lib \
328 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl \
329 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc \
330 $(INSTALL_PREFIX)$(OPENSSLDIR)/certs \
331 $(INSTALL_PREFIX)$(OPENSSLDIR)/private \
332 $(INSTALL_PREFIX)$(OPENSSLDIR)/lib
333 @for i in $(EXHEADER) ;\
334 do \
335 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
336 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
337 done;
338 @for i in $(DIRS) ;\
339 do \
340 (cd $$i; echo "installing $$i..."; \
341 $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' OPENSSLDIR='${OPENSSLDIR}' EX_LIBS='${EX_LIBS}' SDIRS='${SDIRS}' install ); \
342 done
343 @for i in $(LIBS) ;\
344 do \
345 ( echo installing $$i; \
346 cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/lib; \
347 $(RANLIB) $(INSTALL_PREFIX)$(INSTALLTOP)/lib/$$i; \
348 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/lib/$$i ); \
349 done
350
351# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/src/lib/libssl/src/NEWS b/src/lib/libssl/src/NEWS
new file mode 100644
index 0000000000..c152b7155d
--- /dev/null
+++ b/src/lib/libssl/src/NEWS
@@ -0,0 +1,65 @@
1
2 NEWS
3 ====
4
5 This file gives a brief overview of the major changes between each OpenSSL
6 release. For more details please read the CHANGES file.
7
8 Major changes between OpenSSL 0.9.3 and OpenSSL 0.9.4:
9
10 o Transparent support for PKCS#8 format private keys: these are used
11 by several software packages and are more secure than the standard
12 form
13 o PKCS#5 v2.0 implementation
14 o Password callbacks have a new void * argument for application data
15 o Avoid various memory leaks
16 o New pipe-like BIO that allows using the SSL library when actual I/O
17 must be handled by the application (BIO pair)
18
19 Major changes between OpenSSL 0.9.2b and OpenSSL 0.9.3:
20 o Lots of enhancements and cleanups to the Configuration mechanism
21 o RSA OEAP related fixes
22 o Added `openssl ca -revoke' option for revoking a certificate
23 o Source cleanups: const correctness, type-safe stacks and ASN.1 SETs
24 o Source tree cleanups: removed lots of obsolete files
25 o Thawte SXNet, certificate policies and CRL distribution points
26 extension support
27 o Preliminary (experimental) S/MIME support
28 o Support for ASN.1 UTF8String and VisibleString
29 o Full integration of PKCS#12 code
30 o Sparc assembler bignum implementation, optimized hash functions
31 o Option to disable selected ciphers
32
33 Major changes between OpenSSL 0.9.1c and OpenSSL 0.9.2b:
34 o Fixed a security hole related to session resumption
35 o Fixed RSA encryption routines for the p < q case
36 o "ALL" in cipher lists now means "everything except NULL ciphers"
37 o Support for Triple-DES CBCM cipher
38 o Support of Optimal Asymmetric Encryption Padding (OAEP) for RSA
39 o First support for new TLSv1 ciphers
40 o Added a few new BIOs (syslog BIO, reliable BIO)
41 o Extended support for DSA certificate/keys.
42 o Extended support for Certificate Signing Requests (CSR)
43 o Initial support for X.509v3 extensions
44 o Extended support for compression inside the SSL record layer
45 o Overhauled Win32 builds
46 o Cleanups and fixes to the Big Number (BN) library
47 o Support for ASN.1 GeneralizedTime
48 o Splitted ASN.1 SETs from SEQUENCEs
49 o ASN1 and PEM support for Netscape Certificate Sequences
50 o Overhauled Perl interface
51 o Lots of source tree cleanups.
52 o Lots of memory leak fixes.
53 o Lots of bug fixes.
54
55 Major changes between SSLeay 0.9.0b and OpenSSL 0.9.1c:
56 o Integration of the popular NO_RSA/NO_DSA patches
57 o Initial support for compression inside the SSL record layer
58 o Added BIO proxy and filtering functionality
59 o Extended Big Number (BN) library
60 o Added RIPE MD160 message digest
61 o Addeed support for RC2/64bit cipher
62 o Extended ASN.1 parser routines
63 o Adjustations of the source tree for CVS
64 o Support for various new platforms
65
diff --git a/src/lib/libssl/src/README.ASN1 b/src/lib/libssl/src/README.ASN1
new file mode 100644
index 0000000000..11bcfaf4dd
--- /dev/null
+++ b/src/lib/libssl/src/README.ASN1
@@ -0,0 +1,187 @@
1
2OpenSSL ASN1 Revision
3=====================
4
5This document describes some of the issues relating to the new ASN1 code.
6
7Previous OpenSSL ASN1 problems
8=============================
9
10OK why did the OpenSSL ASN1 code need revising in the first place? Well
11there are lots of reasons some of which are included below...
12
131. The code is difficult to read and write. For every single ASN1 structure
14(e.g. SEQUENCE) four functions need to be written for new, free, encode and
15decode operations. This is a very painful and error prone operation. Very few
16people have ever written any OpenSSL ASN1 and those that have usually wish
17they hadn't.
18
192. Partly because of 1. the code is bloated and takes up a disproportionate
20amount of space. The SEQUENCE encoder is particularly bad: it essentially
21contains two copies of the same operation, one to compute the SEQUENCE length
22and the other to encode it.
23
243. The code is memory based: that is it expects to be able to read the whole
25structure from memory. This is fine for small structures but if you have a
26(say) 1Gb PKCS#7 signedData structure it isn't such a good idea...
27
284. The code for the ASN1 IMPLICIT tag is evil. It is handled by temporarily
29changing the tag to the expected one, attempting to read it, then changing it
30back again. This means that decode buffers have to be writable even though they
31are ultimately unchanged. This gets in the way of constification.
32
335. The handling of EXPLICIT isn't much better. It adds a chunk of code into
34the decoder and encoder for every EXPLICIT tag.
35
366. APPLICATION and PRIVATE tags aren't even supported at all.
37
387. Even IMPLICIT isn't complete: there is no support for implicitly tagged
39types that are not OPTIONAL.
40
418. Much of the code assumes that a tag will fit in a single octet. This is
42only true if the tag is 30 or less (mercifully tags over 30 are rare).
43
449. The ASN1 CHOICE type has to be largely handled manually, there aren't any
45macros that properly support it.
46
4710. Encoders have no concept of OPTIONAL and have no error checking. If the
48passed structure contains a NULL in a mandatory field it will not be encoded,
49resulting in an invalid structure.
50
5111. It is tricky to add ASN1 encoders and decoders to external applications.
52
53Template model
54==============
55
56One of the major problems with revision is the sheer volume of the ASN1 code.
57Attempts to change (for example) the IMPLICIT behaviour would result in a
58modification of *every* single decode function.
59
60I decided to adopt a template based approach. I'm using the term 'template'
61in a manner similar to SNACC templates: it has nothing to do with C++
62templates.
63
64A template is a description of an ASN1 module as several constant C structures.
65It describes in a machine readable way exactly how the ASN1 structure should
66behave. If this template contains enough detail then it is possible to write
67versions of new, free, encode, decode (and possibly others operations) that
68operate on templates.
69
70Instead of having to write code to handle each operation only a single
71template needs to be written. If new operations are needed (such as a 'print'
72operation) only a single new template based function needs to be written
73which will then automatically handle all existing templates.
74
75Plans for revision
76==================
77
78The revision will consist of the following steps. Other than the first two
79these can be handled in any order.
80
81o Design and write template new, free, encode and decode operations, initially
82memory based. *DONE*
83
84o Convert existing ASN1 code to template form. *IN PROGRESS*
85
86o Convert an existing ASN1 compiler (probably SNACC) to output templates
87in OpenSSL form.
88
89o Add support for BIO based ASN1 encoders and decoders to handle large
90structures, initially blocking I/O.
91
92o Add support for non blocking I/O: this is quite a bit harder than blocking
93I/O.
94
95o Add new ASN1 structures, such as OCSP, CRMF, S/MIME v3 (CMS), attribute
96certificates etc etc.
97
98Description of major changes
99============================
100
101The BOOLEAN type now takes three values. 0xff is TRUE, 0 is FALSE and -1 is
102absent. The meaning of absent depends on the context. If for example the
103boolean type is DEFAULT FALSE (as in the case of the critical flag for
104certificate extensions) then -1 is FALSE, if DEFAULT TRUE then -1 is TRUE.
105Usually the value will only ever be read via an API which will hide this from
106an application.
107
108There is an evil bug in the old ASN1 code that mishandles OPTIONAL with
109SEQUENCE OF or SET OF. These are both implemented as a STACK structure. The
110old code would omit the structure if the STACK was NULL (which is fine) or if
111it had zero elements (which is NOT OK). This causes problems because an empty
112SEQUENCE OF or SET OF will result in an empty STACK when it is decoded but when
113it is encoded it will be omitted resulting in different encodings. The new code
114only omits the encoding if the STACK is NULL, if it contains zero elements it
115is encoded and empty. There is an additional problem though: because an empty
116STACK was omitted, sometimes the corresponding *_new() function would
117initialize the STACK to empty so an application could immediately use it, if
118this is done with the new code (i.e. a NULL) it wont work. Therefore a new
119STACK should be allocated first. One instance of this is the X509_CRL list of
120revoked certificates: a helper function X509_CRL_add0_revoked() has been added
121for this purpose.
122
123The X509_ATTRIBUTE structure used to have an element called 'set' which took
124the value 1 if the attribute value was a SET OF or 0 if it was a single. Due
125to the behaviour of CHOICE in the new code this has been changed to a field
126called 'single' which is 0 for a SET OF and 1 for single. The old field has
127been deleted to deliberately break source compatibility. Since this structure
128is normally accessed via higher level functions this shouldn't break too much.
129
130The X509_REQ_INFO certificate request info structure no longer has a field
131called 'req_kludge'. This used to be set to 1 if the attributes field was
132(incorrectly) omitted. You can check to see if the field is omitted now by
133checking if the attributes field is NULL. Similarly if you need to omit
134the field then free attributes and set it to NULL.
135
136The top level 'detached' field in the PKCS7 structure is no longer set when
137a PKCS#7 structure is read in. PKCS7_is_detached() should be called instead.
138The behaviour of PKCS7_get_detached() is unaffected.
139
140The values of 'type' in the GENERAL_NAME structure have changed. This is
141because the old code use the ASN1 initial octet as the selector. The new
142code uses the index in the ASN1_CHOICE template.
143
144The DIST_POINT_NAME structure has changed to be a true CHOICE type.
145
146typedef struct DIST_POINT_NAME_st {
147int type;
148union {
149 STACK_OF(GENERAL_NAME) *fullname;
150 STACK_OF(X509_NAME_ENTRY) *relativename;
151} name;
152} DIST_POINT_NAME;
153
154This means that name.fullname or name.relativename should be set
155and type reflects the option. That is if name.fullname is set then
156type is 0 and if name.relativename is set type is 1.
157
158With the old code using the i2d functions would typically involve:
159
160unsigned char *buf, *p;
161int len;
162/* Find length of encoding */
163len = i2d_SOMETHING(x, NULL);
164/* Allocate buffer */
165buf = OPENSSL_malloc(len);
166if(buf == NULL) {
167 /* Malloc error */
168}
169/* Use temp variable because &p gets updated to point to end of
170 * encoding.
171 */
172p = buf;
173i2d_SOMETHING(x, &p);
174
175
176Using the new i2d you can also do:
177
178unsigned char *buf = NULL;
179int len;
180len = i2d_SOMETHING(x, &buf);
181if(len < 0) {
182 /* Malloc error */
183}
184
185and it will automatically allocate and populate a buffer with the
186encoding. After this call 'buf' will point to the start of the
187encoding which is len bytes long.
diff --git a/src/lib/libssl/src/README.ENGINE b/src/lib/libssl/src/README.ENGINE
new file mode 100644
index 0000000000..3d88ed152f
--- /dev/null
+++ b/src/lib/libssl/src/README.ENGINE
@@ -0,0 +1,63 @@
1
2 ENGINE
3 ======
4
5 With OpenSSL 0.9.6, a new component has been added to support external
6 crypto devices, for example accelerator cards. The component is called
7 ENGINE, and has still a pretty experimental status and almost no
8 documentation. It's designed to be faily easily extensible by the
9 calling programs.
10
11 There's currently built-in support for the following crypto devices:
12
13 o CryptoSwift
14 o Compaq Atalla
15 o nCipher CHIL
16
17 A number of things are still needed and are being worked on:
18
19 o An openssl utility command to handle or at least check available
20 engines.
21 o A better way of handling the methods that are handled by the
22 engines.
23 o Documentation!
24
25 What already exists is fairly stable as far as it has been tested, but
26 the test base has been a bit small most of the time.
27
28 Because of this experimental status and what's lacking, the ENGINE
29 component is not yet part of the default OpenSSL distribution. However,
30 we have made a separate kit for those who want to try this out, to be
31 found in the same places as the default OpenSSL distribution, but with
32 "-engine-" being part of the kit file name. For example, version 0.9.6
33 is distributed in the following two files:
34
35 openssl-0.9.6.tar.gz
36 openssl-engine-0.9.6.tar.gz
37
38 NOTES
39 =====
40
41 openssl-engine-0.9.6.tar.gz does not depend on openssl-0.9.6.tar, you do
42 not need to download both.
43
44 openssl-engine-0.9.6.tar.gz is usable even if you don't have an external
45 crypto device. The internal OpenSSL functions are contained in the
46 engine "openssl", and will be used by default.
47
48 No external crypto device is chosen unless you say so. You have actively
49 tell the openssl utility commands to use it through a new command line
50 switch called "-engine". And if you want to use the ENGINE library to
51 do something similar, you must also explicitely choose an external crypto
52 device, or the built-in crypto routines will be used, just as in the
53 default OpenSSL distribution.
54
55
56 PROBLEMS
57 ========
58
59 It seems like the ENGINE part doesn't work too well with Cryptoswift on
60 Win32. A quick test done right before the release showed that trying
61 "openssl speed -engine cswift" generated errors. If the DSO gets enabled,
62 an attempt is made to write at memory address 0x00000002.
63
diff --git a/src/lib/libssl/src/VMS/TODO b/src/lib/libssl/src/VMS/TODO
new file mode 100644
index 0000000000..359e069191
--- /dev/null
+++ b/src/lib/libssl/src/VMS/TODO
@@ -0,0 +1,18 @@
1TODO:
2=====
3
4There are a few things that need to be worked out in the VMS version of
5OpenSSL, still:
6
7- Description files. ("Makefile's" :-))
8- Script code to link an already compiled build tree.
9- A VMSINSTALlable version (way in the future, unless someone else hacks).
10- shareable images (DLL for you Windows folks).
11
12There may be other things that I have missed and that may be desirable.
13Please send mail to <openssl-users@openssl.org> or to me directly if you
14have any ideas.
15
16--
17Richard Levitte <richard@levitte.org>
181999-05-24
diff --git a/src/lib/libssl/src/VMS/WISHLIST.TXT b/src/lib/libssl/src/VMS/WISHLIST.TXT
new file mode 100644
index 0000000000..c151fc8ea7
--- /dev/null
+++ b/src/lib/libssl/src/VMS/WISHLIST.TXT
@@ -0,0 +1,4 @@
1* Have the building procedure contain a LINK-only possibility.
2 Wished by Mark Daniel <mark.daniel@dsto.defence.gov.au>
3
4 One way to enable that is also to go over to DESCRIP.MMS files.
diff --git a/src/lib/libssl/src/VMS/install.com b/src/lib/libssl/src/VMS/install.com
new file mode 100644
index 0000000000..d941392c23
--- /dev/null
+++ b/src/lib/libssl/src/VMS/install.com
@@ -0,0 +1,71 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 23-MAY-1998 19:22
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
23$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
24$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
25$ DEFINE/NOLOG WRK_SSLVEXE WRK_SSLROOT:[VAX_EXE]
26$ DEFINE/NOLOG WRK_SSLAEXE WRK_SSLROOT:[ALPHA_EXE]
27$ DEFINE/NOLOG WRK_SSLCERTS WRK_SSLROOT:[CERTS]
28$ DEFINE/NOLOG WRK_SSLPRIVATE WRK_SSLROOT:[PRIVATE]
29$
30$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLROOT:[000000]
32$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLINCLUDE:
34$ IF F$PARSE("WRK_SSLROOT:[VMS]") .EQS. "" THEN -
35 CREATE/DIR/LOG WRK_SSLROOT:[VMS]
36$
37$ EXHEADER := vms_idhacks.h
38$
39$ COPY 'EXHEADER' WRK_SSLINCLUDE: /LOG
40$
41$ OPEN/WRITE SF WRK_SSLROOT:[VMS]OPENSSL_STARTUP.COM
42$ WRITE SYS$OUTPUT "%OPEN-I-CREATED, ",F$SEARCH("WRK_SSLROOT:[VMS]OPENSSL_STARTUP.COM")," created."
43$ WRITE SF "$! Startup file for Openssl 0.9.2-RL 15-Mar-1999"
44$ WRITE SF "$!"
45$ WRITE SF "$! Do not edit this file, as it will be regenerated during next installation."
46$ WRITE SF "$! Instead, add or change SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"
47$ WRITE SF "$!"
48$ WRITE SF "$! P1 a qualifier to DEFINE. For example ""/SYSTEM"" to get the logical names"
49$ WRITE SF "$! defined in the system logical name table."
50$ WRITE SF "$!"
51$ WRITE SF "$ ARCH = ""VAX"""
52$ WRITE SF "$ IF F$GETSYI(""CPU"") .GE. 128 THEN ARCH = ""ALPHA"""
53$ WRITE SF "$ DEFINE/NOLOG'P1 SSLROOT ",ROOT,".] /TRANS=CONC"
54$ WRITE SF "$ DEFINE/NOLOG'P1 SSLLIB SSLROOT:['ARCH'_LIB]"
55$ WRITE SF "$ DEFINE/NOLOG'P1 SSLINCLUDE SSLROOT:[INCLUDE]"
56$ WRITE SF "$ DEFINE/NOLOG'P1 SSLEXE SSLROOT:['ARCH'_EXE]"
57$ WRITE SF "$ DEFINE/NOLOG'P1 SSLCERTS SSLROOT:[CERTS]"
58$ WRITE SF "$ DEFINE/NOLOG'P1 SSLPRIVATE SSLROOT:[PRIVATE]"
59$ WRITE SF "$"
60$ WRITE SF "$! This is program can include <openssl/{foo}.h>"
61$ WRITE SF "$ DEFINE/NOLOG'P1 OPENSSL SSLINCLUDE:"
62$ WRITE SF "$"
63$ WRITE SF "$ IF F$SEARCH(""SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"") .NES."""" THEN -"
64$ WRITE SF " @SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"
65$ WRITE SF "$"
66$ WRITE SF "$ EXIT"
67$ CLOSE SF
68$
69$ COPY OPENSSL_UTILS.COM WRK_SSLROOT:[VMS]/LOG
70$
71$ EXIT
diff --git a/src/lib/libssl/src/VMS/mkshared.com b/src/lib/libssl/src/VMS/mkshared.com
new file mode 100644
index 0000000000..afdc85bbe0
--- /dev/null
+++ b/src/lib/libssl/src/VMS/mkshared.com
@@ -0,0 +1,353 @@
1$! MKSHARED.COM -- script to created shareable images on VMS
2$!
3$! No command line parameters. This should be run at the start of the source
4$! tree (the same directory where one finds INSTALL.VMS).
5$!
6$! Input: [.UTIL]LIBEAY.NUM,[.AXP.EXE.CRYPTO]LIBCRYPTO.OLB
7$! [.UTIL]SSLEAY.NUM,[.AXP.EXE.SSL]LIBSSL.OLB
8$! Output: [.AXP.EXE.CRYPTO]LIBCRYPTO.OPT,.MAP,.EXE
9$! [.AXP.EXE.SSL]LIBSSL.OPT,.MAP,.EXE
10$!
11$! So far, tests have only been made on VMS for Alpha. VAX will come in time.
12$! ===========================================================================
13$
14$! ----- Prepare info for processing: version number and file info
15$ gosub read_version_info
16$ if libver .eqs. ""
17$ then
18$ write sys$error "ERROR: Couldn't find any library version info..."
19$ exit
20$ endif
21$
22$ if f$getsyi("CPU") .ge. 128
23$ then
24$ libid = "Crypto"
25$ libnum = "[.UTIL]LIBEAY.NUM"
26$ libdir = "[.AXP.EXE.CRYPTO]"
27$ libolb = "''libdir'LIBCRYPTO.OLB"
28$ libopt = "''libdir'LIBCRYPTO.OPT"
29$ libmap = "''libdir'LIBCRYPTO.MAP"
30$ libgoal= "''libdir'LIBCRYPTO.EXE"
31$ libref = ""
32$ gosub create_axp_shr
33$ libid = "SSL"
34$ libnum = "[.UTIL]SSLEAY.NUM"
35$ libdir = "[.AXP.EXE.SSL]"
36$ libolb = "''libdir'LIBSSL.OLB"
37$ libopt = "''libdir'LIBSSL.OPT"
38$ libmap = "''libdir'LIBSSL.MAP"
39$ libgoal= "''libdir'LIBSSL.EXE"
40$ libref = "[.AXP.EXE.CRYPTO]LIBCRYPTO.EXE"
41$ gosub create_axp_shr
42$ else
43$ libtit = "CRYPTO_TRANSFER_VECTOR"
44$ libid = "Crypto"
45$ libnum = "[.UTIL]LIBEAY.NUM"
46$ libdir = "[.VAX.EXE.CRYPTO]"
47$ libmar = "''libdir'LIBCRYPTO.MAR"
48$ libolb = "''libdir'LIBCRYPTO.OLB"
49$ libopt = "''libdir'LIBCRYPTO.OPT"
50$ libobj = "''libdir'LIBCRYPTO.OBJ"
51$ libmap = "''libdir'LIBCRYPTO.MAP"
52$ libgoal= "''libdir'LIBCRYPTO.EXE"
53$ libref = ""
54$ libvec = "LIBCRYPTO"
55$ gosub create_vax_shr
56$ libtit = "SSL_TRANSFER_VECTOR"
57$ libid = "SSL"
58$ libnum = "[.UTIL]SSLEAY.NUM"
59$ libdir = "[.VAX.EXE.SSL]"
60$ libmar = "''libdir'LIBSSL.MAR"
61$ libolb = "''libdir'LIBSSL.OLB"
62$ libopt = "''libdir'LIBSSL.OPT"
63$ libobj = "''libdir'LIBSSL.OBJ"
64$ libmap = "''libdir'LIBSSL.MAP"
65$ libgoal= "''libdir'LIBSSL.EXE"
66$ libref = "[.VAX.EXE.CRYPTO]LIBCRYPTO.EXE"
67$ libvec = "LIBSSL"
68$ gosub create_vax_shr
69$ endif
70$ exit
71$
72$! ----- Soubroutines to actually build the shareable libraries
73$! The way things work, there's a main shareable library creator for each
74$! supported architecture, which is called from the main code above.
75$! The creator will define a number of variables to tell the next levels of
76$! subroutines what routines to use to write to the option files, call the
77$! main processor, read_func_num, and when that is done, it will write version
78$! data at the end of the .opt file, close it, and link the library.
79$!
80$! read_func_num reads through a .num file and calls the writer routine for
81$! each line. It's also responsible for checking that order is properly kept
82$! in the .num file, check that each line applies to VMS and the architecture,
83$! and to fill in "holes" with dummy entries.
84$!
85$! The creator routines depend on the following variables:
86$! libnum The name of the .num file to use as input
87$! libolb The name of the object library to build from
88$! libid The identification string of the shareable library
89$! libopt The name of the .opt file to write
90$! libtit The title of the assembler transfer vector file (VAX only)
91$! libmar The name of the assembler transfer vector file (VAX only)
92$! libmap The name of the map file to write
93$! libgoal The name of the shareable library to write
94$! libref The name of a shareable library to link in
95$!
96$! read_func_num depends on the following variables from the creator:
97$! libwriter The name of the writer routine to call for each .num file line
98$! -----
99$
100$! ----- Subroutines for AXP
101$! -----
102$! The creator routine
103$ create_axp_shr:
104$ open/write opt 'libopt'
105$ write opt "identification=""",libid," ",libverstr,""""
106$ write opt libolb,"/lib"
107$ if libref .nes. "" then write opt libref,"/SHARE"
108$ write opt "SYMBOL_VECTOR=(-"
109$ libfirstentry := true
110$ libwrch := opt
111$ libwriter := write_axp_transfer_entry
112$ textcount = 0
113$ gosub read_func_num
114$ write opt ")"
115$ write opt "GSMATCH=",libvmatch,",",libver
116$ close opt
117$ link/map='libmap'/full/share='libgoal' 'libopt'/option
118$ return
119$
120$! The record writer routine
121$ write_axp_transfer_entry:
122$ if libentry .eqs. ".dummy" then return
123$ if info_kind .eqs. "VARIABLE"
124$ then
125$ pr:=DATA
126$ else
127$ pr:=PROCEDURE
128$ endif
129$ textcount_this = f$length(pr) + f$length(libentry) + 5
130$ if textcount + textcount_this .gt. 1024
131$ then
132$ write opt ")"
133$ write opt "SYMBOL_VECTOR=(-"
134$ textcount = 16
135$ libfirstentry := true
136$ endif
137$ if libfirstentry
138$ then
139$ write 'libwrch' " ",libentry,"=",pr," -"
140$ else
141$ write 'libwrch' " ,",libentry,"=",pr," -"
142$ endif
143$ libfirstentry := false
144$ textcount = textcount + textcount_this
145$ return
146$
147$! ----- Subroutines for AXP
148$! -----
149$! The creator routine
150$ create_vax_shr:
151$ open/write mar 'libmar'
152$ type sys$input:/out=mar:
153;
154; Transfer vector for VAX shareable image
155;
156$ write mar " .TITLE ",libtit
157$ write mar " .IDENT /",libid,"/"
158$ type sys$input:/out=mar:
159;
160; Define macro to assist in building transfer vector entries. Each entry
161; should take no more than 8 bytes.
162;
163 .MACRO FTRANSFER_ENTRY routine
164 .ALIGN QUAD
165 .TRANSFER routine
166 .MASK routine
167 JMP routine+2
168 .ENDM FTRANSFER_ENTRY
169;
170; Place entries in own program section.
171;
172$ write mar " .PSECT $$",libvec,",QUAD,PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT"
173$ write mar libvec,"_xfer:"
174$ libwrch := mar
175$ libwriter := write_vax_ftransfer_entry
176$ gosub read_func_num
177$ type sys$input:/out=mar:
178;
179; Allocate extra storage at end of vector to allow for expansion.
180;
181$ write mar " .BLKB 32768-<.-",libvec,"_xfer> ; 64 pages total."
182$! libwriter := write_vax_vtransfer_entry
183$! gosub read_func_num
184$ write mar " .END"
185$ close mar
186$ open/write opt 'libopt'
187$ write opt "identification=""",libid," ",libverstr,""""
188$ write opt libobj
189$ write opt libolb,"/lib"
190$ if libref .nes. "" then write opt libref,"/SHARE"
191$ type sys$input:/out=opt:
192!
193! Ensure transfer vector is at beginning of image
194!
195CLUSTER=FIRST
196$ write opt "COLLECT=FIRST,$$",libvec
197$ write opt "GSMATCH=",libvmatch,",",libver
198$ type sys$input:/out=opt:
199!
200! make psects nonshareable so image can be installed.
201!
202PSECT_ATTR=$CHAR_STRING_CONSTANTS,NOWRT
203$ libwrch := opt
204$ libwriter := write_vax_psect_attr
205$ gosub read_func_num
206$ close opt
207$ macro/obj='libobj' 'libmar'
208$ link/map='libmap'/full/share='libgoal' 'libopt'/option
209$ return
210$
211$! The record writer routine for VAX functions
212$ write_vax_ftransfer_entry:
213$ if info_kind .nes. "FUNCTION" then return
214$ if libentry .eqs ".dummy"
215$ then
216$ write 'libwrch' " .BLKB 8" ! Dummy is zeroes...
217$ else
218$ write 'libwrch' " FTRANSFER_ENTRY ",libentry
219$ endif
220$ return
221$! The record writer routine for VAX variables (should never happen!)
222$ write_vax_psect_attr:
223$ if info_kind .nes. "VARIABLE" then return
224$ if libentry .eqs ".dummy" then return
225$ write 'libwrch' "PSECT_ATTR=",libentry,",NOSHR"
226$ return
227$
228$! ----- Common subroutines
229$! -----
230$! The .num file reader. This one has great responsability.
231$ read_func_num:
232$ open libnum 'libnum'
233$ goto read_nums
234$
235$ read_nums:
236$ libentrynum=0
237$ liblastentry:=false
238$ entrycount=0
239$ loop:
240$ read/end=loop_end/err=loop_end libnum line
241$ entrynum=f$int(f$element(1," ",f$edit(line,"COMPRESS,TRIM")))
242$ entryinfo=f$element(2," ",f$edit(line,"COMPRESS,TRIM"))
243$ curentry=f$element(0," ",f$edit(line,"COMPRESS,TRIM"))
244$ info_exist=f$element(0,":",entryinfo)
245$ info_platforms=","+f$element(1,":",entryinfo)+","
246$ info_kind=f$element(2,":",entryinfo)
247$ info_algorithms=","+f$element(3,":",entryinfo)+","
248$ if info_exist .eqs. "NOEXIST" then goto loop
249$ truesum = 0
250$ falsesum = 0
251$ negatives = 1
252$ plat_i = 0
253$ loop1:
254$ plat_entry = f$element(plat_i,",",info_platforms)
255$ plat_i = plat_i + 1
256$ if plat_entry .eqs. "" then goto loop1
257$ if plat_entry .nes. ","
258$ then
259$ if f$extract(0,1,plat_entry) .nes. "!" then negatives = 0
260$ if f$getsyi("CPU") .lt. 128
261$ then
262$ if plat_entry .eqs. "EXPORT_VAR_AS_FUNCTION" then -
263$ truesum = truesum + 1
264$ if plat_entry .eqs. "!EXPORT_VAR_AS_FUNCTION" then -
265$ falsesum = falsesum + 1
266$ endif
267$ if plat_entry .eqs. "VMS" then truesum = truesum + 1
268$ if plat_entry .eqs. "!VMS" then falsesum = falsesum + 1
269$ goto loop1
270$ endif
271$ endloop1:
272$!DEBUG!$ if info_platforms - "EXPORT_VAR_AS_FUNCTION" .nes. info_platforms
273$!DEBUG!$ then
274$!DEBUG!$ write sys$output line
275$!DEBUG!$ write sys$output " truesum = ",truesum,-
276$!DEBUG! ", negatives = ",negatives,", falsesum = ",falsesum
277$!DEBUG!$ endif
278$ if falsesum .ne. 0 then goto loop
279$ if truesum+negatives .eq. 0 then goto loop
280$ alg_i = 0
281$ loop2:
282$ alg_entry = f$element(alg_i,",",info_algorithms)
283$ alg_i = alg_i + 1
284$ if alg_entry .eqs. "" then goto loop2
285$ if alg_entry .nes. ","
286$ then
287$ if alg_entry .eqs. "KRB5" then goto loop ! Special for now
288$ if f$trnlnm("OPENSSL_NO_"+alg_entry) .nes. "" then goto loop
289$ goto loop2
290$ endif
291$ endloop2:
292$ if info_platforms - "EXPORT_VAR_AS_FUNCTION" .nes. info_platforms
293$ then
294$!DEBUG!$ write sys$output curentry," ; ",entrynum," ; ",entryinfo
295$ endif
296$ redo:
297$ next:=loop
298$ tolibentry=curentry
299$ if libentrynum .ne. entrynum
300$ then
301$ entrycount=entrycount+1
302$ if entrycount .lt. entrynum
303$ then
304$!DEBUG!$ write sys$output "Info: entrycount: ''entrycount', entrynum: ''entrynum' => 0"
305$ tolibentry=".dummy"
306$ next:=redo
307$ endif
308$ if entrycount .gt. entrynum
309$ then
310$ write sys$error "Decreasing library entry numbers! Can't continue"
311$ write sys$error """",line,""""
312$ close libnum
313$ return
314$ endif
315$ libentry=tolibentry
316$!DEBUG!$ write sys$output entrycount," ",libentry," ",entryinfo
317$ if libentry .nes. "" .and. libwriter .nes. "" then gosub 'libwriter'
318$ else
319$ write sys$error "Info: ""''curentry'"" is an alias for ""''libentry'"". Overriding..."
320$ endif
321$ libentrynum=entrycount
322$ goto 'next'
323$ loop_end:
324$ close libnum
325$ return
326$
327$! The version number reader
328$ read_version_info:
329$ libver = ""
330$ open/read vf [.CRYPTO]OPENSSLV.H
331$ loop_rvi:
332$ read/err=endloop_rvi/end=endloop_rvi vf rvi_line
333$ if rvi_line - "SHLIB_VERSION_NUMBER """ .eqs. rvi_line then -
334 goto loop_rvi
335$ libverstr = f$element(1,"""",rvi_line)
336$ libvmajor = f$element(0,".",libverstr)
337$ libvminor = f$element(1,".",libverstr)
338$ libvedit = f$element(2,".",libverstr)
339$ libvpatch = f$cvui(0,8,f$extract(1,1,libvedit)+"@")-f$cvui(0,8,"@")
340$ libvedit = f$extract(0,1,libvedit)
341$ libver = f$string(f$int(libvmajor)*100)+","+-
342 f$string(f$int(libvminor)*100+f$int(libvedit)*10+f$int(libvpatch))
343$ if libvmajor .eqs. "0"
344$ then
345$ libvmatch = "EQUAL"
346$ else
347$ ! Starting with the 1.0 release, backward compatibility should be
348$ ! kept, so switch over to the following
349$ libvmatch = "LEQUAL"
350$ endif
351$ endloop_rvi:
352$ close vf
353$ return
diff --git a/src/lib/libssl/src/VMS/multinet_shr.opt b/src/lib/libssl/src/VMS/multinet_shr.opt
new file mode 100644
index 0000000000..610f42dddb
--- /dev/null
+++ b/src/lib/libssl/src/VMS/multinet_shr.opt
@@ -0,0 +1 @@
multinet:multinet_socket_library.exe/share
diff --git a/src/lib/libssl/src/VMS/openssl_utils.com b/src/lib/libssl/src/VMS/openssl_utils.com
new file mode 100644
index 0000000000..ddc107394f
--- /dev/null
+++ b/src/lib/libssl/src/VMS/openssl_utils.com
@@ -0,0 +1,38 @@
1$!
2$! APPS.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$!
9$! Slightly modified by Richard Levitte <richard@levitte.org>
10$!
11$ OPENSSL :== $SSLEXE:OPENSSL
12$ VERIFY :== $SSLEXE:OPENSSL VERIFY
13$ ASN1PARSE:== $SSLEXE:OPENSSL ASN1PARS
14$ REQ :== $SSLEXE:OPENSSL REQ
15$ DGST :== $SSLEXE:OPENSSL DGST
16$ DH :== $SSLEXE:OPENSSL DH
17$ ENC :== $SSLEXE:OPENSSL ENC
18$ GENDH :== $SSLEXE:OPENSSL GENDH
19$ ERRSTR :== $SSLEXE:OPENSSL ERRSTR
20$ CA :== $SSLEXE:OPENSSL CA
21$ CRL :== $SSLEXE:OPENSSL CRL
22$ RSA :== $SSLEXE:OPENSSL RSA
23$ DSA :== $SSLEXE:OPENSSL DSA
24$ DSAPARAM :== $SSLEXE:OPENSSL DSAPARAM
25$ X509 :== $SSLEXE:OPENSSL X509
26$ GENRSA :== $SSLEXE:OPENSSL GENRSA
27$ GENDSA :== $SSLEXE:OPENSSL GENDSA
28$ S_SERVER :== $SSLEXE:OPENSSL S_SERVER
29$ S_CLIENT :== $SSLEXE:OPENSSL S_CLIENT
30$ SPEED :== $SSLEXE:OPENSSL SPEED
31$ S_TIME :== $SSLEXE:OPENSSL S_TIME
32$ VERSION :== $SSLEXE:OPENSSL VERSION
33$ PKCS7 :== $SSLEXE:OPENSSL PKCS7
34$ CRL2PKCS7:== $SSLEXE:OPENSSL CRL2P7
35$ SESS_ID :== $SSLEXE:OPENSSL SESS_ID
36$ CIPHERS :== $SSLEXE:OPENSSL CIPHERS
37$ NSEQ :== $SSLEXE:OPENSSL NSEQ
38$ PKCS12 :== $SSLEXE:OPENSSL PKCS12
diff --git a/src/lib/libssl/src/VMS/socketshr_shr.opt b/src/lib/libssl/src/VMS/socketshr_shr.opt
new file mode 100644
index 0000000000..f6e3131626
--- /dev/null
+++ b/src/lib/libssl/src/VMS/socketshr_shr.opt
@@ -0,0 +1 @@
socketshr/share
diff --git a/src/lib/libssl/src/VMS/test-includes.com b/src/lib/libssl/src/VMS/test-includes.com
new file mode 100644
index 0000000000..c1d7ccd0ee
--- /dev/null
+++ b/src/lib/libssl/src/VMS/test-includes.com
@@ -0,0 +1,28 @@
1$! Quick script to check how well including individual header files works
2$! on VMS, even when the VMS macro isn't defined.
3$
4$ sav_def = f$env("DEFAULT")
5$ here = f$parse("A.;0",f$ENV("PROCEDURE")) - "A.;0"
6$ set default 'here'
7$ set default [-.include.openssl]
8$ define openssl 'f$env("DEFAULT")'
9$ set default [--]
10$
11$ loop:
12$ f = f$search("openssl:*.h")
13$ if f .eqs. "" then goto loop_end
14$ write sys$output "Checking ",f
15$ open/write foo foo.c
16$ write foo "#undef VMS"
17$ write foo "#include <stdio.h>"
18$ write foo "#include <openssl/",f$parse(f,,,"NAME"),".h>"
19$ write foo "main()"
20$ write foo "{printf(""foo\n"");}"
21$ close foo
22$ cc/STANDARD=ANSI89/NOLIST/PREFIX=ALL foo.c
23$ delete foo.c;
24$ goto loop
25$ loop_end:
26$ set default 'save_def'
27$ exit
28
diff --git a/src/lib/libssl/src/VMS/ucx_shr_decc.opt b/src/lib/libssl/src/VMS/ucx_shr_decc.opt
new file mode 100644
index 0000000000..28d84f4af6
--- /dev/null
+++ b/src/lib/libssl/src/VMS/ucx_shr_decc.opt
@@ -0,0 +1 @@
sys$share:ucx$ipc_shr.exe/share
diff --git a/src/lib/libssl/src/VMS/ucx_shr_decc_log.opt b/src/lib/libssl/src/VMS/ucx_shr_decc_log.opt
new file mode 100644
index 0000000000..c9d9a96d09
--- /dev/null
+++ b/src/lib/libssl/src/VMS/ucx_shr_decc_log.opt
@@ -0,0 +1 @@
ucx$ipc_shr/share
diff --git a/src/lib/libssl/src/VMS/ucx_shr_vaxc.opt b/src/lib/libssl/src/VMS/ucx_shr_vaxc.opt
new file mode 100644
index 0000000000..86bfaf0d07
--- /dev/null
+++ b/src/lib/libssl/src/VMS/ucx_shr_vaxc.opt
@@ -0,0 +1 @@
sys$library:ucx$ipc.olb/library
diff --git a/src/lib/libssl/src/apps/CA.com b/src/lib/libssl/src/apps/CA.com
new file mode 100644
index 0000000000..f324788eca
--- /dev/null
+++ b/src/lib/libssl/src/apps/CA.com
@@ -0,0 +1,200 @@
1$! CA - wrapper around ca to make it easier to use ... basically ca requires
2$! some setup stuff to be done before you can use it and this makes
3$! things easier between now and when Eric is convinced to fix it :-)
4$!
5$! CA -newca ... will setup the right stuff
6$! CA -newreq ... will generate a certificate request
7$! CA -sign ... will sign the generated request and output
8$!
9$! At the end of that grab newreq.pem and newcert.pem (one has the key
10$! and the other the certificate) and cat them together and that is what
11$! you want/need ... I'll make even this a little cleaner later.
12$!
13$!
14$! 12-Jan-96 tjh Added more things ... including CA -signcert which
15$! converts a certificate to a request and then signs it.
16$! 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
17$! environment variable so this can be driven from
18$! a script.
19$! 25-Jul-96 eay Cleaned up filenames some more.
20$! 11-Jun-96 eay Fixed a few filename missmatches.
21$! 03-May-96 eay Modified to use 'openssl cmd' instead of 'cmd'.
22$! 18-Apr-96 tjh Original hacking
23$!
24$! Tim Hudson
25$! tjh@cryptsoft.com
26$!
27$!
28$! default ssleay.cnf file has setup as per the following
29$! demoCA ... where everything is stored
30$
31$ IF F$TYPE(SSLEAY_CONFIG) .EQS. "" THEN SSLEAY_CONFIG := SSLLIB:SSLEAY.CNF
32$
33$ DAYS = "-days 365"
34$ REQ = openssl + " req " + SSLEAY_CONFIG
35$ CA = openssl + " ca " + SSLEAY_CONFIG
36$ VERIFY = openssl + " verify"
37$ X509 = openssl + " x509"
38$ echo = "write sys$Output"
39$!
40$ s = F$PARSE(F$ENVIRONMENT("DEFAULT"),"[]") - "].;"
41$ CATOP := 's'.demoCA
42$ CAKEY := ]cakey.pem
43$ CACERT := ]cacert.pem
44$
45$ __INPUT := SYS$COMMAND
46$ RET = 1
47$!
48$ i = 1
49$opt_loop:
50$ if i .gt. 8 then goto opt_loop_end
51$
52$ prog_opt = F$EDIT(P'i',"lowercase")
53$
54$ IF (prog_opt .EQS. "?" .OR. prog_opt .EQS. "-h" .OR. prog_opt .EQS. "-help")
55$ THEN
56$ echo "usage: CA -newcert|-newreq|-newca|-sign|-verify"
57$ exit
58$ ENDIF
59$!
60$ IF (prog_opt .EQS. "-input")
61$ THEN
62$ ! Get input from somewhere other than SYS$COMMAND
63$ i = i + 1
64$ __INPUT = P'i'
65$ GOTO opt_loop_continue
66$ ENDIF
67$!
68$ IF (prog_opt .EQS. "-newcert")
69$ THEN
70$ ! Create a certificate.
71$ DEFINE/USER SYS$INPUT '__INPUT'
72$ REQ -new -x509 -keyout newreq.pem -out newreq.pem 'DAYS'
73$ RET=$STATUS
74$ echo "Certificate (and private key) is in newreq.pem"
75$ GOTO opt_loop_continue
76$ ENDIF
77$!
78$ IF (prog_opt .EQS. "-newreq")
79$ THEN
80$ ! Create a certificate request
81$ DEFINE/USER SYS$INPUT '__INPUT'
82$ REQ -new -keyout newreq.pem -out newreq.pem 'DAYS'
83$ RET=$STATUS
84$ echo "Request (and private key) is in newreq.pem"
85$ GOTO opt_loop_continue
86$ ENDIF
87$!
88$ IF (prog_opt .EQS. "-newca")
89$ THEN
90$ ! If explicitly asked for or it doesn't exist then setup the directory
91$ ! structure that Eric likes to manage things.
92$ IF F$SEARCH(CATOP+"]serial.") .EQS. ""
93$ THEN
94$ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP']
95$ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.certs]
96$ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.crl]
97$ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.newcerts]
98$ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.private]
99$ OPEN /WRITE ser_file 'CATOP']serial.
100$ WRITE ser_file "01"
101$ CLOSE ser_file
102$ APPEND/NEW NL: 'CATOP']index.txt
103$ ENDIF
104$!
105$ IF F$SEARCH(CATOP+".private"+CAKEY) .EQS. ""
106$ THEN
107$ READ '__INPUT' FILE -
108 /PROMT="CA certificate filename (or enter to create)"
109$ IF F$SEARCH(FILE) .NES. ""
110$ THEN
111$ COPY 'FILE' 'CATOP'.private'CAKEY'
112$ RET=$STATUS
113$ ELSE
114$ echo "Making CA certificate ..."
115$ DEFINE/USER SYS$INPUT '__INPUT'
116$ REQ -new -x509 -keyout 'CATOP'.private'CAKEY' -
117 -out 'CATOP''CACERT' 'DAYS'
118$ RET=$STATUS
119$ ENDIF
120$ ENDIF
121$ GOTO opt_loop_continue
122$ ENDIF
123$!
124$ IF (prog_opt .EQS. "-xsign")
125$ THEN
126$!
127$ DEFINE/USER SYS$INPUT '__INPUT'
128$ CA -policy policy_anything -infiles newreq.pem
129$ RET=$STATUS
130$ GOTO opt_loop_continue
131$ ENDIF
132$!
133$ IF ((prog_opt .EQS. "-sign") .OR. (prog_opt .EQS. "-signreq"))
134$ THEN
135$!
136$ DEFINE/USER SYS$INPUT '__INPUT'
137$ CA -policy policy_anything -out newcert.pem -infiles newreq.pem
138$ RET=$STATUS
139$ type newcert.pem
140$ echo "Signed certificate is in newcert.pem"
141$ GOTO opt_loop_continue
142$ ENDIF
143$!
144$ IF (prog_opt .EQS. "-signcert")
145$ THEN
146$!
147$ echo "Cert passphrase will be requested twice - bug?"
148$ DEFINE/USER SYS$INPUT '__INPUT'
149$ X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
150$ DEFINE/USER SYS$INPUT '__INPUT'
151$ CA -policy policy_anything -out newcert.pem -infiles tmp.pem
152y
153y
154$ type newcert.pem
155$ echo "Signed certificate is in newcert.pem"
156$ GOTO opt_loop_continue
157$ ENDIF
158$!
159$ IF (prog_opt .EQS. "-verify")
160$ THEN
161$!
162$ i = i + 1
163$ IF (p'i' .EQS. "")
164$ THEN
165$ DEFINE/USER SYS$INPUT '__INPUT'
166$ VERIFY "-CAfile" 'CATOP''CACERT' newcert.pem
167$ ELSE
168$ j = i
169$ verify_opt_loop:
170$ IF j .GT. 8 THEN GOTO verify_opt_loop_end
171$ IF p'j' .NES. ""
172$ THEN
173$ DEFINE/USER SYS$INPUT '__INPUT'
174$ __tmp = p'j'
175$ VERIFY "-CAfile" 'CATOP''CACERT' '__tmp'
176$ tmp=$STATUS
177$ IF tmp .NE. 0 THEN RET=tmp
178$ ENDIF
179$ j = j + 1
180$ GOTO verify_opt_loop
181$ verify_opt_loop_end:
182$ ENDIF
183$
184$ GOTO opt_loop_end
185$ ENDIF
186$!
187$ IF (prog_opt .NES. "")
188$ THEN
189$!
190$ echo "Unknown argument ''prog_opt'"
191$
192$ EXIT 3
193$ ENDIF
194$
195$opt_loop_continue:
196$ i = i + 1
197$ GOTO opt_loop
198$
199$opt_loop_end:
200$ EXIT 'RET'
diff --git a/src/lib/libssl/src/apps/CA.pl b/src/lib/libssl/src/apps/CA.pl
new file mode 100644
index 0000000000..7c023ae71f
--- /dev/null
+++ b/src/lib/libssl/src/apps/CA.pl
@@ -0,0 +1,153 @@
1#!/usr/local/bin/perl
2#
3# CA - wrapper around ca to make it easier to use ... basically ca requires
4# some setup stuff to be done before you can use it and this makes
5# things easier between now and when Eric is convinced to fix it :-)
6#
7# CA -newca ... will setup the right stuff
8# CA -newreq ... will generate a certificate request
9# CA -sign ... will sign the generated request and output
10#
11# At the end of that grab newreq.pem and newcert.pem (one has the key
12# and the other the certificate) and cat them together and that is what
13# you want/need ... I'll make even this a little cleaner later.
14#
15#
16# 12-Jan-96 tjh Added more things ... including CA -signcert which
17# converts a certificate to a request and then signs it.
18# 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
19# environment variable so this can be driven from
20# a script.
21# 25-Jul-96 eay Cleaned up filenames some more.
22# 11-Jun-96 eay Fixed a few filename missmatches.
23# 03-May-96 eay Modified to use 'ssleay cmd' instead of 'cmd'.
24# 18-Apr-96 tjh Original hacking
25#
26# Tim Hudson
27# tjh@cryptsoft.com
28#
29
30# 27-Apr-98 snh Translation into perl, fix existing CA bug.
31#
32#
33# Steve Henson
34# shenson@bigfoot.com
35
36# default openssl.cnf file has setup as per the following
37# demoCA ... where everything is stored
38
39$DAYS="-days 365";
40$REQ="openssl req $SSLEAY_CONFIG";
41$CA="openssl ca $SSLEAY_CONFIG";
42$VERIFY="openssl verify";
43$X509="openssl x509";
44
45$CATOP="./demoCA";
46$CAKEY="cakey.pem";
47$CACERT="cacert.pem";
48
49$DIRMODE = 0777;
50
51$RET = 0;
52
53foreach (@ARGV) {
54 if ( /^(-\?|-h|-help)$/ ) {
55 print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n";
56 exit 0;
57 } elsif (/^-newcert$/) {
58 # create a certificate
59 system ("$REQ -new -x509 -keyout newreq.pem -out newreq.pem $DAYS");
60 $RET=$?;
61 print "Certificate (and private key) is in newreq.pem\n"
62 } elsif (/^-newreq$/) {
63 # create a certificate request
64 system ("$REQ -new -keyout newreq.pem -out newreq.pem $DAYS");
65 $RET=$?;
66 print "Request (and private key) is in newreq.pem\n";
67 } elsif (/^-newca$/) {
68 # if explictly asked for or it doesn't exist then setup the
69 # directory structure that Eric likes to manage things
70 $NEW="1";
71 if ( "$NEW" || ! -f "${CATOP}/serial" ) {
72 # create the directory hierarchy
73 mkdir $CATOP, $DIRMODE;
74 mkdir "${CATOP}/certs", $DIRMODE;
75 mkdir "${CATOP}/crl", $DIRMODE ;
76 mkdir "${CATOP}/newcerts", $DIRMODE;
77 mkdir "${CATOP}/private", $DIRMODE;
78 open OUT, ">${CATOP}/serial";
79 print OUT "01\n";
80 close OUT;
81 open OUT, ">${CATOP}/index.txt";
82 close OUT;
83 }
84 if ( ! -f "${CATOP}/private/$CAKEY" ) {
85 print "CA certificate filename (or enter to create)\n";
86 $FILE = <STDIN>;
87
88 chop $FILE;
89
90 # ask user for existing CA certificate
91 if ($FILE) {
92 cp_pem($FILE,"${CATOP}/private/$CAKEY", "PRIVATE");
93 cp_pem($FILE,"${CATOP}/$CACERT", "CERTIFICATE");
94 $RET=$?;
95 } else {
96 print "Making CA certificate ...\n";
97 system ("$REQ -new -x509 -keyout " .
98 "${CATOP}/private/$CAKEY -out ${CATOP}/$CACERT $DAYS");
99 $RET=$?;
100 }
101 }
102 } elsif (/^-xsign$/) {
103 system ("$CA -policy policy_anything -infiles newreq.pem");
104 $RET=$?;
105 } elsif (/^(-sign|-signreq)$/) {
106 system ("$CA -policy policy_anything -out newcert.pem " .
107 "-infiles newreq.pem");
108 $RET=$?;
109 print "Signed certificate is in newcert.pem\n";
110 } elsif (/^-signcert$/) {
111 system ("$X509 -x509toreq -in newreq.pem -signkey newreq.pem " .
112 "-out tmp.pem");
113 system ("$CA -policy policy_anything -out newcert.pem " .
114 "-infiles tmp.pem");
115 $RET = $?;
116 print "Signed certificate is in newcert.pem\n";
117 } elsif (/^-verify$/) {
118 if (shift) {
119 foreach $j (@ARGV) {
120 system ("$VERIFY -CAfile $CATOP/$CACERT $j");
121 $RET=$? if ($? != 0);
122 }
123 exit $RET;
124 } else {
125 system ("$VERIFY -CAfile $CATOP/$CACERT newcert.pem");
126 $RET=$?;
127 exit 0;
128 }
129 } else {
130 print STDERR "Unknown arg $_\n";
131 print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n";
132 exit 1;
133 }
134}
135
136exit $RET;
137
138sub cp_pem {
139my ($infile, $outfile, $bound) = @_;
140open IN, $infile;
141open OUT, ">$outfile";
142my $flag = 0;
143while (<IN>) {
144 $flag = 1 if (/^-----BEGIN.*$bound/) ;
145 print OUT $_ if ($flag);
146 if (/^-----END.*$bound/) {
147 close IN;
148 close OUT;
149 return;
150 }
151}
152}
153
diff --git a/src/lib/libssl/src/apps/CA.pl.in b/src/lib/libssl/src/apps/CA.pl.in
new file mode 100644
index 0000000000..4eef57e6e3
--- /dev/null
+++ b/src/lib/libssl/src/apps/CA.pl.in
@@ -0,0 +1,162 @@
1#!/usr/local/bin/perl
2#
3# CA - wrapper around ca to make it easier to use ... basically ca requires
4# some setup stuff to be done before you can use it and this makes
5# things easier between now and when Eric is convinced to fix it :-)
6#
7# CA -newca ... will setup the right stuff
8# CA -newreq ... will generate a certificate request
9# CA -sign ... will sign the generated request and output
10#
11# At the end of that grab newreq.pem and newcert.pem (one has the key
12# and the other the certificate) and cat them together and that is what
13# you want/need ... I'll make even this a little cleaner later.
14#
15#
16# 12-Jan-96 tjh Added more things ... including CA -signcert which
17# converts a certificate to a request and then signs it.
18# 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
19# environment variable so this can be driven from
20# a script.
21# 25-Jul-96 eay Cleaned up filenames some more.
22# 11-Jun-96 eay Fixed a few filename missmatches.
23# 03-May-96 eay Modified to use 'ssleay cmd' instead of 'cmd'.
24# 18-Apr-96 tjh Original hacking
25#
26# Tim Hudson
27# tjh@cryptsoft.com
28#
29
30# 27-Apr-98 snh Translation into perl, fix existing CA bug.
31#
32#
33# Steve Henson
34# shenson@bigfoot.com
35
36# default openssl.cnf file has setup as per the following
37# demoCA ... where everything is stored
38
39$DAYS="-days 365";
40$REQ="openssl req $SSLEAY_CONFIG";
41$CA="openssl ca $SSLEAY_CONFIG";
42$VERIFY="openssl verify";
43$X509="openssl x509";
44$PKCS12="openssl pkcs12";
45
46$CATOP="./demoCA";
47$CAKEY="cakey.pem";
48$CACERT="cacert.pem";
49
50$DIRMODE = 0777;
51
52$RET = 0;
53
54foreach (@ARGV) {
55 if ( /^(-\?|-h|-help)$/ ) {
56 print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n";
57 exit 0;
58 } elsif (/^-newcert$/) {
59 # create a certificate
60 system ("$REQ -new -x509 -keyout newreq.pem -out newreq.pem $DAYS");
61 $RET=$?;
62 print "Certificate (and private key) is in newreq.pem\n"
63 } elsif (/^-newreq$/) {
64 # create a certificate request
65 system ("$REQ -new -keyout newreq.pem -out newreq.pem $DAYS");
66 $RET=$?;
67 print "Request (and private key) is in newreq.pem\n";
68 } elsif (/^-newca$/) {
69 # if explicitly asked for or it doesn't exist then setup the
70 # directory structure that Eric likes to manage things
71 $NEW="1";
72 if ( "$NEW" || ! -f "${CATOP}/serial" ) {
73 # create the directory hierarchy
74 mkdir $CATOP, $DIRMODE;
75 mkdir "${CATOP}/certs", $DIRMODE;
76 mkdir "${CATOP}/crl", $DIRMODE ;
77 mkdir "${CATOP}/newcerts", $DIRMODE;
78 mkdir "${CATOP}/private", $DIRMODE;
79 open OUT, ">${CATOP}/serial";
80 print OUT "01\n";
81 close OUT;
82 open OUT, ">${CATOP}/index.txt";
83 close OUT;
84 }
85 if ( ! -f "${CATOP}/private/$CAKEY" ) {
86 print "CA certificate filename (or enter to create)\n";
87 $FILE = <STDIN>;
88
89 chop $FILE;
90
91 # ask user for existing CA certificate
92 if ($FILE) {
93 cp_pem($FILE,"${CATOP}/private/$CAKEY", "PRIVATE");
94 cp_pem($FILE,"${CATOP}/$CACERT", "CERTIFICATE");
95 $RET=$?;
96 } else {
97 print "Making CA certificate ...\n";
98 system ("$REQ -new -x509 -keyout " .
99 "${CATOP}/private/$CAKEY -out ${CATOP}/$CACERT $DAYS");
100 $RET=$?;
101 }
102 }
103 } elsif (/^-pkcs12$/) {
104 my $cname = $ARGV[1];
105 $cname = "My Certificate" unless defined $cname;
106 system ("$PKCS12 -in newcert.pem -inkey newreq.pem " .
107 "-certfile ${CATOP}/$CACERT -out newcert.p12 " .
108 "-export -name \"$cname\"");
109 $RET=$?;
110 exit $RET;
111 } elsif (/^-xsign$/) {
112 system ("$CA -policy policy_anything -infiles newreq.pem");
113 $RET=$?;
114 } elsif (/^(-sign|-signreq)$/) {
115 system ("$CA -policy policy_anything -out newcert.pem " .
116 "-infiles newreq.pem");
117 $RET=$?;
118 print "Signed certificate is in newcert.pem\n";
119 } elsif (/^-signcert$/) {
120 system ("$X509 -x509toreq -in newreq.pem -signkey newreq.pem " .
121 "-out tmp.pem");
122 system ("$CA -policy policy_anything -out newcert.pem " .
123 "-infiles tmp.pem");
124 $RET = $?;
125 print "Signed certificate is in newcert.pem\n";
126 } elsif (/^-verify$/) {
127 if (shift) {
128 foreach $j (@ARGV) {
129 system ("$VERIFY -CAfile $CATOP/$CACERT $j");
130 $RET=$? if ($? != 0);
131 }
132 exit $RET;
133 } else {
134 system ("$VERIFY -CAfile $CATOP/$CACERT newcert.pem");
135 $RET=$?;
136 exit 0;
137 }
138 } else {
139 print STDERR "Unknown arg $_\n";
140 print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n";
141 exit 1;
142 }
143}
144
145exit $RET;
146
147sub cp_pem {
148my ($infile, $outfile, $bound) = @_;
149open IN, $infile;
150open OUT, ">$outfile";
151my $flag = 0;
152while (<IN>) {
153 $flag = 1 if (/^-----BEGIN.*$bound/) ;
154 print OUT $_ if ($flag);
155 if (/^-----END.*$bound/) {
156 close IN;
157 close OUT;
158 return;
159 }
160}
161}
162
diff --git a/src/lib/libssl/src/apps/app_rand.c b/src/lib/libssl/src/apps/app_rand.c
new file mode 100644
index 0000000000..f7f133831d
--- /dev/null
+++ b/src/lib/libssl/src/apps/app_rand.c
@@ -0,0 +1,211 @@
1/* apps/app_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "apps.h"
113#include <openssl/bio.h>
114#include <openssl/rand.h>
115
116
117static int seeded = 0;
118static int egdsocket = 0;
119
120int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn)
121 {
122 int consider_randfile = (file == NULL);
123 char buffer[200];
124
125#ifdef WINDOWS
126 BIO_printf(bio_e,"Loading 'screen' into random state -");
127 BIO_flush(bio_e);
128 RAND_screen();
129 BIO_printf(bio_e," done\n");
130#endif
131
132 if (file == NULL)
133 file = RAND_file_name(buffer, sizeof buffer);
134 else if (RAND_egd(file) > 0)
135 {
136 /* we try if the given filename is an EGD socket.
137 if it is, we don't write anything back to the file. */
138 egdsocket = 1;
139 return 1;
140 }
141 if (file == NULL || !RAND_load_file(file, -1))
142 {
143 if (RAND_status() == 0 && !dont_warn)
144 {
145 BIO_printf(bio_e,"unable to load 'random state'\n");
146 BIO_printf(bio_e,"This means that the random number generator has not been seeded\n");
147 BIO_printf(bio_e,"with much random data.\n");
148 if (consider_randfile) /* explanation does not apply when a file is explicitly named */
149 {
150 BIO_printf(bio_e,"Consider setting the RANDFILE environment variable to point at a file that\n");
151 BIO_printf(bio_e,"'random' data can be kept in (the file will be overwritten).\n");
152 }
153 }
154 return 0;
155 }
156 seeded = 1;
157 return 1;
158 }
159
160long app_RAND_load_files(char *name)
161 {
162 char *p,*n;
163 int last;
164 long tot=0;
165 int egd;
166
167 for (;;)
168 {
169 last=0;
170 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++);
171 if (*p == '\0') last=1;
172 *p='\0';
173 n=name;
174 name=p+1;
175 if (*n == '\0') break;
176
177 egd=RAND_egd(n);
178 if (egd > 0) tot+=egd;
179 tot+=RAND_load_file(n,1024L*1024L);
180 if (last) break;
181 }
182 if (tot > 512)
183 app_RAND_allow_write_file();
184 return(tot);
185 }
186
187int app_RAND_write_file(const char *file, BIO *bio_e)
188 {
189 char buffer[200];
190
191 if (egdsocket || !seeded)
192 /* If we did not manage to read the seed file,
193 * we should not write a low-entropy seed file back --
194 * it would suppress a crucial warning the next time
195 * we want to use it. */
196 return 0;
197
198 if (file == NULL)
199 file = RAND_file_name(buffer, sizeof buffer);
200 if (file == NULL || !RAND_write_file(file))
201 {
202 BIO_printf(bio_e,"unable to write 'random state'\n");
203 return 0;
204 }
205 return 1;
206 }
207
208void app_RAND_allow_write_file(void)
209 {
210 seeded = 1;
211 }
diff --git a/src/lib/libssl/src/apps/dh2048.pem b/src/lib/libssl/src/apps/dh2048.pem
new file mode 100644
index 0000000000..dcd0b8d01b
--- /dev/null
+++ b/src/lib/libssl/src/apps/dh2048.pem
@@ -0,0 +1,12 @@
1-----BEGIN DH PARAMETERS-----
2MIIBCAKCAQEA9kJXtwh/CBdyorrWqULzBej5UxE5T7bxbrlLOCDaAadWoxTpj0BV
389AHxstDqZSt90xkhkn4DIO9ZekX1KHTUPj1WV/cdlJPPT2N286Z4VeSWc39uK50
4T8X8dryDxUcwYc58yWb/Ffm7/ZFexwGq01uejaClcjrUGvC/RgBYK+X0iP1YTknb
5zSC0neSRBzZrM2w4DUUdD3yIsxx8Wy2O9vPJI8BD8KVbGI2Ou1WMuF040zT9fBdX
6Q6MdGGzeMyEstSr/POGxKUAYEY18hKcKctaGxAMZyAcpesqVDNmWn6vQClCbAkbT
7CD1mpF1Bn5x8vYlLIhkmuquiXsNV6TILOwIBAg==
8-----END DH PARAMETERS-----
9
10These are the 2048 bit DH parameters from "Assigned Number for SKIP Protocols"
11(http://www.skip-vpn.org/spec/numbers.html).
12See there for how they were generated.
diff --git a/src/lib/libssl/src/apps/dh4096.pem b/src/lib/libssl/src/apps/dh4096.pem
new file mode 100644
index 0000000000..1b35ad8e62
--- /dev/null
+++ b/src/lib/libssl/src/apps/dh4096.pem
@@ -0,0 +1,18 @@
1-----BEGIN DH PARAMETERS-----
2MIICCAKCAgEA+hRyUsFN4VpJ1O8JLcCo/VWr19k3BCgJ4uk+d+KhehjdRqNDNyOQ
3l/MOyQNQfWXPeGKmOmIig6Ev/nm6Nf9Z2B1h3R4hExf+zTiHnvVPeRBhjdQi81rt
4Xeoh6TNrSBIKIHfUJWBh3va0TxxjQIs6IZOLeVNRLMqzeylWqMf49HsIXqbcokUS
5Vt1BkvLdW48j8PPv5DsKRN3tloTxqDJGo9tKvj1Fuk74A+Xda1kNhB7KFlqMyN98
6VETEJ6c7KpfOo30mnK30wqw3S8OtaIR/maYX72tGOno2ehFDkq3pnPtEbD2CScxc
7alJC+EL7RPk5c/tgeTvCngvc1KZn92Y//EI7G9tPZtylj2b56sHtMftIoYJ9+ODM
8sccD5Piz/rejE3Ome8EOOceUSCYAhXn8b3qvxVI1ddd1pED6FHRhFvLrZxFvBEM9
9ERRMp5QqOaHJkM+Dxv8Cj6MqrCbfC4u+ZErxodzuusgDgvZiLF22uxMZbobFWyte
10OvOzKGtwcTqO/1wV5gKkzu1ZVswVUQd5Gg8lJicwqRWyyNRczDDoG9jVDxmogKTH
11AaqLulO7R8Ifa1SwF2DteSGVtgWEN8gDpN3RBmmPTDngyF2DHb5qmpnznwtFKdTL
12KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=
13-----END DH PARAMETERS-----
14
15These are the 4096 bit DH parameters from "Assigned Number for SKIP Protocols"
16(http://www.skip-vpn.org/spec/numbers.html).
17See there for how they were generated.
18Note that g is not a generator, but this is not a problem since p is a safe prime.
diff --git a/src/lib/libssl/src/apps/dh512.pem b/src/lib/libssl/src/apps/dh512.pem
new file mode 100644
index 0000000000..200d16cd89
--- /dev/null
+++ b/src/lib/libssl/src/apps/dh512.pem
@@ -0,0 +1,9 @@
1-----BEGIN DH PARAMETERS-----
2MEYCQQD1Kv884bEpQBgRjXyEpwpy1obEAxnIByl6ypUM2Zafq9AKUJsCRtMIPWak
3XUGfnHy9iUsiGSa6q6Jew1XpKgVfAgEC
4-----END DH PARAMETERS-----
5
6These are the 512 bit DH parameters from "Assigned Number for SKIP Protocols"
7(http://www.skip-vpn.org/spec/numbers.html).
8See there for how they were generated.
9Note that g is not a generator, but this is not a problem since p is a safe prime.
diff --git a/src/lib/libssl/src/apps/dhparam.c b/src/lib/libssl/src/apps/dhparam.c
new file mode 100644
index 0000000000..293a400d0c
--- /dev/null
+++ b/src/lib/libssl/src/apps/dhparam.c
@@ -0,0 +1,368 @@
1/* apps/dhparam.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_DH
60#include <stdio.h>
61#include <stdlib.h>
62#include <time.h>
63#include <string.h>
64#include "apps.h"
65#include <openssl/bio.h>
66#include <openssl/err.h>
67#include <openssl/bn.h>
68#include <openssl/dh.h>
69#include <openssl/x509.h>
70#include <openssl/pem.h>
71
72#undef PROG
73#define PROG dhparam_main
74
75#define DEFBITS 512
76
77/* -inform arg - input format - default PEM (DER or PEM)
78 * -outform arg - output format - default PEM
79 * -in arg - input file - default stdin
80 * -out arg - output file - default stdout
81 * -check - check the parameters are ok
82 * -noout
83 * -text
84 * -C
85 */
86
87static void MS_CALLBACK dh_cb(int p, int n, void *arg);
88
89int MAIN(int, char **);
90
91int MAIN(int argc, char **argv)
92 {
93 DH *dh=NULL;
94 int i,badops=0,text=0;
95 BIO *in=NULL,*out=NULL;
96 int informat,outformat,check=0,noout=0,C=0,ret=1;
97 char *infile,*outfile,*prog;
98 char *inrand=NULL;
99 int num = 0, g = 0;
100
101 apps_startup();
102
103 if (bio_err == NULL)
104 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
105 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
106
107 infile=NULL;
108 outfile=NULL;
109 informat=FORMAT_PEM;
110 outformat=FORMAT_PEM;
111
112 prog=argv[0];
113 argc--;
114 argv++;
115 while (argc >= 1)
116 {
117 if (strcmp(*argv,"-inform") == 0)
118 {
119 if (--argc < 1) goto bad;
120 informat=str2fmt(*(++argv));
121 }
122 else if (strcmp(*argv,"-outform") == 0)
123 {
124 if (--argc < 1) goto bad;
125 outformat=str2fmt(*(++argv));
126 }
127 else if (strcmp(*argv,"-in") == 0)
128 {
129 if (--argc < 1) goto bad;
130 infile= *(++argv);
131 }
132 else if (strcmp(*argv,"-out") == 0)
133 {
134 if (--argc < 1) goto bad;
135 outfile= *(++argv);
136 }
137 else if (strcmp(*argv,"-check") == 0)
138 check=1;
139 else if (strcmp(*argv,"-text") == 0)
140 text=1;
141 else if (strcmp(*argv,"-C") == 0)
142 C=1;
143 else if (strcmp(*argv,"-noout") == 0)
144 noout=1;
145 else if (strcmp(*argv,"-2") == 0)
146 g=2;
147 else if (strcmp(*argv,"-5") == 0)
148 g=5;
149 else if (strcmp(*argv,"-rand") == 0)
150 {
151 if (--argc < 1) goto bad;
152 inrand= *(++argv);
153 }
154 else if (((sscanf(*argv,"%d",&num) == 0) || (num <= 0)))
155 goto bad;
156 argv++;
157 argc--;
158 }
159
160 if (badops)
161 {
162bad:
163 BIO_printf(bio_err,"%s [options] [numbits]\n",prog);
164 BIO_printf(bio_err,"where options are\n");
165 BIO_printf(bio_err," -inform arg input format - one of DER PEM\n");
166 BIO_printf(bio_err," -outform arg output format - one of DER PEM\n");
167 BIO_printf(bio_err," -in arg input file\n");
168 BIO_printf(bio_err," -out arg output file\n");
169 BIO_printf(bio_err," -check check the DH parameters\n");
170 BIO_printf(bio_err," -text print a text form of the DH parameters\n");
171 BIO_printf(bio_err," -C Output C code\n");
172 BIO_printf(bio_err," -2 generate parameters using 2 as the generator value\n");
173 BIO_printf(bio_err," -5 generate parameters using 5 as the generator value\n");
174 BIO_printf(bio_err," numbits number of bits in to generate (default 512)\n");
175 BIO_printf(bio_err," -rand file:file:...\n");
176 BIO_printf(bio_err," - load the file (or the files in the directory) into\n");
177 BIO_printf(bio_err," the random number generator\n");
178 BIO_printf(bio_err," -noout no output\n");
179 goto end;
180 }
181
182 ERR_load_crypto_strings();
183
184 if(g && !num) num = DEFBITS;
185 else if(num && !g) g = 2;
186
187 if(num) {
188
189 if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL)
190 {
191 BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n");
192 }
193 if (inrand != NULL)
194 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
195 app_RAND_load_files(inrand));
196
197 BIO_printf(bio_err,"Generating DH parameters, %d bit long strong prime, generator of %d\n",num,g);
198 BIO_printf(bio_err,"This is going to take a long time\n");
199 dh=DH_generate_parameters(num,g,dh_cb,bio_err);
200
201 if (dh == NULL) goto end;
202
203 app_RAND_write_file(NULL, bio_err);
204 } else {
205
206 in=BIO_new(BIO_s_file());
207 if (in == NULL)
208 {
209 ERR_print_errors(bio_err);
210 goto end;
211 }
212 if (infile == NULL)
213 BIO_set_fp(in,stdin,BIO_NOCLOSE);
214 else
215 {
216 if (BIO_read_filename(in,infile) <= 0)
217 {
218 perror(infile);
219 goto end;
220 }
221 }
222
223 if (informat == FORMAT_ASN1)
224 dh=d2i_DHparams_bio(in,NULL);
225 else if (informat == FORMAT_PEM)
226 dh=PEM_read_bio_DHparams(in,NULL,NULL,NULL);
227 else
228 {
229 BIO_printf(bio_err,"bad input format specified\n");
230 goto end;
231 }
232 if (dh == NULL)
233 {
234 BIO_printf(bio_err,"unable to load DH parameters\n");
235 ERR_print_errors(bio_err);
236 goto end;
237 }
238
239 }
240
241 out=BIO_new(BIO_s_file());
242 if (out == NULL)
243 {
244 ERR_print_errors(bio_err);
245 goto end;
246 }
247 if (outfile == NULL)
248 BIO_set_fp(out,stdout,BIO_NOCLOSE);
249 else
250 {
251 if (BIO_write_filename(out,outfile) <= 0)
252 {
253 perror(outfile);
254 goto end;
255 }
256 }
257
258
259
260 if (text)
261 {
262 DHparams_print(out,dh);
263 }
264
265 if (check)
266 {
267 if (!DH_check(dh,&i))
268 {
269 ERR_print_errors(bio_err);
270 goto end;
271 }
272 if (i & DH_CHECK_P_NOT_PRIME)
273 printf("p value is not prime\n");
274 if (i & DH_CHECK_P_NOT_STRONG_PRIME)
275 printf("p value is not a strong prime\n");
276 if (i & DH_UNABLE_TO_CHECK_GENERATOR)
277 printf("unable to check the generator value\n");
278 if (i & DH_NOT_SUITABLE_GENERATOR)
279 printf("the g value is not a generator\n");
280 if (i == 0)
281 printf("DH parameters appear to be ok.\n");
282 }
283 if (C)
284 {
285 unsigned char *data;
286 int len,l,bits;
287
288 len=BN_num_bytes(dh->p);
289 bits=BN_num_bits(dh->p);
290 data=(unsigned char *)Malloc(len);
291 if (data == NULL)
292 {
293 perror("Malloc");
294 goto end;
295 }
296 l=BN_bn2bin(dh->p,data);
297 printf("static unsigned char dh%d_p[]={",bits);
298 for (i=0; i<l; i++)
299 {
300 if ((i%12) == 0) printf("\n\t");
301 printf("0x%02X,",data[i]);
302 }
303 printf("\n\t};\n");
304
305 l=BN_bn2bin(dh->g,data);
306 printf("static unsigned char dh%d_g[]={",bits);
307 for (i=0; i<l; i++)
308 {
309 if ((i%12) == 0) printf("\n\t");
310 printf("0x%02X,",data[i]);
311 }
312 printf("\n\t};\n\n");
313
314 printf("DH *get_dh%d()\n\t{\n",bits);
315 printf("\tDH *dh;\n\n");
316 printf("\tif ((dh=DH_new()) == NULL) return(NULL);\n");
317 printf("\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n",
318 bits,bits);
319 printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n",
320 bits,bits);
321 printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n");
322 printf("\t\treturn(NULL);\n");
323 printf("\treturn(dh);\n\t}\n");
324 Free(data);
325 }
326
327
328 if (!noout)
329 {
330 if (outformat == FORMAT_ASN1)
331 i=i2d_DHparams_bio(out,dh);
332 else if (outformat == FORMAT_PEM)
333 i=PEM_write_bio_DHparams(out,dh);
334 else {
335 BIO_printf(bio_err,"bad output format specified for outfile\n");
336 goto end;
337 }
338 if (!i)
339 {
340 BIO_printf(bio_err,"unable to write DH parameters\n");
341 ERR_print_errors(bio_err);
342 goto end;
343 }
344 }
345 ret=0;
346end:
347 if (in != NULL) BIO_free(in);
348 if (out != NULL) BIO_free(out);
349 if (dh != NULL) DH_free(dh);
350 EXIT(ret);
351 }
352
353static void MS_CALLBACK dh_cb(int p, int n, void *arg)
354 {
355 char c='*';
356
357 if (p == 0) c='.';
358 if (p == 1) c='+';
359 if (p == 2) c='*';
360 if (p == 3) c='\n';
361 BIO_write((BIO *)arg,&c,1);
362 (void)BIO_flush((BIO *)arg);
363#ifdef LINT
364 p=n;
365#endif
366 }
367
368#endif
diff --git a/src/lib/libssl/src/apps/engine.c b/src/lib/libssl/src/apps/engine.c
new file mode 100644
index 0000000000..734ecb3e5d
--- /dev/null
+++ b/src/lib/libssl/src/apps/engine.c
@@ -0,0 +1,520 @@
1/* apps/engine.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#ifdef OPENSSL_NO_STDIO
63#define APPS_WIN16
64#endif
65#include "apps.h"
66#include <openssl/err.h>
67#include <openssl/engine.h>
68#include <openssl/ssl.h>
69
70#undef PROG
71#define PROG engine_main
72
73static char *engine_usage[]={
74"usage: engine opts [engine ...]\n",
75" -v[v[v[v]]] - verbose mode, for each engine, list its 'control commands'\n",
76" -vv will additionally display each command's description\n",
77" -vvv will also add the input flags for each command\n",
78" -vvvv will also show internal input flags\n",
79" -c - for each engine, also list the capabilities\n",
80" -t - for each engine, check that they are really available\n",
81" -pre <cmd> - runs command 'cmd' against the ENGINE before any attempts\n",
82" to load it (if -t is used)\n",
83" -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n",
84" (only used if -t is also provided)\n",
85" NB: -pre and -post will be applied to all ENGINEs supplied on the command\n",
86" line, or all supported ENGINEs if none are specified.\n",
87" Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n",
88" argument \"/lib/libdriver.so\".\n",
89NULL
90};
91
92static void identity(void *ptr)
93 {
94 return;
95 }
96
97static int append_buf(char **buf, const char *s, int *size, int step)
98 {
99 int l = strlen(s);
100
101 if (*buf == NULL)
102 {
103 *size = step;
104 *buf = OPENSSL_malloc(*size);
105 if (*buf == NULL)
106 return 0;
107 **buf = '\0';
108 }
109
110 if (**buf != '\0')
111 l += 2; /* ", " */
112
113 if (strlen(*buf) + strlen(s) >= (unsigned int)*size)
114 {
115 *size += step;
116 *buf = OPENSSL_realloc(*buf, *size);
117 }
118
119 if (*buf == NULL)
120 return 0;
121
122 if (**buf != '\0')
123 strcat(*buf, ", ");
124 strcat(*buf, s);
125
126 return 1;
127 }
128
129static int util_flags(BIO *bio_out, unsigned int flags, const char *indent)
130 {
131 int started = 0, err = 0;
132 /* Indent before displaying input flags */
133 BIO_printf(bio_out, "%s%s(input flags): ", indent, indent);
134 if(flags == 0)
135 {
136 BIO_printf(bio_out, "<no flags>\n");
137 return 1;
138 }
139 /* If the object is internal, mark it in a way that shows instead of
140 * having it part of all the other flags, even if it really is. */
141 if(flags & ENGINE_CMD_FLAG_INTERNAL)
142 {
143 BIO_printf(bio_out, "[Internal] ");
144 }
145
146 if(flags & ENGINE_CMD_FLAG_NUMERIC)
147 {
148 if(started)
149 {
150 BIO_printf(bio_out, "|");
151 err = 1;
152 }
153 BIO_printf(bio_out, "NUMERIC");
154 started = 1;
155 }
156 /* Now we check that no combinations of the mutually exclusive NUMERIC,
157 * STRING, and NO_INPUT flags have been used. Future flags that can be
158 * OR'd together with these would need to added after these to preserve
159 * the testing logic. */
160 if(flags & ENGINE_CMD_FLAG_STRING)
161 {
162 if(started)
163 {
164 BIO_printf(bio_out, "|");
165 err = 1;
166 }
167 BIO_printf(bio_out, "STRING");
168 started = 1;
169 }
170 if(flags & ENGINE_CMD_FLAG_NO_INPUT)
171 {
172 if(started)
173 {
174 BIO_printf(bio_out, "|");
175 err = 1;
176 }
177 BIO_printf(bio_out, "NO_INPUT");
178 started = 1;
179 }
180 /* Check for unknown flags */
181 flags = flags & ~ENGINE_CMD_FLAG_NUMERIC &
182 ~ENGINE_CMD_FLAG_STRING &
183 ~ENGINE_CMD_FLAG_NO_INPUT &
184 ~ENGINE_CMD_FLAG_INTERNAL;
185 if(flags)
186 {
187 if(started) BIO_printf(bio_out, "|");
188 BIO_printf(bio_out, "<0x%04X>", flags);
189 }
190 if(err)
191 BIO_printf(bio_out, " <illegal flags!>");
192 BIO_printf(bio_out, "\n");
193 return 1;
194 }
195
196static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent)
197 {
198 static const int line_wrap = 78;
199 int num;
200 int ret = 0;
201 char *name = NULL;
202 char *desc = NULL;
203 int flags;
204 int xpos = 0;
205 STACK *cmds = NULL;
206 if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) ||
207 ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE,
208 0, NULL, NULL)) <= 0))
209 {
210#if 0
211 BIO_printf(bio_out, "%s<no control commands>\n", indent);
212#endif
213 return 1;
214 }
215
216 cmds = sk_new_null();
217
218 if(!cmds)
219 goto err;
220 do {
221 int len;
222 /* Get the command input flags */
223 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
224 NULL, NULL)) < 0)
225 goto err;
226 if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4)
227 {
228 /* Get the command name */
229 if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
230 NULL, NULL)) <= 0)
231 goto err;
232 if((name = OPENSSL_malloc(len + 1)) == NULL)
233 goto err;
234 if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
235 NULL) <= 0)
236 goto err;
237 /* Get the command description */
238 if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
239 NULL, NULL)) < 0)
240 goto err;
241 if(len > 0)
242 {
243 if((desc = OPENSSL_malloc(len + 1)) == NULL)
244 goto err;
245 if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
246 NULL) <= 0)
247 goto err;
248 }
249 /* Now decide on the output */
250 if(xpos == 0)
251 /* Do an indent */
252 xpos = BIO_printf(bio_out, indent);
253 else
254 /* Otherwise prepend a ", " */
255 xpos += BIO_printf(bio_out, ", ");
256 if(verbose == 1)
257 {
258 /* We're just listing names, comma-delimited */
259 if((xpos > (int)strlen(indent)) &&
260 (xpos + (int)strlen(name) > line_wrap))
261 {
262 BIO_printf(bio_out, "\n");
263 xpos = BIO_printf(bio_out, indent);
264 }
265 xpos += BIO_printf(bio_out, "%s", name);
266 }
267 else
268 {
269 /* We're listing names plus descriptions */
270 BIO_printf(bio_out, "%s: %s\n", name,
271 (desc == NULL) ? "<no description>" : desc);
272 /* ... and sometimes input flags */
273 if((verbose >= 3) && !util_flags(bio_out, flags,
274 indent))
275 goto err;
276 xpos = 0;
277 }
278 }
279 OPENSSL_free(name); name = NULL;
280 if(desc) { OPENSSL_free(desc); desc = NULL; }
281 /* Move to the next command */
282 num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE,
283 num, NULL, NULL);
284 } while(num > 0);
285 if(xpos > 0)
286 BIO_printf(bio_out, "\n");
287 ret = 1;
288err:
289 if(cmds) sk_pop_free(cmds, identity);
290 if(name) OPENSSL_free(name);
291 if(desc) OPENSSL_free(desc);
292 return ret;
293 }
294
295static void util_do_cmds(ENGINE *e, STACK *cmds, BIO *bio_out, const char *indent)
296 {
297 int loop, res, num = sk_num(cmds);
298 if(num < 0)
299 {
300 BIO_printf(bio_out, "[Error]: internal stack error\n");
301 return;
302 }
303 for(loop = 0; loop < num; loop++)
304 {
305 char buf[256];
306 const char *cmd, *arg;
307 cmd = sk_value(cmds, loop);
308 res = 1; /* assume success */
309 /* Check if this command has no ":arg" */
310 if((arg = strstr(cmd, ":")) == NULL)
311 {
312 if(!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0))
313 res = 0;
314 }
315 else
316 {
317 if((int)(arg - cmd) > 254)
318 {
319 BIO_printf(bio_out,"[Error]: command name too long\n");
320 return;
321 }
322 memcpy(buf, cmd, (int)(arg - cmd));
323 buf[arg-cmd] = '\0';
324 arg++; /* Move past the ":" */
325 /* Call the command with the argument */
326 if(!ENGINE_ctrl_cmd_string(e, buf, arg, 0))
327 res = 0;
328 }
329 if(res)
330 BIO_printf(bio_out, "[Success]: %s\n", cmd);
331 else
332 {
333 BIO_printf(bio_out, "[Failure]: %s\n", cmd);
334 ERR_print_errors(bio_out);
335 }
336 }
337 }
338
339int MAIN(int, char **);
340
341int MAIN(int argc, char **argv)
342 {
343 int ret=1,i;
344 char **pp;
345 int verbose=0, list_cap=0, test_avail=0;
346 ENGINE *e;
347 STACK *engines = sk_new_null();
348 STACK *pre_cmds = sk_new_null();
349 STACK *post_cmds = sk_new_null();
350 int badops=1;
351 BIO *bio_out=NULL;
352 const char *indent = " ";
353
354 apps_startup();
355 SSL_load_error_strings();
356
357 if (bio_err == NULL)
358 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
359
360 if (!load_config(bio_err, NULL))
361 goto end;
362 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
363#ifdef OPENSSL_SYS_VMS
364 {
365 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
366 bio_out = BIO_push(tmpbio, bio_out);
367 }
368#endif
369
370 argc--;
371 argv++;
372 while (argc >= 1)
373 {
374 if (strncmp(*argv,"-v",2) == 0)
375 {
376 if(strspn(*argv + 1, "v") < strlen(*argv + 1))
377 goto skip_arg_loop;
378 if((verbose=strlen(*argv + 1)) > 4)
379 goto skip_arg_loop;
380 }
381 else if (strcmp(*argv,"-c") == 0)
382 list_cap=1;
383 else if (strcmp(*argv,"-t") == 0)
384 test_avail=1;
385 else if (strcmp(*argv,"-pre") == 0)
386 {
387 argc--; argv++;
388 sk_push(pre_cmds,*argv);
389 }
390 else if (strcmp(*argv,"-post") == 0)
391 {
392 argc--; argv++;
393 sk_push(post_cmds,*argv);
394 }
395 else if ((strncmp(*argv,"-h",2) == 0) ||
396 (strcmp(*argv,"-?") == 0))
397 goto skip_arg_loop;
398 else
399 sk_push(engines,*argv);
400 argc--;
401 argv++;
402 }
403 /* Looks like everything went OK */
404 badops = 0;
405skip_arg_loop:
406
407 if (badops)
408 {
409 for (pp=engine_usage; (*pp != NULL); pp++)
410 BIO_printf(bio_err,"%s",*pp);
411 goto end;
412 }
413
414 if (sk_num(engines) == 0)
415 {
416 for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e))
417 {
418 sk_push(engines,(char *)ENGINE_get_id(e));
419 }
420 }
421
422 for (i=0; i<sk_num(engines); i++)
423 {
424 const char *id = sk_value(engines,i);
425 if ((e = ENGINE_by_id(id)) != NULL)
426 {
427 const char *name = ENGINE_get_name(e);
428 /* Do "id" first, then "name". Easier to auto-parse. */
429 BIO_printf(bio_out, "(%s) %s\n", id, name);
430 util_do_cmds(e, pre_cmds, bio_out, indent);
431 if (strcmp(ENGINE_get_id(e), id) != 0)
432 {
433 BIO_printf(bio_out, "Loaded: (%s) %s\n",
434 ENGINE_get_id(e), ENGINE_get_name(e));
435 }
436 if (list_cap)
437 {
438 int cap_size = 256;
439 char *cap_buf = NULL;
440 int k,n;
441 const int *nids;
442 ENGINE_CIPHERS_PTR fn_c;
443 ENGINE_DIGESTS_PTR fn_d;
444
445 if (ENGINE_get_RSA(e) != NULL
446 && !append_buf(&cap_buf, "RSA",
447 &cap_size, 256))
448 goto end;
449 if (ENGINE_get_DSA(e) != NULL
450 && !append_buf(&cap_buf, "DSA",
451 &cap_size, 256))
452 goto end;
453 if (ENGINE_get_DH(e) != NULL
454 && !append_buf(&cap_buf, "DH",
455 &cap_size, 256))
456 goto end;
457 if (ENGINE_get_RAND(e) != NULL
458 && !append_buf(&cap_buf, "RAND",
459 &cap_size, 256))
460 goto end;
461
462 fn_c = ENGINE_get_ciphers(e);
463 if(!fn_c) goto skip_ciphers;
464 n = fn_c(e, NULL, &nids, 0);
465 for(k=0 ; k < n ; ++k)
466 if(!append_buf(&cap_buf,
467 OBJ_nid2sn(nids[k]),
468 &cap_size, 256))
469 goto end;
470
471skip_ciphers:
472 fn_d = ENGINE_get_digests(e);
473 if(!fn_d) goto skip_digests;
474 n = fn_d(e, NULL, &nids, 0);
475 for(k=0 ; k < n ; ++k)
476 if(!append_buf(&cap_buf,
477 OBJ_nid2sn(nids[k]),
478 &cap_size, 256))
479 goto end;
480
481skip_digests:
482 if (cap_buf && (*cap_buf != '\0'))
483 BIO_printf(bio_out, " [%s]\n", cap_buf);
484
485 OPENSSL_free(cap_buf);
486 }
487 if(test_avail)
488 {
489 BIO_printf(bio_out, "%s", indent);
490 if (ENGINE_init(e))
491 {
492 BIO_printf(bio_out, "[ available ]\n");
493 util_do_cmds(e, post_cmds, bio_out, indent);
494 ENGINE_finish(e);
495 }
496 else
497 {
498 BIO_printf(bio_out, "[ unavailable ]\n");
499 ERR_print_errors_fp(stdout);
500 ERR_clear_error();
501 }
502 }
503 if((verbose > 0) && !util_verbose(e, verbose, bio_out, indent))
504 goto end;
505 ENGINE_free(e);
506 }
507 else
508 ERR_print_errors(bio_err);
509 }
510
511 ret=0;
512end:
513 ERR_print_errors(bio_err);
514 sk_pop_free(engines, identity);
515 sk_pop_free(pre_cmds, identity);
516 sk_pop_free(post_cmds, identity);
517 if (bio_out != NULL) BIO_free_all(bio_out);
518 apps_shutdown();
519 EXIT(ret);
520 }
diff --git a/src/lib/libssl/src/apps/install.com b/src/lib/libssl/src/apps/install.com
new file mode 100644
index 0000000000..f927dc29f5
--- /dev/null
+++ b/src/lib/libssl/src/apps/install.com
@@ -0,0 +1,69 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVEXE WRK_SSLROOT:[VAX_EXE]
23$ DEFINE/NOLOG WRK_SSLAEXE WRK_SSLROOT:[ALPHA_EXE]
24$ DEFINE/NOLOG WRK_SSLLIB WRK_SSLROOT:[LIB]
25$
26$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
27 CREATE/DIR/LOG WRK_SSLROOT:[000000]
28$ IF F$PARSE("WRK_SSLVEXE:") .EQS. "" THEN -
29 CREATE/DIR/LOG WRK_SSLVEXE:
30$ IF F$PARSE("WRK_SSLAEXE:") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLAEXE:
32$ IF F$PARSE("WRK_SSLLIB:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLLIB:
34$
35$ EXE := openssl
36$
37$ VEXE_DIR := [-.VAX.EXE.APPS]
38$ AEXE_DIR := [-.AXP.EXE.APPS]
39$
40$ I = 0
41$ LOOP_EXE:
42$ E = F$EDIT(F$ELEMENT(I, ",", EXE),"TRIM")
43$ I = I + 1
44$ IF E .EQS. "," THEN GOTO LOOP_EXE_END
45$ SET NOON
46$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
47$ THEN
48$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVEXE:'E'.EXE/log
49$ SET FILE/PROT=W:RE WRK_SSLVEXE:'E'.EXE
50$ ENDIF
51$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
52$ THEN
53$ COPY 'AEXE_DIR''E'.EXE WRK_SSLAEXE:'E'.EXE/log
54$ SET FILE/PROT=W:RE WRK_SSLAEXE:'E'.EXE
55$ ENDIF
56$ SET ON
57$ GOTO LOOP_EXE
58$ LOOP_EXE_END:
59$
60$ SET NOON
61$ COPY CA.COM WRK_SSLAEXE:CA.COM/LOG
62$ SET FILE/PROT=W:RE WRK_SSLAEXE:CA.COM
63$ COPY CA.COM WRK_SSLVEXE:CA.COM/LOG
64$ SET FILE/PROT=W:RE WRK_SSLVEXE:CA.COM
65$ COPY OPENSSL-VMS.CNF WRK_SSLROOT:[000000]OPENSSL.CNF/LOG
66$ SET FILE/PROT=W:R WRK_SSLROOT:[000000]OPENSSL.CNF
67$ SET ON
68$
69$ EXIT
diff --git a/src/lib/libssl/src/apps/makeapps.com b/src/lib/libssl/src/apps/makeapps.com
new file mode 100644
index 0000000000..8a15a130ed
--- /dev/null
+++ b/src/lib/libssl/src/apps/makeapps.com
@@ -0,0 +1,1138 @@
1$!
2$! MAKEAPPS.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates all the various different
11$! "application" programs for the different types of encryption for OpenSSL.
12$! The EXE's are placed in the directory [.xxx.EXE.APPS] where "xxx" denotes
13$! either AXP or VAX depending on your machine architecture.
14$!
15$! It was written so it would try to determine what "C" compiler to
16$! use or you can specify which "C" compiler to use.
17$!
18$! Specify RSAREF as P1 to compile with the RSAREF library instead of
19$! the regular one. If you specify NORSAREF it will compile with the
20$! regular RSAREF routines. (Note: If you are in the United States
21$! you MUST compile with RSAREF unless you have a license from RSA).
22$!
23$! Note: The RSAREF libraries are NOT INCLUDED and you have to
24$! download it from "ftp://ftp.rsa.com/rsaref". You have to
25$! get the ".tar-Z" file as the ".zip" file dosen't have the
26$! directory structure stored. You have to extract the file
27$! into the [.RSAREF] directory under the root directory as that
28$! is where the scripts will look for the files.
29$!
30$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger
31$! information.
32$!
33$! Specify which compiler at P3 to try to compile under.
34$!
35$! VAXC For VAX C.
36$! DECC For DEC C.
37$! GNUC For GNU C.
38$!
39$! If you don't speficy a compiler, it will try to determine which
40$! "C" compiler to use.
41$!
42$! P4, if defined, sets a TCP/IP library to use, through one of the following
43$! keywords:
44$!
45$! UCX for UCX
46$! SOCKETSHR for SOCKETSHR+NETLIB
47$!
48$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
49$!
50$! P6, if defined, sets a choice of programs to compile.
51$!
52$!
53$! Define A TCP/IP Library That We Will Need To Link To.
54$! (That Is, If We Need To Link To One.)
55$!
56$ TCPIP_LIB = ""
57$!
58$! Check What Architecture We Are Using.
59$!
60$ IF (F$GETSYI("CPU").GE.128)
61$ THEN
62$!
63$! The Architecture Is AXP.
64$!
65$ ARCH := AXP
66$!
67$! Else...
68$!
69$ ELSE
70$!
71$! The Architecture Is VAX.
72$!
73$ ARCH := VAX
74$!
75$! End The Architecture Check.
76$!
77$ ENDIF
78$!
79$! Define what programs should be compiled
80$!
81$ PROGRAMS := OPENSSL
82$!$ PROGRAMS := VERIFY,ASN1PARS,REQ,DGST,DH,ENC,GENDH,ERRSTR,CA,CRL,-
83$! RSA,DSA,DSAPARAM,-
84$! X509,GENRSA,GENDSA,S_SERVER,S_CLIENT,SPEED,-
85$! S_TIME,VERSION,PKCS7,CRL2P7,SESS_ID,CIPHERS,NSEQ,
86$!
87$! Check To Make Sure We Have Valid Command Line Parameters.
88$!
89$ GOSUB CHECK_OPTIONS
90$!
91$! Initialise logical names and such
92$!
93$ GOSUB INITIALISE
94$!
95$! Tell The User What Kind of Machine We Run On.
96$!
97$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
98$!
99$! Define The CRYPTO Library.
100$!
101$ CRYPTO_LIB := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
102$!
103$! Define The RSAREF Library.
104$!
105$ RSAREF_LIB := SYS$DISK:[-.'ARCH'.EXE.RSAREF]LIBRSAGLUE.OLB
106$!
107$! Define The SSL Library.
108$!
109$ SSL_LIB := SYS$DISK:[-.'ARCH'.EXE.SSL]LIBSSL.OLB
110$!
111$! Define The OBJ Directory.
112$!
113$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.APPS]
114$!
115$! Check To See If The OBJ Directory Exists.
116$!
117$ IF (F$PARSE(OBJ_DIR).EQS."")
118$ THEN
119$!
120$! It Dosen't Exist, So Create It.
121$!
122$ CREATE/DIRECTORY 'OBJ_DIR'
123$!
124$! End The OBJ Directory Check.
125$!
126$ ENDIF
127$!
128$! Define The EXE Directory.
129$!
130$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.APPS]
131$!
132$! Check To See If The EXE Directory Exists.
133$!
134$ IF (F$PARSE(EXE_DIR).EQS."")
135$ THEN
136$!
137$! It Dosen't Exist, So Create It.
138$!
139$ CREATE/DIRECTORY 'EXE_DIR'
140$!
141$! End The EXE Directory Check.
142$!
143$ ENDIF
144$!
145$! Check To See If We Have The Proper Libraries.
146$!
147$ GOSUB LIB_CHECK
148$!
149$! Check To See If We Have A Linker Option File.
150$!
151$ GOSUB CHECK_OPT_FILE
152$!
153$! Define The Application Files.
154$!
155$ LIB_FILES = "VERIFY;ASN1PARS;REQ;DGST;DH;ENC;GENDH;"+-
156 "ERRSTR;CA;"+-
157 "PKCS7;CRL2P7;CRL;"+-
158 "RSA;DSA;DSAPARAM;"+-
159 "X509;GENRSA;GENDSA;S_SERVER;S_CLIENT;SPEED;"+-
160 "S_TIME;APPS;S_CB;S_SOCKET;VERSION;SESS_ID;"+-
161 "CIPHERS;NSEQ;PKCS12;PKCS8"
162$ APP_FILES := OPENSSL,'OBJ_DIR'VERIFY.OBJ,ASN1PARS.OBJ,REQ.OBJ,DGST.OBJ,DH.OBJ,ENC.OBJ,GENDH.OBJ,-
163 ERRSTR.OBJ,CA.OBJ,-
164 PKCS7.OBJ,CRL2P7.OBJ,CRL.OBJ,-
165 RSA.OBJ,DSA.OBJ,DSAPARAM.OBJ,-
166 X509.OBJ,GENRSA.OBJ,GENDSA.OBJ,S_SERVER.OBJ,S_CLIENT.OBJ,SPEED.OBJ,-
167 S_TIME.OBJ,APPS.OBJ,S_CB.OBJ,S_SOCKET.OBJ,VERSION.OBJ,SESS_ID.OBJ,-
168 CIPHERS.OBJ,NSEQ.OBJ,PKCS12.OBJ,PKCS8.OBJ
169$ TCPIP_PROGRAMS = ",,"
170$ IF COMPILER .EQS. "VAXC" THEN -
171 TCPIP_PROGRAMS = ",OPENSSL,"
172$!$ APP_FILES := VERIFY;ASN1PARS;REQ;DGST;DH;ENC;GENDH;ERRSTR;CA;-
173$! PKCS7;CRL2P7;CRL;-
174$! RSA;DSA;DSAPARAM;-
175$! X509;GENRSA;GENDSA;-
176$! S_SERVER,'OBJ_DIR'S_SOCKET.OBJ,'OBJ_DIR'S_CB.OBJ;-
177$! S_CLIENT,'OBJ_DIR'S_SOCKET.OBJ,'OBJ_DIR'S_CB.OBJ;-
178$! SPEED;-
179$! S_TIME,'OBJ_DIR'S_CB.OBJ;VERSION;SESS_ID;CIPHERS;NSEQ
180$!$ TCPIP_PROGRAMS = ",,"
181$!$ IF COMPILER .EQS. "VAXC" THEN -
182$! TCPIP_PROGRAMS = ",S_SERVER,S_CLIENT,SESS_ID,CIPHERS,S_TIME,"
183$!
184$! Setup exceptional compilations
185$!
186$ COMPILEWITH_CC2 = ",S_SOCKET,S_SERVER,S_CLIENT,"
187$!
188$ PHASE := LIB
189$!
190$ RESTART:
191$!
192$! Define A File Counter And Set It To "0".
193$!
194$ FILE_COUNTER = 0
195$!
196$! Top Of The File Loop.
197$!
198$ NEXT_FILE:
199$!
200$! O.K, Extract The File Name From The File List.
201$!
202$ FILE_NAME0 = F$EDIT(F$ELEMENT(FILE_COUNTER,";",'PHASE'_FILES),"TRIM")
203$ FILE_NAME = F$EDIT(F$ELEMENT(0,",",FILE_NAME0),"TRIM")
204$ EXTRA_OBJ = FILE_NAME0 - FILE_NAME
205$!
206$! Check To See If We Are At The End Of The File List.
207$!
208$ IF (FILE_NAME0.EQS.";")
209$ THEN
210$ IF (PHASE.EQS."LIB")
211$ THEN
212$ PHASE := APP
213$ GOTO RESTART
214$ ELSE
215$ GOTO FILE_DONE
216$ ENDIF
217$ ENDIF
218$!
219$! Increment The Counter.
220$!
221$ FILE_COUNTER = FILE_COUNTER + 1
222$!
223$! Check to see if this program should actually be compiled
224$!
225$ IF PHASE .EQS. "APP" .AND. -
226 ","+PROGRAMS+"," - (","+F$EDIT(FILE_NAME,"UPCASE")+",") .EQS. ","+PROGRAMS+","
227$ THEN
228$ GOTO NEXT_FILE
229$ ENDIF
230$!
231$! Create The Source File Name.
232$!
233$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
234$!
235$! Create The Object File Name.
236$!
237$ OBJECT_FILE = OBJ_DIR + FILE_NAME + ".OBJ"
238$!
239$! Create The Executable File Name.
240$!
241$ EXE_FILE = EXE_DIR + FILE_NAME + ".EXE"
242$ ON WARNING THEN GOTO NEXT_FILE
243$!
244$! Check To See If The File We Want To Compile Actually Exists.
245$!
246$ IF (F$SEARCH(SOURCE_FILE).EQS."")
247$ THEN
248$!
249$! Tell The User That The File Dosen't Exist.
250$!
251$ WRITE SYS$OUTPUT ""
252$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
253$ WRITE SYS$OUTPUT ""
254$!
255$! Exit The Build.
256$!
257$ GOTO EXIT
258$!
259$! End The File Exist Check.
260$!
261$ ENDIF
262$!
263$! Tell The User What We Are Building.
264$!
265$ IF (PHASE.EQS."LIB")
266$ THEN
267$ WRITE SYS$OUTPUT "Compiling The ",FILE_NAME,".C File."
268$ ELSE
269$ WRITE SYS$OUTPUT "Building The ",FILE_NAME," Application Program."
270$ ENDIF
271$!
272$! Compile The File.
273$!
274$ ON ERROR THEN GOTO NEXT_FILE
275$ IF COMPILEWITH_CC2 - FILE_NAME .NES. COMPILEWITH_CC2
276$ THEN
277$ CC2/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
278$ ELSE
279$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
280$ ENDIF
281$!
282$ ON WARNING THEN GOTO NEXT_FILE
283$!
284$ IF (PHASE.EQS."LIB")
285$ THEN
286$ GOTO NEXT_FILE
287$ ENDIF
288$!
289$! Check if this program works well without a TCPIP library
290$!
291$ IF TCPIP_LIB .EQS. "" .AND. TCPIP_PROGRAMS - FILE_NAME .NES. TCPIP_PROGRAMS
292$ THEN
293$ WRITE SYS$OUTPUT FILE_NAME," needs a TCP/IP library. Can't link. Skipping..."
294$ GOTO NEXT_FILE
295$ ENDIF
296$!
297$! Link The Program, Check To See If We Need To Link With RSAREF Or Not.
298$!
299$ IF (RSAREF.EQS."TRUE")
300$ THEN
301$!
302$! Check To See If We Are To Link With A Specific TCP/IP Library.
303$!
304$ IF (TCPIP_LIB.NES."")
305$ THEN
306$!
307$! Link With The RSAREF Library And A Specific TCP/IP Library.
308$!
309$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
310 'OBJECT_FILE''EXTRA_OBJ', -
311 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
312 'TCPIP_LIB','OPT_FILE'/OPTION
313$!
314$! Else...
315$!
316$ ELSE
317$!
318$! Link With The RSAREF Library And NO TCP/IP Library.
319$!
320$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
321 'OBJECT_FILE''EXTRA_OBJ', -
322 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
323 'OPT_FILE'/OPTION
324$!
325$! End The TCP/IP Library Check.
326$!
327$ ENDIF
328$!
329$! Else...
330$!
331$ ELSE
332$!
333$! Don't Link With The RSAREF Routines.
334$!
335$!
336$! Check To See If We Are To Link With A Specific TCP/IP Library.
337$!
338$ IF (TCPIP_LIB.NES."")
339$ THEN
340$!
341$! Don't Link With The RSAREF Routines And TCP/IP Library.
342$!
343$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
344 'OBJECT_FILE''EXTRA_OBJ', -
345 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
346 'TCPIP_LIB','OPT_FILE'/OPTION
347$!
348$! Else...
349$!
350$ ELSE
351$!
352$! Don't Link With The RSAREF Routines And Link With A TCP/IP Library.
353$!
354$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
355 'OBJECT_FILE''EXTRA_OBJ', -
356 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
357 'OPT_FILE'/OPTION
358$!
359$! End The TCP/IP Library Check.
360$!
361$ ENDIF
362$!
363$! End The RSAREF Link Check.
364$!
365$ ENDIF
366$!
367$! Go Back And Do It Again.
368$!
369$ GOTO NEXT_FILE
370$!
371$! All Done With This File.
372$!
373$ FILE_DONE:
374$ EXIT:
375$!
376$! All Done, Time To Clean Up And Exit.
377$!
378$ GOSUB CLEANUP
379$ EXIT
380$!
381$! Check For The Link Option FIle.
382$!
383$ CHECK_OPT_FILE:
384$!
385$! Check To See If We Need To Make A VAX C Option File.
386$!
387$ IF (COMPILER.EQS."VAXC")
388$ THEN
389$!
390$! Check To See If We Already Have A VAX C Linker Option File.
391$!
392$ IF (F$SEARCH(OPT_FILE).EQS."")
393$ THEN
394$!
395$! We Need A VAX C Linker Option File.
396$!
397$ CREATE 'OPT_FILE'
398$DECK
399!
400! Default System Options File To Link Agianst
401! The Sharable VAX C Runtime Library.
402!
403SYS$SHARE:VAXCRTL.EXE/SHARE
404$EOD
405$!
406$! End The Option File Check.
407$!
408$ ENDIF
409$!
410$! End The VAXC Check.
411$!
412$ ENDIF
413$!
414$! Check To See If We Need A GNU C Option File.
415$!
416$ IF (COMPILER.EQS."GNUC")
417$ THEN
418$!
419$! Check To See If We Already Have A GNU C Linker Option File.
420$!
421$ IF (F$SEARCH(OPT_FILE).EQS."")
422$ THEN
423$!
424$! We Need A GNU C Linker Option File.
425$!
426$ CREATE 'OPT_FILE'
427$DECK
428!
429! Default System Options File To Link Agianst
430! The Sharable C Runtime Library.
431!
432GNU_CC:[000000]GCCLIB/LIBRARY
433SYS$SHARE:VAXCRTL/SHARE
434$EOD
435$!
436$! End The Option File Check.
437$!
438$ ENDIF
439$!
440$! End The GNU C Check.
441$!
442$ ENDIF
443$!
444$! Check To See If We Need A DEC C Option File.
445$!
446$ IF (COMPILER.EQS."DECC")
447$ THEN
448$!
449$! Check To See If We Already Have A DEC C Linker Option File.
450$!
451$ IF (F$SEARCH(OPT_FILE).EQS."")
452$ THEN
453$!
454$! Figure Out If We Need An AXP Or A VAX Linker Option File.
455$!
456$ IF ARCH.EQS."VAX"
457$ THEN
458$!
459$! We Need A DEC C Linker Option File For VAX.
460$!
461$ CREATE 'OPT_FILE'
462$DECK
463!
464! Default System Options File To Link Agianst
465! The Sharable DEC C Runtime Library.
466!
467SYS$SHARE:DECC$SHR.EXE/SHARE
468$EOD
469$!
470$! Else...
471$!
472$ ELSE
473$!
474$! Create The AXP Linker Option File.
475$!
476$ CREATE 'OPT_FILE'
477$DECK
478!
479! Default System Options File For AXP To Link Agianst
480! The Sharable C Runtime Library.
481!
482SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
483SYS$SHARE:CMA$OPEN_RTL/SHARE
484$EOD
485$!
486$! End The VAX/AXP DEC C Option File Check.
487$!
488$ ENDIF
489$!
490$! End The Option File Search.
491$!
492$ ENDIF
493$!
494$! End The DEC C Check.
495$!
496$ ENDIF
497$!
498$! Tell The User What Linker Option File We Are Using.
499$!
500$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
501$!
502$! Time To RETURN.
503$!
504$ RETURN
505$!
506$! Check To See If We Have The Appropiate Libraries.
507$!
508$ LIB_CHECK:
509$!
510$! Look For The Library LIBCRYPTO.OLB.
511$!
512$ IF (F$SEARCH(CRYPTO_LIB).EQS."")
513$ THEN
514$!
515$! Tell The User We Can't Find The LIBCRYPTO.OLB Library.
516$!
517$ WRITE SYS$OUTPUT ""
518$ WRITE SYS$OUTPUT "Can't Find The Library ",CRYPTO_LIB,"."
519$ WRITE SYS$OUTPUT "We Can't Link Without It."
520$ WRITE SYS$OUTPUT ""
521$!
522$! Since We Can't Link Without It, Exit.
523$!
524$ EXIT
525$!
526$! End The Crypto Library Check.
527$!
528$ ENDIF
529$!
530$! See If We Need The RSAREF Library.
531$!
532$ IF (RSAREF.EQS."TRUE")
533$ THEN
534$!
535$! Look For The Library LIBRSAGLUE.OLB.
536$!
537$ IF (F$SEARCH(RSAREF_LIB).EQS."")
538$ THEN
539$!
540$! Tell The User We Can't Find The LIBRSAGLUE.OLB Library.
541$!
542$ WRITE SYS$OUTPUT ""
543$ WRITE SYS$OUTPUT "Can't Find The Library ",RSAREF_LIB,"."
544$ WRITE SYS$OUTPUT "We Can't Link Without It."
545$ WRITE SYS$OUTPUT ""
546$!
547$! Since We Can't Link Without It, Exit.
548$!
549$ EXIT
550$ ENDIF
551$!
552$! End The RSAREF Library Check.
553$!
554$ ENDIF
555$!
556$! Look For The Library LIBSSL.OLB.
557$!
558$ IF (F$SEARCH(SSL_LIB).EQS."")
559$ THEN
560$!
561$! Tell The User We Can't Find The LIBSSL.OLB Library.
562$!
563$ WRITE SYS$OUTPUT ""
564$ WRITE SYS$OUTPUT "Can't Find The Library ",SSL_LIB,"."
565$ WRITE SYS$OUTPUT "Some Of The Test Programs Need To Link To It."
566$ WRITE SYS$OUTPUT ""
567$!
568$! Since We Can't Link Without It, Exit.
569$!
570$ EXIT
571$!
572$! End The SSL Library Check.
573$!
574$ ENDIF
575$!
576$! Time To Return.
577$!
578$ RETURN
579$!
580$! Check The User's Options.
581$!
582$ CHECK_OPTIONS:
583$!
584$! Check To See If P1 Is Blank.
585$!
586$ IF (P1.EQS."NORSAREF")
587$ THEN
588$!
589$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries.
590$!
591$ RSAREF = "FALSE"
592$!
593$! Else...
594$!
595$ ELSE
596$!
597$! Check To See If We Are To Use The RSAREF Library.
598$!
599$ IF (P1.EQS."RSAREF")
600$ THEN
601$!
602$! Check To Make Sure We Have The RSAREF Source Code Directory.
603$!
604$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
605$ THEN
606$!
607$! We Don't Have The RSAREF Souce Code Directory, So Tell The
608$! User This.
609$!
610$ WRITE SYS$OUTPUT ""
611$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
612$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
613$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
614$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
615$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
616$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
617$ WRITE SYS$OUTPUT ""
618$!
619$! Time To Exit.
620$!
621$ EXIT
622$!
623$! Else...
624$!
625$ ELSE
626$!
627$! Compile Using The RSAREF Library.
628$!
629$ RSAREF = "TRUE"
630$!
631$! End The RSAREF Soure Directory Check.
632$!
633$ ENDIF
634$!
635$! Else...
636$!
637$ ELSE
638$!
639$! They Entered An Invalid Option..
640$!
641$ WRITE SYS$OUTPUT ""
642$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
643$ WRITE SYS$OUTPUT ""
644$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
645$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
646$ WRITE SYS$OUTPUT ""
647$!
648$! Time To EXIT.
649$!
650$ EXIT
651$!
652$! End The Valid Arguement Check.
653$!
654$ ENDIF
655$!
656$! End P1 Check.
657$!
658$ ENDIF
659$!
660$! Check To See If P2 Is Blank.
661$!
662$ IF (P2.EQS."NODEBUG")
663$ THEN
664$!
665$! P2 Is NODEBUG, So Compile Without Debugger Information.
666$!
667$ DEBUGGER = "NODEBUG"
668$ TRACEBACK = "NOTRACEBACK"
669$ GCC_OPTIMIZE = "OPTIMIZE"
670$ CC_OPTIMIZE = "OPTIMIZE"
671$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
672$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
673$!
674$! Else...
675$!
676$ ELSE
677$!
678$! Check To See If We Are To Compile With Debugger Information.
679$!
680$ IF (P2.EQS."DEBUG")
681$ THEN
682$!
683$! Compile With Debugger Information.
684$!
685$ DEBUGGER = "DEBUG"
686$ TRACEBACK = "TRACEBACK"
687$ GCC_OPTIMIZE = "NOOPTIMIZE"
688$ CC_OPTIMIZE = "NOOPTIMIZE"
689$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
690$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
691$ ELSE
692$!
693$! Tell The User Entered An Invalid Option..
694$!
695$ WRITE SYS$OUTPUT ""
696$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
697$ WRITE SYS$OUTPUT ""
698$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
699$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
700$ WRITE SYS$OUTPUT ""
701$!
702$! Time To EXIT.
703$!
704$ EXIT
705$!
706$! End The Valid Arguement Check.
707$!
708$ ENDIF
709$!
710$! End The P2 Check.
711$!
712$ ENDIF
713$!
714$! Check To See If P3 Is Blank.
715$!
716$ IF (P3.EQS."")
717$ THEN
718$!
719$! O.K., The User Didn't Specify A Compiler, Let's Try To
720$! Find Out Which One To Use.
721$!
722$! Check To See If We Have GNU C.
723$!
724$ IF (F$TRNLNM("GNU_CC").NES."")
725$ THEN
726$!
727$! Looks Like GNUC, Set To Use GNUC.
728$!
729$ P3 = "GNUC"
730$!
731$! Else...
732$!
733$ ELSE
734$!
735$! Check To See If We Have VAXC Or DECC.
736$!
737$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
738$ THEN
739$!
740$! Looks Like DECC, Set To Use DECC.
741$!
742$ P3 = "DECC"
743$!
744$! Else...
745$!
746$ ELSE
747$!
748$! Looks Like VAXC, Set To Use VAXC.
749$!
750$ P3 = "VAXC"
751$!
752$! End The VAXC Compiler Check.
753$!
754$ ENDIF
755$!
756$! End The DECC & VAXC Compiler Check.
757$!
758$ ENDIF
759$!
760$! End The Compiler Check.
761$!
762$ ENDIF
763$!
764$! Check To See If We Have A Option For P4.
765$!
766$ IF (P4.EQS."")
767$ THEN
768$!
769$! Find out what socket library we have available
770$!
771$ IF F$PARSE("SOCKETSHR:") .NES. ""
772$ THEN
773$!
774$! We have SOCKETSHR, and it is my opinion that it's the best to use.
775$!
776$ P4 = "SOCKETSHR"
777$!
778$! Tell the user
779$!
780$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
781$!
782$! Else, let's look for something else
783$!
784$ ELSE
785$!
786$! Like UCX (the reason to do this before Multinet is that the UCX
787$! emulation is easier to use...)
788$!
789$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
790 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
791 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
792$ THEN
793$!
794$! Last resort: a UCX or UCX-compatible library
795$!
796$ P4 = "UCX"
797$!
798$! Tell the user
799$!
800$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
801$!
802$! That was all...
803$!
804$ ENDIF
805$ ENDIF
806$ ENDIF
807$!
808$! Set Up Initial CC Definitions, Possibly With User Ones
809$!
810$ CCDEFS = "VMS=1,MONOLITH"
811$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
812$ CCEXTRAFLAGS = ""
813$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
814$ CCDISABLEWARNINGS = ""
815$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
816 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
817$!
818$! Check To See If The User Entered A Valid Paramter.
819$!
820$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
821$ THEN
822$!
823$! Check To See If The User Wanted DECC.
824$!
825$ IF (P3.EQS."DECC")
826$ THEN
827$!
828$! Looks Like DECC, Set To Use DECC.
829$!
830$ COMPILER = "DECC"
831$!
832$! Tell The User We Are Using DECC.
833$!
834$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
835$!
836$! Use DECC...
837$!
838$ CC = "CC"
839$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
840 THEN CC = "CC/DECC"
841$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
842 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
843$!
844$! Define The Linker Options File Name.
845$!
846$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
847$!
848$! End DECC Check.
849$!
850$ ENDIF
851$!
852$! Check To See If We Are To Use VAXC.
853$!
854$ IF (P3.EQS."VAXC")
855$ THEN
856$!
857$! Looks Like VAXC, Set To Use VAXC.
858$!
859$ COMPILER = "VAXC"
860$!
861$! Tell The User We Are Using VAX C.
862$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
863$!
864$! Compile Using VAXC.
865$!
866$ CC = "CC"
867$ IF ARCH.EQS."AXP"
868$ THEN
869$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
870$ EXIT
871$ ENDIF
872$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
873$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
874$ CCDEFS = CCDEFS + ",""VAXC"""
875$!
876$! Define <sys> As SYS$COMMON:[SYSLIB]
877$!
878$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
879$!
880$! Define The Linker Options File Name.
881$!
882$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
883$!
884$! End VAXC Check
885$!
886$ ENDIF
887$!
888$! Check To See If We Are To Use GNU C.
889$!
890$ IF (P3.EQS."GNUC")
891$ THEN
892$!
893$! Looks Like GNUC, Set To Use GNUC.
894$!
895$ COMPILER = "GNUC"
896$!
897$! Tell The User We Are Using GNUC.
898$!
899$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
900$!
901$! Use GNU C...
902$!
903$ IF F$TYPE(GCC) .EQS. "" THEN GCC := GCC
904$ CC = GCC+"/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
905$!
906$! Define The Linker Options File Name.
907$!
908$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
909$!
910$! End The GNU C Check.
911$!
912$ ENDIF
913$!
914$! Set up default defines
915$!
916$ CCDEFS = """FLAT_INC=1""," + CCDEFS
917$!
918$! Check To See If We Are To Compile With RSAREF Routines.
919$!
920$ IF (RSAREF.EQS."TRUE")
921$ THEN
922$!
923$! Compile With RSAREF.
924$!
925$ CCDEFS = CCDEFS + ",""RSAref=1"""
926$!
927$! Tell The User This.
928$!
929$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
930$!
931$! Else, We Don't Care. Compile Without The RSAREF Library.
932$!
933$ ELSE
934$!
935$! Tell The User We Are Compile Without The RSAREF Routines.
936$!
937$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
938$!
939$! End The RSAREF Check.
940$!
941$ ENDIF
942$!
943$! Else The User Entered An Invalid Arguement.
944$!
945$ ELSE
946$!
947$! Tell The User We Don't Know What They Want.
948$!
949$ WRITE SYS$OUTPUT ""
950$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
951$ WRITE SYS$OUTPUT ""
952$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
953$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
954$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
955$ WRITE SYS$OUTPUT ""
956$!
957$! Time To EXIT.
958$!
959$ EXIT
960$ ENDIF
961$!
962$! Time to check the contents, and to make sure we get the correct library.
963$!
964$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX"
965$ THEN
966$!
967$! Check to see if SOCKETSHR was chosen
968$!
969$ IF P4.EQS."SOCKETSHR"
970$ THEN
971$!
972$! Set the library to use SOCKETSHR
973$!
974$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
975$!
976$! Done with SOCKETSHR
977$!
978$ ENDIF
979$!
980$! Check to see if MULTINET was chosen
981$!
982$ IF P4.EQS."MULTINET"
983$ THEN
984$!
985$! Set the library to use UCX emulation.
986$!
987$ P4 = "UCX"
988$!
989$! Done with MULTINET
990$!
991$ ENDIF
992$!
993$! Check to see if UCX was chosen
994$!
995$ IF P4.EQS."UCX"
996$ THEN
997$!
998$! Set the library to use UCX.
999$!
1000$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
1001$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1002$ THEN
1003$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1004$ ELSE
1005$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1006 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1007$ ENDIF
1008$!
1009$! Done with UCX
1010$!
1011$ ENDIF
1012$!
1013$! Add TCP/IP type to CC definitions.
1014$!
1015$ CCDEFS = CCDEFS + ",TCPIP_TYPE_''P4'"
1016$!
1017$! Print info
1018$!
1019$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1020$!
1021$! Else The User Entered An Invalid Arguement.
1022$!
1023$ ELSE
1024$!
1025$! Tell The User We Don't Know What They Want.
1026$!
1027$ WRITE SYS$OUTPUT ""
1028$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1029$ WRITE SYS$OUTPUT ""
1030$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1031$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1032$ WRITE SYS$OUTPUT ""
1033$!
1034$! Time To EXIT.
1035$!
1036$ EXIT
1037$!
1038$! Done with TCP/IP libraries
1039$!
1040$ ENDIF
1041$!
1042$! Finish up the definition of CC.
1043$!
1044$ IF COMPILER .EQS. "DECC"
1045$ THEN
1046$ IF CCDISABLEWARNINGS .NES. ""
1047$ THEN
1048$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1049$ ENDIF
1050$ ELSE
1051$ CCDISABLEWARNINGS = ""
1052$ ENDIF
1053$ CC2 = CC + "/DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
1054$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1055$!
1056$! Show user the result
1057$!
1058$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
1059$!
1060$! Special Threads For OpenVMS v7.1 Or Later
1061$!
1062$! Written By: Richard Levitte
1063$! richard@levitte.org
1064$!
1065$!
1066$! Check To See If We Have A Option For P5.
1067$!
1068$ IF (P5.EQS."")
1069$ THEN
1070$!
1071$! Get The Version Of VMS We Are Using.
1072$!
1073$ ISSEVEN :=
1074$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
1075$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
1076$!
1077$! Check To See If The VMS Version Is v7.1 Or Later.
1078$!
1079$ IF (TMP.GE.71)
1080$ THEN
1081$!
1082$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
1083$!
1084$ ISSEVEN := ,PTHREAD_USE_D4
1085$!
1086$! End The VMS Version Check.
1087$!
1088$ ENDIF
1089$!
1090$! End The P5 Check.
1091$!
1092$ ENDIF
1093$!
1094$! Check if the user wanted to compile just a subset of all the programs.
1095$!
1096$ IF P6 .NES. ""
1097$ THEN
1098$ PROGRAMS = P6
1099$ ENDIF
1100$!
1101$! Time To RETURN...
1102$!
1103$ RETURN
1104$!
1105$ INITIALISE:
1106$!
1107$! Save old value of the logical name OPENSSL
1108$!
1109$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1110$!
1111$! Save directory information
1112$!
1113$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1114$ __TOP = __HERE - "APPS]"
1115$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1116$!
1117$! Set up the logical name OPENSSL to point at the include directory
1118$!
1119$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1120$!
1121$! Done
1122$!
1123$ RETURN
1124$!
1125$ CLEANUP:
1126$!
1127$! Restore the logical name OPENSSL if it had a value
1128$!
1129$ IF __SAVE_OPENSSL .EQS. ""
1130$ THEN
1131$ DEASSIGN OPENSSL
1132$ ELSE
1133$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1134$ ENDIF
1135$!
1136$! Done
1137$!
1138$ RETURN
diff --git a/src/lib/libssl/src/apps/nseq.c b/src/lib/libssl/src/apps/nseq.c
new file mode 100644
index 0000000000..d9d01659e7
--- /dev/null
+++ b/src/lib/libssl/src/apps/nseq.c
@@ -0,0 +1,174 @@
1/* nseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/pem.h>
62#include <openssl/err.h>
63#include "apps.h"
64
65#undef PROG
66#define PROG nseq_main
67
68static int dump_cert_text(BIO *out, X509 *x);
69
70int MAIN(int argc, char **argv)
71{
72 char **args, *infile = NULL, *outfile = NULL;
73 BIO *in = NULL, *out = NULL;
74 int toseq = 0;
75 X509 *x509 = NULL;
76 NETSCAPE_CERT_SEQUENCE *seq = NULL;
77 int i, ret = 1;
78 int badarg = 0;
79 if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
80 ERR_load_crypto_strings();
81 args = argv + 1;
82 while (!badarg && *args && *args[0] == '-') {
83 if (!strcmp (*args, "-toseq")) toseq = 1;
84 else if (!strcmp (*args, "-in")) {
85 if (args[1]) {
86 args++;
87 infile = *args;
88 } else badarg = 1;
89 } else if (!strcmp (*args, "-out")) {
90 if (args[1]) {
91 args++;
92 outfile = *args;
93 } else badarg = 1;
94 } else badarg = 1;
95 args++;
96 }
97
98 if (badarg) {
99 BIO_printf (bio_err, "Netscape certificate sequence utility\n");
100 BIO_printf (bio_err, "Usage nseq [options]\n");
101 BIO_printf (bio_err, "where options are\n");
102 BIO_printf (bio_err, "-in file input file\n");
103 BIO_printf (bio_err, "-out file output file\n");
104 BIO_printf (bio_err, "-toseq output NS Sequence file\n");
105 EXIT(1);
106 }
107
108 if (infile) {
109 if (!(in = BIO_new_file (infile, "r"))) {
110 BIO_printf (bio_err,
111 "Can't open input file %s\n", infile);
112 goto end;
113 }
114 } else in = BIO_new_fp(stdin, BIO_NOCLOSE);
115
116 if (outfile) {
117 if (!(out = BIO_new_file (outfile, "w"))) {
118 BIO_printf (bio_err,
119 "Can't open output file %s\n", outfile);
120 goto end;
121 }
122 } else out = BIO_new_fp(stdout, BIO_NOCLOSE);
123
124 if (toseq) {
125 seq = NETSCAPE_CERT_SEQUENCE_new();
126 seq->certs = sk_X509_new(NULL);
127 while((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL)))
128 sk_X509_push(seq->certs,x509);
129
130 if(!sk_X509_num(seq->certs))
131 {
132 BIO_printf (bio_err, "Error reading certs file %s\n", infile);
133 ERR_print_errors(bio_err);
134 goto end;
135 }
136 PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out, seq);
137 ret = 0;
138 goto end;
139 }
140
141 if (!(seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL))) {
142 BIO_printf (bio_err, "Error reading sequence file %s\n", infile);
143 ERR_print_errors(bio_err);
144 goto end;
145 }
146
147 for(i = 0; i < sk_X509_num(seq->certs); i++) {
148 x509 = sk_X509_value(seq->certs, i);
149 dump_cert_text(out, x509);
150 PEM_write_bio_X509(out, x509);
151 }
152 ret = 0;
153end:
154 BIO_free(in);
155 BIO_free(out);
156 NETSCAPE_CERT_SEQUENCE_free(seq);
157
158 EXIT(ret);
159}
160
161static int dump_cert_text(BIO *out, X509 *x)
162{
163 char buf[256];
164 X509_NAME_oneline(X509_get_subject_name(x),buf,256);
165 BIO_puts(out,"subject=");
166 BIO_puts(out,buf);
167
168 X509_NAME_oneline(X509_get_issuer_name(x),buf,256);
169 BIO_puts(out,"\nissuer= ");
170 BIO_puts(out,buf);
171 BIO_puts(out,"\n");
172 return 0;
173}
174
diff --git a/src/lib/libssl/src/apps/ocsp.c b/src/lib/libssl/src/apps/ocsp.c
new file mode 100644
index 0000000000..c87edbc44b
--- /dev/null
+++ b/src/lib/libssl/src/apps/ocsp.c
@@ -0,0 +1,1211 @@
1/* ocsp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/pem.h>
62#include <openssl/ocsp.h>
63#include <openssl/err.h>
64#include <openssl/ssl.h>
65#include "apps.h"
66
67/* Maximum leeway in validity period: default 5 minutes */
68#define MAX_VALIDITY_PERIOD (5 * 60)
69
70/* CA index.txt definitions */
71#define DB_type 0
72#define DB_exp_date 1
73#define DB_rev_date 2
74#define DB_serial 3 /* index - unique */
75#define DB_file 4
76#define DB_name 5 /* index - unique for active */
77#define DB_NUMBER 6
78
79#define DB_TYPE_REV 'R'
80#define DB_TYPE_EXP 'E'
81#define DB_TYPE_VAL 'V'
82
83static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
84 STACK_OF(OCSP_CERTID) *ids);
85static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
86 STACK_OF(OCSP_CERTID) *ids);
87static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
88 STACK *names, STACK_OF(OCSP_CERTID) *ids,
89 long nsec, long maxage);
90
91static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, TXT_DB *db,
92 X509 *ca, X509 *rcert, EVP_PKEY *rkey,
93 STACK_OF(X509) *rother, unsigned long flags,
94 int nmin, int ndays);
95
96static char **lookup_serial(TXT_DB *db, ASN1_INTEGER *ser);
97static BIO *init_responder(char *port);
98static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, char *port);
99static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp);
100
101#undef PROG
102#define PROG ocsp_main
103
104int MAIN(int, char **);
105
106int MAIN(int argc, char **argv)
107 {
108 ENGINE *e = NULL;
109 char **args;
110 char *host = NULL, *port = NULL, *path = "/";
111 char *reqin = NULL, *respin = NULL;
112 char *reqout = NULL, *respout = NULL;
113 char *signfile = NULL, *keyfile = NULL;
114 char *rsignfile = NULL, *rkeyfile = NULL;
115 char *outfile = NULL;
116 int add_nonce = 1, noverify = 0, use_ssl = -1;
117 OCSP_REQUEST *req = NULL;
118 OCSP_RESPONSE *resp = NULL;
119 OCSP_BASICRESP *bs = NULL;
120 X509 *issuer = NULL, *cert = NULL;
121 X509 *signer = NULL, *rsigner = NULL;
122 EVP_PKEY *key = NULL, *rkey = NULL;
123 BIO *acbio = NULL, *cbio = NULL;
124 BIO *derbio = NULL;
125 BIO *out = NULL;
126 int req_text = 0, resp_text = 0;
127 long nsec = MAX_VALIDITY_PERIOD, maxage = -1;
128 char *CAfile = NULL, *CApath = NULL;
129 X509_STORE *store = NULL;
130 SSL_CTX *ctx = NULL;
131 STACK_OF(X509) *sign_other = NULL, *verify_other = NULL, *rother = NULL;
132 char *sign_certfile = NULL, *verify_certfile = NULL, *rcertfile = NULL;
133 unsigned long sign_flags = 0, verify_flags = 0, rflags = 0;
134 int ret = 1;
135 int accept_count = -1;
136 int badarg = 0;
137 int i;
138 STACK *reqnames = NULL;
139 STACK_OF(OCSP_CERTID) *ids = NULL;
140
141 X509 *rca_cert = NULL;
142 char *ridx_filename = NULL;
143 char *rca_filename = NULL;
144 TXT_DB *rdb = NULL;
145 int nmin = 0, ndays = -1;
146
147 if (bio_err == NULL) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
148
149 if (!load_config(bio_err, NULL))
150 goto end;
151 SSL_load_error_strings();
152 args = argv + 1;
153 reqnames = sk_new_null();
154 ids = sk_OCSP_CERTID_new_null();
155 while (!badarg && *args && *args[0] == '-')
156 {
157 if (!strcmp(*args, "-out"))
158 {
159 if (args[1])
160 {
161 args++;
162 outfile = *args;
163 }
164 else badarg = 1;
165 }
166 else if (!strcmp(*args, "-url"))
167 {
168 if (args[1])
169 {
170 args++;
171 if (!OCSP_parse_url(*args, &host, &port, &path, &use_ssl))
172 {
173 BIO_printf(bio_err, "Error parsing URL\n");
174 badarg = 1;
175 }
176 }
177 else badarg = 1;
178 }
179 else if (!strcmp(*args, "-host"))
180 {
181 if (args[1])
182 {
183 args++;
184 host = *args;
185 }
186 else badarg = 1;
187 }
188 else if (!strcmp(*args, "-port"))
189 {
190 if (args[1])
191 {
192 args++;
193 port = *args;
194 }
195 else badarg = 1;
196 }
197 else if (!strcmp(*args, "-noverify"))
198 noverify = 1;
199 else if (!strcmp(*args, "-nonce"))
200 add_nonce = 2;
201 else if (!strcmp(*args, "-no_nonce"))
202 add_nonce = 0;
203 else if (!strcmp(*args, "-resp_no_certs"))
204 rflags |= OCSP_NOCERTS;
205 else if (!strcmp(*args, "-resp_key_id"))
206 rflags |= OCSP_RESPID_KEY;
207 else if (!strcmp(*args, "-no_certs"))
208 sign_flags |= OCSP_NOCERTS;
209 else if (!strcmp(*args, "-no_signature_verify"))
210 verify_flags |= OCSP_NOSIGS;
211 else if (!strcmp(*args, "-no_cert_verify"))
212 verify_flags |= OCSP_NOVERIFY;
213 else if (!strcmp(*args, "-no_chain"))
214 verify_flags |= OCSP_NOCHAIN;
215 else if (!strcmp(*args, "-no_cert_checks"))
216 verify_flags |= OCSP_NOCHECKS;
217 else if (!strcmp(*args, "-no_explicit"))
218 verify_flags |= OCSP_NOEXPLICIT;
219 else if (!strcmp(*args, "-trust_other"))
220 verify_flags |= OCSP_TRUSTOTHER;
221 else if (!strcmp(*args, "-no_intern"))
222 verify_flags |= OCSP_NOINTERN;
223 else if (!strcmp(*args, "-text"))
224 {
225 req_text = 1;
226 resp_text = 1;
227 }
228 else if (!strcmp(*args, "-req_text"))
229 req_text = 1;
230 else if (!strcmp(*args, "-resp_text"))
231 resp_text = 1;
232 else if (!strcmp(*args, "-reqin"))
233 {
234 if (args[1])
235 {
236 args++;
237 reqin = *args;
238 }
239 else badarg = 1;
240 }
241 else if (!strcmp(*args, "-respin"))
242 {
243 if (args[1])
244 {
245 args++;
246 respin = *args;
247 }
248 else badarg = 1;
249 }
250 else if (!strcmp(*args, "-signer"))
251 {
252 if (args[1])
253 {
254 args++;
255 signfile = *args;
256 }
257 else badarg = 1;
258 }
259 else if (!strcmp (*args, "-VAfile"))
260 {
261 if (args[1])
262 {
263 args++;
264 verify_certfile = *args;
265 verify_flags |= OCSP_TRUSTOTHER;
266 }
267 else badarg = 1;
268 }
269 else if (!strcmp(*args, "-sign_other"))
270 {
271 if (args[1])
272 {
273 args++;
274 sign_certfile = *args;
275 }
276 else badarg = 1;
277 }
278 else if (!strcmp(*args, "-verify_other"))
279 {
280 if (args[1])
281 {
282 args++;
283 verify_certfile = *args;
284 }
285 else badarg = 1;
286 }
287 else if (!strcmp (*args, "-CAfile"))
288 {
289 if (args[1])
290 {
291 args++;
292 CAfile = *args;
293 }
294 else badarg = 1;
295 }
296 else if (!strcmp (*args, "-CApath"))
297 {
298 if (args[1])
299 {
300 args++;
301 CApath = *args;
302 }
303 else badarg = 1;
304 }
305 else if (!strcmp (*args, "-validity_period"))
306 {
307 if (args[1])
308 {
309 args++;
310 nsec = atol(*args);
311 if (nsec < 0)
312 {
313 BIO_printf(bio_err,
314 "Illegal validity period %s\n",
315 *args);
316 badarg = 1;
317 }
318 }
319 else badarg = 1;
320 }
321 else if (!strcmp (*args, "-status_age"))
322 {
323 if (args[1])
324 {
325 args++;
326 maxage = atol(*args);
327 if (maxage < 0)
328 {
329 BIO_printf(bio_err,
330 "Illegal validity age %s\n",
331 *args);
332 badarg = 1;
333 }
334 }
335 else badarg = 1;
336 }
337 else if (!strcmp(*args, "-signkey"))
338 {
339 if (args[1])
340 {
341 args++;
342 keyfile = *args;
343 }
344 else badarg = 1;
345 }
346 else if (!strcmp(*args, "-reqout"))
347 {
348 if (args[1])
349 {
350 args++;
351 reqout = *args;
352 }
353 else badarg = 1;
354 }
355 else if (!strcmp(*args, "-respout"))
356 {
357 if (args[1])
358 {
359 args++;
360 respout = *args;
361 }
362 else badarg = 1;
363 }
364 else if (!strcmp(*args, "-path"))
365 {
366 if (args[1])
367 {
368 args++;
369 path = *args;
370 }
371 else badarg = 1;
372 }
373 else if (!strcmp(*args, "-issuer"))
374 {
375 if (args[1])
376 {
377 args++;
378 X509_free(issuer);
379 issuer = load_cert(bio_err, *args, FORMAT_PEM,
380 NULL, e, "issuer certificate");
381 if(!issuer) goto end;
382 }
383 else badarg = 1;
384 }
385 else if (!strcmp (*args, "-cert"))
386 {
387 if (args[1])
388 {
389 args++;
390 X509_free(cert);
391 cert = load_cert(bio_err, *args, FORMAT_PEM,
392 NULL, e, "certificate");
393 if(!cert) goto end;
394 if(!add_ocsp_cert(&req, cert, issuer, ids))
395 goto end;
396 if(!sk_push(reqnames, *args))
397 goto end;
398 }
399 else badarg = 1;
400 }
401 else if (!strcmp(*args, "-serial"))
402 {
403 if (args[1])
404 {
405 args++;
406 if(!add_ocsp_serial(&req, *args, issuer, ids))
407 goto end;
408 if(!sk_push(reqnames, *args))
409 goto end;
410 }
411 else badarg = 1;
412 }
413 else if (!strcmp(*args, "-index"))
414 {
415 if (args[1])
416 {
417 args++;
418 ridx_filename = *args;
419 }
420 else badarg = 1;
421 }
422 else if (!strcmp(*args, "-CA"))
423 {
424 if (args[1])
425 {
426 args++;
427 rca_filename = *args;
428 }
429 else badarg = 1;
430 }
431 else if (!strcmp (*args, "-nmin"))
432 {
433 if (args[1])
434 {
435 args++;
436 nmin = atol(*args);
437 if (nmin < 0)
438 {
439 BIO_printf(bio_err,
440 "Illegal update period %s\n",
441 *args);
442 badarg = 1;
443 }
444 }
445 if (ndays == -1)
446 ndays = 0;
447 else badarg = 1;
448 }
449 else if (!strcmp (*args, "-nrequest"))
450 {
451 if (args[1])
452 {
453 args++;
454 accept_count = atol(*args);
455 if (accept_count < 0)
456 {
457 BIO_printf(bio_err,
458 "Illegal accept count %s\n",
459 *args);
460 badarg = 1;
461 }
462 }
463 else badarg = 1;
464 }
465 else if (!strcmp (*args, "-ndays"))
466 {
467 if (args[1])
468 {
469 args++;
470 ndays = atol(*args);
471 if (ndays < 0)
472 {
473 BIO_printf(bio_err,
474 "Illegal update period %s\n",
475 *args);
476 badarg = 1;
477 }
478 }
479 else badarg = 1;
480 }
481 else if (!strcmp(*args, "-rsigner"))
482 {
483 if (args[1])
484 {
485 args++;
486 rsignfile = *args;
487 }
488 else badarg = 1;
489 }
490 else if (!strcmp(*args, "-rkey"))
491 {
492 if (args[1])
493 {
494 args++;
495 rkeyfile = *args;
496 }
497 else badarg = 1;
498 }
499 else if (!strcmp(*args, "-rother"))
500 {
501 if (args[1])
502 {
503 args++;
504 rcertfile = *args;
505 }
506 else badarg = 1;
507 }
508 else badarg = 1;
509 args++;
510 }
511
512 /* Have we anything to do? */
513 if (!req && !reqin && !respin && !(port && ridx_filename)) badarg = 1;
514
515 if (badarg)
516 {
517 BIO_printf (bio_err, "OCSP utility\n");
518 BIO_printf (bio_err, "Usage ocsp [options]\n");
519 BIO_printf (bio_err, "where options are\n");
520 BIO_printf (bio_err, "-out file output filename\n");
521 BIO_printf (bio_err, "-issuer file issuer certificate\n");
522 BIO_printf (bio_err, "-cert file certificate to check\n");
523 BIO_printf (bio_err, "-serial n serial number to check\n");
524 BIO_printf (bio_err, "-signer file certificate to sign OCSP request with\n");
525 BIO_printf (bio_err, "-signkey file private key to sign OCSP request with\n");
526 BIO_printf (bio_err, "-sign_certs file additional certificates to include in signed request\n");
527 BIO_printf (bio_err, "-no_certs don't include any certificates in signed request\n");
528 BIO_printf (bio_err, "-req_text print text form of request\n");
529 BIO_printf (bio_err, "-resp_text print text form of response\n");
530 BIO_printf (bio_err, "-text print text form of request and response\n");
531 BIO_printf (bio_err, "-reqout file write DER encoded OCSP request to \"file\"\n");
532 BIO_printf (bio_err, "-respout file write DER encoded OCSP reponse to \"file\"\n");
533 BIO_printf (bio_err, "-reqin file read DER encoded OCSP request from \"file\"\n");
534 BIO_printf (bio_err, "-respin file read DER encoded OCSP reponse from \"file\"\n");
535 BIO_printf (bio_err, "-nonce add OCSP nonce to request\n");
536 BIO_printf (bio_err, "-no_nonce don't add OCSP nonce to request\n");
537 BIO_printf (bio_err, "-url URL OCSP responder URL\n");
538 BIO_printf (bio_err, "-host host:n send OCSP request to host on port n\n");
539 BIO_printf (bio_err, "-path path to use in OCSP request\n");
540 BIO_printf (bio_err, "-CApath dir trusted certificates directory\n");
541 BIO_printf (bio_err, "-CAfile file trusted certificates file\n");
542 BIO_printf (bio_err, "-VAfile file validator certificates file\n");
543 BIO_printf (bio_err, "-validity_period n maximum validity discrepancy in seconds\n");
544 BIO_printf (bio_err, "-status_age n maximum status age in seconds\n");
545 BIO_printf (bio_err, "-noverify don't verify response at all\n");
546 BIO_printf (bio_err, "-verify_certs file additional certificates to search for signer\n");
547 BIO_printf (bio_err, "-trust_other don't verify additional certificates\n");
548 BIO_printf (bio_err, "-no_intern don't search certificates contained in response for signer\n");
549 BIO_printf (bio_err, "-no_sig_verify don't check signature on response\n");
550 BIO_printf (bio_err, "-no_cert_verify don't check signing certificate\n");
551 BIO_printf (bio_err, "-no_chain don't chain verify response\n");
552 BIO_printf (bio_err, "-no_cert_checks don't do additional checks on signing certificate\n");
553 BIO_printf (bio_err, "-port num port to run responder on\n");
554 BIO_printf (bio_err, "-index file certificate status index file\n");
555 BIO_printf (bio_err, "-CA file CA certificate\n");
556 BIO_printf (bio_err, "-rsigner file responder certificate to sign requests with\n");
557 BIO_printf (bio_err, "-rkey file responder key to sign requests with\n");
558 BIO_printf (bio_err, "-rother file other certificates to include in response\n");
559 BIO_printf (bio_err, "-resp_no_certs don't include any certificates in response\n");
560 BIO_printf (bio_err, "-nmin n number of minutes before next update\n");
561 BIO_printf (bio_err, "-ndays n number of days before next update\n");
562 BIO_printf (bio_err, "-resp_key_id identify reponse by signing certificate key ID\n");
563 BIO_printf (bio_err, "-nrequest n number of requests to accept (default unlimited)\n");
564 goto end;
565 }
566
567 if(outfile) out = BIO_new_file(outfile, "w");
568 else out = BIO_new_fp(stdout, BIO_NOCLOSE);
569
570 if(!out)
571 {
572 BIO_printf(bio_err, "Error opening output file\n");
573 goto end;
574 }
575
576 if (!req && (add_nonce != 2)) add_nonce = 0;
577
578 if (!req && reqin)
579 {
580 derbio = BIO_new_file(reqin, "rb");
581 if (!derbio)
582 {
583 BIO_printf(bio_err, "Error Opening OCSP request file\n");
584 goto end;
585 }
586 req = d2i_OCSP_REQUEST_bio(derbio, NULL);
587 BIO_free(derbio);
588 if(!req)
589 {
590 BIO_printf(bio_err, "Error reading OCSP request\n");
591 goto end;
592 }
593 }
594
595 if (!req && port)
596 {
597 acbio = init_responder(port);
598 if (!acbio)
599 goto end;
600 }
601
602 if (rsignfile && !rdb)
603 {
604 if (!rkeyfile) rkeyfile = rsignfile;
605 rsigner = load_cert(bio_err, rsignfile, FORMAT_PEM,
606 NULL, e, "responder certificate");
607 if (!rsigner)
608 {
609 BIO_printf(bio_err, "Error loading responder certificate\n");
610 goto end;
611 }
612 rca_cert = load_cert(bio_err, rca_filename, FORMAT_PEM,
613 NULL, e, "CA certificate");
614 if (rcertfile)
615 {
616 rother = load_certs(bio_err, sign_certfile, FORMAT_PEM,
617 NULL, e, "responder other certificates");
618 if (!sign_other) goto end;
619 }
620 rkey = load_key(bio_err, rkeyfile, FORMAT_PEM, NULL, NULL,
621 "responder private key");
622 if (!rkey)
623 goto end;
624 }
625 if(acbio)
626 BIO_printf(bio_err, "Waiting for OCSP client connections...\n");
627
628 redo_accept:
629
630 if (acbio)
631 {
632 if (!do_responder(&req, &cbio, acbio, port))
633 goto end;
634 if (!req)
635 {
636 resp = OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, NULL);
637 send_ocsp_response(cbio, resp);
638 goto done_resp;
639 }
640 }
641
642 if (!req && (signfile || reqout || host || add_nonce || ridx_filename))
643 {
644 BIO_printf(bio_err, "Need an OCSP request for this operation!\n");
645 goto end;
646 }
647
648 if (req && add_nonce) OCSP_request_add1_nonce(req, NULL, -1);
649
650 if (signfile)
651 {
652 if (!keyfile) keyfile = signfile;
653 signer = load_cert(bio_err, signfile, FORMAT_PEM,
654 NULL, e, "signer certificate");
655 if (!signer)
656 {
657 BIO_printf(bio_err, "Error loading signer certificate\n");
658 goto end;
659 }
660 if (sign_certfile)
661 {
662 sign_other = load_certs(bio_err, sign_certfile, FORMAT_PEM,
663 NULL, e, "signer certificates");
664 if (!sign_other) goto end;
665 }
666 key = load_key(bio_err, keyfile, FORMAT_PEM, NULL, NULL,
667 "signer private key");
668 if (!key)
669 goto end;
670 if (!OCSP_request_sign(req, signer, key, EVP_sha1(), sign_other, sign_flags))
671 {
672 BIO_printf(bio_err, "Error signing OCSP request\n");
673 goto end;
674 }
675 }
676
677 if (req_text && req) OCSP_REQUEST_print(out, req, 0);
678
679 if (ridx_filename && (!rkey || !rsigner || !rca_cert))
680 {
681 BIO_printf(bio_err, "Need a responder certificate, key and CA for this operation!\n");
682 goto end;
683 }
684
685 if (ridx_filename && !rdb)
686 {
687 BIO *db_bio = NULL;
688 db_bio = BIO_new_file(ridx_filename, "r");
689 if (!db_bio)
690 {
691 BIO_printf(bio_err, "Error opening index file %s\n", ridx_filename);
692 goto end;
693 }
694 rdb = TXT_DB_read(db_bio, DB_NUMBER);
695 BIO_free(db_bio);
696 if (!rdb)
697 {
698 BIO_printf(bio_err, "Error reading index file %s\n", ridx_filename);
699 goto end;
700 }
701 if (!make_serial_index(rdb))
702 goto end;
703 }
704
705 if (rdb)
706 {
707 i = make_ocsp_response(&resp, req, rdb, rca_cert, rsigner, rkey, rother, rflags, nmin, ndays);
708 if (cbio)
709 send_ocsp_response(cbio, resp);
710 }
711 else if (host)
712 {
713 cbio = BIO_new_connect(host);
714 if (!cbio)
715 {
716 BIO_printf(bio_err, "Error creating connect BIO\n");
717 goto end;
718 }
719 if (port) BIO_set_conn_port(cbio, port);
720 if (use_ssl == 1)
721 {
722 BIO *sbio;
723 ctx = SSL_CTX_new(SSLv23_client_method());
724 SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);
725 sbio = BIO_new_ssl(ctx, 1);
726 cbio = BIO_push(sbio, cbio);
727 }
728 if (BIO_do_connect(cbio) <= 0)
729 {
730 BIO_printf(bio_err, "Error connecting BIO\n");
731 goto end;
732 }
733 resp = OCSP_sendreq_bio(cbio, path, req);
734 BIO_free_all(cbio);
735 cbio = NULL;
736 if (!resp)
737 {
738 BIO_printf(bio_err, "Error querying OCSP responsder\n");
739 goto end;
740 }
741 }
742 else if (respin)
743 {
744 derbio = BIO_new_file(respin, "rb");
745 if (!derbio)
746 {
747 BIO_printf(bio_err, "Error Opening OCSP response file\n");
748 goto end;
749 }
750 resp = d2i_OCSP_RESPONSE_bio(derbio, NULL);
751 BIO_free(derbio);
752 if(!resp)
753 {
754 BIO_printf(bio_err, "Error reading OCSP response\n");
755 goto end;
756 }
757
758 }
759 else
760 {
761 ret = 0;
762 goto end;
763 }
764
765 done_resp:
766
767 if (respout)
768 {
769 derbio = BIO_new_file(respout, "wb");
770 if(!derbio)
771 {
772 BIO_printf(bio_err, "Error opening file %s\n", respout);
773 goto end;
774 }
775 i2d_OCSP_RESPONSE_bio(derbio, resp);
776 BIO_free(derbio);
777 }
778
779 i = OCSP_response_status(resp);
780
781 if (i != OCSP_RESPONSE_STATUS_SUCCESSFUL)
782 {
783 BIO_printf(out, "Responder Error: %s (%ld)\n",
784 OCSP_response_status_str(i), i);
785 ret = 0;
786 goto end;
787 }
788
789 if (resp_text) OCSP_RESPONSE_print(out, resp, 0);
790
791 /* If running as responder don't verify our own response */
792 if (cbio)
793 {
794 if (accept_count > 0)
795 accept_count--;
796 /* Redo if more connections needed */
797 if (accept_count)
798 {
799 BIO_free_all(cbio);
800 cbio = NULL;
801 OCSP_REQUEST_free(req);
802 req = NULL;
803 OCSP_RESPONSE_free(resp);
804 resp = NULL;
805 goto redo_accept;
806 }
807 goto end;
808 }
809
810 if (!store)
811 store = setup_verify(bio_err, CAfile, CApath);
812 if (verify_certfile)
813 {
814 verify_other = load_certs(bio_err, verify_certfile, FORMAT_PEM,
815 NULL, e, "validator certificate");
816 if (!verify_other) goto end;
817 }
818
819 bs = OCSP_response_get1_basic(resp);
820
821 if (!bs)
822 {
823 BIO_printf(bio_err, "Error parsing response\n");
824 goto end;
825 }
826
827 if (!noverify)
828 {
829 if (req && ((i = OCSP_check_nonce(req, bs)) <= 0))
830 {
831 if (i == -1)
832 BIO_printf(bio_err, "WARNING: no nonce in response\n");
833 else
834 {
835 BIO_printf(bio_err, "Nonce Verify error\n");
836 goto end;
837 }
838 }
839
840 i = OCSP_basic_verify(bs, verify_other, store, verify_flags);
841 if (i < 0) i = OCSP_basic_verify(bs, NULL, store, 0);
842
843 if(i <= 0)
844 {
845 BIO_printf(bio_err, "Response Verify Failure\n", i);
846 ERR_print_errors(bio_err);
847 }
848 else
849 BIO_printf(bio_err, "Response verify OK\n");
850
851 }
852
853 if (!print_ocsp_summary(out, bs, req, reqnames, ids, nsec, maxage))
854 goto end;
855
856 ret = 0;
857
858end:
859 ERR_print_errors(bio_err);
860 X509_free(signer);
861 X509_STORE_free(store);
862 EVP_PKEY_free(key);
863 EVP_PKEY_free(rkey);
864 X509_free(issuer);
865 X509_free(cert);
866 X509_free(rsigner);
867 X509_free(rca_cert);
868 TXT_DB_free(rdb);
869 BIO_free_all(cbio);
870 BIO_free_all(acbio);
871 BIO_free(out);
872 OCSP_REQUEST_free(req);
873 OCSP_RESPONSE_free(resp);
874 OCSP_BASICRESP_free(bs);
875 sk_free(reqnames);
876 sk_OCSP_CERTID_free(ids);
877 sk_X509_pop_free(sign_other, X509_free);
878 sk_X509_pop_free(verify_other, X509_free);
879
880 if (use_ssl != -1)
881 {
882 OPENSSL_free(host);
883 OPENSSL_free(port);
884 OPENSSL_free(path);
885 SSL_CTX_free(ctx);
886 }
887
888 EXIT(ret);
889}
890
891static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
892 STACK_OF(OCSP_CERTID) *ids)
893 {
894 OCSP_CERTID *id;
895 if(!issuer)
896 {
897 BIO_printf(bio_err, "No issuer certificate specified\n");
898 return 0;
899 }
900 if(!*req) *req = OCSP_REQUEST_new();
901 if(!*req) goto err;
902 id = OCSP_cert_to_id(NULL, cert, issuer);
903 if(!id || !sk_OCSP_CERTID_push(ids, id)) goto err;
904 if(!OCSP_request_add0_id(*req, id)) goto err;
905 return 1;
906
907 err:
908 BIO_printf(bio_err, "Error Creating OCSP request\n");
909 return 0;
910 }
911
912static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
913 STACK_OF(OCSP_CERTID) *ids)
914 {
915 OCSP_CERTID *id;
916 X509_NAME *iname;
917 ASN1_BIT_STRING *ikey;
918 ASN1_INTEGER *sno;
919 if(!issuer)
920 {
921 BIO_printf(bio_err, "No issuer certificate specified\n");
922 return 0;
923 }
924 if(!*req) *req = OCSP_REQUEST_new();
925 if(!*req) goto err;
926 iname = X509_get_subject_name(issuer);
927 ikey = X509_get0_pubkey_bitstr(issuer);
928 sno = s2i_ASN1_INTEGER(NULL, serial);
929 if(!sno)
930 {
931 BIO_printf(bio_err, "Error converting serial number %s\n", serial);
932 return 0;
933 }
934 id = OCSP_cert_id_new(EVP_sha1(), iname, ikey, sno);
935 ASN1_INTEGER_free(sno);
936 if(!id || !sk_OCSP_CERTID_push(ids, id)) goto err;
937 if(!OCSP_request_add0_id(*req, id)) goto err;
938 return 1;
939
940 err:
941 BIO_printf(bio_err, "Error Creating OCSP request\n");
942 return 0;
943 }
944
945static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
946 STACK *names, STACK_OF(OCSP_CERTID) *ids,
947 long nsec, long maxage)
948 {
949 OCSP_CERTID *id;
950 char *name;
951 int i;
952
953 int status, reason;
954
955 ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd;
956
957 if (!bs || !req || !sk_num(names) || !sk_OCSP_CERTID_num(ids))
958 return 1;
959
960 for (i = 0; i < sk_OCSP_CERTID_num(ids); i++)
961 {
962 id = sk_OCSP_CERTID_value(ids, i);
963 name = sk_value(names, i);
964 BIO_printf(out, "%s: ", name);
965
966 if(!OCSP_resp_find_status(bs, id, &status, &reason,
967 &rev, &thisupd, &nextupd))
968 {
969 BIO_puts(out, "ERROR: No Status found.\n");
970 continue;
971 }
972
973 /* Check validity: if invalid write to output BIO so we
974 * know which response this refers to.
975 */
976 if (!OCSP_check_validity(thisupd, nextupd, nsec, maxage))
977 {
978 BIO_puts(out, "WARNING: Status times invalid.\n");
979 ERR_print_errors(out);
980 }
981 BIO_printf(out, "%s\n", OCSP_cert_status_str(status));
982
983 BIO_puts(out, "\tThis Update: ");
984 ASN1_GENERALIZEDTIME_print(out, thisupd);
985 BIO_puts(out, "\n");
986
987 if(nextupd)
988 {
989 BIO_puts(out, "\tNext Update: ");
990 ASN1_GENERALIZEDTIME_print(out, nextupd);
991 BIO_puts(out, "\n");
992 }
993
994 if (status != V_OCSP_CERTSTATUS_REVOKED)
995 continue;
996
997 if (reason != -1)
998 BIO_printf(out, "\tReason: %s\n",
999 OCSP_crl_reason_str(reason));
1000
1001 BIO_puts(out, "\tRevocation Time: ");
1002 ASN1_GENERALIZEDTIME_print(out, rev);
1003 BIO_puts(out, "\n");
1004 }
1005
1006 return 1;
1007 }
1008
1009
1010static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, TXT_DB *db,
1011 X509 *ca, X509 *rcert, EVP_PKEY *rkey,
1012 STACK_OF(X509) *rother, unsigned long flags,
1013 int nmin, int ndays)
1014 {
1015 ASN1_TIME *thisupd = NULL, *nextupd = NULL;
1016 OCSP_CERTID *cid, *ca_id = NULL;
1017 OCSP_BASICRESP *bs = NULL;
1018 int i, id_count, ret = 1;
1019
1020
1021 id_count = OCSP_request_onereq_count(req);
1022
1023 if (id_count <= 0)
1024 {
1025 *resp = OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, NULL);
1026 goto end;
1027 }
1028
1029 ca_id = OCSP_cert_to_id(EVP_sha1(), NULL, ca);
1030
1031 bs = OCSP_BASICRESP_new();
1032 thisupd = X509_gmtime_adj(NULL, 0);
1033 if (ndays != -1)
1034 nextupd = X509_gmtime_adj(NULL, nmin * 60 + ndays * 3600 * 24 );
1035
1036 /* Examine each certificate id in the request */
1037 for (i = 0; i < id_count; i++)
1038 {
1039 OCSP_ONEREQ *one;
1040 ASN1_INTEGER *serial;
1041 char **inf;
1042 one = OCSP_request_onereq_get0(req, i);
1043 cid = OCSP_onereq_get0_id(one);
1044 /* Is this request about our CA? */
1045 if (OCSP_id_issuer_cmp(ca_id, cid))
1046 {
1047 OCSP_basic_add1_status(bs, cid,
1048 V_OCSP_CERTSTATUS_UNKNOWN,
1049 0, NULL,
1050 thisupd, nextupd);
1051 continue;
1052 }
1053 OCSP_id_get0_info(NULL, NULL, NULL, &serial, cid);
1054 inf = lookup_serial(db, serial);
1055 if (!inf)
1056 OCSP_basic_add1_status(bs, cid,
1057 V_OCSP_CERTSTATUS_UNKNOWN,
1058 0, NULL,
1059 thisupd, nextupd);
1060 else if (inf[DB_type][0] == DB_TYPE_VAL)
1061 OCSP_basic_add1_status(bs, cid,
1062 V_OCSP_CERTSTATUS_GOOD,
1063 0, NULL,
1064 thisupd, nextupd);
1065 else if (inf[DB_type][0] == DB_TYPE_REV)
1066 {
1067 ASN1_OBJECT *inst = NULL;
1068 ASN1_TIME *revtm = NULL;
1069 ASN1_GENERALIZEDTIME *invtm = NULL;
1070 OCSP_SINGLERESP *single;
1071 int reason = -1;
1072 unpack_revinfo(&revtm, &reason, &inst, &invtm, inf[DB_rev_date]);
1073 single = OCSP_basic_add1_status(bs, cid,
1074 V_OCSP_CERTSTATUS_REVOKED,
1075 reason, revtm,
1076 thisupd, nextupd);
1077 if (invtm)
1078 OCSP_SINGLERESP_add1_ext_i2d(single, NID_invalidity_date, invtm, 0, 0);
1079 else if (inst)
1080 OCSP_SINGLERESP_add1_ext_i2d(single, NID_hold_instruction_code, inst, 0, 0);
1081 ASN1_OBJECT_free(inst);
1082 ASN1_TIME_free(revtm);
1083 ASN1_GENERALIZEDTIME_free(invtm);
1084 }
1085 }
1086
1087 OCSP_copy_nonce(bs, req);
1088
1089 OCSP_basic_sign(bs, rcert, rkey, EVP_sha1(), rother, flags);
1090
1091 *resp = OCSP_response_create(OCSP_RESPONSE_STATUS_SUCCESSFUL, bs);
1092
1093 end:
1094 ASN1_TIME_free(thisupd);
1095 ASN1_TIME_free(nextupd);
1096 OCSP_CERTID_free(ca_id);
1097 OCSP_BASICRESP_free(bs);
1098 return ret;
1099
1100 }
1101
1102static char **lookup_serial(TXT_DB *db, ASN1_INTEGER *ser)
1103 {
1104 int i;
1105 BIGNUM *bn = NULL;
1106 char *itmp, *row[DB_NUMBER],**rrow;
1107 for (i = 0; i < DB_NUMBER; i++) row[i] = NULL;
1108 bn = ASN1_INTEGER_to_BN(ser,NULL);
1109 itmp = BN_bn2hex(bn);
1110 row[DB_serial] = itmp;
1111 BN_free(bn);
1112 rrow=TXT_DB_get_by_index(db,DB_serial,row);
1113 OPENSSL_free(itmp);
1114 return rrow;
1115 }
1116
1117/* Quick and dirty OCSP server: read in and parse input request */
1118
1119static BIO *init_responder(char *port)
1120 {
1121 BIO *acbio = NULL, *bufbio = NULL;
1122 bufbio = BIO_new(BIO_f_buffer());
1123 if (!bufbio)
1124 goto err;
1125 acbio = BIO_new_accept(port);
1126 if (!acbio)
1127 goto err;
1128 BIO_set_accept_bios(acbio, bufbio);
1129 bufbio = NULL;
1130
1131 if (BIO_do_accept(acbio) <= 0)
1132 {
1133 BIO_printf(bio_err, "Error setting up accept BIO\n");
1134 ERR_print_errors(bio_err);
1135 goto err;
1136 }
1137
1138 return acbio;
1139
1140 err:
1141 BIO_free_all(acbio);
1142 BIO_free(bufbio);
1143 return NULL;
1144 }
1145
1146static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, char *port)
1147 {
1148 int have_post = 0, len;
1149 OCSP_REQUEST *req = NULL;
1150 char inbuf[1024];
1151 BIO *cbio = NULL;
1152
1153 if (BIO_do_accept(acbio) <= 0)
1154 {
1155 BIO_printf(bio_err, "Error accepting connection\n");
1156 ERR_print_errors(bio_err);
1157 return 0;
1158 }
1159
1160 cbio = BIO_pop(acbio);
1161 *pcbio = cbio;
1162
1163 for(;;)
1164 {
1165 len = BIO_gets(cbio, inbuf, 1024);
1166 if (len <= 0)
1167 return 1;
1168 /* Look for "POST" signalling start of query */
1169 if (!have_post)
1170 {
1171 if(strncmp(inbuf, "POST", 4))
1172 {
1173 BIO_printf(bio_err, "Invalid request\n");
1174 return 1;
1175 }
1176 have_post = 1;
1177 }
1178 /* Look for end of headers */
1179 if ((inbuf[0] == '\r') || (inbuf[0] == '\n'))
1180 break;
1181 }
1182
1183 /* Try to read OCSP request */
1184
1185 req = d2i_OCSP_REQUEST_bio(cbio, NULL);
1186
1187 if (!req)
1188 {
1189 BIO_printf(bio_err, "Error parsing OCSP request\n");
1190 ERR_print_errors(bio_err);
1191 }
1192
1193 *preq = req;
1194
1195 return 1;
1196
1197 }
1198
1199static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp)
1200 {
1201 char http_resp[] =
1202 "HTTP/1.0 200 OK\r\nContent-type: application/ocsp-response\r\n"
1203 "Content-Length: %d\r\n\r\n";
1204 if (!cbio)
1205 return 0;
1206 BIO_printf(cbio, http_resp, i2d_OCSP_RESPONSE(resp, NULL));
1207 i2d_OCSP_RESPONSE_bio(cbio, resp);
1208 BIO_flush(cbio);
1209 return 1;
1210 }
1211
diff --git a/src/lib/libssl/src/apps/oid.cnf b/src/lib/libssl/src/apps/oid.cnf
new file mode 100644
index 0000000000..faf425a156
--- /dev/null
+++ b/src/lib/libssl/src/apps/oid.cnf
@@ -0,0 +1,6 @@
12.99999.1 SET.ex1 SET x509v3 extension 1
22.99999.2 SET.ex2 SET x509v3 extension 2
32.99999.3 SET.ex3 SET x509v3 extension 3
42.99999.4 SET.ex4 SET x509v3 extension 4
52.99999.5 SET.ex5 SET x509v3 extension 5
62.99999.6 SET.ex6 SET x509v3 extension 6
diff --git a/src/lib/libssl/src/apps/openssl-vms.cnf b/src/lib/libssl/src/apps/openssl-vms.cnf
new file mode 100644
index 0000000000..13d10f21ed
--- /dev/null
+++ b/src/lib/libssl/src/apps/openssl-vms.cnf
@@ -0,0 +1,214 @@
1#
2# OpenSSL example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = $ENV::HOME/.rnd
7oid_file = $ENV::HOME/.oid
8oid_section = new_oids
9
10# To use this configuration file with the "-extfile" option of the
11# "openssl x509" utility, name here the section containing the
12# X.509v3 extensions to use:
13# extensions =
14# (Alternatively, use a configuration file that has only
15# X.509v3 extensions in its main [= default] section.)
16
17[ new_oids ]
18
19# We can add new OIDs in here for use by 'ca' and 'req'.
20# Add a simple OID like this:
21# testoid1=1.2.3.4
22# Or use config file substitution like this:
23# testoid2=${testoid1}.5.6
24
25####################################################################
26[ ca ]
27default_ca = CA_default # The default ca section
28
29####################################################################
30[ CA_default ]
31
32dir = sys\$disk:[.demoCA # Where everything is kept
33certs = $dir.certs] # Where the issued certs are kept
34crl_dir = $dir.crl] # Where the issued crl are kept
35database = $dir]index.txt # database index file.
36new_certs_dir = $dir.newcerts] # default place for new certs.
37
38certificate = $dir]cacert.pem # The CA certificate
39serial = $dir]serial. # The current serial number
40crl = $dir]crl.pem # The current CRL
41private_key = $dir.private]cakey.pem# The private key
42RANDFILE = $dir.private].rand # private random number file
43
44x509_extensions = usr_cert # The extentions to add to the cert
45
46# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
47# so this is commented out by default to leave a V1 CRL.
48# crl_extensions = crl_ext
49
50default_days = 365 # how long to certify for
51default_crl_days= 30 # how long before next CRL
52default_md = md5 # which md to use.
53preserve = no # keep passed DN ordering
54
55# A few difference way of specifying how similar the request should look
56# For type CA, the listed attributes must be the same, and the optional
57# and supplied fields are just that :-)
58policy = policy_match
59
60# For the CA policy
61[ policy_match ]
62countryName = match
63stateOrProvinceName = match
64organizationName = match
65organizationalUnitName = optional
66commonName = supplied
67emailAddress = optional
68
69# For the 'anything' policy
70# At this point in time, you must list all acceptable 'object'
71# types.
72[ policy_anything ]
73countryName = optional
74stateOrProvinceName = optional
75localityName = optional
76organizationName = optional
77organizationalUnitName = optional
78commonName = supplied
79emailAddress = optional
80
81####################################################################
82[ req ]
83default_bits = 1024
84default_keyfile = privkey.pem
85distinguished_name = req_distinguished_name
86attributes = req_attributes
87x509_extensions = v3_ca # The extentions to add to the self signed cert
88
89[ req_distinguished_name ]
90countryName = Country Name (2 letter code)
91countryName_default = AU
92countryName_min = 2
93countryName_max = 2
94
95stateOrProvinceName = State or Province Name (full name)
96stateOrProvinceName_default = Some-State
97
98localityName = Locality Name (eg, city)
99
1000.organizationName = Organization Name (eg, company)
1010.organizationName_default = Internet Widgits Pty Ltd
102
103# we can do this but it is not needed normally :-)
104#1.organizationName = Second Organization Name (eg, company)
105#1.organizationName_default = World Wide Web Pty Ltd
106
107organizationalUnitName = Organizational Unit Name (eg, section)
108#organizationalUnitName_default =
109
110commonName = Common Name (eg, YOUR name)
111commonName_max = 64
112
113emailAddress = Email Address
114emailAddress_max = 40
115
116# SET-ex3 = SET extension number 3
117
118[ req_attributes ]
119challengePassword = A challenge password
120challengePassword_min = 4
121challengePassword_max = 20
122
123unstructuredName = An optional company name
124
125[ usr_cert ]
126
127# These extensions are added when 'ca' signs a request.
128
129# This goes against PKIX guidelines but some CAs do it and some software
130# requires this to avoid interpreting an end user certificate as a CA.
131
132basicConstraints=CA:FALSE
133
134# Here are some examples of the usage of nsCertType. If it is omitted
135# the certificate can be used for anything *except* object signing.
136
137# This is OK for an SSL server.
138# nsCertType = server
139
140# For an object signing certificate this would be used.
141# nsCertType = objsign
142
143# For normal client use this is typical
144# nsCertType = client, email
145
146# and for everything including object signing:
147# nsCertType = client, email, objsign
148
149# This is typical in keyUsage for a client certificate.
150# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
151
152# This will be displayed in Netscape's comment listbox.
153nsComment = "OpenSSL Generated Certificate"
154
155# PKIX recommendations harmless if included in all certificates.
156subjectKeyIdentifier=hash
157authorityKeyIdentifier=keyid,issuer:always
158
159# This stuff is for subjectAltName and issuerAltname.
160# Import the email address.
161# subjectAltName=email:copy
162
163# Copy subject details
164# issuerAltName=issuer:copy
165
166#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
167#nsBaseUrl
168#nsRevocationUrl
169#nsRenewalUrl
170#nsCaPolicyUrl
171#nsSslServerName
172
173[ v3_ca]
174
175# Extensions for a typical CA
176
177
178# PKIX recommendation.
179
180subjectKeyIdentifier=hash
181
182authorityKeyIdentifier=keyid:always,issuer:always
183
184# This is what PKIX recommends but some broken software chokes on critical
185# extensions.
186#basicConstraints = critical,CA:true
187# So we do this instead.
188basicConstraints = CA:true
189
190# Key usage: this is typical for a CA certificate. However since it will
191# prevent it being used as an test self-signed certificate it is best
192# left out by default.
193# keyUsage = cRLSign, keyCertSign
194
195# Some might want this also
196# nsCertType = sslCA, emailCA
197
198# Include email address in subject alt name: another PKIX recommendation
199# subjectAltName=email:copy
200# Copy issuer details
201# issuerAltName=issuer:copy
202
203# RAW DER hex encoding of an extension: beware experts only!
204# 1.2.3.5=RAW:02:03
205# You can even override a supported extension:
206# basicConstraints= critical, RAW:30:03:01:01:FF
207
208[ crl_ext ]
209
210# CRL extensions.
211# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
212
213# issuerAltName=issuer:copy
214authorityKeyIdentifier=keyid:always,issuer:always
diff --git a/src/lib/libssl/src/apps/openssl.c b/src/lib/libssl/src/apps/openssl.c
new file mode 100644
index 0000000000..9a337fb316
--- /dev/null
+++ b/src/lib/libssl/src/apps/openssl.c
@@ -0,0 +1,373 @@
1/* apps/openssl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef DEBUG
60#undef DEBUG
61#endif
62
63#include <stdio.h>
64#include <string.h>
65#include <stdlib.h>
66#include <openssl/bio.h>
67#include <openssl/crypto.h>
68#include <openssl/lhash.h>
69#include <openssl/conf.h>
70#include <openssl/x509.h>
71#include <openssl/pem.h>
72#include <openssl/ssl.h>
73#define SSLEAY /* turn off a few special case MONOLITH macros */
74#define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
75#define SSLEAY_SRC
76#include "apps.h"
77#include "s_apps.h"
78#include <openssl/err.h>
79
80/*
81#ifdef WINDOWS
82#include "bss_file.c"
83#endif
84*/
85
86static unsigned long MS_CALLBACK hash(FUNCTION *a);
87static int MS_CALLBACK cmp(FUNCTION *a,FUNCTION *b);
88static LHASH *prog_init(void );
89static int do_cmd(LHASH *prog,int argc,char *argv[]);
90LHASH *config=NULL;
91char *default_config_file=NULL;
92
93#ifdef DEBUG
94static void sig_stop(int i)
95 {
96 char *a=NULL;
97
98 *a='\0';
99 }
100#endif
101
102/* Make sure there is only one when MONOLITH is defined */
103#ifdef MONOLITH
104BIO *bio_err=NULL;
105#endif
106
107int main(int Argc, char *Argv[])
108 {
109 ARGS arg;
110#define PROG_NAME_SIZE 16
111 char pname[PROG_NAME_SIZE];
112 FUNCTION f,*fp;
113 MS_STATIC char *prompt,buf[1024],config_name[256];
114 int n,i,ret=0;
115 int argc;
116 char **argv,*p;
117 LHASH *prog=NULL;
118 long errline;
119
120 arg.data=NULL;
121 arg.count=0;
122
123 /* SSLeay_add_ssl_algorithms(); is called in apps_startup() */
124 apps_startup();
125
126#if defined(DEBUG) && !defined(WINDOWS) && !defined(MSDOS)
127#ifdef SIGBUS
128 signal(SIGBUS,sig_stop);
129#endif
130#ifdef SIGSEGV
131 signal(SIGSEGV,sig_stop);
132#endif
133#endif
134
135 if (bio_err == NULL)
136 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
137 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
138
139 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
140
141 ERR_load_crypto_strings();
142
143 /* Lets load up our environment a little */
144 p=getenv("OPENSSL_CONF");
145 if (p == NULL)
146 p=getenv("SSLEAY_CONF");
147 if (p == NULL)
148 {
149 strcpy(config_name,X509_get_default_cert_area());
150#ifndef VMS
151 strcat(config_name,"/");
152#endif
153 strcat(config_name,OPENSSL_CONF);
154 p=config_name;
155 }
156
157 default_config_file=p;
158
159 config=CONF_load(config,p,&errline);
160 if (config == NULL) ERR_clear_error();
161
162 prog=prog_init();
163
164 /* first check the program name */
165 program_name(Argv[0],pname,PROG_NAME_SIZE);
166
167 f.name=pname;
168 fp=(FUNCTION *)lh_retrieve(prog,(char *)&f);
169 if (fp != NULL)
170 {
171 Argv[0]=pname;
172 ret=fp->func(Argc,Argv);
173 goto end;
174 }
175
176 /* ok, now check that there are not arguments, if there are,
177 * run with them, shifting the ssleay off the front */
178 if (Argc != 1)
179 {
180 Argc--;
181 Argv++;
182 ret=do_cmd(prog,Argc,Argv);
183 if (ret < 0) ret=0;
184 goto end;
185 }
186
187 /* ok, lets enter the old 'OpenSSL>' mode */
188
189 for (;;)
190 {
191 ret=0;
192 p=buf;
193 n=1024;
194 i=0;
195 for (;;)
196 {
197 p[0]='\0';
198 if (i++)
199 prompt=">";
200 else prompt="OpenSSL> ";
201 fputs(prompt,stdout);
202 fflush(stdout);
203 fgets(p,n,stdin);
204 if (p[0] == '\0') goto end;
205 i=strlen(p);
206 if (i <= 1) break;
207 if (p[i-2] != '\\') break;
208 i-=2;
209 p+=i;
210 n-=i;
211 }
212 if (!chopup_args(&arg,buf,&argc,&argv)) break;
213
214 ret=do_cmd(prog,argc,argv);
215 if (ret < 0)
216 {
217 ret=0;
218 goto end;
219 }
220 if (ret != 0)
221 BIO_printf(bio_err,"error in %s\n",argv[0]);
222 (void)BIO_flush(bio_err);
223 }
224 BIO_printf(bio_err,"bad exit\n");
225 ret=1;
226end:
227 if (config != NULL)
228 {
229 CONF_free(config);
230 config=NULL;
231 }
232 if (prog != NULL) lh_free(prog);
233 if (arg.data != NULL) Free(arg.data);
234 ERR_remove_state(0);
235
236 EVP_cleanup();
237 ERR_free_strings();
238
239 CRYPTO_mem_leaks(bio_err);
240 if (bio_err != NULL)
241 {
242 BIO_free(bio_err);
243 bio_err=NULL;
244 }
245 EXIT(ret);
246 }
247
248#define LIST_STANDARD_COMMANDS "list-standard-commands"
249#define LIST_MESSAGE_DIGEST_COMMANDS "list-message-digest-commands"
250#define LIST_CIPHER_COMMANDS "list-cipher-commands"
251
252static int do_cmd(LHASH *prog, int argc, char *argv[])
253 {
254 FUNCTION f,*fp;
255 int i,ret=1,tp,nl;
256
257 if ((argc <= 0) || (argv[0] == NULL))
258 { ret=0; goto end; }
259 f.name=argv[0];
260 fp=(FUNCTION *)lh_retrieve(prog,(char *)&f);
261 if (fp != NULL)
262 {
263 ret=fp->func(argc,argv);
264 }
265 else if ((strcmp(argv[0],"quit") == 0) ||
266 (strcmp(argv[0],"q") == 0) ||
267 (strcmp(argv[0],"exit") == 0) ||
268 (strcmp(argv[0],"bye") == 0))
269 {
270 ret= -1;
271 goto end;
272 }
273 else if ((strcmp(argv[0],LIST_STANDARD_COMMANDS) == 0) ||
274 (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||
275 (strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0))
276 {
277 int list_type;
278 BIO *bio_stdout;
279
280 if (strcmp(argv[0],LIST_STANDARD_COMMANDS) == 0)
281 list_type = FUNC_TYPE_GENERAL;
282 else if (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0)
283 list_type = FUNC_TYPE_MD;
284 else /* strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0 */
285 list_type = FUNC_TYPE_CIPHER;
286 bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE);
287
288 for (fp=functions; fp->name != NULL; fp++)
289 if (fp->type == list_type)
290 BIO_printf(bio_stdout, "%s\n", fp->name);
291 BIO_free(bio_stdout);
292 ret=0;
293 goto end;
294 }
295 else
296 {
297 BIO_printf(bio_err,"openssl:Error: '%s' is an invalid command.\n",
298 argv[0]);
299 BIO_printf(bio_err, "\nStandard commands");
300 i=0;
301 tp=0;
302 for (fp=functions; fp->name != NULL; fp++)
303 {
304 nl=0;
305 if (((i++) % 5) == 0)
306 {
307 BIO_printf(bio_err,"\n");
308 nl=1;
309 }
310 if (fp->type != tp)
311 {
312 tp=fp->type;
313 if (!nl) BIO_printf(bio_err,"\n");
314 if (tp == FUNC_TYPE_MD)
315 {
316 i=1;
317 BIO_printf(bio_err,
318 "\nMessage Digest commands (see the `dgst' command for more details)\n");
319 }
320 else if (tp == FUNC_TYPE_CIPHER)
321 {
322 i=1;
323 BIO_printf(bio_err,"\nCipher commands (see the `enc' command for more details)\n");
324 }
325 }
326 BIO_printf(bio_err,"%-15s",fp->name);
327 }
328 BIO_printf(bio_err,"\n\n");
329 ret=0;
330 }
331end:
332 return(ret);
333 }
334
335static int SortFnByName(const void *_f1,const void *_f2)
336 {
337 const FUNCTION *f1=_f1;
338 const FUNCTION *f2=_f2;
339
340 if(f1->type != f2->type)
341 return f1->type-f2->type;
342 return strcmp(f1->name,f2->name);
343 }
344
345static LHASH *prog_init(void)
346 {
347 LHASH *ret;
348 FUNCTION *f;
349 int i;
350
351 /* Purely so it looks nice when the user hits ? */
352 for(i=0,f=functions ; f->name != NULL ; ++f,++i)
353 ;
354 qsort(functions,i,sizeof *functions,SortFnByName);
355
356 if ((ret=lh_new(hash,cmp)) == NULL) return(NULL);
357
358 for (f=functions; f->name != NULL; f++)
359 lh_insert(ret,(char *)f);
360 return(ret);
361 }
362
363static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b)
364 {
365 return(strncmp(a->name,b->name,8));
366 }
367
368static unsigned long MS_CALLBACK hash(FUNCTION *a)
369 {
370 return(lh_strhash(a->name));
371 }
372
373#undef SSLEAY
diff --git a/src/lib/libssl/src/apps/openssl.cnf b/src/lib/libssl/src/apps/openssl.cnf
new file mode 100644
index 0000000000..d70dd25622
--- /dev/null
+++ b/src/lib/libssl/src/apps/openssl.cnf
@@ -0,0 +1,214 @@
1#
2# OpenSSL example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = $ENV::HOME/.rnd
7oid_file = $ENV::HOME/.oid
8oid_section = new_oids
9
10# To use this configuration file with the "-extfile" option of the
11# "openssl x509" utility, name here the section containing the
12# X.509v3 extensions to use:
13# extensions =
14# (Alternatively, use a configuration file that has only
15# X.509v3 extensions in its main [= default] section.)
16
17[ new_oids ]
18
19# We can add new OIDs in here for use by 'ca' and 'req'.
20# Add a simple OID like this:
21# testoid1=1.2.3.4
22# Or use config file substitution like this:
23# testoid2=${testoid1}.5.6
24
25####################################################################
26[ ca ]
27default_ca = CA_default # The default ca section
28
29####################################################################
30[ CA_default ]
31
32dir = ./demoCA # Where everything is kept
33certs = $dir/certs # Where the issued certs are kept
34crl_dir = $dir/crl # Where the issued crl are kept
35database = $dir/index.txt # database index file.
36new_certs_dir = $dir/newcerts # default place for new certs.
37
38certificate = $dir/cacert.pem # The CA certificate
39serial = $dir/serial # The current serial number
40crl = $dir/crl.pem # The current CRL
41private_key = $dir/private/cakey.pem# The private key
42RANDFILE = $dir/private/.rand # private random number file
43
44x509_extensions = usr_cert # The extentions to add to the cert
45
46# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
47# so this is commented out by default to leave a V1 CRL.
48# crl_extensions = crl_ext
49
50default_days = 365 # how long to certify for
51default_crl_days= 30 # how long before next CRL
52default_md = md5 # which md to use.
53preserve = no # keep passed DN ordering
54
55# A few difference way of specifying how similar the request should look
56# For type CA, the listed attributes must be the same, and the optional
57# and supplied fields are just that :-)
58policy = policy_match
59
60# For the CA policy
61[ policy_match ]
62countryName = match
63stateOrProvinceName = match
64organizationName = match
65organizationalUnitName = optional
66commonName = supplied
67emailAddress = optional
68
69# For the 'anything' policy
70# At this point in time, you must list all acceptable 'object'
71# types.
72[ policy_anything ]
73countryName = optional
74stateOrProvinceName = optional
75localityName = optional
76organizationName = optional
77organizationalUnitName = optional
78commonName = supplied
79emailAddress = optional
80
81####################################################################
82[ req ]
83default_bits = 1024
84default_keyfile = privkey.pem
85distinguished_name = req_distinguished_name
86attributes = req_attributes
87x509_extensions = v3_ca # The extentions to add to the self signed cert
88
89[ req_distinguished_name ]
90countryName = Country Name (2 letter code)
91countryName_default = AU
92countryName_min = 2
93countryName_max = 2
94
95stateOrProvinceName = State or Province Name (full name)
96stateOrProvinceName_default = Some-State
97
98localityName = Locality Name (eg, city)
99
1000.organizationName = Organization Name (eg, company)
1010.organizationName_default = Internet Widgits Pty Ltd
102
103# we can do this but it is not needed normally :-)
104#1.organizationName = Second Organization Name (eg, company)
105#1.organizationName_default = World Wide Web Pty Ltd
106
107organizationalUnitName = Organizational Unit Name (eg, section)
108#organizationalUnitName_default =
109
110commonName = Common Name (eg, YOUR name)
111commonName_max = 64
112
113emailAddress = Email Address
114emailAddress_max = 40
115
116# SET-ex3 = SET extension number 3
117
118[ req_attributes ]
119challengePassword = A challenge password
120challengePassword_min = 4
121challengePassword_max = 20
122
123unstructuredName = An optional company name
124
125[ usr_cert ]
126
127# These extensions are added when 'ca' signs a request.
128
129# This goes against PKIX guidelines but some CAs do it and some software
130# requires this to avoid interpreting an end user certificate as a CA.
131
132basicConstraints=CA:FALSE
133
134# Here are some examples of the usage of nsCertType. If it is omitted
135# the certificate can be used for anything *except* object signing.
136
137# This is OK for an SSL server.
138# nsCertType = server
139
140# For an object signing certificate this would be used.
141# nsCertType = objsign
142
143# For normal client use this is typical
144# nsCertType = client, email
145
146# and for everything including object signing:
147# nsCertType = client, email, objsign
148
149# This is typical in keyUsage for a client certificate.
150# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
151
152# This will be displayed in Netscape's comment listbox.
153nsComment = "OpenSSL Generated Certificate"
154
155# PKIX recommendations harmless if included in all certificates.
156subjectKeyIdentifier=hash
157authorityKeyIdentifier=keyid,issuer:always
158
159# This stuff is for subjectAltName and issuerAltname.
160# Import the email address.
161# subjectAltName=email:copy
162
163# Copy subject details
164# issuerAltName=issuer:copy
165
166#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
167#nsBaseUrl
168#nsRevocationUrl
169#nsRenewalUrl
170#nsCaPolicyUrl
171#nsSslServerName
172
173[ v3_ca ]
174
175# Extensions for a typical CA
176
177
178# PKIX recommendation.
179
180subjectKeyIdentifier=hash
181
182authorityKeyIdentifier=keyid:always,issuer:always
183
184# This is what PKIX recommends but some broken software chokes on critical
185# extensions.
186#basicConstraints = critical,CA:true
187# So we do this instead.
188basicConstraints = CA:true
189
190# Key usage: this is typical for a CA certificate. However since it will
191# prevent it being used as an test self-signed certificate it is best
192# left out by default.
193# keyUsage = cRLSign, keyCertSign
194
195# Some might want this also
196# nsCertType = sslCA, emailCA
197
198# Include email address in subject alt name: another PKIX recommendation
199# subjectAltName=email:copy
200# Copy issuer details
201# issuerAltName=issuer:copy
202
203# RAW DER hex encoding of an extension: beware experts only!
204# 1.2.3.5=RAW:02:03
205# You can even override a supported extension:
206# basicConstraints= critical, RAW:30:03:01:01:FF
207
208[ crl_ext ]
209
210# CRL extensions.
211# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
212
213# issuerAltName=issuer:copy
214authorityKeyIdentifier=keyid:always,issuer:always
diff --git a/src/lib/libssl/src/apps/passwd.c b/src/lib/libssl/src/apps/passwd.c
new file mode 100644
index 0000000000..c7e21d2081
--- /dev/null
+++ b/src/lib/libssl/src/apps/passwd.c
@@ -0,0 +1,475 @@
1/* apps/passwd.c */
2
3#if defined NO_MD5 || defined CHARSET_EBCDIC
4# define NO_APR1
5#endif
6
7#if !defined(NO_DES) || !defined(NO_APR1)
8
9#include <assert.h>
10#include <string.h>
11
12#include "apps.h"
13
14#include <openssl/bio.h>
15#include <openssl/err.h>
16#include <openssl/evp.h>
17#include <openssl/rand.h>
18
19#ifndef NO_DES
20# include <openssl/des.h>
21#endif
22#ifndef NO_APR1
23# include <openssl/md5.h>
24#endif
25
26
27#undef PROG
28#define PROG passwd_main
29
30
31static unsigned const char cov_2char[64]={
32 /* from crypto/des/fcrypt.c */
33 0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
34 0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
35 0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
36 0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
37 0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
38 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
39 0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
40 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
41};
42
43static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
44 char *passwd, BIO *out, int quiet, int table, int reverse,
45 size_t pw_maxlen, int usecrypt, int useapr1);
46
47/* -crypt - standard Unix password algorithm (default, only choice)
48 * -apr1 - MD5-based password algorithm
49 * -salt string - salt
50 * -in file - read passwords from file
51 * -stdin - read passwords from stdin
52 * -quiet - no warnings
53 * -table - format output as table
54 * -reverse - switch table columns
55 */
56
57int MAIN(int, char **);
58
59int MAIN(int argc, char **argv)
60 {
61 int ret = 1;
62 char *infile = NULL;
63 int in_stdin = 0;
64 char *salt = NULL, *passwd = NULL, **passwds = NULL;
65 char *salt_malloc = NULL, *passwd_malloc = NULL;
66 int pw_source_defined = 0;
67 BIO *in = NULL, *out = NULL;
68 int i, badopt, opt_done;
69 int passed_salt = 0, quiet = 0, table = 0, reverse = 0;
70 int usecrypt = 0, useapr1 = 0;
71 size_t pw_maxlen = 0;
72
73 apps_startup();
74
75 if (bio_err == NULL)
76 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
77 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
78 out = BIO_new(BIO_s_file());
79 if (out == NULL)
80 goto err;
81 BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
82
83 badopt = 0, opt_done = 0;
84 i = 0;
85 while (!badopt && !opt_done && argv[++i] != NULL)
86 {
87 if (strcmp(argv[i], "-crypt") == 0)
88 usecrypt = 1;
89 else if (strcmp(argv[i], "-apr1") == 0)
90 useapr1 = 1;
91 else if (strcmp(argv[i], "-salt") == 0)
92 {
93 if ((argv[i+1] != NULL) && (salt == NULL))
94 {
95 passed_salt = 1;
96 salt = argv[++i];
97 }
98 else
99 badopt = 1;
100 }
101 else if (strcmp(argv[i], "-in") == 0)
102 {
103 if ((argv[i+1] != NULL) && !pw_source_defined)
104 {
105 pw_source_defined = 1;
106 infile = argv[++i];
107 }
108 else
109 badopt = 1;
110 }
111 else if (strcmp(argv[i], "-stdin") == 0)
112 {
113 if (!pw_source_defined)
114 {
115 pw_source_defined = 1;
116 in_stdin = 1;
117 }
118 else
119 badopt = 1;
120 }
121 else if (strcmp(argv[i], "-quiet") == 0)
122 quiet = 1;
123 else if (strcmp(argv[i], "-table") == 0)
124 table = 1;
125 else if (strcmp(argv[i], "-reverse") == 0)
126 reverse = 1;
127 else if (argv[i][0] == '-')
128 badopt = 1;
129 else if (!pw_source_defined)
130 /* non-option arguments, use as passwords */
131 {
132 pw_source_defined = 1;
133 passwds = &argv[i];
134 opt_done = 1;
135 }
136 else
137 badopt = 1;
138 }
139
140 if (!usecrypt && !useapr1) /* use default */
141 usecrypt = 1;
142 if (usecrypt + useapr1 > 1) /* conflict */
143 badopt = 1;
144
145 /* reject unsupported algorithms */
146#ifdef NO_DES
147 if (usecrypt) badopt = 1;
148#endif
149#ifdef NO_APR1
150 if (useapr1) badopt = 1;
151#endif
152
153 if (badopt)
154 {
155 BIO_printf(bio_err, "Usage: passwd [options] [passwords]\n");
156 BIO_printf(bio_err, "where options are\n");
157#ifndef NO_DES
158 BIO_printf(bio_err, "-crypt standard Unix password algorithm (default)\n");
159#endif
160#ifndef NO_APR1
161 BIO_printf(bio_err, "-apr1 MD5-based password algorithm\n");
162#endif
163 BIO_printf(bio_err, "-salt string use provided salt\n");
164 BIO_printf(bio_err, "-in file read passwords from file\n");
165 BIO_printf(bio_err, "-stdin read passwords from stdin\n");
166 BIO_printf(bio_err, "-quiet no warnings\n");
167 BIO_printf(bio_err, "-table format output as table\n");
168 BIO_printf(bio_err, "-reverse switch table columns\n");
169
170 goto err;
171 }
172
173 if ((infile != NULL) || in_stdin)
174 {
175 in = BIO_new(BIO_s_file());
176 if (in == NULL)
177 goto err;
178 if (infile != NULL)
179 {
180 assert(in_stdin == 0);
181 if (BIO_read_filename(in, infile) <= 0)
182 goto err;
183 }
184 else
185 {
186 assert(in_stdin);
187 BIO_set_fp(in, stdin, BIO_NOCLOSE);
188 }
189 }
190
191 if (usecrypt)
192 pw_maxlen = 8;
193 else if (useapr1)
194 pw_maxlen = 256; /* arbitrary limit, should be enough for most passwords */
195
196 if (passwds == NULL)
197 {
198 /* no passwords on the command line */
199 passwd = passwd_malloc = Malloc(pw_maxlen + 1);
200 if (passwd_malloc == NULL)
201 goto err;
202 }
203
204 if ((in == NULL) && (passwds == NULL))
205 {
206 /* build a null-terminated list */
207 static char *passwds_static[2] = {NULL, NULL};
208
209 passwds = passwds_static;
210 if (in == NULL)
211 if (EVP_read_pw_string(passwd_malloc, pw_maxlen + 1, "Password: ", 0) != 0)
212 goto err;
213 passwds[0] = passwd_malloc;
214 }
215
216 if (in == NULL)
217 {
218 assert(passwds != NULL);
219 assert(*passwds != NULL);
220
221 do /* loop over list of passwords */
222 {
223 passwd = *passwds++;
224 if (!do_passwd(passed_salt, &salt, &salt_malloc, passwd, out,
225 quiet, table, reverse, pw_maxlen, usecrypt, useapr1))
226 goto err;
227 }
228 while (*passwds != NULL);
229 }
230 else
231 /* in != NULL */
232 {
233 int done;
234
235 assert (passwd != NULL);
236 do
237 {
238 int r = BIO_gets(in, passwd, pw_maxlen + 1);
239 if (r > 0)
240 {
241 char *c = (strchr(passwd, '\n')) ;
242 if (c != NULL)
243 *c = 0; /* truncate at newline */
244 else
245 {
246 /* ignore rest of line */
247 char trash[BUFSIZ];
248 do
249 r = BIO_gets(in, trash, sizeof trash);
250 while ((r > 0) && (!strchr(trash, '\n')));
251 }
252
253 if (!do_passwd(passed_salt, &salt, &salt_malloc, passwd, out,
254 quiet, table, reverse, pw_maxlen, usecrypt, useapr1))
255 goto err;
256 }
257 done = (r <= 0);
258 }
259 while (!done);
260 }
261
262err:
263 ERR_print_errors(bio_err);
264 if (salt_malloc)
265 Free(salt_malloc);
266 if (passwd_malloc)
267 Free(passwd_malloc);
268 if (in)
269 BIO_free(in);
270 if (out)
271 BIO_free(out);
272 EXIT(ret);
273 }
274
275
276#ifndef NO_APR1
277/* MD5-based password algorithm compatible to the one found in Apache
278 * (should probably be available as a library function;
279 * then the static buffer would not be acceptable) */
280static char *apr1_crypt(const char *passwd, const char *salt)
281 {
282 static char out_buf[6 + 9 + 24 + 2]; /* "$apr1$..salt..$.......md5hash..........\0" */
283 unsigned char buf[MD5_DIGEST_LENGTH];
284 char *salt_out;
285 int n, i;
286 MD5_CTX md;
287 size_t passwd_len, salt_len;
288
289 passwd_len = strlen(passwd);
290 strcpy(out_buf, "$apr1$");
291 strncat(out_buf, salt, 8);
292 assert(strlen(out_buf) <= 6 + 8); /* "$apr1$..salt.." */
293 salt_out = out_buf + 6;
294 salt_len = strlen(salt_out);
295 assert(salt_len <= 8);
296
297 MD5_Init(&md);
298 MD5_Update(&md, passwd, passwd_len);
299 MD5_Update(&md, "$apr1$", 6);
300 MD5_Update(&md, salt_out, salt_len);
301
302 {
303 MD5_CTX md2;
304
305 MD5_Init(&md2);
306 MD5_Update(&md2, passwd, passwd_len);
307 MD5_Update(&md2, salt_out, salt_len);
308 MD5_Update(&md2, passwd, passwd_len);
309 MD5_Final(buf, &md2);
310 }
311 for (i = passwd_len; i > sizeof buf; i -= sizeof buf)
312 MD5_Update(&md, buf, sizeof buf);
313 MD5_Update(&md, buf, i);
314
315 n = passwd_len;
316 while (n)
317 {
318 MD5_Update(&md, (n & 1) ? "\0" : passwd, 1);
319 n >>= 1;
320 }
321 MD5_Final(buf, &md);
322
323 for (i = 0; i < 1000; i++)
324 {
325 MD5_CTX md2;
326
327 MD5_Init(&md2);
328 MD5_Update(&md2, (i & 1) ? (unsigned char *) passwd : buf,
329 (i & 1) ? passwd_len : sizeof buf);
330 if (i % 3)
331 MD5_Update(&md2, salt_out, salt_len);
332 if (i % 7)
333 MD5_Update(&md2, passwd, passwd_len);
334 MD5_Update(&md2, (i & 1) ? buf : (unsigned char *) passwd,
335 (i & 1) ? sizeof buf : passwd_len);
336 MD5_Final(buf, &md2);
337 }
338
339 {
340 /* transform buf into output string */
341
342 unsigned char buf_perm[sizeof buf];
343 int dest, source;
344 char *output;
345
346 /* silly output permutation */
347 for (dest = 0, source = 0; dest < 14; dest++, source = (source + 6) % 17)
348 buf_perm[dest] = buf[source];
349 buf_perm[14] = buf[5];
350 buf_perm[15] = buf[11];
351#ifndef PEDANTIC /* Unfortunately, this generates a "no effect" warning */
352 assert(16 == sizeof buf_perm);
353#endif
354
355 output = salt_out + salt_len;
356 assert(output == out_buf + strlen(out_buf));
357
358 *output++ = '$';
359
360 for (i = 0; i < 15; i += 3)
361 {
362 *output++ = cov_2char[buf_perm[i+2] & 0x3f];
363 *output++ = cov_2char[((buf_perm[i+1] & 0xf) << 2) |
364 (buf_perm[i+2] >> 6)];
365 *output++ = cov_2char[((buf_perm[i] & 3) << 4) |
366 (buf_perm[i+1] >> 4)];
367 *output++ = cov_2char[buf_perm[i] >> 2];
368 }
369 assert(i == 15);
370 *output++ = cov_2char[buf_perm[i] & 0x3f];
371 *output++ = cov_2char[buf_perm[i] >> 6];
372 *output = 0;
373 assert(strlen(out_buf) < sizeof(out_buf));
374 }
375
376 return out_buf;
377 }
378#endif
379
380
381static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
382 char *passwd, BIO *out, int quiet, int table, int reverse,
383 size_t pw_maxlen, int usecrypt, int useapr1)
384 {
385 char *hash = NULL;
386
387 assert(salt_p != NULL);
388 assert(salt_malloc_p != NULL);
389
390 /* first make sure we have a salt */
391 if (!passed_salt)
392 {
393#ifndef NO_DES
394 if (usecrypt)
395 {
396 if (*salt_malloc_p == NULL)
397 {
398 *salt_p = *salt_malloc_p = Malloc(3);
399 if (*salt_malloc_p == NULL)
400 goto err;
401 }
402 if (RAND_pseudo_bytes((unsigned char *)*salt_p, 2) < 0)
403 goto err;
404 (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */
405 (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f]; /* 6 bits */
406 (*salt_p)[2] = 0;
407#ifdef CHARSET_EBCDIC
408 ascii2ebcdic(*salt_p, *salt_p, 2); /* des_crypt will convert
409 * back to ASCII */
410#endif
411 }
412#endif /* !NO_DES */
413
414#ifndef NO_APR1
415 if (useapr1)
416 {
417 int i;
418
419 if (*salt_malloc_p == NULL)
420 {
421 *salt_p = *salt_malloc_p = Malloc(9);
422 if (*salt_malloc_p == NULL)
423 goto err;
424 }
425 if (RAND_pseudo_bytes((unsigned char *)*salt_p, 8) < 0)
426 goto err;
427
428 for (i = 0; i < 8; i++)
429 (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f]; /* 6 bits */
430 (*salt_p)[8] = 0;
431 }
432#endif /* !NO_APR1 */
433 }
434
435 assert(*salt_p != NULL);
436
437 /* truncate password if necessary */
438 if ((strlen(passwd) > pw_maxlen))
439 {
440 if (!quiet)
441 BIO_printf(bio_err, "Warning: truncating password to %u characters\n", pw_maxlen);
442 passwd[pw_maxlen] = 0;
443 }
444 assert(strlen(passwd) <= pw_maxlen);
445
446 /* now compute password hash */
447#ifndef NO_DES
448 if (usecrypt)
449 hash = des_crypt(passwd, *salt_p);
450#endif
451#ifndef NO_APR1
452 if (useapr1)
453 hash = apr1_crypt(passwd, *salt_p);
454#endif
455 assert(hash != NULL);
456
457 if (table && !reverse)
458 BIO_printf(out, "%s\t%s\n", passwd, hash);
459 else if (table && reverse)
460 BIO_printf(out, "%s\t%s\n", hash, passwd);
461 else
462 BIO_printf(out, "%s\n", hash);
463 return 1;
464
465err:
466 return 0;
467 }
468#else
469
470int MAIN(int argc, char **argv)
471 {
472 fputs("Program not available.\n", stderr)
473 EXIT(1);
474 }
475#endif
diff --git a/src/lib/libssl/src/apps/pkcs12.c b/src/lib/libssl/src/apps/pkcs12.c
new file mode 100644
index 0000000000..5defddeb32
--- /dev/null
+++ b/src/lib/libssl/src/apps/pkcs12.c
@@ -0,0 +1,703 @@
1/* pkcs12.c */
2#if !defined(NO_DES) && !defined(NO_SHA1)
3
4/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
5 * project 1999.
6 */
7/* ====================================================================
8 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * licensing@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64#include <openssl/des.h>
65#include <openssl/pem.h>
66#include <openssl/err.h>
67#include <openssl/pkcs12.h>
68
69#include "apps.h"
70#define PROG pkcs12_main
71
72EVP_CIPHER *enc;
73
74
75#define NOKEYS 0x1
76#define NOCERTS 0x2
77#define INFO 0x4
78#define CLCERTS 0x8
79#define CACERTS 0x10
80
81int get_cert_chain(X509 *cert, STACK_OF(X509) **chain);
82int dump_cert_text (BIO *out, X509 *x);
83int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen, int options);
84int dump_certs_pkeys_bags(BIO *out, STACK *bags, char *pass, int passlen, int options);
85int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bags, char *pass, int passlen, int options);
86int print_attribs(BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst, char *name);
87void hex_prin(BIO *out, unsigned char *buf, int len);
88int alg_print(BIO *x, X509_ALGOR *alg);
89int cert_load(BIO *in, STACK_OF(X509) *sk);
90int MAIN(int argc, char **argv)
91{
92 char *infile=NULL, *outfile=NULL, *keyname = NULL;
93 char *certfile=NULL;
94 BIO *in=NULL, *out = NULL, *inkey = NULL, *certsin = NULL;
95 char **args;
96 char *name = NULL;
97 PKCS12 *p12 = NULL;
98 char pass[50], macpass[50];
99 int export_cert = 0;
100 int options = 0;
101 int chain = 0;
102 int badarg = 0;
103 int iter = PKCS12_DEFAULT_ITER;
104 int maciter = 1;
105 int twopass = 0;
106 int keytype = 0;
107 int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
108 int ret = 1;
109 int macver = 1;
110 int noprompt = 0;
111 STACK *canames = NULL;
112 char *cpass = NULL, *mpass = NULL;
113
114 apps_startup();
115
116 enc = EVP_des_ede3_cbc();
117 if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
118
119 args = argv + 1;
120
121
122 while (*args) {
123 if (*args[0] == '-') {
124 if (!strcmp (*args, "-nokeys")) options |= NOKEYS;
125 else if (!strcmp (*args, "-keyex")) keytype = KEY_EX;
126 else if (!strcmp (*args, "-keysig")) keytype = KEY_SIG;
127 else if (!strcmp (*args, "-nocerts")) options |= NOCERTS;
128 else if (!strcmp (*args, "-clcerts")) options |= CLCERTS;
129 else if (!strcmp (*args, "-cacerts")) options |= CACERTS;
130 else if (!strcmp (*args, "-noout")) options |= (NOKEYS|NOCERTS);
131 else if (!strcmp (*args, "-info")) options |= INFO;
132 else if (!strcmp (*args, "-chain")) chain = 1;
133 else if (!strcmp (*args, "-twopass")) twopass = 1;
134 else if (!strcmp (*args, "-nomacver")) macver = 0;
135 else if (!strcmp (*args, "-descert"))
136 cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
137 else if (!strcmp (*args, "-export")) export_cert = 1;
138 else if (!strcmp (*args, "-des")) enc=EVP_des_cbc();
139#ifndef NO_IDEA
140 else if (!strcmp (*args, "-idea")) enc=EVP_idea_cbc();
141#endif
142 else if (!strcmp (*args, "-des3")) enc = EVP_des_ede3_cbc();
143 else if (!strcmp (*args, "-noiter")) iter = 1;
144 else if (!strcmp (*args, "-maciter"))
145 maciter = PKCS12_DEFAULT_ITER;
146 else if (!strcmp (*args, "-nodes")) enc=NULL;
147 else if (!strcmp (*args, "-inkey")) {
148 if (args[1]) {
149 args++;
150 keyname = *args;
151 } else badarg = 1;
152 } else if (!strcmp (*args, "-certfile")) {
153 if (args[1]) {
154 args++;
155 certfile = *args;
156 } else badarg = 1;
157 } else if (!strcmp (*args, "-name")) {
158 if (args[1]) {
159 args++;
160 name = *args;
161 } else badarg = 1;
162 } else if (!strcmp (*args, "-caname")) {
163 if (args[1]) {
164 args++;
165 if (!canames) canames = sk_new(NULL);
166 sk_push(canames, *args);
167 } else badarg = 1;
168 } else if (!strcmp (*args, "-in")) {
169 if (args[1]) {
170 args++;
171 infile = *args;
172 } else badarg = 1;
173 } else if (!strcmp (*args, "-out")) {
174 if (args[1]) {
175 args++;
176 outfile = *args;
177 } else badarg = 1;
178 } else if (!strcmp (*args, "-envpass")) {
179 if (args[1]) {
180 args++;
181 if(!(cpass = getenv(*args))) {
182 BIO_printf(bio_err,
183 "Can't read environment variable %s\n", *args);
184 goto end;
185 }
186 noprompt = 1;
187 } else badarg = 1;
188 } else if (!strcmp (*args, "-password")) {
189 if (args[1]) {
190 args++;
191 cpass = *args;
192 noprompt = 1;
193 } else badarg = 1;
194 } else badarg = 1;
195
196 } else badarg = 1;
197 args++;
198 }
199
200 if (badarg) {
201 BIO_printf (bio_err, "Usage: pkcs12 [options]\n");
202 BIO_printf (bio_err, "where options are\n");
203 BIO_printf (bio_err, "-export output PKCS12 file\n");
204 BIO_printf (bio_err, "-chain add certificate chain\n");
205 BIO_printf (bio_err, "-inkey file private key if not infile\n");
206 BIO_printf (bio_err, "-certfile f add all certs in f\n");
207 BIO_printf (bio_err, "-name \"name\" use name as friendly name\n");
208 BIO_printf (bio_err, "-caname \"nm\" use nm as CA friendly name (can be used more than once).\n");
209 BIO_printf (bio_err, "-in infile input filename\n");
210 BIO_printf (bio_err, "-out outfile output filename\n");
211 BIO_printf (bio_err, "-noout don't output anything, just verify.\n");
212 BIO_printf (bio_err, "-nomacver don't verify MAC.\n");
213 BIO_printf (bio_err, "-nocerts don't output certificates.\n");
214 BIO_printf (bio_err, "-clcerts only output client certificates.\n");
215 BIO_printf (bio_err, "-cacerts only output CA certificates.\n");
216 BIO_printf (bio_err, "-nokeys don't output private keys.\n");
217 BIO_printf (bio_err, "-info give info about PKCS#12 structure.\n");
218 BIO_printf (bio_err, "-des encrypt private keys with DES\n");
219 BIO_printf (bio_err, "-des3 encrypt private keys with triple DES (default)\n");
220#ifndef NO_IDEA
221 BIO_printf (bio_err, "-idea encrypt private keys with idea\n");
222#endif
223 BIO_printf (bio_err, "-nodes don't encrypt private keys\n");
224 BIO_printf (bio_err, "-noiter don't use encryption iteration\n");
225 BIO_printf (bio_err, "-maciter use MAC iteration\n");
226 BIO_printf (bio_err, "-twopass separate MAC, encryption passwords\n");
227 BIO_printf (bio_err, "-descert encrypt PKCS#12 certificates with triple DES (default RC2-40)\n");
228 BIO_printf (bio_err, "-keyex set MS key exchange type\n");
229 BIO_printf (bio_err, "-keysig set MS key signature type\n");
230 BIO_printf (bio_err, "-password p set import/export password (NOT RECOMMENDED)\n");
231 BIO_printf (bio_err, "-envpass p set import/export password from environment\n");
232 goto end;
233 }
234
235 if(cpass) mpass = cpass;
236 else {
237 cpass = pass;
238 mpass = macpass;
239 }
240
241 ERR_load_crypto_strings();
242
243 if (!infile) in = BIO_new_fp(stdin, BIO_NOCLOSE);
244 else in = BIO_new_file(infile, "rb");
245 if (!in) {
246 BIO_printf(bio_err, "Error opening input file %s\n",
247 infile ? infile : "<stdin>");
248 perror (infile);
249 goto end;
250 }
251
252 if (certfile) {
253 if(!(certsin = BIO_new_file(certfile, "r"))) {
254 BIO_printf(bio_err, "Can't open certificate file %s\n", certfile);
255 perror (certfile);
256 goto end;
257 }
258 }
259
260 if (keyname) {
261 if(!(inkey = BIO_new_file(keyname, "r"))) {
262 BIO_printf(bio_err, "Can't key certificate file %s\n", keyname);
263 perror (keyname);
264 goto end;
265 }
266 }
267
268 if (!outfile) out = BIO_new_fp(stdout, BIO_NOCLOSE);
269 else out = BIO_new_file(outfile, "wb");
270 if (!out) {
271 BIO_printf(bio_err, "Error opening output file %s\n",
272 outfile ? outfile : "<stdout>");
273 perror (outfile);
274 goto end;
275 }
276 if (twopass) {
277 if(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert))
278 {
279 BIO_printf (bio_err, "Can't read Password\n");
280 goto end;
281 }
282 }
283
284if (export_cert) {
285 EVP_PKEY *key;
286 STACK *bags, *safes;
287 PKCS12_SAFEBAG *bag;
288 PKCS8_PRIV_KEY_INFO *p8;
289 PKCS7 *authsafe;
290 X509 *cert = NULL, *ucert = NULL;
291 STACK_OF(X509) *certs;
292 char *catmp;
293 int i;
294 unsigned char keyid[EVP_MAX_MD_SIZE];
295 unsigned int keyidlen = 0;
296 key = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL, NULL);
297 if (!inkey) (void) BIO_reset(in);
298 if (!key) {
299 BIO_printf (bio_err, "Error loading private key\n");
300 ERR_print_errors(bio_err);
301 goto end;
302 }
303
304 certs = sk_X509_new(NULL);
305
306 /* Load in all certs in input file */
307 if(!cert_load(in, certs)) {
308 BIO_printf(bio_err, "Error loading certificates from input\n");
309 ERR_print_errors(bio_err);
310 goto end;
311 }
312
313 for(i = 0; i < sk_X509_num(certs); i++) {
314 ucert = sk_X509_value(certs, i);
315 if(X509_check_private_key(ucert, key)) {
316 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
317 break;
318 }
319 }
320
321 if(!keyidlen) {
322 BIO_printf(bio_err, "No certificate matches private key\n");
323 goto end;
324 }
325
326 bags = sk_new (NULL);
327
328 /* Add any more certificates asked for */
329 if (certsin) {
330 if(!cert_load(certsin, certs)) {
331 BIO_printf(bio_err, "Error loading certificates from certfile\n");
332 ERR_print_errors(bio_err);
333 goto end;
334 }
335 BIO_free(certsin);
336 }
337
338 /* If chaining get chain from user cert */
339 if (chain) {
340 int vret;
341 STACK_OF(X509) *chain2;
342 vret = get_cert_chain (ucert, &chain2);
343 if (vret) {
344 BIO_printf (bio_err, "Error %s getting chain.\n",
345 X509_verify_cert_error_string(vret));
346 goto end;
347 }
348 /* Exclude verified certificate */
349 for (i = 1; i < sk_X509_num (chain2) ; i++)
350 sk_X509_push(certs, sk_X509_value (chain2, i));
351 sk_X509_free(chain2);
352
353 }
354
355 /* We now have loads of certificates: include them all */
356 for(i = 0; i < sk_X509_num(certs); i++) {
357 cert = sk_X509_value(certs, i);
358 bag = M_PKCS12_x5092certbag(cert);
359 /* If it matches private key set id */
360 if(cert == ucert) {
361 if(name) PKCS12_add_friendlyname(bag, name, -1);
362 PKCS12_add_localkeyid(bag, keyid, keyidlen);
363 } else if((catmp = sk_shift(canames)))
364 PKCS12_add_friendlyname(bag, catmp, -1);
365 sk_push(bags, (char *)bag);
366 }
367
368 if (canames) sk_free(canames);
369
370 if(!noprompt &&
371 EVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {
372 BIO_printf (bio_err, "Can't read Password\n");
373 goto end;
374 }
375 if (!twopass) strcpy(macpass, pass);
376 /* Turn certbags into encrypted authsafe */
377 authsafe = PKCS12_pack_p7encdata(cert_pbe, cpass, -1, NULL, 0,
378 iter, bags);
379 sk_pop_free(bags, PKCS12_SAFEBAG_free);
380
381 if (!authsafe) {
382 ERR_print_errors (bio_err);
383 goto end;
384 }
385
386 safes = sk_new (NULL);
387 sk_push (safes, (char *)authsafe);
388
389 /* Make a shrouded key bag */
390 p8 = EVP_PKEY2PKCS8 (key);
391 EVP_PKEY_free(key);
392 if(keytype) PKCS8_add_keyusage(p8, keytype);
393 bag = PKCS12_MAKE_SHKEYBAG(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
394 cpass, -1, NULL, 0, iter, p8);
395 PKCS8_PRIV_KEY_INFO_free(p8);
396 if (name) PKCS12_add_friendlyname (bag, name, -1);
397 PKCS12_add_localkeyid (bag, keyid, keyidlen);
398 bags = sk_new(NULL);
399 sk_push (bags, (char *)bag);
400 /* Turn it into unencrypted safe bag */
401 authsafe = PKCS12_pack_p7data (bags);
402 sk_pop_free(bags, PKCS12_SAFEBAG_free);
403 sk_push (safes, (char *)authsafe);
404
405 p12 = PKCS12_init (NID_pkcs7_data);
406
407 M_PKCS12_pack_authsafes (p12, safes);
408
409 sk_pop_free(safes, PKCS7_free);
410
411 PKCS12_set_mac (p12, mpass, -1, NULL, 0, maciter, NULL);
412
413 i2d_PKCS12_bio (out, p12);
414
415 PKCS12_free(p12);
416
417 ret = 0;
418 goto end;
419
420 }
421
422 if (!(p12 = d2i_PKCS12_bio (in, NULL))) {
423 ERR_print_errors(bio_err);
424 goto end;
425 }
426
427 if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) {
428 BIO_printf (bio_err, "Can't read Password\n");
429 goto end;
430 }
431
432 if (!twopass) strcpy(macpass, pass);
433
434 if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);
435 if(macver) {
436 if (!PKCS12_verify_mac (p12, mpass, -1)) {
437 BIO_printf (bio_err, "Mac verify errror: invalid password?\n");
438 ERR_print_errors (bio_err);
439 goto end;
440 } else BIO_printf (bio_err, "MAC verified OK\n");
441 }
442
443 if (!dump_certs_keys_p12 (out, p12, cpass, -1, options)) {
444 BIO_printf(bio_err, "Error outputting keys and certificates\n");
445 ERR_print_errors (bio_err);
446 goto end;
447 }
448 PKCS12_free(p12);
449 ret = 0;
450 end:
451 BIO_free(out);
452 EXIT(ret);
453}
454
455int dump_cert_text (BIO *out, X509 *x)
456{
457 char buf[256];
458 X509_NAME_oneline(X509_get_subject_name(x),buf,256);
459 BIO_puts(out,"subject=");
460 BIO_puts(out,buf);
461
462 X509_NAME_oneline(X509_get_issuer_name(x),buf,256);
463 BIO_puts(out,"\nissuer= ");
464 BIO_puts(out,buf);
465 BIO_puts(out,"\n");
466 return 0;
467}
468
469int dump_certs_keys_p12 (BIO *out, PKCS12 *p12, char *pass,
470 int passlen, int options)
471{
472 STACK *asafes, *bags;
473 int i, bagnid;
474 PKCS7 *p7;
475 if (!( asafes = M_PKCS12_unpack_authsafes (p12))) return 0;
476 for (i = 0; i < sk_num (asafes); i++) {
477 p7 = (PKCS7 *) sk_value (asafes, i);
478 bagnid = OBJ_obj2nid (p7->type);
479 if (bagnid == NID_pkcs7_data) {
480 bags = M_PKCS12_unpack_p7data (p7);
481 if (options & INFO) BIO_printf (bio_err, "PKCS7 Data\n");
482 } else if (bagnid == NID_pkcs7_encrypted) {
483 if (options & INFO) {
484 BIO_printf (bio_err, "PKCS7 Encrypted data: ");
485 alg_print (bio_err,
486 p7->d.encrypted->enc_data->algorithm);
487 }
488 bags = M_PKCS12_unpack_p7encdata (p7, pass, passlen);
489 } else continue;
490 if (!bags) return 0;
491 if (!dump_certs_pkeys_bags (out, bags, pass, passlen,
492 options)) {
493 sk_pop_free (bags, PKCS12_SAFEBAG_free);
494 return 0;
495 }
496 sk_pop_free (bags, PKCS12_SAFEBAG_free);
497 }
498 sk_pop_free (asafes, PKCS7_free);
499 return 1;
500}
501
502int dump_certs_pkeys_bags (BIO *out, STACK *bags, char *pass,
503 int passlen, int options)
504{
505 int i;
506 for (i = 0; i < sk_num (bags); i++) {
507 if (!dump_certs_pkeys_bag (out,
508 (PKCS12_SAFEBAG *)sk_value (bags, i), pass, passlen,
509 options)) return 0;
510 }
511 return 1;
512}
513
514int dump_certs_pkeys_bag (BIO *out, PKCS12_SAFEBAG *bag, char *pass,
515 int passlen, int options)
516{
517 EVP_PKEY *pkey;
518 PKCS8_PRIV_KEY_INFO *p8;
519 X509 *x509;
520
521 switch (M_PKCS12_bag_type(bag))
522 {
523 case NID_keyBag:
524 if (options & INFO) BIO_printf (bio_err, "Key bag\n");
525 if (options & NOKEYS) return 1;
526 print_attribs (out, bag->attrib, "Bag Attributes");
527 p8 = bag->value.keybag;
528 if (!(pkey = EVP_PKCS82PKEY (p8))) return 0;
529 print_attribs (out, p8->attributes, "Key Attributes");
530 PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, NULL);
531 EVP_PKEY_free(pkey);
532 break;
533
534 case NID_pkcs8ShroudedKeyBag:
535 if (options & INFO) {
536 BIO_printf (bio_err, "Shrouded Keybag: ");
537 alg_print (bio_err, bag->value.shkeybag->algor);
538 }
539 if (options & NOKEYS) return 1;
540 print_attribs (out, bag->attrib, "Bag Attributes");
541 if (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen)))
542 return 0;
543 if (!(pkey = EVP_PKCS82PKEY (p8))) return 0;
544 print_attribs (out, p8->attributes, "Key Attributes");
545 PKCS8_PRIV_KEY_INFO_free(p8);
546 PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, NULL);
547 EVP_PKEY_free(pkey);
548 break;
549
550 case NID_certBag:
551 if (options & INFO) BIO_printf (bio_err, "Certificate bag\n");
552 if (options & NOCERTS) return 1;
553 if (PKCS12_get_attr(bag, NID_localKeyID)) {
554 if (options & CACERTS) return 1;
555 } else if (options & CLCERTS) return 1;
556 print_attribs (out, bag->attrib, "Bag Attributes");
557 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
558 return 1;
559 if (!(x509 = M_PKCS12_certbag2x509(bag))) return 0;
560 dump_cert_text (out, x509);
561 PEM_write_bio_X509 (out, x509);
562 X509_free(x509);
563 break;
564
565 case NID_safeContentsBag:
566 if (options & INFO) BIO_printf (bio_err, "Safe Contents bag\n");
567 print_attribs (out, bag->attrib, "Bag Attributes");
568 return dump_certs_pkeys_bags (out, bag->value.safes, pass,
569 passlen, options);
570
571 default:
572 BIO_printf (bio_err, "Warning unsupported bag type: ");
573 i2a_ASN1_OBJECT (bio_err, bag->type);
574 BIO_printf (bio_err, "\n");
575 return 1;
576 break;
577 }
578 return 1;
579}
580
581/* Given a single certificate return a verified chain or NULL if error */
582
583/* Hope this is OK .... */
584
585int get_cert_chain (X509 *cert, STACK_OF(X509) **chain)
586{
587 X509_STORE *store;
588 X509_STORE_CTX store_ctx;
589 STACK_OF(X509) *chn;
590 int i;
591 X509 *x;
592 store = X509_STORE_new ();
593 X509_STORE_set_default_paths (store);
594 X509_STORE_CTX_init(&store_ctx, store, cert, NULL);
595 if (X509_verify_cert(&store_ctx) <= 0) {
596 i = X509_STORE_CTX_get_error (&store_ctx);
597 goto err;
598 }
599 chn = sk_X509_dup(X509_STORE_CTX_get_chain (&store_ctx));
600 for (i = 0; i < sk_X509_num(chn); i++) {
601 x = sk_X509_value(chn, i);
602 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
603 }
604 i = 0;
605 *chain = chn;
606err:
607 X509_STORE_CTX_cleanup(&store_ctx);
608 X509_STORE_free(store);
609
610 return i;
611}
612
613int alg_print (BIO *x, X509_ALGOR *alg)
614{
615 PBEPARAM *pbe;
616 unsigned char *p;
617 p = alg->parameter->value.sequence->data;
618 pbe = d2i_PBEPARAM (NULL, &p, alg->parameter->value.sequence->length);
619 BIO_printf (bio_err, "%s, Iteration %d\n",
620 OBJ_nid2ln(OBJ_obj2nid(alg->algorithm)), ASN1_INTEGER_get(pbe->iter));
621 PBEPARAM_free (pbe);
622 return 0;
623}
624
625/* Load all certificates from a given file */
626
627int cert_load(BIO *in, STACK_OF(X509) *sk)
628{
629 int ret;
630 X509 *cert;
631 ret = 0;
632 while((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
633 ret = 1;
634 sk_X509_push(sk, cert);
635 }
636 if(ret) ERR_clear_error();
637 return ret;
638}
639
640/* Generalised attribute print: handle PKCS#8 and bag attributes */
641
642int print_attribs (BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst, char *name)
643{
644 X509_ATTRIBUTE *attr;
645 ASN1_TYPE *av;
646 char *value;
647 int i, attr_nid;
648 if(!attrlst) {
649 BIO_printf(out, "%s: <No Attributes>\n", name);
650 return 1;
651 }
652 if(!sk_X509_ATTRIBUTE_num(attrlst)) {
653 BIO_printf(out, "%s: <Empty Attributes>\n", name);
654 return 1;
655 }
656 BIO_printf(out, "%s\n", name);
657 for(i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
658 attr = sk_X509_ATTRIBUTE_value(attrlst, i);
659 attr_nid = OBJ_obj2nid(attr->object);
660 BIO_printf(out, " ");
661 if(attr_nid == NID_undef) {
662 i2a_ASN1_OBJECT (out, attr->object);
663 BIO_printf(out, ": ");
664 } else BIO_printf(out, "%s: ", OBJ_nid2ln(attr_nid));
665
666 if(sk_ASN1_TYPE_num(attr->value.set)) {
667 av = sk_ASN1_TYPE_value(attr->value.set, 0);
668 switch(av->type) {
669 case V_ASN1_BMPSTRING:
670 value = uni2asc(av->value.bmpstring->data,
671 av->value.bmpstring->length);
672 BIO_printf(out, "%s\n", value);
673 Free(value);
674 break;
675
676 case V_ASN1_OCTET_STRING:
677 hex_prin(out, av->value.bit_string->data,
678 av->value.bit_string->length);
679 BIO_printf(out, "\n");
680 break;
681
682 case V_ASN1_BIT_STRING:
683 hex_prin(out, av->value.octet_string->data,
684 av->value.octet_string->length);
685 BIO_printf(out, "\n");
686 break;
687
688 default:
689 BIO_printf(out, "<Unsupported tag %d>\n", av->type);
690 break;
691 }
692 } else BIO_printf(out, "<No Values>\n");
693 }
694 return 1;
695}
696
697void hex_prin(BIO *out, unsigned char *buf, int len)
698{
699 int i;
700 for (i = 0; i < len; i++) BIO_printf (out, "%02X ", buf[i]);
701}
702
703#endif
diff --git a/src/lib/libssl/src/apps/pkcs8.c b/src/lib/libssl/src/apps/pkcs8.c
new file mode 100644
index 0000000000..a05388300a
--- /dev/null
+++ b/src/lib/libssl/src/apps/pkcs8.c
@@ -0,0 +1,274 @@
1/* pkcs8.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <stdio.h>
59#include <string.h>
60#include <openssl/pem.h>
61#include <openssl/err.h>
62#include <openssl/evp.h>
63#include <openssl/pkcs12.h>
64
65#include "apps.h"
66#define PROG pkcs8_main
67
68
69int MAIN(int argc, char **argv)
70{
71 char **args, *infile = NULL, *outfile = NULL;
72 BIO *in = NULL, *out = NULL;
73 int topk8 = 0;
74 int pbe_nid = -1;
75 const EVP_CIPHER *cipher = NULL;
76 int iter = PKCS12_DEFAULT_ITER;
77 int informat, outformat;
78 int p8_broken = PKCS8_OK;
79 int nocrypt = 0;
80 X509_SIG *p8;
81 PKCS8_PRIV_KEY_INFO *p8inf;
82 EVP_PKEY *pkey;
83 char pass[50];
84 int badarg = 0;
85 if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
86 informat=FORMAT_PEM;
87 outformat=FORMAT_PEM;
88 ERR_load_crypto_strings();
89 SSLeay_add_all_algorithms();
90 args = argv + 1;
91 while (!badarg && *args && *args[0] == '-') {
92 if (!strcmp(*args,"-v2")) {
93 if (args[1]) {
94 args++;
95 cipher=EVP_get_cipherbyname(*args);
96 if(!cipher) {
97 BIO_printf(bio_err,
98 "Unknown cipher %s\n", *args);
99 badarg = 1;
100 }
101 } else badarg = 1;
102 } else if (!strcmp(*args,"-inform")) {
103 if (args[1]) {
104 args++;
105 informat=str2fmt(*args);
106 } else badarg = 1;
107 } else if (!strcmp(*args,"-outform")) {
108 if (args[1]) {
109 args++;
110 outformat=str2fmt(*args);
111 } else badarg = 1;
112 } else if (!strcmp (*args, "-topk8")) topk8 = 1;
113 else if (!strcmp (*args, "-noiter")) iter = 1;
114 else if (!strcmp (*args, "-nocrypt")) nocrypt = 1;
115 else if (!strcmp (*args, "-nooct")) p8_broken = PKCS8_NO_OCTET;
116 else if (!strcmp (*args, "-in")) {
117 if (args[1]) {
118 args++;
119 infile = *args;
120 } else badarg = 1;
121 } else if (!strcmp (*args, "-out")) {
122 if (args[1]) {
123 args++;
124 outfile = *args;
125 } else badarg = 1;
126 } else badarg = 1;
127 args++;
128 }
129
130 if (badarg) {
131 BIO_printf (bio_err, "Usage pkcs8 [options]\n");
132 BIO_printf (bio_err, "where options are\n");
133 BIO_printf (bio_err, "-in file input file\n");
134 BIO_printf (bio_err, "-inform X input format (DER or PEM)\n");
135 BIO_printf (bio_err, "-outform X output format (DER or PEM)\n");
136 BIO_printf (bio_err, "-out file output file\n");
137 BIO_printf (bio_err, "-topk8 output PKCS8 file\n");
138 BIO_printf (bio_err, "-nooct use (broken) no octet form\n");
139 BIO_printf (bio_err, "-noiter use 1 as iteration count\n");
140 BIO_printf (bio_err, "-nocrypt use or expect unencrypted private key\n");
141 BIO_printf (bio_err, "-v2 alg use PKCS#5 v2.0 and cipher \"alg\"\n");
142 return (1);
143 }
144
145 if ((pbe_nid == -1) && !cipher) pbe_nid = NID_pbeWithMD5AndDES_CBC;
146
147 if (infile) {
148 if (!(in = BIO_new_file (infile, "rb"))) {
149 BIO_printf (bio_err,
150 "Can't open input file %s\n", infile);
151 return (1);
152 }
153 } else in = BIO_new_fp (stdin, BIO_NOCLOSE);
154
155 if (outfile) {
156 if (!(out = BIO_new_file (outfile, "wb"))) {
157 BIO_printf (bio_err,
158 "Can't open output file %s\n", outfile);
159 return (1);
160 }
161 } else out = BIO_new_fp (stdout, BIO_NOCLOSE);
162
163 if (topk8) {
164 if (!(pkey = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL))) {
165 BIO_printf (bio_err, "Error reading key\n", outfile);
166 ERR_print_errors(bio_err);
167 return (1);
168 }
169 BIO_free(in);
170 if (!(p8inf = EVP_PKEY2PKCS8(pkey))) {
171 BIO_printf (bio_err, "Error converting key\n", outfile);
172 ERR_print_errors(bio_err);
173 return (1);
174 }
175 PKCS8_set_broken(p8inf, p8_broken);
176 if(nocrypt) {
177 if(outformat == FORMAT_PEM)
178 PEM_write_bio_PKCS8_PRIV_KEY_INFO(out, p8inf);
179 else if(outformat == FORMAT_ASN1)
180 i2d_PKCS8_PRIV_KEY_INFO_bio(out, p8inf);
181 else {
182 BIO_printf(bio_err, "Bad format specified for key\n");
183 return (1);
184 }
185 } else {
186 EVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1);
187 if (!(p8 = PKCS8_encrypt(pbe_nid, cipher,
188 pass, strlen(pass),
189 NULL, 0, iter, p8inf))) {
190 BIO_printf (bio_err, "Error encrypting key\n",
191 outfile);
192 ERR_print_errors(bio_err);
193 return (1);
194 }
195 if(outformat == FORMAT_PEM)
196 PEM_write_bio_PKCS8 (out, p8);
197 else if(outformat == FORMAT_ASN1)
198 i2d_PKCS8_bio(out, p8);
199 else {
200 BIO_printf(bio_err, "Bad format specified for key\n");
201 return (1);
202 }
203 X509_SIG_free(p8);
204 }
205 PKCS8_PRIV_KEY_INFO_free (p8inf);
206 EVP_PKEY_free(pkey);
207 BIO_free(out);
208 return (0);
209 }
210
211 if(nocrypt) {
212 if(informat == FORMAT_PEM)
213 p8inf = PEM_read_bio_PKCS8_PRIV_KEY_INFO(in,NULL,NULL, NULL);
214 else if(informat == FORMAT_ASN1)
215 p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(in, NULL);
216 else {
217 BIO_printf(bio_err, "Bad format specified for key\n");
218 return (1);
219 }
220 } else {
221 if(informat == FORMAT_PEM)
222 p8 = PEM_read_bio_PKCS8(in, NULL, NULL, NULL);
223 else if(informat == FORMAT_ASN1)
224 p8 = d2i_PKCS8_bio(in, NULL);
225 else {
226 BIO_printf(bio_err, "Bad format specified for key\n");
227 return (1);
228 }
229
230 if (!p8) {
231 BIO_printf (bio_err, "Error reading key\n", outfile);
232 ERR_print_errors(bio_err);
233 return (1);
234 }
235 EVP_read_pw_string(pass, 50, "Enter Password:", 0);
236 p8inf = M_PKCS8_decrypt(p8, pass, strlen(pass));
237 X509_SIG_free(p8);
238 }
239
240 if (!p8inf) {
241 BIO_printf(bio_err, "Error decrypting key\n", outfile);
242 ERR_print_errors(bio_err);
243 return (1);
244 }
245
246 if (!(pkey = EVP_PKCS82PKEY(p8inf))) {
247 BIO_printf(bio_err, "Error converting key\n", outfile);
248 ERR_print_errors(bio_err);
249 return (1);
250 }
251
252 if (p8inf->broken) {
253 BIO_printf(bio_err, "Warning: broken key encoding: ");
254 switch (p8inf->broken) {
255 case PKCS8_NO_OCTET:
256 BIO_printf(bio_err, "No Octet String\n");
257 break;
258
259 default:
260 BIO_printf(bio_err, "Unknown broken type\n");
261 break;
262 }
263 }
264
265 PKCS8_PRIV_KEY_INFO_free(p8inf);
266
267 PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, NULL);
268
269 EVP_PKEY_free(pkey);
270 BIO_free(out);
271 BIO_free(in);
272
273 return (0);
274}
diff --git a/src/lib/libssl/src/apps/progs.pl b/src/lib/libssl/src/apps/progs.pl
new file mode 100644
index 0000000000..7a69fc7b18
--- /dev/null
+++ b/src/lib/libssl/src/apps/progs.pl
@@ -0,0 +1,77 @@
1#!/usr/local/bin/perl
2
3print "/* This file was generated by progs.pl. */\n\n";
4
5grep(s/^asn1pars$/asn1parse/,@ARGV);
6
7foreach (@ARGV)
8 { printf "extern int %s_main(int argc,char *argv[]);\n",$_; }
9
10print <<'EOF';
11
12#ifdef SSLEAY_SRC /* Defined only in openssl.c. */
13
14#define FUNC_TYPE_GENERAL 1
15#define FUNC_TYPE_MD 2
16#define FUNC_TYPE_CIPHER 3
17
18typedef struct {
19 int type;
20 char *name;
21 int (*func)();
22 } FUNCTION;
23
24FUNCTION functions[] = {
25EOF
26
27foreach (@ARGV)
28 {
29 push(@files,$_);
30 $str="\t{FUNC_TYPE_GENERAL,\"$_\",${_}_main},\n";
31 if (($_ =~ /^s_/) || ($_ =~ /^ciphers$/))
32 { print "#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))\n${str}#endif\n"; }
33 elsif ( ($_ =~ /^rsa$/) || ($_ =~ /^genrsa$/) )
34 { print "#ifndef NO_RSA\n${str}#endif\n"; }
35 elsif ( ($_ =~ /^dsa$/) || ($_ =~ /^gendsa$/) || ($_ =~ /^dsaparam$/))
36 { print "#ifndef NO_DSA\n${str}#endif\n"; }
37 elsif ( ($_ =~ /^dh$/) || ($_ =~ /^gendh$/))
38 { print "#ifndef NO_DH\n${str}#endif\n"; }
39 else
40 { print $str; }
41 }
42
43foreach ("md2","md5","sha","sha1","mdc2","rmd160")
44 {
45 push(@files,$_);
46 printf "\t{FUNC_TYPE_MD,\"%s\",dgst_main},\n",$_;
47 }
48
49foreach (
50 "base64",
51 "des", "des3", "desx", "idea", "rc4", "rc2","bf","cast","rc5",
52 "des-ecb", "des-ede", "des-ede3",
53 "des-cbc", "des-ede-cbc","des-ede3-cbc",
54 "des-cfb", "des-ede-cfb","des-ede3-cfb",
55 "des-ofb", "des-ede-ofb","des-ede3-ofb",
56 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
57 "rc2-cbc", "rc2-ecb", "rc2-cfb", "rc2-ofb",
58 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
59 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
60 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb")
61 {
62 push(@files,$_);
63
64 $t=sprintf("\t{FUNC_TYPE_CIPHER,\"%s\",enc_main},\n",$_);
65 if ($_ =~ /des/) { $t="#ifndef NO_DES\n${t}#endif\n"; }
66 elsif ($_ =~ /idea/) { $t="#ifndef NO_IDEA\n${t}#endif\n"; }
67 elsif ($_ =~ /rc4/) { $t="#ifndef NO_RC4\n${t}#endif\n"; }
68 elsif ($_ =~ /rc2/) { $t="#ifndef NO_RC2\n${t}#endif\n"; }
69 elsif ($_ =~ /bf/) { $t="#ifndef NO_BF\n${t}#endif\n"; }
70 elsif ($_ =~ /cast/) { $t="#ifndef NO_CAST\n${t}#endif\n"; }
71 elsif ($_ =~ /rc5/) { $t="#ifndef NO_RC5\n${t}#endif\n"; }
72 print $t;
73 }
74
75print "\t{0,NULL,NULL}\n\t};\n";
76print "#endif\n\n";
77
diff --git a/src/lib/libssl/src/apps/rand.c b/src/lib/libssl/src/apps/rand.c
new file mode 100644
index 0000000000..cfbba30755
--- /dev/null
+++ b/src/lib/libssl/src/apps/rand.c
@@ -0,0 +1,140 @@
1/* apps/rand.c */
2
3#include "apps.h"
4
5#include <ctype.h>
6#include <stdio.h>
7#include <string.h>
8
9#include <openssl/bio.h>
10#include <openssl/err.h>
11#include <openssl/rand.h>
12
13#undef PROG
14#define PROG rand_main
15
16/* -out file - write to file
17 * -rand file:file - PRNG seed files
18 * -base64 - encode output
19 * num - write 'num' bytes
20 */
21
22int MAIN(int, char **);
23
24int MAIN(int argc, char **argv)
25 {
26 int i, r, ret = 1;
27 int badopt;
28 char *outfile = NULL;
29 char *inrand = NULL;
30 int base64 = 0;
31 BIO *out = NULL;
32 int num = -1;
33
34 apps_startup();
35
36 if (bio_err == NULL)
37 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
38 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT);
39
40 badopt = 0;
41 i = 0;
42 while (!badopt && argv[++i] != NULL)
43 {
44 if (strcmp(argv[i], "-out") == 0)
45 {
46 if ((argv[i+1] != NULL) && (outfile == NULL))
47 outfile = argv[++i];
48 else
49 badopt = 1;
50 }
51 else if (strcmp(argv[i], "-rand") == 0)
52 {
53 if ((argv[i+1] != NULL) && (inrand == NULL))
54 inrand = argv[++i];
55 else
56 badopt = 1;
57 }
58 else if (strcmp(argv[i], "-base64") == 0)
59 {
60 if (!base64)
61 base64 = 1;
62 else
63 badopt = 1;
64 }
65 else if (isdigit(argv[i][0]))
66 {
67 if (num < 0)
68 {
69 r = sscanf(argv[i], "%d", &num);
70 if (r == 0 || num < 0)
71 badopt = 1;
72 }
73 else
74 badopt = 1;
75 }
76 else
77 badopt = 1;
78 }
79
80 if (num < 0)
81 badopt = 1;
82
83 if (badopt)
84 {
85 BIO_printf(bio_err, "Usage: rand [options] num\n");
86 BIO_printf(bio_err, "where options are\n");
87 BIO_printf(bio_err, "-out file - write to file\n");
88 BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
89 BIO_printf(bio_err, "-base64 - encode output\n");
90 goto err;
91 }
92
93 app_RAND_load_file(NULL, bio_err, (inrand != NULL));
94 if (inrand != NULL)
95 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
96 app_RAND_load_files(inrand));
97
98 out = BIO_new(BIO_s_file());
99 if (out == NULL)
100 goto err;
101 if (outfile != NULL)
102 r = BIO_write_filename(out, outfile);
103 else
104 r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
105 if (r <= 0)
106 goto err;
107
108 if (base64)
109 {
110 BIO *b64 = BIO_new(BIO_f_base64());
111 if (b64 == NULL)
112 goto err;
113 out = BIO_push(b64, out);
114 }
115
116 while (num > 0)
117 {
118 unsigned char buf[4096];
119 int chunk;
120
121 chunk = num;
122 if (chunk > sizeof buf)
123 chunk = sizeof buf;
124 r = RAND_bytes(buf, chunk);
125 if (r <= 0)
126 goto err;
127 BIO_write(out, buf, chunk);
128 num -= chunk;
129 }
130 BIO_flush(out);
131
132 app_RAND_write_file(NULL, bio_err);
133 ret = 0;
134
135err:
136 ERR_print_errors(bio_err);
137 if (out)
138 BIO_free_all(out);
139 EXIT(ret);
140 }
diff --git a/src/lib/libssl/src/apps/rsautl.c b/src/lib/libssl/src/apps/rsautl.c
new file mode 100644
index 0000000000..2ef75649dd
--- /dev/null
+++ b/src/lib/libssl/src/apps/rsautl.c
@@ -0,0 +1,315 @@
1/* rsautl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include "apps.h"
59#include <string.h>
60#include <openssl/err.h>
61#include <openssl/pem.h>
62#include <openssl/engine.h>
63
64#define RSA_SIGN 1
65#define RSA_VERIFY 2
66#define RSA_ENCRYPT 3
67#define RSA_DECRYPT 4
68
69#define KEY_PRIVKEY 1
70#define KEY_PUBKEY 2
71#define KEY_CERT 3
72
73static void usage(void);
74
75#undef PROG
76
77#define PROG rsautl_main
78
79int MAIN(int argc, char **);
80
81int MAIN(int argc, char **argv)
82{
83 ENGINE *e = NULL;
84 BIO *in = NULL, *out = NULL;
85 char *infile = NULL, *outfile = NULL;
86 char *keyfile = NULL;
87 char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY;
88 int keyform = FORMAT_PEM;
89 char need_priv = 0, badarg = 0, rev = 0;
90 char hexdump = 0, asn1parse = 0;
91 X509 *x;
92 EVP_PKEY *pkey = NULL;
93 RSA *rsa = NULL;
94 unsigned char *rsa_in = NULL, *rsa_out = NULL, pad;
95 int rsa_inlen, rsa_outlen = 0;
96 int keysize;
97 char *engine=NULL;
98
99 int ret = 1;
100
101 argc--;
102 argv++;
103
104 if(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
105 ERR_load_crypto_strings();
106 OpenSSL_add_all_algorithms();
107 pad = RSA_PKCS1_PADDING;
108
109 while(argc >= 1)
110 {
111 if (!strcmp(*argv,"-in")) {
112 if (--argc < 1) badarg = 1;
113 infile= *(++argv);
114 } else if (!strcmp(*argv,"-out")) {
115 if (--argc < 1) badarg = 1;
116 outfile= *(++argv);
117 } else if(!strcmp(*argv, "-inkey")) {
118 if (--argc < 1) badarg = 1;
119 keyfile = *(++argv);
120 } else if(!strcmp(*argv, "-engine")) {
121 if (--argc < 1) badarg = 1;
122 engine = *(++argv);
123 } else if(!strcmp(*argv, "-pubin")) {
124 key_type = KEY_PUBKEY;
125 } else if(!strcmp(*argv, "-certin")) {
126 key_type = KEY_CERT;
127 }
128 else if(!strcmp(*argv, "-asn1parse")) asn1parse = 1;
129 else if(!strcmp(*argv, "-hexdump")) hexdump = 1;
130 else if(!strcmp(*argv, "-raw")) pad = RSA_NO_PADDING;
131 else if(!strcmp(*argv, "-oaep")) pad = RSA_PKCS1_OAEP_PADDING;
132 else if(!strcmp(*argv, "-ssl")) pad = RSA_SSLV23_PADDING;
133 else if(!strcmp(*argv, "-pkcs")) pad = RSA_PKCS1_PADDING;
134 else if(!strcmp(*argv, "-sign")) {
135 rsa_mode = RSA_SIGN;
136 need_priv = 1;
137 } else if(!strcmp(*argv, "-verify")) rsa_mode = RSA_VERIFY;
138 else if(!strcmp(*argv, "-rev")) rev = 1;
139 else if(!strcmp(*argv, "-encrypt")) rsa_mode = RSA_ENCRYPT;
140 else if(!strcmp(*argv, "-decrypt")) {
141 rsa_mode = RSA_DECRYPT;
142 need_priv = 1;
143 } else badarg = 1;
144 if(badarg) {
145 usage();
146 goto end;
147 }
148 argc--;
149 argv++;
150 }
151
152 if(need_priv && (key_type != KEY_PRIVKEY)) {
153 BIO_printf(bio_err, "A private key is needed for this operation\n");
154 goto end;
155 }
156
157 if (engine != NULL)
158 {
159 if((e = ENGINE_by_id(engine)) == NULL)
160 {
161 BIO_printf(bio_err,"invalid engine \"%s\"\n",
162 engine);
163 goto end;
164 }
165 if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
166 {
167 BIO_printf(bio_err,"can't use that engine\n");
168 goto end;
169 }
170 BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
171 /* Free our "structural" reference. */
172 ENGINE_free(e);
173 }
174
175/* FIXME: seed PRNG only if needed */
176 app_RAND_load_file(NULL, bio_err, 0);
177
178 switch(key_type) {
179 case KEY_PRIVKEY:
180 pkey = load_key(bio_err, keyfile, keyform, NULL);
181 break;
182
183 case KEY_PUBKEY:
184 pkey = load_pubkey(bio_err, keyfile, keyform);
185 break;
186
187 case KEY_CERT:
188 x = load_cert(bio_err, keyfile, keyform);
189 if(x) {
190 pkey = X509_get_pubkey(x);
191 X509_free(x);
192 }
193 break;
194 }
195
196 if(!pkey) {
197 BIO_printf(bio_err, "Error loading key\n");
198 return 1;
199 }
200
201 rsa = EVP_PKEY_get1_RSA(pkey);
202 EVP_PKEY_free(pkey);
203
204 if(!rsa) {
205 BIO_printf(bio_err, "Error getting RSA key\n");
206 ERR_print_errors(bio_err);
207 goto end;
208 }
209
210
211 if(infile) {
212 if(!(in = BIO_new_file(infile, "rb"))) {
213 BIO_printf(bio_err, "Error Reading Input File\n");
214 ERR_print_errors(bio_err);
215 goto end;
216 }
217 } else in = BIO_new_fp(stdin, BIO_NOCLOSE);
218
219 if(outfile) {
220 if(!(out = BIO_new_file(outfile, "wb"))) {
221 BIO_printf(bio_err, "Error Reading Output File\n");
222 ERR_print_errors(bio_err);
223 goto end;
224 }
225 } else {
226 out = BIO_new_fp(stdout, BIO_NOCLOSE);
227#ifdef VMS
228 {
229 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
230 out = BIO_push(tmpbio, out);
231 }
232#endif
233 }
234
235 keysize = RSA_size(rsa);
236
237 rsa_in = OPENSSL_malloc(keysize * 2);
238 rsa_out = OPENSSL_malloc(keysize);
239
240 /* Read the input data */
241 rsa_inlen = BIO_read(in, rsa_in, keysize * 2);
242 if(rsa_inlen <= 0) {
243 BIO_printf(bio_err, "Error reading input Data\n");
244 exit(1);
245 }
246 if(rev) {
247 int i;
248 unsigned char ctmp;
249 for(i = 0; i < rsa_inlen/2; i++) {
250 ctmp = rsa_in[i];
251 rsa_in[i] = rsa_in[rsa_inlen - 1 - i];
252 rsa_in[rsa_inlen - 1 - i] = ctmp;
253 }
254 }
255 switch(rsa_mode) {
256
257 case RSA_VERIFY:
258 rsa_outlen = RSA_public_decrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
259 break;
260
261 case RSA_SIGN:
262 rsa_outlen = RSA_private_encrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
263 break;
264
265 case RSA_ENCRYPT:
266 rsa_outlen = RSA_public_encrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
267 break;
268
269 case RSA_DECRYPT:
270 rsa_outlen = RSA_private_decrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
271 break;
272
273 }
274
275 if(rsa_outlen <= 0) {
276 BIO_printf(bio_err, "RSA operation error\n");
277 ERR_print_errors(bio_err);
278 goto end;
279 }
280 ret = 0;
281 if(asn1parse) {
282 if(!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) {
283 ERR_print_errors(bio_err);
284 }
285 } else if(hexdump) BIO_dump(out, (char *)rsa_out, rsa_outlen);
286 else BIO_write(out, rsa_out, rsa_outlen);
287 end:
288 RSA_free(rsa);
289 BIO_free(in);
290 BIO_free_all(out);
291 if(rsa_in) OPENSSL_free(rsa_in);
292 if(rsa_out) OPENSSL_free(rsa_out);
293 return ret;
294}
295
296static void usage()
297{
298 BIO_printf(bio_err, "Usage: rsautl [options]\n");
299 BIO_printf(bio_err, "-in file input file\n");
300 BIO_printf(bio_err, "-out file output file\n");
301 BIO_printf(bio_err, "-inkey file input key\n");
302 BIO_printf(bio_err, "-pubin input is an RSA public\n");
303 BIO_printf(bio_err, "-certin input is a certificate carrying an RSA public key\n");
304 BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n");
305 BIO_printf(bio_err, "-ssl use SSL v2 padding\n");
306 BIO_printf(bio_err, "-raw use no padding\n");
307 BIO_printf(bio_err, "-pkcs use PKCS#1 v1.5 padding (default)\n");
308 BIO_printf(bio_err, "-oaep use PKCS#1 OAEP\n");
309 BIO_printf(bio_err, "-sign sign with private key\n");
310 BIO_printf(bio_err, "-verify verify with public key\n");
311 BIO_printf(bio_err, "-encrypt encrypt with public key\n");
312 BIO_printf(bio_err, "-decrypt decrypt with private key\n");
313 BIO_printf(bio_err, "-hexdump hex dump output\n");
314}
315
diff --git a/src/lib/libssl/src/apps/smime.c b/src/lib/libssl/src/apps/smime.c
new file mode 100644
index 0000000000..77633cfb60
--- /dev/null
+++ b/src/lib/libssl/src/apps/smime.c
@@ -0,0 +1,646 @@
1/* smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* S/MIME utility function */
60
61#include <stdio.h>
62#include <string.h>
63#include "apps.h"
64#include <openssl/crypto.h>
65#include <openssl/pem.h>
66#include <openssl/err.h>
67
68#undef PROG
69#define PROG smime_main
70static X509 *load_cert(char *file);
71static EVP_PKEY *load_key(char *file, char *pass);
72static STACK_OF(X509) *load_certs(char *file);
73static X509_STORE *setup_verify(char *CAfile, char *CApath);
74static int save_certs(char *signerfile, STACK_OF(X509) *signers);
75
76#define SMIME_OP 0x10
77#define SMIME_ENCRYPT (1 | SMIME_OP)
78#define SMIME_DECRYPT 2
79#define SMIME_SIGN (3 | SMIME_OP)
80#define SMIME_VERIFY 4
81#define SMIME_PK7OUT 5
82
83int MAIN(int, char **);
84
85int MAIN(int argc, char **argv)
86{
87 int operation = 0;
88 int ret = 0;
89 char **args;
90 char *inmode = "r", *outmode = "w";
91 char *infile = NULL, *outfile = NULL;
92 char *signerfile = NULL, *recipfile = NULL;
93 char *certfile = NULL, *keyfile = NULL;
94 EVP_CIPHER *cipher = NULL;
95 PKCS7 *p7 = NULL;
96 X509_STORE *store = NULL;
97 X509 *cert = NULL, *recip = NULL, *signer = NULL;
98 EVP_PKEY *key = NULL;
99 STACK_OF(X509) *encerts = NULL, *other = NULL;
100 BIO *in = NULL, *out = NULL, *indata = NULL;
101 int badarg = 0;
102 int flags = PKCS7_DETACHED;
103 char *to = NULL, *from = NULL, *subject = NULL;
104 char *CAfile = NULL, *CApath = NULL;
105 char *passargin = NULL, *passin = NULL;
106 char *inrand = NULL;
107 int need_rand = 0;
108 args = argv + 1;
109
110 ret = 1;
111
112 while (!badarg && *args && *args[0] == '-') {
113 if (!strcmp (*args, "-encrypt")) operation = SMIME_ENCRYPT;
114 else if (!strcmp (*args, "-decrypt")) operation = SMIME_DECRYPT;
115 else if (!strcmp (*args, "-sign")) operation = SMIME_SIGN;
116 else if (!strcmp (*args, "-verify")) operation = SMIME_VERIFY;
117 else if (!strcmp (*args, "-pk7out")) operation = SMIME_PK7OUT;
118#ifndef NO_DES
119 else if (!strcmp (*args, "-des3"))
120 cipher = EVP_des_ede3_cbc();
121 else if (!strcmp (*args, "-des"))
122 cipher = EVP_des_cbc();
123#endif
124#ifndef NO_RC2
125 else if (!strcmp (*args, "-rc2-40"))
126 cipher = EVP_rc2_40_cbc();
127 else if (!strcmp (*args, "-rc2-128"))
128 cipher = EVP_rc2_cbc();
129 else if (!strcmp (*args, "-rc2-64"))
130 cipher = EVP_rc2_64_cbc();
131#endif
132 else if (!strcmp (*args, "-text"))
133 flags |= PKCS7_TEXT;
134 else if (!strcmp (*args, "-nointern"))
135 flags |= PKCS7_NOINTERN;
136 else if (!strcmp (*args, "-noverify"))
137 flags |= PKCS7_NOVERIFY;
138 else if (!strcmp (*args, "-nochain"))
139 flags |= PKCS7_NOCHAIN;
140 else if (!strcmp (*args, "-nocerts"))
141 flags |= PKCS7_NOCERTS;
142 else if (!strcmp (*args, "-noattr"))
143 flags |= PKCS7_NOATTR;
144 else if (!strcmp (*args, "-nodetach"))
145 flags &= ~PKCS7_DETACHED;
146 else if (!strcmp (*args, "-binary"))
147 flags |= PKCS7_BINARY;
148 else if (!strcmp (*args, "-nosigs"))
149 flags |= PKCS7_NOSIGS;
150 else if (!strcmp(*args,"-rand")) {
151 if (args[1]) {
152 args++;
153 inrand = *args;
154 } else badarg = 1;
155 need_rand = 1;
156 } else if (!strcmp(*args,"-passin")) {
157 if (args[1]) {
158 args++;
159 passargin = *args;
160 } else badarg = 1;
161 } else if (!strcmp (*args, "-to")) {
162 if (args[1]) {
163 args++;
164 to = *args;
165 } else badarg = 1;
166 } else if (!strcmp (*args, "-from")) {
167 if (args[1]) {
168 args++;
169 from = *args;
170 } else badarg = 1;
171 } else if (!strcmp (*args, "-subject")) {
172 if (args[1]) {
173 args++;
174 subject = *args;
175 } else badarg = 1;
176 } else if (!strcmp (*args, "-signer")) {
177 if (args[1]) {
178 args++;
179 signerfile = *args;
180 } else badarg = 1;
181 } else if (!strcmp (*args, "-recip")) {
182 if (args[1]) {
183 args++;
184 recipfile = *args;
185 } else badarg = 1;
186 } else if (!strcmp (*args, "-inkey")) {
187 if (args[1]) {
188 args++;
189 keyfile = *args;
190 } else badarg = 1;
191 } else if (!strcmp (*args, "-certfile")) {
192 if (args[1]) {
193 args++;
194 certfile = *args;
195 } else badarg = 1;
196 } else if (!strcmp (*args, "-CAfile")) {
197 if (args[1]) {
198 args++;
199 CAfile = *args;
200 } else badarg = 1;
201 } else if (!strcmp (*args, "-CApath")) {
202 if (args[1]) {
203 args++;
204 CApath = *args;
205 } else badarg = 1;
206 } else if (!strcmp (*args, "-in")) {
207 if (args[1]) {
208 args++;
209 infile = *args;
210 } else badarg = 1;
211 } else if (!strcmp (*args, "-out")) {
212 if (args[1]) {
213 args++;
214 outfile = *args;
215 } else badarg = 1;
216 } else badarg = 1;
217 args++;
218 }
219
220 if(operation == SMIME_SIGN) {
221 if(!signerfile) {
222 BIO_printf(bio_err, "No signer certificate specified\n");
223 badarg = 1;
224 }
225 need_rand = 1;
226 } else if(operation == SMIME_DECRYPT) {
227 if(!recipfile) {
228 BIO_printf(bio_err, "No recipient certificate and key specified\n");
229 badarg = 1;
230 }
231 } else if(operation == SMIME_ENCRYPT) {
232 if(!*args) {
233 BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n");
234 badarg = 1;
235 }
236 need_rand = 1;
237 } else if(!operation) badarg = 1;
238
239 if (badarg) {
240 BIO_printf (bio_err, "Usage smime [options] cert.pem ...\n");
241 BIO_printf (bio_err, "where options are\n");
242 BIO_printf (bio_err, "-encrypt encrypt message\n");
243 BIO_printf (bio_err, "-decrypt decrypt encrypted message\n");
244 BIO_printf (bio_err, "-sign sign message\n");
245 BIO_printf (bio_err, "-verify verify signed message\n");
246 BIO_printf (bio_err, "-pk7out output PKCS#7 structure\n");
247#ifndef NO_DES
248 BIO_printf (bio_err, "-des3 encrypt with triple DES\n");
249 BIO_printf (bio_err, "-des encrypt with DES\n");
250#endif
251#ifndef NO_RC2
252 BIO_printf (bio_err, "-rc2-40 encrypt with RC2-40 (default)\n");
253 BIO_printf (bio_err, "-rc2-64 encrypt with RC2-64\n");
254 BIO_printf (bio_err, "-rc2-128 encrypt with RC2-128\n");
255#endif
256 BIO_printf (bio_err, "-nointern don't search certificates in message for signer\n");
257 BIO_printf (bio_err, "-nosigs don't verify message signature\n");
258 BIO_printf (bio_err, "-noverify don't verify signers certificate\n");
259 BIO_printf (bio_err, "-nocerts don't include signers certificate when signing\n");
260 BIO_printf (bio_err, "-nodetach use opaque signing\n");
261 BIO_printf (bio_err, "-noattr don't include any signed attributes\n");
262 BIO_printf (bio_err, "-binary don't translate message to text\n");
263 BIO_printf (bio_err, "-certfile file other certificates file\n");
264 BIO_printf (bio_err, "-signer file signer certificate file\n");
265 BIO_printf (bio_err, "-recip file recipient certificate file for decryption\n");
266 BIO_printf (bio_err, "-in file input file\n");
267 BIO_printf (bio_err, "-inkey file input private key (if not signer or recipient)\n");
268 BIO_printf (bio_err, "-out file output file\n");
269 BIO_printf (bio_err, "-to addr to address\n");
270 BIO_printf (bio_err, "-from ad from address\n");
271 BIO_printf (bio_err, "-subject s subject\n");
272 BIO_printf (bio_err, "-text include or delete text MIME headers\n");
273 BIO_printf (bio_err, "-CApath dir trusted certificates directory\n");
274 BIO_printf (bio_err, "-CAfile file trusted certificates file\n");
275 BIO_printf(bio_err, "-rand file:file:...\n");
276 BIO_printf(bio_err, " load the file (or the files in the directory) into\n");
277 BIO_printf(bio_err, " the random number generator\n");
278 BIO_printf (bio_err, "cert.pem recipient certificate(s) for encryption\n");
279 goto end;
280 }
281
282 if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
283 BIO_printf(bio_err, "Error getting password\n");
284 goto end;
285 }
286
287 if (need_rand) {
288 app_RAND_load_file(NULL, bio_err, (inrand != NULL));
289 if (inrand != NULL)
290 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
291 app_RAND_load_files(inrand));
292 }
293
294 ret = 2;
295
296 if(operation != SMIME_SIGN) flags &= ~PKCS7_DETACHED;
297
298 if(flags & PKCS7_BINARY) {
299 if(operation & SMIME_OP) inmode = "rb";
300 else outmode = "rb";
301 }
302
303 if(operation == SMIME_ENCRYPT) {
304 if (!cipher) {
305#ifndef NO_RC2
306 cipher = EVP_rc2_40_cbc();
307#else
308 BIO_printf(bio_err, "No cipher selected\n");
309 goto end;
310#endif
311 }
312#ifdef CRYPTO_MDEBUG
313 CRYPTO_push_info("load encryption certificates");
314#endif
315 encerts = sk_X509_new_null();
316 while (*args) {
317 if(!(cert = load_cert(*args))) {
318 BIO_printf(bio_err, "Can't read recipient certificate file %s\n", *args);
319 goto end;
320 }
321 sk_X509_push(encerts, cert);
322 cert = NULL;
323 args++;
324 }
325#ifdef CRYPTO_MDEBUG
326 CRYPTO_pop_info();
327#endif
328 }
329
330 if(signerfile && (operation == SMIME_SIGN)) {
331#ifdef CRYPTO_MDEBUG
332 CRYPTO_push_info("load signer certificate");
333#endif
334 if(!(signer = load_cert(signerfile))) {
335 BIO_printf(bio_err, "Can't read signer certificate file %s\n", signerfile);
336 goto end;
337 }
338#ifdef CRYPTO_MDEBUG
339 CRYPTO_pop_info();
340#endif
341 }
342
343 if(certfile) {
344#ifdef CRYPTO_MDEBUG
345 CRYPTO_push_info("load other certfiles");
346#endif
347 if(!(other = load_certs(certfile))) {
348 BIO_printf(bio_err, "Can't read certificate file %s\n", certfile);
349 ERR_print_errors(bio_err);
350 goto end;
351 }
352#ifdef CRYPTO_MDEBUG
353 CRYPTO_pop_info();
354#endif
355 }
356
357 if(recipfile && (operation == SMIME_DECRYPT)) {
358#ifdef CRYPTO_MDEBUG
359 CRYPTO_push_info("load recipient certificate");
360#endif
361 if(!(recip = load_cert(recipfile))) {
362 BIO_printf(bio_err, "Can't read recipient certificate file %s\n", recipfile);
363 ERR_print_errors(bio_err);
364 goto end;
365 }
366#ifdef CRYPTO_MDEBUG
367 CRYPTO_pop_info();
368#endif
369 }
370
371 if(operation == SMIME_DECRYPT) {
372 if(!keyfile) keyfile = recipfile;
373 } else if(operation == SMIME_SIGN) {
374 if(!keyfile) keyfile = signerfile;
375 } else keyfile = NULL;
376
377 if(keyfile) {
378#ifdef CRYPTO_MDEBUG
379 CRYPTO_push_info("load keyfile");
380#endif
381 if(!(key = load_key(keyfile, passin))) {
382 BIO_printf(bio_err, "Can't read recipient certificate file %s\n", keyfile);
383 ERR_print_errors(bio_err);
384 goto end;
385 }
386#ifdef CRYPTO_MDEBUG
387 CRYPTO_pop_info();
388#endif
389 }
390
391#ifdef CRYPTO_MDEBUG
392 CRYPTO_push_info("open input files");
393#endif
394 if (infile) {
395 if (!(in = BIO_new_file(infile, inmode))) {
396 BIO_printf (bio_err,
397 "Can't open input file %s\n", infile);
398 goto end;
399 }
400 } else in = BIO_new_fp(stdin, BIO_NOCLOSE);
401#ifdef CRYPTO_MDEBUG
402 CRYPTO_pop_info();
403#endif
404
405#ifdef CRYPTO_MDEBUG
406 CRYPTO_push_info("open output files");
407#endif
408 if (outfile) {
409 if (!(out = BIO_new_file(outfile, outmode))) {
410 BIO_printf (bio_err,
411 "Can't open output file %s\n", outfile);
412 goto end;
413 }
414 } else out = BIO_new_fp(stdout, BIO_NOCLOSE);
415#ifdef CRYPTO_MDEBUG
416 CRYPTO_pop_info();
417#endif
418
419 if(operation == SMIME_VERIFY) {
420#ifdef CRYPTO_MDEBUG
421 CRYPTO_push_info("setup_verify");
422#endif
423 if(!(store = setup_verify(CAfile, CApath))) goto end;
424#ifdef CRYPTO_MDEBUG
425 CRYPTO_pop_info();
426#endif
427 }
428
429 ret = 3;
430
431 if(operation == SMIME_ENCRYPT) {
432#ifdef CRYPTO_MDEBUG
433 CRYPTO_push_info("PKCS7_encrypt");
434#endif
435 p7 = PKCS7_encrypt(encerts, in, cipher, flags);
436#ifdef CRYPTO_MDEBUG
437 CRYPTO_pop_info();
438#endif
439 } else if(operation == SMIME_SIGN) {
440#ifdef CRYPTO_MDEBUG
441 CRYPTO_push_info("PKCS7_sign");
442#endif
443 p7 = PKCS7_sign(signer, key, other, in, flags);
444 BIO_reset(in);
445#ifdef CRYPTO_MDEBUG
446 CRYPTO_pop_info();
447#endif
448 } else {
449#ifdef CRYPTO_MDEBUG
450 CRYPTO_push_info("SMIME_read_PKCS7");
451#endif
452 if(!(p7 = SMIME_read_PKCS7(in, &indata))) {
453 BIO_printf(bio_err, "Error reading S/MIME message\n");
454 goto end;
455 }
456#ifdef CRYPTO_MDEBUG
457 CRYPTO_pop_info();
458#endif
459 }
460
461 if(!p7) {
462 BIO_printf(bio_err, "Error creating PKCS#7 structure\n");
463 goto end;
464 }
465
466 ret = 4;
467 if(operation == SMIME_DECRYPT) {
468#ifdef CRYPTO_MDEBUG
469 CRYPTO_push_info("PKCS7_decrypt");
470#endif
471 if(!PKCS7_decrypt(p7, key, recip, out, flags)) {
472 BIO_printf(bio_err, "Error decrypting PKCS#7 structure\n");
473 goto end;
474 }
475#ifdef CRYPTO_MDEBUG
476 CRYPTO_pop_info();
477#endif
478 } else if(operation == SMIME_VERIFY) {
479 STACK_OF(X509) *signers;
480#ifdef CRYPTO_MDEBUG
481 CRYPTO_push_info("PKCS7_verify");
482#endif
483 if(PKCS7_verify(p7, other, store, indata, out, flags)) {
484 BIO_printf(bio_err, "Verification Successful\n");
485 } else {
486 BIO_printf(bio_err, "Verification Failure\n");
487 goto end;
488 }
489#ifdef CRYPTO_MDEBUG
490 CRYPTO_pop_info();
491 CRYPTO_push_info("PKCS7_get0_signers");
492#endif
493 signers = PKCS7_get0_signers(p7, other, flags);
494#ifdef CRYPTO_MDEBUG
495 CRYPTO_pop_info();
496 CRYPTO_push_info("save_certs");
497#endif
498 if(!save_certs(signerfile, signers)) {
499 BIO_printf(bio_err, "Error writing signers to %s\n",
500 signerfile);
501 ret = 5;
502 goto end;
503 }
504#ifdef CRYPTO_MDEBUG
505 CRYPTO_pop_info();
506#endif
507 sk_X509_free(signers);
508 } else if(operation == SMIME_PK7OUT) {
509 PEM_write_bio_PKCS7(out, p7);
510 } else {
511 if(to) BIO_printf(out, "To: %s\n", to);
512 if(from) BIO_printf(out, "From: %s\n", from);
513 if(subject) BIO_printf(out, "Subject: %s\n", subject);
514 SMIME_write_PKCS7(out, p7, in, flags);
515 }
516 ret = 0;
517end:
518#ifdef CRYPTO_MDEBUG
519 CRYPTO_remove_all_info();
520#endif
521 if (need_rand)
522 app_RAND_write_file(NULL, bio_err);
523 if(ret) ERR_print_errors(bio_err);
524 sk_X509_pop_free(encerts, X509_free);
525 sk_X509_pop_free(other, X509_free);
526 X509_STORE_free(store);
527 X509_free(cert);
528 X509_free(recip);
529 X509_free(signer);
530 EVP_PKEY_free(key);
531 PKCS7_free(p7);
532 BIO_free(in);
533 BIO_free(indata);
534 BIO_free(out);
535 if(passin) Free(passin);
536 return (ret);
537}
538
539static X509 *load_cert(char *file)
540{
541 BIO *in;
542 X509 *cert;
543 if(!(in = BIO_new_file(file, "r"))) return NULL;
544 cert = PEM_read_bio_X509(in, NULL, NULL,NULL);
545 BIO_free(in);
546 return cert;
547}
548
549static EVP_PKEY *load_key(char *file, char *pass)
550{
551 BIO *in;
552 EVP_PKEY *key;
553 if(!(in = BIO_new_file(file, "r"))) return NULL;
554 key = PEM_read_bio_PrivateKey(in, NULL,NULL,pass);
555 BIO_free(in);
556 return key;
557}
558
559static STACK_OF(X509) *load_certs(char *file)
560{
561 BIO *in;
562 int i;
563 STACK_OF(X509) *othercerts;
564 STACK_OF(X509_INFO) *allcerts;
565 X509_INFO *xi;
566 if(!(in = BIO_new_file(file, "r"))) return NULL;
567 othercerts = sk_X509_new(NULL);
568 if(!othercerts) return NULL;
569 allcerts = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
570 for(i = 0; i < sk_X509_INFO_num(allcerts); i++) {
571 xi = sk_X509_INFO_value (allcerts, i);
572 if (xi->x509) {
573 sk_X509_push(othercerts, xi->x509);
574 xi->x509 = NULL;
575 }
576 }
577 sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
578 BIO_free(in);
579 return othercerts;
580}
581
582static X509_STORE *setup_verify(char *CAfile, char *CApath)
583{
584 X509_STORE *store;
585 X509_LOOKUP *lookup;
586#ifdef CRYPTO_MDEBUG
587 CRYPTO_push_info("X509_STORE_new");
588#endif
589 if(!(store = X509_STORE_new())) goto end;
590#ifdef CRYPTO_MDEBUG
591 CRYPTO_pop_info();
592 CRYPTO_push_info("X509_STORE_add_lookup(...file)");
593#endif
594 lookup=X509_STORE_add_lookup(store,X509_LOOKUP_file());
595 if (lookup == NULL) goto end;
596#ifdef CRYPTO_MDEBUG
597 CRYPTO_pop_info();
598 CRYPTO_push_info("X509_LOOKUP_load_file");
599#endif
600 if (CAfile) {
601 if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) {
602 BIO_printf(bio_err, "Error loading file %s\n", CAfile);
603 goto end;
604 }
605 } else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
606
607#ifdef CRYPTO_MDEBUG
608 CRYPTO_pop_info();
609 CRYPTO_push_info("X509_STORE_add_lookup(...hash_dir)");
610#endif
611 lookup=X509_STORE_add_lookup(store,X509_LOOKUP_hash_dir());
612 if (lookup == NULL) goto end;
613#ifdef CRYPTO_MDEBUG
614 CRYPTO_pop_info();
615 CRYPTO_push_info("X509_LOOKUP_add_dir");
616#endif
617 if (CApath) {
618 if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) {
619 BIO_printf(bio_err, "Error loading directory %s\n", CApath);
620 goto end;
621 }
622 } else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
623#ifdef CRYPTO_MDEBUG
624 CRYPTO_pop_info();
625#endif
626
627 ERR_clear_error();
628 return store;
629 end:
630 X509_STORE_free(store);
631 return NULL;
632}
633
634static int save_certs(char *signerfile, STACK_OF(X509) *signers)
635{
636 int i;
637 BIO *tmp;
638 if(!signerfile) return 1;
639 tmp = BIO_new_file(signerfile, "w");
640 if(!tmp) return 0;
641 for(i = 0; i < sk_X509_num(signers); i++)
642 PEM_write_bio_X509(tmp, sk_X509_value(signers, i));
643 BIO_free(tmp);
644 return 1;
645}
646
diff --git a/src/lib/libssl/src/apps/spkac.c b/src/lib/libssl/src/apps/spkac.c
new file mode 100644
index 0000000000..b35354a8d7
--- /dev/null
+++ b/src/lib/libssl/src/apps/spkac.c
@@ -0,0 +1,274 @@
1/* apps/spkac.c */
2
3/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
4 * project 1999. Based on an original idea by Massimiliano Pala
5 * (madwolf@openca.org).
6 */
7/* ====================================================================
8 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * licensing@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <time.h>
64#include "apps.h"
65#include <openssl/bio.h>
66#include <openssl/err.h>
67#include <openssl/evp.h>
68#include <openssl/x509.h>
69#include <openssl/pem.h>
70
71#undef PROG
72#define PROG spkac_main
73
74/* -in arg - input file - default stdin
75 * -out arg - output file - default stdout
76 */
77
78int MAIN(int, char **);
79
80int MAIN(int argc, char **argv)
81 {
82 int i,badops=0, ret = 1;
83 BIO *in = NULL,*out = NULL, *key = NULL;
84 int verify=0,noout=0,pubkey=0;
85 char *infile = NULL,*outfile = NULL,*prog;
86 char *passargin = NULL, *passin = NULL;
87 char *spkac = "SPKAC", *spksect = "default", *spkstr = NULL;
88 char *challenge = NULL, *keyfile = NULL;
89 LHASH *conf = NULL;
90 NETSCAPE_SPKI *spki = NULL;
91 EVP_PKEY *pkey = NULL;
92
93 apps_startup();
94
95 if (!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
96
97 prog=argv[0];
98 argc--;
99 argv++;
100 while (argc >= 1)
101 {
102 if (strcmp(*argv,"-in") == 0)
103 {
104 if (--argc < 1) goto bad;
105 infile= *(++argv);
106 }
107 else if (strcmp(*argv,"-out") == 0)
108 {
109 if (--argc < 1) goto bad;
110 outfile= *(++argv);
111 }
112 else if (strcmp(*argv,"-passin") == 0)
113 {
114 if (--argc < 1) goto bad;
115 passargin= *(++argv);
116 }
117 else if (strcmp(*argv,"-key") == 0)
118 {
119 if (--argc < 1) goto bad;
120 keyfile= *(++argv);
121 }
122 else if (strcmp(*argv,"-challenge") == 0)
123 {
124 if (--argc < 1) goto bad;
125 challenge= *(++argv);
126 }
127 else if (strcmp(*argv,"-spkac") == 0)
128 {
129 if (--argc < 1) goto bad;
130 spkac= *(++argv);
131 }
132 else if (strcmp(*argv,"-spksect") == 0)
133 {
134 if (--argc < 1) goto bad;
135 spksect= *(++argv);
136 }
137 else if (strcmp(*argv,"-noout") == 0)
138 noout=1;
139 else if (strcmp(*argv,"-pubkey") == 0)
140 pubkey=1;
141 else if (strcmp(*argv,"-verify") == 0)
142 verify=1;
143 else badops = 1;
144 argc--;
145 argv++;
146 }
147
148 if (badops)
149 {
150bad:
151 BIO_printf(bio_err,"%s [options]\n",prog);
152 BIO_printf(bio_err,"where options are\n");
153 BIO_printf(bio_err," -in arg input file\n");
154 BIO_printf(bio_err," -out arg output file\n");
155 BIO_printf(bio_err," -key arg create SPKAC using private key\n");
156 BIO_printf(bio_err," -passin arg input file pass phrase source\n");
157 BIO_printf(bio_err," -challenge arg challenge string\n");
158 BIO_printf(bio_err," -spkac arg alternative SPKAC name\n");
159 BIO_printf(bio_err," -noout don't print SPKAC\n");
160 BIO_printf(bio_err," -pubkey output public key\n");
161 BIO_printf(bio_err," -verify verify SPKAC signature\n");
162 goto end;
163 }
164
165 ERR_load_crypto_strings();
166 if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
167 BIO_printf(bio_err, "Error getting password\n");
168 goto end;
169 }
170
171 if(keyfile) {
172 if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r");
173 else key = BIO_new_fp(stdin, BIO_NOCLOSE);
174 if(!key) {
175 BIO_printf(bio_err, "Error opening key file\n");
176 ERR_print_errors(bio_err);
177 goto end;
178 }
179 pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, passin);
180 if(!pkey) {
181 BIO_printf(bio_err, "Error reading private key\n");
182 ERR_print_errors(bio_err);
183 goto end;
184 }
185 spki = NETSCAPE_SPKI_new();
186 if(challenge) ASN1_STRING_set(spki->spkac->challenge,
187 challenge, strlen(challenge));
188 NETSCAPE_SPKI_set_pubkey(spki, pkey);
189 NETSCAPE_SPKI_sign(spki, pkey, EVP_md5());
190 spkstr = NETSCAPE_SPKI_b64_encode(spki);
191
192 if (outfile) out = BIO_new_file(outfile, "w");
193 else out = BIO_new_fp(stdout, BIO_NOCLOSE);
194
195 if(!out) {
196 BIO_printf(bio_err, "Error opening output file\n");
197 ERR_print_errors(bio_err);
198 goto end;
199 }
200 BIO_printf(out, "SPKAC=%s\n", spkstr);
201 Free(spkstr);
202 ret = 0;
203 goto end;
204 }
205
206
207
208 if (infile) in = BIO_new_file(infile, "r");
209 else in = BIO_new_fp(stdin, BIO_NOCLOSE);
210
211 if(!in) {
212 BIO_printf(bio_err, "Error opening input file\n");
213 ERR_print_errors(bio_err);
214 goto end;
215 }
216
217 conf = CONF_load_bio(NULL, in, NULL);
218
219 if(!conf) {
220 BIO_printf(bio_err, "Error parsing config file\n");
221 ERR_print_errors(bio_err);
222 goto end;
223 }
224
225 spkstr = CONF_get_string(conf, spksect, spkac);
226
227 if(!spkstr) {
228 BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", spkac);
229 ERR_print_errors(bio_err);
230 goto end;
231 }
232
233 spki = NETSCAPE_SPKI_b64_decode(spkstr, -1);
234
235 if(!spki) {
236 BIO_printf(bio_err, "Error loading SPKAC\n");
237 ERR_print_errors(bio_err);
238 goto end;
239 }
240
241 if (outfile) out = BIO_new_file(outfile, "w");
242 else out = BIO_new_fp(stdout, BIO_NOCLOSE);
243
244 if(!out) {
245 BIO_printf(bio_err, "Error opening output file\n");
246 ERR_print_errors(bio_err);
247 goto end;
248 }
249
250 if(!noout) NETSCAPE_SPKI_print(out, spki);
251 pkey = NETSCAPE_SPKI_get_pubkey(spki);
252 if(verify) {
253 i = NETSCAPE_SPKI_verify(spki, pkey);
254 if(i) BIO_printf(bio_err, "Signature OK\n");
255 else {
256 BIO_printf(bio_err, "Signature Failure\n");
257 ERR_print_errors(bio_err);
258 goto end;
259 }
260 }
261 if(pubkey) PEM_write_bio_PUBKEY(out, pkey);
262
263 ret = 0;
264
265end:
266 CONF_free(conf);
267 NETSCAPE_SPKI_free(spki);
268 BIO_free(in);
269 BIO_free(out);
270 BIO_free(key);
271 EVP_PKEY_free(pkey);
272 if(passin) Free(passin);
273 EXIT(ret);
274 }
diff --git a/src/lib/libssl/src/apps/winrand.c b/src/lib/libssl/src/apps/winrand.c
new file mode 100644
index 0000000000..d042258b50
--- /dev/null
+++ b/src/lib/libssl/src/apps/winrand.c
@@ -0,0 +1,149 @@
1/* apps/winrand.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* Usage: winrand [filename]
57 *
58 * Collects entropy from mouse movements and other events and writes
59 * random data to filename or .rnd
60 */
61
62#include <windows.h>
63#include <openssl/opensslv.h>
64#include <openssl/rand.h>
65
66LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
67const char *filename;
68
69int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
70 PSTR cmdline, int iCmdShow)
71 {
72 static char appname[] = "OpenSSL";
73 HWND hwnd;
74 MSG msg;
75 WNDCLASSEX wndclass;
76 char buffer[200];
77
78 if (cmdline[0] == '\0')
79 filename = RAND_file_name(buffer, sizeof buffer);
80 else
81 filename = cmdline;
82
83 RAND_load_file(filename, -1);
84
85 wndclass.cbSize = sizeof(wndclass);
86 wndclass.style = CS_HREDRAW | CS_VREDRAW;
87 wndclass.lpfnWndProc = WndProc;
88 wndclass.cbClsExtra = 0;
89 wndclass.cbWndExtra = 0;
90 wndclass.hInstance = hInstance;
91 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
92 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
93 wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
94 wndclass.lpszMenuName = NULL;
95 wndclass.lpszClassName = appname;
96 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
97 RegisterClassEx(&wndclass);
98
99 hwnd = CreateWindow(appname, OPENSSL_VERSION_TEXT,
100 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
101 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
102
103 ShowWindow(hwnd, iCmdShow);
104 UpdateWindow(hwnd);
105
106
107 while (GetMessage(&msg, NULL, 0, 0))
108 {
109 TranslateMessage(&msg);
110 DispatchMessage(&msg);
111 }
112
113 return msg.wParam;
114 }
115
116LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
117 {
118 HDC hdc;
119 PAINTSTRUCT ps;
120 RECT rect;
121 char buffer[200];
122 static int seeded = 0;
123
124 switch (iMsg)
125 {
126 case WM_PAINT:
127 hdc = BeginPaint(hwnd, &ps);
128 GetClientRect(hwnd, &rect);
129 DrawText(hdc, "Seeding the PRNG. Please move the mouse!", -1,
130 &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
131 EndPaint(hwnd, &ps);
132 return 0;
133
134 case WM_DESTROY:
135 PostQuitMessage(0);
136 return 0;
137 }
138
139 if (RAND_event(iMsg, wParam, lParam) == 1 && seeded == 0)
140 {
141 seeded = 1;
142 if (RAND_write_file(filename) <= 0)
143 MessageBox(hwnd, "Couldn't write random file!",
144 "OpenSSL", MB_OK | MB_ICONERROR);
145 PostQuitMessage(0);
146 }
147
148 return DefWindowProc(hwnd, iMsg, wParam, lParam);
149 }
diff --git a/src/lib/libssl/src/bugs/ultrixcc.c b/src/lib/libssl/src/bugs/ultrixcc.c
new file mode 100644
index 0000000000..7ba75b140f
--- /dev/null
+++ b/src/lib/libssl/src/bugs/ultrixcc.c
@@ -0,0 +1,45 @@
1#include <stdio.h>
2
3/* This is a cc optimiser bug for ultrix 4.3, mips CPU.
4 * What happens is that the compiler, due to the (a)&7,
5 * does
6 * i=a&7;
7 * i--;
8 * i*=4;
9 * Then uses i as the offset into a jump table.
10 * The problem is that a value of 0 generates an offset of
11 * 0xfffffffc.
12 */
13
14main()
15 {
16 f(5);
17 f(0);
18 }
19
20int f(a)
21int a;
22 {
23 switch(a&7)
24 {
25 case 7:
26 printf("7\n");
27 case 6:
28 printf("6\n");
29 case 5:
30 printf("5\n");
31 case 4:
32 printf("4\n");
33 case 3:
34 printf("3\n");
35 case 2:
36 printf("2\n");
37 case 1:
38 printf("1\n");
39#ifdef FIX_BUG
40 case 0:
41 ;
42#endif
43 }
44 }
45
diff --git a/src/lib/libssl/src/certs/RegTP-5R.pem b/src/lib/libssl/src/certs/RegTP-5R.pem
new file mode 100644
index 0000000000..9eb79aa17c
--- /dev/null
+++ b/src/lib/libssl/src/certs/RegTP-5R.pem
@@ -0,0 +1,19 @@
1issuer= CN=5R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
2notBefore=Mar 22 08:55:51 2000 GMT
3notAfter=Mar 22 08:55:51 2005 GMT
4subject= CN=5R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
5-----BEGIN CERTIFICATE-----
6MIICaDCCAdSgAwIBAgIDDIOqMAoGBiskAwMBAgUAMG8xCzAJBgNVBAYTAkRFMT0w
7OwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21tdW5pa2F0
8aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjVSLUNBIDE6UE4w
9IhgPMjAwMDAzMjIwODU1NTFaGA8yMDA1MDMyMjA4NTU1MVowbzELMAkGA1UEBhMC
10REUxPTA7BgNVBAoUNFJlZ3VsaWVydW5nc2JlaMhvcmRlIGbIdXIgVGVsZWtvbW11
11bmlrYXRpb24gdW5kIFBvc3QxITAMBgcCggYBCgcUEwExMBEGA1UEAxQKNVItQ0Eg
12MTpQTjCBoTANBgkqhkiG9w0BAQEFAAOBjwAwgYsCgYEAih5BUycfBpqKhU8RDsaS
13vV5AtzWeXQRColL9CH3t0DKnhjKAlJ8iccFtJNv+d3bh8bb9sh0maRSo647xP7hs
14HTjKgTE4zM5BYNfXvST79OtcMgAzrnDiGjQIIWv8xbfV1MqxxdtZJygrwzRMb9jG
15CAGoJEymoyzAMNG7tSdBWnUCBQDAAAABoxIwEDAOBgNVHQ8BAf8EBAMCAQYwCgYG
16KyQDAwECBQADgYEAOaK8ihVSBUcL2IdVBxZYYUKwMz5m7H3zqhN8W9w+iafWudH6
17b+aahkbENEwzg3C3v5g8nze7v7ssacQze657LHjP+e7ksUDIgcS4R1pU2eN16bjS
18P/qGPF3rhrIEHoK5nJULkjkZYTtNiOvmQ/+G70TXDi3Os/TwLlWRvu+7YLM=
19-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/RegTP-6R.pem b/src/lib/libssl/src/certs/RegTP-6R.pem
new file mode 100644
index 0000000000..4d79c74e5a
--- /dev/null
+++ b/src/lib/libssl/src/certs/RegTP-6R.pem
@@ -0,0 +1,19 @@
1issuer= CN=6R-Ca 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
2notBefore=Feb 1 09:52:17 2001 GMT
3notAfter=Jun 1 09:52:17 2005 GMT
4subject= CN=6R-Ca 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
5-----BEGIN CERTIFICATE-----
6MIICaDCCAdSgAwIBAgIDMtGNMAoGBiskAwMBAgUAMG8xCzAJBgNVBAYTAkRFMT0w
7OwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21tdW5pa2F0
8aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjZSLUNhIDE6UE4w
9IhgPMjAwMTAyMDEwOTUyMTdaGA8yMDA1MDYwMTA5NTIxN1owbzELMAkGA1UEBhMC
10REUxPTA7BgNVBAoUNFJlZ3VsaWVydW5nc2JlaMhvcmRlIGbIdXIgVGVsZWtvbW11
11bmlrYXRpb24gdW5kIFBvc3QxITAMBgcCggYBCgcUEwExMBEGA1UEAxQKNlItQ2Eg
12MTpQTjCBoTANBgkqhkiG9w0BAQEFAAOBjwAwgYsCgYEAg6KrFSTNXKqe+2GKGeW2
13wTmbVeflNkp5H/YxA9K1zmEn5XjKm0S0jH4Wfms6ipPlURVaFwTfnB1s++AnJAWf
14mayaE9BP/pdIY6WtZGgW6aZc32VDMCMKPWyBNyagsJVDmzlakIA5cXBVa7Xqqd3P
15ew8i2feMnQXcqHfDv02CW88CBQDAAAABoxIwEDAOBgNVHQ8BAf8EBAMCAQYwCgYG
16KyQDAwECBQADgYEAOkqkUwdaTCt8wcJLA2zLuOwL5ADHMWLhv6gr5zEF+VckA6qe
17IVLVf8e7fYlRmzQd+5OJcGglCQJLGT+ZplI3Mjnrd4plkoTNKV4iOzBcvJD7K4tn
18XPvs9wCFcC7QU7PLvc1FDsAlr7e4wyefZRDL+wbqNfI7QZTSF1ubLd9AzeQ=
19-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/expired/ICE-CA.pem b/src/lib/libssl/src/certs/expired/ICE-CA.pem
new file mode 100644
index 0000000000..75652366c2
--- /dev/null
+++ b/src/lib/libssl/src/certs/expired/ICE-CA.pem
@@ -0,0 +1,59 @@
1Certificate:
2 Data:
3 Version: 3 (0x2)
4 Serial Number: 1 (0x1)
5 Signature Algorithm: md5WithRSAEncryption
6 Issuer: O=European ICE-TEL project, OU=V3-Certification Authority
7 Validity
8 Not Before: Apr 2 17:35:53 1997 GMT
9 Not After : Apr 2 17:35:53 1998 GMT
10 Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt
11 Subject Public Key Info:
12 Public Key Algorithm: rsa
13 RSA Public Key: (512 bit)
14 Modulus (512 bit):
15 00:82:75:ba:f6:d1:60:b5:f9:15:b3:6a:dd:29:8f:
16 8b:a4:6f:1a:88:e0:50:43:40:0b:79:41:d5:d3:16:
17 44:7d:74:65:17:42:06:52:0b:e9:50:c8:10:cd:24:
18 e2:ae:8d:22:30:73:e6:b4:b7:93:1f:e5:6e:a2:ae:
19 49:11:a5:c9:45
20 Exponent: 65537 (0x10001)
21 X509v3 extensions:
22 X509v3 Authority Key Identifier:
23 0.........z.."p......e..
24 X509v3 Subject Key Identifier:
25 ..~r..:..B.44fu......3
26 X509v3 Key Usage: critical
27 ....
28 X509v3 Certificate Policies: critical
29 0.0...*...
30 X509v3 Subject Alternative Name:
31 0!..secude-support@darmstadt.gmd.de
32 X509v3 Issuer Alternative Name:
33 0I..ice-tel-ca@darmstadt.gmd.de.*http://www.darmstadt.gmd.de/ice-tel/euroca
34 X509v3 Basic Constraints: critical
35 0....
36 X509v3 CRL Distribution Points:
37 0200...,.*http://www.darmstadt.gmd.de/ice-tel/euroca
38 Signature Algorithm: md5WithRSAEncryption
39 17:a2:88:b7:99:5a:05:41:e4:13:34:67:e6:1f:3e:26:ec:4b:
40 69:f9:3e:28:22:be:9d:1c:ab:41:6f:0c:00:85:fe:45:74:f6:
41 98:f0:ce:9b:65:53:4a:50:42:c7:d4:92:bd:d7:a2:a8:3d:98:
42 88:73:cd:60:28:79:a3:fc:48:7a
43-----BEGIN CERTIFICATE-----
44MIICzDCCAnagAwIBAgIBATANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv
45cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
46QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzU1M1oXDTk4MDQwMjE3MzU1M1owXDEhMB8G
47A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0
48aWZpY2F0aW9uIEF1dGhvcml0eTESMBAGA1UEBxMJRGFybXN0YWR0MFkwCgYEVQgB
49AQICAgADSwAwSAJBAIJ1uvbRYLX5FbNq3SmPi6RvGojgUENAC3lB1dMWRH10ZRdC
50BlIL6VDIEM0k4q6NIjBz5rS3kx/lbqKuSRGlyUUCAwEAAaOCATgwggE0MB8GA1Ud
51IwQYMBaAFIr3yNUOx3ro1yJw4AuJ1bbsZbzPMB0GA1UdDgQWBBR+cvL4OoacQog0
52NGZ1w9T80aIRMzAOBgNVHQ8BAf8EBAMCAfYwFAYDVR0gAQH/BAowCDAGBgQqAwQF
53MCoGA1UdEQQjMCGBH3NlY3VkZS1zdXBwb3J0QGRhcm1zdGFkdC5nbWQuZGUwUgYD
54VR0SBEswSYEbaWNlLXRlbC1jYUBkYXJtc3RhZHQuZ21kLmRlhipodHRwOi8vd3d3
55LmRhcm1zdGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2EwDwYDVR0TAQH/BAUwAwEB
56/zA7BgNVHR8ENDAyMDCgLqAshipodHRwOi8vd3d3LmRhcm1zdGFkdC5nbWQuZGUv
57aWNlLXRlbC9ldXJvY2EwDQYJKoZIhvcNAQEEBQADQQAXooi3mVoFQeQTNGfmHz4m
587Etp+T4oIr6dHKtBbwwAhf5FdPaY8M6bZVNKUELH1JK916KoPZiIc81gKHmj/Eh6
59-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/expired/ICE-root.pem b/src/lib/libssl/src/certs/expired/ICE-root.pem
new file mode 100644
index 0000000000..fa991599c9
--- /dev/null
+++ b/src/lib/libssl/src/certs/expired/ICE-root.pem
@@ -0,0 +1,48 @@
1Certificate:
2 Data:
3 Version: 3 (0x2)
4 Serial Number: 0 (0x0)
5 Signature Algorithm: md5WithRSAEncryption
6 Issuer: O=European ICE-TEL project, OU=V3-Certification Authority
7 Validity
8 Not Before: Apr 2 17:33:36 1997 GMT
9 Not After : Apr 2 17:33:36 1998 GMT
10 Subject: O=European ICE-TEL project, OU=V3-Certification Authority
11 Subject Public Key Info:
12 Public Key Algorithm: rsa
13 RSA Public Key: (512 bit)
14 Modulus (512 bit):
15 00:80:3e:eb:ae:47:a9:fe:10:54:0b:81:8b:9c:2b:
16 82:ab:3a:61:36:65:8b:f3:73:9f:ac:ac:7a:15:a7:
17 13:8f:b4:c4:ba:a3:0f:bc:a5:58:8d:cc:b1:93:31:
18 9e:81:9e:8c:19:61:86:fa:52:73:54:d1:97:76:22:
19 e7:c7:9f:41:cd
20 Exponent: 65537 (0x10001)
21 X509v3 extensions:
22 X509v3 Subject Key Identifier:
23 ........z.."p......e..
24 X509v3 Key Usage: critical
25 ....
26 X509v3 Subject Alternative Name:
27 0I.*http://www.darmstadt.gmd.de/ice-tel/euroca..ice-tel-ca@darmstadt.gmd.de
28 X509v3 Basic Constraints: critical
29 0....
30 Signature Algorithm: md5WithRSAEncryption
31 76:69:61:db:b7:cf:8b:06:9e:d8:8c:96:53:d2:4d:a8:23:a6:
32 03:44:e8:8f:24:a5:c0:84:a8:4b:77:d4:2d:2b:7d:37:91:67:
33 f2:2c:ce:02:31:4c:6b:cc:ce:f2:68:a6:11:11:ab:7d:88:b8:
34 7e:22:9f:25:06:60:bd:79:30:3d
35-----BEGIN CERTIFICATE-----
36MIICFjCCAcCgAwIBAgIBADANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv
37cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
38QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzMzNloXDTk4MDQwMjE3MzMzNlowSDEhMB8G
39A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0
40aWZpY2F0aW9uIEF1dGhvcml0eTBZMAoGBFUIAQECAgIAA0sAMEgCQQCAPuuuR6n+
41EFQLgYucK4KrOmE2ZYvzc5+srHoVpxOPtMS6ow+8pViNzLGTMZ6BnowZYYb6UnNU
420Zd2IufHn0HNAgMBAAGjgZcwgZQwHQYDVR0OBBYEFIr3yNUOx3ro1yJw4AuJ1bbs
43ZbzPMA4GA1UdDwEB/wQEAwIB9jBSBgNVHREESzBJhipodHRwOi8vd3d3LmRhcm1z
44dGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2GBG2ljZS10ZWwtY2FAZGFybXN0YWR0
45LmdtZC5kZTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EAdmlh27fP
46iwae2IyWU9JNqCOmA0TojySlwISoS3fULSt9N5Fn8izOAjFMa8zO8mimERGrfYi4
47fiKfJQZgvXkwPQ==
48-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/expired/ICE-user.pem b/src/lib/libssl/src/certs/expired/ICE-user.pem
new file mode 100644
index 0000000000..28065fd37d
--- /dev/null
+++ b/src/lib/libssl/src/certs/expired/ICE-user.pem
@@ -0,0 +1,63 @@
1Certificate:
2 Data:
3 Version: 3 (0x2)
4 Serial Number: 1 (0x1)
5 Signature Algorithm: md5WithRSAEncryption
6 Issuer: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt
7 Validity
8 Not Before: Apr 2 17:35:59 1997 GMT
9 Not After : Apr 2 17:35:59 1998 GMT
10 Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt, CN=USER
11 Subject Public Key Info:
12 Public Key Algorithm: rsa
13 RSA Public Key: (512 bit)
14 Modulus (512 bit):
15 00:a8:a8:53:63:49:1b:93:c3:c3:0b:6c:88:11:55:
16 de:7e:6a:e2:f9:52:a0:dc:69:25:c4:c8:bf:55:e1:
17 31:a8:ce:e4:a9:29:85:99:8a:15:9a:de:f6:2f:e1:
18 b4:50:5f:5e:04:75:a6:f4:76:dc:3c:0e:39:dc:3a:
19 be:3e:a4:61:8b
20 Exponent: 65537 (0x10001)
21 X509v3 extensions:
22 X509v3 Authority Key Identifier:
23 0...~r..:..B.44fu......3
24 X509v3 Subject Key Identifier:
25 ...... .*...1.*.......
26 X509v3 Key Usage: critical
27 ....
28 X509v3 Certificate Policies: critical
29 0.0...*...0.......
30 X509v3 Subject Alternative Name:
31 0:..user@darmstadt.gmd.de.!http://www.darmstadt.gmd.de/~user
32 X509v3 Issuer Alternative Name:
33 0....gmdca@gmd.de..http://www.gmd.de..saturn.darmstadt.gmd.de.\1!0...U.
34..European ICE-TEL project1#0!..U....V3-Certification Authority1.0...U....Darmstadt..141.12.62.26
35 X509v3 Basic Constraints: critical
36 0.
37 X509v3 CRL Distribution Points:
38 0.0.......gmdca@gmd.de
39 Signature Algorithm: md5WithRSAEncryption
40 69:0c:e1:b7:a7:f2:d8:fb:e8:69:c0:13:cd:37:ad:21:06:22:
41 4d:e8:c6:db:f1:04:0b:b7:e0:b3:d6:0c:81:03:ce:c3:6a:3e:
42 c7:e7:24:24:a4:92:64:c2:83:83:06:42:53:0e:6f:09:1e:84:
43 9a:f7:6f:63:9b:94:99:83:d6:a4
44-----BEGIN CERTIFICATE-----
45MIIDTzCCAvmgAwIBAgIBATANBgkqhkiG9w0BAQQFADBcMSEwHwYDVQQKExhFdXJv
46cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
47QXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHQwHhcNOTcwNDAyMTczNTU5WhcN
48OTgwNDAyMTczNTU5WjBrMSEwHwYDVQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2pl
49Y3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQH
50EwlEYXJtc3RhZHQxDTALBgNVBAMTBFVTRVIwWTAKBgRVCAEBAgICAANLADBIAkEA
51qKhTY0kbk8PDC2yIEVXefmri+VKg3GklxMi/VeExqM7kqSmFmYoVmt72L+G0UF9e
52BHWm9HbcPA453Dq+PqRhiwIDAQABo4IBmDCCAZQwHwYDVR0jBBgwFoAUfnLy+DqG
53nEKINDRmdcPU/NGiETMwHQYDVR0OBBYEFJfc4B8gjSoRmLUx4Sq/ucIYiMrPMA4G
54A1UdDwEB/wQEAwIB8DAcBgNVHSABAf8EEjAQMAYGBCoDBAUwBgYECQgHBjBDBgNV
55HREEPDA6gRV1c2VyQGRhcm1zdGFkdC5nbWQuZGWGIWh0dHA6Ly93d3cuZGFybXN0
56YWR0LmdtZC5kZS9+dXNlcjCBsQYDVR0SBIGpMIGmgQxnbWRjYUBnbWQuZGWGEWh0
57dHA6Ly93d3cuZ21kLmRlghdzYXR1cm4uZGFybXN0YWR0LmdtZC5kZaRcMSEwHwYD
58VQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRp
59ZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHSHDDE0MS4xMi42
60Mi4yNjAMBgNVHRMBAf8EAjAAMB0GA1UdHwQWMBQwEqAQoA6BDGdtZGNhQGdtZC5k
61ZTANBgkqhkiG9w0BAQQFAANBAGkM4ben8tj76GnAE803rSEGIk3oxtvxBAu34LPW
62DIEDzsNqPsfnJCSkkmTCg4MGQlMObwkehJr3b2OblJmD1qQ=
63-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/expired/ICE.crl b/src/lib/libssl/src/certs/expired/ICE.crl
new file mode 100644
index 0000000000..21939e8cc4
--- /dev/null
+++ b/src/lib/libssl/src/certs/expired/ICE.crl
@@ -0,0 +1,9 @@
1-----BEGIN X509 CRL-----
2MIIBNDCBnjANBgkqhkiG9w0BAQIFADBFMSEwHwYDVQQKExhFdXJvcGVhbiBJQ0Ut
3VEVMIFByb2plY3QxIDAeBgNVBAsTF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05
4NzA2MDkxNDQyNDNaFw05NzA3MDkxNDQyNDNaMCgwEgIBChcNOTcwMzAzMTQ0MjU0
5WjASAgEJFw05NjEwMDIxMjI5MjdaMA0GCSqGSIb3DQEBAgUAA4GBAH4vgWo2Tej/
6i7kbiw4Imd30If91iosjClNpBFwvwUDBclPEeMuYimHbLOk4H8Nofc0fw11+U/IO
7KSNouUDcqG7B64oY7c4SXKn+i1MWOb5OJiWeodX3TehHjBlyWzoNMWCnYA8XqFP1
8mOKp8Jla1BibEZf14+/HqCi2hnZUiEXh
9-----END X509 CRL-----
diff --git a/src/lib/libssl/src/certs/expired/rsa-ssca.pem b/src/lib/libssl/src/certs/expired/rsa-ssca.pem
new file mode 100644
index 0000000000..c9403212d1
--- /dev/null
+++ b/src/lib/libssl/src/certs/expired/rsa-ssca.pem
@@ -0,0 +1,19 @@
1subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
2issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
3notBefore=941109235417Z
4notAfter =991231235417Z
5-----BEGIN X509 CERTIFICATE-----
6
7MIICKTCCAZYCBQJBAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw
8HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl
9IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDkyMzU0MTda
10Fw05OTEyMzEyMzU0MTdaMF8xCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0
11YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJlIFNlcnZlciBDZXJ0aWZp
12Y2F0aW9uIEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCSznrB
13roM+WqqJg1esJQF2DK2ujiw3zus1eGRUA+WEQFHJv48I4oqCCNIWhjdV6bEhAq12
14aIGaBaJLyUslZiJWbIgHj/eBWW2EB2VwE3F2Ppt3TONQiVaYSLkdpykaEy5KEVmc
15HhXVSVQsczppgrGXOZxtcGdI5d0t1sgeewIDAQABMA0GCSqGSIb3DQEBAgUAA34A
16iNHReSHO4ovo+MF9NFM/YYPZtgs4F7boviGNjwC4i1N+RGceIr2XJ+CchcxK9oU7
17suK+ktPlDemvXA4MRpX/oRxePug2WHpzpgr4IhFrwwk4fia7c+8AvQKk8xQNMD9h
18cHsg/jKjn7P0Z1LctO6EjJY2IN6BCINxIYoPnqk=
19-----END X509 CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/vsignss.pem b/src/lib/libssl/src/certs/vsignss.pem
new file mode 100644
index 0000000000..5de48bfcf9
--- /dev/null
+++ b/src/lib/libssl/src/certs/vsignss.pem
@@ -0,0 +1,17 @@
1subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
2notBefore=Nov 9 00:00:00 1994 GMT
3notAfter=Jan 7 23:59:59 2010 GMT
4-----BEGIN CERTIFICATE-----
5MIICNDCCAaECEAKtZn5ORf5eV288mBle3cAwDQYJKoZIhvcNAQECBQAwXzELMAkG
6A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD
7VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk0
8MTEwOTAwMDAwMFoXDTEwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxIDAeBgNV
9BAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2Vy
10dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGbMA0GCSqGSIb3DQEBAQUAA4GJ
11ADCBhQJ+AJLOesGugz5aqomDV6wlAXYMra6OLDfO6zV4ZFQD5YRAUcm/jwjiioII
120haGN1XpsSECrXZogZoFokvJSyVmIlZsiAeP94FZbYQHZXATcXY+m3dM41CJVphI
13uR2nKRoTLkoRWZweFdVJVCxzOmmCsZc5nG1wZ0jl3S3WyB57AgMBAAEwDQYJKoZI
14hvcNAQECBQADfgBl3X7hsuyw4jrg7HFGmhkRuNPHoLQDQCYCPgmc4RKz0Vr2N6W3
15YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc
161/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA==
17-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/crypto/aes/README b/src/lib/libssl/src/crypto/aes/README
new file mode 100644
index 0000000000..0f9620a80e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/README
@@ -0,0 +1,3 @@
1This is an OpenSSL-compatible version of AES (also called Rijndael).
2aes_core.c is basically the same as rijndael-alg-fst.c but with an
3API that looks like the rest of the OpenSSL symmetric cipher suite.
diff --git a/src/lib/libssl/src/crypto/aes/aes.h b/src/lib/libssl/src/crypto/aes/aes.h
new file mode 100644
index 0000000000..e8da921ec5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes.h
@@ -0,0 +1,109 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_H
53#define HEADER_AES_H
54
55#ifdef OPENSSL_NO_AES
56#error AES is disabled.
57#endif
58
59static const int AES_DECRYPT = 0;
60static const int AES_ENCRYPT = 1;
61/* Because array size can't be a const in C, the following two are macros.
62 Both sizes are in bytes. */
63#define AES_MAXNR 14
64#define AES_BLOCK_SIZE 16
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/* This should be a hidden type, but EVP requires that the size be known */
71struct aes_key_st {
72 unsigned long rd_key[4 *(AES_MAXNR + 1)];
73 int rounds;
74};
75typedef struct aes_key_st AES_KEY;
76
77const char *AES_options(void);
78
79int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
80 AES_KEY *key);
81int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
82 AES_KEY *key);
83
84void AES_encrypt(const unsigned char *in, unsigned char *out,
85 const AES_KEY *key);
86void AES_decrypt(const unsigned char *in, unsigned char *out,
87 const AES_KEY *key);
88
89void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
90 const AES_KEY *key, const int enc);
91void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
92 const unsigned long length, const AES_KEY *key,
93 unsigned char *ivec, const int enc);
94void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
95 const unsigned long length, const AES_KEY *key,
96 unsigned char *ivec, int *num, const int enc);
97void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
98 const unsigned long length, const AES_KEY *key,
99 unsigned char *ivec, int *num);
100void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
101 const unsigned long length, const AES_KEY *key,
102 unsigned char *counter, unsigned int *num);
103
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* !HEADER_AES_H */
diff --git a/src/lib/libssl/src/crypto/aes/aes_cbc.c b/src/lib/libssl/src/crypto/aes/aes_cbc.c
new file mode 100644
index 0000000000..3dfd7aba2a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_cbc.c
@@ -0,0 +1,89 @@
1/* crypto/aes/aes_cbc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <assert.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
57 const unsigned long length, const AES_KEY *key,
58 unsigned char *ivec, const int enc) {
59
60 int n;
61 unsigned long len = length;
62 unsigned char tmp[16];
63
64 assert(in && out && key && ivec);
65 assert(length % AES_BLOCK_SIZE == 0);
66 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
67
68 if (AES_ENCRYPT == enc)
69 while (len > 0) {
70 for(n=0; n < 16; ++n)
71 tmp[n] = in[n] ^ ivec[n];
72 AES_encrypt(tmp, out, key);
73 memcpy(ivec, out, 16);
74 len -= 16;
75 in += 16;
76 out += 16;
77 }
78 else
79 while (len > 0) {
80 memcpy(tmp, in, 16);
81 AES_decrypt(in, out, key);
82 for(n=0; n < 16; ++n)
83 out[n] ^= ivec[n];
84 memcpy(ivec, tmp, 16);
85 len -= 16;
86 in += 16;
87 out += 16;
88 }
89}
diff --git a/src/lib/libssl/src/crypto/aes/aes_cfb.c b/src/lib/libssl/src/crypto/aes/aes_cfb.c
new file mode 100644
index 0000000000..9b2917298a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_cfb.c
@@ -0,0 +1,151 @@
1/* crypto/aes/aes_cfb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#include <assert.h>
109#include <openssl/aes.h>
110#include "aes_locl.h"
111
112/* The input and output encrypted as though 128bit cfb mode is being
113 * used. The extra state information to record how much of the
114 * 128bit block we have used is contained in *num;
115 */
116
117void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
118 const unsigned long length, const AES_KEY *key,
119 unsigned char *ivec, int *num, const int enc) {
120
121 unsigned int n;
122 unsigned long l = length;
123 unsigned char c;
124
125 assert(in && out && key && ivec && num);
126
127 n = *num;
128
129 if (enc) {
130 while (l--) {
131 if (n == 0) {
132 AES_encrypt(ivec, ivec, key);
133 }
134 ivec[n] = *(out++) = *(in++) ^ ivec[n];
135 n = (n+1) % AES_BLOCK_SIZE;
136 }
137 } else {
138 while (l--) {
139 if (n == 0) {
140 AES_decrypt(ivec, ivec, key);
141 }
142 c = *(in);
143 *(out++) = *(in++) ^ ivec[n];
144 ivec[n] = c;
145 n = (n+1) % AES_BLOCK_SIZE;
146 }
147 }
148
149 *num=n;
150}
151
diff --git a/src/lib/libssl/src/crypto/aes/aes_core.c b/src/lib/libssl/src/crypto/aes/aes_core.c
new file mode 100644
index 0000000000..937988dd8c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_core.c
@@ -0,0 +1,1251 @@
1/* crypto/aes/aes_core.c -*- mode:C; c-file-style: "eay" -*- */
2/**
3 * rijndael-alg-fst.c
4 *
5 * @version 3.0 (December 2000)
6 *
7 * Optimised ANSI C code for the Rijndael cipher (now AES)
8 *
9 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
10 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
11 * @author Paulo Barreto <paulo.barreto@terra.com.br>
12 *
13 * This code is hereby placed in the public domain.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Note: rewritten a little bit to provide error control and an OpenSSL-
29 compatible API */
30
31#include <assert.h>
32#include <stdlib.h>
33#include <openssl/aes.h>
34#include "aes_locl.h"
35
36/*
37Te0[x] = S [x].[02, 01, 01, 03];
38Te1[x] = S [x].[03, 02, 01, 01];
39Te2[x] = S [x].[01, 03, 02, 01];
40Te3[x] = S [x].[01, 01, 03, 02];
41Te4[x] = S [x].[01, 01, 01, 01];
42
43Td0[x] = Si[x].[0e, 09, 0d, 0b];
44Td1[x] = Si[x].[0b, 0e, 09, 0d];
45Td2[x] = Si[x].[0d, 0b, 0e, 09];
46Td3[x] = Si[x].[09, 0d, 0b, 0e];
47Td4[x] = Si[x].[01, 01, 01, 01];
48*/
49
50static const u32 Te0[256] = {
51 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
52 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
53 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
54 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
55 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
56 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
57 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
58 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
59 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
60 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
61 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
62 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
63 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
64 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
65 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
66 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
67 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
68 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
69 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
70 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
71 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
72 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
73 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
74 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
75 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
76 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
77 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
78 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
79 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
80 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
81 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
82 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
83 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
84 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
85 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
86 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
87 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
88 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
89 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
90 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
91 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
92 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
93 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
94 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
95 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
96 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
97 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
98 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
99 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
100 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
101 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
102 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
103 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
104 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
105 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
106 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
107 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
108 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
109 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
110 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
111 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
112 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
113 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
114 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
115};
116static const u32 Te1[256] = {
117 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
118 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
119 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
120 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
121 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
122 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
123 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
124 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
125 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
126 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
127 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
128 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
129 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
130 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
131 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
132 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
133 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
134 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
135 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
136 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
137 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
138 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
139 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
140 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
141 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
142 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
143 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
144 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
145 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
146 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
147 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
148 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
149 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
150 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
151 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
152 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
153 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
154 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
155 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
156 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
157 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
158 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
159 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
160 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
161 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
162 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
163 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
164 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
165 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
166 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
167 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
168 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
169 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
170 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
171 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
172 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
173 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
174 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
175 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
176 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
177 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
178 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
179 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
180 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
181};
182static const u32 Te2[256] = {
183 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
184 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
185 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
186 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
187 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
188 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
189 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
190 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
191 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
192 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
193 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
194 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
195 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
196 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
197 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
198 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
199 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
200 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
201 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
202 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
203 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
204 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
205 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
206 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
207 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
208 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
209 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
210 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
211 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
212 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
213 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
214 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
215 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
216 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
217 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
218 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
219 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
220 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
221 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
222 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
223 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
224 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
225 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
226 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
227 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
228 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
229 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
230 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
231 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
232 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
233 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
234 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
235 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
236 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
237 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
238 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
239 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
240 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
241 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
242 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
243 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
244 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
245 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
246 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
247};
248static const u32 Te3[256] = {
249
250 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
251 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
252 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
253 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
254 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
255 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
256 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
257 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
258 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
259 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
260 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
261 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
262 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
263 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
264 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
265 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
266 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
267 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
268 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
269 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
270 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
271 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
272 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
273 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
274 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
275 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
276 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
277 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
278 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
279 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
280 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
281 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
282 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
283 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
284 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
285 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
286 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
287 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
288 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
289 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
290 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
291 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
292 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
293 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
294 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
295 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
296 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
297 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
298 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
299 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
300 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
301 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
302 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
303 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
304 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
305 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
306 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
307 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
308 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
309 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
310 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
311 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
312 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
313 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
314};
315static const u32 Te4[256] = {
316 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
317 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
318 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
319 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
320 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
321 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
322 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
323 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
324 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
325 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
326 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
327 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
328 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
329 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
330 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
331 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
332 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
333 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
334 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
335 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
336 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
337 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
338 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
339 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
340 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
341 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
342 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
343 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
344 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
345 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
346 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
347 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
348 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
349 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
350 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
351 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
352 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
353 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
354 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
355 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
356 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
357 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
358 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
359 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
360 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
361 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
362 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
363 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
364 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
365 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
366 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
367 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
368 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
369 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
370 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
371 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
372 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
373 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
374 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
375 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
376 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
377 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
378 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
379 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
380};
381static const u32 Td0[256] = {
382 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
383 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
384 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
385 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
386 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
387 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
388 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
389 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
390 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
391 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
392 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
393 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
394 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
395 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
396 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
397 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
398 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
399 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
400 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
401 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
402 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
403 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
404 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
405 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
406 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
407 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
408 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
409 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
410 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
411 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
412 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
413 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
414 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
415 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
416 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
417 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
418 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
419 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
420 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
421 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
422 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
423 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
424 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
425 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
426 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
427 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
428 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
429 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
430 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
431 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
432 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
433 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
434 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
435 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
436 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
437 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
438 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
439 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
440 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
441 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
442 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
443 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
444 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
445 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
446};
447static const u32 Td1[256] = {
448 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
449 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
450 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
451 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
452 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
453 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
454 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
455 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
456 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
457 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
458 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
459 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
460 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
461 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
462 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
463 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
464 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
465 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
466 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
467 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
468 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
469 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
470 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
471 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
472 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
473 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
474 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
475 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
476 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
477 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
478 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
479 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
480 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
481 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
482 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
483 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
484 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
485 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
486 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
487 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
488 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
489 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
490 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
491 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
492 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
493 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
494 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
495 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
496 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
497 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
498 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
499 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
500 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
501 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
502 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
503 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
504 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
505 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
506 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
507 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
508 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
509 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
510 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
511 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
512};
513static const u32 Td2[256] = {
514 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
515 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
516 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
517 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
518 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
519 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
520 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
521 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
522 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
523 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
524 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
525 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
526 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
527 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
528 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
529 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
530 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
531 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
532 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
533 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
534
535 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
536 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
537 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
538 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
539 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
540 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
541 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
542 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
543 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
544 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
545 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
546 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
547 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
548 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
549 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
550 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
551 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
552 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
553 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
554 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
555 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
556 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
557 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
558 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
559 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
560 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
561 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
562 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
563 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
564 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
565 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
566 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
567 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
568 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
569 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
570 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
571 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
572 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
573 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
574 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
575 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
576 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
577 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
578 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
579};
580static const u32 Td3[256] = {
581 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
582 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
583 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
584 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
585 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
586 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
587 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
588 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
589 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
590 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
591 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
592 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
593 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
594 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
595 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
596 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
597 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
598 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
599 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
600 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
601 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
602 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
603 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
604 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
605 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
606 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
607 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
608 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
609 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
610 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
611 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
612 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
613 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
614 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
615 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
616 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
617 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
618 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
619 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
620 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
621 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
622 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
623 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
624 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
625 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
626 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
627 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
628 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
629 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
630 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
631 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
632 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
633 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
634 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
635 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
636 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
637 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
638 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
639 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
640 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
641 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
642 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
643 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
644 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
645};
646static const u32 Td4[256] = {
647 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
648 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
649 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
650 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
651 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
652 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
653 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
654 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
655 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
656 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
657 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
658 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
659 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
660 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
661 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
662 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
663 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
664 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
665 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
666 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
667 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
668 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
669 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
670 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
671 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
672 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
673 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
674 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
675 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
676 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
677 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
678 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
679 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
680 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
681 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
682 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
683 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
684 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
685 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
686 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
687 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
688 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
689 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
690 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
691 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
692 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
693 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
694 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
695 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
696 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
697 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
698 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
699 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
700 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
701 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
702 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
703 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
704 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
705 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
706 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
707 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
708 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
709 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
710 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
711};
712static const u32 rcon[] = {
713 0x01000000, 0x02000000, 0x04000000, 0x08000000,
714 0x10000000, 0x20000000, 0x40000000, 0x80000000,
715 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
716};
717
718/**
719 * Expand the cipher key into the encryption key schedule.
720 */
721int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
722 AES_KEY *key) {
723
724 u32 *rk;
725 int i = 0;
726 u32 temp;
727
728 if (!userKey || !key)
729 return -1;
730 if (bits != 128 && bits != 192 && bits != 256)
731 return -2;
732
733 rk = key->rd_key;
734
735 if (bits==128)
736 key->rounds = 10;
737 else if (bits==192)
738 key->rounds = 12;
739 else
740 key->rounds = 14;
741
742 rk[0] = GETU32(userKey );
743 rk[1] = GETU32(userKey + 4);
744 rk[2] = GETU32(userKey + 8);
745 rk[3] = GETU32(userKey + 12);
746 if (bits == 128) {
747 for (;;) {
748 temp = rk[3];
749 rk[4] = rk[0] ^
750 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
751 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
752 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
753 (Te4[(temp >> 24) ] & 0x000000ff) ^
754 rcon[i];
755 rk[5] = rk[1] ^ rk[4];
756 rk[6] = rk[2] ^ rk[5];
757 rk[7] = rk[3] ^ rk[6];
758 if (++i == 10) {
759 return 0;
760 }
761 rk += 4;
762 }
763 }
764 rk[4] = GETU32(userKey + 16);
765 rk[5] = GETU32(userKey + 20);
766 if (bits == 192) {
767 for (;;) {
768 temp = rk[ 5];
769 rk[ 6] = rk[ 0] ^
770 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
771 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
772 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
773 (Te4[(temp >> 24) ] & 0x000000ff) ^
774 rcon[i];
775 rk[ 7] = rk[ 1] ^ rk[ 6];
776 rk[ 8] = rk[ 2] ^ rk[ 7];
777 rk[ 9] = rk[ 3] ^ rk[ 8];
778 if (++i == 8) {
779 return 0;
780 }
781 rk[10] = rk[ 4] ^ rk[ 9];
782 rk[11] = rk[ 5] ^ rk[10];
783 rk += 6;
784 }
785 }
786 rk[6] = GETU32(userKey + 24);
787 rk[7] = GETU32(userKey + 28);
788 if (bits == 256) {
789 for (;;) {
790 temp = rk[ 7];
791 rk[ 8] = rk[ 0] ^
792 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
793 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
794 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
795 (Te4[(temp >> 24) ] & 0x000000ff) ^
796 rcon[i];
797 rk[ 9] = rk[ 1] ^ rk[ 8];
798 rk[10] = rk[ 2] ^ rk[ 9];
799 rk[11] = rk[ 3] ^ rk[10];
800 if (++i == 7) {
801 return 0;
802 }
803 temp = rk[11];
804 rk[12] = rk[ 4] ^
805 (Te4[(temp >> 24) ] & 0xff000000) ^
806 (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
807 (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
808 (Te4[(temp ) & 0xff] & 0x000000ff);
809 rk[13] = rk[ 5] ^ rk[12];
810 rk[14] = rk[ 6] ^ rk[13];
811 rk[15] = rk[ 7] ^ rk[14];
812
813 rk += 8;
814 }
815 }
816 return 0;
817}
818
819/**
820 * Expand the cipher key into the decryption key schedule.
821 */
822int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
823 AES_KEY *key) {
824
825 u32 *rk;
826 int i, j, status;
827 u32 temp;
828
829 /* first, start with an encryption schedule */
830 status = AES_set_encrypt_key(userKey, bits, key);
831 if (status < 0)
832 return status;
833
834 rk = key->rd_key;
835
836 /* invert the order of the round keys: */
837 for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
838 temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
839 temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
840 temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
841 temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
842 }
843 /* apply the inverse MixColumn transform to all round keys but the first and the last: */
844 for (i = 1; i < (key->rounds); i++) {
845 rk += 4;
846 rk[0] =
847 Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
848 Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
849 Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
850 Td3[Te4[(rk[0] ) & 0xff] & 0xff];
851 rk[1] =
852 Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
853 Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
854 Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
855 Td3[Te4[(rk[1] ) & 0xff] & 0xff];
856 rk[2] =
857 Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
858 Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
859 Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
860 Td3[Te4[(rk[2] ) & 0xff] & 0xff];
861 rk[3] =
862 Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
863 Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
864 Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
865 Td3[Te4[(rk[3] ) & 0xff] & 0xff];
866 }
867 return 0;
868}
869
870/*
871 * Encrypt a single block
872 * in and out can overlap
873 */
874void AES_encrypt(const unsigned char *in, unsigned char *out,
875 const AES_KEY *key) {
876
877 const u32 *rk;
878 u32 s0, s1, s2, s3, t0, t1, t2, t3;
879#ifndef FULL_UNROLL
880 int r;
881#endif /* ?FULL_UNROLL */
882
883 assert(in && out && key);
884 rk = key->rd_key;
885
886 /*
887 * map byte array block to cipher state
888 * and add initial round key:
889 */
890 s0 = GETU32(in ) ^ rk[0];
891 s1 = GETU32(in + 4) ^ rk[1];
892 s2 = GETU32(in + 8) ^ rk[2];
893 s3 = GETU32(in + 12) ^ rk[3];
894#ifdef FULL_UNROLL
895 /* round 1: */
896 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
897 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
898 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
899 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
900 /* round 2: */
901 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
902 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
903 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
904 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
905 /* round 3: */
906 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
907 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
908 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
909 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
910 /* round 4: */
911 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
912 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
913 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
914 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
915 /* round 5: */
916 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
917 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
918 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
919 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
920 /* round 6: */
921 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
922 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
923 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
924 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
925 /* round 7: */
926 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
927 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
928 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
929 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
930 /* round 8: */
931 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
932 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
933 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
934 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
935 /* round 9: */
936 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
937 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
938 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
939 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
940 if (key->rounds > 10) {
941 /* round 10: */
942 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
943 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
944 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
945 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
946 /* round 11: */
947 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
948 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
949 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
950 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
951 if (key->rounds > 12) {
952 /* round 12: */
953 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
954 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
955 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
956 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
957 /* round 13: */
958 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
959 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
960 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
961 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
962 }
963 }
964 rk += key->rounds << 2;
965#else /* !FULL_UNROLL */
966 /*
967 * Nr - 1 full rounds:
968 */
969 r = key->rounds >> 1;
970 for (;;) {
971 t0 =
972 Te0[(s0 >> 24) ] ^
973 Te1[(s1 >> 16) & 0xff] ^
974 Te2[(s2 >> 8) & 0xff] ^
975 Te3[(s3 ) & 0xff] ^
976 rk[4];
977 t1 =
978 Te0[(s1 >> 24) ] ^
979 Te1[(s2 >> 16) & 0xff] ^
980 Te2[(s3 >> 8) & 0xff] ^
981 Te3[(s0 ) & 0xff] ^
982 rk[5];
983 t2 =
984 Te0[(s2 >> 24) ] ^
985 Te1[(s3 >> 16) & 0xff] ^
986 Te2[(s0 >> 8) & 0xff] ^
987 Te3[(s1 ) & 0xff] ^
988 rk[6];
989 t3 =
990 Te0[(s3 >> 24) ] ^
991 Te1[(s0 >> 16) & 0xff] ^
992 Te2[(s1 >> 8) & 0xff] ^
993 Te3[(s2 ) & 0xff] ^
994 rk[7];
995
996 rk += 8;
997 if (--r == 0) {
998 break;
999 }
1000
1001 s0 =
1002 Te0[(t0 >> 24) ] ^
1003 Te1[(t1 >> 16) & 0xff] ^
1004 Te2[(t2 >> 8) & 0xff] ^
1005 Te3[(t3 ) & 0xff] ^
1006 rk[0];
1007 s1 =
1008 Te0[(t1 >> 24) ] ^
1009 Te1[(t2 >> 16) & 0xff] ^
1010 Te2[(t3 >> 8) & 0xff] ^
1011 Te3[(t0 ) & 0xff] ^
1012 rk[1];
1013 s2 =
1014 Te0[(t2 >> 24) ] ^
1015 Te1[(t3 >> 16) & 0xff] ^
1016 Te2[(t0 >> 8) & 0xff] ^
1017 Te3[(t1 ) & 0xff] ^
1018 rk[2];
1019 s3 =
1020 Te0[(t3 >> 24) ] ^
1021 Te1[(t0 >> 16) & 0xff] ^
1022 Te2[(t1 >> 8) & 0xff] ^
1023 Te3[(t2 ) & 0xff] ^
1024 rk[3];
1025 }
1026#endif /* ?FULL_UNROLL */
1027 /*
1028 * apply last round and
1029 * map cipher state to byte array block:
1030 */
1031 s0 =
1032 (Te4[(t0 >> 24) ] & 0xff000000) ^
1033 (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1034 (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1035 (Te4[(t3 ) & 0xff] & 0x000000ff) ^
1036 rk[0];
1037 PUTU32(out , s0);
1038 s1 =
1039 (Te4[(t1 >> 24) ] & 0xff000000) ^
1040 (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1041 (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1042 (Te4[(t0 ) & 0xff] & 0x000000ff) ^
1043 rk[1];
1044 PUTU32(out + 4, s1);
1045 s2 =
1046 (Te4[(t2 >> 24) ] & 0xff000000) ^
1047 (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1048 (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1049 (Te4[(t1 ) & 0xff] & 0x000000ff) ^
1050 rk[2];
1051 PUTU32(out + 8, s2);
1052 s3 =
1053 (Te4[(t3 >> 24) ] & 0xff000000) ^
1054 (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1055 (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1056 (Te4[(t2 ) & 0xff] & 0x000000ff) ^
1057 rk[3];
1058 PUTU32(out + 12, s3);
1059}
1060
1061/*
1062 * Decrypt a single block
1063 * in and out can overlap
1064 */
1065void AES_decrypt(const unsigned char *in, unsigned char *out,
1066 const AES_KEY *key) {
1067
1068 const u32 *rk;
1069 u32 s0, s1, s2, s3, t0, t1, t2, t3;
1070#ifndef FULL_UNROLL
1071 int r;
1072#endif /* ?FULL_UNROLL */
1073
1074 assert(in && out && key);
1075 rk = key->rd_key;
1076
1077 /*
1078 * map byte array block to cipher state
1079 * and add initial round key:
1080 */
1081 s0 = GETU32(in ) ^ rk[0];
1082 s1 = GETU32(in + 4) ^ rk[1];
1083 s2 = GETU32(in + 8) ^ rk[2];
1084 s3 = GETU32(in + 12) ^ rk[3];
1085#ifdef FULL_UNROLL
1086 /* round 1: */
1087 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4];
1088 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5];
1089 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6];
1090 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7];
1091 /* round 2: */
1092 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8];
1093 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9];
1094 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10];
1095 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11];
1096 /* round 3: */
1097 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12];
1098 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13];
1099 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14];
1100 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15];
1101 /* round 4: */
1102 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16];
1103 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17];
1104 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18];
1105 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19];
1106 /* round 5: */
1107 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20];
1108 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21];
1109 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22];
1110 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23];
1111 /* round 6: */
1112 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24];
1113 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25];
1114 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26];
1115 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27];
1116 /* round 7: */
1117 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28];
1118 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29];
1119 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30];
1120 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31];
1121 /* round 8: */
1122 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32];
1123 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33];
1124 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34];
1125 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35];
1126 /* round 9: */
1127 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36];
1128 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37];
1129 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38];
1130 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39];
1131 if (key->rounds > 10) {
1132 /* round 10: */
1133 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40];
1134 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41];
1135 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42];
1136 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43];
1137 /* round 11: */
1138 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44];
1139 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45];
1140 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46];
1141 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47];
1142 if (key->rounds > 12) {
1143 /* round 12: */
1144 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48];
1145 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49];
1146 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50];
1147 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51];
1148 /* round 13: */
1149 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52];
1150 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53];
1151 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54];
1152 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55];
1153 }
1154 }
1155 rk += key->rounds << 2;
1156#else /* !FULL_UNROLL */
1157 /*
1158 * Nr - 1 full rounds:
1159 */
1160 r = key->rounds >> 1;
1161 for (;;) {
1162 t0 =
1163 Td0[(s0 >> 24) ] ^
1164 Td1[(s3 >> 16) & 0xff] ^
1165 Td2[(s2 >> 8) & 0xff] ^
1166 Td3[(s1 ) & 0xff] ^
1167 rk[4];
1168 t1 =
1169 Td0[(s1 >> 24) ] ^
1170 Td1[(s0 >> 16) & 0xff] ^
1171 Td2[(s3 >> 8) & 0xff] ^
1172 Td3[(s2 ) & 0xff] ^
1173 rk[5];
1174 t2 =
1175 Td0[(s2 >> 24) ] ^
1176 Td1[(s1 >> 16) & 0xff] ^
1177 Td2[(s0 >> 8) & 0xff] ^
1178 Td3[(s3 ) & 0xff] ^
1179 rk[6];
1180 t3 =
1181 Td0[(s3 >> 24) ] ^
1182 Td1[(s2 >> 16) & 0xff] ^
1183 Td2[(s1 >> 8) & 0xff] ^
1184 Td3[(s0 ) & 0xff] ^
1185 rk[7];
1186
1187 rk += 8;
1188 if (--r == 0) {
1189 break;
1190 }
1191
1192 s0 =
1193 Td0[(t0 >> 24) ] ^
1194 Td1[(t3 >> 16) & 0xff] ^
1195 Td2[(t2 >> 8) & 0xff] ^
1196 Td3[(t1 ) & 0xff] ^
1197 rk[0];
1198 s1 =
1199 Td0[(t1 >> 24) ] ^
1200 Td1[(t0 >> 16) & 0xff] ^
1201 Td2[(t3 >> 8) & 0xff] ^
1202 Td3[(t2 ) & 0xff] ^
1203 rk[1];
1204 s2 =
1205 Td0[(t2 >> 24) ] ^
1206 Td1[(t1 >> 16) & 0xff] ^
1207 Td2[(t0 >> 8) & 0xff] ^
1208 Td3[(t3 ) & 0xff] ^
1209 rk[2];
1210 s3 =
1211 Td0[(t3 >> 24) ] ^
1212 Td1[(t2 >> 16) & 0xff] ^
1213 Td2[(t1 >> 8) & 0xff] ^
1214 Td3[(t0 ) & 0xff] ^
1215 rk[3];
1216 }
1217#endif /* ?FULL_UNROLL */
1218 /*
1219 * apply last round and
1220 * map cipher state to byte array block:
1221 */
1222 s0 =
1223 (Td4[(t0 >> 24) ] & 0xff000000) ^
1224 (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1225 (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1226 (Td4[(t1 ) & 0xff] & 0x000000ff) ^
1227 rk[0];
1228 PUTU32(out , s0);
1229 s1 =
1230 (Td4[(t1 >> 24) ] & 0xff000000) ^
1231 (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1232 (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1233 (Td4[(t2 ) & 0xff] & 0x000000ff) ^
1234 rk[1];
1235 PUTU32(out + 4, s1);
1236 s2 =
1237 (Td4[(t2 >> 24) ] & 0xff000000) ^
1238 (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1239 (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1240 (Td4[(t3 ) & 0xff] & 0x000000ff) ^
1241 rk[2];
1242 PUTU32(out + 8, s2);
1243 s3 =
1244 (Td4[(t3 >> 24) ] & 0xff000000) ^
1245 (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1246 (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1247 (Td4[(t0 ) & 0xff] & 0x000000ff) ^
1248 rk[3];
1249 PUTU32(out + 12, s3);
1250}
1251
diff --git a/src/lib/libssl/src/crypto/aes/aes_ctr.c b/src/lib/libssl/src/crypto/aes/aes_ctr.c
new file mode 100644
index 0000000000..8e800481de
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_ctr.c
@@ -0,0 +1,117 @@
1/* crypto/aes/aes_ctr.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <assert.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56/* NOTE: CTR mode is big-endian. The rest of the AES code
57 * is endian-neutral. */
58
59/* increment counter (128-bit int) by 2^64 */
60static void AES_ctr128_inc(unsigned char *counter) {
61 unsigned long c;
62
63 /* Grab 3rd dword of counter and increment */
64#ifdef L_ENDIAN
65 c = GETU32(counter + 8);
66 c++;
67 PUTU32(counter + 8, c);
68#else
69 c = GETU32(counter + 4);
70 c++;
71 PUTU32(counter + 4, c);
72#endif
73
74 /* if no overflow, we're done */
75 if (c)
76 return;
77
78 /* Grab top dword of counter and increment */
79#ifdef L_ENDIAN
80 c = GETU32(counter + 12);
81 c++;
82 PUTU32(counter + 12, c);
83#else
84 c = GETU32(counter + 0);
85 c++;
86 PUTU32(counter + 0, c);
87#endif
88
89}
90
91/* The input encrypted as though 128bit counter mode is being
92 * used. The extra state information to record how much of the
93 * 128bit block we have used is contained in *num;
94 */
95void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
96 const unsigned long length, const AES_KEY *key,
97 unsigned char *counter, unsigned int *num) {
98
99 unsigned int n;
100 unsigned long l=length;
101 unsigned char tmp[AES_BLOCK_SIZE];
102
103 assert(in && out && key && counter && num);
104
105 n = *num;
106
107 while (l--) {
108 if (n == 0) {
109 AES_ctr128_inc(counter);
110 AES_encrypt(counter, tmp, key);
111 }
112 *(out++) = *(in++) ^ tmp[n];
113 n = (n+1) % AES_BLOCK_SIZE;
114 }
115
116 *num=n;
117}
diff --git a/src/lib/libssl/src/crypto/aes/aes_ecb.c b/src/lib/libssl/src/crypto/aes/aes_ecb.c
new file mode 100644
index 0000000000..1cb2e07d3d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_ecb.c
@@ -0,0 +1,67 @@
1/* crypto/aes/aes_ecb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <assert.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
57 const AES_KEY *key, const int enc) {
58
59 assert(in && out && key);
60 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
61
62 if (AES_ENCRYPT == enc)
63 AES_encrypt(in, out, key);
64 else
65 AES_decrypt(in, out, key);
66}
67
diff --git a/src/lib/libssl/src/crypto/aes/aes_locl.h b/src/lib/libssl/src/crypto/aes/aes_locl.h
new file mode 100644
index 0000000000..541d1d6e84
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_locl.h
@@ -0,0 +1,88 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_LOCL_H
53#define HEADER_AES_LOCL_H
54
55#include <openssl/e_os2.h>
56
57#ifdef OPENSSL_NO_AES
58#error AES is disabled.
59#endif
60
61#include <stdio.h>
62#include <stdlib.h>
63
64#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
65#include <string.h>
66#endif
67
68#ifdef _MSC_VER
69# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
70# define GETU32(p) SWAP(*((u32 *)(p)))
71# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
72#else
73# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
74# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
75#endif
76
77typedef unsigned long u32;
78typedef unsigned short u16;
79typedef unsigned char u8;
80
81#define MAXKC (256/32)
82#define MAXKB (256/8)
83#define MAXNR 14
84
85/* This controls loop-unrolling in aes_core.c */
86#undef FULL_UNROLL
87
88#endif /* !HEADER_AES_LOCL_H */
diff --git a/src/lib/libssl/src/crypto/aes/aes_misc.c b/src/lib/libssl/src/crypto/aes/aes_misc.c
new file mode 100644
index 0000000000..090def25d5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_misc.c
@@ -0,0 +1,64 @@
1/* crypto/aes/aes_misc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <openssl/opensslv.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56const char *AES_version="AES" OPENSSL_VERSION_PTEXT;
57
58const char *AES_options(void) {
59#ifdef FULL_UNROLL
60 return "aes(full)";
61#else
62 return "aes(partial)";
63#endif
64}
diff --git a/src/lib/libssl/src/crypto/aes/aes_ofb.c b/src/lib/libssl/src/crypto/aes/aes_ofb.c
new file mode 100644
index 0000000000..e33bdaea28
--- /dev/null
+++ b/src/lib/libssl/src/crypto/aes/aes_ofb.c
@@ -0,0 +1,136 @@
1/* crypto/aes/aes_ofb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#include <assert.h>
109#include <openssl/aes.h>
110#include "aes_locl.h"
111
112/* The input and output encrypted as though 128bit ofb mode is being
113 * used. The extra state information to record how much of the
114 * 128bit block we have used is contained in *num;
115 */
116void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
117 const unsigned long length, const AES_KEY *key,
118 unsigned char *ivec, int *num) {
119
120 unsigned int n;
121 unsigned long l=length;
122
123 assert(in && out && key && ivec && num);
124
125 n = *num;
126
127 while (l--) {
128 if (n == 0) {
129 AES_encrypt(ivec, ivec, key);
130 }
131 *(out++) = *(in++) ^ ivec[n];
132 n = (n+1) % AES_BLOCK_SIZE;
133 }
134
135 *num=n;
136}
diff --git a/src/lib/libssl/src/crypto/asn1/a_enum.c b/src/lib/libssl/src/crypto/asn1/a_enum.c
new file mode 100644
index 0000000000..9239ecc439
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_enum.c
@@ -0,0 +1,326 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
69 {
70 int pad=0,ret,r,i,t;
71 unsigned char *p,*n,pb=0;
72
73 if ((a == NULL) || (a->data == NULL)) return(0);
74 t=a->type;
75 if (a->length == 0)
76 ret=1;
77 else
78 {
79 ret=a->length;
80 i=a->data[0];
81 if ((t == V_ASN1_ENUMERATED) && (i > 127)) {
82 pad=1;
83 pb=0;
84 } else if(t == V_ASN1_NEG_ENUMERATED) {
85 if(i>128) {
86 pad=1;
87 pb=0xFF;
88 } else if(i == 128) {
89 for(i = 1; i < a->length; i++) if(a->data[i]) {
90 pad=1;
91 pb=0xFF;
92 break;
93 }
94 }
95 }
96 ret+=pad;
97 }
98 r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED);
99 if (pp == NULL) return(r);
100 p= *pp;
101
102 ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
103 if (pad) *(p++)=pb;
104 if (a->length == 0)
105 *(p++)=0;
106 else if (t == V_ASN1_ENUMERATED)
107 {
108 memcpy(p,a->data,(unsigned int)a->length);
109 p+=a->length;
110 }
111 else {
112 /* Begin at the end of the encoding */
113 n=a->data + a->length - 1;
114 p += a->length - 1;
115 i = a->length;
116 /* Copy zeros to destination as long as source is zero */
117 while(!*n) {
118 *(p--) = 0;
119 n--;
120 i--;
121 }
122 /* Complement and increment next octet */
123 *(p--) = ((*(n--)) ^ 0xff) + 1;
124 i--;
125 /* Complement any octets left */
126 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
127 p += a->length;
128 }
129
130 *pp=p;
131 return(r);
132 }
133
134ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
135 long length)
136 {
137 ASN1_ENUMERATED *ret=NULL;
138 unsigned char *p,*to,*s;
139 long len;
140 int inf,tag,xclass;
141 int i;
142
143 if ((a == NULL) || ((*a) == NULL))
144 {
145 if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL);
146 ret->type=V_ASN1_ENUMERATED;
147 }
148 else
149 ret=(*a);
150
151 p= *pp;
152 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
153 if (inf & 0x80)
154 {
155 i=ASN1_R_BAD_OBJECT_HEADER;
156 goto err;
157 }
158
159 if (tag != V_ASN1_ENUMERATED)
160 {
161 i=ASN1_R_EXPECTING_AN_ENUMERATED;
162 goto err;
163 }
164
165 /* We must Malloc stuff, even for 0 bytes otherwise it
166 * signifies a missing NULL parameter. */
167 s=(unsigned char *)Malloc((int)len+1);
168 if (s == NULL)
169 {
170 i=ERR_R_MALLOC_FAILURE;
171 goto err;
172 }
173 to=s;
174 if (*p & 0x80) /* a negative number */
175 {
176 ret->type=V_ASN1_NEG_ENUMERATED;
177 if ((*p == 0xff) && (len != 1)) {
178 p++;
179 len--;
180 }
181 i = len;
182 p += i - 1;
183 to += i - 1;
184 while((!*p) && i) {
185 *(to--) = 0;
186 i--;
187 p--;
188 }
189 if(!i) {
190 *s = 1;
191 s[len] = 0;
192 p += len;
193 len++;
194 } else {
195 *(to--) = (*(p--) ^ 0xff) + 1;
196 i--;
197 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
198 p += len;
199 }
200 } else {
201 ret->type=V_ASN1_ENUMERATED;
202 if ((*p == 0) && (len != 1))
203 {
204 p++;
205 len--;
206 }
207 memcpy(s,p,(int)len);
208 p+=len;
209 }
210
211 if (ret->data != NULL) Free((char *)ret->data);
212 ret->data=s;
213 ret->length=(int)len;
214 if (a != NULL) (*a)=ret;
215 *pp=p;
216 return(ret);
217err:
218 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
219 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
220 ASN1_ENUMERATED_free(ret);
221 return(NULL);
222 }
223
224int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
225 {
226 int i,j,k;
227 unsigned char buf[sizeof(long)+1];
228 long d;
229
230 a->type=V_ASN1_ENUMERATED;
231 if (a->length < (sizeof(long)+1))
232 {
233 if (a->data != NULL)
234 Free((char *)a->data);
235 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
236 memset((char *)a->data,0,sizeof(long)+1);
237 }
238 if (a->data == NULL)
239 {
240 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
241 return(0);
242 }
243 d=v;
244 if (d < 0)
245 {
246 d= -d;
247 a->type=V_ASN1_NEG_ENUMERATED;
248 }
249
250 for (i=0; i<sizeof(long); i++)
251 {
252 if (d == 0) break;
253 buf[i]=(int)d&0xff;
254 d>>=8;
255 }
256 j=0;
257 for (k=i-1; k >=0; k--)
258 a->data[j++]=buf[k];
259 a->length=j;
260 return(1);
261 }
262
263long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
264 {
265 int neg=0,i;
266 long r=0;
267
268 if (a == NULL) return(0L);
269 i=a->type;
270 if (i == V_ASN1_NEG_ENUMERATED)
271 neg=1;
272 else if (i != V_ASN1_ENUMERATED)
273 return(0);
274
275 if (a->length > sizeof(long))
276 {
277 /* hmm... a bit ugly */
278 return(0xffffffffL);
279 }
280 if (a->data == NULL)
281 return(0);
282
283 for (i=0; i<a->length; i++)
284 {
285 r<<=8;
286 r|=(unsigned char)a->data[i];
287 }
288 if (neg) r= -r;
289 return(r);
290 }
291
292ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
293 {
294 ASN1_ENUMERATED *ret;
295 int len,j;
296
297 if (ai == NULL)
298 ret=ASN1_ENUMERATED_new();
299 else
300 ret=ai;
301 if (ret == NULL)
302 {
303 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
304 goto err;
305 }
306 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
307 else ret->type=V_ASN1_ENUMERATED;
308 j=BN_num_bits(bn);
309 len=((j == 0)?0:((j/8)+1));
310 ret->data=(unsigned char *)Malloc(len+4);
311 ret->length=BN_bn2bin(bn,ret->data);
312 return(ret);
313err:
314 if (ret != ai) ASN1_ENUMERATED_free(ret);
315 return(NULL);
316 }
317
318BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
319 {
320 BIGNUM *ret;
321
322 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
323 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
324 if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1;
325 return(ret);
326 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_gentm.c b/src/lib/libssl/src/crypto/asn1/a_gentm.c
new file mode 100644
index 0000000000..226474f057
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_gentm.c
@@ -0,0 +1,224 @@
1/* crypto/asn1/a_gentm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */
60
61#include <stdio.h>
62#include <time.h>
63#include "cryptlib.h"
64#include <openssl/asn1.h>
65
66int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
67 {
68#ifdef CHARSET_EBCDIC
69 /* KLUDGE! We convert to ascii before writing DER */
70 int len;
71 char tmp[24];
72 ASN1_STRING tmpstr = *(ASN1_STRING *)a;
73
74 len = tmpstr.length;
75 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
76 tmpstr.data = tmp;
77
78 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
79#endif
80 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
81 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
82 }
83
84
85ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
86 unsigned char **pp, long length)
87 {
88 ASN1_GENERALIZEDTIME *ret=NULL;
89
90 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
91 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
92 if (ret == NULL)
93 {
94 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
95 return(NULL);
96 }
97#ifdef CHARSET_EBCDIC
98 ascii2ebcdic(ret->data, ret->data, ret->length);
99#endif
100 if (!ASN1_GENERALIZEDTIME_check(ret))
101 {
102 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
103 goto err;
104 }
105
106 return(ret);
107err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 ASN1_GENERALIZEDTIME_free(ret);
110 return(NULL);
111 }
112
113int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
114 {
115 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
116 static int max[9]={99, 99,12,31,23,59,59,12,59};
117 char *a;
118 int n,i,l,o;
119
120 if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
121 l=d->length;
122 a=(char *)d->data;
123 o=0;
124 /* GENERALIZEDTIME is similar to UTCTIME except the year is
125 * represented as YYYY. This stuff treats everything as a two digit
126 * field so make first two fields 00 to 99
127 */
128 if (l < 13) goto err;
129 for (i=0; i<7; i++)
130 {
131 if ((i == 6) && ((a[o] == 'Z') ||
132 (a[o] == '+') || (a[o] == '-')))
133 { i++; break; }
134 if ((a[o] < '0') || (a[o] > '9')) goto err;
135 n= a[o]-'0';
136 if (++o > l) goto err;
137
138 if ((a[o] < '0') || (a[o] > '9')) goto err;
139 n=(n*10)+ a[o]-'0';
140 if (++o > l) goto err;
141
142 if ((n < min[i]) || (n > max[i])) goto err;
143 }
144 if (a[o] == 'Z')
145 o++;
146 else if ((a[o] == '+') || (a[o] == '-'))
147 {
148 o++;
149 if (o+4 > l) goto err;
150 for (i=7; i<9; i++)
151 {
152 if ((a[o] < '0') || (a[o] > '9')) goto err;
153 n= a[o]-'0';
154 o++;
155 if ((a[o] < '0') || (a[o] > '9')) goto err;
156 n=(n*10)+ a[o]-'0';
157 if ((n < min[i]) || (n > max[i])) goto err;
158 o++;
159 }
160 }
161 return(o == l);
162err:
163 return(0);
164 }
165
166int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
167 {
168 ASN1_GENERALIZEDTIME t;
169
170 t.type=V_ASN1_GENERALIZEDTIME;
171 t.length=strlen(str);
172 t.data=(unsigned char *)str;
173 if (ASN1_GENERALIZEDTIME_check(&t))
174 {
175 if (s != NULL)
176 {
177 ASN1_STRING_set((ASN1_STRING *)s,
178 (unsigned char *)str,t.length);
179 }
180 return(1);
181 }
182 else
183 return(0);
184 }
185
186ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
187 time_t t)
188 {
189 char *p;
190 struct tm *ts;
191#if defined(THREADS) && !defined(WIN32)
192 struct tm data;
193#endif
194
195 if (s == NULL)
196 s=ASN1_GENERALIZEDTIME_new();
197 if (s == NULL)
198 return(NULL);
199
200#if defined(THREADS) && !defined(WIN32)
201 gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
202 ts=&data;
203#else
204 ts=gmtime(&t);
205#endif
206 p=(char *)s->data;
207 if ((p == NULL) || (s->length < 16))
208 {
209 p=Malloc(20);
210 if (p == NULL) return(NULL);
211 if (s->data != NULL)
212 Free(s->data);
213 s->data=(unsigned char *)p;
214 }
215
216 sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
217 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
218 s->length=strlen(p);
219 s->type=V_ASN1_GENERALIZEDTIME;
220#ifdef CHARSET_EBCDIC_not
221 ebcdic2ascii(s->data, s->data, s->length);
222#endif
223 return(s);
224 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_mbstr.c b/src/lib/libssl/src/crypto/asn1/a_mbstr.c
new file mode 100644
index 0000000000..7a710d5459
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_mbstr.c
@@ -0,0 +1,390 @@
1/* a_mbstr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63
64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg);
69static int cpy_asc(unsigned long value, void *arg);
70static int cpy_bmp(unsigned long value, void *arg);
71static int cpy_univ(unsigned long value, void *arg);
72static int cpy_utf8(unsigned long value, void *arg);
73static int is_printable(unsigned long value);
74
75/* These functions take a string in UTF8, ASCII or multibyte form and
76 * a mask of permissible ASN1 string types. It then works out the minimal
77 * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
78 * and creates a string of the correct type with the supplied data.
79 * Yes this is horrible: it has to be :-(
80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */
82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
84 int inform, unsigned long mask)
85{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87}
88
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
90 int inform, unsigned long mask,
91 long minsize, long maxsize)
92{
93 int str_type;
94 int ret;
95 int outform, outlen;
96 ASN1_STRING *dest;
97 unsigned char *p;
98 int nchar;
99 char strbuf[32];
100 int (*cpyfunc)(unsigned long,void *) = NULL;
101 if(len == -1) len = strlen((const char *)in);
102 if(!mask) mask = DIRSTRING_TYPE;
103
104 /* First do a string check and work out the number of characters */
105 switch(inform) {
106
107 case MBSTRING_BMP:
108 if(len & 1) {
109 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
110 ASN1_R_INVALID_BMPSTRING_LENGTH);
111 return -1;
112 }
113 nchar = len >> 1;
114 break;
115
116 case MBSTRING_UNIV:
117 if(len & 3) {
118 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
119 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
120 return -1;
121 }
122 nchar = len >> 2;
123 break;
124
125 case MBSTRING_UTF8:
126 nchar = 0;
127 /* This counts the characters and does utf8 syntax checking */
128 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
129 if(ret < 0) {
130 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
131 ASN1_R_INVALID_UTF8STRING);
132 return -1;
133 }
134 break;
135
136 case MBSTRING_ASC:
137 nchar = len;
138 break;
139
140 default:
141 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
142 return -1;
143 }
144
145 if((minsize > 0) && (nchar < minsize)) {
146 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
147 sprintf(strbuf, "%ld", minsize);
148 ERR_add_error_data(2, "minsize=", strbuf);
149 return -1;
150 }
151
152 if((maxsize > 0) && (nchar > maxsize)) {
153 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
154 sprintf(strbuf, "%ld", maxsize);
155 ERR_add_error_data(2, "maxsize=", strbuf);
156 return -1;
157 }
158
159 /* Now work out minimal type (if any) */
160 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
161 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
162 return -1;
163 }
164
165
166 /* Now work out output format and string type */
167 outform = MBSTRING_ASC;
168 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
169 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
170 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
171 else if(mask & B_ASN1_BMPSTRING) {
172 str_type = V_ASN1_BMPSTRING;
173 outform = MBSTRING_BMP;
174 } else if(mask & B_ASN1_UNIVERSALSTRING) {
175 str_type = V_ASN1_UNIVERSALSTRING;
176 outform = MBSTRING_UNIV;
177 } else {
178 str_type = V_ASN1_UTF8STRING;
179 outform = MBSTRING_UTF8;
180 }
181 if(!out) return str_type;
182 if(*out) {
183 dest = *out;
184 if(dest->data) {
185 dest->length = 0;
186 Free(dest->data);
187 dest->data = NULL;
188 }
189 dest->type = str_type;
190 } else {
191 dest = ASN1_STRING_type_new(str_type);
192 if(!dest) {
193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
194 ERR_R_MALLOC_FAILURE);
195 return -1;
196 }
197 *out = dest;
198 }
199 /* If both the same type just copy across */
200 if(inform == outform) {
201 if(!ASN1_STRING_set(dest, in, len)) {
202 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
203 return -1;
204 }
205 return str_type;
206 }
207
208 /* Work out how much space the destination will need */
209 switch(outform) {
210 case MBSTRING_ASC:
211 outlen = nchar;
212 cpyfunc = cpy_asc;
213 break;
214
215 case MBSTRING_BMP:
216 outlen = nchar << 1;
217 cpyfunc = cpy_bmp;
218 break;
219
220 case MBSTRING_UNIV:
221 outlen = nchar << 2;
222 cpyfunc = cpy_univ;
223 break;
224
225 case MBSTRING_UTF8:
226 outlen = 0;
227 traverse_string(in, len, inform, out_utf8, &outlen);
228 cpyfunc = cpy_utf8;
229 break;
230 }
231 if(!(p = Malloc(outlen + 1))) {
232 ASN1_STRING_free(dest);
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
234 return -1;
235 }
236 dest->length = outlen;
237 dest->data = p;
238 p[outlen] = 0;
239 traverse_string(in, len, inform, cpyfunc, &p);
240 return str_type;
241}
242
243/* This function traverses a string and passes the value of each character
244 * to an optional function along with a void * argument.
245 */
246
247static int traverse_string(const unsigned char *p, int len, int inform,
248 int (*rfunc)(unsigned long value, void *in), void *arg)
249{
250 unsigned long value;
251 int ret;
252 while(len) {
253 if(inform == MBSTRING_ASC) {
254 value = *p++;
255 len--;
256 } else if(inform == MBSTRING_BMP) {
257 value = *p++ << 8;
258 value |= *p++;
259 len -= 2;
260 } else if(inform == MBSTRING_UNIV) {
261 value = *p++ << 24;
262 value |= *p++ << 16;
263 value |= *p++ << 8;
264 value |= *p++;
265 len -= 4;
266 } else {
267 ret = UTF8_getc(p, len, &value);
268 if(ret < 0) return -1;
269 len -= ret;
270 p += ret;
271 }
272 if(rfunc) {
273 ret = rfunc(value, arg);
274 if(ret <= 0) return ret;
275 }
276 }
277 return 1;
278}
279
280/* Various utility functions for traverse_string */
281
282/* Just count number of characters */
283
284static int in_utf8(unsigned long value, void *arg)
285{
286 int *nchar;
287 nchar = arg;
288 (*nchar)++;
289 return 1;
290}
291
292/* Determine size of output as a UTF8 String */
293
294static int out_utf8(unsigned long value, void *arg)
295{
296 long *outlen;
297 outlen = arg;
298 *outlen += UTF8_putc(NULL, -1, value);
299 return 1;
300}
301
302/* Determine the "type" of a string: check each character against a
303 * supplied "mask".
304 */
305
306static int type_str(unsigned long value, void *arg)
307{
308 unsigned long types;
309 types = *((unsigned long *)arg);
310 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
311 types &= ~B_ASN1_PRINTABLESTRING;
312 if((types & B_ASN1_IA5STRING) && (value > 127))
313 types &= ~B_ASN1_IA5STRING;
314 if((types & B_ASN1_T61STRING) && (value > 0xff))
315 types &= ~B_ASN1_T61STRING;
316 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
317 types &= ~B_ASN1_BMPSTRING;
318 if(!types) return -1;
319 *((unsigned long *)arg) = types;
320 return 1;
321}
322
323/* Copy one byte per character ASCII like strings */
324
325static int cpy_asc(unsigned long value, void *arg)
326{
327 unsigned char **p, *q;
328 p = arg;
329 q = *p;
330 *q = (unsigned char) value;
331 (*p)++;
332 return 1;
333}
334
335/* Copy two byte per character BMPStrings */
336
337static int cpy_bmp(unsigned long value, void *arg)
338{
339 unsigned char **p, *q;
340 p = arg;
341 q = *p;
342 *q++ = (unsigned char) ((value >> 8) & 0xff);
343 *q = (unsigned char) (value & 0xff);
344 *p += 2;
345 return 1;
346}
347
348/* Copy four byte per character UniversalStrings */
349
350static int cpy_univ(unsigned long value, void *arg)
351{
352 unsigned char **p, *q;
353 p = arg;
354 q = *p;
355 *q++ = (unsigned char) ((value >> 24) & 0xff);
356 *q++ = (unsigned char) ((value >> 16) & 0xff);
357 *q++ = (unsigned char) ((value >> 8) & 0xff);
358 *q = (unsigned char) (value & 0xff);
359 *p += 4;
360 return 1;
361}
362
363/* Copy to a UTF8String */
364
365static int cpy_utf8(unsigned long value, void *arg)
366{
367 unsigned char **p;
368 int ret;
369 p = arg;
370 /* We already know there is enough room so pass 0xff as the length */
371 ret = UTF8_putc(*p, 0xff, value);
372 *p += ret;
373 return 1;
374}
375
376/* Return 1 if the character is permitted in a PrintableString */
377static int is_printable(unsigned long value)
378{
379 int ch;
380 if(value > 0x7f) return 0;
381 ch = (int) value;
382 /* Note: we can't use 'isalnum' because certain accented
383 * characters may count as alphanumeric in some environments.
384 */
385 if((ch >= 'a') && (ch <= 'z')) return 1;
386 if((ch >= 'A') && (ch <= 'Z')) return 1;
387 if((ch >= '0') && (ch <= '9')) return 1;
388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
389 return 0;
390}
diff --git a/src/lib/libssl/src/crypto/asn1/a_strex.c b/src/lib/libssl/src/crypto/asn1/a_strex.c
new file mode 100644
index 0000000000..569b811998
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_strex.c
@@ -0,0 +1,533 @@
1/* a_strex.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63#include <openssl/asn1.h>
64
65#include "charmap.h"
66
67/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
68 * Enhanced string and name printing routines handling
69 * multibyte characters, RFC2253 and a host of other
70 * options.
71 */
72
73
74#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
75
76
77/* Three IO functions for sending data to memory, a BIO and
78 * and a FILE pointer.
79 */
80
81int send_mem_chars(void *arg, const void *buf, int len)
82{
83 unsigned char **out = arg;
84 if(!out) return 1;
85 memcpy(*out, buf, len);
86 *out += len;
87 return 1;
88}
89
90int send_bio_chars(void *arg, const void *buf, int len)
91{
92 if(!arg) return 1;
93 if(BIO_write(arg, buf, len) != len) return 0;
94 return 1;
95}
96
97int send_fp_chars(void *arg, const void *buf, int len)
98{
99 if(!arg) return 1;
100 if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0;
101 return 1;
102}
103
104typedef int char_io(void *arg, const void *buf, int len);
105
106/* This function handles display of
107 * strings, one character at a time.
108 * It is passed an unsigned long for each
109 * character because it could come from 2 or even
110 * 4 byte forms.
111 */
112
113static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
114{
115 unsigned char chflgs, chtmp;
116 char tmphex[11];
117 if(c > 0xffff) {
118 BIO_snprintf(tmphex, 11, "\\W%08lX", c);
119 if(!io_ch(arg, tmphex, 10)) return -1;
120 return 10;
121 }
122 if(c > 0xff) {
123 BIO_snprintf(tmphex, 11, "\\U%04lX", c);
124 if(!io_ch(arg, tmphex, 6)) return -1;
125 return 6;
126 }
127 chtmp = (unsigned char)c;
128 if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB;
129 else chflgs = char_type[chtmp] & flags;
130 if(chflgs & CHARTYPE_BS_ESC) {
131 /* If we don't escape with quotes, signal we need quotes */
132 if(chflgs & ASN1_STRFLGS_ESC_QUOTE) {
133 if(do_quotes) *do_quotes = 1;
134 if(!io_ch(arg, &chtmp, 1)) return -1;
135 return 1;
136 }
137 if(!io_ch(arg, "\\", 1)) return -1;
138 if(!io_ch(arg, &chtmp, 1)) return -1;
139 return 2;
140 }
141 if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
142 BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
143 if(!io_ch(arg, tmphex, 3)) return -1;
144 return 3;
145 }
146 if(!io_ch(arg, &chtmp, 1)) return -1;
147 return 1;
148}
149
150#define BUF_TYPE_WIDTH_MASK 0x7
151#define BUF_TYPE_CONVUTF8 0x8
152
153/* This function sends each character in a buffer to
154 * do_esc_char(). It interprets the content formats
155 * and converts to or from UTF8 as appropriate.
156 */
157
158static int do_buf(unsigned char *buf, int buflen,
159 int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
160{
161 int i, outlen, len;
162 unsigned char orflags, *p, *q;
163 unsigned long c;
164 p = buf;
165 q = buf + buflen;
166 outlen = 0;
167 while(p != q) {
168 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
169 else orflags = 0;
170 switch(type & BUF_TYPE_WIDTH_MASK) {
171 case 4:
172 c = ((unsigned long)*p++) << 24;
173 c |= ((unsigned long)*p++) << 16;
174 c |= ((unsigned long)*p++) << 8;
175 c |= *p++;
176 break;
177
178 case 2:
179 c = ((unsigned long)*p++) << 8;
180 c |= *p++;
181 break;
182
183 case 1:
184 c = *p++;
185 break;
186
187 case 0:
188 i = UTF8_getc(p, buflen, &c);
189 if(i < 0) return -1; /* Invalid UTF8String */
190 p += i;
191 break;
192 }
193 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
194 if(type & BUF_TYPE_CONVUTF8) {
195 unsigned char utfbuf[6];
196 int utflen;
197 utflen = UTF8_putc(utfbuf, 6, c);
198 for(i = 0; i < utflen; i++) {
199 /* We don't need to worry about setting orflags correctly
200 * because if utflen==1 its value will be correct anyway
201 * otherwise each character will be > 0x7f and so the
202 * character will never be escaped on first and last.
203 */
204 len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg);
205 if(len < 0) return -1;
206 outlen += len;
207 }
208 } else {
209 len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg);
210 if(len < 0) return -1;
211 outlen += len;
212 }
213 }
214 return outlen;
215}
216
217/* This function hex dumps a buffer of characters */
218
219static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
220{
221 const static char hexdig[] = "0123456789ABCDEF";
222 unsigned char *p, *q;
223 char hextmp[2];
224 if(arg) {
225 p = buf;
226 q = buf + buflen;
227 while(p != q) {
228 hextmp[0] = hexdig[*p >> 4];
229 hextmp[1] = hexdig[*p & 0xf];
230 if(!io_ch(arg, hextmp, 2)) return -1;
231 p++;
232 }
233 }
234 return buflen << 1;
235}
236
237/* "dump" a string. This is done when the type is unknown,
238 * or the flags request it. We can either dump the content
239 * octets or the entire DER encoding. This uses the RFC2253
240 * #01234 format.
241 */
242
243int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
244{
245 /* Placing the ASN1_STRING in a temp ASN1_TYPE allows
246 * the DER encoding to readily obtained
247 */
248 ASN1_TYPE t;
249 unsigned char *der_buf, *p;
250 int outlen, der_len;
251
252 if(!io_ch(arg, "#", 1)) return -1;
253 /* If we don't dump DER encoding just dump content octets */
254 if(!(lflags & ASN1_STRFLGS_DUMP_DER)) {
255 outlen = do_hex_dump(io_ch, arg, str->data, str->length);
256 if(outlen < 0) return -1;
257 return outlen + 1;
258 }
259 t.type = str->type;
260 t.value.ptr = (char *)str;
261 der_len = i2d_ASN1_TYPE(&t, NULL);
262 der_buf = OPENSSL_malloc(der_len);
263 if(!der_buf) return -1;
264 p = der_buf;
265 i2d_ASN1_TYPE(&t, &p);
266 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
267 OPENSSL_free(der_buf);
268 if(outlen < 0) return -1;
269 return outlen + 1;
270}
271
272/* Lookup table to convert tags to character widths,
273 * 0 = UTF8 encoded, -1 is used for non string types
274 * otherwise it is the number of bytes per character
275 */
276
277const static char tag2nbyte[] = {
278 -1, -1, -1, -1, -1, /* 0-4 */
279 -1, -1, -1, -1, -1, /* 5-9 */
280 -1, -1, 0, -1, /* 10-13 */
281 -1, -1, -1, -1, /* 15-17 */
282 -1, 1, 1, /* 18-20 */
283 -1, 1, -1,-1, /* 21-24 */
284 -1, 1, -1, /* 25-27 */
285 4, -1, 2 /* 28-30 */
286};
287
288#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
289 ASN1_STRFLGS_ESC_QUOTE | \
290 ASN1_STRFLGS_ESC_CTRL | \
291 ASN1_STRFLGS_ESC_MSB)
292
293/* This is the main function, print out an
294 * ASN1_STRING taking note of various escape
295 * and display options. Returns number of
296 * characters written or -1 if an error
297 * occurred.
298 */
299
300static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
301{
302 int outlen, len;
303 int type;
304 char quotes;
305 unsigned char flags;
306 quotes = 0;
307 /* Keep a copy of escape flags */
308 flags = (unsigned char)(lflags & ESC_FLAGS);
309
310 type = str->type;
311
312 outlen = 0;
313
314
315 if(lflags & ASN1_STRFLGS_SHOW_TYPE) {
316 const char *tagname;
317 tagname = ASN1_tag2str(type);
318 outlen += strlen(tagname);
319 if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1;
320 outlen++;
321 }
322
323 /* Decide what to do with type, either dump content or display it */
324
325 /* Dump everything */
326 if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1;
327 /* Ignore the string type */
328 else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1;
329 else {
330 /* Else determine width based on type */
331 if((type > 0) && (type < 31)) type = tag2nbyte[type];
332 else type = -1;
333 if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1;
334 }
335
336 if(type == -1) {
337 len = do_dump(lflags, io_ch, arg, str);
338 if(len < 0) return -1;
339 outlen += len;
340 return outlen;
341 }
342
343 if(lflags & ASN1_STRFLGS_UTF8_CONVERT) {
344 /* Note: if string is UTF8 and we want
345 * to convert to UTF8 then we just interpret
346 * it as 1 byte per character to avoid converting
347 * twice.
348 */
349 if(!type) type = 1;
350 else type |= BUF_TYPE_CONVUTF8;
351 }
352
353 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
354 if(outlen < 0) return -1;
355 outlen += len;
356 if(quotes) outlen += 2;
357 if(!arg) return outlen;
358 if(quotes && !io_ch(arg, "\"", 1)) return -1;
359 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
360 if(quotes && !io_ch(arg, "\"", 1)) return -1;
361 return outlen;
362}
363
364/* Used for line indenting: print 'indent' spaces */
365
366static int do_indent(char_io *io_ch, void *arg, int indent)
367{
368 int i;
369 for(i = 0; i < indent; i++)
370 if(!io_ch(arg, " ", 1)) return 0;
371 return 1;
372}
373
374
375static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
376 int indent, unsigned long flags)
377{
378 int i, prev = -1, orflags, cnt;
379 int fn_opt, fn_nid;
380 ASN1_OBJECT *fn;
381 ASN1_STRING *val;
382 X509_NAME_ENTRY *ent;
383 char objtmp[80];
384 const char *objbuf;
385 int outlen, len;
386 char *sep_dn, *sep_mv, *sep_eq;
387 int sep_dn_len, sep_mv_len, sep_eq_len;
388 if(indent < 0) indent = 0;
389 outlen = indent;
390 if(!do_indent(io_ch, arg, indent)) return -1;
391 switch (flags & XN_FLAG_SEP_MASK)
392 {
393 case XN_FLAG_SEP_MULTILINE:
394 sep_dn = "\n";
395 sep_dn_len = 1;
396 sep_mv = " + ";
397 sep_mv_len = 3;
398 break;
399
400 case XN_FLAG_SEP_COMMA_PLUS:
401 sep_dn = ",";
402 sep_dn_len = 1;
403 sep_mv = "+";
404 sep_mv_len = 1;
405 indent = 0;
406 break;
407
408 case XN_FLAG_SEP_CPLUS_SPC:
409 sep_dn = ", ";
410 sep_dn_len = 2;
411 sep_mv = " + ";
412 sep_mv_len = 3;
413 indent = 0;
414 break;
415
416 case XN_FLAG_SEP_SPLUS_SPC:
417 sep_dn = "; ";
418 sep_dn_len = 2;
419 sep_mv = " + ";
420 sep_mv_len = 3;
421 indent = 0;
422 break;
423
424 default:
425 return -1;
426 }
427
428 if(flags & XN_FLAG_SPC_EQ) {
429 sep_eq = " = ";
430 sep_eq_len = 3;
431 } else {
432 sep_eq = "=";
433 sep_eq_len = 1;
434 }
435
436 fn_opt = flags & XN_FLAG_FN_MASK;
437
438 cnt = X509_NAME_entry_count(n);
439 for(i = 0; i < cnt; i++) {
440 if(flags & XN_FLAG_DN_REV)
441 ent = X509_NAME_get_entry(n, cnt - i - 1);
442 else ent = X509_NAME_get_entry(n, i);
443 if(prev != -1) {
444 if(prev == ent->set) {
445 if(!io_ch(arg, sep_mv, sep_mv_len)) return -1;
446 outlen += sep_mv_len;
447 } else {
448 if(!io_ch(arg, sep_dn, sep_dn_len)) return -1;
449 outlen += sep_dn_len;
450 if(!do_indent(io_ch, arg, indent)) return -1;
451 outlen += indent;
452 }
453 }
454 prev = ent->set;
455 fn = X509_NAME_ENTRY_get_object(ent);
456 val = X509_NAME_ENTRY_get_data(ent);
457 fn_nid = OBJ_obj2nid(fn);
458 if(fn_opt != XN_FLAG_FN_NONE) {
459 int objlen;
460 if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
461 OBJ_obj2txt(objtmp, 80, fn, 1);
462 objbuf = objtmp;
463 } else {
464 if(fn_opt == XN_FLAG_FN_SN)
465 objbuf = OBJ_nid2sn(fn_nid);
466 else if(fn_opt == XN_FLAG_FN_LN)
467 objbuf = OBJ_nid2ln(fn_nid);
468 else objbuf = "";
469 }
470 objlen = strlen(objbuf);
471 if(!io_ch(arg, objbuf, objlen)) return -1;
472 if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
473 outlen += objlen + sep_eq_len;
474 }
475 /* If the field name is unknown then fix up the DER dump
476 * flag. We might want to limit this further so it will
477 * DER dump on anything other than a few 'standard' fields.
478 */
479 if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
480 orflags = ASN1_STRFLGS_DUMP_ALL;
481 else orflags = 0;
482
483 len = do_print_ex(io_ch, arg, flags | orflags, val);
484 if(len < 0) return -1;
485 outlen += len;
486 }
487 return outlen;
488}
489
490/* Wrappers round the main functions */
491
492int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
493{
494 return do_name_ex(send_bio_chars, out, nm, indent, flags);
495}
496
497
498int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
499{
500 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
501}
502
503int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
504{
505 return do_print_ex(send_bio_chars, out, flags, str);
506}
507
508
509int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
510{
511 return do_print_ex(send_fp_chars, fp, flags, str);
512}
513
514/* Utility function: convert any string type to UTF8, returns number of bytes
515 * in output string or a negative error code
516 */
517
518int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
519{
520 ASN1_STRING stmp, *str = &stmp;
521 int mbflag, type, ret;
522 if(!*out || !in) return -1;
523 type = in->type;
524 if((type < 0) || (type > 30)) return -1;
525 mbflag = tag2nbyte[type];
526 if(mbflag == -1) return -1;
527 mbflag |= MBSTRING_FLAG;
528 stmp.data = NULL;
529 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
530 if(ret < 0) return ret;
531 if(out) *out = stmp.data;
532 return stmp.length;
533}
diff --git a/src/lib/libssl/src/crypto/asn1/a_strnid.c b/src/lib/libssl/src/crypto/asn1/a_strnid.c
new file mode 100644
index 0000000000..ab8417ffab
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_strnid.c
@@ -0,0 +1,247 @@
1/* a_strnid.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65
66static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67static void st_free(ASN1_STRING_TABLE *tbl);
68static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b);
69static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b);
70
71
72/* This is the global mask for the mbstring functions: this is use to
73 * mask out certain types (such as BMPString and UTF8String) because
74 * certain software (e.g. Netscape) has problems with them.
75 */
76
77static unsigned long global_mask = 0xFFFFFFFFL;
78
79void ASN1_STRING_set_default_mask(unsigned long mask)
80{
81 global_mask = mask;
82}
83
84unsigned long ASN1_STRING_get_default_mask(void)
85{
86 return global_mask;
87}
88
89/* This function sets the default to various "flavours" of configuration.
90 * based on an ASCII string. Currently this is:
91 * MASK:XXXX : a numerical mask value.
92 * nobmp : Don't use BMPStrings (just Printable, T61).
93 * pkix : PKIX recommendation in RFC2459.
94 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
95 * default: the default value, Printable, T61, BMP.
96 */
97
98int ASN1_STRING_set_default_mask_asc(char *p)
99{
100 unsigned long mask;
101 char *end;
102 if(!strncmp(p, "MASK:", 5)) {
103 if(!p[5]) return 0;
104 mask = strtoul(p + 5, &end, 0);
105 if(*end) return 0;
106 } else if(!strcmp(p, "nombstr"))
107 mask = ~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING);
108 else if(!strcmp(p, "pkix"))
109 mask = ~B_ASN1_T61STRING;
110 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
111 else if(!strcmp(p, "default"))
112 mask = 0xFFFFFFFFL;
113 else return 0;
114 ASN1_STRING_set_default_mask(mask);
115 return 1;
116}
117
118/* The following function generates an ASN1_STRING based on limits in a table.
119 * Frequently the types and length of an ASN1_STRING are restricted by a
120 * corresponding OID. For example certificates and certificate requests.
121 */
122
123ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
124 int inlen, int inform, int nid)
125{
126 ASN1_STRING_TABLE *tbl;
127 ASN1_STRING *str = NULL;
128 unsigned long mask;
129 int ret;
130 if(!out) out = &str;
131 tbl = ASN1_STRING_TABLE_get(nid);
132 if(tbl) {
133 mask = tbl->mask;
134 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
135 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, tbl->mask,
136 tbl->minsize, tbl->maxsize);
137 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
138 if(ret <= 0) return NULL;
139 return *out;
140}
141
142/* Now the tables and helper functions for the string table:
143 */
144
145/* size limits: this stuff is taken straight from RFC2459 */
146
147#define ub_name 32768
148#define ub_common_name 64
149#define ub_locality_name 128
150#define ub_state_name 128
151#define ub_organization_name 64
152#define ub_organization_unit_name 64
153#define ub_title 64
154#define ub_email_address 128
155
156/* This table must be kept in NID order */
157
158static ASN1_STRING_TABLE tbl_standard[] = {
159{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
160{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
161{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
162{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
163{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
164{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
165{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
166{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
167{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
168{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
169{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
170{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
171{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
172{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}
174};
175
176static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b)
177{
178 return (*a)->nid - (*b)->nid;
179}
180
181static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b)
182{
183 return a->nid - b->nid;
184}
185
186ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
187{
188 int idx;
189 ASN1_STRING_TABLE *ttmp;
190 ASN1_STRING_TABLE fnd;
191 fnd.nid = nid;
192 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
193 (char *)tbl_standard,
194 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
195 sizeof(ASN1_STRING_TABLE), (int(*)())table_cmp);
196 if(ttmp) return ttmp;
197 if(!stable) return NULL;
198 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
199 if(idx < 0) return NULL;
200 return sk_ASN1_STRING_TABLE_value(stable, idx);
201}
202
203int ASN1_STRING_TABLE_add(int nid,
204 long minsize, long maxsize, unsigned long mask,
205 unsigned long flags)
206{
207 ASN1_STRING_TABLE *tmp;
208 char new_nid = 0;
209 flags &= ~STABLE_FLAGS_MALLOC;
210 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
211 if(!stable) {
212 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
213 return 0;
214 }
215 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
216 tmp = Malloc(sizeof(ASN1_STRING_TABLE));
217 if(!tmp) {
218 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
219 ERR_R_MALLOC_FAILURE);
220 return 0;
221 }
222 tmp->flags = flags | STABLE_FLAGS_MALLOC;
223 tmp->nid = nid;
224 new_nid = 1;
225 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
226 if(minsize != -1) tmp->minsize = minsize;
227 if(maxsize != -1) tmp->maxsize = maxsize;
228 tmp->mask = mask;
229 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
230 return 1;
231}
232
233void ASN1_STRING_TABLE_cleanup(void)
234{
235 STACK_OF(ASN1_STRING_TABLE) *tmp;
236 tmp = stable;
237 if(!tmp) return;
238 stable = NULL;
239 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
240}
241
242static void st_free(ASN1_STRING_TABLE *tbl)
243{
244 if(tbl->flags & STABLE_FLAGS_MALLOC) Free(tbl);
245}
246
247IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
diff --git a/src/lib/libssl/src/crypto/asn1/a_time.c b/src/lib/libssl/src/crypto/asn1/a_time.c
new file mode 100644
index 0000000000..c1690a5694
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_time.c
@@ -0,0 +1,123 @@
1/* crypto/asn1/a_time.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57/* This is an implementation of the ASN1 Time structure which is:
58 * Time ::= CHOICE {
59 * utcTime UTCTime,
60 * generalTime GeneralizedTime }
61 * written by Steve Henson.
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include "cryptlib.h"
67#include <openssl/asn1.h>
68
69int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
70 {
71#ifdef CHARSET_EBCDIC
72 /* KLUDGE! We convert to ascii before writing DER */
73 char tmp[24];
74 ASN1_STRING tmpstr;
75
76 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
77 int len;
78
79 tmpstr = *(ASN1_STRING *)a;
80 len = tmpstr.length;
81 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
82 tmpstr.data = tmp;
83 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
84 }
85#endif
86 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
87 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
88 a->type ,V_ASN1_UNIVERSAL));
89 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
90 return -1;
91 }
92
93
94ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
95 {
96 unsigned char tag;
97 tag = **pp & ~V_ASN1_CONSTRUCTED;
98 if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
99 return d2i_ASN1_UTCTIME(a, pp, length);
100 if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
101 return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
102 ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
103 return(NULL);
104 }
105
106
107ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
108 {
109 struct tm *ts;
110#if defined(THREADS) && !defined(WIN32)
111 struct tm data;
112#endif
113
114#if defined(THREADS) && !defined(WIN32)
115 gmtime_r(&t,&data);
116 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
117#else
118 ts=gmtime(&t);
119#endif
120 if((ts->tm_year >= 50) && (ts->tm_year < 150))
121 return ASN1_UTCTIME_set(s, t);
122 return ASN1_GENERALIZEDTIME_set(s,t);
123 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_utf8.c b/src/lib/libssl/src/crypto/asn1/a_utf8.c
new file mode 100644
index 0000000000..4a8a92e9e4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_utf8.c
@@ -0,0 +1,83 @@
1/* crypto/asn1/a_utf8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
64 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
66 V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
67 }
68
69ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
70 long length)
71 {
72 ASN1_UTF8STRING *ret=NULL;
73
74 ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
75 pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
76 if (ret == NULL)
77 {
78 ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
79 return(NULL);
80 }
81 return(ret);
82 }
83
diff --git a/src/lib/libssl/src/crypto/asn1/asn1t.h b/src/lib/libssl/src/crypto/asn1/asn1t.h
new file mode 100644
index 0000000000..ed372f8554
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1t.h
@@ -0,0 +1,846 @@
1/* asn1t.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#ifndef HEADER_ASN1T_H
59#define HEADER_ASN1T_H
60
61#include <stddef.h>
62#include <openssl/e_os2.h>
63#include <openssl/asn1.h>
64
65#ifdef OPENSSL_BUILD_SHLIBCRYPTO
66# undef OPENSSL_EXTERN
67# define OPENSSL_EXTERN OPENSSL_EXPORT
68#endif
69
70/* ASN1 template defines, structures and functions */
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76
77#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
78
79/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
80#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
81
82
83/* Macros for start and end of ASN1_ITEM definition */
84
85#define ASN1_ITEM_start(itname) \
86 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
87
88#define ASN1_ITEM_end(itname) \
89 };
90
91#else
92
93/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
94#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
95
96
97/* Macros for start and end of ASN1_ITEM definition */
98
99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \
101 { \
102 static const ASN1_ITEM local_it = { \
103
104#define ASN1_ITEM_end(itname) \
105 }; \
106 return &local_it; \
107 }
108
109#endif
110
111
112/* Macros to aid ASN1 template writing */
113
114#define ASN1_ITEM_TEMPLATE(tname) \
115 const static ASN1_TEMPLATE tname##_item_tt
116
117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\
119 ASN1_ITEM_start(tname) \
120 ASN1_ITYPE_PRIMITIVE,\
121 -1,\
122 &tname##_item_tt,\
123 0,\
124 NULL,\
125 0,\
126 #tname \
127 ASN1_ITEM_end(tname)
128
129
130/* This is a ASN1 type which just embeds a template */
131
132/* This pair helps declare a SEQUENCE. We can do:
133 *
134 * ASN1_SEQUENCE(stname) = {
135 * ... SEQUENCE components ...
136 * } ASN1_SEQUENCE_END(stname)
137 *
138 * This will produce an ASN1_ITEM called stname_it
139 * for a structure called stname.
140 *
141 * If you want the same structure but a different
142 * name then use:
143 *
144 * ASN1_SEQUENCE(itname) = {
145 * ... SEQUENCE components ...
146 * } ASN1_SEQUENCE_END_name(stname, itname)
147 *
148 * This will create an item called itname_it using
149 * a structure called stname.
150 */
151
152#define ASN1_SEQUENCE(tname) \
153 const static ASN1_TEMPLATE tname##_seq_tt[]
154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156
157#define ASN1_SEQUENCE_END_name(stname, tname) \
158 ;\
159 ASN1_ITEM_start(tname) \
160 ASN1_ITYPE_SEQUENCE,\
161 V_ASN1_SEQUENCE,\
162 tname##_seq_tt,\
163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
164 NULL,\
165 sizeof(stname),\
166 #stname \
167 ASN1_ITEM_end(tname)
168
169#define ASN1_SEQUENCE_cb(tname, cb) \
170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
171 ASN1_SEQUENCE(tname)
172
173#define ASN1_BROKEN_SEQUENCE(tname) \
174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
175 ASN1_SEQUENCE(tname)
176
177#define ASN1_SEQUENCE_ref(tname, cb, lck) \
178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
179 ASN1_SEQUENCE(tname)
180
181#define ASN1_SEQUENCE_enc(tname, enc, cb) \
182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
183 ASN1_SEQUENCE(tname)
184
185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
186
187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
188
189#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
190
191#define ASN1_SEQUENCE_END_ref(stname, tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 &tname##_aux,\
199 sizeof(stname),\
200 #stname \
201 ASN1_ITEM_end(tname)
202
203
204/* This pair helps declare a CHOICE type. We can do:
205 *
206 * ASN1_CHOICE(chname) = {
207 * ... CHOICE options ...
208 * ASN1_CHOICE_END(chname)
209 *
210 * This will produce an ASN1_ITEM called chname_it
211 * for a structure called chname. The structure
212 * definition must look like this:
213 * typedef struct {
214 * int type;
215 * union {
216 * ASN1_SOMETHING *opt1;
217 * ASN1_SOMEOTHER *opt2;
218 * } value;
219 * } chname;
220 *
221 * the name of the selector must be 'type'.
222 * to use an alternative selector name use the
223 * ASN1_CHOICE_END_selector() version.
224 */
225
226#define ASN1_CHOICE(tname) \
227 const static ASN1_TEMPLATE tname##_ch_tt[]
228
229#define ASN1_CHOICE_cb(tname, cb) \
230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
231 ASN1_CHOICE(tname)
232
233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
234
235#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
236
237#define ASN1_CHOICE_END_selector(stname, tname, selname) \
238 ;\
239 ASN1_ITEM_start(tname) \
240 ASN1_ITYPE_CHOICE,\
241 offsetof(stname,selname) ,\
242 tname##_ch_tt,\
243 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
244 NULL,\
245 sizeof(stname),\
246 #stname \
247 ASN1_ITEM_end(tname)
248
249#define ASN1_CHOICE_END_cb(stname, tname, selname) \
250 ;\
251 ASN1_ITEM_start(tname) \
252 ASN1_ITYPE_CHOICE,\
253 offsetof(stname,selname) ,\
254 tname##_ch_tt,\
255 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
256 &tname##_aux,\
257 sizeof(stname),\
258 #stname \
259 ASN1_ITEM_end(tname)
260
261/* This helps with the template wrapper form of ASN1_ITEM */
262
263#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
264 (flags), (tag), 0,\
265 #name, ASN1_ITEM_ref(type) }
266
267/* These help with SEQUENCE or CHOICE components */
268
269/* used to declare other types */
270
271#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
272 (flags), (tag), offsetof(stname, field),\
273 #field, ASN1_ITEM_ref(type) }
274
275/* used when the structure is combined with the parent */
276
277#define ASN1_EX_COMBINE(flags, tag, type) { \
278 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
279
280/* implicit and explicit helper macros */
281
282#define ASN1_IMP_EX(stname, field, type, tag, ex) \
283 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
284
285#define ASN1_EXP_EX(stname, field, type, tag, ex) \
286 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
287
288/* Any defined by macros: the field used is in the table itself */
289
290#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
291#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
292#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
293#else
294#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
295#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
296#endif
297/* Plain simple type */
298#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
299
300/* OPTIONAL simple type */
301#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
302
303/* IMPLICIT tagged simple type */
304#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
305
306/* IMPLICIT tagged OPTIONAL simple type */
307#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
308
309/* Same as above but EXPLICIT */
310
311#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
312#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
313
314/* SEQUENCE OF type */
315#define ASN1_SEQUENCE_OF(stname, field, type) \
316 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
317
318/* OPTIONAL SEQUENCE OF */
319#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
320 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
321
322/* Same as above but for SET OF */
323
324#define ASN1_SET_OF(stname, field, type) \
325 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
326
327#define ASN1_SET_OF_OPT(stname, field, type) \
328 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
329
330/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
331
332#define ASN1_IMP_SET_OF(stname, field, type, tag) \
333 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
334
335#define ASN1_EXP_SET_OF(stname, field, type, tag) \
336 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
337
338#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
339 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
340
341#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
342 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
343
344#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
345 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
346
347#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
348 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
349
350#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
351 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
352
353#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
354 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
355
356/* Macros for the ASN1_ADB structure */
357
358#define ASN1_ADB(name) \
359 const static ASN1_ADB_TABLE name##_adbtbl[]
360
361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
362
363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
364 ;\
365 const static ASN1_ADB name##_adb = {\
366 flags,\
367 offsetof(name, field),\
368 app_table,\
369 name##_adbtbl,\
370 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
371 def,\
372 none\
373 }
374
375#else
376
377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
378 ;\
379 const static ASN1_ITEM *name##_adb(void) \
380 { \
381 const static ASN1_ADB internal_adb = \
382 {\
383 flags,\
384 offsetof(name, field),\
385 app_table,\
386 name##_adbtbl,\
387 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
388 def,\
389 none\
390 }; \
391 return (const ASN1_ITEM *) &internal_adb; \
392 } \
393 void dummy_function(void)
394
395#endif
396
397#define ADB_ENTRY(val, template) {val, template}
398
399#define ASN1_ADB_TEMPLATE(name) \
400 const static ASN1_TEMPLATE name##_tt
401
402/* This is the ASN1 template structure that defines
403 * a wrapper round the actual type. It determines the
404 * actual position of the field in the value structure,
405 * various flags such as OPTIONAL and the field name.
406 */
407
408struct ASN1_TEMPLATE_st {
409unsigned long flags; /* Various flags */
410long tag; /* tag, not used if no tagging */
411unsigned long offset; /* Offset of this field in structure */
412#ifndef NO_ASN1_FIELD_NAMES
413char *field_name; /* Field name */
414#endif
415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
416};
417
418/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
419
420#define ASN1_TEMPLATE_item(t) (t->item_ptr)
421#define ASN1_TEMPLATE_adb(t) (t->item_ptr)
422
423typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
424typedef struct ASN1_ADB_st ASN1_ADB;
425
426struct ASN1_ADB_st {
427 unsigned long flags; /* Various flags */
428 unsigned long offset; /* Offset of selector field */
429 STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
430 const ASN1_ADB_TABLE *tbl; /* Table of possible types */
431 long tblcount; /* Number of entries in tbl */
432 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
433 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
434};
435
436struct ASN1_ADB_TABLE_st {
437 long value; /* NID for an object or value for an int */
438 const ASN1_TEMPLATE tt; /* item for this value */
439};
440
441/* template flags */
442
443/* Field is optional */
444#define ASN1_TFLG_OPTIONAL (0x1)
445
446/* Field is a SET OF */
447#define ASN1_TFLG_SET_OF (0x1 << 1)
448
449/* Field is a SEQUENCE OF */
450#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
451
452/* Special case: this refers to a SET OF that
453 * will be sorted into DER order when encoded *and*
454 * the corresponding STACK will be modified to match
455 * the new order.
456 */
457#define ASN1_TFLG_SET_ORDER (0x3 << 1)
458
459/* Mask for SET OF or SEQUENCE OF */
460#define ASN1_TFLG_SK_MASK (0x3 << 1)
461
462/* These flags mean the tag should be taken from the
463 * tag field. If EXPLICIT then the underlying type
464 * is used for the inner tag.
465 */
466
467/* IMPLICIT tagging */
468#define ASN1_TFLG_IMPTAG (0x1 << 3)
469
470
471/* EXPLICIT tagging, inner tag from underlying type */
472#define ASN1_TFLG_EXPTAG (0x2 << 3)
473
474#define ASN1_TFLG_TAG_MASK (0x3 << 3)
475
476/* context specific IMPLICIT */
477#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
478
479/* context specific EXPLICIT */
480#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
481
482/* If tagging is in force these determine the
483 * type of tag to use. Otherwise the tag is
484 * determined by the underlying type. These
485 * values reflect the actual octet format.
486 */
487
488/* Universal tag */
489#define ASN1_TFLG_UNIVERSAL (0x0<<6)
490/* Application tag */
491#define ASN1_TFLG_APPLICATION (0x1<<6)
492/* Context specific tag */
493#define ASN1_TFLG_CONTEXT (0x2<<6)
494/* Private tag */
495#define ASN1_TFLG_PRIVATE (0x3<<6)
496
497#define ASN1_TFLG_TAG_CLASS (0x3<<6)
498
499/* These are for ANY DEFINED BY type. In this case
500 * the 'item' field points to an ASN1_ADB structure
501 * which contains a table of values to decode the
502 * relevant type
503 */
504
505#define ASN1_TFLG_ADB_MASK (0x3<<8)
506
507#define ASN1_TFLG_ADB_OID (0x1<<8)
508
509#define ASN1_TFLG_ADB_INT (0x1<<9)
510
511/* This flag means a parent structure is passed
512 * instead of the field: this is useful is a
513 * SEQUENCE is being combined with a CHOICE for
514 * example. Since this means the structure and
515 * item name will differ we need to use the
516 * ASN1_CHOICE_END_name() macro for example.
517 */
518
519#define ASN1_TFLG_COMBINE (0x1<<10)
520
521/* This is the actual ASN1 item itself */
522
523struct ASN1_ITEM_st {
524char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
525long utype; /* underlying type */
526const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
527long tcount; /* Number of templates if SEQUENCE or CHOICE */
528const void *funcs; /* functions that handle this type */
529long size; /* Structure size (usually)*/
530#ifndef NO_ASN1_FIELD_NAMES
531const char *sname; /* Structure name */
532#endif
533};
534
535/* These are values for the itype field and
536 * determine how the type is interpreted.
537 *
538 * For PRIMITIVE types the underlying type
539 * determines the behaviour if items is NULL.
540 *
541 * Otherwise templates must contain a single
542 * template and the type is treated in the
543 * same way as the type specified in the template.
544 *
545 * For SEQUENCE types the templates field points
546 * to the members, the size field is the
547 * structure size.
548 *
549 * For CHOICE types the templates field points
550 * to each possible member (typically a union)
551 * and the 'size' field is the offset of the
552 * selector.
553 *
554 * The 'funcs' field is used for application
555 * specific functions.
556 *
557 * For COMPAT types the funcs field gives a
558 * set of functions that handle this type, this
559 * supports the old d2i, i2d convention.
560 *
561 * The EXTERN type uses a new style d2i/i2d.
562 * The new style should be used where possible
563 * because it avoids things like the d2i IMPLICIT
564 * hack.
565 *
566 * MSTRING is a multiple string type, it is used
567 * for a CHOICE of character strings where the
568 * actual strings all occupy an ASN1_STRING
569 * structure. In this case the 'utype' field
570 * has a special meaning, it is used as a mask
571 * of acceptable types using the B_ASN1 constants.
572 *
573 */
574
575#define ASN1_ITYPE_PRIMITIVE 0x0
576
577#define ASN1_ITYPE_SEQUENCE 0x1
578
579#define ASN1_ITYPE_CHOICE 0x2
580
581#define ASN1_ITYPE_COMPAT 0x3
582
583#define ASN1_ITYPE_EXTERN 0x4
584
585#define ASN1_ITYPE_MSTRING 0x5
586
587/* Cache for ASN1 tag and length, so we
588 * don't keep re-reading it for things
589 * like CHOICE
590 */
591
592struct ASN1_TLC_st{
593 char valid; /* Values below are valid */
594 int ret; /* return value */
595 long plen; /* length */
596 int ptag; /* class value */
597 int pclass; /* class value */
598 int hdrlen; /* header length */
599};
600
601/* Typedefs for ASN1 function pointers */
602
603typedef ASN1_VALUE * ASN1_new_func(void);
604typedef void ASN1_free_func(ASN1_VALUE *a);
605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length);
606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
607
608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
609 int tag, int aclass, char opt, ASN1_TLC *ctx);
610
611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
612typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
613typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
614
615typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
616typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
617
618typedef struct ASN1_COMPAT_FUNCS_st {
619 ASN1_new_func *asn1_new;
620 ASN1_free_func *asn1_free;
621 ASN1_d2i_func *asn1_d2i;
622 ASN1_i2d_func *asn1_i2d;
623} ASN1_COMPAT_FUNCS;
624
625typedef struct ASN1_EXTERN_FUNCS_st {
626 void *app_data;
627 ASN1_ex_new_func *asn1_ex_new;
628 ASN1_ex_free_func *asn1_ex_free;
629 ASN1_ex_free_func *asn1_ex_clear;
630 ASN1_ex_d2i *asn1_ex_d2i;
631 ASN1_ex_i2d *asn1_ex_i2d;
632} ASN1_EXTERN_FUNCS;
633
634typedef struct ASN1_PRIMITIVE_FUNCS_st {
635 void *app_data;
636 unsigned long flags;
637 ASN1_ex_new_func *prim_new;
638 ASN1_ex_free_func *prim_free;
639 ASN1_ex_free_func *prim_clear;
640 ASN1_primitive_c2i *prim_c2i;
641 ASN1_primitive_i2c *prim_i2c;
642} ASN1_PRIMITIVE_FUNCS;
643
644/* This is the ASN1_AUX structure: it handles various
645 * miscellaneous requirements. For example the use of
646 * reference counts and an informational callback.
647 *
648 * The "informational callback" is called at various
649 * points during the ASN1 encoding and decoding. It can
650 * be used to provide minor customisation of the structures
651 * used. This is most useful where the supplied routines
652 * *almost* do the right thing but need some extra help
653 * at a few points. If the callback returns zero then
654 * it is assumed a fatal error has occurred and the
655 * main operation should be abandoned.
656 *
657 * If major changes in the default behaviour are required
658 * then an external type is more appropriate.
659 */
660
661typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
662
663typedef struct ASN1_AUX_st {
664 void *app_data;
665 int flags;
666 int ref_offset; /* Offset of reference value */
667 int ref_lock; /* Lock type to use */
668 ASN1_aux_cb *asn1_cb;
669 int enc_offset; /* Offset of ASN1_ENCODING structure */
670} ASN1_AUX;
671
672/* Flags in ASN1_AUX */
673
674/* Use a reference count */
675#define ASN1_AFLG_REFCOUNT 1
676/* Save the encoding of structure (useful for signatures) */
677#define ASN1_AFLG_ENCODING 2
678/* The Sequence length is invalid */
679#define ASN1_AFLG_BROKEN 4
680
681/* operation values for asn1_cb */
682
683#define ASN1_OP_NEW_PRE 0
684#define ASN1_OP_NEW_POST 1
685#define ASN1_OP_FREE_PRE 2
686#define ASN1_OP_FREE_POST 3
687#define ASN1_OP_D2I_PRE 4
688#define ASN1_OP_D2I_POST 5
689#define ASN1_OP_I2D_PRE 6
690#define ASN1_OP_I2D_POST 7
691
692/* Macro to implement a primitive type */
693#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
694#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
695 ASN1_ITEM_start(itname) \
696 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
697 ASN1_ITEM_end(itname)
698
699/* Macro to implement a multi string type */
700#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
701 ASN1_ITEM_start(itname) \
702 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
703 ASN1_ITEM_end(itname)
704
705/* Macro to implement an ASN1_ITEM in terms of old style funcs */
706
707#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
708
709#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
710 static const ASN1_COMPAT_FUNCS sname##_ff = { \
711 (ASN1_new_func *)sname##_new, \
712 (ASN1_free_func *)sname##_free, \
713 (ASN1_d2i_func *)d2i_##sname, \
714 (ASN1_i2d_func *)i2d_##sname, \
715 }; \
716 ASN1_ITEM_start(sname) \
717 ASN1_ITYPE_COMPAT, \
718 tag, \
719 NULL, \
720 0, \
721 &sname##_ff, \
722 0, \
723 #sname \
724 ASN1_ITEM_end(sname)
725
726#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
727 ASN1_ITEM_start(sname) \
728 ASN1_ITYPE_EXTERN, \
729 tag, \
730 NULL, \
731 0, \
732 &fptrs, \
733 0, \
734 #sname \
735 ASN1_ITEM_end(sname)
736
737/* Macro to implement standard functions in terms of ASN1_ITEM structures */
738
739#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
740
741#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
742
743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
745
746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
747 stname *fname##_new(void) \
748 { \
749 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
750 } \
751 void fname##_free(stname *a) \
752 { \
753 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
754 }
755
756#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
757 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
759
760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \
762 { \
763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
764 } \
765 int i2d_##fname(stname *a, unsigned char **out) \
766 { \
767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
768 }
769
770/* This includes evil casts to remove const: they will go away when full
771 * ASN1 constification is done.
772 */
773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
775 { \
776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\
777 } \
778 int i2d_##fname(const stname *a, unsigned char **out) \
779 { \
780 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
781 }
782
783#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
784 stname * stname##_dup(stname *x) \
785 { \
786 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
787 }
788
789#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
790 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
791
792#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
793 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
794 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
795
796/* external definitions for primitive types */
797
798DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
802DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
803DECLARE_ASN1_ITEM(CBIGNUM)
804DECLARE_ASN1_ITEM(BIGNUM)
805DECLARE_ASN1_ITEM(LONG)
806DECLARE_ASN1_ITEM(ZLONG)
807
808DECLARE_STACK_OF(ASN1_VALUE)
809
810/* Functions used internally by the ASN1 code */
811
812int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
813void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
814int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
816
817void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
818int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt);
819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
820 int tag, int aclass, char opt, ASN1_TLC *ctx);
821
822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
823int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
825
826int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
827int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
828
829int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
830int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
831
832ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
833
834const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
835
836int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
837
838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
839void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
840int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it);
842
843#ifdef __cplusplus
844}
845#endif
846#endif
diff --git a/src/lib/libssl/src/crypto/asn1/asn_moid.c b/src/lib/libssl/src/crypto/asn1/asn_moid.c
new file mode 100644
index 0000000000..be20db4bad
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn_moid.c
@@ -0,0 +1,95 @@
1/* asn_moid.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65
66/* Simple ASN1 OID module: add all objects in a given section */
67
68static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
69 {
70 int i;
71 const char *oid_section;
72 STACK_OF(CONF_VALUE) *sktmp;
73 CONF_VALUE *oval;
74 oid_section = CONF_imodule_get_value(md);
75 if(!(sktmp = NCONF_get_section(cnf, oid_section)))
76 {
77 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
78 return 0;
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
81 {
82 oval = sk_CONF_VALUE_value(sktmp, i);
83 if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef)
84 {
85 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
86 return 0;
87 }
88 }
89 return 1;
90}
91
92void ASN1_add_oid_module(void)
93 {
94 CONF_module_add("oid_section", oid_module_init, 0);
95 }
diff --git a/src/lib/libssl/src/crypto/asn1/asn_pack.c b/src/lib/libssl/src/crypto/asn1/asn_pack.c
new file mode 100644
index 0000000000..662a2626a1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn_pack.c
@@ -0,0 +1,145 @@
1/* asn_pack.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/* ASN1 packing and unpacking functions */
64
65/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
66
67STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
68 void (*free_func)())
69{
70 STACK *sk;
71 unsigned char *pbuf;
72 pbuf = buf;
73 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
74 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
75 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
76 return sk;
77}
78
79/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
80 * Malloc'ed buffer
81 */
82
83unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
84 int *len)
85{
86 int safelen;
87 unsigned char *safe, *p;
88 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
89 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
90 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
91 return NULL;
92 }
93 if (!(safe = Malloc (safelen))) {
94 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 p = safe;
98 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
99 IS_SEQUENCE);
100 if (len) *len = safelen;
101 if (buf) *buf = safe;
102 return safe;
103}
104
105/* Extract an ASN1 object from an ASN1_STRING */
106
107void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
108{
109 unsigned char *p;
110 char *ret;
111
112 p = oct->data;
113 if(!(ret = d2i(NULL, &p, oct->length)))
114 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
115 return ret;
116}
117
118/* Pack an ASN1 object into an ASN1_STRING */
119
120ASN1_STRING *ASN1_pack_string (void *obj, int (*i2d)(), ASN1_STRING **oct)
121{
122 unsigned char *p;
123 ASN1_STRING *octmp;
124
125 if (!oct || !*oct) {
126 if (!(octmp = ASN1_STRING_new ())) {
127 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 if (oct) *oct = octmp;
131 } else octmp = *oct;
132
133 if (!(octmp->length = i2d(obj, NULL))) {
134 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
135 return NULL;
136 }
137 if (!(p = Malloc (octmp->length))) {
138 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
139 return NULL;
140 }
141 octmp->data = p;
142 i2d (obj, &p);
143 return octmp;
144}
145
diff --git a/src/lib/libssl/src/crypto/asn1/charmap.h b/src/lib/libssl/src/crypto/asn1/charmap.h
new file mode 100644
index 0000000000..bd020a9562
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/charmap.h
@@ -0,0 +1,15 @@
1/* Auto generated with chartype.pl script.
2 * Mask of various character properties
3 */
4
5static unsigned char char_type[] = {
6 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
8120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
916,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
10 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1116,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
12 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1316,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
14};
15
diff --git a/src/lib/libssl/src/crypto/asn1/charmap.pl b/src/lib/libssl/src/crypto/asn1/charmap.pl
new file mode 100644
index 0000000000..2875c59867
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/charmap.pl
@@ -0,0 +1,80 @@
1#!/usr/local/bin/perl -w
2
3use strict;
4
5my ($i, @arr);
6
7# Set up an array with the type of ASCII characters
8# Each set bit represents a character property.
9
10# RFC2253 character properties
11my $RFC2253_ESC = 1; # Character escaped with \
12my $ESC_CTRL = 2; # Escaped control character
13# These are used with RFC1779 quoting using "
14my $NOESC_QUOTE = 8; # Not escaped if quoted
15my $PSTRING_CHAR = 0x10; # Valid PrintableString character
16my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
17my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character
18
19for($i = 0; $i < 128; $i++) {
20 # Set the RFC2253 escape characters (control)
21 $arr[$i] = 0;
22 if(($i < 32) || ($i > 126)) {
23 $arr[$i] |= $ESC_CTRL;
24 }
25
26 # Some PrintableString characters
27 if( ( ( $i >= ord("a")) && ( $i <= ord("z")) )
28 || ( ( $i >= ord("A")) && ( $i <= ord("Z")) )
29 || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) {
30 $arr[$i] |= $PSTRING_CHAR;
31 }
32}
33
34# Now setup the rest
35
36# Remaining RFC2253 escaped characters
37
38$arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
39$arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
40
41$arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
42$arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
43$arr[ord("\"")] |= $RFC2253_ESC;
44$arr[ord("\\")] |= $RFC2253_ESC;
45$arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
46$arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
47$arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
48
49# Remaining PrintableString characters
50
51$arr[ord(" ")] |= $PSTRING_CHAR;
52$arr[ord("'")] |= $PSTRING_CHAR;
53$arr[ord("(")] |= $PSTRING_CHAR;
54$arr[ord(")")] |= $PSTRING_CHAR;
55$arr[ord("+")] |= $PSTRING_CHAR;
56$arr[ord(",")] |= $PSTRING_CHAR;
57$arr[ord("-")] |= $PSTRING_CHAR;
58$arr[ord(".")] |= $PSTRING_CHAR;
59$arr[ord("/")] |= $PSTRING_CHAR;
60$arr[ord(":")] |= $PSTRING_CHAR;
61$arr[ord("=")] |= $PSTRING_CHAR;
62$arr[ord("?")] |= $PSTRING_CHAR;
63
64# Now generate the C code
65
66print <<EOF;
67/* Auto generated with chartype.pl script.
68 * Mask of various character properties
69 */
70
71static unsigned char char_type[] = {
72EOF
73
74for($i = 0; $i < 128; $i++) {
75 print("\n") if($i && (($i % 16) == 0));
76 printf("%2d", $arr[$i]);
77 print(",") if ($i != 127);
78}
79print("\n};\n\n");
80
diff --git a/src/lib/libssl/src/crypto/asn1/f_enum.c b/src/lib/libssl/src/crypto/asn1/f_enum.c
new file mode 100644
index 0000000000..3bcceecdb8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/f_enum.c
@@ -0,0 +1,207 @@
1/* crypto/asn1/f_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64/* Based on a_int.c: equivalent ENUMERATED functions */
65
66int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
67 {
68 int i,n=0;
69 static const char *h="0123456789ABCDEF";
70 char buf[2];
71
72 if (a == NULL) return(0);
73
74 if (a->length == 0)
75 {
76 if (BIO_write(bp,"00",2) != 2) goto err;
77 n=2;
78 }
79 else
80 {
81 for (i=0; i<a->length; i++)
82 {
83 if ((i != 0) && (i%35 == 0))
84 {
85 if (BIO_write(bp,"\\\n",2) != 2) goto err;
86 n+=2;
87 }
88 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
89 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
90 if (BIO_write(bp,buf,2) != 2) goto err;
91 n+=2;
92 }
93 }
94 return(n);
95err:
96 return(-1);
97 }
98
99int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
100 {
101 int ret=0;
102 int i,j,k,m,n,again,bufsize;
103 unsigned char *s=NULL,*sp;
104 unsigned char *bufp;
105 int num=0,slen=0,first=1;
106
107 bs->type=V_ASN1_ENUMERATED;
108
109 bufsize=BIO_gets(bp,buf,size);
110 for (;;)
111 {
112 if (bufsize < 1) goto err_sl;
113 i=bufsize;
114 if (buf[i-1] == '\n') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 if (buf[i-1] == '\r') buf[--i]='\0';
117 if (i == 0) goto err_sl;
118 again=(buf[i-1] == '\\');
119
120 for (j=0; j<i; j++)
121 {
122 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
123 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
124 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
125 {
126 i=j;
127 break;
128 }
129 }
130 buf[i]='\0';
131 /* We have now cleared all the crap off the end of the
132 * line */
133 if (i < 2) goto err_sl;
134
135 bufp=(unsigned char *)buf;
136 if (first)
137 {
138 first=0;
139 if ((bufp[0] == '0') && (buf[1] == '0'))
140 {
141 bufp+=2;
142 i-=2;
143 }
144 }
145 k=0;
146 i-=again;
147 if (i%2 != 0)
148 {
149 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err;
151 }
152 i/=2;
153 if (num+i > slen)
154 {
155 if (s == NULL)
156 sp=(unsigned char *)Malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)Realloc(s,
160 (unsigned int)num+i*2);
161 if (sp == NULL)
162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) Free((char *)s);
165 goto err;
166 }
167 s=sp;
168 slen=num+i*2;
169 }
170 for (j=0; j<i; j++,k+=2)
171 {
172 for (n=0; n<2; n++)
173 {
174 m=bufp[k+n];
175 if ((m >= '0') && (m <= '9'))
176 m-='0';
177 else if ((m >= 'a') && (m <= 'f'))
178 m=m-'a'+10;
179 else if ((m >= 'A') && (m <= 'F'))
180 m=m-'A'+10;
181 else
182 {
183 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
184 goto err;
185 }
186 s[num+j]<<=4;
187 s[num+j]|=m;
188 }
189 }
190 num+=i;
191 if (again)
192 bufsize=BIO_gets(bp,buf,size);
193 else
194 break;
195 }
196 bs->length=num;
197 bs->data=s;
198 ret=1;
199err:
200 if (0)
201 {
202err_sl:
203 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
204 }
205 return(ret);
206 }
207
diff --git a/src/lib/libssl/src/crypto/asn1/nsseq.c b/src/lib/libssl/src/crypto/asn1/nsseq.c
new file mode 100644
index 0000000000..417d024b81
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/nsseq.c
@@ -0,0 +1,118 @@
1/* nsseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1_mac.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64#include <openssl/objects.h>
65
66/* Netscape certificate sequence structure */
67
68int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69{
70 int v = 0;
71 M_ASN1_I2D_vars(a);
72 M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
74 V_ASN1_SEQUENCE,v);
75
76 M_ASN1_I2D_seq_total();
77
78 M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
79 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
80 V_ASN1_SEQUENCE,v);
81
82 M_ASN1_I2D_finish();
83}
84
85NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
86{
87 NETSCAPE_CERT_SEQUENCE *ret=NULL;
88 ASN1_CTX c;
89 M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
90 /* Note hardcoded object type */
91 ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
92 ret->certs = NULL;
93 return (ret);
94 M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95}
96
97NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
98 unsigned char **pp, long length)
99{
100 M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101 NETSCAPE_CERT_SEQUENCE_new);
102 M_ASN1_D2I_Init();
103 M_ASN1_D2I_start_sequence();
104 M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
105 M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106 V_ASN1_SEQUENCE);
107 M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108 ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
109}
110
111void NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112{
113 if (a == NULL) return;
114 ASN1_OBJECT_free(a->type);
115 if(a->certs)
116 sk_X509_pop_free(a->certs, X509_free);
117 Free (a);
118}
diff --git a/src/lib/libssl/src/crypto/asn1/p5_pbe.c b/src/lib/libssl/src/crypto/asn1/p5_pbe.c
new file mode 100644
index 0000000000..b831836e7b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/p5_pbe.c
@@ -0,0 +1,156 @@
1/* p5_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING);
71 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);
76 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
77 M_ASN1_I2D_finish();
78}
79
80PBEPARAM *PBEPARAM_new(void)
81{
82 PBEPARAM *ret=NULL;
83 ASN1_CTX c;
84 M_ASN1_New_Malloc(ret, PBEPARAM);
85 M_ASN1_New(ret->iter,ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new);
87 return (ret);
88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW);
89}
90
91PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length)
92{
93 M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new);
94 M_ASN1_D2I_Init();
95 M_ASN1_D2I_start_sequence();
96 M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING);
97 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
98 M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM);
99}
100
101void PBEPARAM_free (PBEPARAM *a)
102{
103 if(a==NULL) return;
104 ASN1_OCTET_STRING_free(a->salt);
105 ASN1_INTEGER_free (a->iter);
106 Free ((char *)a);
107}
108
109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
110
111X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
112 int saltlen)
113{
114 PBEPARAM *pbe;
115 ASN1_OBJECT *al;
116 X509_ALGOR *algor;
117 ASN1_TYPE *astype;
118
119 if (!(pbe = PBEPARAM_new ())) {
120 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
124 ASN1_INTEGER_set (pbe->iter, iter);
125 if (!saltlen) saltlen = PKCS5_SALT_LEN;
126 if (!(pbe->salt->data = Malloc (saltlen))) {
127 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 pbe->salt->length = saltlen;
131 if (salt) memcpy (pbe->salt->data, salt, saltlen);
132 else RAND_bytes (pbe->salt->data, saltlen);
133
134 if (!(astype = ASN1_TYPE_new())) {
135 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 astype->type = V_ASN1_SEQUENCE;
140 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
141 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
142 return NULL;
143 }
144 PBEPARAM_free (pbe);
145
146 al = OBJ_nid2obj(alg); /* never need to free al */
147 if (!(algor = X509_ALGOR_new())) {
148 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
149 return NULL;
150 }
151 ASN1_OBJECT_free(algor->algorithm);
152 algor->algorithm = al;
153 algor->parameter = astype;
154
155 return (algor);
156}
diff --git a/src/lib/libssl/src/crypto/asn1/p5_pbev2.c b/src/lib/libssl/src/crypto/asn1/p5_pbev2.c
new file mode 100644
index 0000000000..09f4bf6112
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/p5_pbev2.c
@@ -0,0 +1,274 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR);
76 M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR);
77
78 M_ASN1_I2D_finish();
79}
80
81PBE2PARAM *PBE2PARAM_new(void)
82{
83 PBE2PARAM *ret=NULL;
84 ASN1_CTX c;
85 M_ASN1_New_Malloc(ret, PBE2PARAM);
86 M_ASN1_New(ret->keyfunc,X509_ALGOR_new);
87 M_ASN1_New(ret->encryption,X509_ALGOR_new);
88 return (ret);
89 M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW);
90}
91
92PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length)
93{
94 M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new);
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR);
98 M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR);
99 M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM);
100}
101
102void PBE2PARAM_free (PBE2PARAM *a)
103{
104 if(a==NULL) return;
105 X509_ALGOR_free(a->keyfunc);
106 X509_ALGOR_free(a->encryption);
107 Free ((char *)a);
108}
109
110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
111{
112 M_ASN1_I2D_vars(a);
113 M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE);
114 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
115 M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER);
116 M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR);
117
118 M_ASN1_I2D_seq_total ();
119
120 M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE);
121 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
122 M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER);
123 M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR);
124
125 M_ASN1_I2D_finish();
126}
127
128PBKDF2PARAM *PBKDF2PARAM_new(void)
129{
130 PBKDF2PARAM *ret=NULL;
131 ASN1_CTX c;
132 M_ASN1_New_Malloc(ret, PBKDF2PARAM);
133 M_ASN1_New(ret->salt, ASN1_TYPE_new);
134 M_ASN1_New(ret->iter, ASN1_INTEGER_new);
135 ret->keylength = NULL;
136 ret->prf = NULL;
137 return (ret);
138 M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW);
139}
140
141PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp,
142 long length)
143{
144 M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new);
145 M_ASN1_D2I_Init();
146 M_ASN1_D2I_start_sequence();
147 M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE);
148 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
149 M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
150 M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE);
151 M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM);
152}
153
154void PBKDF2PARAM_free (PBKDF2PARAM *a)
155{
156 if(a==NULL) return;
157 ASN1_TYPE_free(a->salt);
158 ASN1_INTEGER_free(a->iter);
159 ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf);
161 Free ((char *)a);
162}
163
164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
165 * yes I know this is horrible!
166 */
167
168X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
169 unsigned char *salt, int saltlen)
170{
171 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
172 int alg_nid;
173 EVP_CIPHER_CTX ctx;
174 unsigned char iv[EVP_MAX_IV_LENGTH];
175 PBKDF2PARAM *kdf = NULL;
176 PBE2PARAM *pbe2 = NULL;
177 ASN1_OCTET_STRING *osalt = NULL;
178
179 if(!(pbe2 = PBE2PARAM_new())) goto merr;
180
181 /* Setup the AlgorithmIdentifier for the encryption scheme */
182 scheme = pbe2->encryption;
183
184 alg_nid = EVP_CIPHER_type(cipher);
185
186 scheme->algorithm = OBJ_nid2obj(alg_nid);
187 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
188
189 /* Create random IV */
190 RAND_bytes(iv, EVP_CIPHER_iv_length(cipher));
191
192 /* Dummy cipherinit to just setup the IV */
193 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
194 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
195 ASN1err(ASN1_F_PKCS5_PBE2_SET,
196 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
197 goto err;
198 }
199 EVP_CIPHER_CTX_cleanup(&ctx);
200
201 if(!(kdf = PBKDF2PARAM_new())) goto merr;
202 if(!(osalt = ASN1_OCTET_STRING_new())) goto merr;
203
204 if (!saltlen) saltlen = PKCS5_SALT_LEN;
205 if (!(osalt->data = Malloc (saltlen))) goto merr;
206 osalt->length = saltlen;
207 if (salt) memcpy (osalt->data, salt, saltlen);
208 else RAND_bytes (osalt->data, saltlen);
209
210 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
211 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
212
213 /* Now include salt in kdf structure */
214 kdf->salt->value.octet_string = osalt;
215 kdf->salt->type = V_ASN1_OCTET_STRING;
216 osalt = NULL;
217
218 /* If its RC2 then we'd better setup the key length */
219
220 if(alg_nid == NID_rc2_cbc) {
221 if(!(kdf->keylength = ASN1_INTEGER_new())) goto merr;
222 if(!ASN1_INTEGER_set (kdf->keylength,
223 EVP_CIPHER_key_length(cipher))) goto merr;
224 }
225
226 /* prf can stay NULL because we are using hmacWithSHA1 */
227
228 /* Now setup the PBE2PARAM keyfunc structure */
229
230 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
231
232 /* Encode PBKDF2PARAM into parameter of pbe2 */
233
234 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
235
236 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
237 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
238 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
239
240 PBKDF2PARAM_free(kdf);
241 kdf = NULL;
242
243 /* Now set up top level AlgorithmIdentifier */
244
245 if(!(ret = X509_ALGOR_new())) goto merr;
246 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
247
248 ret->algorithm = OBJ_nid2obj(NID_pbes2);
249
250 /* Encode PBE2PARAM into parameter */
251
252 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
253 &ret->parameter->value.sequence)) goto merr;
254 ret->parameter->type = V_ASN1_SEQUENCE;
255
256 PBE2PARAM_free(pbe2);
257 pbe2 = NULL;
258
259 return ret;
260
261 merr:
262 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
263
264 err:
265 PBE2PARAM_free(pbe2);
266 /* Note 'scheme' is freed as part of pbe2 */
267 ASN1_OCTET_STRING_free(osalt);
268 PBKDF2PARAM_free(kdf);
269 X509_ALGOR_free(kalg);
270 X509_ALGOR_free(ret);
271
272 return NULL;
273
274}
diff --git a/src/lib/libssl/src/crypto/asn1/p8_key.c b/src/lib/libssl/src/crypto/asn1/p8_key.c
new file mode 100644
index 0000000000..0b24374627
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/p8_key.c
@@ -0,0 +1,131 @@
1/* crypto/asn1/p8_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63
64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
69 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
70 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
71
72 M_ASN1_I2D_seq_total();
73
74 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
75 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
76 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
82 {
83 M_ASN1_D2I_vars(a,X509 *,X509_new);
84
85 M_ASN1_D2I_Init();
86 M_ASN1_D2I_start_sequence();
87 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
88 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
89 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
91 }
92
93X509 *X509_KEY_new(void)
94 {
95 X509_KEY *ret=NULL;
96
97 M_ASN1_New_Malloc(ret,X509_KEY);
98 ret->references=1;
99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new);
101 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
102 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_NEW);
105 }
106
107void X509_KEY_free(X509 *a)
108 {
109 int i;
110
111 if (a == NULL) return;
112
113 i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
114#ifdef REF_PRINT
115 REF_PRINT("X509_KEY",a);
116#endif
117 if (i > 0) return;
118#ifdef REF_CHECK
119 if (i < 0)
120 {
121 fprintf(stderr,"X509_KEY_free, bad reference count\n");
122 abort();
123 }
124#endif
125
126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature);
129 Free(a);
130 }
131
diff --git a/src/lib/libssl/src/crypto/asn1/p8_pkey.c b/src/lib/libssl/src/crypto/asn1/p8_pkey.c
new file mode 100644
index 0000000000..aa9a4f6c96
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/p8_pkey.c
@@ -0,0 +1,129 @@
1/* p8_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_PKCS8_PRIV_KEY_INFO (PKCS8_PRIV_KEY_INFO *a, unsigned char **pp)
65{
66
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
70 M_ASN1_I2D_len (a->pkeyalg, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->pkey, i2d_ASN1_TYPE);
72 M_ASN1_I2D_len_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
73 i2d_X509_ATTRIBUTE, 0);
74
75 M_ASN1_I2D_seq_total ();
76
77 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put (a->pkeyalg, i2d_X509_ALGOR);
79 M_ASN1_I2D_put (a->pkey, i2d_ASN1_TYPE);
80 M_ASN1_I2D_put_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
81 i2d_X509_ATTRIBUTE, 0);
82
83 M_ASN1_I2D_finish();
84}
85
86PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void)
87{
88 PKCS8_PRIV_KEY_INFO *ret=NULL;
89 ASN1_CTX c;
90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO);
91 M_ASN1_New (ret->version, ASN1_INTEGER_new);
92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new);
93 M_ASN1_New (ret->pkey, ASN1_TYPE_new);
94 ret->attributes = NULL;
95 ret->broken = PKCS8_OK;
96 return (ret);
97 M_ASN1_New_Error(ASN1_F_PKCS8_PRIV_KEY_INFO_NEW);
98}
99
100PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
101 unsigned char **pp, long length)
102{
103 M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);
104 M_ASN1_D2I_Init();
105 M_ASN1_D2I_start_sequence();
106 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
107 M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);
108 M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);
109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
110 d2i_X509_ATTRIBUTE,
111 X509_ATTRIBUTE_free, 0);
112 if (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE)
113 ret->broken = PKCS8_NO_OCTET;
114 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
115}
116
117void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
118{
119 if (a == NULL) return;
120 ASN1_INTEGER_free (a->version);
121 X509_ALGOR_free(a->pkeyalg);
122 /* Clear sensitive data */
123 if (a->pkey->value.octet_string)
124 memset (a->pkey->value.octet_string->data,
125 0, a->pkey->value.octet_string->length);
126 ASN1_TYPE_free (a->pkey);
127 sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free);
128 Free (a);
129}
diff --git a/src/lib/libssl/src/crypto/asn1/t_bitst.c b/src/lib/libssl/src/crypto/asn1/t_bitst.c
new file mode 100644
index 0000000000..8ee789f082
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_bitst.c
@@ -0,0 +1,99 @@
1/* t_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65 BIT_STRING_BITNAME *tbl, int indent)
66{
67 BIT_STRING_BITNAME *bnam;
68 char first = 1;
69 BIO_printf(out, "%*s", indent, "");
70 for(bnam = tbl; bnam->lname; bnam++) {
71 if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72 if(!first) BIO_puts(out, ", ");
73 BIO_puts(out, bnam->lname);
74 first = 0;
75 }
76 }
77 BIO_puts(out, "\n");
78 return 1;
79}
80
81int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82 BIT_STRING_BITNAME *tbl)
83{
84 int bitnum;
85 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86 if(bitnum < 0) return 0;
87 if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value);
88 return 1;
89}
90
91int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
92{
93 BIT_STRING_BITNAME *bnam;
94 for(bnam = tbl; bnam->lname; bnam++) {
95 if(!strcmp(bnam->sname, name) ||
96 !strcmp(bnam->lname, name) ) return bnam->bitnum;
97 }
98 return -1;
99}
diff --git a/src/lib/libssl/src/crypto/asn1/t_crl.c b/src/lib/libssl/src/crypto/asn1/t_crl.c
new file mode 100644
index 0000000000..c2e447ce6f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_crl.c
@@ -0,0 +1,166 @@
1/* t_crl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67static void ext_print(BIO *out, X509_EXTENSION *ex);
68#ifndef NO_FP_API
69int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
70 {
71 BIO *b;
72 int ret;
73
74 if ((b=BIO_new(BIO_s_file())) == NULL)
75 {
76 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
77 return(0);
78 }
79 BIO_set_fp(b,fp,BIO_NOCLOSE);
80 ret=X509_CRL_print(b, x);
81 BIO_free(b);
82 return(ret);
83 }
84#endif
85
86int X509_CRL_print(BIO *out, X509_CRL *x)
87{
88 char buf[256];
89 unsigned char *s;
90 STACK_OF(X509_REVOKED) *rev;
91 X509_REVOKED *r;
92 long l;
93 int i, j, n;
94
95 BIO_printf(out, "Certificate Revocation List (CRL):\n");
96 l = X509_CRL_get_version(x);
97 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
98 i = OBJ_obj2nid(x->sig_alg->algorithm);
99 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
100 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
101 X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256);
102 BIO_printf(out,"%8sIssuer: %s\n","",buf);
103 BIO_printf(out,"%8sLast Update: ","");
104 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
105 BIO_printf(out,"\n%8sNext Update: ","");
106 if (X509_CRL_get_nextUpdate(x))
107 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
108 else BIO_printf(out,"NONE");
109 BIO_printf(out,"\n");
110
111 n=X509_CRL_get_ext_count(x);
112 if (n > 0) {
113 BIO_printf(out,"%8sCRL extensions:\n","");
114 for (i=0; i<n; i++) ext_print(out, X509_CRL_get_ext(x, i));
115 }
116
117
118 rev = X509_CRL_get_REVOKED(x);
119
120 if(sk_X509_REVOKED_num(rev))
121 BIO_printf(out, "Revoked Certificates:\n");
122 else BIO_printf(out, "No Revoked Certificates.\n");
123
124 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
125 r = sk_X509_REVOKED_value(rev, i);
126 BIO_printf(out," Serial Number: ");
127 i2a_ASN1_INTEGER(out,r->serialNumber);
128 BIO_printf(out,"\n Revocation Date: ","");
129 ASN1_TIME_print(out,r->revocationDate);
130 BIO_printf(out,"\n");
131 for(j = 0; j < X509_REVOKED_get_ext_count(r); j++)
132 ext_print(out, X509_REVOKED_get_ext(r, j));
133 }
134
135 i=OBJ_obj2nid(x->sig_alg->algorithm);
136 BIO_printf(out," Signature Algorithm: %s",
137 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
138
139 s = x->signature->data;
140 n = x->signature->length;
141 for (i=0; i<n; i++, s++)
142 {
143 if ((i%18) == 0) BIO_write(out,"\n ",9);
144 BIO_printf(out,"%02x%s",*s, ((i+1) == n)?"":":");
145 }
146 BIO_write(out,"\n",1);
147
148 return 1;
149
150}
151
152static void ext_print(BIO *out, X509_EXTENSION *ex)
153{
154 ASN1_OBJECT *obj;
155 int j;
156 BIO_printf(out,"%12s","");
157 obj=X509_EXTENSION_get_object(ex);
158 i2a_ASN1_OBJECT(out,obj);
159 j=X509_EXTENSION_get_critical(ex);
160 BIO_printf(out, ": %s\n", j ? "critical":"","");
161 if(!X509V3_EXT_print(out, ex, 0, 16)) {
162 BIO_printf(out, "%16s", "");
163 ASN1_OCTET_STRING_print(out,ex->value);
164 }
165 BIO_write(out,"\n",1);
166}
diff --git a/src/lib/libssl/src/crypto/asn1/t_spki.c b/src/lib/libssl/src/crypto/asn1/t_spki.c
new file mode 100644
index 0000000000..d708434fca
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_spki.c
@@ -0,0 +1,116 @@
1/* t_spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64/* Print out an SPKI */
65
66int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
67{
68 EVP_PKEY *pkey;
69 ASN1_IA5STRING *chal;
70 int i, n;
71 char *s;
72 BIO_printf(out, "Netscape SPKI:\n");
73 i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
74 BIO_printf(out," Public Key Algorithm: %s\n",
75 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
76 pkey = X509_PUBKEY_get(spki->spkac->pubkey);
77 if(!pkey) BIO_printf(out, " Unable to load public key\n");
78 else {
79#ifndef NO_RSA
80 if (pkey->type == EVP_PKEY_RSA)
81 {
82 BIO_printf(out," RSA Public Key: (%d bit)\n",
83 BN_num_bits(pkey->pkey.rsa->n));
84 RSA_print(out,pkey->pkey.rsa,2);
85 }
86 else
87#endif
88#ifndef NO_DSA
89 if (pkey->type == EVP_PKEY_DSA)
90 {
91 BIO_printf(out," DSA Public Key:\n");
92 DSA_print(out,pkey->pkey.dsa,2);
93 }
94 else
95#endif
96 BIO_printf(out," Unknown Public Key:\n");
97 EVP_PKEY_free(pkey);
98 }
99 chal = spki->spkac->challenge;
100 if(chal->length)
101 BIO_printf(out, " Challenge String: %s\n", chal->data);
102 i=OBJ_obj2nid(spki->sig_algor->algorithm);
103 BIO_printf(out," Signature Algorithm: %s",
104 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
105
106 n=spki->signature->length;
107 s=(char *)spki->signature->data;
108 for (i=0; i<n; i++)
109 {
110 if ((i%18) == 0) BIO_write(out,"\n ",7);
111 BIO_printf(out,"%02x%s",(unsigned char)s[i],
112 ((i+1) == n)?"":":");
113 }
114 BIO_write(out,"\n",1);
115 return 1;
116}
diff --git a/src/lib/libssl/src/crypto/asn1/t_x509a.c b/src/lib/libssl/src/crypto/asn1/t_x509a.c
new file mode 100644
index 0000000000..a18ebb586c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_x509a.c
@@ -0,0 +1,102 @@
1/* t_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX and string set routines
66 */
67
68int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
69{
70 char oidstr[80], first;
71 int i;
72 if(!aux) return 1;
73 if(aux->trust) {
74 first = 1;
75 BIO_printf(out, "%*sTrusted Uses:\n%*s",
76 indent, "", indent + 2, "");
77 for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
78 if(!first) BIO_puts(out, ", ");
79 else first = 0;
80 OBJ_obj2txt(oidstr, 80,
81 sk_ASN1_OBJECT_value(aux->trust, i), 0);
82 BIO_puts(out, oidstr);
83 }
84 BIO_puts(out, "\n");
85 } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
86 if(aux->reject) {
87 first = 1;
88 BIO_printf(out, "%*sRejected Uses:\n%*s",
89 indent, "", indent + 2, "");
90 for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
91 if(!first) BIO_puts(out, ", ");
92 else first = 0;
93 OBJ_obj2txt(oidstr, 80,
94 sk_ASN1_OBJECT_value(aux->reject, i), 0);
95 BIO_puts(out, oidstr);
96 }
97 BIO_puts(out, "\n");
98 } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
99 if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "",
100 aux->alias->data);
101 return 1;
102}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_dec.c b/src/lib/libssl/src/crypto/asn1/tasn_dec.c
new file mode 100644
index 0000000000..0fc1f421e2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_dec.c
@@ -0,0 +1,958 @@
1/* tasn_dec.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/buffer.h>
66#include <openssl/err.h>
67
68static int asn1_check_eoc(unsigned char **in, long len);
69static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass);
70static int collect_data(BUF_MEM *buf, unsigned char **p, long plen);
71static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
72 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx);
73static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
74static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
75static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len,
76 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
77
78/* Table to convert tags to bit values, used for MSTRING type */
79static unsigned long tag2bit[32]={
800, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
81B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
82B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
83B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
840, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
85B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
86B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
87B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
88B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
89 };
90
91unsigned long ASN1_tag2bit(int tag)
92{
93 if((tag < 0) || (tag > 30)) return 0;
94 return tag2bit[tag];
95}
96
97/* Macro to initialize and invalidate the cache */
98
99#define asn1_tlc_clear(c) if(c) (c)->valid = 0
100
101/* Decode an ASN1 item, this currently behaves just
102 * like a standard 'd2i' function. 'in' points to
103 * a buffer to read the data from, in future we will
104 * have more advanced versions that can input data
105 * a piece at a time and this will simply be a special
106 * case.
107 */
108
109ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it)
110{
111 ASN1_TLC c;
112 ASN1_VALUE *ptmpval = NULL;
113 if(!pval) pval = &ptmpval;
114 asn1_tlc_clear(&c);
115 if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
116 return *pval;
117 return NULL;
118}
119
120int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt)
121{
122 ASN1_TLC c;
123 asn1_tlc_clear(&c);
124 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
125}
126
127
128/* Decode an item, taking care of IMPLICIT tagging, if any.
129 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
130 */
131
132int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
133 int tag, int aclass, char opt, ASN1_TLC *ctx)
134{
135 const ASN1_TEMPLATE *tt, *errtt = NULL;
136 const ASN1_COMPAT_FUNCS *cf;
137 const ASN1_EXTERN_FUNCS *ef;
138 const ASN1_AUX *aux = it->funcs;
139 ASN1_aux_cb *asn1_cb;
140 unsigned char *p, *q, imphack = 0, oclass;
141 char seq_eoc, seq_nolen, cst, isopt;
142 long tmplen;
143 int i;
144 int otag;
145 int ret = 0;
146 ASN1_VALUE *pchval, **pchptr, *ptmpval;
147 if(!pval) return 0;
148 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
149 else asn1_cb = 0;
150
151 switch(it->itype) {
152
153 case ASN1_ITYPE_PRIMITIVE:
154 if(it->templates) {
155 /* tagging or OPTIONAL is currently illegal on an item template
156 * because the flags can't get passed down. In practice this isn't
157 * a problem: we include the relevant flags from the item template
158 * in the template itself.
159 */
160 if ((tag != -1) || opt) {
161 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
162 goto err;
163 }
164 return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx);
165 }
166 return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx);
167 break;
168
169 case ASN1_ITYPE_MSTRING:
170 p = *in;
171 /* Just read in tag and class */
172 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx);
173 if(!ret) {
174 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
175 goto err;
176 }
177 /* Must be UNIVERSAL class */
178 if(oclass != V_ASN1_UNIVERSAL) {
179 /* If OPTIONAL, assume this is OK */
180 if(opt) return -1;
181 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
182 goto err;
183 }
184 /* Check tag matches bit map */
185 if(!(ASN1_tag2bit(otag) & it->utype)) {
186 /* If OPTIONAL, assume this is OK */
187 if(opt) return -1;
188 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG);
189 goto err;
190 }
191 return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
192
193 case ASN1_ITYPE_EXTERN:
194 /* Use new style d2i */
195 ef = it->funcs;
196 return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
197
198 case ASN1_ITYPE_COMPAT:
199 /* we must resort to old style evil hackery */
200 cf = it->funcs;
201
202 /* If OPTIONAL see if it is there */
203 if(opt) {
204 int exptag;
205 p = *in;
206 if(tag == -1) exptag = it->utype;
207 else exptag = tag;
208 /* Don't care about anything other than presence of expected tag */
209 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx);
210 if(!ret) {
211 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
212 goto err;
213 }
214 if(ret == -1) return -1;
215 }
216 /* This is the old style evil hack IMPLICIT handling:
217 * since the underlying code is expecting a tag and
218 * class other than the one present we change the
219 * buffer temporarily then change it back afterwards.
220 * This doesn't and never did work for tags > 30.
221 *
222 * Yes this is *horrible* but it is only needed for
223 * old style d2i which will hopefully not be around
224 * for much longer.
225 * FIXME: should copy the buffer then modify it so
226 * the input buffer can be const: we should *always*
227 * copy because the old style d2i might modify the
228 * buffer.
229 */
230
231 if(tag != -1) {
232 p = *in;
233 imphack = *p;
234 *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype);
235 }
236
237 ptmpval = cf->asn1_d2i(pval, in, len);
238
239 if(tag != -1) *p = imphack;
240
241 if(ptmpval) return 1;
242 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
243 goto err;
244
245
246 case ASN1_ITYPE_CHOICE:
247 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
248 goto auxerr;
249
250 /* Allocate structure */
251 if(!*pval) {
252 if(!ASN1_item_ex_new(pval, it)) {
253 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
254 goto err;
255 }
256 }
257 /* CHOICE type, try each possibility in turn */
258 pchval = NULL;
259 p = *in;
260 for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
261 pchptr = asn1_get_field_ptr(pval, tt);
262 /* We mark field as OPTIONAL so its absence
263 * can be recognised.
264 */
265 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
266 /* If field not present, try the next one */
267 if(ret == -1) continue;
268 /* If positive return, read OK, break loop */
269 if(ret > 0) break;
270 /* Otherwise must be an ASN1 parsing error */
271 errtt = tt;
272 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
273 goto err;
274 }
275 /* Did we fall off the end without reading anything? */
276 if(i == it->tcount) {
277 /* If OPTIONAL, this is OK */
278 if(opt) {
279 /* Free and zero it */
280 ASN1_item_ex_free(pval, it);
281 return -1;
282 }
283 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
284 goto err;
285 }
286 asn1_set_choice_selector(pval, i, it);
287 *in = p;
288 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
289 goto auxerr;
290 return 1;
291
292 case ASN1_ITYPE_SEQUENCE:
293 p = *in;
294 tmplen = len;
295
296 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
297 if(tag == -1) {
298 tag = V_ASN1_SEQUENCE;
299 aclass = V_ASN1_UNIVERSAL;
300 }
301 /* Get SEQUENCE length and update len, p */
302 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx);
303 if(!ret) {
304 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
305 goto err;
306 } else if(ret == -1) return -1;
307 if(aux && (aux->flags & ASN1_AFLG_BROKEN)) {
308 len = tmplen - (p - *in);
309 seq_nolen = 1;
310 } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */
311 if(!cst) {
312 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
313 goto err;
314 }
315
316 if(!*pval) {
317 if(!ASN1_item_ex_new(pval, it)) {
318 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
319 goto err;
320 }
321 }
322 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
323 goto auxerr;
324
325 /* Get each field entry */
326 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
327 const ASN1_TEMPLATE *seqtt;
328 ASN1_VALUE **pseqval;
329 seqtt = asn1_do_adb(pval, tt, 1);
330 if(!seqtt) goto err;
331 pseqval = asn1_get_field_ptr(pval, seqtt);
332 /* Have we ran out of data? */
333 if(!len) break;
334 q = p;
335 if(asn1_check_eoc(&p, len)) {
336 if(!seq_eoc) {
337 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC);
338 goto err;
339 }
340 len -= p - q;
341 seq_eoc = 0;
342 q = p;
343 break;
344 }
345 /* This determines the OPTIONAL flag value. The field cannot
346 * be omitted if it is the last of a SEQUENCE and there is
347 * still data to be read. This isn't strictly necessary but
348 * it increases efficiency in some cases.
349 */
350 if(i == (it->tcount - 1)) isopt = 0;
351 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
352 /* attempt to read in field, allowing each to be OPTIONAL */
353 ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
354 if(!ret) {
355 errtt = seqtt;
356 goto err;
357 } else if(ret == -1) {
358 /* OPTIONAL component absent. Free and zero the field
359 */
360 ASN1_template_free(pseqval, seqtt);
361 continue;
362 }
363 /* Update length */
364 len -= p - q;
365 }
366 /* Check for EOC if expecting one */
367 if(seq_eoc && !asn1_check_eoc(&p, len)) {
368 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
369 goto err;
370 }
371 /* Check all data read */
372 if(!seq_nolen && len) {
373 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
374 goto err;
375 }
376
377 /* If we get here we've got no more data in the SEQUENCE,
378 * however we may not have read all fields so check all
379 * remaining are OPTIONAL and clear any that are.
380 */
381 for(; i < it->tcount; tt++, i++) {
382 const ASN1_TEMPLATE *seqtt;
383 seqtt = asn1_do_adb(pval, tt, 1);
384 if(!seqtt) goto err;
385 if(seqtt->flags & ASN1_TFLG_OPTIONAL) {
386 ASN1_VALUE **pseqval;
387 pseqval = asn1_get_field_ptr(pval, seqtt);
388 ASN1_template_free(pseqval, seqtt);
389 } else {
390 errtt = seqtt;
391 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING);
392 goto err;
393 }
394 }
395 /* Save encoding */
396 if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr;
397 *in = p;
398 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
399 goto auxerr;
400 return 1;
401
402 default:
403 return 0;
404 }
405 auxerr:
406 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
407 err:
408 ASN1_item_ex_free(pval, it);
409 if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
410 else ERR_add_error_data(2, "Type=", it->sname);
411 return 0;
412}
413
414/* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the
415 * rest.
416 */
417
418static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
419{
420 int flags, aclass;
421 int ret;
422 long len;
423 unsigned char *p, *q;
424 char exp_eoc;
425 if(!val) return 0;
426 flags = tt->flags;
427 aclass = flags & ASN1_TFLG_TAG_CLASS;
428
429 p = *in;
430
431 /* Check if EXPLICIT tag expected */
432 if(flags & ASN1_TFLG_EXPTAG) {
433 char cst;
434 /* Need to work out amount of data available to the inner content and where it
435 * starts: so read in EXPLICIT header to get the info.
436 */
437 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx);
438 q = p;
439 if(!ret) {
440 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
441 return 0;
442 } else if(ret == -1) return -1;
443 if(!cst) {
444 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
445 return 0;
446 }
447 /* We've found the field so it can't be OPTIONAL now */
448 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
449 if(!ret) {
450 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
451 return 0;
452 }
453 /* We read the field in OK so update length */
454 len -= p - q;
455 if(exp_eoc) {
456 /* If NDEF we must have an EOC here */
457 if(!asn1_check_eoc(&p, len)) {
458 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
459 goto err;
460 }
461 } else {
462 /* Otherwise we must hit the EXPLICIT tag end or its an error */
463 if(len) {
464 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
465 goto err;
466 }
467 }
468 } else
469 return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
470
471 *in = p;
472 return 1;
473
474 err:
475 ASN1_template_free(val, tt);
476 *val = NULL;
477 return 0;
478}
479
480static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
481{
482 int flags, aclass;
483 int ret;
484 unsigned char *p, *q;
485 if(!val) return 0;
486 flags = tt->flags;
487 aclass = flags & ASN1_TFLG_TAG_CLASS;
488
489 p = *in;
490 q = p;
491
492 if(flags & ASN1_TFLG_SK_MASK) {
493 /* SET OF, SEQUENCE OF */
494 int sktag, skaclass;
495 char sk_eoc;
496 /* First work out expected inner tag value */
497 if(flags & ASN1_TFLG_IMPTAG) {
498 sktag = tt->tag;
499 skaclass = aclass;
500 } else {
501 skaclass = V_ASN1_UNIVERSAL;
502 if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET;
503 else sktag = V_ASN1_SEQUENCE;
504 }
505 /* Get the tag */
506 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx);
507 if(!ret) {
508 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
509 return 0;
510 } else if(ret == -1) return -1;
511 if(!*val) *val = (ASN1_VALUE *)sk_new_null();
512 else {
513 /* We've got a valid STACK: free up any items present */
514 STACK *sktmp = (STACK *)*val;
515 ASN1_VALUE *vtmp;
516 while(sk_num(sktmp) > 0) {
517 vtmp = (ASN1_VALUE *)sk_pop(sktmp);
518 ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
519 }
520 }
521
522 if(!*val) {
523 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE);
524 goto err;
525 }
526 /* Read as many items as we can */
527 while(len > 0) {
528 ASN1_VALUE *skfield;
529 q = p;
530 /* See if EOC found */
531 if(asn1_check_eoc(&p, len)) {
532 if(!sk_eoc) {
533 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC);
534 goto err;
535 }
536 len -= p - q;
537 sk_eoc = 0;
538 break;
539 }
540 skfield = NULL;
541 if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
542 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
543 goto err;
544 }
545 len -= p - q;
546 if(!sk_push((STACK *)*val, (char *)skfield)) {
547 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE);
548 goto err;
549 }
550 }
551 if(sk_eoc) {
552 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
553 goto err;
554 }
555 } else if(flags & ASN1_TFLG_IMPTAG) {
556 /* IMPLICIT tagging */
557 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
558 if(!ret) {
559 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
560 goto err;
561 } else if(ret == -1) return -1;
562 } else {
563 /* Nothing special */
564 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx);
565 if(!ret) {
566 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
567 goto err;
568 } else if(ret == -1) return -1;
569 }
570
571 *in = p;
572 return 1;
573
574 err:
575 ASN1_template_free(val, tt);
576 *val = NULL;
577 return 0;
578}
579
580static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen,
581 const ASN1_ITEM *it,
582 int tag, int aclass, char opt, ASN1_TLC *ctx)
583{
584 int ret = 0, utype;
585 long plen;
586 char cst, inf, free_cont = 0;
587 unsigned char *p;
588 BUF_MEM buf;
589 unsigned char *cont = NULL;
590 long len;
591 if(!pval) {
592 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
593 return 0; /* Should never happen */
594 }
595
596 if(it->itype == ASN1_ITYPE_MSTRING) {
597 utype = tag;
598 tag = -1;
599 } else utype = it->utype;
600
601 if(utype == V_ASN1_ANY) {
602 /* If type is ANY need to figure out type from tag */
603 unsigned char oclass;
604 if(tag >= 0) {
605 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY);
606 return 0;
607 }
608 if(opt) {
609 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY);
610 return 0;
611 }
612 p = *in;
613 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx);
614 if(!ret) {
615 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
616 return 0;
617 }
618 if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER;
619 }
620 if(tag == -1) {
621 tag = utype;
622 aclass = V_ASN1_UNIVERSAL;
623 }
624 p = *in;
625 /* Check header */
626 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx);
627 if(!ret) {
628 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
629 return 0;
630 } else if(ret == -1) return -1;
631 /* SEQUENCE, SET and "OTHER" are left in encoded form */
632 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
633 /* Clear context cache for type OTHER because the auto clear when
634 * we have a exact match wont work
635 */
636 if(utype == V_ASN1_OTHER) {
637 asn1_tlc_clear(ctx);
638 /* SEQUENCE and SET must be constructed */
639 } else if(!cst) {
640 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED);
641 return 0;
642 }
643
644 cont = *in;
645 /* If indefinite length constructed find the real end */
646 if(inf) {
647 if(!asn1_collect(NULL, &p, plen, inf, -1, -1)) goto err;
648 len = p - cont;
649 } else {
650 len = p - cont + plen;
651 p += plen;
652 buf.data = NULL;
653 }
654 } else if(cst) {
655 buf.length = 0;
656 buf.max = 0;
657 buf.data = NULL;
658 /* Should really check the internal tags are correct but
659 * some things may get this wrong. The relevant specs
660 * say that constructed string types should be OCTET STRINGs
661 * internally irrespective of the type. So instead just check
662 * for UNIVERSAL class and ignore the tag.
663 */
664 if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err;
665 len = buf.length;
666 /* Append a final null to string */
667 if(!BUF_MEM_grow(&buf, len + 1)) {
668 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
669 return 0;
670 }
671 buf.data[len] = 0;
672 cont = (unsigned char *)buf.data;
673 free_cont = 1;
674 } else {
675 cont = p;
676 len = plen;
677 p += plen;
678 }
679
680 /* We now have content length and type: translate into a structure */
681 if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err;
682
683 *in = p;
684 ret = 1;
685 err:
686 if(free_cont && buf.data) OPENSSL_free(buf.data);
687 return ret;
688}
689
690/* Translate ASN1 content octets into a structure */
691
692int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
693{
694 ASN1_STRING *stmp;
695 ASN1_TYPE *typ = NULL;
696 int ret = 0;
697 const ASN1_PRIMITIVE_FUNCS *pf;
698 ASN1_INTEGER **tint;
699 pf = it->funcs;
700 if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
701 /* If ANY type clear type and set pointer to internal value */
702 if(it->utype == V_ASN1_ANY) {
703 if(!*pval) {
704 typ = ASN1_TYPE_new();
705 *pval = (ASN1_VALUE *)typ;
706 } else typ = (ASN1_TYPE *)*pval;
707 if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL);
708 pval = (ASN1_VALUE **)&typ->value.ptr;
709 }
710 switch(utype) {
711 case V_ASN1_OBJECT:
712 if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err;
713 break;
714
715 case V_ASN1_NULL:
716 if(len) {
717 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH);
718 goto err;
719 }
720 *pval = (ASN1_VALUE *)1;
721 break;
722
723 case V_ASN1_BOOLEAN:
724 if(len != 1) {
725 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
726 goto err;
727 } else {
728 ASN1_BOOLEAN *tbool;
729 tbool = (ASN1_BOOLEAN *)pval;
730 *tbool = *cont;
731 }
732 break;
733
734 case V_ASN1_BIT_STRING:
735 if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err;
736 break;
737
738 case V_ASN1_INTEGER:
739 case V_ASN1_NEG_INTEGER:
740 case V_ASN1_ENUMERATED:
741 case V_ASN1_NEG_ENUMERATED:
742 tint = (ASN1_INTEGER **)pval;
743 if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err;
744 /* Fixup type to match the expected form */
745 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
746 break;
747
748 case V_ASN1_OCTET_STRING:
749 case V_ASN1_NUMERICSTRING:
750 case V_ASN1_PRINTABLESTRING:
751 case V_ASN1_T61STRING:
752 case V_ASN1_VIDEOTEXSTRING:
753 case V_ASN1_IA5STRING:
754 case V_ASN1_UTCTIME:
755 case V_ASN1_GENERALIZEDTIME:
756 case V_ASN1_GRAPHICSTRING:
757 case V_ASN1_VISIBLESTRING:
758 case V_ASN1_GENERALSTRING:
759 case V_ASN1_UNIVERSALSTRING:
760 case V_ASN1_BMPSTRING:
761 case V_ASN1_UTF8STRING:
762 case V_ASN1_OTHER:
763 case V_ASN1_SET:
764 case V_ASN1_SEQUENCE:
765 default:
766 /* All based on ASN1_STRING and handled the same */
767 if(!*pval) {
768 stmp = ASN1_STRING_type_new(utype);
769 if(!stmp) {
770 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
771 goto err;
772 }
773 *pval = (ASN1_VALUE *)stmp;
774 } else {
775 stmp = (ASN1_STRING *)*pval;
776 stmp->type = utype;
777 }
778 /* If we've already allocated a buffer use it */
779 if(*free_cont) {
780 if(stmp->data) OPENSSL_free(stmp->data);
781 stmp->data = cont;
782 stmp->length = len;
783 *free_cont = 0;
784 } else {
785 if(!ASN1_STRING_set(stmp, cont, len)) {
786 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
787 ASN1_STRING_free(stmp);
788 *pval = NULL;
789 goto err;
790 }
791 }
792 break;
793 }
794 /* If ASN1_ANY and NULL type fix up value */
795 if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL;
796
797 ret = 1;
798 err:
799 if(!ret) ASN1_TYPE_free(typ);
800 return ret;
801}
802
803/* This function collects the asn1 data from a constructred string
804 * type into a buffer. The values of 'in' and 'len' should refer
805 * to the contents of the constructed type and 'inf' should be set
806 * if it is indefinite length. If 'buf' is NULL then we just want
807 * to find the end of the current structure: useful for indefinite
808 * length constructed stuff.
809 */
810
811static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass)
812{
813 unsigned char *p, *q;
814 long plen;
815 char cst, ininf;
816 p = *in;
817 inf &= 1;
818 /* If no buffer and not indefinite length constructed just pass over the encoded data */
819 if(!buf && !inf) {
820 *in += len;
821 return 1;
822 }
823 while(len > 0) {
824 q = p;
825 /* Check for EOC */
826 if(asn1_check_eoc(&p, len)) {
827 /* EOC is illegal outside indefinite length constructed form */
828 if(!inf) {
829 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
830 return 0;
831 }
832 inf = 0;
833 break;
834 }
835 if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) {
836 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
837 return 0;
838 }
839 /* If indefinite length constructed update max length */
840 if(cst) {
841 if(!asn1_collect(buf, &p, plen, ininf, tag, aclass)) return 0;
842 } else {
843 if(!collect_data(buf, &p, plen)) return 0;
844 }
845 len -= p - q;
846 }
847 if(inf) {
848 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
849 return 0;
850 }
851 *in = p;
852 return 1;
853}
854
855static int collect_data(BUF_MEM *buf, unsigned char **p, long plen)
856{
857 int len;
858 if(buf) {
859 len = buf->length;
860 if(!BUF_MEM_grow(buf, len + plen)) {
861 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
862 return 0;
863 }
864 memcpy(buf->data + len, *p, plen);
865 }
866 *p += plen;
867 return 1;
868}
869
870/* Check for ASN1 EOC and swallow it if found */
871
872static int asn1_check_eoc(unsigned char **in, long len)
873{
874 unsigned char *p;
875 if(len < 2) return 0;
876 p = *in;
877 if(!p[0] && !p[1]) {
878 *in += 2;
879 return 1;
880 }
881 return 0;
882}
883
884/* Check an ASN1 tag and length: a bit like ASN1_get_object
885 * but it sets the length for indefinite length constructed
886 * form, we don't know the exact length but we can set an
887 * upper bound to the amount of data available minus the
888 * header length just read.
889 */
890
891static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
892 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx)
893{
894 int i;
895 int ptag, pclass;
896 long plen;
897 unsigned char *p, *q;
898 p = *in;
899 q = p;
900
901 if(ctx && ctx->valid) {
902 i = ctx->ret;
903 plen = ctx->plen;
904 pclass = ctx->pclass;
905 ptag = ctx->ptag;
906 p += ctx->hdrlen;
907 } else {
908 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
909 if(ctx) {
910 ctx->ret = i;
911 ctx->plen = plen;
912 ctx->pclass = pclass;
913 ctx->ptag = ptag;
914 ctx->hdrlen = p - q;
915 ctx->valid = 1;
916 /* If definite length, length + header can't exceed total
917 * amount of data available.
918 */
919 if(!(i & 1) && ((plen + ctx->hdrlen) > len)) {
920 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
921 asn1_tlc_clear(ctx);
922 return 0;
923 }
924 }
925 }
926
927 if(i & 0x80) {
928 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
929 asn1_tlc_clear(ctx);
930 return 0;
931 }
932 if(exptag >= 0) {
933 if((exptag != ptag) || (expclass != pclass)) {
934 /* If type is OPTIONAL, not an error, but indicate missing
935 * type.
936 */
937 if(opt) return -1;
938 asn1_tlc_clear(ctx);
939 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
940 return 0;
941 }
942 /* We have a tag and class match, so assume we are going to do something with it */
943 asn1_tlc_clear(ctx);
944 }
945
946 if(i & 1) plen = len - (p - q);
947
948 if(inf) *inf = i & 1;
949
950 if(cst) *cst = i & V_ASN1_CONSTRUCTED;
951
952 if(olen) *olen = plen;
953 if(oclass) *oclass = pclass;
954 if(otag) *otag = ptag;
955
956 *in = p;
957 return 1;
958}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_enc.c b/src/lib/libssl/src/crypto/asn1/tasn_enc.c
new file mode 100644
index 0000000000..f6c8ddef0a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_enc.c
@@ -0,0 +1,497 @@
1/* tasn_enc.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65
66static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
67static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
68
69/* Encode an ASN1 item, this is compatible with the
70 * standard 'i2d' function. 'out' points to
71 * a buffer to output the data to, in future we will
72 * have more advanced versions that can output data
73 * a piece at a time and this will simply be a special
74 * case.
75 *
76 * The new i2d has one additional feature. If the output
77 * buffer is NULL (i.e. *out == NULL) then a buffer is
78 * allocated and populated with the encoding.
79 */
80
81
82int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
83{
84 if(out && !*out) {
85 unsigned char *p, *buf;
86 int len;
87 len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
88 if(len <= 0) return len;
89 buf = OPENSSL_malloc(len);
90 if(!buf) return -1;
91 p = buf;
92 ASN1_item_ex_i2d(&val, &p, it, -1, 0);
93 *out = buf;
94 return len;
95 }
96
97 return ASN1_item_ex_i2d(&val, out, it, -1, 0);
98}
99
100/* Encode an item, taking care of IMPLICIT tagging (if any).
101 * This function performs the normal item handling: it can be
102 * used in external types.
103 */
104
105int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
106{
107 const ASN1_TEMPLATE *tt = NULL;
108 unsigned char *p = NULL;
109 int i, seqcontlen, seqlen;
110 ASN1_STRING *strtmp;
111 const ASN1_COMPAT_FUNCS *cf;
112 const ASN1_EXTERN_FUNCS *ef;
113 const ASN1_AUX *aux = it->funcs;
114 ASN1_aux_cb *asn1_cb;
115 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
116 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
117 else asn1_cb = 0;
118
119 switch(it->itype) {
120
121 case ASN1_ITYPE_PRIMITIVE:
122 if(it->templates)
123 return ASN1_template_i2d(pval, out, it->templates);
124 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
125 break;
126
127 case ASN1_ITYPE_MSTRING:
128 strtmp = (ASN1_STRING *)*pval;
129 return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
130
131 case ASN1_ITYPE_CHOICE:
132 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
133 return 0;
134 i = asn1_get_choice_selector(pval, it);
135 if((i >= 0) && (i < it->tcount)) {
136 ASN1_VALUE **pchval;
137 const ASN1_TEMPLATE *chtt;
138 chtt = it->templates + i;
139 pchval = asn1_get_field_ptr(pval, chtt);
140 return ASN1_template_i2d(pchval, out, chtt);
141 }
142 /* Fixme: error condition if selector out of range */
143 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
144 return 0;
145 break;
146
147 case ASN1_ITYPE_EXTERN:
148 /* If new style i2d it does all the work */
149 ef = it->funcs;
150 return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
151
152 case ASN1_ITYPE_COMPAT:
153 /* old style hackery... */
154 cf = it->funcs;
155 if(out) p = *out;
156 i = cf->asn1_i2d(*pval, out);
157 /* Fixup for IMPLICIT tag: note this messes up for tags > 30,
158 * but so did the old code. Tags > 30 are very rare anyway.
159 */
160 if(out && (tag != -1))
161 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
162 return i;
163
164 case ASN1_ITYPE_SEQUENCE:
165 i = asn1_enc_restore(&seqcontlen, out, pval, it);
166 /* An error occurred */
167 if(i < 0) return 0;
168 /* We have a valid cached encoding... */
169 if(i > 0) return seqcontlen;
170 /* Otherwise carry on */
171 seqcontlen = 0;
172 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
173 if(tag == -1) {
174 tag = V_ASN1_SEQUENCE;
175 aclass = V_ASN1_UNIVERSAL;
176 }
177 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
178 return 0;
179 /* First work out sequence content length */
180 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
181 const ASN1_TEMPLATE *seqtt;
182 ASN1_VALUE **pseqval;
183 seqtt = asn1_do_adb(pval, tt, 1);
184 if(!seqtt) return 0;
185 pseqval = asn1_get_field_ptr(pval, seqtt);
186 /* FIXME: check for errors in enhanced version */
187 /* FIXME: special handling of indefinite length encoding */
188 seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
189 }
190 seqlen = ASN1_object_size(1, seqcontlen, tag);
191 if(!out) return seqlen;
192 /* Output SEQUENCE header */
193 ASN1_put_object(out, 1, seqcontlen, tag, aclass);
194 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
195 const ASN1_TEMPLATE *seqtt;
196 ASN1_VALUE **pseqval;
197 seqtt = asn1_do_adb(pval, tt, 1);
198 if(!seqtt) return 0;
199 pseqval = asn1_get_field_ptr(pval, seqtt);
200 /* FIXME: check for errors in enhanced version */
201 ASN1_template_i2d(pseqval, out, seqtt);
202 }
203 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
204 return 0;
205 return seqlen;
206
207 default:
208 return 0;
209 }
210 return 0;
211}
212
213int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
214{
215 int i, ret, flags, aclass;
216 flags = tt->flags;
217 aclass = flags & ASN1_TFLG_TAG_CLASS;
218 if(flags & ASN1_TFLG_SK_MASK) {
219 /* SET OF, SEQUENCE OF */
220 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
221 int isset, sktag, skaclass;
222 int skcontlen, sklen;
223 ASN1_VALUE *skitem;
224 if(!*pval) return 0;
225 if(flags & ASN1_TFLG_SET_OF) {
226 isset = 1;
227 /* 2 means we reorder */
228 if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
229 } else isset = 0;
230 /* First work out inner tag value */
231 if(flags & ASN1_TFLG_IMPTAG) {
232 sktag = tt->tag;
233 skaclass = aclass;
234 } else {
235 skaclass = V_ASN1_UNIVERSAL;
236 if(isset) sktag = V_ASN1_SET;
237 else sktag = V_ASN1_SEQUENCE;
238 }
239 /* Now work out length of items */
240 skcontlen = 0;
241 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
242 skitem = sk_ASN1_VALUE_value(sk, i);
243 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
244 }
245 sklen = ASN1_object_size(1, skcontlen, sktag);
246 /* If EXPLICIT need length of surrounding tag */
247 if(flags & ASN1_TFLG_EXPTAG)
248 ret = ASN1_object_size(1, sklen, tt->tag);
249 else ret = sklen;
250
251 if(!out) return ret;
252
253 /* Now encode this lot... */
254 /* EXPLICIT tag */
255 if(flags & ASN1_TFLG_EXPTAG)
256 ASN1_put_object(out, 1, sklen, tt->tag, aclass);
257 /* SET or SEQUENCE and IMPLICIT tag */
258 ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
259 /* And finally the stuff itself */
260 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
261
262 return ret;
263 }
264
265 if(flags & ASN1_TFLG_EXPTAG) {
266 /* EXPLICIT tagging */
267 /* Find length of tagged item */
268 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
269 if(!i) return 0;
270 /* Find length of EXPLICIT tag */
271 ret = ASN1_object_size(1, i, tt->tag);
272 if(out) {
273 /* Output tag and item */
274 ASN1_put_object(out, 1, i, tt->tag, aclass);
275 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
276 }
277 return ret;
278 }
279 if(flags & ASN1_TFLG_IMPTAG) {
280 /* IMPLICIT tagging */
281 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
282 }
283 /* Nothing special: treat as normal */
284 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
285}
286
287/* Temporary structure used to hold DER encoding of items for SET OF */
288
289typedef struct {
290 unsigned char *data;
291 int length;
292 ASN1_VALUE *field;
293} DER_ENC;
294
295static int der_cmp(const void *a, const void *b)
296{
297 const DER_ENC *d1 = a, *d2 = b;
298 int cmplen, i;
299 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
300 i = memcmp(d1->data, d2->data, cmplen);
301 if(i) return i;
302 return d1->length - d2->length;
303}
304
305/* Output the content octets of SET OF or SEQUENCE OF */
306
307static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
308{
309 int i;
310 ASN1_VALUE *skitem;
311 unsigned char *tmpdat = NULL, *p = NULL;
312 DER_ENC *derlst = NULL, *tder;
313 if(do_sort) {
314 /* Don't need to sort less than 2 items */
315 if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0;
316 else {
317 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst));
318 tmpdat = OPENSSL_malloc(skcontlen);
319 if(!derlst || !tmpdat) return 0;
320 }
321 }
322 /* If not sorting just output each item */
323 if(!do_sort) {
324 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
325 skitem = sk_ASN1_VALUE_value(sk, i);
326 ASN1_item_i2d(skitem, out, item);
327 }
328 return 1;
329 }
330 p = tmpdat;
331 /* Doing sort: build up a list of each member's DER encoding */
332 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
333 skitem = sk_ASN1_VALUE_value(sk, i);
334 tder->data = p;
335 tder->length = ASN1_item_i2d(skitem, &p, item);
336 tder->field = skitem;
337 }
338 /* Now sort them */
339 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
340 /* Output sorted DER encoding */
341 p = *out;
342 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
343 memcpy(p, tder->data, tder->length);
344 p += tder->length;
345 }
346 *out = p;
347 /* If do_sort is 2 then reorder the STACK */
348 if(do_sort == 2) {
349 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
350 sk_ASN1_VALUE_set(sk, i, tder->field);
351 }
352 OPENSSL_free(derlst);
353 OPENSSL_free(tmpdat);
354 return 1;
355}
356
357static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
358{
359 int len;
360 int utype;
361 int usetag;
362
363 utype = it->utype;
364
365 /* Get length of content octets and maybe find
366 * out the underlying type.
367 */
368
369 len = asn1_ex_i2c(pval, NULL, &utype, it);
370
371 /* If SEQUENCE, SET or OTHER then header is
372 * included in pseudo content octets so don't
373 * include tag+length. We need to check here
374 * because the call to asn1_ex_i2c() could change
375 * utype.
376 */
377 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
378 (utype == V_ASN1_OTHER))
379 usetag = 0;
380 else usetag = 1;
381
382 /* -1 means omit type */
383
384 if(len == -1) return 0;
385
386 /* If not implicitly tagged get tag from underlying type */
387 if(tag == -1) tag = utype;
388
389 /* Output tag+length followed by content octets */
390 if(out) {
391 if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
392 asn1_ex_i2c(pval, *out, &utype, it);
393 *out += len;
394 }
395
396 if(usetag) return ASN1_object_size(0, len, tag);
397 return len;
398}
399
400/* Produce content octets from a structure */
401
402int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it)
403{
404 ASN1_BOOLEAN *tbool = NULL;
405 ASN1_STRING *strtmp;
406 ASN1_OBJECT *otmp;
407 int utype;
408 unsigned char *cont, c;
409 int len;
410 const ASN1_PRIMITIVE_FUNCS *pf;
411 pf = it->funcs;
412 if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it);
413
414 /* Should type be omitted? */
415 if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
416 if(!*pval) return -1;
417 }
418
419 if(it->itype == ASN1_ITYPE_MSTRING) {
420 /* If MSTRING type set the underlying type */
421 strtmp = (ASN1_STRING *)*pval;
422 utype = strtmp->type;
423 *putype = utype;
424 } else if(it->utype == V_ASN1_ANY) {
425 /* If ANY set type and pointer to value */
426 ASN1_TYPE *typ;
427 typ = (ASN1_TYPE *)*pval;
428 utype = typ->type;
429 *putype = utype;
430 pval = (ASN1_VALUE **)&typ->value.ptr;
431 } else utype = *putype;
432
433 switch(utype) {
434 case V_ASN1_OBJECT:
435 otmp = (ASN1_OBJECT *)*pval;
436 cont = otmp->data;
437 len = otmp->length;
438 break;
439
440 case V_ASN1_NULL:
441 cont = NULL;
442 len = 0;
443 break;
444
445 case V_ASN1_BOOLEAN:
446 tbool = (ASN1_BOOLEAN *)pval;
447 if(*tbool == -1) return -1;
448 /* Default handling if value == size field then omit */
449 if(*tbool && (it->size > 0)) return -1;
450 if(!*tbool && !it->size) return -1;
451 c = (unsigned char)*tbool;
452 cont = &c;
453 len = 1;
454 break;
455
456 case V_ASN1_BIT_STRING:
457 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
458 break;
459
460 case V_ASN1_INTEGER:
461 case V_ASN1_NEG_INTEGER:
462 case V_ASN1_ENUMERATED:
463 case V_ASN1_NEG_ENUMERATED:
464 /* These are all have the same content format
465 * as ASN1_INTEGER
466 */
467 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
468 break;
469
470 case V_ASN1_OCTET_STRING:
471 case V_ASN1_NUMERICSTRING:
472 case V_ASN1_PRINTABLESTRING:
473 case V_ASN1_T61STRING:
474 case V_ASN1_VIDEOTEXSTRING:
475 case V_ASN1_IA5STRING:
476 case V_ASN1_UTCTIME:
477 case V_ASN1_GENERALIZEDTIME:
478 case V_ASN1_GRAPHICSTRING:
479 case V_ASN1_VISIBLESTRING:
480 case V_ASN1_GENERALSTRING:
481 case V_ASN1_UNIVERSALSTRING:
482 case V_ASN1_BMPSTRING:
483 case V_ASN1_UTF8STRING:
484 case V_ASN1_SEQUENCE:
485 case V_ASN1_SET:
486 default:
487 /* All based on ASN1_STRING and handled the same */
488 strtmp = (ASN1_STRING *)*pval;
489 cont = strtmp->data;
490 len = strtmp->length;
491
492 break;
493
494 }
495 if(cout && len) memcpy(cout, cont, len);
496 return len;
497}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_fre.c b/src/lib/libssl/src/crypto/asn1/tasn_fre.c
new file mode 100644
index 0000000000..c7610776f2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_fre.c
@@ -0,0 +1,226 @@
1/* tasn_fre.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63#include <openssl/objects.h>
64
65static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
66
67/* Free up an ASN1 structure */
68
69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70{
71 asn1_item_combine_free(&val, it, 0);
72}
73
74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75{
76 asn1_item_combine_free(pval, it, 0);
77}
78
79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80{
81 const ASN1_TEMPLATE *tt = NULL, *seqtt;
82 const ASN1_EXTERN_FUNCS *ef;
83 const ASN1_COMPAT_FUNCS *cf;
84 const ASN1_AUX *aux = it->funcs;
85 ASN1_aux_cb *asn1_cb;
86 int i;
87 if(!pval) return;
88 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90 else asn1_cb = 0;
91
92 switch(it->itype) {
93
94 case ASN1_ITYPE_PRIMITIVE:
95 if(it->templates) ASN1_template_free(pval, it->templates);
96 else ASN1_primitive_free(pval, it);
97 break;
98
99 case ASN1_ITYPE_MSTRING:
100 ASN1_primitive_free(pval, it);
101 break;
102
103 case ASN1_ITYPE_CHOICE:
104 if(asn1_cb) {
105 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
106 if(i == 2) return;
107 }
108 i = asn1_get_choice_selector(pval, it);
109 if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
110 if((i >= 0) && (i < it->tcount)) {
111 ASN1_VALUE **pchval;
112 tt = it->templates + i;
113 pchval = asn1_get_field_ptr(pval, tt);
114 ASN1_template_free(pchval, tt);
115 }
116 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
117 if(!combine) {
118 OPENSSL_free(*pval);
119 *pval = NULL;
120 }
121 break;
122
123 case ASN1_ITYPE_COMPAT:
124 cf = it->funcs;
125 if(cf && cf->asn1_free) cf->asn1_free(*pval);
126 break;
127
128 case ASN1_ITYPE_EXTERN:
129 ef = it->funcs;
130 if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
131 break;
132
133 case ASN1_ITYPE_SEQUENCE:
134 if(asn1_do_lock(pval, -1, it) > 0) return;
135 if(asn1_cb) {
136 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
137 if(i == 2) return;
138 }
139 asn1_enc_free(pval, it);
140 /* If we free up as normal we will invalidate any
141 * ANY DEFINED BY field and we wont be able to
142 * determine the type of the field it defines. So
143 * free up in reverse order.
144 */
145 tt = it->templates + it->tcount - 1;
146 for(i = 0; i < it->tcount; tt--, i++) {
147 ASN1_VALUE **pseqval;
148 seqtt = asn1_do_adb(pval, tt, 0);
149 if(!seqtt) continue;
150 pseqval = asn1_get_field_ptr(pval, seqtt);
151 ASN1_template_free(pseqval, seqtt);
152 }
153 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
154 if(!combine) {
155 OPENSSL_free(*pval);
156 *pval = NULL;
157 }
158 break;
159 }
160}
161
162void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
163{
164 int i;
165 if(tt->flags & ASN1_TFLG_SK_MASK) {
166 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
167 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
168 ASN1_VALUE *vtmp;
169 vtmp = sk_ASN1_VALUE_value(sk, i);
170 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
171 }
172 sk_ASN1_VALUE_free(sk);
173 *pval = NULL;
174 } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
175 tt->flags & ASN1_TFLG_COMBINE);
176}
177
178void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
179{
180 int utype;
181 if(it) {
182 const ASN1_PRIMITIVE_FUNCS *pf;
183 pf = it->funcs;
184 if(pf && pf->prim_free) {
185 pf->prim_free(pval, it);
186 return;
187 }
188 }
189 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
190 if(!it) {
191 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
192 utype = typ->type;
193 pval = (ASN1_VALUE **)&typ->value.ptr;
194 if(!*pval) return;
195 } else if(it->itype == ASN1_ITYPE_MSTRING) {
196 utype = -1;
197 if(!*pval) return;
198 } else {
199 utype = it->utype;
200 if((utype != V_ASN1_BOOLEAN) && !*pval) return;
201 }
202
203 switch(utype) {
204 case V_ASN1_OBJECT:
205 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
206 break;
207
208 case V_ASN1_BOOLEAN:
209 *(ASN1_BOOLEAN *)pval = it->size;
210 return;
211
212 case V_ASN1_NULL:
213 break;
214
215 case V_ASN1_ANY:
216 ASN1_primitive_free(pval, NULL);
217 OPENSSL_free(*pval);
218 break;
219
220 default:
221 ASN1_STRING_free((ASN1_STRING *)*pval);
222 *pval = NULL;
223 break;
224 }
225 *pval = NULL;
226}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_new.c b/src/lib/libssl/src/crypto/asn1/tasn_new.c
new file mode 100644
index 0000000000..e33861f864
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_new.c
@@ -0,0 +1,348 @@
1/* tasn_new.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/err.h>
64#include <openssl/asn1t.h>
65#include <string.h>
66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
71
72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
73{
74 ASN1_VALUE *ret = NULL;
75 if(ASN1_item_ex_new(&ret, it) > 0) return ret;
76 return NULL;
77}
78
79/* Allocate an ASN1 structure */
80
81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
82{
83 return asn1_item_ex_combine_new(pval, it, 0);
84}
85
86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
87{
88 const ASN1_TEMPLATE *tt = NULL;
89 const ASN1_COMPAT_FUNCS *cf;
90 const ASN1_EXTERN_FUNCS *ef;
91 const ASN1_AUX *aux = it->funcs;
92 ASN1_aux_cb *asn1_cb;
93 ASN1_VALUE **pseqval;
94 int i;
95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
96 else asn1_cb = 0;
97
98 if(!combine) *pval = NULL;
99
100#ifdef CRYPTO_MDEBUG
101 if(it->sname) CRYPTO_push_info(it->sname);
102#endif
103
104 switch(it->itype) {
105
106 case ASN1_ITYPE_EXTERN:
107 ef = it->funcs;
108 if(ef && ef->asn1_ex_new) {
109 if(!ef->asn1_ex_new(pval, it))
110 goto memerr;
111 }
112 break;
113
114 case ASN1_ITYPE_COMPAT:
115 cf = it->funcs;
116 if(cf && cf->asn1_new) {
117 *pval = cf->asn1_new();
118 if(!*pval) goto memerr;
119 }
120 break;
121
122 case ASN1_ITYPE_PRIMITIVE:
123 if(it->templates) {
124 if(!ASN1_template_new(pval, it->templates))
125 goto memerr;
126 } else {
127 if(!ASN1_primitive_new(pval, it))
128 goto memerr;
129 }
130 break;
131
132 case ASN1_ITYPE_MSTRING:
133 if(!ASN1_primitive_new(pval, it))
134 goto memerr;
135 break;
136
137 case ASN1_ITYPE_CHOICE:
138 if(asn1_cb) {
139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
140 if(!i) goto auxerr;
141 if(i==2) {
142#ifdef CRYPTO_MDEBUG
143 if(it->sname) CRYPTO_pop_info();
144#endif
145 return 1;
146 }
147 }
148 if(!combine) {
149 *pval = OPENSSL_malloc(it->size);
150 if(!*pval) goto memerr;
151 memset(*pval, 0, it->size);
152 }
153 asn1_set_choice_selector(pval, -1, it);
154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
155 goto auxerr;
156 break;
157
158 case ASN1_ITYPE_SEQUENCE:
159 if(asn1_cb) {
160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
161 if(!i) goto auxerr;
162 if(i==2) {
163#ifdef CRYPTO_MDEBUG
164 if(it->sname) CRYPTO_pop_info();
165#endif
166 return 1;
167 }
168 }
169 if(!combine) {
170 *pval = OPENSSL_malloc(it->size);
171 if(!*pval) goto memerr;
172 memset(*pval, 0, it->size);
173 asn1_do_lock(pval, 0, it);
174 asn1_enc_init(pval, it);
175 }
176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
177 pseqval = asn1_get_field_ptr(pval, tt);
178 if(!ASN1_template_new(pseqval, tt)) goto memerr;
179 }
180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
181 goto auxerr;
182 break;
183 }
184#ifdef CRYPTO_MDEBUG
185 if(it->sname) CRYPTO_pop_info();
186#endif
187 return 1;
188
189 memerr:
190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE);
191#ifdef CRYPTO_MDEBUG
192 if(it->sname) CRYPTO_pop_info();
193#endif
194 return 0;
195
196 auxerr:
197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR);
198 ASN1_item_ex_free(pval, it);
199#ifdef CRYPTO_MDEBUG
200 if(it->sname) CRYPTO_pop_info();
201#endif
202 return 0;
203
204}
205
206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
207{
208 const ASN1_EXTERN_FUNCS *ef;
209
210 switch(it->itype) {
211
212 case ASN1_ITYPE_EXTERN:
213 ef = it->funcs;
214 if(ef && ef->asn1_ex_clear)
215 ef->asn1_ex_clear(pval, it);
216 else *pval = NULL;
217 break;
218
219
220 case ASN1_ITYPE_PRIMITIVE:
221 if(it->templates)
222 asn1_template_clear(pval, it->templates);
223 else
224 asn1_primitive_clear(pval, it);
225 break;
226
227 case ASN1_ITYPE_MSTRING:
228 asn1_primitive_clear(pval, it);
229 break;
230
231 case ASN1_ITYPE_COMPAT:
232 case ASN1_ITYPE_CHOICE:
233 case ASN1_ITYPE_SEQUENCE:
234 *pval = NULL;
235 break;
236 }
237}
238
239
240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
241{
242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
243 int ret;
244 if(tt->flags & ASN1_TFLG_OPTIONAL) {
245 asn1_template_clear(pval, tt);
246 return 1;
247 }
248 /* If ANY DEFINED BY nothing to do */
249
250 if(tt->flags & ASN1_TFLG_ADB_MASK) {
251 *pval = NULL;
252 return 1;
253 }
254#ifdef CRYPTO_MDEBUG
255 if(tt->field_name) CRYPTO_push_info(tt->field_name);
256#endif
257 /* If SET OF or SEQUENCE OF, its a STACK */
258 if(tt->flags & ASN1_TFLG_SK_MASK) {
259 STACK_OF(ASN1_VALUE) *skval;
260 skval = sk_ASN1_VALUE_new_null();
261 if(!skval) {
262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
263 ret = 0;
264 goto done;
265 }
266 *pval = (ASN1_VALUE *)skval;
267 ret = 1;
268 goto done;
269 }
270 /* Otherwise pass it back to the item routine */
271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
272 done:
273#ifdef CRYPTO_MDEBUG
274 if(it->sname) CRYPTO_pop_info();
275#endif
276 return ret;
277}
278
279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
280{
281 /* If ADB or STACK just NULL the field */
282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
283 *pval = NULL;
284 else
285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
286}
287
288
289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
290 * functions.
291 */
292
293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
294{
295 ASN1_TYPE *typ;
296 int utype;
297 const ASN1_PRIMITIVE_FUNCS *pf;
298 pf = it->funcs;
299 if(pf && pf->prim_new) return pf->prim_new(pval, it);
300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
301 else utype = it->utype;
302 switch(utype) {
303 case V_ASN1_OBJECT:
304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
305 return 1;
306
307 case V_ASN1_BOOLEAN:
308 *(ASN1_BOOLEAN *)pval = it->size;
309 return 1;
310
311 case V_ASN1_NULL:
312 *pval = (ASN1_VALUE *)1;
313 return 1;
314
315 case V_ASN1_ANY:
316 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
317 if(!typ) return 0;
318 typ->value.ptr = NULL;
319 typ->type = -1;
320 *pval = (ASN1_VALUE *)typ;
321 break;
322
323 default:
324 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
325 break;
326 }
327 if(*pval) return 1;
328 return 0;
329}
330
331void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
332{
333 int utype;
334 const ASN1_PRIMITIVE_FUNCS *pf;
335 pf = it->funcs;
336 if(pf) {
337 if(pf->prim_clear)
338 pf->prim_clear(pval, it);
339 else
340 *pval = NULL;
341 return;
342 }
343 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
344 else utype = it->utype;
345 if(utype == V_ASN1_BOOLEAN)
346 *(ASN1_BOOLEAN *)pval = it->size;
347 else *pval = NULL;
348}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_prn.c b/src/lib/libssl/src/crypto/asn1/tasn_prn.c
new file mode 100644
index 0000000000..fab67ae5ac
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_prn.c
@@ -0,0 +1,198 @@
1/* tasn_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/nasn.h>
66
67/* Print routines. Print out a whole structure from a template.
68 */
69
70static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name);
71
72int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it)
73{
74 return asn1_item_print_nm(out, fld, indent, it, it->sname);
75}
76
77static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name)
78{
79 ASN1_STRING *str;
80 const ASN1_TEMPLATE *tt;
81 void *tmpfld;
82 int i;
83 if(!fld) {
84 BIO_printf(out, "%*s%s ABSENT\n", indent, "", name);
85 return 1;
86 }
87 switch(it->itype) {
88
89 case ASN1_ITYPE_PRIMITIVE:
90 if(it->templates)
91 return ASN1_template_print(out, fld, indent, it->templates);
92 return asn1_primitive_print(out, fld, it->utype, indent, name);
93 break;
94
95 case ASN1_ITYPE_MSTRING:
96 str = fld;
97 return asn1_primitive_print(out, fld, str->type, indent, name);
98
99 case ASN1_ITYPE_EXTERN:
100 BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
101 return 1;
102 case ASN1_ITYPE_COMPAT:
103 BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
104 return 1;
105
106
107 case ASN1_ITYPE_CHOICE:
108 /* CHOICE type, get selector */
109 i = asn1_get_choice_selector(fld, it);
110 /* This should never happen... */
111 if((i < 0) || (i >= it->tcount)) {
112 BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i);
113 return 1;
114 }
115 tt = it->templates + i;
116 tmpfld = asn1_get_field(fld, tt);
117 return ASN1_template_print(out, tmpfld, indent, tt);
118
119 case ASN1_ITYPE_SEQUENCE:
120 BIO_printf(out, "%*s%s {\n", indent, "", name);
121 /* Get each field entry */
122 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
123 tmpfld = asn1_get_field(fld, tt);
124 ASN1_template_print(out, tmpfld, indent + 2, tt);
125 }
126 BIO_printf(out, "%*s}\n", indent, "");
127 return 1;
128
129 default:
130 return 0;
131 }
132}
133
134int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt)
135{
136 int i, flags;
137#if 0
138 if(!fld) return 0;
139#endif
140 flags = tt->flags;
141 if(flags & ASN1_TFLG_SK_MASK) {
142 char *tname;
143 void *skitem;
144 /* SET OF, SEQUENCE OF */
145 if(flags & ASN1_TFLG_SET_OF) tname = "SET";
146 else tname = "SEQUENCE";
147 if(fld) {
148 BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name);
149 for(i = 0; i < sk_num(fld); i++) {
150 skitem = sk_value(fld, i);
151 asn1_item_print_nm(out, skitem, indent + 2, tt->item, "");
152 }
153 BIO_printf(out, "%*s}\n", indent, "");
154 } else
155 BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name);
156 return 1;
157 }
158 return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name);
159}
160
161static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name)
162{
163 ASN1_STRING *str = fld;
164 if(fld) {
165 if(utype == V_ASN1_BOOLEAN) {
166 int *bool = fld;
167if(*bool == -1) printf("BOOL MISSING\n");
168 BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE");
169 } else if((utype == V_ASN1_INTEGER)
170 || (utype == V_ASN1_ENUMERATED)) {
171 char *s, *nm;
172 s = i2s_ASN1_INTEGER(NULL, fld);
173 if(utype == V_ASN1_INTEGER) nm = "INTEGER";
174 else nm = "ENUMERATED";
175 BIO_printf(out, "%*s%s:%s", indent, "", nm, s);
176 OPENSSL_free(s);
177 } else if(utype == V_ASN1_NULL) {
178 BIO_printf(out, "%*s%s", indent, "", "NULL");
179 } else if(utype == V_ASN1_UTCTIME) {
180 BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME");
181 ASN1_UTCTIME_print(out, str);
182 } else if(utype == V_ASN1_GENERALIZEDTIME) {
183 BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME");
184 ASN1_GENERALIZEDTIME_print(out, str);
185 } else if(utype == V_ASN1_OBJECT) {
186 char objbuf[80], *ln;
187 ln = OBJ_nid2ln(OBJ_obj2nid(fld));
188 if(!ln) ln = "";
189 OBJ_obj2txt(objbuf, 80, fld, 1);
190 BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf);
191 } else {
192 BIO_printf(out, "%*s%s:", indent, "", name);
193 ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
194 }
195 BIO_printf(out, "\n");
196 } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name);
197 return 1;
198}
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_typ.c b/src/lib/libssl/src/crypto/asn1/tasn_typ.c
new file mode 100644
index 0000000000..804d2eeba2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_typ.c
@@ -0,0 +1,133 @@
1/* tasn_typ.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <stdio.h>
59#include <openssl/asn1.h>
60#include <openssl/asn1t.h>
61
62/* Declarations for string types */
63
64
65IMPLEMENT_ASN1_TYPE(ASN1_INTEGER)
66IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER)
67
68IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED)
69IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED)
70
71IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING)
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING)
73
74IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING)
75IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
76
77IMPLEMENT_ASN1_TYPE(ASN1_NULL)
78IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
79
80IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
81
82IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING)
83IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING)
84
85IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING)
86IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
87
88IMPLEMENT_ASN1_TYPE(ASN1_T61STRING)
89IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING)
90
91IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING)
92IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING)
93
94IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING)
95IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
96
97IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME)
98IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME)
99
100IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME)
101IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
102
103IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING)
104IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
105
106IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING)
107IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
108
109IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING)
110IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING)
111
112IMPLEMENT_ASN1_TYPE(ASN1_ANY)
113
114/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
115IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
116
117IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
118
119/* Multistring types */
120
121IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
122IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
123
124IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
125IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
126
127IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
128IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
129
130/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_utl.c b/src/lib/libssl/src/crypto/asn1/tasn_utl.c
new file mode 100644
index 0000000000..8996ce8c13
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/tasn_utl.c
@@ -0,0 +1,253 @@
1/* tasn_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/err.h>
66
67/* Utility functions for manipulating fields and offsets */
68
69/* Add 'offset' to 'addr' */
70#define offset2ptr(addr, offset) (void *)(((char *) addr) + offset)
71
72/* Given an ASN1_ITEM CHOICE type return
73 * the selector value
74 */
75
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77{
78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel;
80}
81
82/* Given an ASN1_ITEM CHOICE type set
83 * the selector value, return old value.
84 */
85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
87{
88 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype);
90 ret = *sel;
91 *sel = value;
92 return ret;
93}
94
95/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is
97 * set to 1. If op is -1 count is decremented and the return value
98 * is the current refrence count or 0 if no reference count exists.
99 */
100
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102{
103 const ASN1_AUX *aux;
104 int *lck, ret;
105 if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
106 aux = it->funcs;
107 if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
108 lck = offset2ptr(*pval, aux->ref_offset);
109 if(op == 0) {
110 *lck = 1;
111 return 1;
112 }
113 ret = CRYPTO_add(lck, op, aux->ref_lock);
114#ifdef REF_PRINT
115 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
116#endif
117#ifdef REF_CHECK
118 if(ret < 0)
119 fprintf(stderr, "%s, bad reference count\n", it->sname);
120#endif
121 return ret;
122}
123
124static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
125{
126 const ASN1_AUX *aux;
127 if(!pval || !*pval) return NULL;
128 aux = it->funcs;
129 if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
130 return offset2ptr(*pval, aux->enc_offset);
131}
132
133void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
134{
135 ASN1_ENCODING *enc;
136 enc = asn1_get_enc_ptr(pval, it);
137 if(enc) {
138 enc->enc = NULL;
139 enc->len = 0;
140 enc->modified = 1;
141 }
142}
143
144void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
145{
146 ASN1_ENCODING *enc;
147 enc = asn1_get_enc_ptr(pval, it);
148 if(enc) {
149 if(enc->enc) OPENSSL_free(enc->enc);
150 enc->enc = NULL;
151 enc->len = 0;
152 enc->modified = 1;
153 }
154}
155
156int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it)
157{
158 ASN1_ENCODING *enc;
159 enc = asn1_get_enc_ptr(pval, it);
160 if(!enc) return 1;
161
162 if(enc->enc) OPENSSL_free(enc->enc);
163 enc->enc = OPENSSL_malloc(inlen);
164 if(!enc->enc) return 0;
165 memcpy(enc->enc, in, inlen);
166 enc->len = inlen;
167 enc->modified = 0;
168
169 return 1;
170}
171
172int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
173{
174 ASN1_ENCODING *enc;
175 enc = asn1_get_enc_ptr(pval, it);
176 if(!enc || enc->modified) return 0;
177 if(out) {
178 memcpy(*out, enc->enc, enc->len);
179 *out += enc->len;
180 }
181 if(len) *len = enc->len;
182 return 1;
183}
184
185/* Given an ASN1_TEMPLATE get a pointer to a field */
186ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
187{
188 ASN1_VALUE **pvaltmp;
189 if(tt->flags & ASN1_TFLG_COMBINE) return pval;
190 pvaltmp = offset2ptr(*pval, tt->offset);
191 /* NOTE for BOOLEAN types the field is just a plain
192 * int so we can't return int **, so settle for
193 * (int *).
194 */
195 return pvaltmp;
196}
197
198/* Handle ANY DEFINED BY template, find the selector, look up
199 * the relevant ASN1_TEMPLATE in the table and return it.
200 */
201
202const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
203{
204 const ASN1_ADB *adb;
205 const ASN1_ADB_TABLE *atbl;
206 long selector;
207 ASN1_VALUE **sfld;
208 int i;
209 if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
210
211 /* Else ANY DEFINED BY ... get the table */
212 adb = ASN1_ADB_ptr(tt->item);
213
214 /* Get the selector field */
215 sfld = offset2ptr(*pval, adb->offset);
216
217 /* Check if NULL */
218 if(!sfld) {
219 if(!adb->null_tt) goto err;
220 return adb->null_tt;
221 }
222
223 /* Convert type to a long:
224 * NB: don't check for NID_undef here because it
225 * might be a legitimate value in the table
226 */
227 if(tt->flags & ASN1_TFLG_ADB_OID)
228 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
229 else
230 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
231
232 /* Try to find matching entry in table
233 * Maybe should check application types first to
234 * allow application override? Might also be useful
235 * to have a flag which indicates table is sorted and
236 * we can do a binary search. For now stick to a
237 * linear search.
238 */
239
240 for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
241 if(atbl->value == selector) return &atbl->tt;
242
243 /* FIXME: need to search application table too */
244
245 /* No match, return default type */
246 if(!adb->default_tt) goto err;
247 return adb->default_tt;
248
249 err:
250 /* FIXME: should log the value or OID of unsupported type */
251 if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
252 return NULL;
253}
diff --git a/src/lib/libssl/src/crypto/asn1/x_bignum.c b/src/lib/libssl/src/crypto/asn1/x_bignum.c
new file mode 100644
index 0000000000..848c7a0877
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_bignum.c
@@ -0,0 +1,137 @@
1/* x_bignum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
64 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all
65 * BIGNUMs used are non negative and anything that looks negative is normally due
66 * to an encoding error.
67 */
68
69#define BN_SENSITIVE 1
70
71static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
72static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
73
74static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
75static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
76
77static ASN1_PRIMITIVE_FUNCS bignum_pf = {
78 NULL, 0,
79 bn_new,
80 bn_free,
81 0,
82 bn_c2i,
83 bn_i2c
84};
85
86ASN1_ITEM_start(BIGNUM)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
88ASN1_ITEM_end(BIGNUM)
89
90ASN1_ITEM_start(CBIGNUM)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
92ASN1_ITEM_end(CBIGNUM)
93
94static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{
96 *pval = (ASN1_VALUE *)BN_new();
97 if(*pval) return 1;
98 else return 0;
99}
100
101static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
102{
103 if(!*pval) return;
104 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval);
105 else BN_free((BIGNUM *)*pval);
106 *pval = NULL;
107}
108
109static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
110{
111 BIGNUM *bn;
112 int pad;
113 if(!*pval) return -1;
114 bn = (BIGNUM *)*pval;
115 /* If MSB set in an octet we need a padding byte */
116 if(BN_num_bits(bn) & 0x7) pad = 0;
117 else pad = 1;
118 if(cont) {
119 if(pad) *cont++ = 0;
120 BN_bn2bin(bn, cont);
121 }
122 return pad + BN_num_bytes(bn);
123}
124
125static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
126{
127 BIGNUM *bn;
128 if(!*pval) bn_new(pval, it);
129 bn = (BIGNUM *)*pval;
130 if(!BN_bin2bn(cont, len, bn)) {
131 bn_free(pval, it);
132 return 0;
133 }
134 return 1;
135}
136
137
diff --git a/src/lib/libssl/src/crypto/asn1/x_long.c b/src/lib/libssl/src/crypto/asn1/x_long.c
new file mode 100644
index 0000000000..c5f25956cb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_long.c
@@ -0,0 +1,169 @@
1/* x_long.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
64 * and a long directly.
65 */
66
67
68static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
70
71static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
72static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
73
74static ASN1_PRIMITIVE_FUNCS long_pf = {
75 NULL, 0,
76 long_new,
77 long_free,
78 long_free, /* Clear should set to initial value */
79 long_c2i,
80 long_i2c
81};
82
83ASN1_ITEM_start(LONG)
84 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
85ASN1_ITEM_end(LONG)
86
87ASN1_ITEM_start(ZLONG)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
89ASN1_ITEM_end(ZLONG)
90
91static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
92{
93 *(long *)pval = it->size;
94 return 1;
95}
96
97static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
98{
99 *(long *)pval = it->size;
100}
101
102static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
103{
104 long ltmp;
105 unsigned long utmp;
106 int clen, pad, i;
107 /* this exists to bypass broken gcc optimization */
108 char *cp = (char *)pval;
109
110 /* use memcpy, because we may not be long aligned */
111 memcpy(&ltmp, cp, sizeof(long));
112
113 if(ltmp == it->size) return -1;
114 /* Convert the long to positive: we subtract one if negative so
115 * we can cleanly handle the padding if only the MSB of the leading
116 * octet is set.
117 */
118 if(ltmp < 0) utmp = -ltmp - 1;
119 else utmp = ltmp;
120 clen = BN_num_bits_word(utmp);
121 /* If MSB of leading octet set we need to pad */
122 if(!(clen & 0x7)) pad = 1;
123 else pad = 0;
124
125 /* Convert number of bits to number of octets */
126 clen = (clen + 7) >> 3;
127
128 if(cont) {
129 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0;
130 for(i = clen - 1; i >= 0; i--) {
131 cont[i] = (unsigned char)(utmp & 0xff);
132 if(ltmp < 0) cont[i] ^= 0xff;
133 utmp >>= 8;
134 }
135 }
136 return clen + pad;
137}
138
139static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
140{
141 int neg, i;
142 long ltmp;
143 unsigned long utmp = 0;
144 char *cp = (char *)pval;
145 if(len > sizeof(long)) {
146 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
147 return 0;
148 }
149 /* Is it negative? */
150 if(len && (cont[0] & 0x80)) neg = 1;
151 else neg = 0;
152 utmp = 0;
153 for(i = 0; i < len; i++) {
154 utmp <<= 8;
155 if(neg) utmp |= cont[i] ^ 0xff;
156 else utmp |= cont[i];
157 }
158 ltmp = (long)utmp;
159 if(neg) {
160 ltmp++;
161 ltmp = -ltmp;
162 }
163 if(ltmp == it->size) {
164 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
165 return 0;
166 }
167 memcpy(cp, &ltmp, sizeof(long));
168 return 1;
169}
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509a.c b/src/lib/libssl/src/crypto/asn1/x_x509a.c
new file mode 100644
index 0000000000..b9987ea968
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_x509a.c
@@ -0,0 +1,200 @@
1/* a_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data.
70 */
71
72static X509_CERT_AUX *aux_get(X509 *x);
73
74X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, unsigned char **pp, long length)
75{
76 M_ASN1_D2I_vars(a, X509_CERT_AUX *, X509_CERT_AUX_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80
81 M_ASN1_D2I_get_seq_opt_type(ASN1_OBJECT, ret->trust,
82 d2i_ASN1_OBJECT, ASN1_OBJECT_free);
83 M_ASN1_D2I_get_IMP_set_opt_type(ASN1_OBJECT, ret->reject,
84 d2i_ASN1_OBJECT, ASN1_OBJECT_free, 0);
85 M_ASN1_D2I_get_opt(ret->alias, d2i_ASN1_UTF8STRING, V_ASN1_UTF8STRING);
86 M_ASN1_D2I_get_opt(ret->keyid, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
87 M_ASN1_D2I_get_IMP_set_opt_type(X509_ALGOR, ret->other,
88 d2i_X509_ALGOR, X509_ALGOR_free, 1);
89
90 M_ASN1_D2I_Finish(a, X509_CERT_AUX_free, ASN1_F_D2I_X509_CERT_AUX);
91}
92
93X509_CERT_AUX *X509_CERT_AUX_new()
94{
95 X509_CERT_AUX *ret = NULL;
96 ASN1_CTX c;
97 M_ASN1_New_Malloc(ret, X509_CERT_AUX);
98 ret->trust = NULL;
99 ret->reject = NULL;
100 ret->alias = NULL;
101 ret->keyid = NULL;
102 ret->other = NULL;
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_CERT_AUX_NEW);
105}
106
107void X509_CERT_AUX_free(X509_CERT_AUX *a)
108{
109 if(a == NULL) return;
110 sk_ASN1_OBJECT_pop_free(a->trust, ASN1_OBJECT_free);
111 sk_ASN1_OBJECT_pop_free(a->reject, ASN1_OBJECT_free);
112 ASN1_UTF8STRING_free(a->alias);
113 ASN1_OCTET_STRING_free(a->keyid);
114 sk_X509_ALGOR_pop_free(a->other, X509_ALGOR_free);
115 Free(a);
116}
117
118int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **pp)
119{
120 M_ASN1_I2D_vars(a);
121
122 M_ASN1_I2D_len_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
123 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
124
125 M_ASN1_I2D_len(a->alias, i2d_ASN1_UTF8STRING);
126 M_ASN1_I2D_len(a->keyid, i2d_ASN1_OCTET_STRING);
127 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
128
129 M_ASN1_I2D_seq_total();
130
131 M_ASN1_I2D_put_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
132 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
133
134 M_ASN1_I2D_put(a->alias, i2d_ASN1_UTF8STRING);
135 M_ASN1_I2D_put(a->keyid, i2d_ASN1_OCTET_STRING);
136 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
137
138 M_ASN1_I2D_finish();
139}
140
141static X509_CERT_AUX *aux_get(X509 *x)
142{
143 if(!x) return NULL;
144 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
145 return x->aux;
146}
147
148int X509_alias_set1(X509 *x, unsigned char *name, int len)
149{
150 X509_CERT_AUX *aux;
151 if(!(aux = aux_get(x))) return 0;
152 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
153 return ASN1_STRING_set(aux->alias, name, len);
154}
155
156unsigned char *X509_alias_get0(X509 *x, int *len)
157{
158 if(!x->aux || !x->aux->alias) return NULL;
159 if(len) *len = x->aux->alias->length;
160 return x->aux->alias->data;
161}
162
163int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
164{
165 X509_CERT_AUX *aux;
166 ASN1_OBJECT *objtmp;
167 if(!(objtmp = OBJ_dup(obj))) return 0;
168 if(!(aux = aux_get(x))) return 0;
169 if(!aux->trust
170 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
171 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
172}
173
174int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
175{
176 X509_CERT_AUX *aux;
177 ASN1_OBJECT *objtmp;
178 if(!(objtmp = OBJ_dup(obj))) return 0;
179 if(!(aux = aux_get(x))) return 0;
180 if(!aux->reject
181 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
182 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
183}
184
185void X509_trust_clear(X509 *x)
186{
187 if(x->aux && x->aux->trust) {
188 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
189 x->aux->trust = NULL;
190 }
191}
192
193void X509_reject_clear(X509 *x)
194{
195 if(x->aux && x->aux->reject) {
196 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
197 x->aux->reject = NULL;
198 }
199}
200
diff --git a/src/lib/libssl/src/crypto/bf/bf_locl.h b/src/lib/libssl/src/crypto/bf/bf_locl.h
new file mode 100644
index 0000000000..05756b5d3b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_locl.h
@@ -0,0 +1,219 @@
1/* crypto/bf/bf_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BF_LOCL_H
60#define HEADER_BF_LOCL_H
61#include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
62
63#undef c2l
64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
65 l|=((unsigned long)(*((c)++)))<< 8L, \
66 l|=((unsigned long)(*((c)++)))<<16L, \
67 l|=((unsigned long)(*((c)++)))<<24L)
68
69/* NOTE - c is not incremented as per c2l */
70#undef c2ln
71#define c2ln(c,l1,l2,n) { \
72 c+=n; \
73 l1=l2=0; \
74 switch (n) { \
75 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
76 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
77 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
78 case 5: l2|=((unsigned long)(*(--(c)))); \
79 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
80 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
81 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
82 case 1: l1|=((unsigned long)(*(--(c)))); \
83 } \
84 }
85
86#undef l2c
87#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
88 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
89 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
90 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
91
92/* NOTE - c is not incremented as per l2c */
93#undef l2cn
94#define l2cn(l1,l2,c,n) { \
95 c+=n; \
96 switch (n) { \
97 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
98 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
99 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
100 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
101 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
102 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
103 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
104 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
105 } \
106 }
107
108/* NOTE - c is not incremented as per n2l */
109#define n2ln(c,l1,l2,n) { \
110 c+=n; \
111 l1=l2=0; \
112 switch (n) { \
113 case 8: l2 =((unsigned long)(*(--(c)))) ; \
114 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
115 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
116 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
117 case 4: l1 =((unsigned long)(*(--(c)))) ; \
118 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
119 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
120 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
121 } \
122 }
123
124/* NOTE - c is not incremented as per l2n */
125#define l2nn(l1,l2,c,n) { \
126 c+=n; \
127 switch (n) { \
128 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
129 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
130 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
131 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
132 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
133 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
134 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
135 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
136 } \
137 }
138
139#undef n2l
140#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
141 l|=((unsigned long)(*((c)++)))<<16L, \
142 l|=((unsigned long)(*((c)++)))<< 8L, \
143 l|=((unsigned long)(*((c)++))))
144
145#undef l2n
146#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
147 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff))
150
151/* This is actually a big endian algorithm, the most significate byte
152 * is used to lookup array 0 */
153
154#if defined(BF_PTR2)
155
156/*
157 * This is basically a special Intel version. Point is that Intel
158 * doesn't have many registers, but offers a reach choice of addressing
159 * modes. So we spare some registers by directly traversing BF_KEY
160 * structure and hiring the most decorated addressing mode. The code
161 * generated by EGCS is *perfectly* competitive with assembler
162 * implementation!
163 */
164#define BF_ENC(LL,R,KEY,Pi) (\
165 LL^=KEY[Pi], \
166 t= KEY[BF_ROUNDS+2 + 0 + ((R>>24)&0xFF)], \
167 t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \
168 t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \
169 t+= KEY[BF_ROUNDS+2 + 768 + ((R )&0xFF)], \
170 LL^=t \
171 )
172
173#elif defined(BF_PTR)
174
175#ifndef BF_LONG_LOG2
176#define BF_LONG_LOG2 2 /* default to BF_LONG being 32 bits */
177#endif
178#define BF_M (0xFF<<BF_LONG_LOG2)
179#define BF_0 (24-BF_LONG_LOG2)
180#define BF_1 (16-BF_LONG_LOG2)
181#define BF_2 ( 8-BF_LONG_LOG2)
182#define BF_3 BF_LONG_LOG2 /* left shift */
183
184/*
185 * This is normally very good on RISC platforms where normally you
186 * have to explicitely "multiplicate" array index by sizeof(BF_LONG)
187 * in order to caclulate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most
189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
190 * rlwinm. So let'em double-check if their compiler does it.
191 */
192
193#define BF_ENC(LL,R,S,P) ( \
194 LL^=P, \
195 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \
196 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
197 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
198 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))) \
199 )
200#else
201
202/*
203 * This is a *generic* version. Seem to perform best on platforms that
204 * offer explicit support for extraction of 8-bit nibbles preferably
205 * complemented with "multiplying" of array index by sizeof(BF_LONG).
206 * For the moment of this writing the list comprises Alpha CPU featuring
207 * extbl and s[48]addq instructions.
208 */
209
210#define BF_ENC(LL,R,S,P) ( \
211 LL^=P, \
212 LL^=((( S[ ((int)(R>>24)&0xff)] + \
213 S[0x0100+((int)(R>>16)&0xff)])^ \
214 S[0x0200+((int)(R>> 8)&0xff)])+ \
215 S[0x0300+((int)(R )&0xff)])&0xffffffffL \
216 )
217#endif
218
219#endif
diff --git a/src/lib/libssl/src/crypto/bio/bf_lbuf.c b/src/lib/libssl/src/crypto/bio/bf_lbuf.c
new file mode 100644
index 0000000000..7bcf8ed941
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bf_lbuf.c
@@ -0,0 +1,397 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64
65static int linebuffer_write(BIO *h, const char *buf,int num);
66static int linebuffer_read(BIO *h, char *buf, int size);
67static int linebuffer_puts(BIO *h, const char *str);
68static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73
74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10
76
77/* #define DEBUG */
78
79static BIO_METHOD methods_linebuffer=
80 {
81 BIO_TYPE_LINEBUFFER,
82 "linebuffer",
83 linebuffer_write,
84 linebuffer_read,
85 linebuffer_puts,
86 linebuffer_gets,
87 linebuffer_ctrl,
88 linebuffer_new,
89 linebuffer_free,
90 linebuffer_callback_ctrl,
91 };
92
93BIO_METHOD *BIO_f_linebuffer(void)
94 {
95 return(&methods_linebuffer);
96 }
97
98typedef struct bio_linebuffer_ctx_struct
99 {
100 char *obuf; /* the output char array */
101 int obuf_size; /* how big is the output buffer */
102 int obuf_len; /* how many bytes are in it */
103 } BIO_LINEBUFFER_CTX;
104
105static int linebuffer_new(BIO *bi)
106 {
107 BIO_LINEBUFFER_CTX *ctx;
108
109 ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) return(0);
111 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
112 if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
113 ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
114 ctx->obuf_len=0;
115
116 bi->init=1;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int linebuffer_free(BIO *a)
123 {
124 BIO_LINEBUFFER_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_LINEBUFFER_CTX *)a->ptr;
128 if (b->obuf != NULL) OPENSSL_free(b->obuf);
129 OPENSSL_free(a->ptr);
130 a->ptr=NULL;
131 a->init=0;
132 a->flags=0;
133 return(1);
134 }
135
136static int linebuffer_read(BIO *b, char *out, int outl)
137 {
138 int ret=0;
139
140 if (out == NULL) return(0);
141 if (b->next_bio == NULL) return(0);
142 ret=BIO_read(b->next_bio,out,outl);
143 BIO_clear_retry_flags(b);
144 BIO_copy_next_retry(b);
145 return(ret);
146 }
147
148static int linebuffer_write(BIO *b, const char *in, int inl)
149 {
150 int i,num=0,foundnl;
151 BIO_LINEBUFFER_CTX *ctx;
152
153 if ((in == NULL) || (inl <= 0)) return(0);
154 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
155 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
156
157 BIO_clear_retry_flags(b);
158
159 do
160 {
161 const char *p;
162
163 for(p = in; p < in + inl && *p != '\n'; p++)
164 ;
165 if (*p == '\n')
166 {
167 p++;
168 foundnl = 1;
169 }
170 else
171 foundnl = 0;
172
173 /* If a NL was found and we already have text in the save
174 buffer, concatenate them and write */
175 while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
176 && ctx->obuf_len > 0)
177 {
178 int orig_olen = ctx->obuf_len;
179
180 i = ctx->obuf_size - ctx->obuf_len;
181 if (p - in > 0)
182 {
183 if (i >= p - in)
184 {
185 memcpy(&(ctx->obuf[ctx->obuf_len]),
186 in,p - in);
187 ctx->obuf_len += p - in;
188 inl -= p - in;
189 num += p - in;
190 in = p;
191 }
192 else
193 {
194 memcpy(&(ctx->obuf[ctx->obuf_len]),
195 in,i);
196 ctx->obuf_len += i;
197 inl -= i;
198 in += i;
199 num += i;
200 }
201 }
202
203#ifdef DEBUG
204BIO_write(b->next_bio, "<*<", 3);
205#endif
206 i=BIO_write(b->next_bio,
207 ctx->obuf, ctx->obuf_len);
208 if (i <= 0)
209 {
210 ctx->obuf_len = orig_olen;
211 BIO_copy_next_retry(b);
212
213#ifdef DEBUG
214BIO_write(b->next_bio, ">*>", 3);
215#endif
216 if (i < 0) return((num > 0)?num:i);
217 if (i == 0) return(num);
218 }
219#ifdef DEBUG
220BIO_write(b->next_bio, ">*>", 3);
221#endif
222 if (i < ctx->obuf_len)
223 memmove(ctx->obuf, ctx->obuf + i,
224 ctx->obuf_len - i);
225 ctx->obuf_len-=i;
226 }
227
228 /* Now that the save buffer is emptied, let's write the input
229 buffer if a NL was found and there is anything to write. */
230 if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
231 {
232#ifdef DEBUG
233BIO_write(b->next_bio, "<*<", 3);
234#endif
235 i=BIO_write(b->next_bio,in,p - in);
236 if (i <= 0)
237 {
238 BIO_copy_next_retry(b);
239#ifdef DEBUG
240BIO_write(b->next_bio, ">*>", 3);
241#endif
242 if (i < 0) return((num > 0)?num:i);
243 if (i == 0) return(num);
244 }
245#ifdef DEBUG
246BIO_write(b->next_bio, ">*>", 3);
247#endif
248 num+=i;
249 in+=i;
250 inl-=i;
251 }
252 }
253 while(foundnl && inl > 0);
254 /* We've written as much as we can. The rest of the input buffer, if
255 any, is text that doesn't and with a NL and therefore needs to be
256 saved for the next trip. */
257 if (inl > 0)
258 {
259 memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
260 ctx->obuf_len += inl;
261 num += inl;
262 }
263 return num;
264 }
265
266static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
267 {
268 BIO *dbio;
269 BIO_LINEBUFFER_CTX *ctx;
270 long ret=1;
271 char *p;
272 int r;
273 int obs;
274
275 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
276
277 switch (cmd)
278 {
279 case BIO_CTRL_RESET:
280 ctx->obuf_len=0;
281 if (b->next_bio == NULL) return(0);
282 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
283 break;
284 case BIO_CTRL_INFO:
285 ret=(long)ctx->obuf_len;
286 break;
287 case BIO_CTRL_WPENDING:
288 ret=(long)ctx->obuf_len;
289 if (ret == 0)
290 {
291 if (b->next_bio == NULL) return(0);
292 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
293 }
294 break;
295 case BIO_C_SET_BUFF_SIZE:
296 obs=(int)num;
297 p=ctx->obuf;
298 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
299 {
300 p=(char *)OPENSSL_malloc((int)num);
301 if (p == NULL)
302 goto malloc_error;
303 }
304 if (ctx->obuf != p)
305 {
306 if (ctx->obuf_len > obs)
307 {
308 ctx->obuf_len = obs;
309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf);
312 ctx->obuf=p;
313 ctx->obuf_size=obs;
314 }
315 break;
316 case BIO_C_DO_STATE_MACHINE:
317 if (b->next_bio == NULL) return(0);
318 BIO_clear_retry_flags(b);
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 BIO_copy_next_retry(b);
321 break;
322
323 case BIO_CTRL_FLUSH:
324 if (b->next_bio == NULL) return(0);
325 if (ctx->obuf_len <= 0)
326 {
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 }
330
331 for (;;)
332 {
333 BIO_clear_retry_flags(b);
334 if (ctx->obuf_len > 0)
335 {
336 r=BIO_write(b->next_bio,
337 ctx->obuf, ctx->obuf_len);
338#if 0
339fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
340#endif
341 BIO_copy_next_retry(b);
342 if (r <= 0) return((long)r);
343 if (r < ctx->obuf_len)
344 memmove(ctx->obuf, ctx->obuf + r,
345 ctx->obuf_len - r);
346 ctx->obuf_len-=r;
347 }
348 else
349 {
350 ctx->obuf_len=0;
351 ret=1;
352 break;
353 }
354 }
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_DUP:
358 dbio=(BIO *)ptr;
359 if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
360 ret=0;
361 break;
362 default:
363 if (b->next_bio == NULL) return(0);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 break;
366 }
367 return(ret);
368malloc_error:
369 BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
370 return(0);
371 }
372
373static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387static int linebuffer_gets(BIO *b, char *buf, int size)
388 {
389 if (b->next_bio == NULL) return(0);
390 return(BIO_gets(b->next_bio,buf,size));
391 }
392
393static int linebuffer_puts(BIO *b, const char *str)
394 {
395 return(linebuffer_write(b,str,strlen(str)));
396 }
397
diff --git a/src/lib/libssl/src/crypto/bio/bss_bio.c b/src/lib/libssl/src/crypto/bio/bss_bio.c
new file mode 100644
index 0000000000..562e9d8de2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_bio.c
@@ -0,0 +1,588 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2
3/* Special method for a BIO where the other endpoint is also a BIO
4 * of this kind, handled by the same thread (i.e. the "peer" is actually
5 * ourselves, wearing a different hat).
6 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
7 * for which no specific BIO method is available.
8 * See ssl/ssltest.c for some hints on how this can be used. */
9
10#ifndef BIO_PAIR_DEBUG
11# undef NDEBUG /* avoid conflicting definitions */
12# define NDEBUG
13#endif
14
15#include <assert.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <openssl/bio.h>
20#include <openssl/err.h>
21#include <openssl/crypto.h>
22
23static int bio_new(BIO *bio);
24static int bio_free(BIO *bio);
25static int bio_read(BIO *bio, char *buf, int size);
26static int bio_write(BIO *bio, char *buf, int num);
27static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
28static int bio_puts(BIO *bio, char *str);
29
30static int bio_make_pair(BIO *bio1, BIO *bio2);
31static void bio_destroy_pair(BIO *bio);
32
33static BIO_METHOD methods_biop =
34{
35 BIO_TYPE_BIO,
36 "BIO pair",
37 bio_write,
38 bio_read,
39 bio_puts,
40 NULL /* no bio_gets */,
41 bio_ctrl,
42 bio_new,
43 bio_free
44};
45
46BIO_METHOD *BIO_s_bio(void)
47 {
48 return &methods_biop;
49 }
50
51struct bio_bio_st
52{
53 BIO *peer; /* NULL if buf == NULL.
54 * If peer != NULL, then peer->ptr is also a bio_bio_st,
55 * and its "peer" member points back to us.
56 * peer != NULL iff init != 0 in the BIO. */
57
58 /* This is for what we write (i.e. reading uses peer's struct): */
59 int closed; /* valid iff peer != NULL */
60 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
61 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
62 size_t size;
63 char *buf; /* "size" elements (if != NULL) */
64
65 size_t request; /* valid iff peer != NULL; 0 if len != 0,
66 * otherwise set by peer to number of bytes
67 * it (unsuccesfully) tried to read,
68 * never more than buffer space (size-len) warrants. */
69};
70
71static int bio_new(BIO *bio)
72 {
73 struct bio_bio_st *b;
74
75 b = Malloc(sizeof *b);
76 if (b == NULL)
77 return 0;
78
79 b->peer = NULL;
80 b->size = 17*1024; /* enough for one TLS record (just a default) */
81 b->buf = NULL;
82
83 bio->ptr = b;
84 return 1;
85 }
86
87
88static int bio_free(BIO *bio)
89 {
90 struct bio_bio_st *b;
91
92 if (bio == NULL)
93 return 0;
94 b = bio->ptr;
95
96 assert(b != NULL);
97
98 if (b->peer)
99 bio_destroy_pair(bio);
100
101 if (b->buf != NULL)
102 {
103 Free(b->buf);
104 }
105
106 Free(b);
107
108 return 1;
109 }
110
111
112
113static int bio_read(BIO *bio, char *buf, int size_)
114 {
115 size_t size = size_;
116 size_t rest;
117 struct bio_bio_st *b, *peer_b;
118
119 BIO_clear_retry_flags(bio);
120
121 if (!bio->init)
122 return 0;
123
124 b = bio->ptr;
125 assert(b != NULL);
126 assert(b->peer != NULL);
127 peer_b = b->peer->ptr;
128 assert(peer_b != NULL);
129 assert(peer_b->buf != NULL);
130
131 peer_b->request = 0; /* will be set in "retry_read" situation */
132
133 if (buf == NULL || size == 0)
134 return 0;
135
136 if (peer_b->len == 0)
137 {
138 if (peer_b->closed)
139 return 0; /* writer has closed, and no data is left */
140 else
141 {
142 BIO_set_retry_read(bio); /* buffer is empty */
143 if (size <= peer_b->size)
144 peer_b->request = size;
145 else
146 /* don't ask for more than the peer can
147 * deliver in one write */
148 peer_b->request = peer_b->size;
149 return -1;
150 }
151 }
152
153 /* we can read */
154 if (peer_b->len < size)
155 size = peer_b->len;
156
157 /* now read "size" bytes */
158
159 rest = size;
160
161 assert(rest > 0);
162 do /* one or two iterations */
163 {
164 size_t chunk;
165
166 assert(rest <= peer_b->len);
167 if (peer_b->offset + rest <= peer_b->size)
168 chunk = rest;
169 else
170 /* wrap around ring buffer */
171 chunk = peer_b->size - peer_b->offset;
172 assert(peer_b->offset + chunk <= peer_b->size);
173
174 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
175
176 peer_b->len -= chunk;
177 if (peer_b->len)
178 {
179 peer_b->offset += chunk;
180 assert(peer_b->offset <= peer_b->size);
181 if (peer_b->offset == peer_b->size)
182 peer_b->offset = 0;
183 buf += chunk;
184 }
185 else
186 {
187 /* buffer now empty, no need to advance "buf" */
188 assert(chunk == rest);
189 peer_b->offset = 0;
190 }
191 rest -= chunk;
192 }
193 while (rest);
194
195 return size;
196 }
197
198static int bio_write(BIO *bio, char *buf, int num_)
199 {
200 size_t num = num_;
201 size_t rest;
202 struct bio_bio_st *b;
203
204 BIO_clear_retry_flags(bio);
205
206 if (!bio->init || buf == NULL || num == 0)
207 return 0;
208
209 b = bio->ptr;
210 assert(b != NULL);
211 assert(b->peer != NULL);
212 assert(b->buf != NULL);
213
214 b->request = 0;
215 if (b->closed)
216 {
217 /* we already closed */
218 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
219 return -1;
220 }
221
222 assert(b->len <= b->size);
223
224 if (b->len == b->size)
225 {
226 BIO_set_retry_write(bio); /* buffer is full */
227 return -1;
228 }
229
230 /* we can write */
231 if (num > b->size - b->len)
232 num = b->size - b->len;
233
234 /* now write "num" bytes */
235
236 rest = num;
237
238 assert(rest > 0);
239 do /* one or two iterations */
240 {
241 size_t write_offset;
242 size_t chunk;
243
244 assert(b->len + rest <= b->size);
245
246 write_offset = b->offset + b->len;
247 if (write_offset >= b->size)
248 write_offset -= b->size;
249 /* b->buf[write_offset] is the first byte we can write to. */
250
251 if (write_offset + rest <= b->size)
252 chunk = rest;
253 else
254 /* wrap around ring buffer */
255 chunk = b->size - write_offset;
256
257 memcpy(b->buf + write_offset, buf, chunk);
258
259 b->len += chunk;
260
261 assert(b->len <= b->size);
262
263 rest -= chunk;
264 buf += chunk;
265 }
266 while (rest);
267
268 return num;
269 }
270
271
272static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
273 {
274 long ret;
275 struct bio_bio_st *b = bio->ptr;
276
277 assert(b != NULL);
278
279 switch (cmd)
280 {
281 /* specific CTRL codes */
282
283 case BIO_C_SET_WRITE_BUF_SIZE:
284 if (b->peer)
285 {
286 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
287 ret = 0;
288 }
289 else if (num == 0)
290 {
291 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
292 ret = 0;
293 }
294 else
295 {
296 size_t new_size = num;
297
298 if (b->size != new_size)
299 {
300 if (b->buf)
301 {
302 Free(b->buf);
303 b->buf = NULL;
304 }
305 b->size = new_size;
306 }
307 ret = 1;
308 }
309 break;
310
311 case BIO_C_GET_WRITE_BUF_SIZE:
312 num = (long) b->size;
313
314 case BIO_C_MAKE_BIO_PAIR:
315 {
316 BIO *other_bio = ptr;
317
318 if (bio_make_pair(bio, other_bio))
319 ret = 1;
320 else
321 ret = 0;
322 }
323 break;
324
325 case BIO_C_DESTROY_BIO_PAIR:
326 /* Effects both BIOs in the pair -- call just once!
327 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
328 bio_destroy_pair(bio);
329 ret = 1;
330 break;
331
332 case BIO_C_GET_WRITE_GUARANTEE:
333 /* How many bytes can the caller feed to the next write
334 * withouth having to keep any? */
335 if (b->peer == NULL || b->closed)
336 ret = 0;
337 else
338 ret = (long) b->size - b->len;
339 break;
340
341 case BIO_C_GET_READ_REQUEST:
342 /* If the peer unsuccesfully tried to read, how many bytes
343 * were requested? (As with BIO_CTRL_PENDING, that number
344 * can usually be treated as boolean.) */
345 ret = (long) b->request;
346 break;
347
348 case BIO_C_SHUTDOWN_WR:
349 /* similar to shutdown(..., SHUT_WR) */
350 b->closed = 1;
351 ret = 1;
352 break;
353
354
355 /* standard CTRL codes follow */
356
357 case BIO_CTRL_RESET:
358 if (b->buf != NULL)
359 {
360 b->len = 0;
361 b->offset = 0;
362 }
363 ret = 0;
364 break;
365
366 case BIO_CTRL_GET_CLOSE:
367 ret = bio->shutdown;
368 break;
369
370 case BIO_CTRL_SET_CLOSE:
371 bio->shutdown = (int) num;
372 ret = 1;
373 break;
374
375 case BIO_CTRL_PENDING:
376 if (b->peer != NULL)
377 {
378 struct bio_bio_st *peer_b = b->peer->ptr;
379
380 ret = (long) peer_b->len;
381 }
382 else
383 ret = 0;
384 break;
385
386 case BIO_CTRL_WPENDING:
387 if (b->buf != NULL)
388 ret = (long) b->len;
389 else
390 ret = 0;
391 break;
392
393 case BIO_CTRL_DUP:
394 /* See BIO_dup_chain for circumstances we have to expect. */
395 {
396 BIO *other_bio = ptr;
397 struct bio_bio_st *other_b;
398
399 assert(other_bio != NULL);
400 other_b = other_bio->ptr;
401 assert(other_b != NULL);
402
403 assert(other_b->buf == NULL); /* other_bio is always fresh */
404
405 other_b->size = b->size;
406 }
407
408 ret = 1;
409 break;
410
411 case BIO_CTRL_FLUSH:
412 ret = 1;
413 break;
414
415 case BIO_CTRL_EOF:
416 {
417 BIO *other_bio = ptr;
418
419 if (other_bio)
420 {
421 struct bio_bio_st *other_b = other_bio->ptr;
422
423 assert(other_b != NULL);
424 ret = other_b->len == 0 && other_b->closed;
425 }
426 else
427 ret = 1;
428 }
429 break;
430
431 default:
432 ret = 0;
433 }
434 return ret;
435 }
436
437static int bio_puts(BIO *bio, char *str)
438 {
439 return bio_write(bio, str, strlen(str));
440 }
441
442
443static int bio_make_pair(BIO *bio1, BIO *bio2)
444 {
445 struct bio_bio_st *b1, *b2;
446
447 assert(bio1 != NULL);
448 assert(bio2 != NULL);
449
450 b1 = bio1->ptr;
451 b2 = bio2->ptr;
452
453 if (b1->peer != NULL || b2->peer != NULL)
454 {
455 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
456 return 0;
457 }
458
459 if (b1->buf == NULL)
460 {
461 b1->buf = Malloc(b1->size);
462 if (b1->buf == NULL)
463 {
464 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
465 return 0;
466 }
467 b1->len = 0;
468 b1->offset = 0;
469 }
470
471 if (b2->buf == NULL)
472 {
473 b2->buf = Malloc(b2->size);
474 if (b2->buf == NULL)
475 {
476 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
477 return 0;
478 }
479 b2->len = 0;
480 b2->offset = 0;
481 }
482
483 b1->peer = bio2;
484 b1->closed = 0;
485 b1->request = 0;
486 b2->peer = bio1;
487 b2->closed = 0;
488 b2->request = 0;
489
490 bio1->init = 1;
491 bio2->init = 1;
492
493 return 1;
494 }
495
496static void bio_destroy_pair(BIO *bio)
497 {
498 struct bio_bio_st *b = bio->ptr;
499
500 if (b != NULL)
501 {
502 BIO *peer_bio = b->peer;
503
504 if (peer_bio != NULL)
505 {
506 struct bio_bio_st *peer_b = peer_bio->ptr;
507
508 assert(peer_b != NULL);
509 assert(peer_b->peer == bio);
510
511 peer_b->peer = NULL;
512 peer_bio->init = 0;
513 assert(peer_b->buf != NULL);
514 peer_b->len = 0;
515 peer_b->offset = 0;
516
517 b->peer = NULL;
518 bio->init = 0;
519 assert(b->buf != NULL);
520 b->len = 0;
521 b->offset = 0;
522 }
523 }
524 }
525
526
527/* Exported convenience functions */
528int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
529 BIO **bio2_p, size_t writebuf2)
530 {
531 BIO *bio1 = NULL, *bio2 = NULL;
532 long r;
533 int ret = 0;
534
535 bio1 = BIO_new(BIO_s_bio());
536 if (bio1 == NULL)
537 goto err;
538 bio2 = BIO_new(BIO_s_bio());
539 if (bio2 == NULL)
540 goto err;
541
542 if (writebuf1)
543 {
544 r = BIO_set_write_buf_size(bio1, writebuf1);
545 if (!r)
546 goto err;
547 }
548 if (writebuf2)
549 {
550 r = BIO_set_write_buf_size(bio2, writebuf2);
551 if (!r)
552 goto err;
553 }
554
555 r = BIO_make_bio_pair(bio1, bio2);
556 if (!r)
557 goto err;
558 ret = 1;
559
560 err:
561 if (ret == 0)
562 {
563 if (bio1)
564 {
565 BIO_free(bio1);
566 bio1 = NULL;
567 }
568 if (bio2)
569 {
570 BIO_free(bio2);
571 bio2 = NULL;
572 }
573 }
574
575 *bio1_p = bio1;
576 *bio2_p = bio2;
577 return ret;
578 }
579
580size_t BIO_ctrl_get_write_guarantee(BIO *bio)
581 {
582 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
583 }
584
585size_t BIO_ctrl_get_read_request(BIO *bio)
586 {
587 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
588 }
diff --git a/src/lib/libssl/src/crypto/bio/bss_log.c b/src/lib/libssl/src/crypto/bio/bss_log.c
new file mode 100644
index 0000000000..db82e757e7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_log.c
@@ -0,0 +1,232 @@
1/* crypto/bio/bss_log.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 Why BIO_s_log?
58
59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (or event log
61 under NT).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#ifndef WIN32
70#ifdef __ultrix
71#include <sys/syslog.h>
72#else
73#include <syslog.h>
74#endif
75#endif
76
77#include "cryptlib.h"
78#include <openssl/buffer.h>
79#include <openssl/err.h>
80#ifndef NO_SYSLOG
81
82
83static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
84static int MS_CALLBACK slg_puts(BIO *h,char *str);
85static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
86static int MS_CALLBACK slg_new(BIO *h);
87static int MS_CALLBACK slg_free(BIO *data);
88static int xopenlog(BIO* bp, const char* name, int level);
89static int xcloselog(BIO* bp);
90
91static BIO_METHOD methods_slg=
92 {
93 BIO_TYPE_MEM,"syslog",
94 slg_write,
95 NULL,
96 slg_puts,
97 NULL,
98 slg_ctrl,
99 slg_new,
100 slg_free,
101 };
102
103BIO_METHOD *BIO_s_log(void)
104 {
105 return(&methods_slg);
106 }
107
108static int MS_CALLBACK slg_new(BIO *bi)
109 {
110 bi->init=1;
111 bi->num=0;
112 bi->ptr=NULL;
113#ifndef WIN32
114 xopenlog(bi, "application", LOG_DAEMON);
115#else
116 xopenlog(bi, "application", 0);
117#endif
118 return(1);
119 }
120
121static int MS_CALLBACK slg_free(BIO *a)
122 {
123 if (a == NULL) return(0);
124 xcloselog(a);
125 return(1);
126 }
127
128static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
129 {
130 int ret= inl;
131 char* buf= in;
132 char* pp;
133#if defined(WIN32)
134 LPTSTR lpszStrings[1];
135 WORD evtype= EVENTLOG_ERROR_TYPE;
136#else
137 int priority;
138#endif
139
140 if((buf= (char *)Malloc(inl+ 1)) == NULL){
141 return(0);
142 }
143 strncpy(buf, in, inl);
144 buf[inl]= '\0';
145#if defined(WIN32)
146 if(strncmp(buf, "ERR ", 4) == 0){
147 evtype= EVENTLOG_ERROR_TYPE;
148 pp= buf+ 4;
149 }else if(strncmp(buf, "WAR ", 4) == 0){
150 evtype= EVENTLOG_WARNING_TYPE;
151 pp= buf+ 4;
152 }else if(strncmp(buf, "INF ", 4) == 0){
153 evtype= EVENTLOG_INFORMATION_TYPE;
154 pp= buf+ 4;
155 }else{
156 evtype= EVENTLOG_ERROR_TYPE;
157 pp= buf;
158 }
159 lpszStrings[0]= pp;
160
161 if(b->ptr)
162 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0,
163 lpszStrings, NULL);
164#else
165 if(strncmp(buf, "ERR ", 4) == 0){
166 priority= LOG_ERR;
167 pp= buf+ 4;
168 }else if(strncmp(buf, "WAR ", 4) == 0){
169 priority= LOG_WARNING;
170 pp= buf+ 4;
171 }else if(strncmp(buf, "INF ", 4) == 0){
172 priority= LOG_INFO;
173 pp= buf+ 4;
174 }else{
175 priority= LOG_ERR;
176 pp= buf;
177 }
178
179 syslog(priority, "%s", pp);
180#endif
181 Free(buf);
182 return(ret);
183 }
184
185static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
186 {
187 switch (cmd)
188 {
189 case BIO_CTRL_SET:
190 xcloselog(b);
191 xopenlog(b, ptr, num);
192 break;
193 default:
194 break;
195 }
196 return(0);
197 }
198
199static int MS_CALLBACK slg_puts(BIO *bp, char *str)
200 {
201 int n,ret;
202
203 n=strlen(str);
204 ret=slg_write(bp,str,n);
205 return(ret);
206 }
207
208static int xopenlog(BIO* bp, const char* name, int level)
209{
210#if defined(WIN32)
211 if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){
212 return(0);
213 }
214#else
215 openlog(name, LOG_PID|LOG_CONS, level);
216#endif
217 return(1);
218}
219
220static int xcloselog(BIO* bp)
221{
222#if defined(WIN32)
223 if(bp->ptr)
224 DeregisterEventSource((HANDLE)(bp->ptr));
225 bp->ptr= NULL;
226#else
227 closelog();
228#endif
229 return(1);
230}
231
232#endif
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.s.works b/src/lib/libssl/src/crypto/bn/asm/alpha.s.works
new file mode 100644
index 0000000000..ee6c587809
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.s.works
@@ -0,0 +1,533 @@
1
2 # DEC Alpha assember
3 # The bn_div64 is actually gcc output but the other parts are hand done.
4 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
5 # bn_div64.
6 # I've gone back and re-done most of routines.
7 # The key thing to remeber for the 164 CPU is that while a
8 # multiply operation takes 8 cycles, another one can only be issued
9 # after 4 cycles have elapsed. I've done modification to help
10 # improve this. Also, normally, a ld instruction will not be available
11 # for about 3 cycles.
12 .file 1 "bn_asm.c"
13 .set noat
14gcc2_compiled.:
15__gnu_compiled_c:
16 .text
17 .align 3
18 .globl bn_mul_add_words
19 .ent bn_mul_add_words
20bn_mul_add_words:
21bn_mul_add_words..ng:
22 .frame $30,0,$26,0
23 .prologue 0
24 .align 5
25 subq $18,4,$18
26 bis $31,$31,$0
27 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
28 ldq $20,0($17) # 1 1
29 ldq $1,0($16) # 1 1
30 .align 3
31$42:
32 mulq $20,$19,$5 # 1 2 1 ######
33 ldq $21,8($17) # 2 1
34 ldq $2,8($16) # 2 1
35 umulh $20,$19,$20 # 1 2 ######
36 ldq $27,16($17) # 3 1
37 ldq $3,16($16) # 3 1
38 mulq $21,$19,$6 # 2 2 1 ######
39 ldq $28,24($17) # 4 1
40 addq $1,$5,$1 # 1 2 2
41 ldq $4,24($16) # 4 1
42 umulh $21,$19,$21 # 2 2 ######
43 cmpult $1,$5,$22 # 1 2 3 1
44 addq $20,$22,$20 # 1 3 1
45 addq $1,$0,$1 # 1 2 3 1
46 mulq $27,$19,$7 # 3 2 1 ######
47 cmpult $1,$0,$0 # 1 2 3 2
48 addq $2,$6,$2 # 2 2 2
49 addq $20,$0,$0 # 1 3 2
50 cmpult $2,$6,$23 # 2 2 3 1
51 addq $21,$23,$21 # 2 3 1
52 umulh $27,$19,$27 # 3 2 ######
53 addq $2,$0,$2 # 2 2 3 1
54 cmpult $2,$0,$0 # 2 2 3 2
55 subq $18,4,$18
56 mulq $28,$19,$8 # 4 2 1 ######
57 addq $21,$0,$0 # 2 3 2
58 addq $3,$7,$3 # 3 2 2
59 addq $16,32,$16
60 cmpult $3,$7,$24 # 3 2 3 1
61 stq $1,-32($16) # 1 2 4
62 umulh $28,$19,$28 # 4 2 ######
63 addq $27,$24,$27 # 3 3 1
64 addq $3,$0,$3 # 3 2 3 1
65 stq $2,-24($16) # 2 2 4
66 cmpult $3,$0,$0 # 3 2 3 2
67 stq $3,-16($16) # 3 2 4
68 addq $4,$8,$4 # 4 2 2
69 addq $27,$0,$0 # 3 3 2
70 cmpult $4,$8,$25 # 4 2 3 1
71 addq $17,32,$17
72 addq $28,$25,$28 # 4 3 1
73 addq $4,$0,$4 # 4 2 3 1
74 cmpult $4,$0,$0 # 4 2 3 2
75 stq $4,-8($16) # 4 2 4
76 addq $28,$0,$0 # 4 3 2
77 blt $18,$43
78
79 ldq $20,0($17) # 1 1
80 ldq $1,0($16) # 1 1
81
82 br $42
83
84 .align 4
85$45:
86 ldq $20,0($17) # 4 1
87 ldq $1,0($16) # 4 1
88 mulq $20,$19,$5 # 4 2 1
89 subq $18,1,$18
90 addq $16,8,$16
91 addq $17,8,$17
92 umulh $20,$19,$20 # 4 2
93 addq $1,$5,$1 # 4 2 2
94 cmpult $1,$5,$22 # 4 2 3 1
95 addq $20,$22,$20 # 4 3 1
96 addq $1,$0,$1 # 4 2 3 1
97 cmpult $1,$0,$0 # 4 2 3 2
98 addq $20,$0,$0 # 4 3 2
99 stq $1,-8($16) # 4 2 4
100 bgt $18,$45
101 ret $31,($26),1 # else exit
102
103 .align 4
104$43:
105 addq $18,4,$18
106 bgt $18,$45 # goto tail code
107 ret $31,($26),1 # else exit
108
109 .end bn_mul_add_words
110 .align 3
111 .globl bn_mul_words
112 .ent bn_mul_words
113bn_mul_words:
114bn_mul_words..ng:
115 .frame $30,0,$26,0
116 .prologue 0
117 .align 5
118 subq $18,4,$18
119 bis $31,$31,$0
120 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
121 ldq $20,0($17) # 1 1
122 .align 3
123$142:
124
125 mulq $20,$19,$5 # 1 2 1 #####
126 ldq $21,8($17) # 2 1
127 ldq $27,16($17) # 3 1
128 umulh $20,$19,$20 # 1 2 #####
129 ldq $28,24($17) # 4 1
130 mulq $21,$19,$6 # 2 2 1 #####
131 addq $5,$0,$5 # 1 2 3 1
132 subq $18,4,$18
133 cmpult $5,$0,$0 # 1 2 3 2
134 umulh $21,$19,$21 # 2 2 #####
135 addq $20,$0,$0 # 1 3 2
136 addq $17,32,$17
137 addq $6,$0,$6 # 2 2 3 1
138 mulq $27,$19,$7 # 3 2 1 #####
139 cmpult $6,$0,$0 # 2 2 3 2
140 addq $21,$0,$0 # 2 3 2
141 addq $16,32,$16
142 umulh $27,$19,$27 # 3 2 #####
143 stq $5,-32($16) # 1 2 4
144 mulq $28,$19,$8 # 4 2 1 #####
145 addq $7,$0,$7 # 3 2 3 1
146 stq $6,-24($16) # 2 2 4
147 cmpult $7,$0,$0 # 3 2 3 2
148 umulh $28,$19,$28 # 4 2 #####
149 addq $27,$0,$0 # 3 3 2
150 stq $7,-16($16) # 3 2 4
151 addq $8,$0,$8 # 4 2 3 1
152 cmpult $8,$0,$0 # 4 2 3 2
153
154 addq $28,$0,$0 # 4 3 2
155
156 stq $8,-8($16) # 4 2 4
157
158 blt $18,$143
159
160 ldq $20,0($17) # 1 1
161
162 br $142
163
164 .align 4
165$145:
166 ldq $20,0($17) # 4 1
167 mulq $20,$19,$5 # 4 2 1
168 subq $18,1,$18
169 umulh $20,$19,$20 # 4 2
170 addq $5,$0,$5 # 4 2 3 1
171 addq $16,8,$16
172 cmpult $5,$0,$0 # 4 2 3 2
173 addq $17,8,$17
174 addq $20,$0,$0 # 4 3 2
175 stq $5,-8($16) # 4 2 4
176
177 bgt $18,$145
178 ret $31,($26),1 # else exit
179
180 .align 4
181$143:
182 addq $18,4,$18
183 bgt $18,$145 # goto tail code
184 ret $31,($26),1 # else exit
185
186 .end bn_mul_words
187 .align 3
188 .globl bn_sqr_words
189 .ent bn_sqr_words
190bn_sqr_words:
191bn_sqr_words..ng:
192 .frame $30,0,$26,0
193 .prologue 0
194
195 subq $18,4,$18
196 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
197 ldq $20,0($17) # 1 1
198 .align 3
199$542:
200 mulq $20,$20,$5 ######
201 ldq $21,8($17) # 1 1
202 subq $18,4
203 umulh $20,$20,$1 ######
204 ldq $27,16($17) # 1 1
205 mulq $21,$21,$6 ######
206 ldq $28,24($17) # 1 1
207 stq $5,0($16) # r[0]
208 umulh $21,$21,$2 ######
209 stq $1,8($16) # r[1]
210 mulq $27,$27,$7 ######
211 stq $6,16($16) # r[0]
212 umulh $27,$27,$3 ######
213 stq $2,24($16) # r[1]
214 mulq $28,$28,$8 ######
215 stq $7,32($16) # r[0]
216 umulh $28,$28,$4 ######
217 stq $3,40($16) # r[1]
218
219 addq $16,64,$16
220 addq $17,32,$17
221 stq $8,-16($16) # r[0]
222 stq $4,-8($16) # r[1]
223
224 blt $18,$543
225 ldq $20,0($17) # 1 1
226 br $542
227
228$442:
229 ldq $20,0($17) # a[0]
230 mulq $20,$20,$5 # a[0]*w low part r2
231 addq $16,16,$16
232 addq $17,8,$17
233 subq $18,1,$18
234 umulh $20,$20,$1 # a[0]*w high part r3
235 stq $5,-16($16) # r[0]
236 stq $1,-8($16) # r[1]
237
238 bgt $18,$442
239 ret $31,($26),1 # else exit
240
241 .align 4
242$543:
243 addq $18,4,$18
244 bgt $18,$442 # goto tail code
245 ret $31,($26),1 # else exit
246 .end bn_sqr_words
247
248 .align 3
249 .globl bn_add_words
250 .ent bn_add_words
251bn_add_words:
252bn_add_words..ng:
253 .frame $30,0,$26,0
254 .prologue 0
255
256 subq $19,4,$19
257 bis $31,$31,$0 # carry = 0
258 blt $19,$900
259 ldq $5,0($17) # a[0]
260 ldq $1,0($18) # b[1]
261 .align 3
262$901:
263 addq $1,$5,$1 # r=a+b;
264 ldq $6,8($17) # a[1]
265 cmpult $1,$5,$22 # did we overflow?
266 ldq $2,8($18) # b[1]
267 addq $1,$0,$1 # c+= overflow
268 ldq $7,16($17) # a[2]
269 cmpult $1,$0,$0 # overflow?
270 ldq $3,16($18) # b[2]
271 addq $0,$22,$0
272 ldq $8,24($17) # a[3]
273 addq $2,$6,$2 # r=a+b;
274 ldq $4,24($18) # b[3]
275 cmpult $2,$6,$23 # did we overflow?
276 addq $3,$7,$3 # r=a+b;
277 addq $2,$0,$2 # c+= overflow
278 cmpult $3,$7,$24 # did we overflow?
279 cmpult $2,$0,$0 # overflow?
280 addq $4,$8,$4 # r=a+b;
281 addq $0,$23,$0
282 cmpult $4,$8,$25 # did we overflow?
283 addq $3,$0,$3 # c+= overflow
284 stq $1,0($16) # r[0]=c
285 cmpult $3,$0,$0 # overflow?
286 stq $2,8($16) # r[1]=c
287 addq $0,$24,$0
288 stq $3,16($16) # r[2]=c
289 addq $4,$0,$4 # c+= overflow
290 subq $19,4,$19 # loop--
291 cmpult $4,$0,$0 # overflow?
292 addq $17,32,$17 # a++
293 addq $0,$25,$0
294 stq $4,24($16) # r[3]=c
295 addq $18,32,$18 # b++
296 addq $16,32,$16 # r++
297
298 blt $19,$900
299 ldq $5,0($17) # a[0]
300 ldq $1,0($18) # b[1]
301 br $901
302 .align 4
303$945:
304 ldq $5,0($17) # a[0]
305 ldq $1,0($18) # b[1]
306 addq $1,$5,$1 # r=a+b;
307 subq $19,1,$19 # loop--
308 addq $1,$0,$1 # c+= overflow
309 addq $17,8,$17 # a++
310 cmpult $1,$5,$22 # did we overflow?
311 cmpult $1,$0,$0 # overflow?
312 addq $18,8,$18 # b++
313 stq $1,0($16) # r[0]=c
314 addq $0,$22,$0
315 addq $16,8,$16 # r++
316
317 bgt $19,$945
318 ret $31,($26),1 # else exit
319
320$900:
321 addq $19,4,$19
322 bgt $19,$945 # goto tail code
323 ret $31,($26),1 # else exit
324 .end bn_add_words
325
326 #
327 # What follows was taken directly from the C compiler with a few
328 # hacks to redo the lables.
329 #
330.text
331 .align 3
332 .globl bn_div64
333 .ent bn_div64
334bn_div64:
335 ldgp $29,0($27)
336bn_div64..ng:
337 lda $30,-48($30)
338 .frame $30,48,$26,0
339 stq $26,0($30)
340 stq $9,8($30)
341 stq $10,16($30)
342 stq $11,24($30)
343 stq $12,32($30)
344 stq $13,40($30)
345 .mask 0x4003e00,-48
346 .prologue 1
347 bis $16,$16,$9
348 bis $17,$17,$10
349 bis $18,$18,$11
350 bis $31,$31,$13
351 bis $31,2,$12
352 bne $11,$119
353 lda $0,-1
354 br $31,$136
355 .align 4
356$119:
357 bis $11,$11,$16
358 jsr $26,BN_num_bits_word
359 ldgp $29,0($26)
360 subq $0,64,$1
361 beq $1,$120
362 bis $31,1,$1
363 sll $1,$0,$1
364 cmpule $9,$1,$1
365 bne $1,$120
366 # lda $16,_IO_stderr_
367 # lda $17,$C32
368 # bis $0,$0,$18
369 # jsr $26,fprintf
370 # ldgp $29,0($26)
371 jsr $26,abort
372 ldgp $29,0($26)
373 .align 4
374$120:
375 bis $31,64,$3
376 cmpult $9,$11,$2
377 subq $3,$0,$1
378 addl $1,$31,$0
379 subq $9,$11,$1
380 cmoveq $2,$1,$9
381 beq $0,$122
382 zapnot $0,15,$2
383 subq $3,$0,$1
384 sll $11,$2,$11
385 sll $9,$2,$3
386 srl $10,$1,$1
387 sll $10,$2,$10
388 bis $3,$1,$9
389$122:
390 srl $11,32,$5
391 zapnot $11,15,$6
392 lda $7,-1
393 .align 5
394$123:
395 srl $9,32,$1
396 subq $1,$5,$1
397 bne $1,$126
398 zapnot $7,15,$27
399 br $31,$127
400 .align 4
401$126:
402 bis $9,$9,$24
403 bis $5,$5,$25
404 divqu $24,$25,$27
405$127:
406 srl $10,32,$4
407 .align 5
408$128:
409 mulq $27,$5,$1
410 subq $9,$1,$3
411 zapnot $3,240,$1
412 bne $1,$129
413 mulq $6,$27,$2
414 sll $3,32,$1
415 addq $1,$4,$1
416 cmpule $2,$1,$2
417 bne $2,$129
418 subq $27,1,$27
419 br $31,$128
420 .align 4
421$129:
422 mulq $27,$6,$1
423 mulq $27,$5,$4
424 srl $1,32,$3
425 sll $1,32,$1
426 addq $4,$3,$4
427 cmpult $10,$1,$2
428 subq $10,$1,$10
429 addq $2,$4,$2
430 cmpult $9,$2,$1
431 bis $2,$2,$4
432 beq $1,$134
433 addq $9,$11,$9
434 subq $27,1,$27
435$134:
436 subl $12,1,$12
437 subq $9,$4,$9
438 beq $12,$124
439 sll $27,32,$13
440 sll $9,32,$2
441 srl $10,32,$1
442 sll $10,32,$10
443 bis $2,$1,$9
444 br $31,$123
445 .align 4
446$124:
447 bis $13,$27,$0
448$136:
449 ldq $26,0($30)
450 ldq $9,8($30)
451 ldq $10,16($30)
452 ldq $11,24($30)
453 ldq $12,32($30)
454 ldq $13,40($30)
455 addq $30,48,$30
456 ret $31,($26),1
457 .end bn_div64
458
459 .set noat
460 .text
461 .align 3
462 .globl bn_sub_words
463 .ent bn_sub_words
464bn_sub_words:
465bn_sub_words..ng:
466 .frame $30,0,$26,0
467 .prologue 0
468
469 subq $19, 4, $19
470 bis $31, $31, $0
471 blt $19, $100
472 ldq $1, 0($17)
473 ldq $2, 0($18)
474$101:
475 ldq $3, 8($17)
476 cmpult $1, $2, $4
477 ldq $5, 8($18)
478 subq $1, $2, $1
479 ldq $6, 16($17)
480 cmpult $1, $0, $2
481 ldq $7, 16($18)
482 subq $1, $0, $23
483 ldq $8, 24($17)
484 addq $2, $4, $0
485 cmpult $3, $5, $24
486 subq $3, $5, $3
487 ldq $22, 24($18)
488 cmpult $3, $0, $5
489 subq $3, $0, $25
490 addq $5, $24, $0
491 cmpult $6, $7, $27
492 subq $6, $7, $6
493 stq $23, 0($16)
494 cmpult $6, $0, $7
495 subq $6, $0, $28
496 addq $7, $27, $0
497 cmpult $8, $22, $21
498 subq $8, $22, $8
499 stq $25, 8($16)
500 cmpult $8, $0, $22
501 subq $8, $0, $20
502 addq $22, $21, $0
503 stq $28, 16($16)
504 subq $19, 4, $19
505 stq $20, 24($16)
506 addq $17, 32, $17
507 addq $18, 32, $18
508 addq $16, 32, $16
509 blt $19, $100
510 ldq $1, 0($17)
511 ldq $2, 0($18)
512 br $101
513$102:
514 ldq $1, 0($17)
515 ldq $2, 0($18)
516 cmpult $1, $2, $27
517 subq $1, $2, $1
518 cmpult $1, $0, $2
519 subq $1, $0, $1
520 stq $1, 0($16)
521 addq $2, $27, $0
522 addq $17, 8, $17
523 addq $18, 8, $18
524 addq $16, 8, $16
525 subq $19, 1, $19
526 bgt $19, $102
527 ret $31,($26),1
528$100:
529 addq $19, 4, $19
530 bgt $19, $102
531$103:
532 ret $31,($26),1
533 .end bn_sub_words
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/add.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/add.pl
new file mode 100644
index 0000000000..4dc76e6b69
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/add.pl
@@ -0,0 +1,119 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$b0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($b0,&QWPw(0,$bp));
28
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84##################################################
85 # Do the last 0..3 words
86
87 ($t0,$o0)=&NR(2);
88 &set_label("last_loop");
89
90 &ld($a0,&QWPw(0,$ap)); # get a
91 &ld($b0,&QWPw(0,$bp)); # get b
92
93 &add($a0,$b0,$o0);
94 &cmpult($o0,$b0,$t0); # will we borrow?
95 &add($o0,$cc,$o0); # will we borrow?
96 &cmpult($o0,$cc,$cc); # will we borrow?
97 &add($cc,$t0,$cc); # add the borrows
98 &st($o0,&QWPw(0,$rp)); # save
99
100 &add($ap,$QWS,$ap);
101 &add($bp,$QWS,$bp);
102 &add($rp,$QWS,$rp);
103 &sub($count,1,$count);
104 &bgt($count,&label("last_loop"));
105 &function_end_A($name);
106
107######################################################
108 &set_label("finish");
109 &add($count,4,$count);
110 &bgt($count,&label("last_loop"));
111
112 &FR($o0,$t0,$a0,$b0);
113 &set_label("end");
114 &function_end($name);
115
116 &fin_pool;
117 }
118
1191;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/div.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/div.pl
new file mode 100644
index 0000000000..7ec144377f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div64
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div64
15 .ent bn_div64
16bn_div64:
17 ldgp $29,0($27)
18bn_div64..ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div64
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul.pl
new file mode 100644
index 0000000000..b182bae452
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &mul($a0,$word,($l0)=&NR(1));
93 &add($ap,$QWS,$ap);
94 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
95 &add($l0,$cc,$l0);
96 &add($rp,$QWS,$rp);
97 &sub($count,1,$count);
98 &cmpult($l0,$cc,$cc);
99 &st($l0,&QWPw(-1,$rp)); &FR($l0);
100 &add($h0,$cc,$cc); &FR($h0);
101
102 &bgt($count,&label("last_loop"));
103 &function_end_A($name);
104
105######################################################
106 &set_label("finish");
107 &add($count,4,$count);
108 &bgt($count,&label("last_loop"));
109
110 &set_label("end");
111 &function_end($name);
112
113 &fin_pool;
114 }
115
1161;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_add.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_add.pl
new file mode 100644
index 0000000000..e37f6315fb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_add.pl
@@ -0,0 +1,120 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
93 &mul($a0,$word,($l0)=&NR(1));
94 &sub($count,1,$count);
95 &add($ap,$QWS,$ap);
96 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
97 &add($r0,$l0,$r0);
98 &add($rp,$QWS,$rp);
99 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
100 &add($r0,$cc,$r0);
101 &add($h0,$t0,$h0); &FR($t0);
102 &cmpult($r0,$cc,$cc);
103 &st($r0,&QWPw(-1,$rp)); &FR($r0);
104 &add($h0,$cc,$cc); &FR($h0);
105
106 &bgt($count,&label("last_loop"));
107 &function_end_A($name);
108
109######################################################
110 &set_label("finish");
111 &add($count,4,$count);
112 &bgt($count,&label("last_loop"));
113
114 &set_label("end");
115 &function_end($name);
116
117 &fin_pool;
118 }
119
1201;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.pl
new file mode 100644
index 0000000000..5efd201281
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.pl
@@ -0,0 +1,213 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$b,($l1)=&NR(1));
10 &muh($a,$b,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
13 &add($t1,$h1,$h1); &FR($t1);
14 &add($c1,$h1,$c1);
15 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub bn_mul_comba4
20 {
21 local($name)=@_;
22 local(@a,@b,$r,$c0,$c1,$c2);
23
24 $cnt=1;
25 &init_pool(3);
26
27 $rp=&wparam(0);
28 $ap=&wparam(1);
29 $bp=&wparam(2);
30
31 &function_begin($name,"");
32
33 &comment("");
34
35 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
36 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
37 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
38 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
39 &mul($a[0],$b[0],($r00)=&NR(1));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &muh($a[0],$b[0],($r01)=&NR(1));
43 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
44 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
45 &mul($a[0],$b[1],($r02)=&NR(1));
46
47 ($R,$H1,$H2)=&NR(3);
48
49 &st($r00,&QWPw(0,$rp)); &FR($r00);
50
51 &mov("zero",$R);
52 &mul($a[1],$b[0],($r03)=&NR(1));
53
54 &mov("zero",$H1);
55 &mov("zero",$H0);
56 &add($R,$r01,$R);
57 &muh($a[0],$b[1],($r04)=&NR(1));
58 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
59 &add($R,$r02,$R);
60 &add($H1,$t01,$H1) &FR($t01);
61 &muh($a[1],$b[0],($r05)=&NR(1));
62 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
63 &add($R,$r03,$R);
64 &add($H2,$t02,$H2) &FR($t02);
65 &mul($a[0],$b[2],($r06)=&NR(1));
66 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
67 &add($H1,$t03,$H1) &FR($t03);
68 &st($R,&QWPw(1,$rp));
69 &add($H1,$H2,$R);
70
71 &mov("zero",$H1);
72 &add($R,$r04,$R);
73 &mov("zero",$H2);
74 &mul($a[1],$b[1],($r07)=&NR(1));
75 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
76 &add($R,$r05,$R);
77 &add($H1,$t04,$H1) &FR($t04);
78 &mul($a[2],$b[0],($r08)=&NR(1));
79 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
80 &add($R,$r01,$R);
81 &add($H2,$t05,$H2) &FR($t05);
82 &muh($a[0],$b[2],($r09)=&NR(1));
83 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
84 &add($R,$r07,$R);
85 &add($H1,$t06,$H1) &FR($t06);
86 &muh($a[1],$b[1],($r10)=&NR(1));
87 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
88 &add($R,$r08,$R);
89 &add($H2,$t07,$H2) &FR($t07);
90 &muh($a[2],$b[0],($r11)=&NR(1));
91 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
92 &add($H1,$t08,$H1) &FR($t08);
93 &st($R,&QWPw(2,$rp));
94 &add($H1,$H2,$R);
95
96 &mov("zero",$H1);
97 &add($R,$r09,$R);
98 &mov("zero",$H2);
99 &mul($a[0],$b[3],($r12)=&NR(1));
100 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
101 &add($R,$r10,$R);
102 &add($H1,$t09,$H1) &FR($t09);
103 &mul($a[1],$b[2],($r13)=&NR(1));
104 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
105 &add($R,$r11,$R);
106 &add($H1,$t10,$H1) &FR($t10);
107 &mul($a[2],$b[1],($r14)=&NR(1));
108 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
109 &add($R,$r12,$R);
110 &add($H1,$t11,$H1) &FR($t11);
111 &mul($a[3],$b[0],($r15)=&NR(1));
112 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
113 &add($R,$r13,$R);
114 &add($H1,$t12,$H1) &FR($t12);
115 &muh($a[0],$b[3],($r16)=&NR(1));
116 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
117 &add($R,$r14,$R);
118 &add($H1,$t13,$H1) &FR($t13);
119 &muh($a[1],$b[2],($r17)=&NR(1));
120 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
121 &add($R,$r15,$R);
122 &add($H1,$t14,$H1) &FR($t14);
123 &muh($a[2],$b[1],($r18)=&NR(1));
124 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
125 &add($H1,$t15,$H1) &FR($t15);
126 &st($R,&QWPw(3,$rp));
127 &add($H1,$H2,$R);
128
129 &mov("zero",$H1);
130 &add($R,$r16,$R);
131 &mov("zero",$H2);
132 &muh($a[3],$b[0],($r19)=&NR(1));
133 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
134 &add($R,$r17,$R);
135 &add($H1,$t16,$H1) &FR($t16);
136 &mul($a[1],$b[3],($r20)=&NR(1));
137 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
138 &add($R,$r18,$R);
139 &add($H1,$t17,$H1) &FR($t17);
140 &mul($a[2],$b[2],($r21)=&NR(1));
141 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
142 &add($R,$r19,$R);
143 &add($H1,$t18,$H1) &FR($t18);
144 &mul($a[3],$b[1],($r22)=&NR(1));
145 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
146 &add($R,$r20,$R);
147 &add($H1,$t19,$H1) &FR($t19);
148 &muh($a[1],$b[3],($r23)=&NR(1));
149 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
150 &add($R,$r21,$R);
151 &add($H1,$t20,$H1) &FR($t20);
152 &muh($a[2],$b[2],($r24)=&NR(1));
153 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
154 &add($R,$r22,$R);
155 &add($H1,$t21,$H1) &FR($t21);
156 &muh($a[3],$b[1],($r25)=&NR(1));
157 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
158 &add($H1,$t22,$H1) &FR($t22);
159 &st($R,&QWPw(4,$rp));
160 &add($H1,$H2,$R);
161
162 &mov("zero",$H1);
163 &add($R,$r23,$R);
164 &mov("zero",$H2);
165 &mul($a[2],$b[3],($r26)=&NR(1));
166 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
167 &add($R,$r24,$R);
168 &add($H1,$t23,$H1) &FR($t23);
169 &mul($a[3],$b[2],($r27)=&NR(1));
170 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
171 &add($R,$r25,$R);
172 &add($H1,$t24,$H1) &FR($t24);
173 &muh($a[2],$b[3],($r28)=&NR(1));
174 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
175 &add($R,$r26,$R);
176 &add($H1,$t25,$H1) &FR($t25);
177 &muh($a[3],$b[2],($r29)=&NR(1));
178 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
179 &add($R,$r27,$R);
180 &add($H1,$t26,$H1) &FR($t26);
181 &mul($a[3],$b[3],($r30)=&NR(1));
182 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
183 &add($H1,$t27,$H1) &FR($t27);
184 &st($R,&QWPw(5,$rp));
185 &add($H1,$H2,$R);
186
187 &mov("zero",$H1);
188 &add($R,$r28,$R);
189 &mov("zero",$H2);
190 &muh($a[3],$b[3],($r31)=&NR(1));
191 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
192 &add($R,$r29,$R);
193 &add($H1,$t28,$H1) &FR($t28);
194 ############
195 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
196 &add($R,$r30,$R);
197 &add($H1,$t29,$H1) &FR($t29);
198 ############
199 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
200 &add($H1,$t30,$H1) &FR($t30);
201 &st($R,&QWPw(6,$rp));
202 &add($H1,$H2,$R);
203
204 &add($R,$r31,$R); &FR($r31);
205 &st($R,&QWPw(7,$rp));
206
207 &FR($R,$H1,$H2);
208 &function_end($name);
209
210 &fin_pool;
211 }
212
2131;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.works.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c8.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c4.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c8.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.works/sub.pl b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.works/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/add.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/add.pl
new file mode 100644
index 0000000000..13bf516428
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/add.pl
@@ -0,0 +1,118 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25
26##########################################################
27 &set_label("loop");
28
29 &ld(($a0)=&NR(1),&QWPw(0,$ap));
30 &ld(($b0)=&NR(1),&QWPw(0,$bp));
31 &ld(($a1)=&NR(1),&QWPw(1,$ap));
32 &ld(($b1)=&NR(1),&QWPw(1,$bp));
33
34 ($o0,$t0)=&NR(2);
35 &add($a0,$b0,$o0);
36 &ld(($a2)=&NR(1),&QWPw(2,$ap));
37 &cmpult($o0,$b0,$t0);
38 &add($o0,$cc,$o0);
39 &cmpult($o0,$cc,$cc);
40 &ld(($b2)=&NR(1),&QWPw(2,$bp));
41 &add($cc,$t0,$cc); &FR($t0);
42
43 ($t1,$o1)=&NR(2);
44
45 &add($a1,$b1,$o1); &FR($a1);
46 &cmpult($o1,$b1,$t1); &FR($b1);
47 &add($o1,$cc,$o1);
48 &cmpult($o1,$cc,$cc);
49 &ld(($a3)=&NR(1),&QWPw(3,$ap));
50 &add($cc,$t1,$cc); &FR($t1);
51
52 ($t2,$o2)=&NR(2);
53
54 &add($a2,$b2,$o2); &FR($a2);
55 &cmpult($o2,$b2,$t2); &FR($b2);
56 &add($o2,$cc,$o2);
57 &cmpult($o2,$cc,$cc);
58 &ld(($b3)=&NR(1),&QWPw(3,$bp));
59 &st($o0,&QWPw(0,$rp)); &FR($o0);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &st($o1,&QWPw(0,$rp)); &FR($o1);
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &st($o2,&QWPw(0,$rp)); &FR($o2);
69 &cmpult($o3,$cc,$cc);
70 &st($o3,&QWPw(0,$rp)); &FR($o3);
71 &add($cc,$t3,$cc); &FR($t3);
72
73
74 &sub($count,4,$count); # count-=4
75 &add($ap,4*$QWS,$ap); # count+=4
76 &add($bp,4*$QWS,$bp); # count+=4
77 &add($rp,4*$QWS,$rp); # count+=4
78
79 ###
80 &bge($count,&label("loop"));
81 ###
82 &br(&label("finish"));
83##################################################
84 # Do the last 0..3 words
85
86 ($t0,$o0)=&NR(2);
87 &set_label("last_loop");
88
89 &ld($a0,&QWPw(0,$ap)); # get a
90 &ld($b0,&QWPw(0,$bp)); # get b
91 &add($ap,$QWS,$ap);
92 &add($bp,$QWS,$bp);
93 &add($a0,$b0,$o0);
94 &sub($count,1,$count);
95 &cmpult($o0,$b0,$t0); # will we borrow?
96 &add($o0,$cc,$o0); # will we borrow?
97 &cmpult($o0,$cc,$cc); # will we borrow?
98 &add($rp,$QWS,$rp);
99 &st($o0,&QWPw(-1,$rp)); # save
100 &add($cc,$t0,$cc); # add the borrows
101
102 ###
103 &bgt($count,&label("last_loop"));
104 &function_end_A($name);
105
106######################################################
107 &set_label("finish");
108 &add($count,4,$count);
109 &bgt($count,&label("last_loop"));
110
111 &FR($o0,$t0,$a0,$b0);
112 &set_label("end");
113 &function_end($name);
114
115 &fin_pool;
116 }
117
1181;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/div.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/div.pl
new file mode 100644
index 0000000000..e9e680897a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div_words
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div_words
15 .ent bn_div_words
16bn_div_words
17 ldgp $29,0($27)
18bn_div_words.ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div_words
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/mul.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/mul.pl
new file mode 100644
index 0000000000..76c926566c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/mul.pl
@@ -0,0 +1,104 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
26
27 &set_label("loop");
28
29 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
30 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
31
32 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
33 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
34 ### wait 8
35 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
36 ### wait 8
37 &muh($a1,$word,($h1)=&NR(1)); &FR($a1);
38 &add($l0,$cc,$l0); ### wait 8
39 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
40 &cmpult($l0,$cc,$cc); ### wait 8
41 &muh($a2,$word,($h2)=&NR(1)); &FR($a2);
42 &add($h0,$cc,$cc); &FR($h0); ### wait 8
43 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
44 &add($l1,$cc,$l1); ### wait 8
45 &st($l0,&QWPw(0,$rp)); &FR($l0);
46 &cmpult($l1,$cc,$cc); ### wait 8
47 &muh($a3,$word,($h3)=&NR(1)); &FR($a3);
48 &add($h1,$cc,$cc); &FR($h1);
49 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
50 &add($l2,$cc,$l2);
51 &st($l1,&QWPw(1,$rp)); &FR($l1);
52 &cmpult($l2,$cc,$cc);
53 &add($h2,$cc,$cc); &FR($h2);
54 &sub($count,4,$count); # count-=4
55 &st($l2,&QWPw(2,$rp)); &FR($l2);
56 &add($l3,$cc,$l3);
57 &cmpult($l3,$cc,$cc);
58 &add($bp,4*$QWS,$bp); # count+=4
59 &add($h3,$cc,$cc); &FR($h3);
60 &add($ap,4*$QWS,$ap); # count+=4
61 &st($l3,&QWPw(3,$rp)); &FR($l3);
62 &add($rp,4*$QWS,$rp); # count+=4
63 ###
64 &blt($count,&label("finish"));
65 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
66 &br(&label("finish"));
67##################################################
68
69##################################################
70 # Do the last 0..3 words
71
72 &set_label("last_loop");
73
74 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
75 ###
76 ###
77 ###
78 &muh($a0,$word,($h0)=&NR(1));
79 ### Wait 8 for next mul issue
80 &mul($a0,$word,($l0)=&NR(1)); &FR($a0)
81 &add($ap,$QWS,$ap);
82 ### Loose 12 until result is available
83 &add($rp,$QWS,$rp);
84 &sub($count,1,$count);
85 &add($l0,$cc,$l0);
86 ###
87 &st($l0,&QWPw(-1,$rp)); &FR($l0);
88 &cmpult($l0,$cc,$cc);
89 &add($h0,$cc,$cc); &FR($h0);
90 &bgt($count,&label("last_loop"));
91 &function_end_A($name);
92
93######################################################
94 &set_label("finish");
95 &add($count,4,$count);
96 &bgt($count,&label("last_loop"));
97
98 &set_label("end");
99 &function_end($name);
100
101 &fin_pool;
102 }
103
1041;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/mul_add.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_add.pl
new file mode 100644
index 0000000000..0d6df69bc4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_add.pl
@@ -0,0 +1,123 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 &ld(($a0)=&NR(1),&QWPw(0,$ap));
26
27$a=<<'EOF';
28##########################################################
29 &set_label("loop");
30
31 &ld(($r0)=&NR(1),&QWPw(0,$rp));
32 &ld(($a1)=&NR(1),&QWPw(1,$ap));
33 &muh($a0,$word,($h0)=&NR(1));
34 &ld(($r1)=&NR(1),&QWPw(1,$rp));
35 &ld(($a2)=&NR(1),&QWPw(2,$ap));
36 ###
37 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
38 &ld(($r2)=&NR(1),&QWPw(2,$rp));
39 &muh($a1,$word,($h1)=&NR(1));
40 &ld(($a3)=&NR(1),&QWPw(3,$ap));
41 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
42 &ld(($r3)=&NR(1),&QWPw(3,$rp));
43 &add($r0,$l0,$r0);
44 &add($r1,$l1,$r1);
45 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
46 &cmpult($r1,$l1,($t1)=&NR(1)); &FR($l1);
47 &muh($a2,$word,($h2)=&NR(1));
48 &add($r0,$cc,$r0);
49 &add($h0,$t0,$h0); &FR($t0);
50 &cmpult($r0,$cc,$cc);
51 &add($h1,$t1,$h1); &FR($t1);
52 &add($h0,$cc,$cc); &FR($h0);
53 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
54 &add($r1,$cc,$r1);
55 &cmpult($r1,$cc,$cc);
56 &add($r2,$l2,$r2);
57 &add($h1,$cc,$cc); &FR($h1);
58 &cmpult($r2,$l2,($t2)=&NR(1)); &FR($l2);
59 &muh($a3,$word,($h3)=&NR(1));
60 &add($r2,$cc,$r2);
61 &st($r0,&QWPw(0,$rp)); &FR($r0);
62 &add($h2,$t2,$h2); &FR($t2);
63 &st($r1,&QWPw(1,$rp)); &FR($r1);
64 &cmpult($r2,$cc,$cc);
65 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
66 &add($h2,$cc,$cc); &FR($h2);
67 &st($r2,&QWPw(2,$rp)); &FR($r2);
68 &sub($count,4,$count); # count-=4
69 &add($rp,4*$QWS,$rp); # count+=4
70 &add($r3,$l3,$r3);
71 &add($ap,4*$QWS,$ap); # count+=4
72 &cmpult($r3,$l3,($t3)=&NR(1)); &FR($l3);
73 &add($r3,$cc,$r3);
74 &add($h3,$t3,$h3); &FR($t3);
75 &cmpult($r3,$cc,$cc);
76 &st($r3,&QWPw(-1,$rp)); &FR($r3);
77 &add($h3,$cc,$cc); &FR($h3);
78
79 ###
80 &blt($count,&label("finish"));
81 &ld(($a0)=&NR(1),&QWPw(0,$ap));
82 &br(&label("loop"));
83EOF
84##################################################
85 # Do the last 0..3 words
86
87 &set_label("last_loop");
88
89 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
90 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
91 ###
92 ###
93 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
94 ### wait 8
95 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
96 &add($rp,$QWS,$rp);
97 &add($ap,$QWS,$ap);
98 &sub($count,1,$count);
99 ### wait 3 until l0 is available
100 &add($r0,$l0,$r0);
101 ###
102 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
103 &add($r0,$cc,$r0);
104 &add($h0,$t0,$h0); &FR($t0);
105 &cmpult($r0,$cc,$cc);
106 &add($h0,$cc,$cc); &FR($h0);
107
108 &st($r0,&QWPw(-1,$rp)); &FR($r0);
109 &bgt($count,&label("last_loop"));
110 &function_end_A($name);
111
112######################################################
113 &set_label("finish");
114 &add($count,4,$count);
115 &bgt($count,&label("last_loop"));
116
117 &set_label("end");
118 &function_end($name);
119
120 &fin_pool;
121 }
122
1231;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.pl
new file mode 100644
index 0000000000..9cc876ded4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.pl
@@ -0,0 +1,215 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4# upto
5
6sub mul_add_c
7 {
8 local($a,$b,$c0,$c1,$c2)=@_;
9 local($l1,$h1,$t1,$t2);
10
11 &mul($a,$b,($l1)=&NR(1));
12 &muh($a,$b,($h1)=&NR(1));
13 &add($c0,$l1,$c0);
14 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
15 &add($t1,$h1,$h1); &FR($t1);
16 &add($c1,$h1,$c1);
17 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
18 &add($c2,$t2,$c2); &FR($t2);
19 }
20
21sub bn_mul_comba4
22 {
23 local($name)=@_;
24 local(@a,@b,$r,$c0,$c1,$c2);
25
26 $cnt=1;
27 &init_pool(3);
28
29 $rp=&wparam(0);
30 $ap=&wparam(1);
31 $bp=&wparam(2);
32
33 &function_begin($name,"");
34
35 &comment("");
36
37 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
38 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
39 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
40 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
41 &mul($a[0],$b[0],($r00)=&NR(1));
42 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
43 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
44 &muh($a[0],$b[0],($r01)=&NR(1));
45 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
46 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
47 &mul($a[0],$b[1],($r02)=&NR(1));
48
49 ($R,$H1,$H2)=&NR(3);
50
51 &st($r00,&QWPw(0,$rp)); &FR($r00);
52
53 &mov("zero",$R);
54 &mul($a[1],$b[0],($r03)=&NR(1));
55
56 &mov("zero",$H1);
57 &mov("zero",$H0);
58 &add($R,$r01,$R);
59 &muh($a[0],$b[1],($r04)=&NR(1));
60 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
61 &add($R,$r02,$R);
62 &add($H1,$t01,$H1) &FR($t01);
63 &muh($a[1],$b[0],($r05)=&NR(1));
64 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
65 &add($R,$r03,$R);
66 &add($H2,$t02,$H2) &FR($t02);
67 &mul($a[0],$b[2],($r06)=&NR(1));
68 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
69 &add($H1,$t03,$H1) &FR($t03);
70 &st($R,&QWPw(1,$rp));
71 &add($H1,$H2,$R);
72
73 &mov("zero",$H1);
74 &add($R,$r04,$R);
75 &mov("zero",$H2);
76 &mul($a[1],$b[1],($r07)=&NR(1));
77 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
78 &add($R,$r05,$R);
79 &add($H1,$t04,$H1) &FR($t04);
80 &mul($a[2],$b[0],($r08)=&NR(1));
81 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
82 &add($R,$r01,$R);
83 &add($H2,$t05,$H2) &FR($t05);
84 &muh($a[0],$b[2],($r09)=&NR(1));
85 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
86 &add($R,$r07,$R);
87 &add($H1,$t06,$H1) &FR($t06);
88 &muh($a[1],$b[1],($r10)=&NR(1));
89 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
90 &add($R,$r08,$R);
91 &add($H2,$t07,$H2) &FR($t07);
92 &muh($a[2],$b[0],($r11)=&NR(1));
93 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
94 &add($H1,$t08,$H1) &FR($t08);
95 &st($R,&QWPw(2,$rp));
96 &add($H1,$H2,$R);
97
98 &mov("zero",$H1);
99 &add($R,$r09,$R);
100 &mov("zero",$H2);
101 &mul($a[0],$b[3],($r12)=&NR(1));
102 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
103 &add($R,$r10,$R);
104 &add($H1,$t09,$H1) &FR($t09);
105 &mul($a[1],$b[2],($r13)=&NR(1));
106 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
107 &add($R,$r11,$R);
108 &add($H1,$t10,$H1) &FR($t10);
109 &mul($a[2],$b[1],($r14)=&NR(1));
110 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
111 &add($R,$r12,$R);
112 &add($H1,$t11,$H1) &FR($t11);
113 &mul($a[3],$b[0],($r15)=&NR(1));
114 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
115 &add($R,$r13,$R);
116 &add($H1,$t12,$H1) &FR($t12);
117 &muh($a[0],$b[3],($r16)=&NR(1));
118 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
119 &add($R,$r14,$R);
120 &add($H1,$t13,$H1) &FR($t13);
121 &muh($a[1],$b[2],($r17)=&NR(1));
122 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
123 &add($R,$r15,$R);
124 &add($H1,$t14,$H1) &FR($t14);
125 &muh($a[2],$b[1],($r18)=&NR(1));
126 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
127 &add($H1,$t15,$H1) &FR($t15);
128 &st($R,&QWPw(3,$rp));
129 &add($H1,$H2,$R);
130
131 &mov("zero",$H1);
132 &add($R,$r16,$R);
133 &mov("zero",$H2);
134 &muh($a[3],$b[0],($r19)=&NR(1));
135 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
136 &add($R,$r17,$R);
137 &add($H1,$t16,$H1) &FR($t16);
138 &mul($a[1],$b[3],($r20)=&NR(1));
139 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
140 &add($R,$r18,$R);
141 &add($H1,$t17,$H1) &FR($t17);
142 &mul($a[2],$b[2],($r21)=&NR(1));
143 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
144 &add($R,$r19,$R);
145 &add($H1,$t18,$H1) &FR($t18);
146 &mul($a[3],$b[1],($r22)=&NR(1));
147 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
148 &add($R,$r20,$R);
149 &add($H1,$t19,$H1) &FR($t19);
150 &muh($a[1],$b[3],($r23)=&NR(1));
151 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
152 &add($R,$r21,$R);
153 &add($H1,$t20,$H1) &FR($t20);
154 &muh($a[2],$b[2],($r24)=&NR(1));
155 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
156 &add($R,$r22,$R);
157 &add($H1,$t21,$H1) &FR($t21);
158 &muh($a[3],$b[1],($r25)=&NR(1));
159 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
160 &add($H1,$t22,$H1) &FR($t22);
161 &st($R,&QWPw(4,$rp));
162 &add($H1,$H2,$R);
163
164 &mov("zero",$H1);
165 &add($R,$r23,$R);
166 &mov("zero",$H2);
167 &mul($a[2],$b[3],($r26)=&NR(1));
168 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
169 &add($R,$r24,$R);
170 &add($H1,$t23,$H1) &FR($t23);
171 &mul($a[3],$b[2],($r27)=&NR(1));
172 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
173 &add($R,$r25,$R);
174 &add($H1,$t24,$H1) &FR($t24);
175 &muh($a[2],$b[3],($r28)=&NR(1));
176 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
177 &add($R,$r26,$R);
178 &add($H1,$t25,$H1) &FR($t25);
179 &muh($a[3],$b[2],($r29)=&NR(1));
180 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
181 &add($R,$r27,$R);
182 &add($H1,$t26,$H1) &FR($t26);
183 &mul($a[3],$b[3],($r30)=&NR(1));
184 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
185 &add($H1,$t27,$H1) &FR($t27);
186 &st($R,&QWPw(5,$rp));
187 &add($H1,$H2,$R);
188
189 &mov("zero",$H1);
190 &add($R,$r28,$R);
191 &mov("zero",$H2);
192 &muh($a[3],$b[3],($r31)=&NR(1));
193 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
194 &add($R,$r29,$R);
195 &add($H1,$t28,$H1) &FR($t28);
196 ############
197 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
198 &add($R,$r30,$R);
199 &add($H1,$t29,$H1) &FR($t29);
200 ############
201 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
202 &add($H1,$t30,$H1) &FR($t30);
203 &st($R,&QWPw(6,$rp));
204 &add($H1,$H2,$R);
205
206 &add($R,$r31,$R); &FR($r31);
207 &st($R,&QWPw(7,$rp));
208
209 &FR($R,$H1,$H2);
210 &function_end($name);
211
212 &fin_pool;
213 }
214
2151;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.works.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c8.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/sqr.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c4.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c8.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha/sub.pl b/src/lib/libssl/src/crypto/bn/asm/alpha/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libssl/src/crypto/bn/asm/bn-alpha.pl b/src/lib/libssl/src/crypto/bn/asm/bn-alpha.pl
new file mode 100644
index 0000000000..302edf2376
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/bn-alpha.pl
@@ -0,0 +1,571 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6$d=&data();
7$d =~ s/CC/0/g;
8$d =~ s/R1/1/g;
9$d =~ s/R2/2/g;
10$d =~ s/R3/3/g;
11$d =~ s/R4/4/g;
12$d =~ s/L1/5/g;
13$d =~ s/L2/6/g;
14$d =~ s/L3/7/g;
15$d =~ s/L4/8/g;
16$d =~ s/O1/22/g;
17$d =~ s/O2/23/g;
18$d =~ s/O3/24/g;
19$d =~ s/O4/25/g;
20$d =~ s/A1/20/g;
21$d =~ s/A2/21/g;
22$d =~ s/A3/27/g;
23$d =~ s/A4/28/g;
24if (0){
25}
26
27print $d;
28
29sub data
30 {
31 local($data)=<<'EOF';
32
33 # DEC Alpha assember
34 # The bn_div_words is actually gcc output but the other parts are hand done.
35 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
36 # bn_div_words.
37 # I've gone back and re-done most of routines.
38 # The key thing to remeber for the 164 CPU is that while a
39 # multiply operation takes 8 cycles, another one can only be issued
40 # after 4 cycles have elapsed. I've done modification to help
41 # improve this. Also, normally, a ld instruction will not be available
42 # for about 3 cycles.
43 .file 1 "bn_asm.c"
44 .set noat
45gcc2_compiled.:
46__gnu_compiled_c:
47 .text
48 .align 3
49 .globl bn_mul_add_words
50 .ent bn_mul_add_words
51bn_mul_add_words:
52bn_mul_add_words..ng:
53 .frame $30,0,$26,0
54 .prologue 0
55 .align 5
56 subq $18,4,$18
57 bis $31,$31,$CC
58 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
59 ldq $A1,0($17) # 1 1
60 ldq $R1,0($16) # 1 1
61 .align 3
62$42:
63 mulq $A1,$19,$L1 # 1 2 1 ######
64 ldq $A2,8($17) # 2 1
65 ldq $R2,8($16) # 2 1
66 umulh $A1,$19,$A1 # 1 2 ######
67 ldq $A3,16($17) # 3 1
68 ldq $R3,16($16) # 3 1
69 mulq $A2,$19,$L2 # 2 2 1 ######
70 ldq $A4,24($17) # 4 1
71 addq $R1,$L1,$R1 # 1 2 2
72 ldq $R4,24($16) # 4 1
73 umulh $A2,$19,$A2 # 2 2 ######
74 cmpult $R1,$L1,$O1 # 1 2 3 1
75 addq $A1,$O1,$A1 # 1 3 1
76 addq $R1,$CC,$R1 # 1 2 3 1
77 mulq $A3,$19,$L3 # 3 2 1 ######
78 cmpult $R1,$CC,$CC # 1 2 3 2
79 addq $R2,$L2,$R2 # 2 2 2
80 addq $A1,$CC,$CC # 1 3 2
81 cmpult $R2,$L2,$O2 # 2 2 3 1
82 addq $A2,$O2,$A2 # 2 3 1
83 umulh $A3,$19,$A3 # 3 2 ######
84 addq $R2,$CC,$R2 # 2 2 3 1
85 cmpult $R2,$CC,$CC # 2 2 3 2
86 subq $18,4,$18
87 mulq $A4,$19,$L4 # 4 2 1 ######
88 addq $A2,$CC,$CC # 2 3 2
89 addq $R3,$L3,$R3 # 3 2 2
90 addq $16,32,$16
91 cmpult $R3,$L3,$O3 # 3 2 3 1
92 stq $R1,-32($16) # 1 2 4
93 umulh $A4,$19,$A4 # 4 2 ######
94 addq $A3,$O3,$A3 # 3 3 1
95 addq $R3,$CC,$R3 # 3 2 3 1
96 stq $R2,-24($16) # 2 2 4
97 cmpult $R3,$CC,$CC # 3 2 3 2
98 stq $R3,-16($16) # 3 2 4
99 addq $R4,$L4,$R4 # 4 2 2
100 addq $A3,$CC,$CC # 3 3 2
101 cmpult $R4,$L4,$O4 # 4 2 3 1
102 addq $17,32,$17
103 addq $A4,$O4,$A4 # 4 3 1
104 addq $R4,$CC,$R4 # 4 2 3 1
105 cmpult $R4,$CC,$CC # 4 2 3 2
106 stq $R4,-8($16) # 4 2 4
107 addq $A4,$CC,$CC # 4 3 2
108 blt $18,$43
109
110 ldq $A1,0($17) # 1 1
111 ldq $R1,0($16) # 1 1
112
113 br $42
114
115 .align 4
116$45:
117 ldq $A1,0($17) # 4 1
118 ldq $R1,0($16) # 4 1
119 mulq $A1,$19,$L1 # 4 2 1
120 subq $18,1,$18
121 addq $16,8,$16
122 addq $17,8,$17
123 umulh $A1,$19,$A1 # 4 2
124 addq $R1,$L1,$R1 # 4 2 2
125 cmpult $R1,$L1,$O1 # 4 2 3 1
126 addq $A1,$O1,$A1 # 4 3 1
127 addq $R1,$CC,$R1 # 4 2 3 1
128 cmpult $R1,$CC,$CC # 4 2 3 2
129 addq $A1,$CC,$CC # 4 3 2
130 stq $R1,-8($16) # 4 2 4
131 bgt $18,$45
132 ret $31,($26),1 # else exit
133
134 .align 4
135$43:
136 addq $18,4,$18
137 bgt $18,$45 # goto tail code
138 ret $31,($26),1 # else exit
139
140 .end bn_mul_add_words
141 .align 3
142 .globl bn_mul_words
143 .ent bn_mul_words
144bn_mul_words:
145bn_mul_words..ng:
146 .frame $30,0,$26,0
147 .prologue 0
148 .align 5
149 subq $18,4,$18
150 bis $31,$31,$CC
151 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
152 ldq $A1,0($17) # 1 1
153 .align 3
154$142:
155
156 mulq $A1,$19,$L1 # 1 2 1 #####
157 ldq $A2,8($17) # 2 1
158 ldq $A3,16($17) # 3 1
159 umulh $A1,$19,$A1 # 1 2 #####
160 ldq $A4,24($17) # 4 1
161 mulq $A2,$19,$L2 # 2 2 1 #####
162 addq $L1,$CC,$L1 # 1 2 3 1
163 subq $18,4,$18
164 cmpult $L1,$CC,$CC # 1 2 3 2
165 umulh $A2,$19,$A2 # 2 2 #####
166 addq $A1,$CC,$CC # 1 3 2
167 addq $17,32,$17
168 addq $L2,$CC,$L2 # 2 2 3 1
169 mulq $A3,$19,$L3 # 3 2 1 #####
170 cmpult $L2,$CC,$CC # 2 2 3 2
171 addq $A2,$CC,$CC # 2 3 2
172 addq $16,32,$16
173 umulh $A3,$19,$A3 # 3 2 #####
174 stq $L1,-32($16) # 1 2 4
175 mulq $A4,$19,$L4 # 4 2 1 #####
176 addq $L3,$CC,$L3 # 3 2 3 1
177 stq $L2,-24($16) # 2 2 4
178 cmpult $L3,$CC,$CC # 3 2 3 2
179 umulh $A4,$19,$A4 # 4 2 #####
180 addq $A3,$CC,$CC # 3 3 2
181 stq $L3,-16($16) # 3 2 4
182 addq $L4,$CC,$L4 # 4 2 3 1
183 cmpult $L4,$CC,$CC # 4 2 3 2
184
185 addq $A4,$CC,$CC # 4 3 2
186
187 stq $L4,-8($16) # 4 2 4
188
189 blt $18,$143
190
191 ldq $A1,0($17) # 1 1
192
193 br $142
194
195 .align 4
196$145:
197 ldq $A1,0($17) # 4 1
198 mulq $A1,$19,$L1 # 4 2 1
199 subq $18,1,$18
200 umulh $A1,$19,$A1 # 4 2
201 addq $L1,$CC,$L1 # 4 2 3 1
202 addq $16,8,$16
203 cmpult $L1,$CC,$CC # 4 2 3 2
204 addq $17,8,$17
205 addq $A1,$CC,$CC # 4 3 2
206 stq $L1,-8($16) # 4 2 4
207
208 bgt $18,$145
209 ret $31,($26),1 # else exit
210
211 .align 4
212$143:
213 addq $18,4,$18
214 bgt $18,$145 # goto tail code
215 ret $31,($26),1 # else exit
216
217 .end bn_mul_words
218 .align 3
219 .globl bn_sqr_words
220 .ent bn_sqr_words
221bn_sqr_words:
222bn_sqr_words..ng:
223 .frame $30,0,$26,0
224 .prologue 0
225
226 subq $18,4,$18
227 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
228 ldq $A1,0($17) # 1 1
229 .align 3
230$542:
231 mulq $A1,$A1,$L1 ######
232 ldq $A2,8($17) # 1 1
233 subq $18,4
234 umulh $A1,$A1,$R1 ######
235 ldq $A3,16($17) # 1 1
236 mulq $A2,$A2,$L2 ######
237 ldq $A4,24($17) # 1 1
238 stq $L1,0($16) # r[0]
239 umulh $A2,$A2,$R2 ######
240 stq $R1,8($16) # r[1]
241 mulq $A3,$A3,$L3 ######
242 stq $L2,16($16) # r[0]
243 umulh $A3,$A3,$R3 ######
244 stq $R2,24($16) # r[1]
245 mulq $A4,$A4,$L4 ######
246 stq $L3,32($16) # r[0]
247 umulh $A4,$A4,$R4 ######
248 stq $R3,40($16) # r[1]
249
250 addq $16,64,$16
251 addq $17,32,$17
252 stq $L4,-16($16) # r[0]
253 stq $R4,-8($16) # r[1]
254
255 blt $18,$543
256 ldq $A1,0($17) # 1 1
257 br $542
258
259$442:
260 ldq $A1,0($17) # a[0]
261 mulq $A1,$A1,$L1 # a[0]*w low part r2
262 addq $16,16,$16
263 addq $17,8,$17
264 subq $18,1,$18
265 umulh $A1,$A1,$R1 # a[0]*w high part r3
266 stq $L1,-16($16) # r[0]
267 stq $R1,-8($16) # r[1]
268
269 bgt $18,$442
270 ret $31,($26),1 # else exit
271
272 .align 4
273$543:
274 addq $18,4,$18
275 bgt $18,$442 # goto tail code
276 ret $31,($26),1 # else exit
277 .end bn_sqr_words
278
279 .align 3
280 .globl bn_add_words
281 .ent bn_add_words
282bn_add_words:
283bn_add_words..ng:
284 .frame $30,0,$26,0
285 .prologue 0
286
287 subq $19,4,$19
288 bis $31,$31,$CC # carry = 0
289 blt $19,$900
290 ldq $L1,0($17) # a[0]
291 ldq $R1,0($18) # b[1]
292 .align 3
293$901:
294 addq $R1,$L1,$R1 # r=a+b;
295 ldq $L2,8($17) # a[1]
296 cmpult $R1,$L1,$O1 # did we overflow?
297 ldq $R2,8($18) # b[1]
298 addq $R1,$CC,$R1 # c+= overflow
299 ldq $L3,16($17) # a[2]
300 cmpult $R1,$CC,$CC # overflow?
301 ldq $R3,16($18) # b[2]
302 addq $CC,$O1,$CC
303 ldq $L4,24($17) # a[3]
304 addq $R2,$L2,$R2 # r=a+b;
305 ldq $R4,24($18) # b[3]
306 cmpult $R2,$L2,$O2 # did we overflow?
307 addq $R3,$L3,$R3 # r=a+b;
308 addq $R2,$CC,$R2 # c+= overflow
309 cmpult $R3,$L3,$O3 # did we overflow?
310 cmpult $R2,$CC,$CC # overflow?
311 addq $R4,$L4,$R4 # r=a+b;
312 addq $CC,$O2,$CC
313 cmpult $R4,$L4,$O4 # did we overflow?
314 addq $R3,$CC,$R3 # c+= overflow
315 stq $R1,0($16) # r[0]=c
316 cmpult $R3,$CC,$CC # overflow?
317 stq $R2,8($16) # r[1]=c
318 addq $CC,$O3,$CC
319 stq $R3,16($16) # r[2]=c
320 addq $R4,$CC,$R4 # c+= overflow
321 subq $19,4,$19 # loop--
322 cmpult $R4,$CC,$CC # overflow?
323 addq $17,32,$17 # a++
324 addq $CC,$O4,$CC
325 stq $R4,24($16) # r[3]=c
326 addq $18,32,$18 # b++
327 addq $16,32,$16 # r++
328
329 blt $19,$900
330 ldq $L1,0($17) # a[0]
331 ldq $R1,0($18) # b[1]
332 br $901
333 .align 4
334$945:
335 ldq $L1,0($17) # a[0]
336 ldq $R1,0($18) # b[1]
337 addq $R1,$L1,$R1 # r=a+b;
338 subq $19,1,$19 # loop--
339 addq $R1,$CC,$R1 # c+= overflow
340 addq $17,8,$17 # a++
341 cmpult $R1,$L1,$O1 # did we overflow?
342 cmpult $R1,$CC,$CC # overflow?
343 addq $18,8,$18 # b++
344 stq $R1,0($16) # r[0]=c
345 addq $CC,$O1,$CC
346 addq $16,8,$16 # r++
347
348 bgt $19,$945
349 ret $31,($26),1 # else exit
350
351$900:
352 addq $19,4,$19
353 bgt $19,$945 # goto tail code
354 ret $31,($26),1 # else exit
355 .end bn_add_words
356
357 .align 3
358 .globl bn_sub_words
359 .ent bn_sub_words
360bn_sub_words:
361bn_sub_words..ng:
362 .frame $30,0,$26,0
363 .prologue 0
364
365 subq $19,4,$19
366 bis $31,$31,$CC # carry = 0
367 br $800
368 blt $19,$800
369 ldq $L1,0($17) # a[0]
370 ldq $R1,0($18) # b[1]
371 .align 3
372$801:
373 addq $R1,$L1,$R1 # r=a+b;
374 ldq $L2,8($17) # a[1]
375 cmpult $R1,$L1,$O1 # did we overflow?
376 ldq $R2,8($18) # b[1]
377 addq $R1,$CC,$R1 # c+= overflow
378 ldq $L3,16($17) # a[2]
379 cmpult $R1,$CC,$CC # overflow?
380 ldq $R3,16($18) # b[2]
381 addq $CC,$O1,$CC
382 ldq $L4,24($17) # a[3]
383 addq $R2,$L2,$R2 # r=a+b;
384 ldq $R4,24($18) # b[3]
385 cmpult $R2,$L2,$O2 # did we overflow?
386 addq $R3,$L3,$R3 # r=a+b;
387 addq $R2,$CC,$R2 # c+= overflow
388 cmpult $R3,$L3,$O3 # did we overflow?
389 cmpult $R2,$CC,$CC # overflow?
390 addq $R4,$L4,$R4 # r=a+b;
391 addq $CC,$O2,$CC
392 cmpult $R4,$L4,$O4 # did we overflow?
393 addq $R3,$CC,$R3 # c+= overflow
394 stq $R1,0($16) # r[0]=c
395 cmpult $R3,$CC,$CC # overflow?
396 stq $R2,8($16) # r[1]=c
397 addq $CC,$O3,$CC
398 stq $R3,16($16) # r[2]=c
399 addq $R4,$CC,$R4 # c+= overflow
400 subq $19,4,$19 # loop--
401 cmpult $R4,$CC,$CC # overflow?
402 addq $17,32,$17 # a++
403 addq $CC,$O4,$CC
404 stq $R4,24($16) # r[3]=c
405 addq $18,32,$18 # b++
406 addq $16,32,$16 # r++
407
408 blt $19,$800
409 ldq $L1,0($17) # a[0]
410 ldq $R1,0($18) # b[1]
411 br $801
412 .align 4
413$845:
414 ldq $L1,0($17) # a[0]
415 ldq $R1,0($18) # b[1]
416 cmpult $L1,$R1,$O1 # will we borrow?
417 subq $L1,$R1,$R1 # r=a-b;
418 subq $19,1,$19 # loop--
419 cmpult $R1,$CC,$O2 # will we borrow?
420 subq $R1,$CC,$R1 # c+= overflow
421 addq $17,8,$17 # a++
422 addq $18,8,$18 # b++
423 stq $R1,0($16) # r[0]=c
424 addq $O2,$O1,$CC
425 addq $16,8,$16 # r++
426
427 bgt $19,$845
428 ret $31,($26),1 # else exit
429
430$800:
431 addq $19,4,$19
432 bgt $19,$845 # goto tail code
433 ret $31,($26),1 # else exit
434 .end bn_sub_words
435
436 #
437 # What follows was taken directly from the C compiler with a few
438 # hacks to redo the lables.
439 #
440.text
441 .align 3
442 .globl bn_div_words
443 .ent bn_div_words
444bn_div_words:
445 ldgp $29,0($27)
446bn_div_words..ng:
447 lda $30,-48($30)
448 .frame $30,48,$26,0
449 stq $26,0($30)
450 stq $9,8($30)
451 stq $10,16($30)
452 stq $11,24($30)
453 stq $12,32($30)
454 stq $13,40($30)
455 .mask 0x4003e00,-48
456 .prologue 1
457 bis $16,$16,$9
458 bis $17,$17,$10
459 bis $18,$18,$11
460 bis $31,$31,$13
461 bis $31,2,$12
462 bne $11,$119
463 lda $0,-1
464 br $31,$136
465 .align 4
466$119:
467 bis $11,$11,$16
468 jsr $26,BN_num_bits_word
469 ldgp $29,0($26)
470 subq $0,64,$1
471 beq $1,$120
472 bis $31,1,$1
473 sll $1,$0,$1
474 cmpule $9,$1,$1
475 bne $1,$120
476 # lda $16,_IO_stderr_
477 # lda $17,$C32
478 # bis $0,$0,$18
479 # jsr $26,fprintf
480 # ldgp $29,0($26)
481 jsr $26,abort
482 ldgp $29,0($26)
483 .align 4
484$120:
485 bis $31,64,$3
486 cmpult $9,$11,$2
487 subq $3,$0,$1
488 addl $1,$31,$0
489 subq $9,$11,$1
490 cmoveq $2,$1,$9
491 beq $0,$122
492 zapnot $0,15,$2
493 subq $3,$0,$1
494 sll $11,$2,$11
495 sll $9,$2,$3
496 srl $10,$1,$1
497 sll $10,$2,$10
498 bis $3,$1,$9
499$122:
500 srl $11,32,$5
501 zapnot $11,15,$6
502 lda $7,-1
503 .align 5
504$123:
505 srl $9,32,$1
506 subq $1,$5,$1
507 bne $1,$126
508 zapnot $7,15,$27
509 br $31,$127
510 .align 4
511$126:
512 bis $9,$9,$24
513 bis $5,$5,$25
514 divqu $24,$25,$27
515$127:
516 srl $10,32,$4
517 .align 5
518$128:
519 mulq $27,$5,$1
520 subq $9,$1,$3
521 zapnot $3,240,$1
522 bne $1,$129
523 mulq $6,$27,$2
524 sll $3,32,$1
525 addq $1,$4,$1
526 cmpule $2,$1,$2
527 bne $2,$129
528 subq $27,1,$27
529 br $31,$128
530 .align 4
531$129:
532 mulq $27,$6,$1
533 mulq $27,$5,$4
534 srl $1,32,$3
535 sll $1,32,$1
536 addq $4,$3,$4
537 cmpult $10,$1,$2
538 subq $10,$1,$10
539 addq $2,$4,$2
540 cmpult $9,$2,$1
541 bis $2,$2,$4
542 beq $1,$134
543 addq $9,$11,$9
544 subq $27,1,$27
545$134:
546 subl $12,1,$12
547 subq $9,$4,$9
548 beq $12,$124
549 sll $27,32,$13
550 sll $9,32,$2
551 srl $10,32,$1
552 sll $10,32,$10
553 bis $2,$1,$9
554 br $31,$123
555 .align 4
556$124:
557 bis $13,$27,$0
558$136:
559 ldq $26,0($30)
560 ldq $9,8($30)
561 ldq $10,16($30)
562 ldq $11,24($30)
563 ldq $12,32($30)
564 ldq $13,40($30)
565 addq $30,48,$30
566 ret $31,($26),1
567 .end bn_div_words
568EOF
569 return($data);
570 }
571
diff --git a/src/lib/libssl/src/crypto/bn/asm/ca.pl b/src/lib/libssl/src/crypto/bn/asm/ca.pl
new file mode 100644
index 0000000000..c1ce67a6b4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/ca.pl
@@ -0,0 +1,33 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8require "alpha/mul_add.pl";
9require "alpha/mul.pl";
10require "alpha/sqr.pl";
11require "alpha/add.pl";
12require "alpha/sub.pl";
13require "alpha/mul_c8.pl";
14require "alpha/mul_c4.pl";
15require "alpha/sqr_c4.pl";
16require "alpha/sqr_c8.pl";
17require "alpha/div.pl";
18
19&asm_init($ARGV[0],$0);
20
21&bn_mul_words("bn_mul_words");
22&bn_sqr_words("bn_sqr_words");
23&bn_mul_add_words("bn_mul_add_words");
24&bn_add_words("bn_add_words");
25&bn_sub_words("bn_sub_words");
26&bn_div_words("bn_div_words");
27&bn_mul_comba8("bn_mul_comba8");
28&bn_mul_comba4("bn_mul_comba4");
29&bn_sqr_comba4("bn_sqr_comba4");
30&bn_sqr_comba8("bn_sqr_comba8");
31
32&asm_finish();
33
diff --git a/src/lib/libssl/src/crypto/bn/asm/co-586.pl b/src/lib/libssl/src/crypto/bn/asm/co-586.pl
new file mode 100644
index 0000000000..5d962cb957
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/co-586.pl
@@ -0,0 +1,286 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_comba("bn_mul_comba8",8);
9&bn_mul_comba("bn_mul_comba4",4);
10&bn_sqr_comba("bn_sqr_comba8",8);
11&bn_sqr_comba("bn_sqr_comba4",4);
12
13&asm_finish();
14
15sub mul_add_c
16 {
17 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
18
19 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
20 # words, and 1 if load return value
21
22 &comment("mul a[$ai]*b[$bi]");
23
24 # "eax" and "edx" will always be pre-loaded.
25 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
26 # &mov("edx",&DWP($bi*4,$b,"",0));
27
28 &mul("edx");
29 &add($c0,"eax");
30 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
31 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
32 ###
33 &adc($c1,"edx");
34 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
35 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
36 ###
37 &adc($c2,0);
38 # is pos > 1, it means it is the last loop
39 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
40 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
41 }
42
43sub sqr_add_c
44 {
45 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
46
47 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
48 # words, and 1 if load return value
49
50 &comment("sqr a[$ai]*a[$bi]");
51
52 # "eax" and "edx" will always be pre-loaded.
53 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
54 # &mov("edx",&DWP($bi*4,$b,"",0));
55
56 if ($ai == $bi)
57 { &mul("eax");}
58 else
59 { &mul("edx");}
60 &add($c0,"eax");
61 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
62 ###
63 &adc($c1,"edx");
64 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
65 ###
66 &adc($c2,0);
67 # is pos > 1, it means it is the last loop
68 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
69 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
70 }
71
72sub sqr_add_c2
73 {
74 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
75
76 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
77 # words, and 1 if load return value
78
79 &comment("sqr a[$ai]*a[$bi]");
80
81 # "eax" and "edx" will always be pre-loaded.
82 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
83 # &mov("edx",&DWP($bi*4,$a,"",0));
84
85 if ($ai == $bi)
86 { &mul("eax");}
87 else
88 { &mul("edx");}
89 &add("eax","eax");
90 ###
91 &adc("edx","edx");
92 ###
93 &adc($c2,0);
94 &add($c0,"eax");
95 &adc($c1,"edx");
96 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
97 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
98 &adc($c2,0);
99 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
100 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
101 ###
102 }
103
104sub bn_mul_comba
105 {
106 local($name,$num)=@_;
107 local($a,$b,$c0,$c1,$c2);
108 local($i,$as,$ae,$bs,$be,$ai,$bi);
109 local($tot,$end);
110
111 &function_begin_B($name,"");
112
113 $c0="ebx";
114 $c1="ecx";
115 $c2="ebp";
116 $a="esi";
117 $b="edi";
118
119 $as=0;
120 $ae=0;
121 $bs=0;
122 $be=0;
123 $tot=$num+$num-1;
124
125 &push("esi");
126 &mov($a,&wparam(1));
127 &push("edi");
128 &mov($b,&wparam(2));
129 &push("ebp");
130 &push("ebx");
131
132 &xor($c0,$c0);
133 &mov("eax",&DWP(0,$a,"",0)); # load the first word
134 &xor($c1,$c1);
135 &mov("edx",&DWP(0,$b,"",0)); # load the first second
136
137 for ($i=0; $i<$tot; $i++)
138 {
139 $ai=$as;
140 $bi=$bs;
141 $end=$be+1;
142
143 &comment("################## Calculate word $i");
144
145 for ($j=$bs; $j<$end; $j++)
146 {
147 &xor($c2,$c2) if ($j == $bs);
148 if (($j+1) == $end)
149 {
150 $v=1;
151 $v=2 if (($i+1) == $tot);
152 }
153 else
154 { $v=0; }
155 if (($j+1) != $end)
156 {
157 $na=($ai-1);
158 $nb=($bi+1);
159 }
160 else
161 {
162 $na=$as+($i < ($num-1));
163 $nb=$bs+($i >= ($num-1));
164 }
165#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
166 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
167 if ($v)
168 {
169 &comment("saved r[$i]");
170 # &mov("eax",&wparam(0));
171 # &mov(&DWP($i*4,"eax","",0),$c0);
172 ($c0,$c1,$c2)=($c1,$c2,$c0);
173 }
174 $ai--;
175 $bi++;
176 }
177 $as++ if ($i < ($num-1));
178 $ae++ if ($i >= ($num-1));
179
180 $bs++ if ($i >= ($num-1));
181 $be++ if ($i < ($num-1));
182 }
183 &comment("save r[$i]");
184 # &mov("eax",&wparam(0));
185 &mov(&DWP($i*4,"eax","",0),$c0);
186
187 &pop("ebx");
188 &pop("ebp");
189 &pop("edi");
190 &pop("esi");
191 &ret();
192 &function_end_B($name);
193 }
194
195sub bn_sqr_comba
196 {
197 local($name,$num)=@_;
198 local($r,$a,$c0,$c1,$c2)=@_;
199 local($i,$as,$ae,$bs,$be,$ai,$bi);
200 local($b,$tot,$end,$half);
201
202 &function_begin_B($name,"");
203
204 $c0="ebx";
205 $c1="ecx";
206 $c2="ebp";
207 $a="esi";
208 $r="edi";
209
210 &push("esi");
211 &push("edi");
212 &push("ebp");
213 &push("ebx");
214 &mov($r,&wparam(0));
215 &mov($a,&wparam(1));
216 &xor($c0,$c0);
217 &xor($c1,$c1);
218 &mov("eax",&DWP(0,$a,"",0)); # load the first word
219
220 $as=0;
221 $ae=0;
222 $bs=0;
223 $be=0;
224 $tot=$num+$num-1;
225
226 for ($i=0; $i<$tot; $i++)
227 {
228 $ai=$as;
229 $bi=$bs;
230 $end=$be+1;
231
232 &comment("############### Calculate word $i");
233 for ($j=$bs; $j<$end; $j++)
234 {
235 &xor($c2,$c2) if ($j == $bs);
236 if (($ai-1) < ($bi+1))
237 {
238 $v=1;
239 $v=2 if ($i+1) == $tot;
240 }
241 else
242 { $v=0; }
243 if (!$v)
244 {
245 $na=$ai-1;
246 $nb=$bi+1;
247 }
248 else
249 {
250 $na=$as+($i < ($num-1));
251 $nb=$bs+($i >= ($num-1));
252 }
253 if ($ai == $bi)
254 {
255 &sqr_add_c($r,$a,$ai,$bi,
256 $c0,$c1,$c2,$v,$i,$na,$nb);
257 }
258 else
259 {
260 &sqr_add_c2($r,$a,$ai,$bi,
261 $c0,$c1,$c2,$v,$i,$na,$nb);
262 }
263 if ($v)
264 {
265 &comment("saved r[$i]");
266 #&mov(&DWP($i*4,$r,"",0),$c0);
267 ($c0,$c1,$c2)=($c1,$c2,$c0);
268 last;
269 }
270 $ai--;
271 $bi++;
272 }
273 $as++ if ($i < ($num-1));
274 $ae++ if ($i >= ($num-1));
275
276 $bs++ if ($i >= ($num-1));
277 $be++ if ($i < ($num-1));
278 }
279 &mov(&DWP($i*4,$r,"",0),$c0);
280 &pop("ebx");
281 &pop("ebp");
282 &pop("edi");
283 &pop("esi");
284 &ret();
285 &function_end_B($name);
286 }
diff --git a/src/lib/libssl/src/crypto/bn/asm/co-alpha.pl b/src/lib/libssl/src/crypto/bn/asm/co-alpha.pl
new file mode 100644
index 0000000000..67dad3e3d5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/co-alpha.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8
9&asm_init($ARGV[0],$0);
10
11print &bn_sub_words("bn_sub_words");
12
13&asm_finish();
14
15sub bn_sub_words
16 {
17 local($name)=@_;
18 local($cc,$a,$b,$r);
19
20 $cc="r0";
21 $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13";
22 $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14";
23 $a2="r3"; $b2="r7"; $r2="r11";
24 $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15";
25
26 $rp=&wparam(0);
27 $ap=&wparam(1);
28 $bp=&wparam(2);
29 $count=&wparam(3);
30
31 &function_begin($name,"");
32
33 &comment("");
34 &sub($count,4,$count);
35 &mov("zero",$cc);
36 &blt($count,&label("finish"));
37
38 &ld($a0,&QWPw(0,$ap));
39 &ld($b0,&QWPw(0,$bp));
40
41##########################################################
42 &set_label("loop");
43
44 &ld($a1,&QWPw(1,$ap));
45 &cmpult($a0,$b0,$tmp); # will we borrow?
46 &ld($b1,&QWPw(1,$bp));
47 &sub($a0,$b0,$a0); # do the subtract
48 &ld($a2,&QWPw(2,$ap));
49 &cmpult($a0,$cc,$b0); # will we borrow?
50 &ld($b2,&QWPw(2,$bp));
51 &sub($a0,$cc,$a0); # will we borrow?
52 &ld($a3,&QWPw(3,$ap));
53 &add($b0,$tmp,$cc); # add the borrows
54
55 &cmpult($a1,$b1,$t1); # will we borrow?
56 &sub($a1,$b1,$a1); # do the subtract
57 &ld($b3,&QWPw(3,$bp));
58 &cmpult($a1,$cc,$b1); # will we borrow?
59 &sub($a1,$cc,$a1); # will we borrow?
60 &add($b1,$t1,$cc); # add the borrows
61
62 &cmpult($a2,$b2,$tmp); # will we borrow?
63 &sub($a2,$b2,$a2); # do the subtract
64 &st($a0,&QWPw(0,$rp)); # save
65 &cmpult($a2,$cc,$b2); # will we borrow?
66 &sub($a2,$cc,$a2); # will we borrow?
67 &add($b2,$tmp,$cc); # add the borrows
68
69 &cmpult($a3,$b3,$t3); # will we borrow?
70 &sub($a3,$b3,$a3); # do the subtract
71 &st($a1,&QWPw(1,$rp)); # save
72 &cmpult($a3,$cc,$b3); # will we borrow?
73 &sub($a3,$cc,$a3); # will we borrow?
74 &add($b3,$t3,$cc); # add the borrows
75
76 &st($a2,&QWPw(2,$rp)); # save
77 &sub($count,4,$count); # count-=4
78 &st($a3,&QWPw(3,$rp)); # save
79 &add($ap,4*$QWS,$ap); # count+=4
80 &add($bp,4*$QWS,$bp); # count+=4
81 &add($rp,4*$QWS,$rp); # count+=4
82
83 &blt($count,&label("finish"));
84 &ld($a0,&QWPw(0,$ap));
85 &ld($b0,&QWPw(0,$bp));
86 &br(&label("loop"));
87##################################################
88 # Do the last 0..3 words
89
90 &set_label("last_loop");
91
92 &ld($a0,&QWPw(0,$ap)); # get a
93 &ld($b0,&QWPw(0,$bp)); # get b
94 &cmpult($a0,$b0,$tmp); # will we borrow?
95 &sub($a0,$b0,$a0); # do the subtract
96 &cmpult($a0,$cc,$b0); # will we borrow?
97 &sub($a0,$cc,$a0); # will we borrow?
98 &st($a0,&QWPw(0,$rp)); # save
99 &add($b0,$tmp,$cc); # add the borrows
100
101 &add($ap,$QWS,$ap);
102 &add($bp,$QWS,$bp);
103 &add($rp,$QWS,$rp);
104 &sub($count,1,$count);
105 &bgt($count,&label("last_loop"));
106 &function_end_A($name);
107
108######################################################
109 &set_label("finish");
110 &add($count,4,$count);
111 &bgt($count,&label("last_loop"));
112
113 &set_label("end");
114 &function_end($name);
115 }
116
diff --git a/src/lib/libssl/src/crypto/bn/asm/ia64.S b/src/lib/libssl/src/crypto/bn/asm/ia64.S
new file mode 100644
index 0000000000..ae56066310
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/ia64.S
@@ -0,0 +1,1498 @@
1.explicit
2.text
3.ident "ia64.S, Version 1.1"
4.ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
5
6//
7// ====================================================================
8// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
9// project.
10//
11// Rights for redistribution and usage in source and binary forms are
12// granted according to the OpenSSL license. Warranty of any kind is
13// disclaimed.
14// ====================================================================
15//
16
17// Q. How much faster does it get?
18// A. Here is the output from 'openssl speed rsa dsa' for vanilla
19// 0.9.6a compiled with gcc version 2.96 20000731 (Red Hat
20// Linux 7.1 2.96-81):
21//
22// sign verify sign/s verify/s
23// rsa 512 bits 0.0036s 0.0003s 275.3 2999.2
24// rsa 1024 bits 0.0203s 0.0011s 49.3 894.1
25// rsa 2048 bits 0.1331s 0.0040s 7.5 250.9
26// rsa 4096 bits 0.9270s 0.0147s 1.1 68.1
27// sign verify sign/s verify/s
28// dsa 512 bits 0.0035s 0.0043s 288.3 234.8
29// dsa 1024 bits 0.0111s 0.0135s 90.0 74.2
30//
31// And here is similar output but for this assembler
32// implementation:-)
33//
34// sign verify sign/s verify/s
35// rsa 512 bits 0.0021s 0.0001s 549.4 9638.5
36// rsa 1024 bits 0.0055s 0.0002s 183.8 4481.1
37// rsa 2048 bits 0.0244s 0.0006s 41.4 1726.3
38// rsa 4096 bits 0.1295s 0.0018s 7.7 561.5
39// sign verify sign/s verify/s
40// dsa 512 bits 0.0012s 0.0013s 891.9 756.6
41// dsa 1024 bits 0.0023s 0.0028s 440.4 376.2
42//
43// Yes, you may argue that it's not fair comparison as it's
44// possible to craft the C implementation with BN_UMULT_HIGH
45// inline assembler macro. But of course! Here is the output
46// with the macro:
47//
48// sign verify sign/s verify/s
49// rsa 512 bits 0.0020s 0.0002s 495.0 6561.0
50// rsa 1024 bits 0.0086s 0.0004s 116.2 2235.7
51// rsa 2048 bits 0.0519s 0.0015s 19.3 667.3
52// rsa 4096 bits 0.3464s 0.0053s 2.9 187.7
53// sign verify sign/s verify/s
54// dsa 512 bits 0.0016s 0.0020s 613.1 510.5
55// dsa 1024 bits 0.0045s 0.0054s 221.0 183.9
56//
57// My code is still way faster, huh:-) And I believe that even
58// higher performance can be achieved. Note that as keys get
59// longer, performance gain is larger. Why? According to the
60// profiler there is another player in the field, namely
61// BN_from_montgomery consuming larger and larger portion of CPU
62// time as keysize decreases. I therefore consider putting effort
63// to assembler implementation of the following routine:
64//
65// void bn_mul_add_mont (BN_ULONG *rp,BN_ULONG *np,int nl,BN_ULONG n0)
66// {
67// int i,j;
68// BN_ULONG v;
69//
70// for (i=0; i<nl; i++)
71// {
72// v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
73// nrp++;
74// rp++;
75// if (((nrp[-1]+=v)&BN_MASK2) < v)
76// for (j=0; ((++nrp[j])&BN_MASK2) == 0; j++) ;
77// }
78// }
79//
80// It might as well be beneficial to implement even combaX
81// variants, as it appears as it can literally unleash the
82// performance (see comment section to bn_mul_comba8 below).
83//
84// And finally for your reference the output for 0.9.6a compiled
85// with SGIcc version 0.01.0-12 (keep in mind that for the moment
86// of this writing it's not possible to convince SGIcc to use
87// BN_UMULT_HIGH inline assembler macro, yet the code is fast,
88// i.e. for a compiler generated one:-):
89//
90// sign verify sign/s verify/s
91// rsa 512 bits 0.0022s 0.0002s 452.7 5894.3
92// rsa 1024 bits 0.0097s 0.0005s 102.7 2002.9
93// rsa 2048 bits 0.0578s 0.0017s 17.3 600.2
94// rsa 4096 bits 0.3838s 0.0061s 2.6 164.5
95// sign verify sign/s verify/s
96// dsa 512 bits 0.0018s 0.0022s 547.3 459.6
97// dsa 1024 bits 0.0051s 0.0062s 196.6 161.3
98//
99// Oh! Benchmarks were performed on 733MHz Lion-class Itanium
100// system running Redhat Linux 7.1 (very special thanks to Ray
101// McCaffity of Williams Communications for providing an account).
102//
103// Q. What's the heck with 'rum 1<<5' at the end of every function?
104// A. Well, by clearing the "upper FP registers written" bit of the
105// User Mask I want to excuse the kernel from preserving upper
106// (f32-f128) FP register bank over process context switch, thus
107// minimizing bus bandwidth consumption during the switch (i.e.
108// after PKI opration completes and the program is off doing
109// something else like bulk symmetric encryption). Having said
110// this, I also want to point out that it might be good idea
111// to compile the whole toolkit (as well as majority of the
112// programs for that matter) with -mfixed-range=f32-f127 command
113// line option. No, it doesn't prevent the compiler from writing
114// to upper bank, but at least discourages to do so. If you don't
115// like the idea you have the option to compile the module with
116// -Drum=nop.m in command line.
117//
118
119#if 1
120//
121// bn_[add|sub]_words routines.
122//
123// Loops are spinning in 2*(n+5) ticks on Itanuim (provided that the
124// data reside in L1 cache, i.e. 2 ticks away). It's possible to
125// compress the epilogue and get down to 2*n+6, but at the cost of
126// scalability (the neat feature of this implementation is that it
127// shall automagically spin in n+5 on "wider" IA-64 implementations:-)
128// I consider that the epilogue is short enough as it is to trade tiny
129// performance loss on Itanium for scalability.
130//
131// BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
132//
133.global bn_add_words#
134.proc bn_add_words#
135.align 64
136.skip 32 // makes the loop body aligned at 64-byte boundary
137bn_add_words:
138 .prologue
139 .fframe 0
140 .save ar.pfs,r2
141{ .mii; alloc r2=ar.pfs,4,12,0,16
142 cmp4.le p6,p0=r35,r0 };;
143{ .mfb; mov r8=r0 // return value
144(p6) br.ret.spnt.many b0 };;
145
146 .save ar.lc,r3
147{ .mib; sub r10=r35,r0,1
148 mov r3=ar.lc
149 brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16
150 }
151 .body
152{ .mib; mov r14=r32 // rp
153 mov r9=pr };;
154{ .mii; mov r15=r33 // ap
155 mov ar.lc=r10
156 mov ar.ec=6 }
157{ .mib; mov r16=r34 // bp
158 mov pr.rot=1<<16 };;
159
160.L_bn_add_words_ctop:
161{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
162 (p18) add r39=r37,r34
163 (p19) cmp.ltu.unc p56,p0=r40,r38 }
164{ .mfb; (p0) nop.m 0x0
165 (p0) nop.f 0x0
166 (p0) nop.b 0x0 }
167{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
168 (p58) cmp.eq.or p57,p0=-1,r41 // (p20)
169 (p58) add r41=1,r41 } // (p20)
170{ .mfb; (p21) st8 [r14]=r42,8 // *(rp++)=r
171 (p0) nop.f 0x0
172 br.ctop.sptk .L_bn_add_words_ctop };;
173.L_bn_add_words_cend:
174
175{ .mii;
176(p59) add r8=1,r8 // return value
177 mov pr=r9,-1
178 mov ar.lc=r3 }
179{ .mbb; nop.b 0x0
180 br.ret.sptk.many b0 };;
181.endp bn_add_words#
182
183//
184// BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
185//
186.global bn_sub_words#
187.proc bn_sub_words#
188.align 64
189.skip 32 // makes the loop body aligned at 64-byte boundary
190bn_sub_words:
191 .prologue
192 .fframe 0
193 .save ar.pfs,r2
194{ .mii; alloc r2=ar.pfs,4,12,0,16
195 cmp4.le p6,p0=r35,r0 };;
196{ .mfb; mov r8=r0 // return value
197(p6) br.ret.spnt.many b0 };;
198
199 .save ar.lc,r3
200{ .mib; sub r10=r35,r0,1
201 mov r3=ar.lc
202 brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16
203 }
204 .body
205{ .mib; mov r14=r32 // rp
206 mov r9=pr };;
207{ .mii; mov r15=r33 // ap
208 mov ar.lc=r10
209 mov ar.ec=6 }
210{ .mib; mov r16=r34 // bp
211 mov pr.rot=1<<16 };;
212
213.L_bn_sub_words_ctop:
214{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
215 (p18) sub r39=r37,r34
216 (p19) cmp.gtu.unc p56,p0=r40,r38 }
217{ .mfb; (p0) nop.m 0x0
218 (p0) nop.f 0x0
219 (p0) nop.b 0x0 }
220{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
221 (p58) cmp.eq.or p57,p0=0,r41 // (p20)
222 (p58) add r41=-1,r41 } // (p20)
223{ .mbb; (p21) st8 [r14]=r42,8 // *(rp++)=r
224 (p0) nop.b 0x0
225 br.ctop.sptk .L_bn_sub_words_ctop };;
226.L_bn_sub_words_cend:
227
228{ .mii;
229(p59) add r8=1,r8 // return value
230 mov pr=r9,-1
231 mov ar.lc=r3 }
232{ .mbb; nop.b 0x0
233 br.ret.sptk.many b0 };;
234.endp bn_sub_words#
235#endif
236
237#if 0
238#define XMA_TEMPTATION
239#endif
240
241#if 1
242//
243// BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
244//
245.global bn_mul_words#
246.proc bn_mul_words#
247.align 64
248.skip 32 // makes the loop body aligned at 64-byte boundary
249bn_mul_words:
250 .prologue
251 .fframe 0
252 .save ar.pfs,r2
253#ifdef XMA_TEMPTATION
254{ .mfi; alloc r2=ar.pfs,4,0,0,0 };;
255#else
256{ .mfi; alloc r2=ar.pfs,4,4,0,8 };;
257#endif
258{ .mib; mov r8=r0 // return value
259 cmp4.le p6,p0=r34,r0
260(p6) br.ret.spnt.many b0 };;
261
262 .save ar.lc,r3
263{ .mii; sub r10=r34,r0,1
264 mov r3=ar.lc
265 mov r9=pr };;
266
267 .body
268{ .mib; setf.sig f8=r35 // w
269 mov pr.rot=0x400001<<16
270 // ------^----- serves as (p48) at first (p26)
271 brp.loop.imp .L_bn_mul_words_ctop,.L_bn_mul_words_cend-16
272 }
273
274#ifndef XMA_TEMPTATION
275
276{ .mii; mov r14=r32 // rp
277 mov r15=r33 // ap
278 mov ar.lc=r10 }
279{ .mii; mov r39=0 // serves as r33 at first (p26)
280 mov ar.ec=12 };;
281
282// This loop spins in 2*(n+11) ticks. It's scheduled for data in L2
283// cache (i.e. 9 ticks away) as floating point load/store instructions
284// bypass L1 cache and L2 latency is actually best-case scenario for
285// ldf8. The loop is not scalable and shall run in 2*(n+11) even on
286// "wider" IA-64 implementations. It's a trade-off here. n+22 loop
287// would give us ~5% in *overall* performance improvement on "wider"
288// IA-64, but would hurt Itanium for about same because of longer
289// epilogue. As it's a matter of few percents in either case I've
290// chosen to trade the scalability for development time (you can see
291// this very instruction sequence in bn_mul_add_words loop which in
292// turn is scalable).
293.L_bn_mul_words_ctop:
294{ .mfi; (p25) getf.sig r36=f49 // low
295 (p21) xmpy.lu f45=f37,f8
296 (p27) cmp.ltu p52,p48=r39,r38 }
297{ .mfi; (p16) ldf8 f32=[r15],8
298 (p21) xmpy.hu f38=f37,f8
299 (p0) nop.i 0x0 };;
300{ .mii; (p26) getf.sig r32=f43 // high
301 .pred.rel "mutex",p48,p52
302 (p48) add r38=r37,r33 // (p26)
303 (p52) add r38=r37,r33,1 } // (p26)
304{ .mfb; (p27) st8 [r14]=r39,8
305 (p0) nop.f 0x0
306 br.ctop.sptk .L_bn_mul_words_ctop };;
307.L_bn_mul_words_cend:
308
309{ .mii; nop.m 0x0
310.pred.rel "mutex",p49,p53
311(p49) add r8=r34,r0
312(p53) add r8=r34,r0,1 }
313{ .mfb; nop.m 0x0
314 nop.f 0x0
315 nop.b 0x0 }
316
317#else // XMA_TEMPTATION
318
319 setf.sig f37=r0 // serves as carry at (p18) tick
320 mov ar.lc=r10
321 mov ar.ec=5;;
322
323// Most of you examining this code very likely wonder why in the name
324// of Intel the following loop is commented out? Indeed, it looks so
325// neat that you find it hard to believe that it's something wrong
326// with it, right? The catch is that every iteration depends on the
327// result from previous one and the latter isn't available instantly.
328// The loop therefore spins at the latency of xma minus 1, or in other
329// words at 6*(n+4) ticks:-( Compare to the "production" loop above
330// that runs in 2*(n+11) where the low latency problem is worked around
331// by moving the dependency to one-tick latent interger ALU. Note that
332// "distance" between ldf8 and xma is not latency of ldf8, but the
333// *difference* between xma and ldf8 latencies.
334.L_bn_mul_words_ctop:
335{ .mfi; (p16) ldf8 f32=[r33],8
336 (p18) xma.hu f38=f34,f8,f39 }
337{ .mfb; (p20) stf8 [r32]=f37,8
338 (p18) xma.lu f35=f34,f8,f39
339 br.ctop.sptk .L_bn_mul_words_ctop };;
340.L_bn_mul_words_cend:
341
342 getf.sig r8=f41 // the return value
343
344#endif // XMA_TEMPTATION
345
346{ .mii; nop.m 0x0
347 mov pr=r9,-1
348 mov ar.lc=r3 }
349{ .mfb; rum 1<<5 // clear um.mfh
350 nop.f 0x0
351 br.ret.sptk.many b0 };;
352.endp bn_mul_words#
353#endif
354
355#if 1
356//
357// BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
358//
359.global bn_mul_add_words#
360.proc bn_mul_add_words#
361.align 64
362//.skip 0 // makes the loop split at 64-byte boundary
363bn_mul_add_words:
364 .prologue
365 .fframe 0
366 .save ar.pfs,r2
367{ .mii; alloc r2=ar.pfs,4,12,0,16
368 cmp4.le p6,p0=r34,r0 };;
369{ .mfb; mov r8=r0 // return value
370(p6) br.ret.spnt.many b0 };;
371
372 .save ar.lc,r3
373{ .mii; sub r10=r34,r0,1
374 mov r3=ar.lc
375 mov r9=pr };;
376
377 .body
378{ .mib; setf.sig f8=r35 // w
379 mov pr.rot=0x400001<<16
380 // ------^----- serves as (p48) at first (p26)
381 brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16
382 }
383{ .mii; mov r14=r32 // rp
384 mov r15=r33 // ap
385 mov ar.lc=r10 }
386{ .mii; mov r39=0 // serves as r33 at first (p26)
387 mov r18=r32 // rp copy
388 mov ar.ec=14 };;
389
390// This loop spins in 3*(n+13) ticks on Itanium and should spin in
391// 2*(n+13) on "wider" IA-64 implementations (to be verified with new
392// µ-architecture manuals as they become available). As usual it's
393// possible to compress the epilogue, down to 10 in this case, at the
394// cost of scalability. Compressed (and therefore non-scalable) loop
395// running at 3*(n+10) would buy you ~10% on Itanium but take ~35%
396// from "wider" IA-64 so let it be scalable! Special attention was
397// paid for having the loop body split at 64-byte boundary. ld8 is
398// scheduled for L1 cache as the data is more than likely there.
399// Indeed, bn_mul_words has put it there a moment ago:-)
400.L_bn_mul_add_words_ctop:
401{ .mfi; (p25) getf.sig r36=f49 // low
402 (p21) xmpy.lu f45=f37,f8
403 (p27) cmp.ltu p52,p48=r39,r38 }
404{ .mfi; (p16) ldf8 f32=[r15],8
405 (p21) xmpy.hu f38=f37,f8
406 (p27) add r43=r43,r39 };;
407{ .mii; (p26) getf.sig r32=f43 // high
408 .pred.rel "mutex",p48,p52
409 (p48) add r38=r37,r33 // (p26)
410 (p52) add r38=r37,r33,1 } // (p26)
411{ .mfb; (p27) cmp.ltu.unc p56,p0=r43,r39
412 (p0) nop.f 0x0
413 (p0) nop.b 0x0 }
414{ .mii; (p26) ld8 r42=[r18],8
415 (p58) cmp.eq.or p57,p0=-1,r44
416 (p58) add r44=1,r44 }
417{ .mfb; (p29) st8 [r14]=r45,8
418 (p0) nop.f 0x0
419 br.ctop.sptk .L_bn_mul_add_words_ctop};;
420.L_bn_mul_add_words_cend:
421
422{ .mii; nop.m 0x0
423.pred.rel "mutex",p51,p55
424(p51) add r8=r36,r0
425(p55) add r8=r36,r0,1 }
426{ .mfb; nop.m 0x0
427 nop.f 0x0
428 nop.b 0x0 };;
429{ .mii;
430(p59) add r8=1,r8
431 mov pr=r9,-1
432 mov ar.lc=r3 }
433{ .mfb; rum 1<<5 // clear um.mfh
434 nop.f 0x0
435 br.ret.sptk.many b0 };;
436.endp bn_mul_add_words#
437#endif
438
439#if 1
440//
441// void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
442//
443.global bn_sqr_words#
444.proc bn_sqr_words#
445.align 64
446.skip 32 // makes the loop body aligned at 64-byte boundary
447bn_sqr_words:
448 .prologue
449 .fframe 0
450 .save ar.pfs,r2
451{ .mii; alloc r2=ar.pfs,3,0,0,0
452 sxt4 r34=r34 };;
453{ .mii; cmp.le p6,p0=r34,r0
454 mov r8=r0 } // return value
455{ .mfb; nop.f 0x0
456(p6) br.ret.spnt.many b0 };;
457
458 .save ar.lc,r3
459{ .mii; sub r10=r34,r0,1
460 mov r3=ar.lc
461 mov r9=pr };;
462
463 .body
464{ .mib;
465 mov pr.rot=1<<16
466 brp.loop.imp .L_bn_sqr_words_ctop,.L_bn_sqr_words_cend-16
467 }
468{ .mii; add r34=8,r32
469 mov ar.lc=r10
470 mov ar.ec=18 };;
471
472// 2*(n+17) on Itanium, (n+17) on "wider" IA-64 implementations. It's
473// possible to compress the epilogue (I'm getting tired to write this
474// comment over and over) and get down to 2*n+16 at the cost of
475// scalability. The decision will very likely be reconsidered after the
476// benchmark program is profiled. I.e. if perfomance gain on Itanium
477// will appear larger than loss on "wider" IA-64, then the loop should
478// be explicitely split and the epilogue compressed.
479.L_bn_sqr_words_ctop:
480{ .mfi; (p16) ldf8 f32=[r33],8
481 (p25) xmpy.lu f42=f41,f41
482 (p0) nop.i 0x0 }
483{ .mib; (p33) stf8 [r32]=f50,16
484 (p0) nop.i 0x0
485 (p0) nop.b 0x0 }
486{ .mfi; (p0) nop.m 0x0
487 (p25) xmpy.hu f52=f41,f41
488 (p0) nop.i 0x0 }
489{ .mib; (p33) stf8 [r34]=f60,16
490 (p0) nop.i 0x0
491 br.ctop.sptk .L_bn_sqr_words_ctop };;
492.L_bn_sqr_words_cend:
493
494{ .mii; nop.m 0x0
495 mov pr=r9,-1
496 mov ar.lc=r3 }
497{ .mfb; rum 1<<5 // clear um.mfh
498 nop.f 0x0
499 br.ret.sptk.many b0 };;
500.endp bn_sqr_words#
501#endif
502
503#if 1
504// Apparently we win nothing by implementing special bn_sqr_comba8.
505// Yes, it is possible to reduce the number of multiplications by
506// almost factor of two, but then the amount of additions would
507// increase by factor of two (as we would have to perform those
508// otherwise performed by xma ourselves). Normally we would trade
509// anyway as multiplications are way more expensive, but not this
510// time... Multiplication kernel is fully pipelined and as we drain
511// one 128-bit multiplication result per clock cycle multiplications
512// are effectively as inexpensive as additions. Special implementation
513// might become of interest for "wider" IA-64 implementation as you'll
514// be able to get through the multiplication phase faster (there won't
515// be any stall issues as discussed in the commentary section below and
516// you therefore will be able to employ all 4 FP units)... But these
517// Itanium days it's simply too hard to justify the effort so I just
518// drop down to bn_mul_comba8 code:-)
519//
520// void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
521//
522.global bn_sqr_comba8#
523.proc bn_sqr_comba8#
524.align 64
525bn_sqr_comba8:
526 .prologue
527 .fframe 0
528 .save ar.pfs,r2
529{ .mii; alloc r2=ar.pfs,2,1,0,0
530 mov r34=r33
531 add r14=8,r33 };;
532 .body
533{ .mii; add r17=8,r34
534 add r15=16,r33
535 add r18=16,r34 }
536{ .mfb; add r16=24,r33
537 br .L_cheat_entry_point8 };;
538.endp bn_sqr_comba8#
539#endif
540
541#if 1
542// I've estimated this routine to run in ~120 ticks, but in reality
543// (i.e. according to ar.itc) it takes ~160 ticks. Are those extra
544// cycles consumed for instructions fetch? Or did I misinterpret some
545// clause in Itanium µ-architecture manual? Comments are welcomed and
546// highly appreciated.
547//
548// However! It should be noted that even 160 ticks is darn good result
549// as it's over 10 (yes, ten, spelled as t-e-n) times faster than the
550// C version (compiled with gcc with inline assembler). I really
551// kicked compiler's butt here, didn't I? Yeah! This brings us to the
552// following statement. It's damn shame that this routine isn't called
553// very often nowadays! According to the profiler most CPU time is
554// consumed by bn_mul_add_words called from BN_from_montgomery. In
555// order to estimate what we're missing, I've compared the performance
556// of this routine against "traditional" implementation, i.e. against
557// following routine:
558//
559// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
560// { r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
561// r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
562// r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
563// r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
564// r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
565// r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
566// r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
567// r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
568// }
569//
570// The one below is over 8 times faster than the one above:-( Even
571// more reasons to "combafy" bn_mul_add_mont...
572//
573// And yes, this routine really made me wish there were an optimizing
574// assembler! It also feels like it deserves a dedication.
575//
576// To my wife for being there and to my kids...
577//
578// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
579//
580#define carry1 r14
581#define carry2 r15
582#define carry3 r34
583.global bn_mul_comba8#
584.proc bn_mul_comba8#
585.align 64
586bn_mul_comba8:
587 .prologue
588 .fframe 0
589 .save ar.pfs,r2
590{ .mii; alloc r2=ar.pfs,3,0,0,0
591 add r14=8,r33
592 add r17=8,r34 }
593 .body
594{ .mii; add r15=16,r33
595 add r18=16,r34
596 add r16=24,r33 }
597.L_cheat_entry_point8:
598{ .mmi; add r19=24,r34
599
600 ldf8 f32=[r33],32 };;
601
602{ .mmi; ldf8 f120=[r34],32
603 ldf8 f121=[r17],32 }
604{ .mmi; ldf8 f122=[r18],32
605 ldf8 f123=[r19],32 };;
606{ .mmi; ldf8 f124=[r34]
607 ldf8 f125=[r17] }
608{ .mmi; ldf8 f126=[r18]
609 ldf8 f127=[r19] }
610
611{ .mmi; ldf8 f33=[r14],32
612 ldf8 f34=[r15],32 }
613{ .mmi; ldf8 f35=[r16],32;;
614 ldf8 f36=[r33] }
615{ .mmi; ldf8 f37=[r14]
616 ldf8 f38=[r15] }
617{ .mfi; ldf8 f39=[r16]
618// -------\ Entering multiplier's heaven /-------
619// ------------\ /------------
620// -----------------\ /-----------------
621// ----------------------\/----------------------
622 xma.hu f41=f32,f120,f0 }
623{ .mfi; xma.lu f40=f32,f120,f0 };; // (*)
624{ .mfi; xma.hu f51=f32,f121,f0 }
625{ .mfi; xma.lu f50=f32,f121,f0 };;
626{ .mfi; xma.hu f61=f32,f122,f0 }
627{ .mfi; xma.lu f60=f32,f122,f0 };;
628{ .mfi; xma.hu f71=f32,f123,f0 }
629{ .mfi; xma.lu f70=f32,f123,f0 };;
630{ .mfi; xma.hu f81=f32,f124,f0 }
631{ .mfi; xma.lu f80=f32,f124,f0 };;
632{ .mfi; xma.hu f91=f32,f125,f0 }
633{ .mfi; xma.lu f90=f32,f125,f0 };;
634{ .mfi; xma.hu f101=f32,f126,f0 }
635{ .mfi; xma.lu f100=f32,f126,f0 };;
636{ .mfi; xma.hu f111=f32,f127,f0 }
637{ .mfi; xma.lu f110=f32,f127,f0 };;//
638// (*) You can argue that splitting at every second bundle would
639// prevent "wider" IA-64 implementations from achieving the peak
640// performance. Well, not really... The catch is that if you
641// intend to keep 4 FP units busy by splitting at every fourth
642// bundle and thus perform these 16 multiplications in 4 ticks,
643// the first bundle *below* would stall because the result from
644// the first xma bundle *above* won't be available for another 3
645// ticks (if not more, being an optimist, I assume that "wider"
646// implementation will have same latency:-). This stall will hold
647// you back and the performance would be as if every second bundle
648// were split *anyway*...
649{ .mfi; getf.sig r16=f40
650 xma.hu f42=f33,f120,f41
651 add r33=8,r32 }
652{ .mfi; xma.lu f41=f33,f120,f41 };;
653{ .mfi; getf.sig r24=f50
654 xma.hu f52=f33,f121,f51 }
655{ .mfi; xma.lu f51=f33,f121,f51 };;
656{ .mfi; st8 [r32]=r16,16
657 xma.hu f62=f33,f122,f61 }
658{ .mfi; xma.lu f61=f33,f122,f61 };;
659{ .mfi; xma.hu f72=f33,f123,f71 }
660{ .mfi; xma.lu f71=f33,f123,f71 };;
661{ .mfi; xma.hu f82=f33,f124,f81 }
662{ .mfi; xma.lu f81=f33,f124,f81 };;
663{ .mfi; xma.hu f92=f33,f125,f91 }
664{ .mfi; xma.lu f91=f33,f125,f91 };;
665{ .mfi; xma.hu f102=f33,f126,f101 }
666{ .mfi; xma.lu f101=f33,f126,f101 };;
667{ .mfi; xma.hu f112=f33,f127,f111 }
668{ .mfi; xma.lu f111=f33,f127,f111 };;//
669//-------------------------------------------------//
670{ .mfi; getf.sig r25=f41
671 xma.hu f43=f34,f120,f42 }
672{ .mfi; xma.lu f42=f34,f120,f42 };;
673{ .mfi; getf.sig r16=f60
674 xma.hu f53=f34,f121,f52 }
675{ .mfi; xma.lu f52=f34,f121,f52 };;
676{ .mfi; getf.sig r17=f51
677 xma.hu f63=f34,f122,f62
678 add r25=r25,r24 }
679{ .mfi; xma.lu f62=f34,f122,f62
680 mov carry1=0 };;
681{ .mfi; cmp.ltu p6,p0=r25,r24
682 xma.hu f73=f34,f123,f72 }
683{ .mfi; xma.lu f72=f34,f123,f72 };;
684{ .mfi; st8 [r33]=r25,16
685 xma.hu f83=f34,f124,f82
686(p6) add carry1=1,carry1 }
687{ .mfi; xma.lu f82=f34,f124,f82 };;
688{ .mfi; xma.hu f93=f34,f125,f92 }
689{ .mfi; xma.lu f92=f34,f125,f92 };;
690{ .mfi; xma.hu f103=f34,f126,f102 }
691{ .mfi; xma.lu f102=f34,f126,f102 };;
692{ .mfi; xma.hu f113=f34,f127,f112 }
693{ .mfi; xma.lu f112=f34,f127,f112 };;//
694//-------------------------------------------------//
695{ .mfi; getf.sig r18=f42
696 xma.hu f44=f35,f120,f43
697 add r17=r17,r16 }
698{ .mfi; xma.lu f43=f35,f120,f43 };;
699{ .mfi; getf.sig r24=f70
700 xma.hu f54=f35,f121,f53 }
701{ .mfi; mov carry2=0
702 xma.lu f53=f35,f121,f53 };;
703{ .mfi; getf.sig r25=f61
704 xma.hu f64=f35,f122,f63
705 cmp.ltu p7,p0=r17,r16 }
706{ .mfi; add r18=r18,r17
707 xma.lu f63=f35,f122,f63 };;
708{ .mfi; getf.sig r26=f52
709 xma.hu f74=f35,f123,f73
710(p7) add carry2=1,carry2 }
711{ .mfi; cmp.ltu p7,p0=r18,r17
712 xma.lu f73=f35,f123,f73
713 add r18=r18,carry1 };;
714{ .mfi;
715 xma.hu f84=f35,f124,f83
716(p7) add carry2=1,carry2 }
717{ .mfi; cmp.ltu p7,p0=r18,carry1
718 xma.lu f83=f35,f124,f83 };;
719{ .mfi; st8 [r32]=r18,16
720 xma.hu f94=f35,f125,f93
721(p7) add carry2=1,carry2 }
722{ .mfi; xma.lu f93=f35,f125,f93 };;
723{ .mfi; xma.hu f104=f35,f126,f103 }
724{ .mfi; xma.lu f103=f35,f126,f103 };;
725{ .mfi; xma.hu f114=f35,f127,f113 }
726{ .mfi; mov carry1=0
727 xma.lu f113=f35,f127,f113
728 add r25=r25,r24 };;//
729//-------------------------------------------------//
730{ .mfi; getf.sig r27=f43
731 xma.hu f45=f36,f120,f44
732 cmp.ltu p6,p0=r25,r24 }
733{ .mfi; xma.lu f44=f36,f120,f44
734 add r26=r26,r25 };;
735{ .mfi; getf.sig r16=f80
736 xma.hu f55=f36,f121,f54
737(p6) add carry1=1,carry1 }
738{ .mfi; xma.lu f54=f36,f121,f54 };;
739{ .mfi; getf.sig r17=f71
740 xma.hu f65=f36,f122,f64
741 cmp.ltu p6,p0=r26,r25 }
742{ .mfi; xma.lu f64=f36,f122,f64
743 add r27=r27,r26 };;
744{ .mfi; getf.sig r18=f62
745 xma.hu f75=f36,f123,f74
746(p6) add carry1=1,carry1 }
747{ .mfi; cmp.ltu p6,p0=r27,r26
748 xma.lu f74=f36,f123,f74
749 add r27=r27,carry2 };;
750{ .mfi; getf.sig r19=f53
751 xma.hu f85=f36,f124,f84
752(p6) add carry1=1,carry1 }
753{ .mfi; xma.lu f84=f36,f124,f84
754 cmp.ltu p6,p0=r27,carry2 };;
755{ .mfi; st8 [r33]=r27,16
756 xma.hu f95=f36,f125,f94
757(p6) add carry1=1,carry1 }
758{ .mfi; xma.lu f94=f36,f125,f94 };;
759{ .mfi; xma.hu f105=f36,f126,f104 }
760{ .mfi; mov carry2=0
761 xma.lu f104=f36,f126,f104
762 add r17=r17,r16 };;
763{ .mfi; xma.hu f115=f36,f127,f114
764 cmp.ltu p7,p0=r17,r16 }
765{ .mfi; xma.lu f114=f36,f127,f114
766 add r18=r18,r17 };;//
767//-------------------------------------------------//
768{ .mfi; getf.sig r20=f44
769 xma.hu f46=f37,f120,f45
770(p7) add carry2=1,carry2 }
771{ .mfi; cmp.ltu p7,p0=r18,r17
772 xma.lu f45=f37,f120,f45
773 add r19=r19,r18 };;
774{ .mfi; getf.sig r24=f90
775 xma.hu f56=f37,f121,f55 }
776{ .mfi; xma.lu f55=f37,f121,f55 };;
777{ .mfi; getf.sig r25=f81
778 xma.hu f66=f37,f122,f65
779(p7) add carry2=1,carry2 }
780{ .mfi; cmp.ltu p7,p0=r19,r18
781 xma.lu f65=f37,f122,f65
782 add r20=r20,r19 };;
783{ .mfi; getf.sig r26=f72
784 xma.hu f76=f37,f123,f75
785(p7) add carry2=1,carry2 }
786{ .mfi; cmp.ltu p7,p0=r20,r19
787 xma.lu f75=f37,f123,f75
788 add r20=r20,carry1 };;
789{ .mfi; getf.sig r27=f63
790 xma.hu f86=f37,f124,f85
791(p7) add carry2=1,carry2 }
792{ .mfi; xma.lu f85=f37,f124,f85
793 cmp.ltu p7,p0=r20,carry1 };;
794{ .mfi; getf.sig r28=f54
795 xma.hu f96=f37,f125,f95
796(p7) add carry2=1,carry2 }
797{ .mfi; st8 [r32]=r20,16
798 xma.lu f95=f37,f125,f95 };;
799{ .mfi; xma.hu f106=f37,f126,f105 }
800{ .mfi; mov carry1=0
801 xma.lu f105=f37,f126,f105
802 add r25=r25,r24 };;
803{ .mfi; xma.hu f116=f37,f127,f115
804 cmp.ltu p6,p0=r25,r24 }
805{ .mfi; xma.lu f115=f37,f127,f115
806 add r26=r26,r25 };;//
807//-------------------------------------------------//
808{ .mfi; getf.sig r29=f45
809 xma.hu f47=f38,f120,f46
810(p6) add carry1=1,carry1 }
811{ .mfi; cmp.ltu p6,p0=r26,r25
812 xma.lu f46=f38,f120,f46
813 add r27=r27,r26 };;
814{ .mfi; getf.sig r16=f100
815 xma.hu f57=f38,f121,f56
816(p6) add carry1=1,carry1 }
817{ .mfi; cmp.ltu p6,p0=r27,r26
818 xma.lu f56=f38,f121,f56
819 add r28=r28,r27 };;
820{ .mfi; getf.sig r17=f91
821 xma.hu f67=f38,f122,f66
822(p6) add carry1=1,carry1 }
823{ .mfi; cmp.ltu p6,p0=r28,r27
824 xma.lu f66=f38,f122,f66
825 add r29=r29,r28 };;
826{ .mfi; getf.sig r18=f82
827 xma.hu f77=f38,f123,f76
828(p6) add carry1=1,carry1 }
829{ .mfi; cmp.ltu p6,p0=r29,r28
830 xma.lu f76=f38,f123,f76
831 add r29=r29,carry2 };;
832{ .mfi; getf.sig r19=f73
833 xma.hu f87=f38,f124,f86
834(p6) add carry1=1,carry1 }
835{ .mfi; xma.lu f86=f38,f124,f86
836 cmp.ltu p6,p0=r29,carry2 };;
837{ .mfi; getf.sig r20=f64
838 xma.hu f97=f38,f125,f96
839(p6) add carry1=1,carry1 }
840{ .mfi; st8 [r33]=r29,16
841 xma.lu f96=f38,f125,f96 };;
842{ .mfi; getf.sig r21=f55
843 xma.hu f107=f38,f126,f106 }
844{ .mfi; mov carry2=0
845 xma.lu f106=f38,f126,f106
846 add r17=r17,r16 };;
847{ .mfi; xma.hu f117=f38,f127,f116
848 cmp.ltu p7,p0=r17,r16 }
849{ .mfi; xma.lu f116=f38,f127,f116
850 add r18=r18,r17 };;//
851//-------------------------------------------------//
852{ .mfi; getf.sig r22=f46
853 xma.hu f48=f39,f120,f47
854(p7) add carry2=1,carry2 }
855{ .mfi; cmp.ltu p7,p0=r18,r17
856 xma.lu f47=f39,f120,f47
857 add r19=r19,r18 };;
858{ .mfi; getf.sig r24=f110
859 xma.hu f58=f39,f121,f57
860(p7) add carry2=1,carry2 }
861{ .mfi; cmp.ltu p7,p0=r19,r18
862 xma.lu f57=f39,f121,f57
863 add r20=r20,r19 };;
864{ .mfi; getf.sig r25=f101
865 xma.hu f68=f39,f122,f67
866(p7) add carry2=1,carry2 }
867{ .mfi; cmp.ltu p7,p0=r20,r19
868 xma.lu f67=f39,f122,f67
869 add r21=r21,r20 };;
870{ .mfi; getf.sig r26=f92
871 xma.hu f78=f39,f123,f77
872(p7) add carry2=1,carry2 }
873{ .mfi; cmp.ltu p7,p0=r21,r20
874 xma.lu f77=f39,f123,f77
875 add r22=r22,r21 };;
876{ .mfi; getf.sig r27=f83
877 xma.hu f88=f39,f124,f87
878(p7) add carry2=1,carry2 }
879{ .mfi; cmp.ltu p7,p0=r22,r21
880 xma.lu f87=f39,f124,f87
881 add r22=r22,carry1 };;
882{ .mfi; getf.sig r28=f74
883 xma.hu f98=f39,f125,f97
884(p7) add carry2=1,carry2 }
885{ .mfi; xma.lu f97=f39,f125,f97
886 cmp.ltu p7,p0=r22,carry1 };;
887{ .mfi; getf.sig r29=f65
888 xma.hu f108=f39,f126,f107
889(p7) add carry2=1,carry2 }
890{ .mfi; st8 [r32]=r22,16
891 xma.lu f107=f39,f126,f107 };;
892{ .mfi; getf.sig r30=f56
893 xma.hu f118=f39,f127,f117 }
894{ .mfi; xma.lu f117=f39,f127,f117 };;//
895//-------------------------------------------------//
896// Leaving muliplier's heaven... Quite a ride, huh?
897
898{ .mii; getf.sig r31=f47
899 add r25=r25,r24
900 mov carry1=0 };;
901{ .mii; getf.sig r16=f111
902 cmp.ltu p6,p0=r25,r24
903 add r26=r26,r25 };;
904{ .mfb; getf.sig r17=f102 }
905{ .mii;
906(p6) add carry1=1,carry1
907 cmp.ltu p6,p0=r26,r25
908 add r27=r27,r26 };;
909{ .mfb; nop.m 0x0 }
910{ .mii;
911(p6) add carry1=1,carry1
912 cmp.ltu p6,p0=r27,r26
913 add r28=r28,r27 };;
914{ .mii; getf.sig r18=f93
915 add r17=r17,r16
916 mov carry3=0 }
917{ .mii;
918(p6) add carry1=1,carry1
919 cmp.ltu p6,p0=r28,r27
920 add r29=r29,r28 };;
921{ .mii; getf.sig r19=f84
922 cmp.ltu p7,p0=r17,r16 }
923{ .mii;
924(p6) add carry1=1,carry1
925 cmp.ltu p6,p0=r29,r28
926 add r30=r30,r29 };;
927{ .mii; getf.sig r20=f75
928 add r18=r18,r17 }
929{ .mii;
930(p6) add carry1=1,carry1
931 cmp.ltu p6,p0=r30,r29
932 add r31=r31,r30 };;
933{ .mfb; getf.sig r21=f66 }
934{ .mii; (p7) add carry3=1,carry3
935 cmp.ltu p7,p0=r18,r17
936 add r19=r19,r18 }
937{ .mfb; nop.m 0x0 }
938{ .mii;
939(p6) add carry1=1,carry1
940 cmp.ltu p6,p0=r31,r30
941 add r31=r31,carry2 };;
942{ .mfb; getf.sig r22=f57 }
943{ .mii; (p7) add carry3=1,carry3
944 cmp.ltu p7,p0=r19,r18
945 add r20=r20,r19 }
946{ .mfb; nop.m 0x0 }
947{ .mii;
948(p6) add carry1=1,carry1
949 cmp.ltu p6,p0=r31,carry2 };;
950{ .mfb; getf.sig r23=f48 }
951{ .mii; (p7) add carry3=1,carry3
952 cmp.ltu p7,p0=r20,r19
953 add r21=r21,r20 }
954{ .mii;
955(p6) add carry1=1,carry1 }
956{ .mfb; st8 [r33]=r31,16 };;
957
958{ .mfb; getf.sig r24=f112 }
959{ .mii; (p7) add carry3=1,carry3
960 cmp.ltu p7,p0=r21,r20
961 add r22=r22,r21 };;
962{ .mfb; getf.sig r25=f103 }
963{ .mii; (p7) add carry3=1,carry3
964 cmp.ltu p7,p0=r22,r21
965 add r23=r23,r22 };;
966{ .mfb; getf.sig r26=f94 }
967{ .mii; (p7) add carry3=1,carry3
968 cmp.ltu p7,p0=r23,r22
969 add r23=r23,carry1 };;
970{ .mfb; getf.sig r27=f85 }
971{ .mii; (p7) add carry3=1,carry3
972 cmp.ltu p7,p8=r23,carry1};;
973{ .mii; getf.sig r28=f76
974 add r25=r25,r24
975 mov carry1=0 }
976{ .mii; st8 [r32]=r23,16
977 (p7) add carry2=1,carry3
978 (p8) add carry2=0,carry3 };;
979
980{ .mfb; nop.m 0x0 }
981{ .mii; getf.sig r29=f67
982 cmp.ltu p6,p0=r25,r24
983 add r26=r26,r25 };;
984{ .mfb; getf.sig r30=f58 }
985{ .mii;
986(p6) add carry1=1,carry1
987 cmp.ltu p6,p0=r26,r25
988 add r27=r27,r26 };;
989{ .mfb; getf.sig r16=f113 }
990{ .mii;
991(p6) add carry1=1,carry1
992 cmp.ltu p6,p0=r27,r26
993 add r28=r28,r27 };;
994{ .mfb; getf.sig r17=f104 }
995{ .mii;
996(p6) add carry1=1,carry1
997 cmp.ltu p6,p0=r28,r27
998 add r29=r29,r28 };;
999{ .mfb; getf.sig r18=f95 }
1000{ .mii;
1001(p6) add carry1=1,carry1
1002 cmp.ltu p6,p0=r29,r28
1003 add r30=r30,r29 };;
1004{ .mii; getf.sig r19=f86
1005 add r17=r17,r16
1006 mov carry3=0 }
1007{ .mii;
1008(p6) add carry1=1,carry1
1009 cmp.ltu p6,p0=r30,r29
1010 add r30=r30,carry2 };;
1011{ .mii; getf.sig r20=f77
1012 cmp.ltu p7,p0=r17,r16
1013 add r18=r18,r17 }
1014{ .mii;
1015(p6) add carry1=1,carry1
1016 cmp.ltu p6,p0=r30,carry2 };;
1017{ .mfb; getf.sig r21=f68 }
1018{ .mii; st8 [r33]=r30,16
1019(p6) add carry1=1,carry1 };;
1020
1021{ .mfb; getf.sig r24=f114 }
1022{ .mii; (p7) add carry3=1,carry3
1023 cmp.ltu p7,p0=r18,r17
1024 add r19=r19,r18 };;
1025{ .mfb; getf.sig r25=f105 }
1026{ .mii; (p7) add carry3=1,carry3
1027 cmp.ltu p7,p0=r19,r18
1028 add r20=r20,r19 };;
1029{ .mfb; getf.sig r26=f96 }
1030{ .mii; (p7) add carry3=1,carry3
1031 cmp.ltu p7,p0=r20,r19
1032 add r21=r21,r20 };;
1033{ .mfb; getf.sig r27=f87 }
1034{ .mii; (p7) add carry3=1,carry3
1035 cmp.ltu p7,p0=r21,r20
1036 add r21=r21,carry1 };;
1037{ .mib; getf.sig r28=f78
1038 add r25=r25,r24 }
1039{ .mib; (p7) add carry3=1,carry3
1040 cmp.ltu p7,p8=r21,carry1};;
1041{ .mii; st8 [r32]=r21,16
1042 (p7) add carry2=1,carry3
1043 (p8) add carry2=0,carry3 }
1044
1045{ .mii; mov carry1=0
1046 cmp.ltu p6,p0=r25,r24
1047 add r26=r26,r25 };;
1048{ .mfb; getf.sig r16=f115 }
1049{ .mii;
1050(p6) add carry1=1,carry1
1051 cmp.ltu p6,p0=r26,r25
1052 add r27=r27,r26 };;
1053{ .mfb; getf.sig r17=f106 }
1054{ .mii;
1055(p6) add carry1=1,carry1
1056 cmp.ltu p6,p0=r27,r26
1057 add r28=r28,r27 };;
1058{ .mfb; getf.sig r18=f97 }
1059{ .mii;
1060(p6) add carry1=1,carry1
1061 cmp.ltu p6,p0=r28,r27
1062 add r28=r28,carry2 };;
1063{ .mib; getf.sig r19=f88
1064 add r17=r17,r16 }
1065{ .mib;
1066(p6) add carry1=1,carry1
1067 cmp.ltu p6,p0=r28,carry2 };;
1068{ .mii; st8 [r33]=r28,16
1069(p6) add carry1=1,carry1 }
1070
1071{ .mii; mov carry2=0
1072 cmp.ltu p7,p0=r17,r16
1073 add r18=r18,r17 };;
1074{ .mfb; getf.sig r24=f116 }
1075{ .mii; (p7) add carry2=1,carry2
1076 cmp.ltu p7,p0=r18,r17
1077 add r19=r19,r18 };;
1078{ .mfb; getf.sig r25=f107 }
1079{ .mii; (p7) add carry2=1,carry2
1080 cmp.ltu p7,p0=r19,r18
1081 add r19=r19,carry1 };;
1082{ .mfb; getf.sig r26=f98 }
1083{ .mii; (p7) add carry2=1,carry2
1084 cmp.ltu p7,p0=r19,carry1};;
1085{ .mii; st8 [r32]=r19,16
1086 (p7) add carry2=1,carry2 }
1087
1088{ .mfb; add r25=r25,r24 };;
1089
1090{ .mfb; getf.sig r16=f117 }
1091{ .mii; mov carry1=0
1092 cmp.ltu p6,p0=r25,r24
1093 add r26=r26,r25 };;
1094{ .mfb; getf.sig r17=f108 }
1095{ .mii;
1096(p6) add carry1=1,carry1
1097 cmp.ltu p6,p0=r26,r25
1098 add r26=r26,carry2 };;
1099{ .mfb; nop.m 0x0 }
1100{ .mii;
1101(p6) add carry1=1,carry1
1102 cmp.ltu p6,p0=r26,carry2 };;
1103{ .mii; st8 [r33]=r26,16
1104(p6) add carry1=1,carry1 }
1105
1106{ .mfb; add r17=r17,r16 };;
1107{ .mfb; getf.sig r24=f118 }
1108{ .mii; mov carry2=0
1109 cmp.ltu p7,p0=r17,r16
1110 add r17=r17,carry1 };;
1111{ .mii; (p7) add carry2=1,carry2
1112 cmp.ltu p7,p0=r17,carry1};;
1113{ .mii; st8 [r32]=r17
1114 (p7) add carry2=1,carry2 };;
1115{ .mfb; add r24=r24,carry2 };;
1116{ .mib; st8 [r33]=r24 }
1117
1118{ .mib; rum 1<<5 // clear um.mfh
1119 br.ret.sptk.many b0 };;
1120.endp bn_mul_comba8#
1121#undef carry3
1122#undef carry2
1123#undef carry1
1124#endif
1125
1126#if 1
1127// It's possible to make it faster (see comment to bn_sqr_comba8), but
1128// I reckon it doesn't worth the effort. Basically because the routine
1129// (actually both of them) practically never called... So I just play
1130// same trick as with bn_sqr_comba8.
1131//
1132// void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1133//
1134.global bn_sqr_comba4#
1135.proc bn_sqr_comba4#
1136.align 64
1137bn_sqr_comba4:
1138 .prologue
1139 .fframe 0
1140 .save ar.pfs,r2
1141{ .mii; alloc r2=ar.pfs,2,1,0,0
1142 mov r34=r33
1143 add r14=8,r33 };;
1144 .body
1145{ .mii; add r17=8,r34
1146 add r15=16,r33
1147 add r18=16,r34 }
1148{ .mfb; add r16=24,r33
1149 br .L_cheat_entry_point4 };;
1150.endp bn_sqr_comba4#
1151#endif
1152
1153#if 1
1154// Runs in ~115 cycles and ~4.5 times faster than C. Well, whatever...
1155//
1156// void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1157//
1158#define carry1 r14
1159#define carry2 r15
1160.global bn_mul_comba4#
1161.proc bn_mul_comba4#
1162.align 64
1163bn_mul_comba4:
1164 .prologue
1165 .fframe 0
1166 .save ar.pfs,r2
1167{ .mii; alloc r2=ar.pfs,3,0,0,0
1168 add r14=8,r33
1169 add r17=8,r34 }
1170 .body
1171{ .mii; add r15=16,r33
1172 add r18=16,r34
1173 add r16=24,r33 };;
1174.L_cheat_entry_point4:
1175{ .mmi; add r19=24,r34
1176
1177 ldf8 f32=[r33] }
1178
1179{ .mmi; ldf8 f120=[r34]
1180 ldf8 f121=[r17] };;
1181{ .mmi; ldf8 f122=[r18]
1182 ldf8 f123=[r19] }
1183
1184{ .mmi; ldf8 f33=[r14]
1185 ldf8 f34=[r15] }
1186{ .mfi; ldf8 f35=[r16]
1187
1188 xma.hu f41=f32,f120,f0 }
1189{ .mfi; xma.lu f40=f32,f120,f0 };;
1190{ .mfi; xma.hu f51=f32,f121,f0 }
1191{ .mfi; xma.lu f50=f32,f121,f0 };;
1192{ .mfi; xma.hu f61=f32,f122,f0 }
1193{ .mfi; xma.lu f60=f32,f122,f0 };;
1194{ .mfi; xma.hu f71=f32,f123,f0 }
1195{ .mfi; xma.lu f70=f32,f123,f0 };;//
1196// Major stall takes place here, and 3 more places below. Result from
1197// first xma is not available for another 3 ticks.
1198{ .mfi; getf.sig r16=f40
1199 xma.hu f42=f33,f120,f41
1200 add r33=8,r32 }
1201{ .mfi; xma.lu f41=f33,f120,f41 };;
1202{ .mfi; getf.sig r24=f50
1203 xma.hu f52=f33,f121,f51 }
1204{ .mfi; xma.lu f51=f33,f121,f51 };;
1205{ .mfi; st8 [r32]=r16,16
1206 xma.hu f62=f33,f122,f61 }
1207{ .mfi; xma.lu f61=f33,f122,f61 };;
1208{ .mfi; xma.hu f72=f33,f123,f71 }
1209{ .mfi; xma.lu f71=f33,f123,f71 };;//
1210//-------------------------------------------------//
1211{ .mfi; getf.sig r25=f41
1212 xma.hu f43=f34,f120,f42 }
1213{ .mfi; xma.lu f42=f34,f120,f42 };;
1214{ .mfi; getf.sig r16=f60
1215 xma.hu f53=f34,f121,f52 }
1216{ .mfi; xma.lu f52=f34,f121,f52 };;
1217{ .mfi; getf.sig r17=f51
1218 xma.hu f63=f34,f122,f62
1219 add r25=r25,r24 }
1220{ .mfi; mov carry1=0
1221 xma.lu f62=f34,f122,f62 };;
1222{ .mfi; st8 [r33]=r25,16
1223 xma.hu f73=f34,f123,f72
1224 cmp.ltu p6,p0=r25,r24 }
1225{ .mfi; xma.lu f72=f34,f123,f72 };;//
1226//-------------------------------------------------//
1227{ .mfi; getf.sig r18=f42
1228 xma.hu f44=f35,f120,f43
1229(p6) add carry1=1,carry1 }
1230{ .mfi; add r17=r17,r16
1231 xma.lu f43=f35,f120,f43
1232 mov carry2=0 };;
1233{ .mfi; getf.sig r24=f70
1234 xma.hu f54=f35,f121,f53
1235 cmp.ltu p7,p0=r17,r16 }
1236{ .mfi; xma.lu f53=f35,f121,f53 };;
1237{ .mfi; getf.sig r25=f61
1238 xma.hu f64=f35,f122,f63
1239 add r18=r18,r17 }
1240{ .mfi; xma.lu f63=f35,f122,f63
1241(p7) add carry2=1,carry2 };;
1242{ .mfi; getf.sig r26=f52
1243 xma.hu f74=f35,f123,f73
1244 cmp.ltu p7,p0=r18,r17 }
1245{ .mfi; xma.lu f73=f35,f123,f73
1246 add r18=r18,carry1 };;
1247//-------------------------------------------------//
1248{ .mii; st8 [r32]=r18,16
1249(p7) add carry2=1,carry2
1250 cmp.ltu p7,p0=r18,carry1 };;
1251
1252{ .mfi; getf.sig r27=f43 // last major stall
1253(p7) add carry2=1,carry2 };;
1254{ .mii; getf.sig r16=f71
1255 add r25=r25,r24
1256 mov carry1=0 };;
1257{ .mii; getf.sig r17=f62
1258 cmp.ltu p6,p0=r25,r24
1259 add r26=r26,r25 };;
1260{ .mii;
1261(p6) add carry1=1,carry1
1262 cmp.ltu p6,p0=r26,r25
1263 add r27=r27,r26 };;
1264{ .mii;
1265(p6) add carry1=1,carry1
1266 cmp.ltu p6,p0=r27,r26
1267 add r27=r27,carry2 };;
1268{ .mii; getf.sig r18=f53
1269(p6) add carry1=1,carry1
1270 cmp.ltu p6,p0=r27,carry2 };;
1271{ .mfi; st8 [r33]=r27,16
1272(p6) add carry1=1,carry1 }
1273
1274{ .mii; getf.sig r19=f44
1275 add r17=r17,r16
1276 mov carry2=0 };;
1277{ .mii; getf.sig r24=f72
1278 cmp.ltu p7,p0=r17,r16
1279 add r18=r18,r17 };;
1280{ .mii; (p7) add carry2=1,carry2
1281 cmp.ltu p7,p0=r18,r17
1282 add r19=r19,r18 };;
1283{ .mii; (p7) add carry2=1,carry2
1284 cmp.ltu p7,p0=r19,r18
1285 add r19=r19,carry1 };;
1286{ .mii; getf.sig r25=f63
1287 (p7) add carry2=1,carry2
1288 cmp.ltu p7,p0=r19,carry1};;
1289{ .mii; st8 [r32]=r19,16
1290 (p7) add carry2=1,carry2 }
1291
1292{ .mii; getf.sig r26=f54
1293 add r25=r25,r24
1294 mov carry1=0 };;
1295{ .mii; getf.sig r16=f73
1296 cmp.ltu p6,p0=r25,r24
1297 add r26=r26,r25 };;
1298{ .mii;
1299(p6) add carry1=1,carry1
1300 cmp.ltu p6,p0=r26,r25
1301 add r26=r26,carry2 };;
1302{ .mii; getf.sig r17=f64
1303(p6) add carry1=1,carry1
1304 cmp.ltu p6,p0=r26,carry2 };;
1305{ .mii; st8 [r33]=r26,16
1306(p6) add carry1=1,carry1 }
1307
1308{ .mii; getf.sig r24=f74
1309 add r17=r17,r16
1310 mov carry2=0 };;
1311{ .mii; cmp.ltu p7,p0=r17,r16
1312 add r17=r17,carry1 };;
1313
1314{ .mii; (p7) add carry2=1,carry2
1315 cmp.ltu p7,p0=r17,carry1};;
1316{ .mii; st8 [r32]=r17,16
1317 (p7) add carry2=1,carry2 };;
1318
1319{ .mii; add r24=r24,carry2 };;
1320{ .mii; st8 [r33]=r24 }
1321
1322{ .mib; rum 1<<5 // clear um.mfh
1323 br.ret.sptk.many b0 };;
1324.endp bn_mul_comba4#
1325#undef carry2
1326#undef carry1
1327#endif
1328
1329#if 1
1330//
1331// BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
1332//
1333// In the nutshell it's a port of my MIPS III/IV implementation.
1334//
1335#define AT r14
1336#define H r16
1337#define HH r20
1338#define L r17
1339#define D r18
1340#define DH r22
1341#define I r21
1342
1343#if 0
1344// Some preprocessors (most notably HP-UX) apper to be allergic to
1345// macros enclosed to parenthesis as these three will be.
1346#define cont p16
1347#define break p0 // p20
1348#define equ p24
1349#else
1350cont=p16
1351break=p0
1352equ=p24
1353#endif
1354
1355.global abort#
1356.global bn_div_words#
1357.proc bn_div_words#
1358.align 64
1359bn_div_words:
1360 .prologue
1361 .fframe 0
1362 .save ar.pfs,r2
1363 .save b0,r3
1364{ .mii; alloc r2=ar.pfs,3,5,0,8
1365 mov r3=b0
1366 mov r10=pr };;
1367{ .mmb; cmp.eq p6,p0=r34,r0
1368 mov r8=-1
1369(p6) br.ret.spnt.many b0 };;
1370
1371 .body
1372{ .mii; mov H=r32 // save h
1373 mov ar.ec=0 // don't rotate at exit
1374 mov pr.rot=0 }
1375{ .mii; mov L=r33 // save l
1376 mov r36=r0 };;
1377
1378.L_divw_shift: // -vv- note signed comparison
1379{ .mfi; (p0) cmp.lt p16,p0=r0,r34 // d
1380 (p0) shladd r33=r34,1,r0 }
1381{ .mfb; (p0) add r35=1,r36
1382 (p0) nop.f 0x0
1383(p16) br.wtop.dpnt .L_divw_shift };;
1384
1385{ .mii; mov D=r34
1386 shr.u DH=r34,32
1387 sub r35=64,r36 };;
1388{ .mii; setf.sig f7=DH
1389 shr.u AT=H,r35
1390 mov I=r36 };;
1391{ .mib; cmp.ne p6,p0=r0,AT
1392 shl H=H,r36
1393(p6) br.call.spnt.clr b0=abort };; // overflow, die...
1394
1395{ .mfi; fcvt.xuf.s1 f7=f7
1396 shr.u AT=L,r35 };;
1397{ .mii; shl L=L,r36
1398 or H=H,AT };;
1399
1400{ .mii; nop.m 0x0
1401 cmp.leu p6,p0=D,H;;
1402(p6) sub H=H,D }
1403
1404{ .mlx; setf.sig f14=D
1405 movl AT=0xffffffff };;
1406///////////////////////////////////////////////////////////
1407{ .mii; setf.sig f6=H
1408 shr.u HH=H,32;;
1409 cmp.eq p6,p7=HH,DH };;
1410{ .mfb;
1411(p6) setf.sig f8=AT
1412(p7) fcvt.xuf.s1 f6=f6
1413(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1414
1415{ .mfi; getf.sig r33=f8 // q
1416 xmpy.lu f9=f8,f14 }
1417{ .mfi; xmpy.hu f10=f8,f14
1418 shrp H=H,L,32 };;
1419
1420{ .mmi; getf.sig r35=f9 // tl
1421 getf.sig r31=f10 };; // th
1422
1423.L_divw_1st_iter:
1424{ .mii; (p0) add r32=-1,r33
1425 (p0) cmp.eq equ,cont=HH,r31 };;
1426{ .mii; (p0) cmp.ltu p8,p0=r35,D
1427 (p0) sub r34=r35,D
1428 (equ) cmp.leu break,cont=r35,H };;
1429{ .mib; (cont) cmp.leu cont,break=HH,r31
1430 (p8) add r31=-1,r31
1431(cont) br.wtop.spnt .L_divw_1st_iter };;
1432///////////////////////////////////////////////////////////
1433{ .mii; sub H=H,r35
1434 shl r8=r33,32
1435 shl L=L,32 };;
1436///////////////////////////////////////////////////////////
1437{ .mii; setf.sig f6=H
1438 shr.u HH=H,32;;
1439 cmp.eq p6,p7=HH,DH };;
1440{ .mfb;
1441(p6) setf.sig f8=AT
1442(p7) fcvt.xuf.s1 f6=f6
1443(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1444
1445{ .mfi; getf.sig r33=f8 // q
1446 xmpy.lu f9=f8,f14 }
1447{ .mfi; xmpy.hu f10=f8,f14
1448 shrp H=H,L,32 };;
1449
1450{ .mmi; getf.sig r35=f9 // tl
1451 getf.sig r31=f10 };; // th
1452
1453.L_divw_2nd_iter:
1454{ .mii; (p0) add r32=-1,r33
1455 (p0) cmp.eq equ,cont=HH,r31 };;
1456{ .mii; (p0) cmp.ltu p8,p0=r35,D
1457 (p0) sub r34=r35,D
1458 (equ) cmp.leu break,cont=r35,H };;
1459{ .mib; (cont) cmp.leu cont,break=HH,r31
1460 (p8) add r31=-1,r31
1461(cont) br.wtop.spnt .L_divw_2nd_iter };;
1462///////////////////////////////////////////////////////////
1463{ .mii; sub H=H,r35
1464 or r8=r8,r33
1465 mov ar.pfs=r2 };;
1466{ .mii; shr.u r9=H,I // remainder if anybody wants it
1467 mov pr=r10,-1 }
1468{ .mfb; br.ret.sptk.many b0 };;
1469
1470// Unsigned 64 by 32 (well, by 64 for the moment) bit integer division
1471// procedure.
1472//
1473// inputs: f6 = (double)a, f7 = (double)b
1474// output: f8 = (int)(a/b)
1475// clobbered: f8,f9,f10,f11,pred
1476pred=p15
1477// This procedure is essentially Intel code and therefore is
1478// copyrighted to Intel Corporation (I suppose...). It's sligtly
1479// modified for specific needs.
1480.align 32
1481.skip 16
1482.L_udiv64_32_b6:
1483 frcpa.s1 f8,pred=f6,f7;; // [0] y0 = 1 / b
1484
1485(pred) fnma.s1 f9=f7,f8,f1 // [5] e0 = 1 - b * y0
1486(pred) fmpy.s1 f10=f6,f8;; // [5] q0 = a * y0
1487(pred) fmpy.s1 f11=f9,f9 // [10] e1 = e0 * e0
1488(pred) fma.s1 f10=f9,f10,f10;; // [10] q1 = q0 + e0 * q0
1489(pred) fma.s1 f8=f9,f8,f8 //;; // [15] y1 = y0 + e0 * y0
1490(pred) fma.s1 f9=f11,f10,f10;; // [15] q2 = q1 + e1 * q1
1491(pred) fma.s1 f8=f11,f8,f8 //;; // [20] y2 = y1 + e1 * y1
1492(pred) fnma.s1 f10=f7,f9,f6;; // [20] r2 = a - b * q2
1493(pred) fma.s1 f8=f10,f8,f9;; // [25] q3 = q2 + r2 * y2
1494
1495 fcvt.fxu.trunc.s1 f8=f8 // [30] q = trunc(q3)
1496 br.ret.sptk.many b6;;
1497.endp bn_div_words#
1498#endif
diff --git a/src/lib/libssl/src/crypto/bn/asm/mips1.s b/src/lib/libssl/src/crypto/bn/asm/mips1.s
new file mode 100644
index 0000000000..44fa1254c7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/mips1.s
@@ -0,0 +1,539 @@
1/* This assember is for R2000/R3000 machines, or higher ones that do
2 * no want to do any 64 bit arithmatic.
3 * Make sure that the SSLeay bignum library is compiled with
4 * THIRTY_TWO_BIT set.
5 * This must either be compiled with the system CC, or, if you use GNU gas,
6 * cc -E mips1.s|gas -o mips1.o
7 */
8 .set reorder
9 .set noat
10
11#define R1 $1
12#define CC $2
13#define R2 $3
14#define R3 $8
15#define R4 $9
16#define L1 $10
17#define L2 $11
18#define L3 $12
19#define L4 $13
20#define H1 $14
21#define H2 $15
22#define H3 $24
23#define H4 $25
24
25#define P1 $4
26#define P2 $5
27#define P3 $6
28#define P4 $7
29
30 .align 2
31 .ent bn_mul_add_words
32 .globl bn_mul_add_words
33.text
34bn_mul_add_words:
35 .frame $sp,0,$31
36 .mask 0x00000000,0
37 .fmask 0x00000000,0
38
39 #blt P3,4,$lab34
40
41 subu R1,P3,4
42 move CC,$0
43 bltz R1,$lab34
44$lab2:
45 lw R1,0(P1)
46 lw L1,0(P2)
47 lw R2,4(P1)
48 lw L2,4(P2)
49 lw R3,8(P1)
50 lw L3,8(P2)
51 lw R4,12(P1)
52 lw L4,12(P2)
53 multu L1,P4
54 addu R1,R1,CC
55 mflo L1
56 sltu CC,R1,CC
57 addu R1,R1,L1
58 mfhi H1
59 sltu L1,R1,L1
60 sw R1,0(P1)
61 addu CC,CC,L1
62 multu L2,P4
63 addu CC,H1,CC
64 mflo L2
65 addu R2,R2,CC
66 sltu CC,R2,CC
67 mfhi H2
68 addu R2,R2,L2
69 addu P2,P2,16
70 sltu L2,R2,L2
71 sw R2,4(P1)
72 addu CC,CC,L2
73 multu L3,P4
74 addu CC,H2,CC
75 mflo L3
76 addu R3,R3,CC
77 sltu CC,R3,CC
78 mfhi H3
79 addu R3,R3,L3
80 addu P1,P1,16
81 sltu L3,R3,L3
82 sw R3,-8(P1)
83 addu CC,CC,L3
84 multu L4,P4
85 addu CC,H3,CC
86 mflo L4
87 addu R4,R4,CC
88 sltu CC,R4,CC
89 mfhi H4
90 addu R4,R4,L4
91 subu P3,P3,4
92 sltu L4,R4,L4
93 addu CC,CC,L4
94 addu CC,H4,CC
95
96 subu R1,P3,4
97 sw R4,-4(P1) # delay slot
98 bgez R1,$lab2
99
100 bleu P3,0,$lab3
101 .align 2
102$lab33:
103 lw L1,0(P2)
104 lw R1,0(P1)
105 multu L1,P4
106 addu R1,R1,CC
107 sltu CC,R1,CC
108 addu P1,P1,4
109 mflo L1
110 mfhi H1
111 addu R1,R1,L1
112 addu P2,P2,4
113 sltu L1,R1,L1
114 subu P3,P3,1
115 addu CC,CC,L1
116 sw R1,-4(P1)
117 addu CC,H1,CC
118 bgtz P3,$lab33
119 j $31
120 .align 2
121$lab3:
122 j $31
123 .align 2
124$lab34:
125 bgt P3,0,$lab33
126 j $31
127 .end bn_mul_add_words
128
129 .align 2
130 # Program Unit: bn_mul_words
131 .ent bn_mul_words
132 .globl bn_mul_words
133.text
134bn_mul_words:
135 .frame $sp,0,$31
136 .mask 0x00000000,0
137 .fmask 0x00000000,0
138
139 subu P3,P3,4
140 move CC,$0
141 bltz P3,$lab45
142$lab44:
143 lw L1,0(P2)
144 lw L2,4(P2)
145 lw L3,8(P2)
146 lw L4,12(P2)
147 multu L1,P4
148 subu P3,P3,4
149 mflo L1
150 mfhi H1
151 addu L1,L1,CC
152 multu L2,P4
153 sltu CC,L1,CC
154 sw L1,0(P1)
155 addu CC,H1,CC
156 mflo L2
157 mfhi H2
158 addu L2,L2,CC
159 multu L3,P4
160 sltu CC,L2,CC
161 sw L2,4(P1)
162 addu CC,H2,CC
163 mflo L3
164 mfhi H3
165 addu L3,L3,CC
166 multu L4,P4
167 sltu CC,L3,CC
168 sw L3,8(P1)
169 addu CC,H3,CC
170 mflo L4
171 mfhi H4
172 addu L4,L4,CC
173 addu P1,P1,16
174 sltu CC,L4,CC
175 addu P2,P2,16
176 addu CC,H4,CC
177 sw L4,-4(P1)
178
179 bgez P3,$lab44
180 b $lab45
181$lab46:
182 lw L1,0(P2)
183 addu P1,P1,4
184 multu L1,P4
185 addu P2,P2,4
186 mflo L1
187 mfhi H1
188 addu L1,L1,CC
189 subu P3,P3,1
190 sltu CC,L1,CC
191 sw L1,-4(P1)
192 addu CC,H1,CC
193 bgtz P3,$lab46
194 j $31
195$lab45:
196 addu P3,P3,4
197 bgtz P3,$lab46
198 j $31
199 .align 2
200 .end bn_mul_words
201
202 # Program Unit: bn_sqr_words
203 .ent bn_sqr_words
204 .globl bn_sqr_words
205.text
206bn_sqr_words:
207 .frame $sp,0,$31
208 .mask 0x00000000,0
209 .fmask 0x00000000,0
210
211 subu P3,P3,4
212 bltz P3,$lab55
213$lab54:
214 lw L1,0(P2)
215 lw L2,4(P2)
216 lw L3,8(P2)
217 lw L4,12(P2)
218
219 multu L1,L1
220 subu P3,P3,4
221 mflo L1
222 mfhi H1
223 sw L1,0(P1)
224 sw H1,4(P1)
225
226 multu L2,L2
227 addu P1,P1,32
228 mflo L2
229 mfhi H2
230 sw L2,-24(P1)
231 sw H2,-20(P1)
232
233 multu L3,L3
234 addu P2,P2,16
235 mflo L3
236 mfhi H3
237 sw L3,-16(P1)
238 sw H3,-12(P1)
239
240 multu L4,L4
241
242 mflo L4
243 mfhi H4
244 sw L4,-8(P1)
245 sw H4,-4(P1)
246
247 bgtz P3,$lab54
248 b $lab55
249$lab56:
250 lw L1,0(P2)
251 addu P1,P1,8
252 multu L1,L1
253 addu P2,P2,4
254 subu P3,P3,1
255 mflo L1
256 mfhi H1
257 sw L1,-8(P1)
258 sw H1,-4(P1)
259
260 bgtz P3,$lab56
261 j $31
262$lab55:
263 addu P3,P3,4
264 bgtz P3,$lab56
265 j $31
266 .align 2
267 .end bn_sqr_words
268
269 # Program Unit: bn_add_words
270 .ent bn_add_words
271 .globl bn_add_words
272.text
273bn_add_words: # 0x590
274 .frame $sp,0,$31
275 .mask 0x00000000,0
276 .fmask 0x00000000,0
277
278 subu P4,P4,4
279 move CC,$0
280 bltz P4,$lab65
281$lab64:
282 lw L1,0(P2)
283 lw R1,0(P3)
284 lw L2,4(P2)
285 lw R2,4(P3)
286
287 addu L1,L1,CC
288 lw L3,8(P2)
289 sltu CC,L1,CC
290 addu L1,L1,R1
291 sltu R1,L1,R1
292 lw R3,8(P3)
293 addu CC,CC,R1
294 lw L4,12(P2)
295
296 addu L2,L2,CC
297 lw R4,12(P3)
298 sltu CC,L2,CC
299 addu L2,L2,R2
300 sltu R2,L2,R2
301 sw L1,0(P1)
302 addu CC,CC,R2
303 addu P1,P1,16
304 addu L3,L3,CC
305 sw L2,-12(P1)
306
307 sltu CC,L3,CC
308 addu L3,L3,R3
309 sltu R3,L3,R3
310 addu P2,P2,16
311 addu CC,CC,R3
312
313 addu L4,L4,CC
314 addu P3,P3,16
315 sltu CC,L4,CC
316 addu L4,L4,R4
317 subu P4,P4,4
318 sltu R4,L4,R4
319 sw L3,-8(P1)
320 addu CC,CC,R4
321 sw L4,-4(P1)
322
323 bgtz P4,$lab64
324 b $lab65
325$lab66:
326 lw L1,0(P2)
327 lw R1,0(P3)
328 addu L1,L1,CC
329 addu P1,P1,4
330 sltu CC,L1,CC
331 addu P2,P2,4
332 addu P3,P3,4
333 addu L1,L1,R1
334 subu P4,P4,1
335 sltu R1,L1,R1
336 sw L1,-4(P1)
337 addu CC,CC,R1
338
339 bgtz P4,$lab66
340 j $31
341$lab65:
342 addu P4,P4,4
343 bgtz P4,$lab66
344 j $31
345 .end bn_add_words
346
347 # Program Unit: bn_div64
348 .set at
349 .set reorder
350 .text
351 .align 2
352 .globl bn_div64
353 # 321 {
354 .ent bn_div64 2
355bn_div64:
356 subu $sp, 64
357 sw $31, 56($sp)
358 sw $16, 48($sp)
359 .mask 0x80010000, -56
360 .frame $sp, 64, $31
361 move $9, $4
362 move $12, $5
363 move $16, $6
364 # 322 BN_ULONG dh,dl,q,ret=0,th,tl,t;
365 move $31, $0
366 # 323 int i,count=2;
367 li $13, 2
368 # 324
369 # 325 if (d == 0) return(BN_MASK2);
370 bne $16, 0, $80
371 li $2, -1
372 b $93
373$80:
374 # 326
375 # 327 i=BN_num_bits_word(d);
376 move $4, $16
377 sw $31, 16($sp)
378 sw $9, 24($sp)
379 sw $12, 32($sp)
380 sw $13, 40($sp)
381 .livereg 0x800ff0e,0xfff
382 jal BN_num_bits_word
383 li $4, 32
384 lw $31, 16($sp)
385 lw $9, 24($sp)
386 lw $12, 32($sp)
387 lw $13, 40($sp)
388 move $3, $2
389 # 328 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
390 beq $2, $4, $81
391 li $14, 1
392 sll $15, $14, $2
393 bleu $9, $15, $81
394 # 329 {
395 # 330 #if !defined(NO_STDIO) && !defined(WIN16)
396 # 331 fprintf(stderr,"Division would overflow (%d)\n",i);
397 # 332 #endif
398 # 333 abort();
399 sw $3, 8($sp)
400 sw $9, 24($sp)
401 sw $12, 32($sp)
402 sw $13, 40($sp)
403 sw $31, 26($sp)
404 .livereg 0xff0e,0xfff
405 jal abort
406 lw $3, 8($sp)
407 li $4, 32
408 lw $9, 24($sp)
409 lw $12, 32($sp)
410 lw $13, 40($sp)
411 lw $31, 26($sp)
412 # 334 }
413$81:
414 # 335 i=BN_BITS2-i;
415 subu $3, $4, $3
416 # 336 if (h >= d) h-=d;
417 bltu $9, $16, $82
418 subu $9, $9, $16
419$82:
420 # 337
421 # 338 if (i)
422 beq $3, 0, $83
423 # 339 {
424 # 340 d<<=i;
425 sll $16, $16, $3
426 # 341 h=(h<<i)|(l>>(BN_BITS2-i));
427 sll $24, $9, $3
428 subu $25, $4, $3
429 srl $14, $12, $25
430 or $9, $24, $14
431 # 342 l<<=i;
432 sll $12, $12, $3
433 # 343 }
434$83:
435 # 344 dh=(d&BN_MASK2h)>>BN_BITS4;
436 # 345 dl=(d&BN_MASK2l);
437 and $8, $16, -65536
438 srl $8, $8, 16
439 and $10, $16, 65535
440 li $6, -65536
441$84:
442 # 346 for (;;)
443 # 347 {
444 # 348 if ((h>>BN_BITS4) == dh)
445 srl $15, $9, 16
446 bne $8, $15, $85
447 # 349 q=BN_MASK2l;
448 li $5, 65535
449 b $86
450$85:
451 # 350 else
452 # 351 q=h/dh;
453 divu $5, $9, $8
454$86:
455 # 352
456 # 353 for (;;)
457 # 354 {
458 # 355 t=(h-q*dh);
459 mul $4, $5, $8
460 subu $2, $9, $4
461 move $3, $2
462 # 356 if ((t&BN_MASK2h) ||
463 # 357 ((dl*q) <= (
464 # 358 (t<<BN_BITS4)+
465 # 359 ((l&BN_MASK2h)>>BN_BITS4))))
466 and $25, $2, $6
467 bne $25, $0, $87
468 mul $24, $10, $5
469 sll $14, $3, 16
470 and $15, $12, $6
471 srl $25, $15, 16
472 addu $15, $14, $25
473 bgtu $24, $15, $88
474$87:
475 # 360 break;
476 mul $3, $10, $5
477 b $89
478$88:
479 # 361 q--;
480 addu $5, $5, -1
481 # 362 }
482 b $86
483$89:
484 # 363 th=q*dh;
485 # 364 tl=q*dl;
486 # 365 t=(tl>>BN_BITS4);
487 # 366 tl=(tl<<BN_BITS4)&BN_MASK2h;
488 sll $14, $3, 16
489 and $2, $14, $6
490 move $11, $2
491 # 367 th+=t;
492 srl $25, $3, 16
493 addu $7, $4, $25
494 # 368
495 # 369 if (l < tl) th++;
496 bgeu $12, $2, $90
497 addu $7, $7, 1
498$90:
499 # 370 l-=tl;
500 subu $12, $12, $11
501 # 371 if (h < th)
502 bgeu $9, $7, $91
503 # 372 {
504 # 373 h+=d;
505 addu $9, $9, $16
506 # 374 q--;
507 addu $5, $5, -1
508 # 375 }
509$91:
510 # 376 h-=th;
511 subu $9, $9, $7
512 # 377
513 # 378 if (--count == 0) break;
514 addu $13, $13, -1
515 beq $13, 0, $92
516 # 379
517 # 380 ret=q<<BN_BITS4;
518 sll $31, $5, 16
519 # 381 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
520 sll $24, $9, 16
521 srl $15, $12, 16
522 or $9, $24, $15
523 # 382 l=(l&BN_MASK2l)<<BN_BITS4;
524 and $12, $12, 65535
525 sll $12, $12, 16
526 # 383 }
527 b $84
528$92:
529 # 384 ret|=q;
530 or $31, $31, $5
531 # 385 return(ret);
532 move $2, $31
533$93:
534 lw $16, 48($sp)
535 lw $31, 56($sp)
536 addu $sp, 64
537 j $31
538 .end bn_div64
539
diff --git a/src/lib/libssl/src/crypto/bn/asm/mips3.s b/src/lib/libssl/src/crypto/bn/asm/mips3.s
new file mode 100644
index 0000000000..191345d920
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/mips3.s
@@ -0,0 +1,2138 @@
1.rdata
2.asciiz "mips3.s, Version 1.0"
3.asciiz "MIPS III/IV ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
4
5/*
6 * ====================================================================
7 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
8 * project.
9 *
10 * Rights for redistribution and usage in source and binary forms are
11 * granted according to the OpenSSL license. Warranty of any kind is
12 * disclaimed.
13 * ====================================================================
14 */
15
16/*
17 * This is my modest contributon to the OpenSSL project (see
18 * http://www.openssl.org/ for more information about it) and is
19 * a drop-in MIPS III/IV ISA replacement for crypto/bn/bn_asm.c
20 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
21 *
22 * The module is designed to work with either of the "new" MIPS ABI(5),
23 * namely N32 or N64, offered by IRIX 6.x. It's not ment to work under
24 * IRIX 5.x not only because it doesn't support new ABIs but also
25 * because 5.x kernels put R4x00 CPU into 32-bit mode and all those
26 * 64-bit instructions (daddu, dmultu, etc.) found below gonna only
27 * cause illegal instruction exception:-(
28 *
29 * In addition the code depends on preprocessor flags set up by MIPSpro
30 * compiler driver (either as or cc) and therefore (probably?) can't be
31 * compiled by the GNU assembler. GNU C driver manages fine though...
32 * I mean as long as -mmips-as is specified or is the default option,
33 * because then it simply invokes /usr/bin/as which in turn takes
34 * perfect care of the preprocessor definitions. Another neat feature
35 * offered by the MIPSpro assembler is an optimization pass. This gave
36 * me the opportunity to have the code looking more regular as all those
37 * architecture dependent instruction rescheduling details were left to
38 * the assembler. Cool, huh?
39 *
40 * Performance improvement is astonishing! 'apps/openssl speed rsa dsa'
41 * goes way over 3 times faster!
42 *
43 * <appro@fy.chalmers.se>
44 */
45#include <asm.h>
46#include <regdef.h>
47
48#if _MIPS_ISA>=4
49#define MOVNZ(cond,dst,src) \
50 movn dst,src,cond
51#else
52#define MOVNZ(cond,dst,src) \
53 .set noreorder; \
54 bnezl cond,.+8; \
55 move dst,src; \
56 .set reorder
57#endif
58
59.text
60
61.set noat
62.set reorder
63
64#define MINUS4 v1
65
66.align 5
67LEAF(bn_mul_add_words)
68 .set noreorder
69 bgtzl a2,.L_bn_mul_add_words_proceed
70 ld t0,0(a1)
71 jr ra
72 move v0,zero
73 .set reorder
74
75.L_bn_mul_add_words_proceed:
76 li MINUS4,-4
77 and ta0,a2,MINUS4
78 move v0,zero
79 beqz ta0,.L_bn_mul_add_words_tail
80
81.L_bn_mul_add_words_loop:
82 dmultu t0,a3
83 ld t1,0(a0)
84 ld t2,8(a1)
85 ld t3,8(a0)
86 ld ta0,16(a1)
87 ld ta1,16(a0)
88 daddu t1,v0
89 sltu v0,t1,v0 /* All manuals say it "compares 32-bit
90 * values", but it seems to work fine
91 * even on 64-bit registers. */
92 mflo AT
93 mfhi t0
94 daddu t1,AT
95 daddu v0,t0
96 sltu AT,t1,AT
97 sd t1,0(a0)
98 daddu v0,AT
99
100 dmultu t2,a3
101 ld ta2,24(a1)
102 ld ta3,24(a0)
103 daddu t3,v0
104 sltu v0,t3,v0
105 mflo AT
106 mfhi t2
107 daddu t3,AT
108 daddu v0,t2
109 sltu AT,t3,AT
110 sd t3,8(a0)
111 daddu v0,AT
112
113 dmultu ta0,a3
114 subu a2,4
115 PTR_ADD a0,32
116 PTR_ADD a1,32
117 daddu ta1,v0
118 sltu v0,ta1,v0
119 mflo AT
120 mfhi ta0
121 daddu ta1,AT
122 daddu v0,ta0
123 sltu AT,ta1,AT
124 sd ta1,-16(a0)
125 daddu v0,AT
126
127
128 dmultu ta2,a3
129 and ta0,a2,MINUS4
130 daddu ta3,v0
131 sltu v0,ta3,v0
132 mflo AT
133 mfhi ta2
134 daddu ta3,AT
135 daddu v0,ta2
136 sltu AT,ta3,AT
137 sd ta3,-8(a0)
138 daddu v0,AT
139 .set noreorder
140 bgtzl ta0,.L_bn_mul_add_words_loop
141 ld t0,0(a1)
142
143 bnezl a2,.L_bn_mul_add_words_tail
144 ld t0,0(a1)
145 .set reorder
146
147.L_bn_mul_add_words_return:
148 jr ra
149
150.L_bn_mul_add_words_tail:
151 dmultu t0,a3
152 ld t1,0(a0)
153 subu a2,1
154 daddu t1,v0
155 sltu v0,t1,v0
156 mflo AT
157 mfhi t0
158 daddu t1,AT
159 daddu v0,t0
160 sltu AT,t1,AT
161 sd t1,0(a0)
162 daddu v0,AT
163 beqz a2,.L_bn_mul_add_words_return
164
165 ld t0,8(a1)
166 dmultu t0,a3
167 ld t1,8(a0)
168 subu a2,1
169 daddu t1,v0
170 sltu v0,t1,v0
171 mflo AT
172 mfhi t0
173 daddu t1,AT
174 daddu v0,t0
175 sltu AT,t1,AT
176 sd t1,8(a0)
177 daddu v0,AT
178 beqz a2,.L_bn_mul_add_words_return
179
180 ld t0,16(a1)
181 dmultu t0,a3
182 ld t1,16(a0)
183 daddu t1,v0
184 sltu v0,t1,v0
185 mflo AT
186 mfhi t0
187 daddu t1,AT
188 daddu v0,t0
189 sltu AT,t1,AT
190 sd t1,16(a0)
191 daddu v0,AT
192 jr ra
193END(bn_mul_add_words)
194
195.align 5
196LEAF(bn_mul_words)
197 .set noreorder
198 bgtzl a2,.L_bn_mul_words_proceed
199 ld t0,0(a1)
200 jr ra
201 move v0,zero
202 .set reorder
203
204.L_bn_mul_words_proceed:
205 li MINUS4,-4
206 and ta0,a2,MINUS4
207 move v0,zero
208 beqz ta0,.L_bn_mul_words_tail
209
210.L_bn_mul_words_loop:
211 dmultu t0,a3
212 ld t2,8(a1)
213 ld ta0,16(a1)
214 ld ta2,24(a1)
215 mflo AT
216 mfhi t0
217 daddu v0,AT
218 sltu t1,v0,AT
219 sd v0,0(a0)
220 daddu v0,t1,t0
221
222 dmultu t2,a3
223 subu a2,4
224 PTR_ADD a0,32
225 PTR_ADD a1,32
226 mflo AT
227 mfhi t2
228 daddu v0,AT
229 sltu t3,v0,AT
230 sd v0,-24(a0)
231 daddu v0,t3,t2
232
233 dmultu ta0,a3
234 mflo AT
235 mfhi ta0
236 daddu v0,AT
237 sltu ta1,v0,AT
238 sd v0,-16(a0)
239 daddu v0,ta1,ta0
240
241
242 dmultu ta2,a3
243 and ta0,a2,MINUS4
244 mflo AT
245 mfhi ta2
246 daddu v0,AT
247 sltu ta3,v0,AT
248 sd v0,-8(a0)
249 daddu v0,ta3,ta2
250 .set noreorder
251 bgtzl ta0,.L_bn_mul_words_loop
252 ld t0,0(a1)
253
254 bnezl a2,.L_bn_mul_words_tail
255 ld t0,0(a1)
256 .set reorder
257
258.L_bn_mul_words_return:
259 jr ra
260
261.L_bn_mul_words_tail:
262 dmultu t0,a3
263 subu a2,1
264 mflo AT
265 mfhi t0
266 daddu v0,AT
267 sltu t1,v0,AT
268 sd v0,0(a0)
269 daddu v0,t1,t0
270 beqz a2,.L_bn_mul_words_return
271
272 ld t0,8(a1)
273 dmultu t0,a3
274 subu a2,1
275 mflo AT
276 mfhi t0
277 daddu v0,AT
278 sltu t1,v0,AT
279 sd v0,8(a0)
280 daddu v0,t1,t0
281 beqz a2,.L_bn_mul_words_return
282
283 ld t0,16(a1)
284 dmultu t0,a3
285 mflo AT
286 mfhi t0
287 daddu v0,AT
288 sltu t1,v0,AT
289 sd v0,16(a0)
290 daddu v0,t1,t0
291 jr ra
292END(bn_mul_words)
293
294.align 5
295LEAF(bn_sqr_words)
296 .set noreorder
297 bgtzl a2,.L_bn_sqr_words_proceed
298 ld t0,0(a1)
299 jr ra
300 move v0,zero
301 .set reorder
302
303.L_bn_sqr_words_proceed:
304 li MINUS4,-4
305 and ta0,a2,MINUS4
306 move v0,zero
307 beqz ta0,.L_bn_sqr_words_tail
308
309.L_bn_sqr_words_loop:
310 dmultu t0,t0
311 ld t2,8(a1)
312 ld ta0,16(a1)
313 ld ta2,24(a1)
314 mflo t1
315 mfhi t0
316 sd t1,0(a0)
317 sd t0,8(a0)
318
319 dmultu t2,t2
320 subu a2,4
321 PTR_ADD a0,64
322 PTR_ADD a1,32
323 mflo t3
324 mfhi t2
325 sd t3,-48(a0)
326 sd t2,-40(a0)
327
328 dmultu ta0,ta0
329 mflo ta1
330 mfhi ta0
331 sd ta1,-32(a0)
332 sd ta0,-24(a0)
333
334
335 dmultu ta2,ta2
336 and ta0,a2,MINUS4
337 mflo ta3
338 mfhi ta2
339 sd ta3,-16(a0)
340 sd ta2,-8(a0)
341
342 .set noreorder
343 bgtzl ta0,.L_bn_sqr_words_loop
344 ld t0,0(a1)
345
346 bnezl a2,.L_bn_sqr_words_tail
347 ld t0,0(a1)
348 .set reorder
349
350.L_bn_sqr_words_return:
351 move v0,zero
352 jr ra
353
354.L_bn_sqr_words_tail:
355 dmultu t0,t0
356 subu a2,1
357 mflo t1
358 mfhi t0
359 sd t1,0(a0)
360 sd t0,8(a0)
361 beqz a2,.L_bn_sqr_words_return
362
363 ld t0,8(a1)
364 dmultu t0,t0
365 subu a2,1
366 mflo t1
367 mfhi t0
368 sd t1,16(a0)
369 sd t0,24(a0)
370 beqz a2,.L_bn_sqr_words_return
371
372 ld t0,16(a1)
373 dmultu t0,t0
374 mflo t1
375 mfhi t0
376 sd t1,32(a0)
377 sd t0,40(a0)
378 jr ra
379END(bn_sqr_words)
380
381.align 5
382LEAF(bn_add_words)
383 .set noreorder
384 bgtzl a3,.L_bn_add_words_proceed
385 ld t0,0(a1)
386 jr ra
387 move v0,zero
388 .set reorder
389
390.L_bn_add_words_proceed:
391 li MINUS4,-4
392 and AT,a3,MINUS4
393 move v0,zero
394 beqz AT,.L_bn_add_words_tail
395
396.L_bn_add_words_loop:
397 ld ta0,0(a2)
398 ld t1,8(a1)
399 ld ta1,8(a2)
400 ld t2,16(a1)
401 ld ta2,16(a2)
402 ld t3,24(a1)
403 ld ta3,24(a2)
404 daddu ta0,t0
405 subu a3,4
406 sltu t8,ta0,t0
407 daddu t0,ta0,v0
408 PTR_ADD a0,32
409 sltu v0,t0,ta0
410 sd t0,-32(a0)
411 daddu v0,t8
412
413 daddu ta1,t1
414 PTR_ADD a1,32
415 sltu t9,ta1,t1
416 daddu t1,ta1,v0
417 PTR_ADD a2,32
418 sltu v0,t1,ta1
419 sd t1,-24(a0)
420 daddu v0,t9
421
422 daddu ta2,t2
423 and AT,a3,MINUS4
424 sltu t8,ta2,t2
425 daddu t2,ta2,v0
426 sltu v0,t2,ta2
427 sd t2,-16(a0)
428 daddu v0,t8
429
430 daddu ta3,t3
431 sltu t9,ta3,t3
432 daddu t3,ta3,v0
433 sltu v0,t3,ta3
434 sd t3,-8(a0)
435 daddu v0,t9
436
437 .set noreorder
438 bgtzl AT,.L_bn_add_words_loop
439 ld t0,0(a1)
440
441 bnezl a3,.L_bn_add_words_tail
442 ld t0,0(a1)
443 .set reorder
444
445.L_bn_add_words_return:
446 jr ra
447
448.L_bn_add_words_tail:
449 ld ta0,0(a2)
450 daddu ta0,t0
451 subu a3,1
452 sltu t8,ta0,t0
453 daddu t0,ta0,v0
454 sltu v0,t0,ta0
455 sd t0,0(a0)
456 daddu v0,t8
457 beqz a3,.L_bn_add_words_return
458
459 ld t1,8(a1)
460 ld ta1,8(a2)
461 daddu ta1,t1
462 subu a3,1
463 sltu t9,ta1,t1
464 daddu t1,ta1,v0
465 sltu v0,t1,ta1
466 sd t1,8(a0)
467 daddu v0,t9
468 beqz a3,.L_bn_add_words_return
469
470 ld t2,16(a1)
471 ld ta2,16(a2)
472 daddu ta2,t2
473 sltu t8,ta2,t2
474 daddu t2,ta2,v0
475 sltu v0,t2,ta2
476 sd t2,16(a0)
477 daddu v0,t8
478 jr ra
479END(bn_add_words)
480
481.align 5
482LEAF(bn_sub_words)
483 .set noreorder
484 bgtzl a3,.L_bn_sub_words_proceed
485 ld t0,0(a1)
486 jr ra
487 move v0,zero
488 .set reorder
489
490.L_bn_sub_words_proceed:
491 li MINUS4,-4
492 and AT,a3,MINUS4
493 move v0,zero
494 beqz AT,.L_bn_sub_words_tail
495
496.L_bn_sub_words_loop:
497 ld ta0,0(a2)
498 ld t1,8(a1)
499 ld ta1,8(a2)
500 ld t2,16(a1)
501 ld ta2,16(a2)
502 ld t3,24(a1)
503 ld ta3,24(a2)
504 sltu t8,t0,ta0
505 dsubu t0,ta0
506 subu a3,4
507 dsubu ta0,t0,v0
508 and AT,a3,MINUS4
509 sd ta0,0(a0)
510 MOVNZ (t0,v0,t8)
511
512 sltu t9,t1,ta1
513 dsubu t1,ta1
514 PTR_ADD a0,32
515 dsubu ta1,t1,v0
516 PTR_ADD a1,32
517 sd ta1,-24(a0)
518 MOVNZ (t1,v0,t9)
519
520
521 sltu t8,t2,ta2
522 dsubu t2,ta2
523 dsubu ta2,t2,v0
524 PTR_ADD a2,32
525 sd ta2,-16(a0)
526 MOVNZ (t2,v0,t8)
527
528 sltu t9,t3,ta3
529 dsubu t3,ta3
530 dsubu ta3,t3,v0
531 sd ta3,-8(a0)
532 MOVNZ (t3,v0,t9)
533
534 .set noreorder
535 bgtzl AT,.L_bn_sub_words_loop
536 ld t0,0(a1)
537
538 bnezl a3,.L_bn_sub_words_tail
539 ld t0,0(a1)
540 .set reorder
541
542.L_bn_sub_words_return:
543 jr ra
544
545.L_bn_sub_words_tail:
546 ld ta0,0(a2)
547 subu a3,1
548 sltu t8,t0,ta0
549 dsubu t0,ta0
550 dsubu ta0,t0,v0
551 MOVNZ (t0,v0,t8)
552 sd ta0,0(a0)
553 beqz a3,.L_bn_sub_words_return
554
555 ld t1,8(a1)
556 subu a3,1
557 ld ta1,8(a2)
558 sltu t9,t1,ta1
559 dsubu t1,ta1
560 dsubu ta1,t1,v0
561 MOVNZ (t1,v0,t9)
562 sd ta1,8(a0)
563 beqz a3,.L_bn_sub_words_return
564
565 ld t2,16(a1)
566 ld ta2,16(a2)
567 sltu t8,t2,ta2
568 dsubu t2,ta2
569 dsubu ta2,t2,v0
570 MOVNZ (t2,v0,t8)
571 sd ta2,16(a0)
572 jr ra
573END(bn_sub_words)
574
575#undef MINUS4
576
577.align 5
578LEAF(bn_div_words)
579 .set noreorder
580 bnezl a2,.L_bn_div_words_proceed
581 move v1,zero
582 jr ra
583 li v0,-1 /* I'd rather signal div-by-zero
584 * which can be done with 'break 7' */
585
586.L_bn_div_words_proceed:
587 bltz a2,.L_bn_div_words_body
588 move t9,v1
589 dsll a2,1
590 bgtz a2,.-4
591 addu t9,1
592
593 .set reorder
594 negu t1,t9
595 li t2,-1
596 dsll t2,t1
597 and t2,a0
598 dsrl AT,a1,t1
599 .set noreorder
600 bnezl t2,.+8
601 break 6 /* signal overflow */
602 .set reorder
603 dsll a0,t9
604 dsll a1,t9
605 or a0,AT
606
607#define QT ta0
608#define HH ta1
609#define DH v1
610.L_bn_div_words_body:
611 dsrl DH,a2,32
612 sgeu AT,a0,a2
613 .set noreorder
614 bnezl AT,.+8
615 dsubu a0,a2
616 .set reorder
617
618 li QT,-1
619 dsrl HH,a0,32
620 dsrl QT,32 /* q=0xffffffff */
621 beq DH,HH,.L_bn_div_words_skip_div1
622 ddivu zero,a0,DH
623 mflo QT
624.L_bn_div_words_skip_div1:
625 dmultu a2,QT
626 dsll t3,a0,32
627 dsrl AT,a1,32
628 or t3,AT
629 mflo t0
630 mfhi t1
631.L_bn_div_words_inner_loop1:
632 sltu t2,t3,t0
633 seq t8,HH,t1
634 sltu AT,HH,t1
635 and t2,t8
636 or AT,t2
637 .set noreorder
638 beqz AT,.L_bn_div_words_inner_loop1_done
639 sltu t2,t0,a2
640 .set reorder
641 dsubu QT,1
642 dsubu t0,a2
643 dsubu t1,t2
644 b .L_bn_div_words_inner_loop1
645.L_bn_div_words_inner_loop1_done:
646
647 dsll a1,32
648 dsubu a0,t3,t0
649 dsll v0,QT,32
650
651 li QT,-1
652 dsrl HH,a0,32
653 dsrl QT,32 /* q=0xffffffff */
654 beq DH,HH,.L_bn_div_words_skip_div2
655 ddivu zero,a0,DH
656 mflo QT
657.L_bn_div_words_skip_div2:
658 dmultu a2,QT
659 dsll t3,a0,32
660 dsrl AT,a1,32
661 or t3,AT
662 mflo t0
663 mfhi t1
664.L_bn_div_words_inner_loop2:
665 sltu t2,t3,t0
666 seq t8,HH,t1
667 sltu AT,HH,t1
668 and t2,t8
669 or AT,t2
670 .set noreorder
671 beqz AT,.L_bn_div_words_inner_loop2_done
672 sltu t2,t0,a2
673 .set reorder
674 dsubu QT,1
675 dsubu t0,a2
676 dsubu t1,t2
677 b .L_bn_div_words_inner_loop2
678.L_bn_div_words_inner_loop2_done:
679
680 dsubu a0,t3,t0
681 or v0,QT
682 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */
683 dsrl a2,t9 /* restore a2 */
684 jr ra
685#undef HH
686#undef DH
687#undef QT
688END(bn_div_words)
689
690.align 5
691LEAF(bn_div_3_words)
692 .set reorder
693 move a3,a0 /* we know that bn_div_words doesn't
694 * touch a3, ta2, ta3 and preserves a2
695 * so that we can save two arguments
696 * and return address in registers
697 * instead of stack:-)
698 */
699 ld a0,(a3)
700 move ta2,a2
701 move a2,a1
702 ld a1,-8(a3)
703 move ta3,ra
704 move v1,zero
705 li v0,-1
706 beq a0,a2,.L_bn_div_3_words_skip_div
707 jal bn_div_words
708 move ra,ta3
709.L_bn_div_3_words_skip_div:
710 dmultu ta2,v0
711 ld t2,-16(a3)
712 mflo t0
713 mfhi t1
714.L_bn_div_3_words_inner_loop:
715 sgeu AT,t2,t0
716 seq t9,t1,v1
717 sltu t8,t1,v1
718 and AT,t9
719 or AT,t8
720 bnez AT,.L_bn_div_3_words_inner_loop_done
721 daddu v1,a2
722 sltu t3,t0,ta2
723 sltu AT,v1,a2
724 dsubu v0,1
725 dsubu t0,ta2
726 dsubu t1,t3
727 beqz AT,.L_bn_div_3_words_inner_loop
728.L_bn_div_3_words_inner_loop_done:
729 jr ra
730END(bn_div_3_words)
731
732#define a_0 t0
733#define a_1 t1
734#define a_2 t2
735#define a_3 t3
736#define b_0 ta0
737#define b_1 ta1
738#define b_2 ta2
739#define b_3 ta3
740
741#define a_4 s0
742#define a_5 s2
743#define a_6 s4
744#define a_7 a1 /* once we load a[7] we don't need a anymore */
745#define b_4 s1
746#define b_5 s3
747#define b_6 s5
748#define b_7 a2 /* once we load b[7] we don't need b anymore */
749
750#define t_1 t8
751#define t_2 t9
752
753#define c_1 v0
754#define c_2 v1
755#define c_3 a3
756
757#define FRAME_SIZE 48
758
759.align 5
760LEAF(bn_mul_comba8)
761 .set noreorder
762 PTR_SUB sp,FRAME_SIZE
763 .frame sp,64,ra
764 .set reorder
765 ld a_0,0(a1) /* If compiled with -mips3 option on
766 * R5000 box assembler barks on this
767 * line with "shouldn't have mult/div
768 * as last instruction in bb (R10K
769 * bug)" warning. If anybody out there
770 * has a clue about how to circumvent
771 * this do send me a note.
772 * <appro@fy.chalmers.se>
773 */
774 ld b_0,0(a2)
775 ld a_1,8(a1)
776 ld a_2,16(a1)
777 ld a_3,24(a1)
778 ld b_1,8(a2)
779 ld b_2,16(a2)
780 ld b_3,24(a2)
781 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
782 sd s0,0(sp)
783 sd s1,8(sp)
784 sd s2,16(sp)
785 sd s3,24(sp)
786 sd s4,32(sp)
787 sd s5,40(sp)
788 mflo c_1
789 mfhi c_2
790
791 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
792 ld a_4,32(a1)
793 ld a_5,40(a1)
794 ld a_6,48(a1)
795 ld a_7,56(a1)
796 ld b_4,32(a2)
797 ld b_5,40(a2)
798 mflo t_1
799 mfhi t_2
800 daddu c_2,t_1
801 sltu AT,c_2,t_1
802 daddu c_3,t_2,AT
803 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
804 ld b_6,48(a2)
805 ld b_7,56(a2)
806 sd c_1,0(a0) /* r[0]=c1; */
807 mflo t_1
808 mfhi t_2
809 daddu c_2,t_1
810 sltu AT,c_2,t_1
811 daddu t_2,AT
812 daddu c_3,t_2
813 sltu c_1,c_3,t_2
814 sd c_2,8(a0) /* r[1]=c2; */
815
816 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
817 mflo t_1
818 mfhi t_2
819 daddu c_3,t_1
820 sltu AT,c_3,t_1
821 daddu t_2,AT
822 daddu c_1,t_2
823 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
824 mflo t_1
825 mfhi t_2
826 daddu c_3,t_1
827 sltu AT,c_3,t_1
828 daddu t_2,AT
829 daddu c_1,t_2
830 sltu c_2,c_1,t_2
831 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
832 mflo t_1
833 mfhi t_2
834 daddu c_3,t_1
835 sltu AT,c_3,t_1
836 daddu t_2,AT
837 daddu c_1,t_2
838 sltu AT,c_1,t_2
839 daddu c_2,AT
840 sd c_3,16(a0) /* r[2]=c3; */
841
842 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
843 mflo t_1
844 mfhi t_2
845 daddu c_1,t_1
846 sltu AT,c_1,t_1
847 daddu t_2,AT
848 daddu c_2,t_2
849 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
850 mflo t_1
851 mfhi t_2
852 daddu c_1,t_1
853 sltu AT,c_1,t_1
854 daddu t_2,AT
855 daddu c_2,t_2
856 sltu c_3,c_2,t_2
857 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
858 mflo t_1
859 mfhi t_2
860 daddu c_1,t_1
861 sltu AT,c_1,t_1
862 daddu t_2,AT
863 daddu c_2,t_2
864 sltu AT,c_2,t_2
865 daddu c_3,AT
866 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
867 mflo t_1
868 mfhi t_2
869 daddu c_1,t_1
870 sltu AT,c_1,t_1
871 daddu t_2,AT
872 daddu c_2,t_2
873 sltu AT,c_2,t_2
874 daddu c_3,AT
875 sd c_1,24(a0) /* r[3]=c1; */
876
877 dmultu a_4,b_0 /* mul_add_c(a[4],b[0],c2,c3,c1); */
878 mflo t_1
879 mfhi t_2
880 daddu c_2,t_1
881 sltu AT,c_2,t_1
882 daddu t_2,AT
883 daddu c_3,t_2
884 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
885 mflo t_1
886 mfhi t_2
887 daddu c_2,t_1
888 sltu AT,c_2,t_1
889 daddu t_2,AT
890 daddu c_3,t_2
891 sltu c_1,c_3,t_2
892 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
893 mflo t_1
894 mfhi t_2
895 daddu c_2,t_1
896 sltu AT,c_2,t_1
897 daddu t_2,AT
898 daddu c_3,t_2
899 sltu AT,c_3,t_2
900 daddu c_1,AT
901 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
902 mflo t_1
903 mfhi t_2
904 daddu c_2,t_1
905 sltu AT,c_2,t_1
906 daddu t_2,AT
907 daddu c_3,t_2
908 sltu AT,c_3,t_2
909 daddu c_1,AT
910 dmultu a_0,b_4 /* mul_add_c(a[0],b[4],c2,c3,c1); */
911 mflo t_1
912 mfhi t_2
913 daddu c_2,t_1
914 sltu AT,c_2,t_1
915 daddu t_2,AT
916 daddu c_3,t_2
917 sltu AT,c_3,t_2
918 daddu c_1,AT
919 sd c_2,32(a0) /* r[4]=c2; */
920
921 dmultu a_0,b_5 /* mul_add_c(a[0],b[5],c3,c1,c2); */
922 mflo t_1
923 mfhi t_2
924 daddu c_3,t_1
925 sltu AT,c_3,t_1
926 daddu t_2,AT
927 daddu c_1,t_2
928 dmultu a_1,b_4 /* mul_add_c(a[1],b[4],c3,c1,c2); */
929 mflo t_1
930 mfhi t_2
931 daddu c_3,t_1
932 sltu AT,c_3,t_1
933 daddu t_2,AT
934 daddu c_1,t_2
935 sltu c_2,c_1,t_2
936 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
937 mflo t_1
938 mfhi t_2
939 daddu c_3,t_1
940 sltu AT,c_3,t_1
941 daddu t_2,AT
942 daddu c_1,t_2
943 sltu AT,c_1,t_2
944 daddu c_2,AT
945 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
946 mflo t_1
947 mfhi t_2
948 daddu c_3,t_1
949 sltu AT,c_3,t_1
950 daddu t_2,AT
951 daddu c_1,t_2
952 sltu AT,c_1,t_2
953 daddu c_2,AT
954 dmultu a_4,b_1 /* mul_add_c(a[4],b[1],c3,c1,c2); */
955 mflo t_1
956 mfhi t_2
957 daddu c_3,t_1
958 sltu AT,c_3,t_1
959 daddu t_2,AT
960 daddu c_1,t_2
961 sltu AT,c_1,t_2
962 daddu c_2,AT
963 dmultu a_5,b_0 /* mul_add_c(a[5],b[0],c3,c1,c2); */
964 mflo t_1
965 mfhi t_2
966 daddu c_3,t_1
967 sltu AT,c_3,t_1
968 daddu t_2,AT
969 daddu c_1,t_2
970 sltu AT,c_1,t_2
971 daddu c_2,AT
972 sd c_3,40(a0) /* r[5]=c3; */
973
974 dmultu a_6,b_0 /* mul_add_c(a[6],b[0],c1,c2,c3); */
975 mflo t_1
976 mfhi t_2
977 daddu c_1,t_1
978 sltu AT,c_1,t_1
979 daddu t_2,AT
980 daddu c_2,t_2
981 dmultu a_5,b_1 /* mul_add_c(a[5],b[1],c1,c2,c3); */
982 mflo t_1
983 mfhi t_2
984 daddu c_1,t_1
985 sltu AT,c_1,t_1
986 daddu t_2,AT
987 daddu c_2,t_2
988 sltu c_3,c_2,t_2
989 dmultu a_4,b_2 /* mul_add_c(a[4],b[2],c1,c2,c3); */
990 mflo t_1
991 mfhi t_2
992 daddu c_1,t_1
993 sltu AT,c_1,t_1
994 daddu t_2,AT
995 daddu c_2,t_2
996 sltu AT,c_2,t_2
997 daddu c_3,AT
998 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
999 mflo t_1
1000 mfhi t_2
1001 daddu c_1,t_1
1002 sltu AT,c_1,t_1
1003 daddu t_2,AT
1004 daddu c_2,t_2
1005 sltu AT,c_2,t_2
1006 daddu c_3,AT
1007 dmultu a_2,b_4 /* mul_add_c(a[2],b[4],c1,c2,c3); */
1008 mflo t_1
1009 mfhi t_2
1010 daddu c_1,t_1
1011 sltu AT,c_1,t_1
1012 daddu t_2,AT
1013 daddu c_2,t_2
1014 sltu AT,c_2,t_2
1015 daddu c_3,AT
1016 dmultu a_1,b_5 /* mul_add_c(a[1],b[5],c1,c2,c3); */
1017 mflo t_1
1018 mfhi t_2
1019 daddu c_1,t_1
1020 sltu AT,c_1,t_1
1021 daddu t_2,AT
1022 daddu c_2,t_2
1023 sltu AT,c_2,t_2
1024 daddu c_3,AT
1025 dmultu a_0,b_6 /* mul_add_c(a[0],b[6],c1,c2,c3); */
1026 mflo t_1
1027 mfhi t_2
1028 daddu c_1,t_1
1029 sltu AT,c_1,t_1
1030 daddu t_2,AT
1031 daddu c_2,t_2
1032 sltu AT,c_2,t_2
1033 daddu c_3,AT
1034 sd c_1,48(a0) /* r[6]=c1; */
1035
1036 dmultu a_0,b_7 /* mul_add_c(a[0],b[7],c2,c3,c1); */
1037 mflo t_1
1038 mfhi t_2
1039 daddu c_2,t_1
1040 sltu AT,c_2,t_1
1041 daddu t_2,AT
1042 daddu c_3,t_2
1043 dmultu a_1,b_6 /* mul_add_c(a[1],b[6],c2,c3,c1); */
1044 mflo t_1
1045 mfhi t_2
1046 daddu c_2,t_1
1047 sltu AT,c_2,t_1
1048 daddu t_2,AT
1049 daddu c_3,t_2
1050 sltu c_1,c_3,t_2
1051 dmultu a_2,b_5 /* mul_add_c(a[2],b[5],c2,c3,c1); */
1052 mflo t_1
1053 mfhi t_2
1054 daddu c_2,t_1
1055 sltu AT,c_2,t_1
1056 daddu t_2,AT
1057 daddu c_3,t_2
1058 sltu AT,c_3,t_2
1059 daddu c_1,AT
1060 dmultu a_3,b_4 /* mul_add_c(a[3],b[4],c2,c3,c1); */
1061 mflo t_1
1062 mfhi t_2
1063 daddu c_2,t_1
1064 sltu AT,c_2,t_1
1065 daddu t_2,AT
1066 daddu c_3,t_2
1067 sltu AT,c_3,t_2
1068 daddu c_1,AT
1069 dmultu a_4,b_3 /* mul_add_c(a[4],b[3],c2,c3,c1); */
1070 mflo t_1
1071 mfhi t_2
1072 daddu c_2,t_1
1073 sltu AT,c_2,t_1
1074 daddu t_2,AT
1075 daddu c_3,t_2
1076 sltu AT,c_3,t_2
1077 daddu c_1,AT
1078 dmultu a_5,b_2 /* mul_add_c(a[5],b[2],c2,c3,c1); */
1079 mflo t_1
1080 mfhi t_2
1081 daddu c_2,t_1
1082 sltu AT,c_2,t_1
1083 daddu t_2,AT
1084 daddu c_3,t_2
1085 sltu AT,c_3,t_2
1086 daddu c_1,AT
1087 dmultu a_6,b_1 /* mul_add_c(a[6],b[1],c2,c3,c1); */
1088 mflo t_1
1089 mfhi t_2
1090 daddu c_2,t_1
1091 sltu AT,c_2,t_1
1092 daddu t_2,AT
1093 daddu c_3,t_2
1094 sltu AT,c_3,t_2
1095 daddu c_1,AT
1096 dmultu a_7,b_0 /* mul_add_c(a[7],b[0],c2,c3,c1); */
1097 mflo t_1
1098 mfhi t_2
1099 daddu c_2,t_1
1100 sltu AT,c_2,t_1
1101 daddu t_2,AT
1102 daddu c_3,t_2
1103 sltu AT,c_3,t_2
1104 daddu c_1,AT
1105 sd c_2,56(a0) /* r[7]=c2; */
1106
1107 dmultu a_7,b_1 /* mul_add_c(a[7],b[1],c3,c1,c2); */
1108 mflo t_1
1109 mfhi t_2
1110 daddu c_3,t_1
1111 sltu AT,c_3,t_1
1112 daddu t_2,AT
1113 daddu c_1,t_2
1114 dmultu a_6,b_2 /* mul_add_c(a[6],b[2],c3,c1,c2); */
1115 mflo t_1
1116 mfhi t_2
1117 daddu c_3,t_1
1118 sltu AT,c_3,t_1
1119 daddu t_2,AT
1120 daddu c_1,t_2
1121 sltu c_2,c_1,t_2
1122 dmultu a_5,b_3 /* mul_add_c(a[5],b[3],c3,c1,c2); */
1123 mflo t_1
1124 mfhi t_2
1125 daddu c_3,t_1
1126 sltu AT,c_3,t_1
1127 daddu t_2,AT
1128 daddu c_1,t_2
1129 sltu AT,c_1,t_2
1130 daddu c_2,AT
1131 dmultu a_4,b_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1132 mflo t_1
1133 mfhi t_2
1134 daddu c_3,t_1
1135 sltu AT,c_3,t_1
1136 daddu t_2,AT
1137 daddu c_1,t_2
1138 sltu AT,c_1,t_2
1139 daddu c_2,AT
1140 dmultu a_3,b_5 /* mul_add_c(a[3],b[5],c3,c1,c2); */
1141 mflo t_1
1142 mfhi t_2
1143 daddu c_3,t_1
1144 sltu AT,c_3,t_1
1145 daddu t_2,AT
1146 daddu c_1,t_2
1147 sltu AT,c_1,t_2
1148 daddu c_2,AT
1149 dmultu a_2,b_6 /* mul_add_c(a[2],b[6],c3,c1,c2); */
1150 mflo t_1
1151 mfhi t_2
1152 daddu c_3,t_1
1153 sltu AT,c_3,t_1
1154 daddu t_2,AT
1155 daddu c_1,t_2
1156 sltu AT,c_1,t_2
1157 daddu c_2,AT
1158 dmultu a_1,b_7 /* mul_add_c(a[1],b[7],c3,c1,c2); */
1159 mflo t_1
1160 mfhi t_2
1161 daddu c_3,t_1
1162 sltu AT,c_3,t_1
1163 daddu t_2,AT
1164 daddu c_1,t_2
1165 sltu AT,c_1,t_2
1166 daddu c_2,AT
1167 sd c_3,64(a0) /* r[8]=c3; */
1168
1169 dmultu a_2,b_7 /* mul_add_c(a[2],b[7],c1,c2,c3); */
1170 mflo t_1
1171 mfhi t_2
1172 daddu c_1,t_1
1173 sltu AT,c_1,t_1
1174 daddu t_2,AT
1175 daddu c_2,t_2
1176 dmultu a_3,b_6 /* mul_add_c(a[3],b[6],c1,c2,c3); */
1177 mflo t_1
1178 mfhi t_2
1179 daddu c_1,t_1
1180 sltu AT,c_1,t_1
1181 daddu t_2,AT
1182 daddu c_2,t_2
1183 sltu c_3,c_2,t_2
1184 dmultu a_4,b_5 /* mul_add_c(a[4],b[5],c1,c2,c3); */
1185 mflo t_1
1186 mfhi t_2
1187 daddu c_1,t_1
1188 sltu AT,c_1,t_1
1189 daddu t_2,AT
1190 daddu c_2,t_2
1191 sltu AT,c_2,t_2
1192 daddu c_3,AT
1193 dmultu a_5,b_4 /* mul_add_c(a[5],b[4],c1,c2,c3); */
1194 mflo t_1
1195 mfhi t_2
1196 daddu c_1,t_1
1197 sltu AT,c_1,t_1
1198 daddu t_2,AT
1199 daddu c_2,t_2
1200 sltu AT,c_2,t_2
1201 daddu c_3,AT
1202 dmultu a_6,b_3 /* mul_add_c(a[6],b[3],c1,c2,c3); */
1203 mflo t_1
1204 mfhi t_2
1205 daddu c_1,t_1
1206 sltu AT,c_1,t_1
1207 daddu t_2,AT
1208 daddu c_2,t_2
1209 sltu AT,c_2,t_2
1210 daddu c_3,AT
1211 dmultu a_7,b_2 /* mul_add_c(a[7],b[2],c1,c2,c3); */
1212 mflo t_1
1213 mfhi t_2
1214 daddu c_1,t_1
1215 sltu AT,c_1,t_1
1216 daddu t_2,AT
1217 daddu c_2,t_2
1218 sltu AT,c_2,t_2
1219 daddu c_3,AT
1220 sd c_1,72(a0) /* r[9]=c1; */
1221
1222 dmultu a_7,b_3 /* mul_add_c(a[7],b[3],c2,c3,c1); */
1223 mflo t_1
1224 mfhi t_2
1225 daddu c_2,t_1
1226 sltu AT,c_2,t_1
1227 daddu t_2,AT
1228 daddu c_3,t_2
1229 dmultu a_6,b_4 /* mul_add_c(a[6],b[4],c2,c3,c1); */
1230 mflo t_1
1231 mfhi t_2
1232 daddu c_2,t_1
1233 sltu AT,c_2,t_1
1234 daddu t_2,AT
1235 daddu c_3,t_2
1236 sltu c_1,c_3,t_2
1237 dmultu a_5,b_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1238 mflo t_1
1239 mfhi t_2
1240 daddu c_2,t_1
1241 sltu AT,c_2,t_1
1242 daddu t_2,AT
1243 daddu c_3,t_2
1244 sltu AT,c_3,t_2
1245 daddu c_1,AT
1246 dmultu a_4,b_6 /* mul_add_c(a[4],b[6],c2,c3,c1); */
1247 mflo t_1
1248 mfhi t_2
1249 daddu c_2,t_1
1250 sltu AT,c_2,t_1
1251 daddu t_2,AT
1252 daddu c_3,t_2
1253 sltu AT,c_3,t_2
1254 daddu c_1,AT
1255 dmultu a_3,b_7 /* mul_add_c(a[3],b[7],c2,c3,c1); */
1256 mflo t_1
1257 mfhi t_2
1258 daddu c_2,t_1
1259 sltu AT,c_2,t_1
1260 daddu t_2,AT
1261 daddu c_3,t_2
1262 sltu AT,c_3,t_2
1263 daddu c_1,AT
1264 sd c_2,80(a0) /* r[10]=c2; */
1265
1266 dmultu a_4,b_7 /* mul_add_c(a[4],b[7],c3,c1,c2); */
1267 mflo t_1
1268 mfhi t_2
1269 daddu c_3,t_1
1270 sltu AT,c_3,t_1
1271 daddu t_2,AT
1272 daddu c_1,t_2
1273 dmultu a_5,b_6 /* mul_add_c(a[5],b[6],c3,c1,c2); */
1274 mflo t_1
1275 mfhi t_2
1276 daddu c_3,t_1
1277 sltu AT,c_3,t_1
1278 daddu t_2,AT
1279 daddu c_1,t_2
1280 sltu c_2,c_1,t_2
1281 dmultu a_6,b_5 /* mul_add_c(a[6],b[5],c3,c1,c2); */
1282 mflo t_1
1283 mfhi t_2
1284 daddu c_3,t_1
1285 sltu AT,c_3,t_1
1286 daddu t_2,AT
1287 daddu c_1,t_2
1288 sltu AT,c_1,t_2
1289 daddu c_2,AT
1290 dmultu a_7,b_4 /* mul_add_c(a[7],b[4],c3,c1,c2); */
1291 mflo t_1
1292 mfhi t_2
1293 daddu c_3,t_1
1294 sltu AT,c_3,t_1
1295 daddu t_2,AT
1296 daddu c_1,t_2
1297 sltu AT,c_1,t_2
1298 daddu c_2,AT
1299 sd c_3,88(a0) /* r[11]=c3; */
1300
1301 dmultu a_7,b_5 /* mul_add_c(a[7],b[5],c1,c2,c3); */
1302 mflo t_1
1303 mfhi t_2
1304 daddu c_1,t_1
1305 sltu AT,c_1,t_1
1306 daddu t_2,AT
1307 daddu c_2,t_2
1308 dmultu a_6,b_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1309 mflo t_1
1310 mfhi t_2
1311 daddu c_1,t_1
1312 sltu AT,c_1,t_1
1313 daddu t_2,AT
1314 daddu c_2,t_2
1315 sltu c_3,c_2,t_2
1316 dmultu a_5,b_7 /* mul_add_c(a[5],b[7],c1,c2,c3); */
1317 mflo t_1
1318 mfhi t_2
1319 daddu c_1,t_1
1320 sltu AT,c_1,t_1
1321 daddu t_2,AT
1322 daddu c_2,t_2
1323 sltu AT,c_2,t_2
1324 daddu c_3,AT
1325 sd c_1,96(a0) /* r[12]=c1; */
1326
1327 dmultu a_6,b_7 /* mul_add_c(a[6],b[7],c2,c3,c1); */
1328 mflo t_1
1329 mfhi t_2
1330 daddu c_2,t_1
1331 sltu AT,c_2,t_1
1332 daddu t_2,AT
1333 daddu c_3,t_2
1334 dmultu a_7,b_6 /* mul_add_c(a[7],b[6],c2,c3,c1); */
1335 mflo t_1
1336 mfhi t_2
1337 daddu c_2,t_1
1338 sltu AT,c_2,t_1
1339 daddu t_2,AT
1340 daddu c_3,t_2
1341 sltu c_1,c_3,t_2
1342 sd c_2,104(a0) /* r[13]=c2; */
1343
1344 dmultu a_7,b_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
1345 ld s0,0(sp)
1346 ld s1,8(sp)
1347 ld s2,16(sp)
1348 ld s3,24(sp)
1349 ld s4,32(sp)
1350 ld s5,40(sp)
1351 mflo t_1
1352 mfhi t_2
1353 daddu c_3,t_1
1354 sltu AT,c_3,t_1
1355 daddu t_2,AT
1356 daddu c_1,t_2
1357 sd c_3,112(a0) /* r[14]=c3; */
1358 sd c_1,120(a0) /* r[15]=c1; */
1359
1360 PTR_ADD sp,FRAME_SIZE
1361
1362 jr ra
1363END(bn_mul_comba8)
1364
1365.align 5
1366LEAF(bn_mul_comba4)
1367 .set reorder
1368 ld a_0,0(a1)
1369 ld b_0,0(a2)
1370 ld a_1,8(a1)
1371 ld a_2,16(a1)
1372 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1373 ld a_3,24(a1)
1374 ld b_1,8(a2)
1375 ld b_2,16(a2)
1376 ld b_3,24(a2)
1377 mflo c_1
1378 mfhi c_2
1379 sd c_1,0(a0)
1380
1381 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
1382 mflo t_1
1383 mfhi t_2
1384 daddu c_2,t_1
1385 sltu AT,c_2,t_1
1386 daddu c_3,t_2,AT
1387 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
1388 mflo t_1
1389 mfhi t_2
1390 daddu c_2,t_1
1391 sltu AT,c_2,t_1
1392 daddu t_2,AT
1393 daddu c_3,t_2
1394 sltu c_1,c_3,t_2
1395 sd c_2,8(a0)
1396
1397 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
1398 mflo t_1
1399 mfhi t_2
1400 daddu c_3,t_1
1401 sltu AT,c_3,t_1
1402 daddu t_2,AT
1403 daddu c_1,t_2
1404 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1405 mflo t_1
1406 mfhi t_2
1407 daddu c_3,t_1
1408 sltu AT,c_3,t_1
1409 daddu t_2,AT
1410 daddu c_1,t_2
1411 sltu c_2,c_1,t_2
1412 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
1413 mflo t_1
1414 mfhi t_2
1415 daddu c_3,t_1
1416 sltu AT,c_3,t_1
1417 daddu t_2,AT
1418 daddu c_1,t_2
1419 sltu AT,c_1,t_2
1420 daddu c_2,AT
1421 sd c_3,16(a0)
1422
1423 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
1424 mflo t_1
1425 mfhi t_2
1426 daddu c_1,t_1
1427 sltu AT,c_1,t_1
1428 daddu t_2,AT
1429 daddu c_2,t_2
1430 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
1431 mflo t_1
1432 mfhi t_2
1433 daddu c_1,t_1
1434 sltu AT,c_1,t_1
1435 daddu t_2,AT
1436 daddu c_2,t_2
1437 sltu c_3,c_2,t_2
1438 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
1439 mflo t_1
1440 mfhi t_2
1441 daddu c_1,t_1
1442 sltu AT,c_1,t_1
1443 daddu t_2,AT
1444 daddu c_2,t_2
1445 sltu AT,c_2,t_2
1446 daddu c_3,AT
1447 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
1448 mflo t_1
1449 mfhi t_2
1450 daddu c_1,t_1
1451 sltu AT,c_1,t_1
1452 daddu t_2,AT
1453 daddu c_2,t_2
1454 sltu AT,c_2,t_2
1455 daddu c_3,AT
1456 sd c_1,24(a0)
1457
1458 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
1459 mflo t_1
1460 mfhi t_2
1461 daddu c_2,t_1
1462 sltu AT,c_2,t_1
1463 daddu t_2,AT
1464 daddu c_3,t_2
1465 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1466 mflo t_1
1467 mfhi t_2
1468 daddu c_2,t_1
1469 sltu AT,c_2,t_1
1470 daddu t_2,AT
1471 daddu c_3,t_2
1472 sltu c_1,c_3,t_2
1473 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
1474 mflo t_1
1475 mfhi t_2
1476 daddu c_2,t_1
1477 sltu AT,c_2,t_1
1478 daddu t_2,AT
1479 daddu c_3,t_2
1480 sltu AT,c_3,t_2
1481 daddu c_1,AT
1482 sd c_2,32(a0)
1483
1484 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
1485 mflo t_1
1486 mfhi t_2
1487 daddu c_3,t_1
1488 sltu AT,c_3,t_1
1489 daddu t_2,AT
1490 daddu c_1,t_2
1491 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
1492 mflo t_1
1493 mfhi t_2
1494 daddu c_3,t_1
1495 sltu AT,c_3,t_1
1496 daddu t_2,AT
1497 daddu c_1,t_2
1498 sltu c_2,c_1,t_2
1499 sd c_3,40(a0)
1500
1501 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1502 mflo t_1
1503 mfhi t_2
1504 daddu c_1,t_1
1505 sltu AT,c_1,t_1
1506 daddu t_2,AT
1507 daddu c_2,t_2
1508 sd c_1,48(a0)
1509 sd c_2,56(a0)
1510
1511 jr ra
1512END(bn_mul_comba4)
1513
1514#undef a_4
1515#undef a_5
1516#undef a_6
1517#undef a_7
1518#define a_4 b_0
1519#define a_5 b_1
1520#define a_6 b_2
1521#define a_7 b_3
1522
1523.align 5
1524LEAF(bn_sqr_comba8)
1525 .set reorder
1526 ld a_0,0(a1)
1527 ld a_1,8(a1)
1528 ld a_2,16(a1)
1529 ld a_3,24(a1)
1530
1531 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1532 ld a_4,32(a1)
1533 ld a_5,40(a1)
1534 ld a_6,48(a1)
1535 ld a_7,56(a1)
1536 mflo c_1
1537 mfhi c_2
1538 sd c_1,0(a0)
1539
1540 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
1541 mflo t_1
1542 mfhi t_2
1543 daddu c_2,t_1
1544 sltu AT,c_2,t_1
1545 daddu c_3,t_2,AT
1546 daddu c_2,t_1
1547 sltu AT,c_2,t_1
1548 daddu t_2,AT
1549 daddu c_3,t_2
1550 sltu c_1,c_3,t_2
1551 sd c_2,8(a0)
1552
1553 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
1554 mflo t_1
1555 mfhi t_2
1556 daddu c_3,t_1
1557 sltu AT,c_3,t_1
1558 daddu a2,t_2,AT
1559 daddu c_1,a2
1560 daddu c_3,t_1
1561 sltu AT,c_3,t_1
1562 daddu t_2,AT
1563 daddu c_1,t_2
1564 sltu c_2,c_1,t_2
1565 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1566 mflo t_1
1567 mfhi t_2
1568 daddu c_3,t_1
1569 sltu AT,c_3,t_1
1570 daddu t_2,AT
1571 daddu c_1,t_2
1572 sltu AT,c_1,t_2
1573 daddu c_2,AT
1574 sd c_3,16(a0)
1575
1576 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
1577 mflo t_1
1578 mfhi t_2
1579 daddu c_1,t_1
1580 sltu AT,c_1,t_1
1581 daddu a2,t_2,AT
1582 daddu c_2,a2
1583 daddu c_1,t_1
1584 sltu AT,c_1,t_1
1585 daddu t_2,AT
1586 daddu c_2,t_2
1587 sltu c_3,c_2,t_2
1588 dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */
1589 mflo t_1
1590 mfhi t_2
1591 daddu c_1,t_1
1592 sltu AT,c_1,t_1
1593 daddu a2,t_2,AT
1594 daddu c_2,a2
1595 sltu AT,c_2,a2
1596 daddu c_3,AT
1597 daddu c_1,t_1
1598 sltu AT,c_1,t_1
1599 daddu t_2,AT
1600 daddu c_2,t_2
1601 sltu AT,c_2,t_2
1602 daddu c_3,AT
1603 sd c_1,24(a0)
1604
1605 dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */
1606 mflo t_1
1607 mfhi t_2
1608 daddu c_2,t_1
1609 sltu AT,c_2,t_1
1610 daddu a2,t_2,AT
1611 daddu c_3,a2
1612 daddu c_2,t_1
1613 sltu AT,c_2,t_1
1614 daddu t_2,AT
1615 daddu c_3,t_2
1616 sltu c_1,c_3,t_2
1617 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
1618 mflo t_1
1619 mfhi t_2
1620 daddu c_2,t_1
1621 sltu AT,c_2,t_1
1622 daddu a2,t_2,AT
1623 daddu c_3,a2
1624 sltu AT,c_3,a2
1625 daddu c_1,AT
1626 daddu c_2,t_1
1627 sltu AT,c_2,t_1
1628 daddu t_2,AT
1629 daddu c_3,t_2
1630 sltu AT,c_3,t_2
1631 daddu c_1,AT
1632 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1633 mflo t_1
1634 mfhi t_2
1635 daddu c_2,t_1
1636 sltu AT,c_2,t_1
1637 daddu t_2,AT
1638 daddu c_3,t_2
1639 sltu AT,c_3,t_2
1640 daddu c_1,AT
1641 sd c_2,32(a0)
1642
1643 dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */
1644 mflo t_1
1645 mfhi t_2
1646 daddu c_3,t_1
1647 sltu AT,c_3,t_1
1648 daddu a2,t_2,AT
1649 daddu c_1,a2
1650 daddu c_3,t_1
1651 sltu AT,c_3,t_1
1652 daddu t_2,AT
1653 daddu c_1,t_2
1654 sltu c_2,c_1,t_2
1655 dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */
1656 mflo t_1
1657 mfhi t_2
1658 daddu c_3,t_1
1659 sltu AT,c_3,t_1
1660 daddu a2,t_2,AT
1661 daddu c_1,a2
1662 sltu AT,c_1,a2
1663 daddu c_2,AT
1664 daddu c_3,t_1
1665 sltu AT,c_3,t_1
1666 daddu t_2,AT
1667 daddu c_1,t_2
1668 sltu AT,c_1,t_2
1669 daddu c_2,AT
1670 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
1671 mflo t_1
1672 mfhi t_2
1673 daddu c_3,t_1
1674 sltu AT,c_3,t_1
1675 daddu a2,t_2,AT
1676 daddu c_1,a2
1677 sltu AT,c_1,a2
1678 daddu c_2,AT
1679 daddu c_3,t_1
1680 sltu AT,c_3,t_1
1681 daddu t_2,AT
1682 daddu c_1,t_2
1683 sltu AT,c_1,t_2
1684 daddu c_2,AT
1685 sd c_3,40(a0)
1686
1687 dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */
1688 mflo t_1
1689 mfhi t_2
1690 daddu c_1,t_1
1691 sltu AT,c_1,t_1
1692 daddu a2,t_2,AT
1693 daddu c_2,a2
1694 daddu c_1,t_1
1695 sltu AT,c_1,t_1
1696 daddu t_2,AT
1697 daddu c_2,t_2
1698 sltu c_3,c_2,t_2
1699 dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */
1700 mflo t_1
1701 mfhi t_2
1702 daddu c_1,t_1
1703 sltu AT,c_1,t_1
1704 daddu a2,t_2,AT
1705 daddu c_2,a2
1706 sltu AT,c_2,a2
1707 daddu c_3,AT
1708 daddu c_1,t_1
1709 sltu AT,c_1,t_1
1710 daddu t_2,AT
1711 daddu c_2,t_2
1712 sltu AT,c_2,t_2
1713 daddu c_3,AT
1714 dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */
1715 mflo t_1
1716 mfhi t_2
1717 daddu c_1,t_1
1718 sltu AT,c_1,t_1
1719 daddu a2,t_2,AT
1720 daddu c_2,a2
1721 sltu AT,c_2,a2
1722 daddu c_3,AT
1723 daddu c_1,t_1
1724 sltu AT,c_1,t_1
1725 daddu t_2,AT
1726 daddu c_2,t_2
1727 sltu AT,c_2,t_2
1728 daddu c_3,AT
1729 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1730 mflo t_1
1731 mfhi t_2
1732 daddu c_1,t_1
1733 sltu AT,c_1,t_1
1734 daddu t_2,AT
1735 daddu c_2,t_2
1736 sltu AT,c_2,t_2
1737 daddu c_3,AT
1738 sd c_1,48(a0)
1739
1740 dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */
1741 mflo t_1
1742 mfhi t_2
1743 daddu c_2,t_1
1744 sltu AT,c_2,t_1
1745 daddu a2,t_2,AT
1746 daddu c_3,a2
1747 daddu c_2,t_1
1748 sltu AT,c_2,t_1
1749 daddu t_2,AT
1750 daddu c_3,t_2
1751 sltu c_1,c_3,t_2
1752 dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */
1753 mflo t_1
1754 mfhi t_2
1755 daddu c_2,t_1
1756 sltu AT,c_2,t_1
1757 daddu a2,t_2,AT
1758 daddu c_3,a2
1759 sltu AT,c_3,a2
1760 daddu c_1,AT
1761 daddu c_2,t_1
1762 sltu AT,c_2,t_1
1763 daddu t_2,AT
1764 daddu c_3,t_2
1765 sltu AT,c_3,t_2
1766 daddu c_1,AT
1767 dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */
1768 mflo t_1
1769 mfhi t_2
1770 daddu c_2,t_1
1771 sltu AT,c_2,t_1
1772 daddu a2,t_2,AT
1773 daddu c_3,a2
1774 sltu AT,c_3,a2
1775 daddu c_1,AT
1776 daddu c_2,t_1
1777 sltu AT,c_2,t_1
1778 daddu t_2,AT
1779 daddu c_3,t_2
1780 sltu AT,c_3,t_2
1781 daddu c_1,AT
1782 dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */
1783 mflo t_1
1784 mfhi t_2
1785 daddu c_2,t_1
1786 sltu AT,c_2,t_1
1787 daddu a2,t_2,AT
1788 daddu c_3,a2
1789 sltu AT,c_3,a2
1790 daddu c_1,AT
1791 daddu c_2,t_1
1792 sltu AT,c_2,t_1
1793 daddu t_2,AT
1794 daddu c_3,t_2
1795 sltu AT,c_3,t_2
1796 daddu c_1,AT
1797 sd c_2,56(a0)
1798
1799 dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */
1800 mflo t_1
1801 mfhi t_2
1802 daddu c_3,t_1
1803 sltu AT,c_3,t_1
1804 daddu a2,t_2,AT
1805 daddu c_1,a2
1806 daddu c_3,t_1
1807 sltu AT,c_3,t_1
1808 daddu t_2,AT
1809 daddu c_1,t_2
1810 sltu c_2,c_1,t_2
1811 dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */
1812 mflo t_1
1813 mfhi t_2
1814 daddu c_3,t_1
1815 sltu AT,c_3,t_1
1816 daddu a2,t_2,AT
1817 daddu c_1,a2
1818 sltu AT,c_1,a2
1819 daddu c_2,AT
1820 daddu c_3,t_1
1821 sltu AT,c_3,t_1
1822 daddu t_2,AT
1823 daddu c_1,t_2
1824 sltu AT,c_1,t_2
1825 daddu c_2,AT
1826 dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */
1827 mflo t_1
1828 mfhi t_2
1829 daddu c_3,t_1
1830 sltu AT,c_3,t_1
1831 daddu a2,t_2,AT
1832 daddu c_1,a2
1833 sltu AT,c_1,a2
1834 daddu c_2,AT
1835 daddu c_3,t_1
1836 sltu AT,c_3,t_1
1837 daddu t_2,AT
1838 daddu c_1,t_2
1839 sltu AT,c_1,t_2
1840 daddu c_2,AT
1841 dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1842 mflo t_1
1843 mfhi t_2
1844 daddu c_3,t_1
1845 sltu AT,c_3,t_1
1846 daddu t_2,AT
1847 daddu c_1,t_2
1848 sltu AT,c_1,t_2
1849 daddu c_2,AT
1850 sd c_3,64(a0)
1851
1852 dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */
1853 mflo t_1
1854 mfhi t_2
1855 daddu c_1,t_1
1856 sltu AT,c_1,t_1
1857 daddu a2,t_2,AT
1858 daddu c_2,a2
1859 daddu c_1,t_1
1860 sltu AT,c_1,t_1
1861 daddu t_2,AT
1862 daddu c_2,t_2
1863 sltu c_3,c_2,t_2
1864 dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */
1865 mflo t_1
1866 mfhi t_2
1867 daddu c_1,t_1
1868 sltu AT,c_1,t_1
1869 daddu a2,t_2,AT
1870 daddu c_2,a2
1871 sltu AT,c_2,a2
1872 daddu c_3,AT
1873 daddu c_1,t_1
1874 sltu AT,c_1,t_1
1875 daddu t_2,AT
1876 daddu c_2,t_2
1877 sltu AT,c_2,t_2
1878 daddu c_3,AT
1879 dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */
1880 mflo t_1
1881 mfhi t_2
1882 daddu c_1,t_1
1883 sltu AT,c_1,t_1
1884 daddu a2,t_2,AT
1885 daddu c_2,a2
1886 sltu AT,c_2,a2
1887 daddu c_3,AT
1888 daddu c_1,t_1
1889 sltu AT,c_1,t_1
1890 daddu t_2,AT
1891 daddu c_2,t_2
1892 sltu AT,c_2,t_2
1893 daddu c_3,AT
1894 sd c_1,72(a0)
1895
1896 dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */
1897 mflo t_1
1898 mfhi t_2
1899 daddu c_2,t_1
1900 sltu AT,c_2,t_1
1901 daddu a2,t_2,AT
1902 daddu c_3,a2
1903 daddu c_2,t_1
1904 sltu AT,c_2,t_1
1905 daddu t_2,AT
1906 daddu c_3,t_2
1907 sltu c_1,c_3,t_2
1908 dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */
1909 mflo t_1
1910 mfhi t_2
1911 daddu c_2,t_1
1912 sltu AT,c_2,t_1
1913 daddu a2,t_2,AT
1914 daddu c_3,a2
1915 sltu AT,c_3,a2
1916 daddu c_1,AT
1917 daddu c_2,t_1
1918 sltu AT,c_2,t_1
1919 daddu t_2,AT
1920 daddu c_3,t_2
1921 sltu AT,c_3,t_2
1922 daddu c_1,AT
1923 dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1924 mflo t_1
1925 mfhi t_2
1926 daddu c_2,t_1
1927 sltu AT,c_2,t_1
1928 daddu t_2,AT
1929 daddu c_3,t_2
1930 sltu AT,c_3,t_2
1931 daddu c_1,AT
1932 sd c_2,80(a0)
1933
1934 dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */
1935 mflo t_1
1936 mfhi t_2
1937 daddu c_3,t_1
1938 sltu AT,c_3,t_1
1939 daddu a2,t_2,AT
1940 daddu c_1,a2
1941 daddu c_3,t_1
1942 sltu AT,c_3,t_1
1943 daddu t_2,AT
1944 daddu c_1,t_2
1945 sltu c_2,c_1,t_2
1946 dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */
1947 mflo t_1
1948 mfhi t_2
1949 daddu c_3,t_1
1950 sltu AT,c_3,t_1
1951 daddu a2,t_2,AT
1952 daddu c_1,a2
1953 sltu AT,c_1,a2
1954 daddu c_2,AT
1955 daddu c_3,t_1
1956 sltu AT,c_3,t_1
1957 daddu t_2,AT
1958 daddu c_1,t_2
1959 sltu AT,c_1,t_2
1960 daddu c_2,AT
1961 sd c_3,88(a0)
1962
1963 dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */
1964 mflo t_1
1965 mfhi t_2
1966 daddu c_1,t_1
1967 sltu AT,c_1,t_1
1968 daddu a2,t_2,AT
1969 daddu c_2,a2
1970 daddu c_1,t_1
1971 sltu AT,c_1,t_1
1972 daddu t_2,AT
1973 daddu c_2,t_2
1974 sltu c_3,c_2,t_2
1975 dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1976 mflo t_1
1977 mfhi t_2
1978 daddu c_1,t_1
1979 sltu AT,c_1,t_1
1980 daddu t_2,AT
1981 daddu c_2,t_2
1982 sltu AT,c_2,t_2
1983 daddu c_3,AT
1984 sd c_1,96(a0)
1985
1986 dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */
1987 mflo t_1
1988 mfhi t_2
1989 daddu c_2,t_1
1990 sltu AT,c_2,t_1
1991 daddu a2,t_2,AT
1992 daddu c_3,a2
1993 daddu c_2,t_1
1994 sltu AT,c_2,t_1
1995 daddu t_2,AT
1996 daddu c_3,t_2
1997 sltu c_1,c_3,t_2
1998 sd c_2,104(a0)
1999
2000 dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
2001 mflo t_1
2002 mfhi t_2
2003 daddu c_3,t_1
2004 sltu AT,c_3,t_1
2005 daddu t_2,AT
2006 daddu c_1,t_2
2007 sd c_3,112(a0)
2008 sd c_1,120(a0)
2009
2010 jr ra
2011END(bn_sqr_comba8)
2012
2013.align 5
2014LEAF(bn_sqr_comba4)
2015 .set reorder
2016 ld a_0,0(a1)
2017 ld a_1,8(a1)
2018 ld a_2,16(a1)
2019 ld a_3,24(a1)
2020 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
2021 mflo c_1
2022 mfhi c_2
2023 sd c_1,0(a0)
2024
2025 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
2026 mflo t_1
2027 mfhi t_2
2028 daddu c_2,t_1
2029 sltu AT,c_2,t_1
2030 daddu c_3,t_2,AT
2031 daddu c_2,t_1
2032 sltu AT,c_2,t_1
2033 daddu t_2,AT
2034 daddu c_3,t_2
2035 sltu c_1,c_3,t_2
2036 sd c_2,8(a0)
2037
2038 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
2039 mflo t_1
2040 mfhi t_2
2041 daddu c_3,t_1
2042 sltu AT,c_3,t_1
2043 daddu a2,t_2,AT
2044 daddu c_1,a2
2045 daddu c_3,t_1
2046 sltu AT,c_3,t_1
2047 daddu t_2,AT
2048 daddu c_1,t_2
2049 sltu c_2,c_1,t_2
2050 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
2051 mflo t_1
2052 mfhi t_2
2053 daddu c_3,t_1
2054 sltu AT,c_3,t_1
2055 daddu t_2,AT
2056 daddu c_1,t_2
2057 sltu AT,c_1,t_2
2058 daddu c_2,AT
2059 sd c_3,16(a0)
2060
2061 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
2062 mflo t_1
2063 mfhi t_2
2064 daddu c_1,t_1
2065 sltu AT,c_1,t_1
2066 daddu a2,t_2,AT
2067 daddu c_2,a2
2068 daddu c_1,t_1
2069 sltu AT,c_1,t_1
2070 daddu t_2,AT
2071 daddu c_2,t_2
2072 sltu c_3,c_2,t_2
2073 dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */
2074 mflo t_1
2075 mfhi t_2
2076 daddu c_1,t_1
2077 sltu AT,c_1,t_1
2078 daddu a2,t_2,AT
2079 daddu c_2,a2
2080 sltu AT,c_2,a2
2081 daddu c_3,AT
2082 daddu c_1,t_1
2083 sltu AT,c_1,t_1
2084 daddu t_2,AT
2085 daddu c_2,t_2
2086 sltu AT,c_2,t_2
2087 daddu c_3,AT
2088 sd c_1,24(a0)
2089
2090 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
2091 mflo t_1
2092 mfhi t_2
2093 daddu c_2,t_1
2094 sltu AT,c_2,t_1
2095 daddu a2,t_2,AT
2096 daddu c_3,a2
2097 daddu c_2,t_1
2098 sltu AT,c_2,t_1
2099 daddu t_2,AT
2100 daddu c_3,t_2
2101 sltu c_1,c_3,t_2
2102 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
2103 mflo t_1
2104 mfhi t_2
2105 daddu c_2,t_1
2106 sltu AT,c_2,t_1
2107 daddu t_2,AT
2108 daddu c_3,t_2
2109 sltu AT,c_3,t_2
2110 daddu c_1,AT
2111 sd c_2,32(a0)
2112
2113 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
2114 mflo t_1
2115 mfhi t_2
2116 daddu c_3,t_1
2117 sltu AT,c_3,t_1
2118 daddu a2,t_2,AT
2119 daddu c_1,a2
2120 daddu c_3,t_1
2121 sltu AT,c_3,t_1
2122 daddu t_2,AT
2123 daddu c_1,t_2
2124 sltu c_2,c_1,t_2
2125 sd c_3,40(a0)
2126
2127 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
2128 mflo t_1
2129 mfhi t_2
2130 daddu c_1,t_1
2131 sltu AT,c_1,t_1
2132 daddu t_2,AT
2133 daddu c_2,t_2
2134 sd c_1,48(a0)
2135 sd c_2,56(a0)
2136
2137 jr ra
2138END(bn_sqr_comba4)
diff --git a/src/lib/libssl/src/crypto/bn/asm/pa-risc2W.s b/src/lib/libssl/src/crypto/bn/asm/pa-risc2W.s
new file mode 100644
index 0000000000..54b6606252
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/pa-risc2W.s
@@ -0,0 +1,1605 @@
1;
2; PA-RISC 64-bit implementation of bn_asm code
3;
4; This code is approximately 2x faster than the C version
5; for RSA/DSA.
6;
7; See http://devresource.hp.com/ for more details on the PA-RISC
8; architecture. Also see the book "PA-RISC 2.0 Architecture"
9; by Gerry Kane for information on the instruction set architecture.
10;
11; Code written by Chris Ruemmler (with some help from the HP C
12; compiler).
13;
14; The code compiles with HP's assembler
15;
16
17 .level 2.0W
18 .space $TEXT$
19 .subspa $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY
20
21;
22; Global Register definitions used for the routines.
23;
24; Some information about HP's runtime architecture for 64-bits.
25;
26; "Caller save" means the calling function must save the register
27; if it wants the register to be preserved.
28; "Callee save" means if a function uses the register, it must save
29; the value before using it.
30;
31; For the floating point registers
32;
33; "caller save" registers: fr4-fr11, fr22-fr31
34; "callee save" registers: fr12-fr21
35; "special" registers: fr0-fr3 (status and exception registers)
36;
37; For the integer registers
38; value zero : r0
39; "caller save" registers: r1,r19-r26
40; "callee save" registers: r3-r18
41; return register : r2 (rp)
42; return values ; r28 (ret0,ret1)
43; Stack pointer ; r30 (sp)
44; global data pointer ; r27 (dp)
45; argument pointer ; r29 (ap)
46; millicode return ptr ; r31 (also a caller save register)
47
48
49;
50; Arguments to the routines
51;
52r_ptr .reg %r26
53a_ptr .reg %r25
54b_ptr .reg %r24
55num .reg %r24
56w .reg %r23
57n .reg %r23
58
59
60;
61; Globals used in some routines
62;
63
64top_overflow .reg %r29
65high_mask .reg %r22 ; value 0xffffffff80000000L
66
67
68;------------------------------------------------------------------------------
69;
70; bn_mul_add_words
71;
72;BN_ULONG bn_mul_add_words(BN_ULONG *r_ptr, BN_ULONG *a_ptr,
73; int num, BN_ULONG w)
74;
75; arg0 = r_ptr
76; arg1 = a_ptr
77; arg2 = num
78; arg3 = w
79;
80; Local register definitions
81;
82
83fm1 .reg %fr22
84fm .reg %fr23
85ht_temp .reg %fr24
86ht_temp_1 .reg %fr25
87lt_temp .reg %fr26
88lt_temp_1 .reg %fr27
89fm1_1 .reg %fr28
90fm_1 .reg %fr29
91
92fw_h .reg %fr7L
93fw_l .reg %fr7R
94fw .reg %fr7
95
96fht_0 .reg %fr8L
97flt_0 .reg %fr8R
98t_float_0 .reg %fr8
99
100fht_1 .reg %fr9L
101flt_1 .reg %fr9R
102t_float_1 .reg %fr9
103
104tmp_0 .reg %r31
105tmp_1 .reg %r21
106m_0 .reg %r20
107m_1 .reg %r19
108ht_0 .reg %r1
109ht_1 .reg %r3
110lt_0 .reg %r4
111lt_1 .reg %r5
112m1_0 .reg %r6
113m1_1 .reg %r7
114rp_val .reg %r8
115rp_val_1 .reg %r9
116
117bn_mul_add_words
118 .export bn_mul_add_words,entry,NO_RELOCATION,LONG_RETURN
119 .proc
120 .callinfo frame=128
121 .entry
122 .align 64
123
124 STD %r3,0(%sp) ; save r3
125 STD %r4,8(%sp) ; save r4
126 NOP ; Needed to make the loop 16-byte aligned
127 NOP ; Needed to make the loop 16-byte aligned
128
129 STD %r5,16(%sp) ; save r5
130 STD %r6,24(%sp) ; save r6
131 STD %r7,32(%sp) ; save r7
132 STD %r8,40(%sp) ; save r8
133
134 STD %r9,48(%sp) ; save r9
135 COPY %r0,%ret0 ; return 0 by default
136 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
137 STD w,56(%sp) ; store w on stack
138
139 CMPIB,>= 0,num,bn_mul_add_words_exit ; if (num <= 0) then exit
140 LDO 128(%sp),%sp ; bump stack
141
142 ;
143 ; The loop is unrolled twice, so if there is only 1 number
144 ; then go straight to the cleanup code.
145 ;
146 CMPIB,= 1,num,bn_mul_add_words_single_top
147 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
148
149 ;
150 ; This loop is unrolled 2 times (64-byte aligned as well)
151 ;
152 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
153 ; two 32-bit mutiplies can be issued per cycle.
154 ;
155bn_mul_add_words_unroll2
156
157 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
158 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
159 LDD 0(r_ptr),rp_val ; rp[0]
160 LDD 8(r_ptr),rp_val_1 ; rp[1]
161
162 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
163 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = fht_1*fw_l
164 FSTD fm1,-16(%sp) ; -16(sp) = m1[0]
165 FSTD fm1_1,-48(%sp) ; -48(sp) = m1[1]
166
167 XMPYU flt_0,fw_h,fm ; m[0] = flt_0*fw_h
168 XMPYU flt_1,fw_h,fm_1 ; m[1] = flt_1*fw_h
169 FSTD fm,-8(%sp) ; -8(sp) = m[0]
170 FSTD fm_1,-40(%sp) ; -40(sp) = m[1]
171
172 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
173 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp_1 = fht_1*fw_h
174 FSTD ht_temp,-24(%sp) ; -24(sp) = ht_temp
175 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht_temp_1
176
177 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
178 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
179 FSTD lt_temp,-32(%sp) ; -32(sp) = lt_temp
180 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt_temp_1
181
182 LDD -8(%sp),m_0 ; m[0]
183 LDD -40(%sp),m_1 ; m[1]
184 LDD -16(%sp),m1_0 ; m1[0]
185 LDD -48(%sp),m1_1 ; m1[1]
186
187 LDD -24(%sp),ht_0 ; ht[0]
188 LDD -56(%sp),ht_1 ; ht[1]
189 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m[0] + m1[0];
190 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m[1] + m1[1];
191
192 LDD -32(%sp),lt_0
193 LDD -64(%sp),lt_1
194 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m[0] < m1[0])
195 ADD,L ht_0,top_overflow,ht_0 ; ht[0] += (1<<32)
196
197 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m[1] < m1[1])
198 ADD,L ht_1,top_overflow,ht_1 ; ht[1] += (1<<32)
199 EXTRD,U tmp_0,31,32,m_0 ; m[0]>>32
200 DEPD,Z tmp_0,31,32,m1_0 ; m1[0] = m[0]<<32
201
202 EXTRD,U tmp_1,31,32,m_1 ; m[1]>>32
203 DEPD,Z tmp_1,31,32,m1_1 ; m1[1] = m[1]<<32
204 ADD,L ht_0,m_0,ht_0 ; ht[0]+= (m[0]>>32)
205 ADD,L ht_1,m_1,ht_1 ; ht[1]+= (m[1]>>32)
206
207 ADD lt_0,m1_0,lt_0 ; lt[0] = lt[0]+m1[0];
208 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
209 ADD lt_1,m1_1,lt_1 ; lt[1] = lt[1]+m1[1];
210 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
211
212 ADD %ret0,lt_0,lt_0 ; lt[0] = lt[0] + c;
213 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
214 ADD lt_0,rp_val,lt_0 ; lt[0] = lt[0]+rp[0]
215 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
216
217 LDO -2(num),num ; num = num - 2;
218 ADD ht_0,lt_1,lt_1 ; lt[1] = lt[1] + ht_0 (c);
219 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
220 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
221
222 ADD lt_1,rp_val_1,lt_1 ; lt[1] = lt[1]+rp[1]
223 ADD,DC ht_1,%r0,%ret0 ; ht[1]++
224 LDO 16(a_ptr),a_ptr ; a_ptr += 2
225
226 STD lt_1,8(r_ptr) ; rp[1] = lt[1]
227 CMPIB,<= 2,num,bn_mul_add_words_unroll2 ; go again if more to do
228 LDO 16(r_ptr),r_ptr ; r_ptr += 2
229
230 CMPIB,=,N 0,num,bn_mul_add_words_exit ; are we done, or cleanup last one
231
232 ;
233 ; Top of loop aligned on 64-byte boundary
234 ;
235bn_mul_add_words_single_top
236 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
237 LDD 0(r_ptr),rp_val ; rp[0]
238 LDO 8(a_ptr),a_ptr ; a_ptr++
239 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
240 FSTD fm1,-16(%sp) ; -16(sp) = m1
241 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
242 FSTD fm,-8(%sp) ; -8(sp) = m
243 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
244 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
245 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
246 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
247
248 LDD -8(%sp),m_0
249 LDD -16(%sp),m1_0 ; m1 = temp1
250 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
251 LDD -24(%sp),ht_0
252 LDD -32(%sp),lt_0
253
254 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
255 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
256
257 EXTRD,U tmp_0,31,32,m_0 ; m>>32
258 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
259
260 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
261 ADD lt_0,m1_0,tmp_0 ; tmp_0 = lt+m1;
262 ADD,DC ht_0,%r0,ht_0 ; ht++
263 ADD %ret0,tmp_0,lt_0 ; lt = lt + c;
264 ADD,DC ht_0,%r0,ht_0 ; ht++
265 ADD lt_0,rp_val,lt_0 ; lt = lt+rp[0]
266 ADD,DC ht_0,%r0,%ret0 ; ht++
267 STD lt_0,0(r_ptr) ; rp[0] = lt
268
269bn_mul_add_words_exit
270 .EXIT
271 LDD -80(%sp),%r9 ; restore r9
272 LDD -88(%sp),%r8 ; restore r8
273 LDD -96(%sp),%r7 ; restore r7
274 LDD -104(%sp),%r6 ; restore r6
275 LDD -112(%sp),%r5 ; restore r5
276 LDD -120(%sp),%r4 ; restore r4
277 BVE (%rp)
278 LDD,MB -128(%sp),%r3 ; restore r3
279 .PROCEND ;in=23,24,25,26,29;out=28;
280
281;----------------------------------------------------------------------------
282;
283;BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
284;
285; arg0 = rp
286; arg1 = ap
287; arg2 = num
288; arg3 = w
289
290bn_mul_words
291 .proc
292 .callinfo frame=128
293 .entry
294 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
295 .align 64
296
297 STD %r3,0(%sp) ; save r3
298 STD %r4,8(%sp) ; save r4
299 STD %r5,16(%sp) ; save r5
300 STD %r6,24(%sp) ; save r6
301
302 STD %r7,32(%sp) ; save r7
303 COPY %r0,%ret0 ; return 0 by default
304 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
305 STD w,56(%sp) ; w on stack
306
307 CMPIB,>= 0,num,bn_mul_words_exit
308 LDO 128(%sp),%sp ; bump stack
309
310 ;
311 ; See if only 1 word to do, thus just do cleanup
312 ;
313 CMPIB,= 1,num,bn_mul_words_single_top
314 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
315
316 ;
317 ; This loop is unrolled 2 times (64-byte aligned as well)
318 ;
319 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
320 ; two 32-bit mutiplies can be issued per cycle.
321 ;
322bn_mul_words_unroll2
323
324 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
325 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
326 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
327 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = ht*fw_l
328
329 FSTD fm1,-16(%sp) ; -16(sp) = m1
330 FSTD fm1_1,-48(%sp) ; -48(sp) = m1
331 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
332 XMPYU flt_1,fw_h,fm_1 ; m = lt*fw_h
333
334 FSTD fm,-8(%sp) ; -8(sp) = m
335 FSTD fm_1,-40(%sp) ; -40(sp) = m
336 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
337 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp = ht*fw_h
338
339 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
340 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht
341 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
342 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
343
344 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
345 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt
346 LDD -8(%sp),m_0
347 LDD -40(%sp),m_1
348
349 LDD -16(%sp),m1_0
350 LDD -48(%sp),m1_1
351 LDD -24(%sp),ht_0
352 LDD -56(%sp),ht_1
353
354 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m + m1;
355 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m + m1;
356 LDD -32(%sp),lt_0
357 LDD -64(%sp),lt_1
358
359 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m < m1)
360 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
361 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m < m1)
362 ADD,L ht_1,top_overflow,ht_1 ; ht += (1<<32)
363
364 EXTRD,U tmp_0,31,32,m_0 ; m>>32
365 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
366 EXTRD,U tmp_1,31,32,m_1 ; m>>32
367 DEPD,Z tmp_1,31,32,m1_1 ; m1 = m<<32
368
369 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
370 ADD,L ht_1,m_1,ht_1 ; ht+= (m>>32)
371 ADD lt_0,m1_0,lt_0 ; lt = lt+m1;
372 ADD,DC ht_0,%r0,ht_0 ; ht++
373
374 ADD lt_1,m1_1,lt_1 ; lt = lt+m1;
375 ADD,DC ht_1,%r0,ht_1 ; ht++
376 ADD %ret0,lt_0,lt_0 ; lt = lt + c (ret0);
377 ADD,DC ht_0,%r0,ht_0 ; ht++
378
379 ADD ht_0,lt_1,lt_1 ; lt = lt + c (ht_0)
380 ADD,DC ht_1,%r0,ht_1 ; ht++
381 STD lt_0,0(r_ptr) ; rp[0] = lt
382 STD lt_1,8(r_ptr) ; rp[1] = lt
383
384 COPY ht_1,%ret0 ; carry = ht
385 LDO -2(num),num ; num = num - 2;
386 LDO 16(a_ptr),a_ptr ; ap += 2
387 CMPIB,<= 2,num,bn_mul_words_unroll2
388 LDO 16(r_ptr),r_ptr ; rp++
389
390 CMPIB,=,N 0,num,bn_mul_words_exit ; are we done?
391
392 ;
393 ; Top of loop aligned on 64-byte boundary
394 ;
395bn_mul_words_single_top
396 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
397
398 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
399 FSTD fm1,-16(%sp) ; -16(sp) = m1
400 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
401 FSTD fm,-8(%sp) ; -8(sp) = m
402 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
403 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
404 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
405 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
406
407 LDD -8(%sp),m_0
408 LDD -16(%sp),m1_0
409 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
410 LDD -24(%sp),ht_0
411 LDD -32(%sp),lt_0
412
413 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
414 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
415
416 EXTRD,U tmp_0,31,32,m_0 ; m>>32
417 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
418
419 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
420 ADD lt_0,m1_0,lt_0 ; lt= lt+m1;
421 ADD,DC ht_0,%r0,ht_0 ; ht++
422
423 ADD %ret0,lt_0,lt_0 ; lt = lt + c;
424 ADD,DC ht_0,%r0,ht_0 ; ht++
425
426 COPY ht_0,%ret0 ; copy carry
427 STD lt_0,0(r_ptr) ; rp[0] = lt
428
429bn_mul_words_exit
430 .EXIT
431 LDD -96(%sp),%r7 ; restore r7
432 LDD -104(%sp),%r6 ; restore r6
433 LDD -112(%sp),%r5 ; restore r5
434 LDD -120(%sp),%r4 ; restore r4
435 BVE (%rp)
436 LDD,MB -128(%sp),%r3 ; restore r3
437 .PROCEND ;in=23,24,25,26,29;out=28;
438
439;----------------------------------------------------------------------------
440;
441;void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
442;
443; arg0 = rp
444; arg1 = ap
445; arg2 = num
446;
447
448bn_sqr_words
449 .proc
450 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
451 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
452 .entry
453 .align 64
454
455 STD %r3,0(%sp) ; save r3
456 STD %r4,8(%sp) ; save r4
457 NOP
458 STD %r5,16(%sp) ; save r5
459
460 CMPIB,>= 0,num,bn_sqr_words_exit
461 LDO 128(%sp),%sp ; bump stack
462
463 ;
464 ; If only 1, the goto straight to cleanup
465 ;
466 CMPIB,= 1,num,bn_sqr_words_single_top
467 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
468
469 ;
470 ; This loop is unrolled 2 times (64-byte aligned as well)
471 ;
472
473bn_sqr_words_unroll2
474 FLDD 0(a_ptr),t_float_0 ; a[0]
475 FLDD 8(a_ptr),t_float_1 ; a[1]
476 XMPYU fht_0,flt_0,fm ; m[0]
477 XMPYU fht_1,flt_1,fm_1 ; m[1]
478
479 FSTD fm,-24(%sp) ; store m[0]
480 FSTD fm_1,-56(%sp) ; store m[1]
481 XMPYU flt_0,flt_0,lt_temp ; lt[0]
482 XMPYU flt_1,flt_1,lt_temp_1 ; lt[1]
483
484 FSTD lt_temp,-16(%sp) ; store lt[0]
485 FSTD lt_temp_1,-48(%sp) ; store lt[1]
486 XMPYU fht_0,fht_0,ht_temp ; ht[0]
487 XMPYU fht_1,fht_1,ht_temp_1 ; ht[1]
488
489 FSTD ht_temp,-8(%sp) ; store ht[0]
490 FSTD ht_temp_1,-40(%sp) ; store ht[1]
491 LDD -24(%sp),m_0
492 LDD -56(%sp),m_1
493
494 AND m_0,high_mask,tmp_0 ; m[0] & Mask
495 AND m_1,high_mask,tmp_1 ; m[1] & Mask
496 DEPD,Z m_0,30,31,m_0 ; m[0] << 32+1
497 DEPD,Z m_1,30,31,m_1 ; m[1] << 32+1
498
499 LDD -16(%sp),lt_0
500 LDD -48(%sp),lt_1
501 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m[0]&Mask >> 32-1
502 EXTRD,U tmp_1,32,33,tmp_1 ; tmp_1 = m[1]&Mask >> 32-1
503
504 LDD -8(%sp),ht_0
505 LDD -40(%sp),ht_1
506 ADD,L ht_0,tmp_0,ht_0 ; ht[0] += tmp_0
507 ADD,L ht_1,tmp_1,ht_1 ; ht[1] += tmp_1
508
509 ADD lt_0,m_0,lt_0 ; lt = lt+m
510 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
511 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
512 STD ht_0,8(r_ptr) ; rp[1] = ht[1]
513
514 ADD lt_1,m_1,lt_1 ; lt = lt+m
515 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
516 STD lt_1,16(r_ptr) ; rp[2] = lt[1]
517 STD ht_1,24(r_ptr) ; rp[3] = ht[1]
518
519 LDO -2(num),num ; num = num - 2;
520 LDO 16(a_ptr),a_ptr ; ap += 2
521 CMPIB,<= 2,num,bn_sqr_words_unroll2
522 LDO 32(r_ptr),r_ptr ; rp += 4
523
524 CMPIB,=,N 0,num,bn_sqr_words_exit ; are we done?
525
526 ;
527 ; Top of loop aligned on 64-byte boundary
528 ;
529bn_sqr_words_single_top
530 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
531
532 XMPYU fht_0,flt_0,fm ; m
533 FSTD fm,-24(%sp) ; store m
534
535 XMPYU flt_0,flt_0,lt_temp ; lt
536 FSTD lt_temp,-16(%sp) ; store lt
537
538 XMPYU fht_0,fht_0,ht_temp ; ht
539 FSTD ht_temp,-8(%sp) ; store ht
540
541 LDD -24(%sp),m_0 ; load m
542 AND m_0,high_mask,tmp_0 ; m & Mask
543 DEPD,Z m_0,30,31,m_0 ; m << 32+1
544 LDD -16(%sp),lt_0 ; lt
545
546 LDD -8(%sp),ht_0 ; ht
547 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m&Mask >> 32-1
548 ADD m_0,lt_0,lt_0 ; lt = lt+m
549 ADD,L ht_0,tmp_0,ht_0 ; ht += tmp_0
550 ADD,DC ht_0,%r0,ht_0 ; ht++
551
552 STD lt_0,0(r_ptr) ; rp[0] = lt
553 STD ht_0,8(r_ptr) ; rp[1] = ht
554
555bn_sqr_words_exit
556 .EXIT
557 LDD -112(%sp),%r5 ; restore r5
558 LDD -120(%sp),%r4 ; restore r4
559 BVE (%rp)
560 LDD,MB -128(%sp),%r3
561 .PROCEND ;in=23,24,25,26,29;out=28;
562
563
564;----------------------------------------------------------------------------
565;
566;BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
567;
568; arg0 = rp
569; arg1 = ap
570; arg2 = bp
571; arg3 = n
572
573t .reg %r22
574b .reg %r21
575l .reg %r20
576
577bn_add_words
578 .proc
579 .entry
580 .callinfo
581 .EXPORT bn_add_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
582 .align 64
583
584 CMPIB,>= 0,n,bn_add_words_exit
585 COPY %r0,%ret0 ; return 0 by default
586
587 ;
588 ; If 2 or more numbers do the loop
589 ;
590 CMPIB,= 1,n,bn_add_words_single_top
591 NOP
592
593 ;
594 ; This loop is unrolled 2 times (64-byte aligned as well)
595 ;
596bn_add_words_unroll2
597 LDD 0(a_ptr),t
598 LDD 0(b_ptr),b
599 ADD t,%ret0,t ; t = t+c;
600 ADD,DC %r0,%r0,%ret0 ; set c to carry
601 ADD t,b,l ; l = t + b[0]
602 ADD,DC %ret0,%r0,%ret0 ; c+= carry
603 STD l,0(r_ptr)
604
605 LDD 8(a_ptr),t
606 LDD 8(b_ptr),b
607 ADD t,%ret0,t ; t = t+c;
608 ADD,DC %r0,%r0,%ret0 ; set c to carry
609 ADD t,b,l ; l = t + b[0]
610 ADD,DC %ret0,%r0,%ret0 ; c+= carry
611 STD l,8(r_ptr)
612
613 LDO -2(n),n
614 LDO 16(a_ptr),a_ptr
615 LDO 16(b_ptr),b_ptr
616
617 CMPIB,<= 2,n,bn_add_words_unroll2
618 LDO 16(r_ptr),r_ptr
619
620 CMPIB,=,N 0,n,bn_add_words_exit ; are we done?
621
622bn_add_words_single_top
623 LDD 0(a_ptr),t
624 LDD 0(b_ptr),b
625
626 ADD t,%ret0,t ; t = t+c;
627 ADD,DC %r0,%r0,%ret0 ; set c to carry (could use CMPCLR??)
628 ADD t,b,l ; l = t + b[0]
629 ADD,DC %ret0,%r0,%ret0 ; c+= carry
630 STD l,0(r_ptr)
631
632bn_add_words_exit
633 .EXIT
634 BVE (%rp)
635 NOP
636 .PROCEND ;in=23,24,25,26,29;out=28;
637
638;----------------------------------------------------------------------------
639;
640;BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
641;
642; arg0 = rp
643; arg1 = ap
644; arg2 = bp
645; arg3 = n
646
647t1 .reg %r22
648t2 .reg %r21
649sub_tmp1 .reg %r20
650sub_tmp2 .reg %r19
651
652
653bn_sub_words
654 .proc
655 .callinfo
656 .EXPORT bn_sub_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
657 .entry
658 .align 64
659
660 CMPIB,>= 0,n,bn_sub_words_exit
661 COPY %r0,%ret0 ; return 0 by default
662
663 ;
664 ; If 2 or more numbers do the loop
665 ;
666 CMPIB,= 1,n,bn_sub_words_single_top
667 NOP
668
669 ;
670 ; This loop is unrolled 2 times (64-byte aligned as well)
671 ;
672bn_sub_words_unroll2
673 LDD 0(a_ptr),t1
674 LDD 0(b_ptr),t2
675 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
676 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
677
678 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
679 LDO 1(%r0),sub_tmp2
680
681 CMPCLR,*= t1,t2,%r0
682 COPY sub_tmp2,%ret0
683 STD sub_tmp1,0(r_ptr)
684
685 LDD 8(a_ptr),t1
686 LDD 8(b_ptr),t2
687 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
688 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
689 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
690 LDO 1(%r0),sub_tmp2
691
692 CMPCLR,*= t1,t2,%r0
693 COPY sub_tmp2,%ret0
694 STD sub_tmp1,8(r_ptr)
695
696 LDO -2(n),n
697 LDO 16(a_ptr),a_ptr
698 LDO 16(b_ptr),b_ptr
699
700 CMPIB,<= 2,n,bn_sub_words_unroll2
701 LDO 16(r_ptr),r_ptr
702
703 CMPIB,=,N 0,n,bn_sub_words_exit ; are we done?
704
705bn_sub_words_single_top
706 LDD 0(a_ptr),t1
707 LDD 0(b_ptr),t2
708 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
709 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
710 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
711 LDO 1(%r0),sub_tmp2
712
713 CMPCLR,*= t1,t2,%r0
714 COPY sub_tmp2,%ret0
715
716 STD sub_tmp1,0(r_ptr)
717
718bn_sub_words_exit
719 .EXIT
720 BVE (%rp)
721 NOP
722 .PROCEND ;in=23,24,25,26,29;out=28;
723
724;------------------------------------------------------------------------------
725;
726; unsigned long bn_div_words(unsigned long h, unsigned long l, unsigned long d)
727;
728; arg0 = h
729; arg1 = l
730; arg2 = d
731;
732; This is mainly just modified assembly from the compiler, thus the
733; lack of variable names.
734;
735;------------------------------------------------------------------------------
736bn_div_words
737 .proc
738 .callinfo CALLER,FRAME=272,ENTRY_GR=%r10,SAVE_RP,ARGS_SAVED,ORDERING_AWARE
739 .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
740 .IMPORT BN_num_bits_word,CODE,NO_RELOCATION
741 .IMPORT __iob,DATA
742 .IMPORT fprintf,CODE,NO_RELOCATION
743 .IMPORT abort,CODE,NO_RELOCATION
744 .IMPORT $$div2U,MILLICODE
745 .entry
746 STD %r2,-16(%r30)
747 STD,MA %r3,352(%r30)
748 STD %r4,-344(%r30)
749 STD %r5,-336(%r30)
750 STD %r6,-328(%r30)
751 STD %r7,-320(%r30)
752 STD %r8,-312(%r30)
753 STD %r9,-304(%r30)
754 STD %r10,-296(%r30)
755
756 STD %r27,-288(%r30) ; save gp
757
758 COPY %r24,%r3 ; save d
759 COPY %r26,%r4 ; save h (high 64-bits)
760 LDO -1(%r0),%ret0 ; return -1 by default
761
762 CMPB,*= %r0,%arg2,$D3 ; if (d == 0)
763 COPY %r25,%r5 ; save l (low 64-bits)
764
765 LDO -48(%r30),%r29 ; create ap
766 .CALL ;in=26,29;out=28;
767 B,L BN_num_bits_word,%r2
768 COPY %r3,%r26
769 LDD -288(%r30),%r27 ; restore gp
770 LDI 64,%r21
771
772 CMPB,= %r21,%ret0,$00000012 ;if (i == 64) (forward)
773 COPY %ret0,%r24 ; i
774 MTSARCM %r24
775 DEPDI,Z -1,%sar,1,%r29
776 CMPB,*<<,N %r29,%r4,bn_div_err_case ; if (h > 1<<i) (forward)
777
778$00000012
779 SUBI 64,%r24,%r31 ; i = 64 - i;
780 CMPCLR,*<< %r4,%r3,%r0 ; if (h >= d)
781 SUB %r4,%r3,%r4 ; h -= d
782 CMPB,= %r31,%r0,$0000001A ; if (i)
783 COPY %r0,%r10 ; ret = 0
784 MTSARCM %r31 ; i to shift
785 DEPD,Z %r3,%sar,64,%r3 ; d <<= i;
786 SUBI 64,%r31,%r19 ; 64 - i; redundent
787 MTSAR %r19 ; (64 -i) to shift
788 SHRPD %r4,%r5,%sar,%r4 ; l>> (64-i)
789 MTSARCM %r31 ; i to shift
790 DEPD,Z %r5,%sar,64,%r5 ; l <<= i;
791
792$0000001A
793 DEPDI,Z -1,31,32,%r19
794 EXTRD,U %r3,31,32,%r6 ; dh=(d&0xfff)>>32
795 EXTRD,U %r3,63,32,%r8 ; dl = d&0xffffff
796 LDO 2(%r0),%r9
797 STD %r3,-280(%r30) ; "d" to stack
798
799$0000001C
800 DEPDI,Z -1,63,32,%r29 ;
801 EXTRD,U %r4,31,32,%r31 ; h >> 32
802 CMPB,*=,N %r31,%r6,$D2 ; if ((h>>32) != dh)(forward) div
803 COPY %r4,%r26
804 EXTRD,U %r4,31,32,%r25
805 COPY %r6,%r24
806 .CALL ;in=23,24,25,26;out=20,21,22,28,29; (MILLICALL)
807 B,L $$div2U,%r2
808 EXTRD,U %r6,31,32,%r23
809 DEPD %r28,31,32,%r29
810$D2
811 STD %r29,-272(%r30) ; q
812 AND %r5,%r19,%r24 ; t & 0xffffffff00000000;
813 EXTRD,U %r24,31,32,%r24 ; ???
814 FLDD -272(%r30),%fr7 ; q
815 FLDD -280(%r30),%fr8 ; d
816 XMPYU %fr8L,%fr7L,%fr10
817 FSTD %fr10,-256(%r30)
818 XMPYU %fr8L,%fr7R,%fr22
819 FSTD %fr22,-264(%r30)
820 XMPYU %fr8R,%fr7L,%fr11
821 XMPYU %fr8R,%fr7R,%fr23
822 FSTD %fr11,-232(%r30)
823 FSTD %fr23,-240(%r30)
824 LDD -256(%r30),%r28
825 DEPD,Z %r28,31,32,%r2
826 LDD -264(%r30),%r20
827 ADD,L %r20,%r2,%r31
828 LDD -232(%r30),%r22
829 DEPD,Z %r22,31,32,%r22
830 LDD -240(%r30),%r21
831 B $00000024 ; enter loop
832 ADD,L %r21,%r22,%r23
833
834$0000002A
835 LDO -1(%r29),%r29
836 SUB %r23,%r8,%r23
837$00000024
838 SUB %r4,%r31,%r25
839 AND %r25,%r19,%r26
840 CMPB,*<>,N %r0,%r26,$00000046 ; (forward)
841 DEPD,Z %r25,31,32,%r20
842 OR %r20,%r24,%r21
843 CMPB,*<<,N %r21,%r23,$0000002A ;(backward)
844 SUB %r31,%r6,%r31
845;-------------Break path---------------------
846
847$00000046
848 DEPD,Z %r23,31,32,%r25 ;tl
849 EXTRD,U %r23,31,32,%r26 ;t
850 AND %r25,%r19,%r24 ;tl = (tl<<32)&0xfffffff0000000L
851 ADD,L %r31,%r26,%r31 ;th += t;
852 CMPCLR,*>>= %r5,%r24,%r0 ;if (l<tl)
853 LDO 1(%r31),%r31 ; th++;
854 CMPB,*<<=,N %r31,%r4,$00000036 ;if (n < th) (forward)
855 LDO -1(%r29),%r29 ;q--;
856 ADD,L %r4,%r3,%r4 ;h += d;
857$00000036
858 ADDIB,=,N -1,%r9,$D1 ;if (--count == 0) break (forward)
859 SUB %r5,%r24,%r28 ; l -= tl;
860 SUB %r4,%r31,%r24 ; h -= th;
861 SHRPD %r24,%r28,32,%r4 ; h = ((h<<32)|(l>>32));
862 DEPD,Z %r29,31,32,%r10 ; ret = q<<32
863 b $0000001C
864 DEPD,Z %r28,31,32,%r5 ; l = l << 32
865
866$D1
867 OR %r10,%r29,%r28 ; ret |= q
868$D3
869 LDD -368(%r30),%r2
870$D0
871 LDD -296(%r30),%r10
872 LDD -304(%r30),%r9
873 LDD -312(%r30),%r8
874 LDD -320(%r30),%r7
875 LDD -328(%r30),%r6
876 LDD -336(%r30),%r5
877 LDD -344(%r30),%r4
878 BVE (%r2)
879 .EXIT
880 LDD,MB -352(%r30),%r3
881
882bn_div_err_case
883 MFIA %r6
884 ADDIL L'bn_div_words-bn_div_err_case,%r6,%r1
885 LDO R'bn_div_words-bn_div_err_case(%r1),%r6
886 ADDIL LT'__iob,%r27,%r1
887 LDD RT'__iob(%r1),%r26
888 ADDIL L'C$4-bn_div_words,%r6,%r1
889 LDO R'C$4-bn_div_words(%r1),%r25
890 LDO 64(%r26),%r26
891 .CALL ;in=24,25,26,29;out=28;
892 B,L fprintf,%r2
893 LDO -48(%r30),%r29
894 LDD -288(%r30),%r27
895 .CALL ;in=29;
896 B,L abort,%r2
897 LDO -48(%r30),%r29
898 LDD -288(%r30),%r27
899 B $D0
900 LDD -368(%r30),%r2
901 .PROCEND ;in=24,25,26,29;out=28;
902
903;----------------------------------------------------------------------------
904;
905; Registers to hold 64-bit values to manipulate. The "L" part
906; of the register corresponds to the upper 32-bits, while the "R"
907; part corresponds to the lower 32-bits
908;
909; Note, that when using b6 and b7, the code must save these before
910; using them because they are callee save registers
911;
912;
913; Floating point registers to use to save values that
914; are manipulated. These don't collide with ftemp1-6 and
915; are all caller save registers
916;
917a0 .reg %fr22
918a0L .reg %fr22L
919a0R .reg %fr22R
920
921a1 .reg %fr23
922a1L .reg %fr23L
923a1R .reg %fr23R
924
925a2 .reg %fr24
926a2L .reg %fr24L
927a2R .reg %fr24R
928
929a3 .reg %fr25
930a3L .reg %fr25L
931a3R .reg %fr25R
932
933a4 .reg %fr26
934a4L .reg %fr26L
935a4R .reg %fr26R
936
937a5 .reg %fr27
938a5L .reg %fr27L
939a5R .reg %fr27R
940
941a6 .reg %fr28
942a6L .reg %fr28L
943a6R .reg %fr28R
944
945a7 .reg %fr29
946a7L .reg %fr29L
947a7R .reg %fr29R
948
949b0 .reg %fr30
950b0L .reg %fr30L
951b0R .reg %fr30R
952
953b1 .reg %fr31
954b1L .reg %fr31L
955b1R .reg %fr31R
956
957;
958; Temporary floating point variables, these are all caller save
959; registers
960;
961ftemp1 .reg %fr4
962ftemp2 .reg %fr5
963ftemp3 .reg %fr6
964ftemp4 .reg %fr7
965
966;
967; The B set of registers when used.
968;
969
970b2 .reg %fr8
971b2L .reg %fr8L
972b2R .reg %fr8R
973
974b3 .reg %fr9
975b3L .reg %fr9L
976b3R .reg %fr9R
977
978b4 .reg %fr10
979b4L .reg %fr10L
980b4R .reg %fr10R
981
982b5 .reg %fr11
983b5L .reg %fr11L
984b5R .reg %fr11R
985
986b6 .reg %fr12
987b6L .reg %fr12L
988b6R .reg %fr12R
989
990b7 .reg %fr13
991b7L .reg %fr13L
992b7R .reg %fr13R
993
994c1 .reg %r21 ; only reg
995temp1 .reg %r20 ; only reg
996temp2 .reg %r19 ; only reg
997temp3 .reg %r31 ; only reg
998
999m1 .reg %r28
1000c2 .reg %r23
1001high_one .reg %r1
1002ht .reg %r6
1003lt .reg %r5
1004m .reg %r4
1005c3 .reg %r3
1006
1007SQR_ADD_C .macro A0L,A0R,C1,C2,C3
1008 XMPYU A0L,A0R,ftemp1 ; m
1009 FSTD ftemp1,-24(%sp) ; store m
1010
1011 XMPYU A0R,A0R,ftemp2 ; lt
1012 FSTD ftemp2,-16(%sp) ; store lt
1013
1014 XMPYU A0L,A0L,ftemp3 ; ht
1015 FSTD ftemp3,-8(%sp) ; store ht
1016
1017 LDD -24(%sp),m ; load m
1018 AND m,high_mask,temp2 ; m & Mask
1019 DEPD,Z m,30,31,temp3 ; m << 32+1
1020 LDD -16(%sp),lt ; lt
1021
1022 LDD -8(%sp),ht ; ht
1023 EXTRD,U temp2,32,33,temp1 ; temp1 = m&Mask >> 32-1
1024 ADD temp3,lt,lt ; lt = lt+m
1025 ADD,L ht,temp1,ht ; ht += temp1
1026 ADD,DC ht,%r0,ht ; ht++
1027
1028 ADD C1,lt,C1 ; c1=c1+lt
1029 ADD,DC ht,%r0,ht ; ht++
1030
1031 ADD C2,ht,C2 ; c2=c2+ht
1032 ADD,DC C3,%r0,C3 ; c3++
1033.endm
1034
1035SQR_ADD_C2 .macro A0L,A0R,A1L,A1R,C1,C2,C3
1036 XMPYU A0L,A1R,ftemp1 ; m1 = bl*ht
1037 FSTD ftemp1,-16(%sp) ;
1038 XMPYU A0R,A1L,ftemp2 ; m = bh*lt
1039 FSTD ftemp2,-8(%sp) ;
1040 XMPYU A0R,A1R,ftemp3 ; lt = bl*lt
1041 FSTD ftemp3,-32(%sp)
1042 XMPYU A0L,A1L,ftemp4 ; ht = bh*ht
1043 FSTD ftemp4,-24(%sp) ;
1044
1045 LDD -8(%sp),m ; r21 = m
1046 LDD -16(%sp),m1 ; r19 = m1
1047 ADD,L m,m1,m ; m+m1
1048
1049 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1050 LDD -24(%sp),ht ; r24 = ht
1051
1052 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1053 ADD,L ht,high_one,ht ; ht+=high_one
1054
1055 EXTRD,U m,31,32,temp1 ; m >> 32
1056 LDD -32(%sp),lt ; lt
1057 ADD,L ht,temp1,ht ; ht+= m>>32
1058 ADD lt,temp3,lt ; lt = lt+m1
1059 ADD,DC ht,%r0,ht ; ht++
1060
1061 ADD ht,ht,ht ; ht=ht+ht;
1062 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1063
1064 ADD lt,lt,lt ; lt=lt+lt;
1065 ADD,DC ht,%r0,ht ; add in carry (ht++)
1066
1067 ADD C1,lt,C1 ; c1=c1+lt
1068 ADD,DC,*NUV ht,%r0,ht ; add in carry (ht++)
1069 LDO 1(C3),C3 ; bump c3 if overflow,nullify otherwise
1070
1071 ADD C2,ht,C2 ; c2 = c2 + ht
1072 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1073.endm
1074
1075;
1076;void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
1077; arg0 = r_ptr
1078; arg1 = a_ptr
1079;
1080
1081bn_sqr_comba8
1082 .PROC
1083 .CALLINFO FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1084 .EXPORT bn_sqr_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1085 .ENTRY
1086 .align 64
1087
1088 STD %r3,0(%sp) ; save r3
1089 STD %r4,8(%sp) ; save r4
1090 STD %r5,16(%sp) ; save r5
1091 STD %r6,24(%sp) ; save r6
1092
1093 ;
1094 ; Zero out carries
1095 ;
1096 COPY %r0,c1
1097 COPY %r0,c2
1098 COPY %r0,c3
1099
1100 LDO 128(%sp),%sp ; bump stack
1101 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1102 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1103
1104 ;
1105 ; Load up all of the values we are going to use
1106 ;
1107 FLDD 0(a_ptr),a0
1108 FLDD 8(a_ptr),a1
1109 FLDD 16(a_ptr),a2
1110 FLDD 24(a_ptr),a3
1111 FLDD 32(a_ptr),a4
1112 FLDD 40(a_ptr),a5
1113 FLDD 48(a_ptr),a6
1114 FLDD 56(a_ptr),a7
1115
1116 SQR_ADD_C a0L,a0R,c1,c2,c3
1117 STD c1,0(r_ptr) ; r[0] = c1;
1118 COPY %r0,c1
1119
1120 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1121 STD c2,8(r_ptr) ; r[1] = c2;
1122 COPY %r0,c2
1123
1124 SQR_ADD_C a1L,a1R,c3,c1,c2
1125 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1126 STD c3,16(r_ptr) ; r[2] = c3;
1127 COPY %r0,c3
1128
1129 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1130 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1131 STD c1,24(r_ptr) ; r[3] = c1;
1132 COPY %r0,c1
1133
1134 SQR_ADD_C a2L,a2R,c2,c3,c1
1135 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1136 SQR_ADD_C2 a4L,a4R,a0L,a0R,c2,c3,c1
1137 STD c2,32(r_ptr) ; r[4] = c2;
1138 COPY %r0,c2
1139
1140 SQR_ADD_C2 a5L,a5R,a0L,a0R,c3,c1,c2
1141 SQR_ADD_C2 a4L,a4R,a1L,a1R,c3,c1,c2
1142 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1143 STD c3,40(r_ptr) ; r[5] = c3;
1144 COPY %r0,c3
1145
1146 SQR_ADD_C a3L,a3R,c1,c2,c3
1147 SQR_ADD_C2 a4L,a4R,a2L,a2R,c1,c2,c3
1148 SQR_ADD_C2 a5L,a5R,a1L,a1R,c1,c2,c3
1149 SQR_ADD_C2 a6L,a6R,a0L,a0R,c1,c2,c3
1150 STD c1,48(r_ptr) ; r[6] = c1;
1151 COPY %r0,c1
1152
1153 SQR_ADD_C2 a7L,a7R,a0L,a0R,c2,c3,c1
1154 SQR_ADD_C2 a6L,a6R,a1L,a1R,c2,c3,c1
1155 SQR_ADD_C2 a5L,a5R,a2L,a2R,c2,c3,c1
1156 SQR_ADD_C2 a4L,a4R,a3L,a3R,c2,c3,c1
1157 STD c2,56(r_ptr) ; r[7] = c2;
1158 COPY %r0,c2
1159
1160 SQR_ADD_C a4L,a4R,c3,c1,c2
1161 SQR_ADD_C2 a5L,a5R,a3L,a3R,c3,c1,c2
1162 SQR_ADD_C2 a6L,a6R,a2L,a2R,c3,c1,c2
1163 SQR_ADD_C2 a7L,a7R,a1L,a1R,c3,c1,c2
1164 STD c3,64(r_ptr) ; r[8] = c3;
1165 COPY %r0,c3
1166
1167 SQR_ADD_C2 a7L,a7R,a2L,a2R,c1,c2,c3
1168 SQR_ADD_C2 a6L,a6R,a3L,a3R,c1,c2,c3
1169 SQR_ADD_C2 a5L,a5R,a4L,a4R,c1,c2,c3
1170 STD c1,72(r_ptr) ; r[9] = c1;
1171 COPY %r0,c1
1172
1173 SQR_ADD_C a5L,a5R,c2,c3,c1
1174 SQR_ADD_C2 a6L,a6R,a4L,a4R,c2,c3,c1
1175 SQR_ADD_C2 a7L,a7R,a3L,a3R,c2,c3,c1
1176 STD c2,80(r_ptr) ; r[10] = c2;
1177 COPY %r0,c2
1178
1179 SQR_ADD_C2 a7L,a7R,a4L,a4R,c3,c1,c2
1180 SQR_ADD_C2 a6L,a6R,a5L,a5R,c3,c1,c2
1181 STD c3,88(r_ptr) ; r[11] = c3;
1182 COPY %r0,c3
1183
1184 SQR_ADD_C a6L,a6R,c1,c2,c3
1185 SQR_ADD_C2 a7L,a7R,a5L,a5R,c1,c2,c3
1186 STD c1,96(r_ptr) ; r[12] = c1;
1187 COPY %r0,c1
1188
1189 SQR_ADD_C2 a7L,a7R,a6L,a6R,c2,c3,c1
1190 STD c2,104(r_ptr) ; r[13] = c2;
1191 COPY %r0,c2
1192
1193 SQR_ADD_C a7L,a7R,c3,c1,c2
1194 STD c3, 112(r_ptr) ; r[14] = c3
1195 STD c1, 120(r_ptr) ; r[15] = c1
1196
1197 .EXIT
1198 LDD -104(%sp),%r6 ; restore r6
1199 LDD -112(%sp),%r5 ; restore r5
1200 LDD -120(%sp),%r4 ; restore r4
1201 BVE (%rp)
1202 LDD,MB -128(%sp),%r3
1203
1204 .PROCEND
1205
1206;-----------------------------------------------------------------------------
1207;
1208;void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1209; arg0 = r_ptr
1210; arg1 = a_ptr
1211;
1212
1213bn_sqr_comba4
1214 .proc
1215 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1216 .EXPORT bn_sqr_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1217 .entry
1218 .align 64
1219 STD %r3,0(%sp) ; save r3
1220 STD %r4,8(%sp) ; save r4
1221 STD %r5,16(%sp) ; save r5
1222 STD %r6,24(%sp) ; save r6
1223
1224 ;
1225 ; Zero out carries
1226 ;
1227 COPY %r0,c1
1228 COPY %r0,c2
1229 COPY %r0,c3
1230
1231 LDO 128(%sp),%sp ; bump stack
1232 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1233 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1234
1235 ;
1236 ; Load up all of the values we are going to use
1237 ;
1238 FLDD 0(a_ptr),a0
1239 FLDD 8(a_ptr),a1
1240 FLDD 16(a_ptr),a2
1241 FLDD 24(a_ptr),a3
1242 FLDD 32(a_ptr),a4
1243 FLDD 40(a_ptr),a5
1244 FLDD 48(a_ptr),a6
1245 FLDD 56(a_ptr),a7
1246
1247 SQR_ADD_C a0L,a0R,c1,c2,c3
1248
1249 STD c1,0(r_ptr) ; r[0] = c1;
1250 COPY %r0,c1
1251
1252 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1253
1254 STD c2,8(r_ptr) ; r[1] = c2;
1255 COPY %r0,c2
1256
1257 SQR_ADD_C a1L,a1R,c3,c1,c2
1258 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1259
1260 STD c3,16(r_ptr) ; r[2] = c3;
1261 COPY %r0,c3
1262
1263 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1264 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1265
1266 STD c1,24(r_ptr) ; r[3] = c1;
1267 COPY %r0,c1
1268
1269 SQR_ADD_C a2L,a2R,c2,c3,c1
1270 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1271
1272 STD c2,32(r_ptr) ; r[4] = c2;
1273 COPY %r0,c2
1274
1275 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1276 STD c3,40(r_ptr) ; r[5] = c3;
1277 COPY %r0,c3
1278
1279 SQR_ADD_C a3L,a3R,c1,c2,c3
1280 STD c1,48(r_ptr) ; r[6] = c1;
1281 STD c2,56(r_ptr) ; r[7] = c2;
1282
1283 .EXIT
1284 LDD -104(%sp),%r6 ; restore r6
1285 LDD -112(%sp),%r5 ; restore r5
1286 LDD -120(%sp),%r4 ; restore r4
1287 BVE (%rp)
1288 LDD,MB -128(%sp),%r3
1289
1290 .PROCEND
1291
1292
1293;---------------------------------------------------------------------------
1294
1295MUL_ADD_C .macro A0L,A0R,B0L,B0R,C1,C2,C3
1296 XMPYU A0L,B0R,ftemp1 ; m1 = bl*ht
1297 FSTD ftemp1,-16(%sp) ;
1298 XMPYU A0R,B0L,ftemp2 ; m = bh*lt
1299 FSTD ftemp2,-8(%sp) ;
1300 XMPYU A0R,B0R,ftemp3 ; lt = bl*lt
1301 FSTD ftemp3,-32(%sp)
1302 XMPYU A0L,B0L,ftemp4 ; ht = bh*ht
1303 FSTD ftemp4,-24(%sp) ;
1304
1305 LDD -8(%sp),m ; r21 = m
1306 LDD -16(%sp),m1 ; r19 = m1
1307 ADD,L m,m1,m ; m+m1
1308
1309 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1310 LDD -24(%sp),ht ; r24 = ht
1311
1312 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1313 ADD,L ht,high_one,ht ; ht+=high_one
1314
1315 EXTRD,U m,31,32,temp1 ; m >> 32
1316 LDD -32(%sp),lt ; lt
1317 ADD,L ht,temp1,ht ; ht+= m>>32
1318 ADD lt,temp3,lt ; lt = lt+m1
1319 ADD,DC ht,%r0,ht ; ht++
1320
1321 ADD C1,lt,C1 ; c1=c1+lt
1322 ADD,DC ht,%r0,ht ; bump c3 if overflow,nullify otherwise
1323
1324 ADD C2,ht,C2 ; c2 = c2 + ht
1325 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1326.endm
1327
1328
1329;
1330;void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1331; arg0 = r_ptr
1332; arg1 = a_ptr
1333; arg2 = b_ptr
1334;
1335
1336bn_mul_comba8
1337 .proc
1338 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1339 .EXPORT bn_mul_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1340 .entry
1341 .align 64
1342
1343 STD %r3,0(%sp) ; save r3
1344 STD %r4,8(%sp) ; save r4
1345 STD %r5,16(%sp) ; save r5
1346 STD %r6,24(%sp) ; save r6
1347 FSTD %fr12,32(%sp) ; save r6
1348 FSTD %fr13,40(%sp) ; save r7
1349
1350 ;
1351 ; Zero out carries
1352 ;
1353 COPY %r0,c1
1354 COPY %r0,c2
1355 COPY %r0,c3
1356
1357 LDO 128(%sp),%sp ; bump stack
1358 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1359
1360 ;
1361 ; Load up all of the values we are going to use
1362 ;
1363 FLDD 0(a_ptr),a0
1364 FLDD 8(a_ptr),a1
1365 FLDD 16(a_ptr),a2
1366 FLDD 24(a_ptr),a3
1367 FLDD 32(a_ptr),a4
1368 FLDD 40(a_ptr),a5
1369 FLDD 48(a_ptr),a6
1370 FLDD 56(a_ptr),a7
1371
1372 FLDD 0(b_ptr),b0
1373 FLDD 8(b_ptr),b1
1374 FLDD 16(b_ptr),b2
1375 FLDD 24(b_ptr),b3
1376 FLDD 32(b_ptr),b4
1377 FLDD 40(b_ptr),b5
1378 FLDD 48(b_ptr),b6
1379 FLDD 56(b_ptr),b7
1380
1381 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1382 STD c1,0(r_ptr)
1383 COPY %r0,c1
1384
1385 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1386 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1387 STD c2,8(r_ptr)
1388 COPY %r0,c2
1389
1390 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1391 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1392 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1393 STD c3,16(r_ptr)
1394 COPY %r0,c3
1395
1396 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1397 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1398 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1399 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1400 STD c1,24(r_ptr)
1401 COPY %r0,c1
1402
1403 MUL_ADD_C a4L,a4R,b0L,b0R,c2,c3,c1
1404 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1405 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1406 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1407 MUL_ADD_C a0L,a0R,b4L,b4R,c2,c3,c1
1408 STD c2,32(r_ptr)
1409 COPY %r0,c2
1410
1411 MUL_ADD_C a0L,a0R,b5L,b5R,c3,c1,c2
1412 MUL_ADD_C a1L,a1R,b4L,b4R,c3,c1,c2
1413 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1414 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1415 MUL_ADD_C a4L,a4R,b1L,b1R,c3,c1,c2
1416 MUL_ADD_C a5L,a5R,b0L,b0R,c3,c1,c2
1417 STD c3,40(r_ptr)
1418 COPY %r0,c3
1419
1420 MUL_ADD_C a6L,a6R,b0L,b0R,c1,c2,c3
1421 MUL_ADD_C a5L,a5R,b1L,b1R,c1,c2,c3
1422 MUL_ADD_C a4L,a4R,b2L,b2R,c1,c2,c3
1423 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1424 MUL_ADD_C a2L,a2R,b4L,b4R,c1,c2,c3
1425 MUL_ADD_C a1L,a1R,b5L,b5R,c1,c2,c3
1426 MUL_ADD_C a0L,a0R,b6L,b6R,c1,c2,c3
1427 STD c1,48(r_ptr)
1428 COPY %r0,c1
1429
1430 MUL_ADD_C a0L,a0R,b7L,b7R,c2,c3,c1
1431 MUL_ADD_C a1L,a1R,b6L,b6R,c2,c3,c1
1432 MUL_ADD_C a2L,a2R,b5L,b5R,c2,c3,c1
1433 MUL_ADD_C a3L,a3R,b4L,b4R,c2,c3,c1
1434 MUL_ADD_C a4L,a4R,b3L,b3R,c2,c3,c1
1435 MUL_ADD_C a5L,a5R,b2L,b2R,c2,c3,c1
1436 MUL_ADD_C a6L,a6R,b1L,b1R,c2,c3,c1
1437 MUL_ADD_C a7L,a7R,b0L,b0R,c2,c3,c1
1438 STD c2,56(r_ptr)
1439 COPY %r0,c2
1440
1441 MUL_ADD_C a7L,a7R,b1L,b1R,c3,c1,c2
1442 MUL_ADD_C a6L,a6R,b2L,b2R,c3,c1,c2
1443 MUL_ADD_C a5L,a5R,b3L,b3R,c3,c1,c2
1444 MUL_ADD_C a4L,a4R,b4L,b4R,c3,c1,c2
1445 MUL_ADD_C a3L,a3R,b5L,b5R,c3,c1,c2
1446 MUL_ADD_C a2L,a2R,b6L,b6R,c3,c1,c2
1447 MUL_ADD_C a1L,a1R,b7L,b7R,c3,c1,c2
1448 STD c3,64(r_ptr)
1449 COPY %r0,c3
1450
1451 MUL_ADD_C a2L,a2R,b7L,b7R,c1,c2,c3
1452 MUL_ADD_C a3L,a3R,b6L,b6R,c1,c2,c3
1453 MUL_ADD_C a4L,a4R,b5L,b5R,c1,c2,c3
1454 MUL_ADD_C a5L,a5R,b4L,b4R,c1,c2,c3
1455 MUL_ADD_C a6L,a6R,b3L,b3R,c1,c2,c3
1456 MUL_ADD_C a7L,a7R,b2L,b2R,c1,c2,c3
1457 STD c1,72(r_ptr)
1458 COPY %r0,c1
1459
1460 MUL_ADD_C a7L,a7R,b3L,b3R,c2,c3,c1
1461 MUL_ADD_C a6L,a6R,b4L,b4R,c2,c3,c1
1462 MUL_ADD_C a5L,a5R,b5L,b5R,c2,c3,c1
1463 MUL_ADD_C a4L,a4R,b6L,b6R,c2,c3,c1
1464 MUL_ADD_C a3L,a3R,b7L,b7R,c2,c3,c1
1465 STD c2,80(r_ptr)
1466 COPY %r0,c2
1467
1468 MUL_ADD_C a4L,a4R,b7L,b7R,c3,c1,c2
1469 MUL_ADD_C a5L,a5R,b6L,b6R,c3,c1,c2
1470 MUL_ADD_C a6L,a6R,b5L,b5R,c3,c1,c2
1471 MUL_ADD_C a7L,a7R,b4L,b4R,c3,c1,c2
1472 STD c3,88(r_ptr)
1473 COPY %r0,c3
1474
1475 MUL_ADD_C a7L,a7R,b5L,b5R,c1,c2,c3
1476 MUL_ADD_C a6L,a6R,b6L,b6R,c1,c2,c3
1477 MUL_ADD_C a5L,a5R,b7L,b7R,c1,c2,c3
1478 STD c1,96(r_ptr)
1479 COPY %r0,c1
1480
1481 MUL_ADD_C a6L,a6R,b7L,b7R,c2,c3,c1
1482 MUL_ADD_C a7L,a7R,b6L,b6R,c2,c3,c1
1483 STD c2,104(r_ptr)
1484 COPY %r0,c2
1485
1486 MUL_ADD_C a7L,a7R,b7L,b7R,c3,c1,c2
1487 STD c3,112(r_ptr)
1488 STD c1,120(r_ptr)
1489
1490 .EXIT
1491 FLDD -88(%sp),%fr13
1492 FLDD -96(%sp),%fr12
1493 LDD -104(%sp),%r6 ; restore r6
1494 LDD -112(%sp),%r5 ; restore r5
1495 LDD -120(%sp),%r4 ; restore r4
1496 BVE (%rp)
1497 LDD,MB -128(%sp),%r3
1498
1499 .PROCEND
1500
1501;-----------------------------------------------------------------------------
1502;
1503;void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1504; arg0 = r_ptr
1505; arg1 = a_ptr
1506; arg2 = b_ptr
1507;
1508
1509bn_mul_comba4
1510 .proc
1511 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1512 .EXPORT bn_mul_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1513 .entry
1514 .align 64
1515
1516 STD %r3,0(%sp) ; save r3
1517 STD %r4,8(%sp) ; save r4
1518 STD %r5,16(%sp) ; save r5
1519 STD %r6,24(%sp) ; save r6
1520 FSTD %fr12,32(%sp) ; save r6
1521 FSTD %fr13,40(%sp) ; save r7
1522
1523 ;
1524 ; Zero out carries
1525 ;
1526 COPY %r0,c1
1527 COPY %r0,c2
1528 COPY %r0,c3
1529
1530 LDO 128(%sp),%sp ; bump stack
1531 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1532
1533 ;
1534 ; Load up all of the values we are going to use
1535 ;
1536 FLDD 0(a_ptr),a0
1537 FLDD 8(a_ptr),a1
1538 FLDD 16(a_ptr),a2
1539 FLDD 24(a_ptr),a3
1540
1541 FLDD 0(b_ptr),b0
1542 FLDD 8(b_ptr),b1
1543 FLDD 16(b_ptr),b2
1544 FLDD 24(b_ptr),b3
1545
1546 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1547 STD c1,0(r_ptr)
1548 COPY %r0,c1
1549
1550 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1551 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1552 STD c2,8(r_ptr)
1553 COPY %r0,c2
1554
1555 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1556 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1557 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1558 STD c3,16(r_ptr)
1559 COPY %r0,c3
1560
1561 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1562 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1563 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1564 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1565 STD c1,24(r_ptr)
1566 COPY %r0,c1
1567
1568 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1569 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1570 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1571 STD c2,32(r_ptr)
1572 COPY %r0,c2
1573
1574 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1575 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1576 STD c3,40(r_ptr)
1577 COPY %r0,c3
1578
1579 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1580 STD c1,48(r_ptr)
1581 STD c2,56(r_ptr)
1582
1583 .EXIT
1584 FLDD -88(%sp),%fr13
1585 FLDD -96(%sp),%fr12
1586 LDD -104(%sp),%r6 ; restore r6
1587 LDD -112(%sp),%r5 ; restore r5
1588 LDD -120(%sp),%r4 ; restore r4
1589 BVE (%rp)
1590 LDD,MB -128(%sp),%r3
1591
1592 .PROCEND
1593
1594
1595 .SPACE $TEXT$
1596 .SUBSPA $CODE$
1597 .SPACE $PRIVATE$,SORT=16
1598 .IMPORT $global$,DATA
1599 .SPACE $TEXT$
1600 .SUBSPA $CODE$
1601 .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=16
1602C$4
1603 .ALIGN 8
1604 .STRINGZ "Division would overflow (%d)\n"
1605 .END
diff --git a/src/lib/libssl/src/crypto/bn/asm/sparcv8.S b/src/lib/libssl/src/crypto/bn/asm/sparcv8.S
new file mode 100644
index 0000000000..88c5dc480a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/sparcv8.S
@@ -0,0 +1,1458 @@
1.ident "sparcv8.s, Version 1.4"
2.ident "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * See bn_asm.sparc.v8plus.S for more details.
22 */
23
24/*
25 * Revision history.
26 *
27 * 1.1 - new loop unrolling model(*);
28 * 1.2 - made gas friendly;
29 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
30 * 1.4 - some retunes;
31 *
32 * (*) see bn_asm.sparc.v8plus.S for details
33 */
34
35.section ".text",#alloc,#execinstr
36.file "bn_asm.sparc.v8.S"
37
38.align 32
39
40.global bn_mul_add_words
41/*
42 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
43 * BN_ULONG *rp,*ap;
44 * int num;
45 * BN_ULONG w;
46 */
47bn_mul_add_words:
48 cmp %o2,0
49 bg,a .L_bn_mul_add_words_proceed
50 ld [%o1],%g2
51 retl
52 clr %o0
53
54.L_bn_mul_add_words_proceed:
55 andcc %o2,-4,%g0
56 bz .L_bn_mul_add_words_tail
57 clr %o5
58
59.L_bn_mul_add_words_loop:
60 ld [%o0],%o4
61 ld [%o1+4],%g3
62 umul %o3,%g2,%g2
63 rd %y,%g1
64 addcc %o4,%o5,%o4
65 addx %g1,0,%g1
66 addcc %o4,%g2,%o4
67 st %o4,[%o0]
68 addx %g1,0,%o5
69
70 ld [%o0+4],%o4
71 ld [%o1+8],%g2
72 umul %o3,%g3,%g3
73 dec 4,%o2
74 rd %y,%g1
75 addcc %o4,%o5,%o4
76 addx %g1,0,%g1
77 addcc %o4,%g3,%o4
78 st %o4,[%o0+4]
79 addx %g1,0,%o5
80
81 ld [%o0+8],%o4
82 ld [%o1+12],%g3
83 umul %o3,%g2,%g2
84 inc 16,%o1
85 rd %y,%g1
86 addcc %o4,%o5,%o4
87 addx %g1,0,%g1
88 addcc %o4,%g2,%o4
89 st %o4,[%o0+8]
90 addx %g1,0,%o5
91
92 ld [%o0+12],%o4
93 umul %o3,%g3,%g3
94 inc 16,%o0
95 rd %y,%g1
96 addcc %o4,%o5,%o4
97 addx %g1,0,%g1
98 addcc %o4,%g3,%o4
99 st %o4,[%o0-4]
100 addx %g1,0,%o5
101 andcc %o2,-4,%g0
102 bnz,a .L_bn_mul_add_words_loop
103 ld [%o1],%g2
104
105 tst %o2
106 bnz,a .L_bn_mul_add_words_tail
107 ld [%o1],%g2
108.L_bn_mul_add_words_return:
109 retl
110 mov %o5,%o0
111 nop
112
113.L_bn_mul_add_words_tail:
114 ld [%o0],%o4
115 umul %o3,%g2,%g2
116 addcc %o4,%o5,%o4
117 rd %y,%g1
118 addx %g1,0,%g1
119 addcc %o4,%g2,%o4
120 addx %g1,0,%o5
121 deccc %o2
122 bz .L_bn_mul_add_words_return
123 st %o4,[%o0]
124
125 ld [%o1+4],%g2
126 ld [%o0+4],%o4
127 umul %o3,%g2,%g2
128 rd %y,%g1
129 addcc %o4,%o5,%o4
130 addx %g1,0,%g1
131 addcc %o4,%g2,%o4
132 addx %g1,0,%o5
133 deccc %o2
134 bz .L_bn_mul_add_words_return
135 st %o4,[%o0+4]
136
137 ld [%o1+8],%g2
138 ld [%o0+8],%o4
139 umul %o3,%g2,%g2
140 rd %y,%g1
141 addcc %o4,%o5,%o4
142 addx %g1,0,%g1
143 addcc %o4,%g2,%o4
144 st %o4,[%o0+8]
145 retl
146 addx %g1,0,%o0
147
148.type bn_mul_add_words,#function
149.size bn_mul_add_words,(.-bn_mul_add_words)
150
151.align 32
152
153.global bn_mul_words
154/*
155 * BN_ULONG bn_mul_words(rp,ap,num,w)
156 * BN_ULONG *rp,*ap;
157 * int num;
158 * BN_ULONG w;
159 */
160bn_mul_words:
161 cmp %o2,0
162 bg,a .L_bn_mul_words_proceeed
163 ld [%o1],%g2
164 retl
165 clr %o0
166
167.L_bn_mul_words_proceeed:
168 andcc %o2,-4,%g0
169 bz .L_bn_mul_words_tail
170 clr %o5
171
172.L_bn_mul_words_loop:
173 ld [%o1+4],%g3
174 umul %o3,%g2,%g2
175 addcc %g2,%o5,%g2
176 rd %y,%g1
177 addx %g1,0,%o5
178 st %g2,[%o0]
179
180 ld [%o1+8],%g2
181 umul %o3,%g3,%g3
182 addcc %g3,%o5,%g3
183 rd %y,%g1
184 dec 4,%o2
185 addx %g1,0,%o5
186 st %g3,[%o0+4]
187
188 ld [%o1+12],%g3
189 umul %o3,%g2,%g2
190 addcc %g2,%o5,%g2
191 rd %y,%g1
192 inc 16,%o1
193 st %g2,[%o0+8]
194 addx %g1,0,%o5
195
196 umul %o3,%g3,%g3
197 addcc %g3,%o5,%g3
198 rd %y,%g1
199 inc 16,%o0
200 addx %g1,0,%o5
201 st %g3,[%o0-4]
202 andcc %o2,-4,%g0
203 nop
204 bnz,a .L_bn_mul_words_loop
205 ld [%o1],%g2
206
207 tst %o2
208 bnz,a .L_bn_mul_words_tail
209 ld [%o1],%g2
210.L_bn_mul_words_return:
211 retl
212 mov %o5,%o0
213 nop
214
215.L_bn_mul_words_tail:
216 umul %o3,%g2,%g2
217 addcc %g2,%o5,%g2
218 rd %y,%g1
219 addx %g1,0,%o5
220 deccc %o2
221 bz .L_bn_mul_words_return
222 st %g2,[%o0]
223 nop
224
225 ld [%o1+4],%g2
226 umul %o3,%g2,%g2
227 addcc %g2,%o5,%g2
228 rd %y,%g1
229 addx %g1,0,%o5
230 deccc %o2
231 bz .L_bn_mul_words_return
232 st %g2,[%o0+4]
233
234 ld [%o1+8],%g2
235 umul %o3,%g2,%g2
236 addcc %g2,%o5,%g2
237 rd %y,%g1
238 st %g2,[%o0+8]
239 retl
240 addx %g1,0,%o0
241
242.type bn_mul_words,#function
243.size bn_mul_words,(.-bn_mul_words)
244
245.align 32
246.global bn_sqr_words
247/*
248 * void bn_sqr_words(r,a,n)
249 * BN_ULONG *r,*a;
250 * int n;
251 */
252bn_sqr_words:
253 cmp %o2,0
254 bg,a .L_bn_sqr_words_proceeed
255 ld [%o1],%g2
256 retl
257 clr %o0
258
259.L_bn_sqr_words_proceeed:
260 andcc %o2,-4,%g0
261 bz .L_bn_sqr_words_tail
262 clr %o5
263
264.L_bn_sqr_words_loop:
265 ld [%o1+4],%g3
266 umul %g2,%g2,%o4
267 st %o4,[%o0]
268 rd %y,%o5
269 st %o5,[%o0+4]
270
271 ld [%o1+8],%g2
272 umul %g3,%g3,%o4
273 dec 4,%o2
274 st %o4,[%o0+8]
275 rd %y,%o5
276 st %o5,[%o0+12]
277 nop
278
279 ld [%o1+12],%g3
280 umul %g2,%g2,%o4
281 st %o4,[%o0+16]
282 rd %y,%o5
283 inc 16,%o1
284 st %o5,[%o0+20]
285
286 umul %g3,%g3,%o4
287 inc 32,%o0
288 st %o4,[%o0-8]
289 rd %y,%o5
290 st %o5,[%o0-4]
291 andcc %o2,-4,%g2
292 bnz,a .L_bn_sqr_words_loop
293 ld [%o1],%g2
294
295 tst %o2
296 nop
297 bnz,a .L_bn_sqr_words_tail
298 ld [%o1],%g2
299.L_bn_sqr_words_return:
300 retl
301 clr %o0
302
303.L_bn_sqr_words_tail:
304 umul %g2,%g2,%o4
305 st %o4,[%o0]
306 deccc %o2
307 rd %y,%o5
308 bz .L_bn_sqr_words_return
309 st %o5,[%o0+4]
310
311 ld [%o1+4],%g2
312 umul %g2,%g2,%o4
313 st %o4,[%o0+8]
314 deccc %o2
315 rd %y,%o5
316 nop
317 bz .L_bn_sqr_words_return
318 st %o5,[%o0+12]
319
320 ld [%o1+8],%g2
321 umul %g2,%g2,%o4
322 st %o4,[%o0+16]
323 rd %y,%o5
324 st %o5,[%o0+20]
325 retl
326 clr %o0
327
328.type bn_sqr_words,#function
329.size bn_sqr_words,(.-bn_sqr_words)
330
331.align 32
332
333.global bn_div_words
334/*
335 * BN_ULONG bn_div_words(h,l,d)
336 * BN_ULONG h,l,d;
337 */
338bn_div_words:
339 wr %o0,%y
340 udiv %o1,%o2,%o0
341 retl
342 nop
343
344.type bn_div_words,#function
345.size bn_div_words,(.-bn_div_words)
346
347.align 32
348
349.global bn_add_words
350/*
351 * BN_ULONG bn_add_words(rp,ap,bp,n)
352 * BN_ULONG *rp,*ap,*bp;
353 * int n;
354 */
355bn_add_words:
356 cmp %o3,0
357 bg,a .L_bn_add_words_proceed
358 ld [%o1],%o4
359 retl
360 clr %o0
361
362.L_bn_add_words_proceed:
363 andcc %o3,-4,%g0
364 bz .L_bn_add_words_tail
365 clr %g1
366 ba .L_bn_add_words_warn_loop
367 addcc %g0,0,%g0 ! clear carry flag
368
369.L_bn_add_words_loop:
370 ld [%o1],%o4
371.L_bn_add_words_warn_loop:
372 ld [%o2],%o5
373 ld [%o1+4],%g3
374 ld [%o2+4],%g4
375 dec 4,%o3
376 addxcc %o5,%o4,%o5
377 st %o5,[%o0]
378
379 ld [%o1+8],%o4
380 ld [%o2+8],%o5
381 inc 16,%o1
382 addxcc %g3,%g4,%g3
383 st %g3,[%o0+4]
384
385 ld [%o1-4],%g3
386 ld [%o2+12],%g4
387 inc 16,%o2
388 addxcc %o5,%o4,%o5
389 st %o5,[%o0+8]
390
391 inc 16,%o0
392 addxcc %g3,%g4,%g3
393 st %g3,[%o0-4]
394 addx %g0,0,%g1
395 andcc %o3,-4,%g0
396 bnz,a .L_bn_add_words_loop
397 addcc %g1,-1,%g0
398
399 tst %o3
400 bnz,a .L_bn_add_words_tail
401 ld [%o1],%o4
402.L_bn_add_words_return:
403 retl
404 mov %g1,%o0
405
406.L_bn_add_words_tail:
407 addcc %g1,-1,%g0
408 ld [%o2],%o5
409 addxcc %o5,%o4,%o5
410 addx %g0,0,%g1
411 deccc %o3
412 bz .L_bn_add_words_return
413 st %o5,[%o0]
414
415 ld [%o1+4],%o4
416 addcc %g1,-1,%g0
417 ld [%o2+4],%o5
418 addxcc %o5,%o4,%o5
419 addx %g0,0,%g1
420 deccc %o3
421 bz .L_bn_add_words_return
422 st %o5,[%o0+4]
423
424 ld [%o1+8],%o4
425 addcc %g1,-1,%g0
426 ld [%o2+8],%o5
427 addxcc %o5,%o4,%o5
428 st %o5,[%o0+8]
429 retl
430 addx %g0,0,%o0
431
432.type bn_add_words,#function
433.size bn_add_words,(.-bn_add_words)
434
435.align 32
436
437.global bn_sub_words
438/*
439 * BN_ULONG bn_sub_words(rp,ap,bp,n)
440 * BN_ULONG *rp,*ap,*bp;
441 * int n;
442 */
443bn_sub_words:
444 cmp %o3,0
445 bg,a .L_bn_sub_words_proceed
446 ld [%o1],%o4
447 retl
448 clr %o0
449
450.L_bn_sub_words_proceed:
451 andcc %o3,-4,%g0
452 bz .L_bn_sub_words_tail
453 clr %g1
454 ba .L_bn_sub_words_warm_loop
455 addcc %g0,0,%g0 ! clear carry flag
456
457.L_bn_sub_words_loop:
458 ld [%o1],%o4
459.L_bn_sub_words_warm_loop:
460 ld [%o2],%o5
461 ld [%o1+4],%g3
462 ld [%o2+4],%g4
463 dec 4,%o3
464 subxcc %o4,%o5,%o5
465 st %o5,[%o0]
466
467 ld [%o1+8],%o4
468 ld [%o2+8],%o5
469 inc 16,%o1
470 subxcc %g3,%g4,%g4
471 st %g4,[%o0+4]
472
473 ld [%o1-4],%g3
474 ld [%o2+12],%g4
475 inc 16,%o2
476 subxcc %o4,%o5,%o5
477 st %o5,[%o0+8]
478
479 inc 16,%o0
480 subxcc %g3,%g4,%g4
481 st %g4,[%o0-4]
482 addx %g0,0,%g1
483 andcc %o3,-4,%g0
484 bnz,a .L_bn_sub_words_loop
485 addcc %g1,-1,%g0
486
487 tst %o3
488 nop
489 bnz,a .L_bn_sub_words_tail
490 ld [%o1],%o4
491.L_bn_sub_words_return:
492 retl
493 mov %g1,%o0
494
495.L_bn_sub_words_tail:
496 addcc %g1,-1,%g0
497 ld [%o2],%o5
498 subxcc %o4,%o5,%o5
499 addx %g0,0,%g1
500 deccc %o3
501 bz .L_bn_sub_words_return
502 st %o5,[%o0]
503 nop
504
505 ld [%o1+4],%o4
506 addcc %g1,-1,%g0
507 ld [%o2+4],%o5
508 subxcc %o4,%o5,%o5
509 addx %g0,0,%g1
510 deccc %o3
511 bz .L_bn_sub_words_return
512 st %o5,[%o0+4]
513
514 ld [%o1+8],%o4
515 addcc %g1,-1,%g0
516 ld [%o2+8],%o5
517 subxcc %o4,%o5,%o5
518 st %o5,[%o0+8]
519 retl
520 addx %g0,0,%o0
521
522.type bn_sub_words,#function
523.size bn_sub_words,(.-bn_sub_words)
524
525#define FRAME_SIZE -96
526
527/*
528 * Here is register usage map for *all* routines below.
529 */
530#define t_1 %o0
531#define t_2 %o1
532#define c_1 %o2
533#define c_2 %o3
534#define c_3 %o4
535
536#define ap(I) [%i1+4*I]
537#define bp(I) [%i2+4*I]
538#define rp(I) [%i0+4*I]
539
540#define a_0 %l0
541#define a_1 %l1
542#define a_2 %l2
543#define a_3 %l3
544#define a_4 %l4
545#define a_5 %l5
546#define a_6 %l6
547#define a_7 %l7
548
549#define b_0 %i3
550#define b_1 %i4
551#define b_2 %i5
552#define b_3 %o5
553#define b_4 %g1
554#define b_5 %g2
555#define b_6 %g3
556#define b_7 %g4
557
558.align 32
559.global bn_mul_comba8
560/*
561 * void bn_mul_comba8(r,a,b)
562 * BN_ULONG *r,*a,*b;
563 */
564bn_mul_comba8:
565 save %sp,FRAME_SIZE,%sp
566 ld ap(0),a_0
567 ld bp(0),b_0
568 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
569 ld bp(1),b_1
570 rd %y,c_2
571 st c_1,rp(0) !r[0]=c1;
572
573 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
574 ld ap(1),a_1
575 addcc c_2,t_1,c_2
576 rd %y,t_2
577 addxcc %g0,t_2,c_3 !=
578 addx %g0,%g0,c_1
579 ld ap(2),a_2
580 umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1);
581 addcc c_2,t_1,c_2 !=
582 rd %y,t_2
583 addxcc c_3,t_2,c_3
584 st c_2,rp(1) !r[1]=c2;
585 addx c_1,%g0,c_1 !=
586
587 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
588 addcc c_3,t_1,c_3
589 rd %y,t_2
590 addxcc c_1,t_2,c_1 !=
591 addx %g0,%g0,c_2
592 ld bp(2),b_2
593 umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
594 addcc c_3,t_1,c_3 !=
595 rd %y,t_2
596 addxcc c_1,t_2,c_1
597 ld bp(3),b_3
598 addx c_2,%g0,c_2 !=
599 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
600 addcc c_3,t_1,c_3
601 rd %y,t_2
602 addxcc c_1,t_2,c_1 !=
603 addx c_2,%g0,c_2
604 st c_3,rp(2) !r[2]=c3;
605
606 umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
607 addcc c_1,t_1,c_1 !=
608 rd %y,t_2
609 addxcc c_2,t_2,c_2
610 addx %g0,%g0,c_3
611 umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
612 addcc c_1,t_1,c_1
613 rd %y,t_2
614 addxcc c_2,t_2,c_2
615 addx c_3,%g0,c_3 !=
616 ld ap(3),a_3
617 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
618 addcc c_1,t_1,c_1
619 rd %y,t_2 !=
620 addxcc c_2,t_2,c_2
621 addx c_3,%g0,c_3
622 ld ap(4),a_4
623 umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
624 addcc c_1,t_1,c_1
625 rd %y,t_2
626 addxcc c_2,t_2,c_2
627 addx c_3,%g0,c_3 !=
628 st c_1,rp(3) !r[3]=c1;
629
630 umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
631 addcc c_2,t_1,c_2
632 rd %y,t_2 !=
633 addxcc c_3,t_2,c_3
634 addx %g0,%g0,c_1
635 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
636 addcc c_2,t_1,c_2 !=
637 rd %y,t_2
638 addxcc c_3,t_2,c_3
639 addx c_1,%g0,c_1
640 umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
641 addcc c_2,t_1,c_2
642 rd %y,t_2
643 addxcc c_3,t_2,c_3
644 addx c_1,%g0,c_1 !=
645 ld bp(4),b_4
646 umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
647 addcc c_2,t_1,c_2
648 rd %y,t_2 !=
649 addxcc c_3,t_2,c_3
650 addx c_1,%g0,c_1
651 ld bp(5),b_5
652 umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1);
653 addcc c_2,t_1,c_2
654 rd %y,t_2
655 addxcc c_3,t_2,c_3
656 addx c_1,%g0,c_1 !=
657 st c_2,rp(4) !r[4]=c2;
658
659 umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
660 addcc c_3,t_1,c_3
661 rd %y,t_2 !=
662 addxcc c_1,t_2,c_1
663 addx %g0,%g0,c_2
664 umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
665 addcc c_3,t_1,c_3 !=
666 rd %y,t_2
667 addxcc c_1,t_2,c_1
668 addx c_2,%g0,c_2
669 umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2);
670 addcc c_3,t_1,c_3
671 rd %y,t_2
672 addxcc c_1,t_2,c_1
673 addx c_2,%g0,c_2 !=
674 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
675 addcc c_3,t_1,c_3
676 rd %y,t_2
677 addxcc c_1,t_2,c_1 !=
678 addx c_2,%g0,c_2
679 ld ap(5),a_5
680 umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
681 addcc c_3,t_1,c_3 !=
682 rd %y,t_2
683 addxcc c_1,t_2,c_1
684 ld ap(6),a_6
685 addx c_2,%g0,c_2 !=
686 umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2);
687 addcc c_3,t_1,c_3
688 rd %y,t_2
689 addxcc c_1,t_2,c_1 !=
690 addx c_2,%g0,c_2
691 st c_3,rp(5) !r[5]=c3;
692
693 umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
694 addcc c_1,t_1,c_1 !=
695 rd %y,t_2
696 addxcc c_2,t_2,c_2
697 addx %g0,%g0,c_3
698 umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
699 addcc c_1,t_1,c_1
700 rd %y,t_2
701 addxcc c_2,t_2,c_2
702 addx c_3,%g0,c_3 !=
703 umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3);
704 addcc c_1,t_1,c_1
705 rd %y,t_2
706 addxcc c_2,t_2,c_2 !=
707 addx c_3,%g0,c_3
708 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
709 addcc c_1,t_1,c_1
710 rd %y,t_2 !=
711 addxcc c_2,t_2,c_2
712 addx c_3,%g0,c_3
713 umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3);
714 addcc c_1,t_1,c_1 !=
715 rd %y,t_2
716 addxcc c_2,t_2,c_2
717 ld bp(6),b_6
718 addx c_3,%g0,c_3 !=
719 umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
720 addcc c_1,t_1,c_1
721 rd %y,t_2
722 addxcc c_2,t_2,c_2 !=
723 addx c_3,%g0,c_3
724 ld bp(7),b_7
725 umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
726 addcc c_1,t_1,c_1 !=
727 rd %y,t_2
728 addxcc c_2,t_2,c_2
729 st c_1,rp(6) !r[6]=c1;
730 addx c_3,%g0,c_3 !=
731
732 umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
733 addcc c_2,t_1,c_2
734 rd %y,t_2
735 addxcc c_3,t_2,c_3 !=
736 addx %g0,%g0,c_1
737 umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
738 addcc c_2,t_1,c_2
739 rd %y,t_2 !=
740 addxcc c_3,t_2,c_3
741 addx c_1,%g0,c_1
742 umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
743 addcc c_2,t_1,c_2 !=
744 rd %y,t_2
745 addxcc c_3,t_2,c_3
746 addx c_1,%g0,c_1
747 umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1);
748 addcc c_2,t_1,c_2
749 rd %y,t_2
750 addxcc c_3,t_2,c_3
751 addx c_1,%g0,c_1 !=
752 umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
753 addcc c_2,t_1,c_2
754 rd %y,t_2
755 addxcc c_3,t_2,c_3 !=
756 addx c_1,%g0,c_1
757 umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
758 addcc c_2,t_1,c_2
759 rd %y,t_2 !=
760 addxcc c_3,t_2,c_3
761 addx c_1,%g0,c_1
762 ld ap(7),a_7
763 umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
764 addcc c_2,t_1,c_2
765 rd %y,t_2
766 addxcc c_3,t_2,c_3
767 addx c_1,%g0,c_1 !=
768 umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1);
769 addcc c_2,t_1,c_2
770 rd %y,t_2
771 addxcc c_3,t_2,c_3 !=
772 addx c_1,%g0,c_1
773 st c_2,rp(7) !r[7]=c2;
774
775 umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2);
776 addcc c_3,t_1,c_3 !=
777 rd %y,t_2
778 addxcc c_1,t_2,c_1
779 addx %g0,%g0,c_2
780 umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2);
781 addcc c_3,t_1,c_3
782 rd %y,t_2
783 addxcc c_1,t_2,c_1
784 addx c_2,%g0,c_2 !=
785 umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
786 addcc c_3,t_1,c_3
787 rd %y,t_2
788 addxcc c_1,t_2,c_1 !=
789 addx c_2,%g0,c_2
790 umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
791 addcc c_3,t_1,c_3
792 rd %y,t_2 !=
793 addxcc c_1,t_2,c_1
794 addx c_2,%g0,c_2
795 umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
796 addcc c_3,t_1,c_3 !=
797 rd %y,t_2
798 addxcc c_1,t_2,c_1
799 addx c_2,%g0,c_2
800 umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2);
801 addcc c_3,t_1,c_3
802 rd %y,t_2
803 addxcc c_1,t_2,c_1
804 addx c_2,%g0,c_2 !=
805 umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
806 addcc c_3,t_1,c_3
807 rd %y,t_2
808 addxcc c_1,t_2,c_1 !
809 addx c_2,%g0,c_2
810 st c_3,rp(8) !r[8]=c3;
811
812 umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3);
813 addcc c_1,t_1,c_1 !=
814 rd %y,t_2
815 addxcc c_2,t_2,c_2
816 addx %g0,%g0,c_3
817 umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3);
818 addcc c_1,t_1,c_1
819 rd %y,t_2
820 addxcc c_2,t_2,c_2
821 addx c_3,%g0,c_3 !=
822 umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
823 addcc c_1,t_1,c_1
824 rd %y,t_2
825 addxcc c_2,t_2,c_2 !=
826 addx c_3,%g0,c_3
827 umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
828 addcc c_1,t_1,c_1
829 rd %y,t_2 !=
830 addxcc c_2,t_2,c_2
831 addx c_3,%g0,c_3
832 umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
833 addcc c_1,t_1,c_1 !=
834 rd %y,t_2
835 addxcc c_2,t_2,c_2
836 addx c_3,%g0,c_3
837 umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3);
838 addcc c_1,t_1,c_1
839 rd %y,t_2
840 addxcc c_2,t_2,c_2
841 addx c_3,%g0,c_3 !=
842 st c_1,rp(9) !r[9]=c1;
843
844 umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
845 addcc c_2,t_1,c_2
846 rd %y,t_2 !=
847 addxcc c_3,t_2,c_3
848 addx %g0,%g0,c_1
849 umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
850 addcc c_2,t_1,c_2 !=
851 rd %y,t_2
852 addxcc c_3,t_2,c_3
853 addx c_1,%g0,c_1
854 umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1);
855 addcc c_2,t_1,c_2
856 rd %y,t_2
857 addxcc c_3,t_2,c_3
858 addx c_1,%g0,c_1 !=
859 umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
860 addcc c_2,t_1,c_2
861 rd %y,t_2
862 addxcc c_3,t_2,c_3 !=
863 addx c_1,%g0,c_1
864 umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
865 addcc c_2,t_1,c_2
866 rd %y,t_2 !=
867 addxcc c_3,t_2,c_3
868 addx c_1,%g0,c_1
869 st c_2,rp(10) !r[10]=c2;
870
871 umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2);
872 addcc c_3,t_1,c_3
873 rd %y,t_2
874 addxcc c_1,t_2,c_1
875 addx %g0,%g0,c_2 !=
876 umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
877 addcc c_3,t_1,c_3
878 rd %y,t_2
879 addxcc c_1,t_2,c_1 !=
880 addx c_2,%g0,c_2
881 umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
882 addcc c_3,t_1,c_3
883 rd %y,t_2 !=
884 addxcc c_1,t_2,c_1
885 addx c_2,%g0,c_2
886 umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
887 addcc c_3,t_1,c_3 !=
888 rd %y,t_2
889 addxcc c_1,t_2,c_1
890 st c_3,rp(11) !r[11]=c3;
891 addx c_2,%g0,c_2 !=
892
893 umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
894 addcc c_1,t_1,c_1
895 rd %y,t_2
896 addxcc c_2,t_2,c_2 !=
897 addx %g0,%g0,c_3
898 umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
899 addcc c_1,t_1,c_1
900 rd %y,t_2 !=
901 addxcc c_2,t_2,c_2
902 addx c_3,%g0,c_3
903 umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
904 addcc c_1,t_1,c_1 !=
905 rd %y,t_2
906 addxcc c_2,t_2,c_2
907 st c_1,rp(12) !r[12]=c1;
908 addx c_3,%g0,c_3 !=
909
910 umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
911 addcc c_2,t_1,c_2
912 rd %y,t_2
913 addxcc c_3,t_2,c_3 !=
914 addx %g0,%g0,c_1
915 umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
916 addcc c_2,t_1,c_2
917 rd %y,t_2 !=
918 addxcc c_3,t_2,c_3
919 addx c_1,%g0,c_1
920 st c_2,rp(13) !r[13]=c2;
921
922 umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2);
923 addcc c_3,t_1,c_3
924 rd %y,t_2
925 addxcc c_1,t_2,c_1
926 nop !=
927 st c_3,rp(14) !r[14]=c3;
928 st c_1,rp(15) !r[15]=c1;
929
930 ret
931 restore %g0,%g0,%o0
932
933.type bn_mul_comba8,#function
934.size bn_mul_comba8,(.-bn_mul_comba8)
935
936.align 32
937
938.global bn_mul_comba4
939/*
940 * void bn_mul_comba4(r,a,b)
941 * BN_ULONG *r,*a,*b;
942 */
943bn_mul_comba4:
944 save %sp,FRAME_SIZE,%sp
945 ld ap(0),a_0
946 ld bp(0),b_0
947 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
948 ld bp(1),b_1
949 rd %y,c_2
950 st c_1,rp(0) !r[0]=c1;
951
952 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
953 ld ap(1),a_1
954 addcc c_2,t_1,c_2
955 rd %y,t_2 !=
956 addxcc %g0,t_2,c_3
957 addx %g0,%g0,c_1
958 ld ap(2),a_2
959 umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
960 addcc c_2,t_1,c_2
961 rd %y,t_2
962 addxcc c_3,t_2,c_3
963 addx c_1,%g0,c_1 !=
964 st c_2,rp(1) !r[1]=c2;
965
966 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
967 addcc c_3,t_1,c_3
968 rd %y,t_2 !=
969 addxcc c_1,t_2,c_1
970 addx %g0,%g0,c_2
971 ld bp(2),b_2
972 umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2);
973 addcc c_3,t_1,c_3
974 rd %y,t_2
975 addxcc c_1,t_2,c_1
976 addx c_2,%g0,c_2 !=
977 ld bp(3),b_3
978 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
979 addcc c_3,t_1,c_3
980 rd %y,t_2 !=
981 addxcc c_1,t_2,c_1
982 addx c_2,%g0,c_2
983 st c_3,rp(2) !r[2]=c3;
984
985 umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3);
986 addcc c_1,t_1,c_1
987 rd %y,t_2
988 addxcc c_2,t_2,c_2
989 addx %g0,%g0,c_3 !=
990 umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
991 addcc c_1,t_1,c_1
992 rd %y,t_2
993 addxcc c_2,t_2,c_2 !=
994 addx c_3,%g0,c_3
995 ld ap(3),a_3
996 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
997 addcc c_1,t_1,c_1 !=
998 rd %y,t_2
999 addxcc c_2,t_2,c_2
1000 addx c_3,%g0,c_3
1001 umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);
1002 addcc c_1,t_1,c_1
1003 rd %y,t_2
1004 addxcc c_2,t_2,c_2
1005 addx c_3,%g0,c_3 !=
1006 st c_1,rp(3) !r[3]=c1;
1007
1008 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1009 addcc c_2,t_1,c_2
1010 rd %y,t_2 !=
1011 addxcc c_3,t_2,c_3
1012 addx %g0,%g0,c_1
1013 umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1014 addcc c_2,t_1,c_2 !=
1015 rd %y,t_2
1016 addxcc c_3,t_2,c_3
1017 addx c_1,%g0,c_1
1018 umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1);
1019 addcc c_2,t_1,c_2
1020 rd %y,t_2
1021 addxcc c_3,t_2,c_3
1022 addx c_1,%g0,c_1 !=
1023 st c_2,rp(4) !r[4]=c2;
1024
1025 umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1026 addcc c_3,t_1,c_3
1027 rd %y,t_2 !=
1028 addxcc c_1,t_2,c_1
1029 addx %g0,%g0,c_2
1030 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1031 addcc c_3,t_1,c_3 !=
1032 rd %y,t_2
1033 addxcc c_1,t_2,c_1
1034 st c_3,rp(5) !r[5]=c3;
1035 addx c_2,%g0,c_2 !=
1036
1037 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1038 addcc c_1,t_1,c_1
1039 rd %y,t_2
1040 addxcc c_2,t_2,c_2 !=
1041 st c_1,rp(6) !r[6]=c1;
1042 st c_2,rp(7) !r[7]=c2;
1043
1044 ret
1045 restore %g0,%g0,%o0
1046
1047.type bn_mul_comba4,#function
1048.size bn_mul_comba4,(.-bn_mul_comba4)
1049
1050.align 32
1051
1052.global bn_sqr_comba8
1053bn_sqr_comba8:
1054 save %sp,FRAME_SIZE,%sp
1055 ld ap(0),a_0
1056 ld ap(1),a_1
1057 umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3);
1058 rd %y,c_2
1059 st c_1,rp(0) !r[0]=c1;
1060
1061 ld ap(2),a_2
1062 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1063 addcc c_2,t_1,c_2
1064 rd %y,t_2
1065 addxcc %g0,t_2,c_3
1066 addx %g0,%g0,c_1 !=
1067 addcc c_2,t_1,c_2
1068 addxcc c_3,t_2,c_3
1069 st c_2,rp(1) !r[1]=c2;
1070 addx c_1,%g0,c_1 !=
1071
1072 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1073 addcc c_3,t_1,c_3
1074 rd %y,t_2
1075 addxcc c_1,t_2,c_1 !=
1076 addx %g0,%g0,c_2
1077 addcc c_3,t_1,c_3
1078 addxcc c_1,t_2,c_1
1079 addx c_2,%g0,c_2 !=
1080 ld ap(3),a_3
1081 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1082 addcc c_3,t_1,c_3
1083 rd %y,t_2 !=
1084 addxcc c_1,t_2,c_1
1085 addx c_2,%g0,c_2
1086 st c_3,rp(2) !r[2]=c3;
1087
1088 umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3);
1089 addcc c_1,t_1,c_1
1090 rd %y,t_2
1091 addxcc c_2,t_2,c_2
1092 addx %g0,%g0,c_3 !=
1093 addcc c_1,t_1,c_1
1094 addxcc c_2,t_2,c_2
1095 ld ap(4),a_4
1096 addx c_3,%g0,c_3 !=
1097 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1098 addcc c_1,t_1,c_1
1099 rd %y,t_2
1100 addxcc c_2,t_2,c_2 !=
1101 addx c_3,%g0,c_3
1102 addcc c_1,t_1,c_1
1103 addxcc c_2,t_2,c_2
1104 addx c_3,%g0,c_3 !=
1105 st c_1,rp(3) !r[3]=c1;
1106
1107 umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1108 addcc c_2,t_1,c_2
1109 rd %y,t_2 !=
1110 addxcc c_3,t_2,c_3
1111 addx %g0,%g0,c_1
1112 addcc c_2,t_1,c_2
1113 addxcc c_3,t_2,c_3 !=
1114 addx c_1,%g0,c_1
1115 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1116 addcc c_2,t_1,c_2
1117 rd %y,t_2 !=
1118 addxcc c_3,t_2,c_3
1119 addx c_1,%g0,c_1
1120 addcc c_2,t_1,c_2
1121 addxcc c_3,t_2,c_3 !=
1122 addx c_1,%g0,c_1
1123 ld ap(5),a_5
1124 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1125 addcc c_2,t_1,c_2 !=
1126 rd %y,t_2
1127 addxcc c_3,t_2,c_3
1128 st c_2,rp(4) !r[4]=c2;
1129 addx c_1,%g0,c_1 !=
1130
1131 umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1132 addcc c_3,t_1,c_3
1133 rd %y,t_2
1134 addxcc c_1,t_2,c_1 !=
1135 addx %g0,%g0,c_2
1136 addcc c_3,t_1,c_3
1137 addxcc c_1,t_2,c_1
1138 addx c_2,%g0,c_2 !=
1139 umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1140 addcc c_3,t_1,c_3
1141 rd %y,t_2
1142 addxcc c_1,t_2,c_1 !=
1143 addx c_2,%g0,c_2
1144 addcc c_3,t_1,c_3
1145 addxcc c_1,t_2,c_1
1146 addx c_2,%g0,c_2 !=
1147 ld ap(6),a_6
1148 umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1149 addcc c_3,t_1,c_3
1150 rd %y,t_2 !=
1151 addxcc c_1,t_2,c_1
1152 addx c_2,%g0,c_2
1153 addcc c_3,t_1,c_3
1154 addxcc c_1,t_2,c_1 !=
1155 addx c_2,%g0,c_2
1156 st c_3,rp(5) !r[5]=c3;
1157
1158 umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1159 addcc c_1,t_1,c_1 !=
1160 rd %y,t_2
1161 addxcc c_2,t_2,c_2
1162 addx %g0,%g0,c_3
1163 addcc c_1,t_1,c_1 !=
1164 addxcc c_2,t_2,c_2
1165 addx c_3,%g0,c_3
1166 umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1167 addcc c_1,t_1,c_1 !=
1168 rd %y,t_2
1169 addxcc c_2,t_2,c_2
1170 addx c_3,%g0,c_3
1171 addcc c_1,t_1,c_1 !=
1172 addxcc c_2,t_2,c_2
1173 addx c_3,%g0,c_3
1174 umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1175 addcc c_1,t_1,c_1 !=
1176 rd %y,t_2
1177 addxcc c_2,t_2,c_2
1178 addx c_3,%g0,c_3
1179 addcc c_1,t_1,c_1 !=
1180 addxcc c_2,t_2,c_2
1181 addx c_3,%g0,c_3
1182 ld ap(7),a_7
1183 umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1184 addcc c_1,t_1,c_1
1185 rd %y,t_2
1186 addxcc c_2,t_2,c_2
1187 addx c_3,%g0,c_3 !=
1188 st c_1,rp(6) !r[6]=c1;
1189
1190 umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1191 addcc c_2,t_1,c_2
1192 rd %y,t_2 !=
1193 addxcc c_3,t_2,c_3
1194 addx %g0,%g0,c_1
1195 addcc c_2,t_1,c_2
1196 addxcc c_3,t_2,c_3 !=
1197 addx c_1,%g0,c_1
1198 umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1199 addcc c_2,t_1,c_2
1200 rd %y,t_2 !=
1201 addxcc c_3,t_2,c_3
1202 addx c_1,%g0,c_1
1203 addcc c_2,t_1,c_2
1204 addxcc c_3,t_2,c_3 !=
1205 addx c_1,%g0,c_1
1206 umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1207 addcc c_2,t_1,c_2
1208 rd %y,t_2 !=
1209 addxcc c_3,t_2,c_3
1210 addx c_1,%g0,c_1
1211 addcc c_2,t_1,c_2
1212 addxcc c_3,t_2,c_3 !=
1213 addx c_1,%g0,c_1
1214 umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1215 addcc c_2,t_1,c_2
1216 rd %y,t_2 !=
1217 addxcc c_3,t_2,c_3
1218 addx c_1,%g0,c_1
1219 addcc c_2,t_1,c_2
1220 addxcc c_3,t_2,c_3 !=
1221 addx c_1,%g0,c_1
1222 st c_2,rp(7) !r[7]=c2;
1223
1224 umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1225 addcc c_3,t_1,c_3 !=
1226 rd %y,t_2
1227 addxcc c_1,t_2,c_1
1228 addx %g0,%g0,c_2
1229 addcc c_3,t_1,c_3 !=
1230 addxcc c_1,t_2,c_1
1231 addx c_2,%g0,c_2
1232 umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1233 addcc c_3,t_1,c_3 !=
1234 rd %y,t_2
1235 addxcc c_1,t_2,c_1
1236 addx c_2,%g0,c_2
1237 addcc c_3,t_1,c_3 !=
1238 addxcc c_1,t_2,c_1
1239 addx c_2,%g0,c_2
1240 umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1241 addcc c_3,t_1,c_3 !=
1242 rd %y,t_2
1243 addxcc c_1,t_2,c_1
1244 addx c_2,%g0,c_2
1245 addcc c_3,t_1,c_3 !=
1246 addxcc c_1,t_2,c_1
1247 addx c_2,%g0,c_2
1248 umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1249 addcc c_3,t_1,c_3 !=
1250 rd %y,t_2
1251 addxcc c_1,t_2,c_1
1252 st c_3,rp(8) !r[8]=c3;
1253 addx c_2,%g0,c_2 !=
1254
1255 umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1256 addcc c_1,t_1,c_1
1257 rd %y,t_2
1258 addxcc c_2,t_2,c_2 !=
1259 addx %g0,%g0,c_3
1260 addcc c_1,t_1,c_1
1261 addxcc c_2,t_2,c_2
1262 addx c_3,%g0,c_3 !=
1263 umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1264 addcc c_1,t_1,c_1
1265 rd %y,t_2
1266 addxcc c_2,t_2,c_2 !=
1267 addx c_3,%g0,c_3
1268 addcc c_1,t_1,c_1
1269 addxcc c_2,t_2,c_2
1270 addx c_3,%g0,c_3 !=
1271 umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1272 addcc c_1,t_1,c_1
1273 rd %y,t_2
1274 addxcc c_2,t_2,c_2 !=
1275 addx c_3,%g0,c_3
1276 addcc c_1,t_1,c_1
1277 addxcc c_2,t_2,c_2
1278 addx c_3,%g0,c_3 !=
1279 st c_1,rp(9) !r[9]=c1;
1280
1281 umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1282 addcc c_2,t_1,c_2
1283 rd %y,t_2 !=
1284 addxcc c_3,t_2,c_3
1285 addx %g0,%g0,c_1
1286 addcc c_2,t_1,c_2
1287 addxcc c_3,t_2,c_3 !=
1288 addx c_1,%g0,c_1
1289 umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1290 addcc c_2,t_1,c_2
1291 rd %y,t_2 !=
1292 addxcc c_3,t_2,c_3
1293 addx c_1,%g0,c_1
1294 addcc c_2,t_1,c_2
1295 addxcc c_3,t_2,c_3 !=
1296 addx c_1,%g0,c_1
1297 umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1298 addcc c_2,t_1,c_2
1299 rd %y,t_2 !=
1300 addxcc c_3,t_2,c_3
1301 addx c_1,%g0,c_1
1302 st c_2,rp(10) !r[10]=c2;
1303
1304 umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2);
1305 addcc c_3,t_1,c_3
1306 rd %y,t_2
1307 addxcc c_1,t_2,c_1
1308 addx %g0,%g0,c_2 !=
1309 addcc c_3,t_1,c_3
1310 addxcc c_1,t_2,c_1
1311 addx c_2,%g0,c_2
1312 umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2);
1313 addcc c_3,t_1,c_3
1314 rd %y,t_2
1315 addxcc c_1,t_2,c_1
1316 addx c_2,%g0,c_2 !=
1317 addcc c_3,t_1,c_3
1318 addxcc c_1,t_2,c_1
1319 st c_3,rp(11) !r[11]=c3;
1320 addx c_2,%g0,c_2 !=
1321
1322 umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1323 addcc c_1,t_1,c_1
1324 rd %y,t_2
1325 addxcc c_2,t_2,c_2 !=
1326 addx %g0,%g0,c_3
1327 addcc c_1,t_1,c_1
1328 addxcc c_2,t_2,c_2
1329 addx c_3,%g0,c_3 !=
1330 umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1331 addcc c_1,t_1,c_1
1332 rd %y,t_2
1333 addxcc c_2,t_2,c_2 !=
1334 addx c_3,%g0,c_3
1335 st c_1,rp(12) !r[12]=c1;
1336
1337 umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1338 addcc c_2,t_1,c_2 !=
1339 rd %y,t_2
1340 addxcc c_3,t_2,c_3
1341 addx %g0,%g0,c_1
1342 addcc c_2,t_1,c_2 !=
1343 addxcc c_3,t_2,c_3
1344 st c_2,rp(13) !r[13]=c2;
1345 addx c_1,%g0,c_1 !=
1346
1347 umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1348 addcc c_3,t_1,c_3
1349 rd %y,t_2
1350 addxcc c_1,t_2,c_1 !=
1351 st c_3,rp(14) !r[14]=c3;
1352 st c_1,rp(15) !r[15]=c1;
1353
1354 ret
1355 restore %g0,%g0,%o0
1356
1357.type bn_sqr_comba8,#function
1358.size bn_sqr_comba8,(.-bn_sqr_comba8)
1359
1360.align 32
1361
1362.global bn_sqr_comba4
1363/*
1364 * void bn_sqr_comba4(r,a)
1365 * BN_ULONG *r,*a;
1366 */
1367bn_sqr_comba4:
1368 save %sp,FRAME_SIZE,%sp
1369 ld ap(0),a_0
1370 umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3);
1371 ld ap(1),a_1 !=
1372 rd %y,c_2
1373 st c_1,rp(0) !r[0]=c1;
1374
1375 ld ap(2),a_2
1376 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1377 addcc c_2,t_1,c_2
1378 rd %y,t_2
1379 addxcc %g0,t_2,c_3
1380 addx %g0,%g0,c_1 !=
1381 addcc c_2,t_1,c_2
1382 addxcc c_3,t_2,c_3
1383 addx c_1,%g0,c_1 !=
1384 st c_2,rp(1) !r[1]=c2;
1385
1386 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1387 addcc c_3,t_1,c_3
1388 rd %y,t_2 !=
1389 addxcc c_1,t_2,c_1
1390 addx %g0,%g0,c_2
1391 addcc c_3,t_1,c_3
1392 addxcc c_1,t_2,c_1 !=
1393 addx c_2,%g0,c_2
1394 ld ap(3),a_3
1395 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1396 addcc c_3,t_1,c_3 !=
1397 rd %y,t_2
1398 addxcc c_1,t_2,c_1
1399 st c_3,rp(2) !r[2]=c3;
1400 addx c_2,%g0,c_2 !=
1401
1402 umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1403 addcc c_1,t_1,c_1
1404 rd %y,t_2
1405 addxcc c_2,t_2,c_2 !=
1406 addx %g0,%g0,c_3
1407 addcc c_1,t_1,c_1
1408 addxcc c_2,t_2,c_2
1409 addx c_3,%g0,c_3 !=
1410 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1411 addcc c_1,t_1,c_1
1412 rd %y,t_2
1413 addxcc c_2,t_2,c_2 !=
1414 addx c_3,%g0,c_3
1415 addcc c_1,t_1,c_1
1416 addxcc c_2,t_2,c_2
1417 addx c_3,%g0,c_3 !=
1418 st c_1,rp(3) !r[3]=c1;
1419
1420 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1421 addcc c_2,t_1,c_2
1422 rd %y,t_2 !=
1423 addxcc c_3,t_2,c_3
1424 addx %g0,%g0,c_1
1425 addcc c_2,t_1,c_2
1426 addxcc c_3,t_2,c_3 !=
1427 addx c_1,%g0,c_1
1428 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1429 addcc c_2,t_1,c_2
1430 rd %y,t_2 !=
1431 addxcc c_3,t_2,c_3
1432 addx c_1,%g0,c_1
1433 st c_2,rp(4) !r[4]=c2;
1434
1435 umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2);
1436 addcc c_3,t_1,c_3
1437 rd %y,t_2
1438 addxcc c_1,t_2,c_1
1439 addx %g0,%g0,c_2 !=
1440 addcc c_3,t_1,c_3
1441 addxcc c_1,t_2,c_1
1442 st c_3,rp(5) !r[5]=c3;
1443 addx c_2,%g0,c_2 !=
1444
1445 umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1446 addcc c_1,t_1,c_1
1447 rd %y,t_2
1448 addxcc c_2,t_2,c_2 !=
1449 st c_1,rp(6) !r[6]=c1;
1450 st c_2,rp(7) !r[7]=c2;
1451
1452 ret
1453 restore %g0,%g0,%o0
1454
1455.type bn_sqr_comba4,#function
1456.size bn_sqr_comba4,(.-bn_sqr_comba4)
1457
1458.align 32
diff --git a/src/lib/libssl/src/crypto/bn/asm/sparcv8plus.S b/src/lib/libssl/src/crypto/bn/asm/sparcv8plus.S
new file mode 100644
index 0000000000..0074dfdb75
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/sparcv8plus.S
@@ -0,0 +1,1535 @@
1.ident "sparcv8plus.s, Version 1.4"
2.ident "SPARC v9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * Questions-n-answers.
22 *
23 * Q. How to compile?
24 * A. With SC4.x/SC5.x:
25 *
26 * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
27 *
28 * and with gcc:
29 *
30 * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o
31 *
32 * or if above fails (it does if you have gas installed):
33 *
34 * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o
35 *
36 * Quick-n-dirty way to fuse the module into the library.
37 * Provided that the library is already configured and built
38 * (in 0.9.2 case with no-asm option):
39 *
40 * # cd crypto/bn
41 * # cp /some/place/bn_asm.sparc.v8plus.S .
42 * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
43 * # make
44 * # cd ../..
45 * # make; make test
46 *
47 * Quick-n-dirty way to get rid of it:
48 *
49 * # cd crypto/bn
50 * # touch bn_asm.c
51 * # make
52 * # cd ../..
53 * # make; make test
54 *
55 * Q. V8plus achitecture? What kind of beast is that?
56 * A. Well, it's rather a programming model than an architecture...
57 * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under
58 * special conditions, namely when kernel doesn't preserve upper
59 * 32 bits of otherwise 64-bit registers during a context switch.
60 *
61 * Q. Why just UltraSPARC? What about SuperSPARC?
62 * A. Original release did target UltraSPARC only. Now SuperSPARC
63 * version is provided along. Both version share bn_*comba[48]
64 * implementations (see comment later in code for explanation).
65 * But what's so special about this UltraSPARC implementation?
66 * Why didn't I let compiler do the job? Trouble is that most of
67 * available compilers (well, SC5.0 is the only exception) don't
68 * attempt to take advantage of UltraSPARC's 64-bitness under
69 * 32-bit kernels even though it's perfectly possible (see next
70 * question).
71 *
72 * Q. 64-bit registers under 32-bit kernels? Didn't you just say it
73 * doesn't work?
74 * A. You can't adress *all* registers as 64-bit wide:-( The catch is
75 * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully
76 * preserved if you're in a leaf function, i.e. such never calling
77 * any other functions. All functions in this module are leaf and
78 * 10 registers is a handful. And as a matter of fact none-"comba"
79 * routines don't require even that much and I could even afford to
80 * not allocate own stack frame for 'em:-)
81 *
82 * Q. What about 64-bit kernels?
83 * A. What about 'em? Just kidding:-) Pure 64-bit version is currently
84 * under evaluation and development...
85 *
86 * Q. What about shared libraries?
87 * A. What about 'em? Kidding again:-) Code does *not* contain any
88 * code position dependencies and it's safe to include it into
89 * shared library as is.
90 *
91 * Q. How much faster does it go?
92 * A. Do you have a good benchmark? In either case below is what I
93 * experience with crypto/bn/expspeed.c test program:
94 *
95 * v8plus module on U10/300MHz against bn_asm.c compiled with:
96 *
97 * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12%
98 * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35%
99 * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45%
100 *
101 * v8 module on SS10/60MHz against bn_asm.c compiled with:
102 *
103 * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10%
104 * cc-4.2 -xarch=v8 -xO5 -xdepend +10%
105 * egcs-1.1.2 -mv8 -O3 +35-45%
106 *
107 * As you can see it's damn hard to beat the new Sun C compiler
108 * and it's in first place GNU C users who will appreciate this
109 * assembler implementation:-)
110 */
111
112/*
113 * Revision history.
114 *
115 * 1.0 - initial release;
116 * 1.1 - new loop unrolling model(*);
117 * - some more fine tuning;
118 * 1.2 - made gas friendly;
119 * - updates to documentation concerning v9;
120 * - new performance comparison matrix;
121 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
122 * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient)
123 * resulting in slight overall performance kick;
124 * - some retunes;
125 * - support for GNU as added;
126 *
127 * (*) Originally unrolled loop looked like this:
128 * for (;;) {
129 * op(p+0); if (--n==0) break;
130 * op(p+1); if (--n==0) break;
131 * op(p+2); if (--n==0) break;
132 * op(p+3); if (--n==0) break;
133 * p+=4;
134 * }
135 * I unroll according to following:
136 * while (n&~3) {
137 * op(p+0); op(p+1); op(p+2); op(p+3);
138 * p+=4; n=-4;
139 * }
140 * if (n) {
141 * op(p+0); if (--n==0) return;
142 * op(p+2); if (--n==0) return;
143 * op(p+3); return;
144 * }
145 */
146
147/*
148 * GNU assembler can't stand stuw:-(
149 */
150#define stuw st
151
152.section ".text",#alloc,#execinstr
153.file "bn_asm.sparc.v8plus.S"
154
155.align 32
156
157.global bn_mul_add_words
158/*
159 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
160 * BN_ULONG *rp,*ap;
161 * int num;
162 * BN_ULONG w;
163 */
164bn_mul_add_words:
165 brgz,a %o2,.L_bn_mul_add_words_proceed
166 lduw [%o1],%g2
167 retl
168 clr %o0
169
170.L_bn_mul_add_words_proceed:
171 srl %o3,%g0,%o3 ! clruw %o3
172 andcc %o2,-4,%g0
173 bz,pn %icc,.L_bn_mul_add_words_tail
174 clr %o5
175
176.L_bn_mul_add_words_loop: ! wow! 32 aligned!
177 lduw [%o0],%g1
178 lduw [%o1+4],%g3
179 mulx %o3,%g2,%g2
180 add %g1,%o5,%o4
181 nop
182 add %o4,%g2,%o4
183 stuw %o4,[%o0]
184 srlx %o4,32,%o5
185
186 lduw [%o0+4],%g1
187 lduw [%o1+8],%g2
188 mulx %o3,%g3,%g3
189 add %g1,%o5,%o4
190 dec 4,%o2
191 add %o4,%g3,%o4
192 stuw %o4,[%o0+4]
193 srlx %o4,32,%o5
194
195 lduw [%o0+8],%g1
196 lduw [%o1+12],%g3
197 mulx %o3,%g2,%g2
198 add %g1,%o5,%o4
199 inc 16,%o1
200 add %o4,%g2,%o4
201 stuw %o4,[%o0+8]
202 srlx %o4,32,%o5
203
204 lduw [%o0+12],%g1
205 mulx %o3,%g3,%g3
206 add %g1,%o5,%o4
207 inc 16,%o0
208 add %o4,%g3,%o4
209 andcc %o2,-4,%g0
210 stuw %o4,[%o0-4]
211 srlx %o4,32,%o5
212 bnz,a,pt %icc,.L_bn_mul_add_words_loop
213 lduw [%o1],%g2
214
215 brnz,a,pn %o2,.L_bn_mul_add_words_tail
216 lduw [%o1],%g2
217.L_bn_mul_add_words_return:
218 retl
219 mov %o5,%o0
220
221.L_bn_mul_add_words_tail:
222 lduw [%o0],%g1
223 mulx %o3,%g2,%g2
224 add %g1,%o5,%o4
225 dec %o2
226 add %o4,%g2,%o4
227 srlx %o4,32,%o5
228 brz,pt %o2,.L_bn_mul_add_words_return
229 stuw %o4,[%o0]
230
231 lduw [%o1+4],%g2
232 lduw [%o0+4],%g1
233 mulx %o3,%g2,%g2
234 add %g1,%o5,%o4
235 dec %o2
236 add %o4,%g2,%o4
237 srlx %o4,32,%o5
238 brz,pt %o2,.L_bn_mul_add_words_return
239 stuw %o4,[%o0+4]
240
241 lduw [%o1+8],%g2
242 lduw [%o0+8],%g1
243 mulx %o3,%g2,%g2
244 add %g1,%o5,%o4
245 add %o4,%g2,%o4
246 stuw %o4,[%o0+8]
247 retl
248 srlx %o4,32,%o0
249
250.type bn_mul_add_words,#function
251.size bn_mul_add_words,(.-bn_mul_add_words)
252
253.align 32
254
255.global bn_mul_words
256/*
257 * BN_ULONG bn_mul_words(rp,ap,num,w)
258 * BN_ULONG *rp,*ap;
259 * int num;
260 * BN_ULONG w;
261 */
262bn_mul_words:
263 brgz,a %o2,.L_bn_mul_words_proceeed
264 lduw [%o1],%g2
265 retl
266 clr %o0
267
268.L_bn_mul_words_proceeed:
269 srl %o3,%g0,%o3 ! clruw %o3
270 andcc %o2,-4,%g0
271 bz,pn %icc,.L_bn_mul_words_tail
272 clr %o5
273
274.L_bn_mul_words_loop: ! wow! 32 aligned!
275 lduw [%o1+4],%g3
276 mulx %o3,%g2,%g2
277 add %g2,%o5,%o4
278 nop
279 stuw %o4,[%o0]
280 srlx %o4,32,%o5
281
282 lduw [%o1+8],%g2
283 mulx %o3,%g3,%g3
284 add %g3,%o5,%o4
285 dec 4,%o2
286 stuw %o4,[%o0+4]
287 srlx %o4,32,%o5
288
289 lduw [%o1+12],%g3
290 mulx %o3,%g2,%g2
291 add %g2,%o5,%o4
292 inc 16,%o1
293 stuw %o4,[%o0+8]
294 srlx %o4,32,%o5
295
296 mulx %o3,%g3,%g3
297 add %g3,%o5,%o4
298 inc 16,%o0
299 stuw %o4,[%o0-4]
300 srlx %o4,32,%o5
301 andcc %o2,-4,%g0
302 bnz,a,pt %icc,.L_bn_mul_words_loop
303 lduw [%o1],%g2
304 nop
305 nop
306
307 brnz,a,pn %o2,.L_bn_mul_words_tail
308 lduw [%o1],%g2
309.L_bn_mul_words_return:
310 retl
311 mov %o5,%o0
312
313.L_bn_mul_words_tail:
314 mulx %o3,%g2,%g2
315 add %g2,%o5,%o4
316 dec %o2
317 srlx %o4,32,%o5
318 brz,pt %o2,.L_bn_mul_words_return
319 stuw %o4,[%o0]
320
321 lduw [%o1+4],%g2
322 mulx %o3,%g2,%g2
323 add %g2,%o5,%o4
324 dec %o2
325 srlx %o4,32,%o5
326 brz,pt %o2,.L_bn_mul_words_return
327 stuw %o4,[%o0+4]
328
329 lduw [%o1+8],%g2
330 mulx %o3,%g2,%g2
331 add %g2,%o5,%o4
332 stuw %o4,[%o0+8]
333 retl
334 srlx %o4,32,%o0
335
336.type bn_mul_words,#function
337.size bn_mul_words,(.-bn_mul_words)
338
339.align 32
340.global bn_sqr_words
341/*
342 * void bn_sqr_words(r,a,n)
343 * BN_ULONG *r,*a;
344 * int n;
345 */
346bn_sqr_words:
347 brgz,a %o2,.L_bn_sqr_words_proceeed
348 lduw [%o1],%g2
349 retl
350 clr %o0
351
352.L_bn_sqr_words_proceeed:
353 andcc %o2,-4,%g0
354 nop
355 bz,pn %icc,.L_bn_sqr_words_tail
356 nop
357
358.L_bn_sqr_words_loop: ! wow! 32 aligned!
359 lduw [%o1+4],%g3
360 mulx %g2,%g2,%o4
361 stuw %o4,[%o0]
362 srlx %o4,32,%o5
363 stuw %o5,[%o0+4]
364 nop
365
366 lduw [%o1+8],%g2
367 mulx %g3,%g3,%o4
368 dec 4,%o2
369 stuw %o4,[%o0+8]
370 srlx %o4,32,%o5
371 stuw %o5,[%o0+12]
372
373 lduw [%o1+12],%g3
374 mulx %g2,%g2,%o4
375 srlx %o4,32,%o5
376 stuw %o4,[%o0+16]
377 inc 16,%o1
378 stuw %o5,[%o0+20]
379
380 mulx %g3,%g3,%o4
381 inc 32,%o0
382 stuw %o4,[%o0-8]
383 srlx %o4,32,%o5
384 andcc %o2,-4,%g2
385 stuw %o5,[%o0-4]
386 bnz,a,pt %icc,.L_bn_sqr_words_loop
387 lduw [%o1],%g2
388 nop
389
390 brnz,a,pn %o2,.L_bn_sqr_words_tail
391 lduw [%o1],%g2
392.L_bn_sqr_words_return:
393 retl
394 clr %o0
395
396.L_bn_sqr_words_tail:
397 mulx %g2,%g2,%o4
398 dec %o2
399 stuw %o4,[%o0]
400 srlx %o4,32,%o5
401 brz,pt %o2,.L_bn_sqr_words_return
402 stuw %o5,[%o0+4]
403
404 lduw [%o1+4],%g2
405 mulx %g2,%g2,%o4
406 dec %o2
407 stuw %o4,[%o0+8]
408 srlx %o4,32,%o5
409 brz,pt %o2,.L_bn_sqr_words_return
410 stuw %o5,[%o0+12]
411
412 lduw [%o1+8],%g2
413 mulx %g2,%g2,%o4
414 srlx %o4,32,%o5
415 stuw %o4,[%o0+16]
416 stuw %o5,[%o0+20]
417 retl
418 clr %o0
419
420.type bn_sqr_words,#function
421.size bn_sqr_words,(.-bn_sqr_words)
422
423.align 32
424.global bn_div_words
425/*
426 * BN_ULONG bn_div_words(h,l,d)
427 * BN_ULONG h,l,d;
428 */
429bn_div_words:
430 sllx %o0,32,%o0
431 or %o0,%o1,%o0
432 udivx %o0,%o2,%o0
433 retl
434 srl %o0,%g0,%o0 ! clruw %o0
435
436.type bn_div_words,#function
437.size bn_div_words,(.-bn_div_words)
438
439.align 32
440
441.global bn_add_words
442/*
443 * BN_ULONG bn_add_words(rp,ap,bp,n)
444 * BN_ULONG *rp,*ap,*bp;
445 * int n;
446 */
447bn_add_words:
448 brgz,a %o3,.L_bn_add_words_proceed
449 lduw [%o1],%o4
450 retl
451 clr %o0
452
453.L_bn_add_words_proceed:
454 andcc %o3,-4,%g0
455 bz,pn %icc,.L_bn_add_words_tail
456 addcc %g0,0,%g0 ! clear carry flag
457 nop
458
459.L_bn_add_words_loop: ! wow! 32 aligned!
460 dec 4,%o3
461 lduw [%o2],%o5
462 lduw [%o1+4],%g1
463 lduw [%o2+4],%g2
464 lduw [%o1+8],%g3
465 lduw [%o2+8],%g4
466 addccc %o5,%o4,%o5
467 stuw %o5,[%o0]
468
469 lduw [%o1+12],%o4
470 lduw [%o2+12],%o5
471 inc 16,%o1
472 addccc %g1,%g2,%g1
473 stuw %g1,[%o0+4]
474
475 inc 16,%o2
476 addccc %g3,%g4,%g3
477 stuw %g3,[%o0+8]
478
479 inc 16,%o0
480 addccc %o5,%o4,%o5
481 stuw %o5,[%o0-4]
482 and %o3,-4,%g1
483 brnz,a,pt %g1,.L_bn_add_words_loop
484 lduw [%o1],%o4
485
486 brnz,a,pn %o3,.L_bn_add_words_tail
487 lduw [%o1],%o4
488.L_bn_add_words_return:
489 clr %o0
490 retl
491 movcs %icc,1,%o0
492 nop
493
494.L_bn_add_words_tail:
495 lduw [%o2],%o5
496 dec %o3
497 addccc %o5,%o4,%o5
498 brz,pt %o3,.L_bn_add_words_return
499 stuw %o5,[%o0]
500
501 lduw [%o1+4],%o4
502 lduw [%o2+4],%o5
503 dec %o3
504 addccc %o5,%o4,%o5
505 brz,pt %o3,.L_bn_add_words_return
506 stuw %o5,[%o0+4]
507
508 lduw [%o1+8],%o4
509 lduw [%o2+8],%o5
510 addccc %o5,%o4,%o5
511 stuw %o5,[%o0+8]
512 clr %o0
513 retl
514 movcs %icc,1,%o0
515
516.type bn_add_words,#function
517.size bn_add_words,(.-bn_add_words)
518
519.global bn_sub_words
520/*
521 * BN_ULONG bn_sub_words(rp,ap,bp,n)
522 * BN_ULONG *rp,*ap,*bp;
523 * int n;
524 */
525bn_sub_words:
526 brgz,a %o3,.L_bn_sub_words_proceed
527 lduw [%o1],%o4
528 retl
529 clr %o0
530
531.L_bn_sub_words_proceed:
532 andcc %o3,-4,%g0
533 bz,pn %icc,.L_bn_sub_words_tail
534 addcc %g0,0,%g0 ! clear carry flag
535 nop
536
537.L_bn_sub_words_loop: ! wow! 32 aligned!
538 dec 4,%o3
539 lduw [%o2],%o5
540 lduw [%o1+4],%g1
541 lduw [%o2+4],%g2
542 lduw [%o1+8],%g3
543 lduw [%o2+8],%g4
544 subccc %o4,%o5,%o5
545 stuw %o5,[%o0]
546
547 lduw [%o1+12],%o4
548 lduw [%o2+12],%o5
549 inc 16,%o1
550 subccc %g1,%g2,%g2
551 stuw %g2,[%o0+4]
552
553 inc 16,%o2
554 subccc %g3,%g4,%g4
555 stuw %g4,[%o0+8]
556
557 inc 16,%o0
558 subccc %o4,%o5,%o5
559 stuw %o5,[%o0-4]
560 and %o3,-4,%g1
561 brnz,a,pt %g1,.L_bn_sub_words_loop
562 lduw [%o1],%o4
563
564 brnz,a,pn %o3,.L_bn_sub_words_tail
565 lduw [%o1],%o4
566.L_bn_sub_words_return:
567 clr %o0
568 retl
569 movcs %icc,1,%o0
570 nop
571
572.L_bn_sub_words_tail: ! wow! 32 aligned!
573 lduw [%o2],%o5
574 dec %o3
575 subccc %o4,%o5,%o5
576 brz,pt %o3,.L_bn_sub_words_return
577 stuw %o5,[%o0]
578
579 lduw [%o1+4],%o4
580 lduw [%o2+4],%o5
581 dec %o3
582 subccc %o4,%o5,%o5
583 brz,pt %o3,.L_bn_sub_words_return
584 stuw %o5,[%o0+4]
585
586 lduw [%o1+8],%o4
587 lduw [%o2+8],%o5
588 subccc %o4,%o5,%o5
589 stuw %o5,[%o0+8]
590 clr %o0
591 retl
592 movcs %icc,1,%o0
593
594.type bn_sub_words,#function
595.size bn_sub_words,(.-bn_sub_words)
596
597/*
598 * Code below depends on the fact that upper parts of the %l0-%l7
599 * and %i0-%i7 are zeroed by kernel after context switch. In
600 * previous versions this comment stated that "the trouble is that
601 * it's not feasible to implement the mumbo-jumbo in less V9
602 * instructions:-(" which apparently isn't true thanks to
603 * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement
604 * results not from the shorter code, but from elimination of
605 * multicycle none-pairable 'rd %y,%rd' instructions.
606 *
607 * Andy.
608 */
609
610#define FRAME_SIZE -96
611
612/*
613 * Here is register usage map for *all* routines below.
614 */
615#define t_1 %o0
616#define t_2 %o1
617#define c_12 %o2
618#define c_3 %o3
619
620#define ap(I) [%i1+4*I]
621#define bp(I) [%i2+4*I]
622#define rp(I) [%i0+4*I]
623
624#define a_0 %l0
625#define a_1 %l1
626#define a_2 %l2
627#define a_3 %l3
628#define a_4 %l4
629#define a_5 %l5
630#define a_6 %l6
631#define a_7 %l7
632
633#define b_0 %i3
634#define b_1 %i4
635#define b_2 %i5
636#define b_3 %o4
637#define b_4 %o5
638#define b_5 %o7
639#define b_6 %g1
640#define b_7 %g4
641
642.align 32
643.global bn_mul_comba8
644/*
645 * void bn_mul_comba8(r,a,b)
646 * BN_ULONG *r,*a,*b;
647 */
648bn_mul_comba8:
649 save %sp,FRAME_SIZE,%sp
650 mov 1,t_2
651 lduw ap(0),a_0
652 sllx t_2,32,t_2
653 lduw bp(0),b_0 !=
654 lduw bp(1),b_1
655 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
656 srlx t_1,32,c_12
657 stuw t_1,rp(0) !=!r[0]=c1;
658
659 lduw ap(1),a_1
660 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
661 addcc c_12,t_1,c_12
662 clr c_3 !=
663 bcs,a %xcc,.+8
664 add c_3,t_2,c_3
665 lduw ap(2),a_2
666 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
667 addcc c_12,t_1,t_1
668 bcs,a %xcc,.+8
669 add c_3,t_2,c_3
670 srlx t_1,32,c_12 !=
671 stuw t_1,rp(1) !r[1]=c2;
672 or c_12,c_3,c_12
673
674 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
675 addcc c_12,t_1,c_12 !=
676 clr c_3
677 bcs,a %xcc,.+8
678 add c_3,t_2,c_3
679 lduw bp(2),b_2 !=
680 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
681 addcc c_12,t_1,c_12
682 bcs,a %xcc,.+8
683 add c_3,t_2,c_3 !=
684 lduw bp(3),b_3
685 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
686 addcc c_12,t_1,t_1
687 bcs,a %xcc,.+8 !=
688 add c_3,t_2,c_3
689 srlx t_1,32,c_12
690 stuw t_1,rp(2) !r[2]=c3;
691 or c_12,c_3,c_12 !=
692
693 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
694 addcc c_12,t_1,c_12
695 clr c_3
696 bcs,a %xcc,.+8 !=
697 add c_3,t_2,c_3
698 mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
699 addcc c_12,t_1,c_12
700 bcs,a %xcc,.+8 !=
701 add c_3,t_2,c_3
702 lduw ap(3),a_3
703 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
704 addcc c_12,t_1,c_12 !=
705 bcs,a %xcc,.+8
706 add c_3,t_2,c_3
707 lduw ap(4),a_4
708 mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!=
709 addcc c_12,t_1,t_1
710 bcs,a %xcc,.+8
711 add c_3,t_2,c_3
712 srlx t_1,32,c_12 !=
713 stuw t_1,rp(3) !r[3]=c1;
714 or c_12,c_3,c_12
715
716 mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
717 addcc c_12,t_1,c_12 !=
718 clr c_3
719 bcs,a %xcc,.+8
720 add c_3,t_2,c_3
721 mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1);
722 addcc c_12,t_1,c_12
723 bcs,a %xcc,.+8
724 add c_3,t_2,c_3
725 mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
726 addcc c_12,t_1,c_12
727 bcs,a %xcc,.+8
728 add c_3,t_2,c_3
729 lduw bp(4),b_4 !=
730 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
731 addcc c_12,t_1,c_12
732 bcs,a %xcc,.+8
733 add c_3,t_2,c_3 !=
734 lduw bp(5),b_5
735 mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1);
736 addcc c_12,t_1,t_1
737 bcs,a %xcc,.+8 !=
738 add c_3,t_2,c_3
739 srlx t_1,32,c_12
740 stuw t_1,rp(4) !r[4]=c2;
741 or c_12,c_3,c_12 !=
742
743 mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
744 addcc c_12,t_1,c_12
745 clr c_3
746 bcs,a %xcc,.+8 !=
747 add c_3,t_2,c_3
748 mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
749 addcc c_12,t_1,c_12
750 bcs,a %xcc,.+8 !=
751 add c_3,t_2,c_3
752 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
753 addcc c_12,t_1,c_12
754 bcs,a %xcc,.+8 !=
755 add c_3,t_2,c_3
756 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
757 addcc c_12,t_1,c_12
758 bcs,a %xcc,.+8 !=
759 add c_3,t_2,c_3
760 lduw ap(5),a_5
761 mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
762 addcc c_12,t_1,c_12 !=
763 bcs,a %xcc,.+8
764 add c_3,t_2,c_3
765 lduw ap(6),a_6
766 mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2);
767 addcc c_12,t_1,t_1
768 bcs,a %xcc,.+8
769 add c_3,t_2,c_3
770 srlx t_1,32,c_12 !=
771 stuw t_1,rp(5) !r[5]=c3;
772 or c_12,c_3,c_12
773
774 mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
775 addcc c_12,t_1,c_12 !=
776 clr c_3
777 bcs,a %xcc,.+8
778 add c_3,t_2,c_3
779 mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
780 addcc c_12,t_1,c_12
781 bcs,a %xcc,.+8
782 add c_3,t_2,c_3
783 mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3);
784 addcc c_12,t_1,c_12
785 bcs,a %xcc,.+8
786 add c_3,t_2,c_3
787 mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3);
788 addcc c_12,t_1,c_12
789 bcs,a %xcc,.+8
790 add c_3,t_2,c_3
791 mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3);
792 addcc c_12,t_1,c_12
793 bcs,a %xcc,.+8
794 add c_3,t_2,c_3
795 lduw bp(6),b_6 !=
796 mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
797 addcc c_12,t_1,c_12
798 bcs,a %xcc,.+8
799 add c_3,t_2,c_3 !=
800 lduw bp(7),b_7
801 mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
802 addcc c_12,t_1,t_1
803 bcs,a %xcc,.+8 !=
804 add c_3,t_2,c_3
805 srlx t_1,32,c_12
806 stuw t_1,rp(6) !r[6]=c1;
807 or c_12,c_3,c_12 !=
808
809 mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
810 addcc c_12,t_1,c_12
811 clr c_3
812 bcs,a %xcc,.+8 !=
813 add c_3,t_2,c_3
814 mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
815 addcc c_12,t_1,c_12
816 bcs,a %xcc,.+8 !=
817 add c_3,t_2,c_3
818 mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
819 addcc c_12,t_1,c_12
820 bcs,a %xcc,.+8 !=
821 add c_3,t_2,c_3
822 mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1);
823 addcc c_12,t_1,c_12
824 bcs,a %xcc,.+8 !=
825 add c_3,t_2,c_3
826 mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
827 addcc c_12,t_1,c_12
828 bcs,a %xcc,.+8 !=
829 add c_3,t_2,c_3
830 mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
831 addcc c_12,t_1,c_12
832 bcs,a %xcc,.+8 !=
833 add c_3,t_2,c_3
834 lduw ap(7),a_7
835 mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
836 addcc c_12,t_1,c_12
837 bcs,a %xcc,.+8
838 add c_3,t_2,c_3
839 mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1);
840 addcc c_12,t_1,t_1
841 bcs,a %xcc,.+8
842 add c_3,t_2,c_3
843 srlx t_1,32,c_12 !=
844 stuw t_1,rp(7) !r[7]=c2;
845 or c_12,c_3,c_12
846
847 mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2);
848 addcc c_12,t_1,c_12
849 clr c_3
850 bcs,a %xcc,.+8
851 add c_3,t_2,c_3 !=
852 mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2);
853 addcc c_12,t_1,c_12
854 bcs,a %xcc,.+8
855 add c_3,t_2,c_3 !=
856 mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
857 addcc c_12,t_1,c_12
858 bcs,a %xcc,.+8
859 add c_3,t_2,c_3 !=
860 mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
861 addcc c_12,t_1,c_12
862 bcs,a %xcc,.+8
863 add c_3,t_2,c_3 !=
864 mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
865 addcc c_12,t_1,c_12
866 bcs,a %xcc,.+8
867 add c_3,t_2,c_3 !=
868 mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2);
869 addcc c_12,t_1,c_12
870 bcs,a %xcc,.+8
871 add c_3,t_2,c_3 !=
872 mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
873 addcc c_12,t_1,t_1
874 bcs,a %xcc,.+8
875 add c_3,t_2,c_3 !=
876 srlx t_1,32,c_12
877 stuw t_1,rp(8) !r[8]=c3;
878 or c_12,c_3,c_12
879
880 mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3);
881 addcc c_12,t_1,c_12
882 clr c_3
883 bcs,a %xcc,.+8
884 add c_3,t_2,c_3 !=
885 mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3);
886 addcc c_12,t_1,c_12
887 bcs,a %xcc,.+8 !=
888 add c_3,t_2,c_3
889 mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
890 addcc c_12,t_1,c_12
891 bcs,a %xcc,.+8 !=
892 add c_3,t_2,c_3
893 mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
894 addcc c_12,t_1,c_12
895 bcs,a %xcc,.+8 !=
896 add c_3,t_2,c_3
897 mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
898 addcc c_12,t_1,c_12
899 bcs,a %xcc,.+8 !=
900 add c_3,t_2,c_3
901 mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3);
902 addcc c_12,t_1,t_1
903 bcs,a %xcc,.+8 !=
904 add c_3,t_2,c_3
905 srlx t_1,32,c_12
906 stuw t_1,rp(9) !r[9]=c1;
907 or c_12,c_3,c_12 !=
908
909 mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
910 addcc c_12,t_1,c_12
911 clr c_3
912 bcs,a %xcc,.+8 !=
913 add c_3,t_2,c_3
914 mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
915 addcc c_12,t_1,c_12
916 bcs,a %xcc,.+8 !=
917 add c_3,t_2,c_3
918 mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1);
919 addcc c_12,t_1,c_12
920 bcs,a %xcc,.+8 !=
921 add c_3,t_2,c_3
922 mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
923 addcc c_12,t_1,c_12
924 bcs,a %xcc,.+8 !=
925 add c_3,t_2,c_3
926 mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
927 addcc c_12,t_1,t_1
928 bcs,a %xcc,.+8 !=
929 add c_3,t_2,c_3
930 srlx t_1,32,c_12
931 stuw t_1,rp(10) !r[10]=c2;
932 or c_12,c_3,c_12 !=
933
934 mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2);
935 addcc c_12,t_1,c_12
936 clr c_3
937 bcs,a %xcc,.+8 !=
938 add c_3,t_2,c_3
939 mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
940 addcc c_12,t_1,c_12
941 bcs,a %xcc,.+8 !=
942 add c_3,t_2,c_3
943 mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
944 addcc c_12,t_1,c_12
945 bcs,a %xcc,.+8 !=
946 add c_3,t_2,c_3
947 mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
948 addcc c_12,t_1,t_1
949 bcs,a %xcc,.+8 !=
950 add c_3,t_2,c_3
951 srlx t_1,32,c_12
952 stuw t_1,rp(11) !r[11]=c3;
953 or c_12,c_3,c_12 !=
954
955 mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
956 addcc c_12,t_1,c_12
957 clr c_3
958 bcs,a %xcc,.+8 !=
959 add c_3,t_2,c_3
960 mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
961 addcc c_12,t_1,c_12
962 bcs,a %xcc,.+8 !=
963 add c_3,t_2,c_3
964 mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
965 addcc c_12,t_1,t_1
966 bcs,a %xcc,.+8 !=
967 add c_3,t_2,c_3
968 srlx t_1,32,c_12
969 stuw t_1,rp(12) !r[12]=c1;
970 or c_12,c_3,c_12 !=
971
972 mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
973 addcc c_12,t_1,c_12
974 clr c_3
975 bcs,a %xcc,.+8 !=
976 add c_3,t_2,c_3
977 mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
978 addcc c_12,t_1,t_1
979 bcs,a %xcc,.+8 !=
980 add c_3,t_2,c_3
981 srlx t_1,32,c_12
982 st t_1,rp(13) !r[13]=c2;
983 or c_12,c_3,c_12 !=
984
985 mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2);
986 addcc c_12,t_1,t_1
987 srlx t_1,32,c_12 !=
988 stuw t_1,rp(14) !r[14]=c3;
989 stuw c_12,rp(15) !r[15]=c1;
990
991 ret
992 restore %g0,%g0,%o0 !=
993
994.type bn_mul_comba8,#function
995.size bn_mul_comba8,(.-bn_mul_comba8)
996
997.align 32
998
999.global bn_mul_comba4
1000/*
1001 * void bn_mul_comba4(r,a,b)
1002 * BN_ULONG *r,*a,*b;
1003 */
1004bn_mul_comba4:
1005 save %sp,FRAME_SIZE,%sp
1006 lduw ap(0),a_0
1007 mov 1,t_2
1008 lduw bp(0),b_0
1009 sllx t_2,32,t_2 !=
1010 lduw bp(1),b_1
1011 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
1012 srlx t_1,32,c_12
1013 stuw t_1,rp(0) !=!r[0]=c1;
1014
1015 lduw ap(1),a_1
1016 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
1017 addcc c_12,t_1,c_12
1018 clr c_3 !=
1019 bcs,a %xcc,.+8
1020 add c_3,t_2,c_3
1021 lduw ap(2),a_2
1022 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
1023 addcc c_12,t_1,t_1
1024 bcs,a %xcc,.+8
1025 add c_3,t_2,c_3
1026 srlx t_1,32,c_12 !=
1027 stuw t_1,rp(1) !r[1]=c2;
1028 or c_12,c_3,c_12
1029
1030 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
1031 addcc c_12,t_1,c_12 !=
1032 clr c_3
1033 bcs,a %xcc,.+8
1034 add c_3,t_2,c_3
1035 lduw bp(2),b_2 !=
1036 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
1037 addcc c_12,t_1,c_12
1038 bcs,a %xcc,.+8
1039 add c_3,t_2,c_3 !=
1040 lduw bp(3),b_3
1041 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
1042 addcc c_12,t_1,t_1
1043 bcs,a %xcc,.+8 !=
1044 add c_3,t_2,c_3
1045 srlx t_1,32,c_12
1046 stuw t_1,rp(2) !r[2]=c3;
1047 or c_12,c_3,c_12 !=
1048
1049 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
1050 addcc c_12,t_1,c_12
1051 clr c_3
1052 bcs,a %xcc,.+8 !=
1053 add c_3,t_2,c_3
1054 mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
1055 addcc c_12,t_1,c_12
1056 bcs,a %xcc,.+8 !=
1057 add c_3,t_2,c_3
1058 lduw ap(3),a_3
1059 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
1060 addcc c_12,t_1,c_12 !=
1061 bcs,a %xcc,.+8
1062 add c_3,t_2,c_3
1063 mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
1064 addcc c_12,t_1,t_1 !=
1065 bcs,a %xcc,.+8
1066 add c_3,t_2,c_3
1067 srlx t_1,32,c_12
1068 stuw t_1,rp(3) !=!r[3]=c1;
1069 or c_12,c_3,c_12
1070
1071 mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1072 addcc c_12,t_1,c_12
1073 clr c_3 !=
1074 bcs,a %xcc,.+8
1075 add c_3,t_2,c_3
1076 mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1077 addcc c_12,t_1,c_12 !=
1078 bcs,a %xcc,.+8
1079 add c_3,t_2,c_3
1080 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
1081 addcc c_12,t_1,t_1 !=
1082 bcs,a %xcc,.+8
1083 add c_3,t_2,c_3
1084 srlx t_1,32,c_12
1085 stuw t_1,rp(4) !=!r[4]=c2;
1086 or c_12,c_3,c_12
1087
1088 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1089 addcc c_12,t_1,c_12
1090 clr c_3 !=
1091 bcs,a %xcc,.+8
1092 add c_3,t_2,c_3
1093 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1094 addcc c_12,t_1,t_1 !=
1095 bcs,a %xcc,.+8
1096 add c_3,t_2,c_3
1097 srlx t_1,32,c_12
1098 stuw t_1,rp(5) !=!r[5]=c3;
1099 or c_12,c_3,c_12
1100
1101 mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1102 addcc c_12,t_1,t_1
1103 srlx t_1,32,c_12 !=
1104 stuw t_1,rp(6) !r[6]=c1;
1105 stuw c_12,rp(7) !r[7]=c2;
1106
1107 ret
1108 restore %g0,%g0,%o0
1109
1110.type bn_mul_comba4,#function
1111.size bn_mul_comba4,(.-bn_mul_comba4)
1112
1113.align 32
1114
1115.global bn_sqr_comba8
1116bn_sqr_comba8:
1117 save %sp,FRAME_SIZE,%sp
1118 mov 1,t_2
1119 lduw ap(0),a_0
1120 sllx t_2,32,t_2
1121 lduw ap(1),a_1
1122 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1123 srlx t_1,32,c_12
1124 stuw t_1,rp(0) !r[0]=c1;
1125
1126 lduw ap(2),a_2
1127 mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1128 addcc c_12,t_1,c_12
1129 clr c_3
1130 bcs,a %xcc,.+8
1131 add c_3,t_2,c_3
1132 addcc c_12,t_1,t_1
1133 bcs,a %xcc,.+8
1134 add c_3,t_2,c_3
1135 srlx t_1,32,c_12
1136 stuw t_1,rp(1) !r[1]=c2;
1137 or c_12,c_3,c_12
1138
1139 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1140 addcc c_12,t_1,c_12
1141 clr c_3
1142 bcs,a %xcc,.+8
1143 add c_3,t_2,c_3
1144 addcc c_12,t_1,c_12
1145 bcs,a %xcc,.+8
1146 add c_3,t_2,c_3
1147 lduw ap(3),a_3
1148 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1149 addcc c_12,t_1,t_1
1150 bcs,a %xcc,.+8
1151 add c_3,t_2,c_3
1152 srlx t_1,32,c_12
1153 stuw t_1,rp(2) !r[2]=c3;
1154 or c_12,c_3,c_12
1155
1156 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1157 addcc c_12,t_1,c_12
1158 clr c_3
1159 bcs,a %xcc,.+8
1160 add c_3,t_2,c_3
1161 addcc c_12,t_1,c_12
1162 bcs,a %xcc,.+8
1163 add c_3,t_2,c_3
1164 lduw ap(4),a_4
1165 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1166 addcc c_12,t_1,c_12
1167 bcs,a %xcc,.+8
1168 add c_3,t_2,c_3
1169 addcc c_12,t_1,t_1
1170 bcs,a %xcc,.+8
1171 add c_3,t_2,c_3
1172 srlx t_1,32,c_12
1173 st t_1,rp(3) !r[3]=c1;
1174 or c_12,c_3,c_12
1175
1176 mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1177 addcc c_12,t_1,c_12
1178 clr c_3
1179 bcs,a %xcc,.+8
1180 add c_3,t_2,c_3
1181 addcc c_12,t_1,c_12
1182 bcs,a %xcc,.+8
1183 add c_3,t_2,c_3
1184 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1185 addcc c_12,t_1,c_12
1186 bcs,a %xcc,.+8
1187 add c_3,t_2,c_3
1188 addcc c_12,t_1,c_12
1189 bcs,a %xcc,.+8
1190 add c_3,t_2,c_3
1191 lduw ap(5),a_5
1192 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1193 addcc c_12,t_1,t_1
1194 bcs,a %xcc,.+8
1195 add c_3,t_2,c_3
1196 srlx t_1,32,c_12
1197 stuw t_1,rp(4) !r[4]=c2;
1198 or c_12,c_3,c_12
1199
1200 mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1201 addcc c_12,t_1,c_12
1202 clr c_3
1203 bcs,a %xcc,.+8
1204 add c_3,t_2,c_3
1205 addcc c_12,t_1,c_12
1206 bcs,a %xcc,.+8
1207 add c_3,t_2,c_3
1208 mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1209 addcc c_12,t_1,c_12
1210 bcs,a %xcc,.+8
1211 add c_3,t_2,c_3
1212 addcc c_12,t_1,c_12
1213 bcs,a %xcc,.+8
1214 add c_3,t_2,c_3
1215 lduw ap(6),a_6
1216 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1217 addcc c_12,t_1,c_12
1218 bcs,a %xcc,.+8
1219 add c_3,t_2,c_3
1220 addcc c_12,t_1,t_1
1221 bcs,a %xcc,.+8
1222 add c_3,t_2,c_3
1223 srlx t_1,32,c_12
1224 stuw t_1,rp(5) !r[5]=c3;
1225 or c_12,c_3,c_12
1226
1227 mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1228 addcc c_12,t_1,c_12
1229 clr c_3
1230 bcs,a %xcc,.+8
1231 add c_3,t_2,c_3
1232 addcc c_12,t_1,c_12
1233 bcs,a %xcc,.+8
1234 add c_3,t_2,c_3
1235 mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1236 addcc c_12,t_1,c_12
1237 bcs,a %xcc,.+8
1238 add c_3,t_2,c_3
1239 addcc c_12,t_1,c_12
1240 bcs,a %xcc,.+8
1241 add c_3,t_2,c_3
1242 mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1243 addcc c_12,t_1,c_12
1244 bcs,a %xcc,.+8
1245 add c_3,t_2,c_3
1246 addcc c_12,t_1,c_12
1247 bcs,a %xcc,.+8
1248 add c_3,t_2,c_3
1249 lduw ap(7),a_7
1250 mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1251 addcc c_12,t_1,t_1
1252 bcs,a %xcc,.+8
1253 add c_3,t_2,c_3
1254 srlx t_1,32,c_12
1255 stuw t_1,rp(6) !r[6]=c1;
1256 or c_12,c_3,c_12
1257
1258 mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1259 addcc c_12,t_1,c_12
1260 clr c_3
1261 bcs,a %xcc,.+8
1262 add c_3,t_2,c_3
1263 addcc c_12,t_1,c_12
1264 bcs,a %xcc,.+8
1265 add c_3,t_2,c_3
1266 mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1267 addcc c_12,t_1,c_12
1268 bcs,a %xcc,.+8
1269 add c_3,t_2,c_3
1270 addcc c_12,t_1,c_12
1271 bcs,a %xcc,.+8
1272 add c_3,t_2,c_3
1273 mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1274 addcc c_12,t_1,c_12
1275 bcs,a %xcc,.+8
1276 add c_3,t_2,c_3
1277 addcc c_12,t_1,c_12
1278 bcs,a %xcc,.+8
1279 add c_3,t_2,c_3
1280 mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1281 addcc c_12,t_1,c_12
1282 bcs,a %xcc,.+8
1283 add c_3,t_2,c_3
1284 addcc c_12,t_1,t_1
1285 bcs,a %xcc,.+8
1286 add c_3,t_2,c_3
1287 srlx t_1,32,c_12
1288 stuw t_1,rp(7) !r[7]=c2;
1289 or c_12,c_3,c_12
1290
1291 mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1292 addcc c_12,t_1,c_12
1293 clr c_3
1294 bcs,a %xcc,.+8
1295 add c_3,t_2,c_3
1296 addcc c_12,t_1,c_12
1297 bcs,a %xcc,.+8
1298 add c_3,t_2,c_3
1299 mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1300 addcc c_12,t_1,c_12
1301 bcs,a %xcc,.+8
1302 add c_3,t_2,c_3
1303 addcc c_12,t_1,c_12
1304 bcs,a %xcc,.+8
1305 add c_3,t_2,c_3
1306 mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1307 addcc c_12,t_1,c_12
1308 bcs,a %xcc,.+8
1309 add c_3,t_2,c_3
1310 addcc c_12,t_1,c_12
1311 bcs,a %xcc,.+8
1312 add c_3,t_2,c_3
1313 mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1314 addcc c_12,t_1,t_1
1315 bcs,a %xcc,.+8
1316 add c_3,t_2,c_3
1317 srlx t_1,32,c_12
1318 stuw t_1,rp(8) !r[8]=c3;
1319 or c_12,c_3,c_12
1320
1321 mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1322 addcc c_12,t_1,c_12
1323 clr c_3
1324 bcs,a %xcc,.+8
1325 add c_3,t_2,c_3
1326 addcc c_12,t_1,c_12
1327 bcs,a %xcc,.+8
1328 add c_3,t_2,c_3
1329 mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1330 addcc c_12,t_1,c_12
1331 bcs,a %xcc,.+8
1332 add c_3,t_2,c_3
1333 addcc c_12,t_1,c_12
1334 bcs,a %xcc,.+8
1335 add c_3,t_2,c_3
1336 mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1337 addcc c_12,t_1,c_12
1338 bcs,a %xcc,.+8
1339 add c_3,t_2,c_3
1340 addcc c_12,t_1,t_1
1341 bcs,a %xcc,.+8
1342 add c_3,t_2,c_3
1343 srlx t_1,32,c_12
1344 stuw t_1,rp(9) !r[9]=c1;
1345 or c_12,c_3,c_12
1346
1347 mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1348 addcc c_12,t_1,c_12
1349 clr c_3
1350 bcs,a %xcc,.+8
1351 add c_3,t_2,c_3
1352 addcc c_12,t_1,c_12
1353 bcs,a %xcc,.+8
1354 add c_3,t_2,c_3
1355 mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1356 addcc c_12,t_1,c_12
1357 bcs,a %xcc,.+8
1358 add c_3,t_2,c_3
1359 addcc c_12,t_1,c_12
1360 bcs,a %xcc,.+8
1361 add c_3,t_2,c_3
1362 mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1363 addcc c_12,t_1,t_1
1364 bcs,a %xcc,.+8
1365 add c_3,t_2,c_3
1366 srlx t_1,32,c_12
1367 stuw t_1,rp(10) !r[10]=c2;
1368 or c_12,c_3,c_12
1369
1370 mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2);
1371 addcc c_12,t_1,c_12
1372 clr c_3
1373 bcs,a %xcc,.+8
1374 add c_3,t_2,c_3
1375 addcc c_12,t_1,c_12
1376 bcs,a %xcc,.+8
1377 add c_3,t_2,c_3
1378 mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2);
1379 addcc c_12,t_1,c_12
1380 bcs,a %xcc,.+8
1381 add c_3,t_2,c_3
1382 addcc c_12,t_1,t_1
1383 bcs,a %xcc,.+8
1384 add c_3,t_2,c_3
1385 srlx t_1,32,c_12
1386 stuw t_1,rp(11) !r[11]=c3;
1387 or c_12,c_3,c_12
1388
1389 mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1390 addcc c_12,t_1,c_12
1391 clr c_3
1392 bcs,a %xcc,.+8
1393 add c_3,t_2,c_3
1394 addcc c_12,t_1,c_12
1395 bcs,a %xcc,.+8
1396 add c_3,t_2,c_3
1397 mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1398 addcc c_12,t_1,t_1
1399 bcs,a %xcc,.+8
1400 add c_3,t_2,c_3
1401 srlx t_1,32,c_12
1402 stuw t_1,rp(12) !r[12]=c1;
1403 or c_12,c_3,c_12
1404
1405 mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1406 addcc c_12,t_1,c_12
1407 clr c_3
1408 bcs,a %xcc,.+8
1409 add c_3,t_2,c_3
1410 addcc c_12,t_1,t_1
1411 bcs,a %xcc,.+8
1412 add c_3,t_2,c_3
1413 srlx t_1,32,c_12
1414 stuw t_1,rp(13) !r[13]=c2;
1415 or c_12,c_3,c_12
1416
1417 mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1418 addcc c_12,t_1,t_1
1419 srlx t_1,32,c_12
1420 stuw t_1,rp(14) !r[14]=c3;
1421 stuw c_12,rp(15) !r[15]=c1;
1422
1423 ret
1424 restore %g0,%g0,%o0
1425
1426.type bn_sqr_comba8,#function
1427.size bn_sqr_comba8,(.-bn_sqr_comba8)
1428
1429.align 32
1430
1431.global bn_sqr_comba4
1432/*
1433 * void bn_sqr_comba4(r,a)
1434 * BN_ULONG *r,*a;
1435 */
1436bn_sqr_comba4:
1437 save %sp,FRAME_SIZE,%sp
1438 mov 1,t_2
1439 lduw ap(0),a_0
1440 sllx t_2,32,t_2
1441 lduw ap(1),a_1
1442 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1443 srlx t_1,32,c_12
1444 stuw t_1,rp(0) !r[0]=c1;
1445
1446 lduw ap(2),a_2
1447 mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1);
1448 addcc c_12,t_1,c_12
1449 clr c_3
1450 bcs,a %xcc,.+8
1451 add c_3,t_2,c_3
1452 addcc c_12,t_1,t_1
1453 bcs,a %xcc,.+8
1454 add c_3,t_2,c_3
1455 srlx t_1,32,c_12
1456 stuw t_1,rp(1) !r[1]=c2;
1457 or c_12,c_3,c_12
1458
1459 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1460 addcc c_12,t_1,c_12
1461 clr c_3
1462 bcs,a %xcc,.+8
1463 add c_3,t_2,c_3
1464 addcc c_12,t_1,c_12
1465 bcs,a %xcc,.+8
1466 add c_3,t_2,c_3
1467 lduw ap(3),a_3
1468 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1469 addcc c_12,t_1,t_1
1470 bcs,a %xcc,.+8
1471 add c_3,t_2,c_3
1472 srlx t_1,32,c_12
1473 stuw t_1,rp(2) !r[2]=c3;
1474 or c_12,c_3,c_12
1475
1476 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1477 addcc c_12,t_1,c_12
1478 clr c_3
1479 bcs,a %xcc,.+8
1480 add c_3,t_2,c_3
1481 addcc c_12,t_1,c_12
1482 bcs,a %xcc,.+8
1483 add c_3,t_2,c_3
1484 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1485 addcc c_12,t_1,c_12
1486 bcs,a %xcc,.+8
1487 add c_3,t_2,c_3
1488 addcc c_12,t_1,t_1
1489 bcs,a %xcc,.+8
1490 add c_3,t_2,c_3
1491 srlx t_1,32,c_12
1492 stuw t_1,rp(3) !r[3]=c1;
1493 or c_12,c_3,c_12
1494
1495 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1496 addcc c_12,t_1,c_12
1497 clr c_3
1498 bcs,a %xcc,.+8
1499 add c_3,t_2,c_3
1500 addcc c_12,t_1,c_12
1501 bcs,a %xcc,.+8
1502 add c_3,t_2,c_3
1503 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1504 addcc c_12,t_1,t_1
1505 bcs,a %xcc,.+8
1506 add c_3,t_2,c_3
1507 srlx t_1,32,c_12
1508 stuw t_1,rp(4) !r[4]=c2;
1509 or c_12,c_3,c_12
1510
1511 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1512 addcc c_12,t_1,c_12
1513 clr c_3
1514 bcs,a %xcc,.+8
1515 add c_3,t_2,c_3
1516 addcc c_12,t_1,t_1
1517 bcs,a %xcc,.+8
1518 add c_3,t_2,c_3
1519 srlx t_1,32,c_12
1520 stuw t_1,rp(5) !r[5]=c3;
1521 or c_12,c_3,c_12
1522
1523 mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1524 addcc c_12,t_1,t_1
1525 srlx t_1,32,c_12
1526 stuw t_1,rp(6) !r[6]=c1;
1527 stuw c_12,rp(7) !r[7]=c2;
1528
1529 ret
1530 restore %g0,%g0,%o0
1531
1532.type bn_sqr_comba4,#function
1533.size bn_sqr_comba4,(.-bn_sqr_comba4)
1534
1535.align 32
diff --git a/src/lib/libssl/src/crypto/bn/asm/vms.mar b/src/lib/libssl/src/crypto/bn/asm/vms.mar
new file mode 100644
index 0000000000..ac9d57d7b0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/vms.mar
@@ -0,0 +1,6695 @@
1 .title vax_bn_mul_add_word unsigned multiply & add, 32*32+32+32=>64
2;
3; w.j.m. 15-jan-1999
4;
5; it's magic ...
6;
7; ULONG bn_mul_add_words(ULONG r[],ULONG a[],int n,ULONG w) {
8; ULONG c = 0;
9; int i;
10; for(i = 0; i < n; i++) <c,r[i]> := r[i] + c + a[i] * w ;
11; return c;
12; }
13
14r=4 ;(AP)
15a=8 ;(AP)
16n=12 ;(AP) n by value (input)
17w=16 ;(AP) w by value (input)
18
19
20 .psect code,nowrt
21
22.entry bn_mul_add_words,^m<r2,r3,r4,r5,r6>
23
24 moval @r(ap),r2
25 moval @a(ap),r3
26 movl n(ap),r4 ; assumed >0 by C code
27 movl w(ap),r5
28 clrl r6 ; c
29
300$:
31 emul r5,(r3),(r2),r0 ; w, a[], r[] considered signed
32
33 ; fixup for "negative" r[]
34 tstl (r2)
35 bgeq 10$
36 incl r1
3710$:
38
39 ; add in c
40 addl2 r6,r0
41 adwc #0,r1
42
43 ; combined fixup for "negative" w, a[]
44 tstl r5
45 bgeq 20$
46 addl2 (r3),r1
4720$:
48 tstl (r3)
49 bgeq 30$
50 addl2 r5,r1
5130$:
52
53 movl r0,(r2)+ ; store lo result in r[] & advance
54 addl #4,r3 ; advance a[]
55 movl r1,r6 ; store hi result => c
56
57 sobgtr r4,0$
58
59 movl r6,r0 ; return c
60 ret
61
62 .title vax_bn_mul_word unsigned multiply & add, 32*32+32=>64
63;
64; w.j.m. 15-jan-1999
65;
66; it's magic ...
67;
68; ULONG bn_mul_words(ULONG r[],ULONG a[],int n,ULONG w) {
69; ULONG c = 0;
70; int i;
71; for(i = 0; i < num; i++) <c,r[i]> := a[i] * w + c ;
72; return(c);
73; }
74
75r=4 ;(AP)
76a=8 ;(AP)
77n=12 ;(AP) n by value (input)
78w=16 ;(AP) w by value (input)
79
80
81 .psect code,nowrt
82
83.entry bn_mul_words,^m<r2,r3,r4,r5,r6>
84
85 moval @r(ap),r2 ; r2 -> r[]
86 moval @a(ap),r3 ; r3 -> a[]
87 movl n(ap),r4 ; r4 = loop count (assumed >0 by C code)
88 movl w(ap),r5 ; r5 = w
89 clrl r6 ; r6 = c
90
910$:
92 ; <r1,r0> := w * a[] + c
93 emul r5,(r3),r6,r0 ; w, a[], c considered signed
94
95 ; fixup for "negative" c
96 tstl r6 ; c
97 bgeq 10$
98 incl r1
9910$:
100
101 ; combined fixup for "negative" w, a[]
102 tstl r5 ; w
103 bgeq 20$
104 addl2 (r3),r1 ; a[]
10520$:
106 tstl (r3) ; a[]
107 bgeq 30$
108 addl2 r5,r1 ; w
10930$:
110
111 movl r0,(r2)+ ; store lo result in r[] & advance
112 addl #4,r3 ; advance a[]
113 movl r1,r6 ; store hi result => c
114
115 sobgtr r4,0$
116
117 movl r6,r0 ; return c
118 ret
119
120 .title vax_bn_sqr_words unsigned square, 32*32=>64
121;
122; w.j.m. 15-jan-1999
123;
124; it's magic ...
125;
126; void bn_sqr_words(ULONG r[],ULONG a[],int n) {
127; int i;
128; for(i = 0; i < n; i++) <r[2*i+1],r[2*i]> := a[i] * a[i] ;
129; }
130
131r=4 ;(AP)
132a=8 ;(AP)
133n=12 ;(AP) n by value (input)
134
135
136 .psect code,nowrt
137
138.entry bn_sqr_words,^m<r2,r3,r4,r5>
139
140 moval @r(ap),r2 ; r2 -> r[]
141 moval @a(ap),r3 ; r3 -> a[]
142 movl n(ap),r4 ; r4 = n (assumed >0 by C code)
143
1440$:
145 movl (r3)+,r5 ; r5 = a[] & advance
146
147 ; <r1,r0> := a[] * a[]
148 emul r5,r5,#0,r0 ; a[] considered signed
149
150 ; fixup for "negative" a[]
151 tstl r5 ; a[]
152 bgeq 30$
153 addl2 r5,r1 ; a[]
154 addl2 r5,r1 ; a[]
15530$:
156
157 movl r0,(r2)+ ; store lo result in r[] & advance
158 movl r1,(r2)+ ; store hi result in r[] & advance
159
160 sobgtr r4,0$
161
162 movl #1,r0 ; return SS$_NORMAL
163 ret
164
165 .title (generated)
166
167 .psect code,nowrt
168
169.entry BN_DIV_WORDS,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
170 subl2 #4,sp
171
172 clrl r9
173 movl #2,r8
174
175 tstl 12(ap)
176 bneq noname.2
177 mnegl #1,r10
178 brw noname.3
179 tstl r0
180 nop
181noname.2:
182
183 pushl 12(ap)
184 calls #1,BN_NUM_BITS_WORD
185 movl r0,r7
186
187 cmpl r7,#32
188 beql noname.4
189 ashl r7,#1,r2
190 cmpl 4(ap),r2
191 blequ noname.4
192
193 pushl r7
194 calls #1,BN_DIV_WORDS_ABORT
195noname.4:
196
197 subl3 r7,#32,r7
198
199 movl 12(ap),r2
200 cmpl 4(ap),r2
201 blssu noname.5
202 subl2 r2,4(ap)
203noname.5:
204
205 tstl r7
206 beql noname.6
207
208 ashl r7,r2,12(ap)
209
210 ashl r7,4(ap),r4
211 subl3 r7,#32,r3
212 subl3 r3,#32,r2
213 extzv r3,r2,8(ap),r2
214 bisl3 r4,r2,4(ap)
215
216 ashl r7,8(ap),8(ap)
217noname.6:
218
219 bicl3 #65535,12(ap),r2
220 extzv #16,#16,r2,r5
221
222 bicl3 #-65536,12(ap),r6
223
224noname.7:
225
226 moval 4(ap),r2
227 movzwl 2(r2),r0
228 cmpl r0,r5
229 bneq noname.8
230
231 movzwl #65535,r4
232 brb noname.9
233noname.8:
234
235 clrl r1
236 movl (r2),r0
237 movl r5,r2
238 bgeq vcg.1
239 cmpl r2,r0
240 bgtru vcg.2
241 incl r1
242 brb vcg.2
243 nop
244vcg.1:
245 ediv r2,r0,r1,r0
246vcg.2:
247 movl r1,r4
248noname.9:
249
250noname.10:
251
252 mull3 r5,r4,r0
253 subl3 r0,4(ap),r3
254
255 bicl3 #65535,r3,r0
256 bneq noname.13
257 mull3 r6,r4,r2
258 ashl #16,r3,r1
259 bicl3 #65535,8(ap),r0
260 extzv #16,#16,r0,r0
261 addl2 r0,r1
262 cmpl r2,r1
263 bgtru noname.12
264noname.11:
265
266 brb noname.13
267 nop
268noname.12:
269
270 decl r4
271 brb noname.10
272noname.13:
273
274 mull3 r5,r4,r1
275
276 mull3 r6,r4,r0
277
278 extzv #16,#16,r0,r3
279
280 ashl #16,r0,r2
281 bicl3 #65535,r2,r0
282
283 addl2 r3,r1
284
285 moval 8(ap),r3
286 cmpl (r3),r0
287 bgequ noname.15
288 incl r1
289noname.15:
290
291 subl2 r0,(r3)
292
293 cmpl 4(ap),r1
294 bgequ noname.16
295
296 addl2 12(ap),4(ap)
297
298 decl r4
299noname.16:
300
301 subl2 r1,4(ap)
302
303 decl r8
304 beql noname.18
305noname.17:
306
307 ashl #16,r4,r9
308
309 ashl #16,4(ap),r2
310 movzwl 2(r3),r0
311 bisl2 r0,r2
312 bicl3 #0,r2,4(ap)
313
314 bicl3 #-65536,(r3),r0
315 ashl #16,r0,(r3)
316 brw noname.7
317 nop
318noname.18:
319
320 bisl2 r4,r9
321
322 movl r9,r10
323
324noname.3:
325 movl r10,r0
326 ret
327 tstl r0
328
329
330 .psect code,nowrt
331
332.entry BN_ADD_WORDS,^m<r2,r3,r4,r5,r6,r7>
333
334 tstl 16(ap)
335 bgtr noname.21
336 clrl r7
337 brw noname.22
338noname.21:
339
340 clrl r4
341
342 tstl r0
343noname.23:
344
345 movl 8(ap),r6
346 addl3 r4,(r6),r2
347
348 bicl2 #0,r2
349
350 clrl r0
351 cmpl r2,r4
352 bgequ vcg.3
353 incl r0
354vcg.3:
355 movl r0,r4
356
357 movl 12(ap),r5
358 addl3 (r5),r2,r1
359 bicl2 #0,r1
360
361 clrl r0
362 cmpl r1,r2
363 bgequ vcg.4
364 incl r0
365vcg.4:
366 addl2 r0,r4
367
368 movl 4(ap),r3
369 movl r1,(r3)
370
371 decl 16(ap)
372 bgtr gen.1
373 brw noname.25
374gen.1:
375noname.24:
376
377 addl3 r4,4(r6),r2
378
379 bicl2 #0,r2
380
381 clrl r0
382 cmpl r2,r4
383 bgequ vcg.5
384 incl r0
385vcg.5:
386 movl r0,r4
387
388 addl3 4(r5),r2,r1
389 bicl2 #0,r1
390
391 clrl r0
392 cmpl r1,r2
393 bgequ vcg.6
394 incl r0
395vcg.6:
396 addl2 r0,r4
397
398 movl r1,4(r3)
399
400 decl 16(ap)
401 bleq noname.25
402noname.26:
403
404 addl3 r4,8(r6),r2
405
406 bicl2 #0,r2
407
408 clrl r0
409 cmpl r2,r4
410 bgequ vcg.7
411 incl r0
412vcg.7:
413 movl r0,r4
414
415 addl3 8(r5),r2,r1
416 bicl2 #0,r1
417
418 clrl r0
419 cmpl r1,r2
420 bgequ vcg.8
421 incl r0
422vcg.8:
423 addl2 r0,r4
424
425 movl r1,8(r3)
426
427 decl 16(ap)
428 bleq noname.25
429noname.27:
430
431 addl3 r4,12(r6),r2
432
433 bicl2 #0,r2
434
435 clrl r0
436 cmpl r2,r4
437 bgequ vcg.9
438 incl r0
439vcg.9:
440 movl r0,r4
441
442 addl3 12(r5),r2,r1
443 bicl2 #0,r1
444
445 clrl r0
446 cmpl r1,r2
447 bgequ vcg.10
448 incl r0
449vcg.10:
450 addl2 r0,r4
451
452 movl r1,12(r3)
453
454 decl 16(ap)
455 bleq noname.25
456noname.28:
457
458 addl3 #16,r6,8(ap)
459
460 addl3 #16,r5,12(ap)
461
462 addl3 #16,r3,4(ap)
463 brw noname.23
464 tstl r0
465noname.25:
466
467 movl r4,r7
468
469noname.22:
470 movl r7,r0
471 ret
472 nop
473
474
475
476;r=4 ;(AP)
477;a=8 ;(AP)
478;b=12 ;(AP)
479;n=16 ;(AP) n by value (input)
480
481 .psect code,nowrt
482
483.entry BN_SUB_WORDS,^m<r2,r3,r4,r5,r6,r7>
484
485 clrl r6
486
487 tstl 16(ap)
488 bgtr noname.31
489 clrl r7
490 brw noname.32
491 tstl r0
492noname.31:
493
494noname.33:
495
496 movl 8(ap),r5
497 movl (r5),r1
498 movl 12(ap),r4
499 movl (r4),r2
500
501 movl 4(ap),r3
502 subl3 r2,r1,r0
503 subl2 r6,r0
504 bicl3 #0,r0,(r3)
505
506 cmpl r1,r2
507 beql noname.34
508 clrl r0
509 cmpl r1,r2
510 bgequ vcg.11
511 incl r0
512vcg.11:
513 movl r0,r6
514noname.34:
515
516 decl 16(ap)
517 bgtr gen.2
518 brw noname.36
519gen.2:
520noname.35:
521
522 movl 4(r5),r2
523 movl 4(r4),r1
524
525 subl3 r1,r2,r0
526 subl2 r6,r0
527 bicl3 #0,r0,4(r3)
528
529 cmpl r2,r1
530 beql noname.37
531 clrl r0
532 cmpl r2,r1
533 bgequ vcg.12
534 incl r0
535vcg.12:
536 movl r0,r6
537noname.37:
538
539 decl 16(ap)
540 bleq noname.36
541noname.38:
542
543 movl 8(r5),r1
544 movl 8(r4),r2
545
546 subl3 r2,r1,r0
547 subl2 r6,r0
548 bicl3 #0,r0,8(r3)
549
550 cmpl r1,r2
551 beql noname.39
552 clrl r0
553 cmpl r1,r2
554 bgequ vcg.13
555 incl r0
556vcg.13:
557 movl r0,r6
558noname.39:
559
560 decl 16(ap)
561 bleq noname.36
562noname.40:
563
564 movl 12(r5),r1
565 movl 12(r4),r2
566
567 subl3 r2,r1,r0
568 subl2 r6,r0
569 bicl3 #0,r0,12(r3)
570
571 cmpl r1,r2
572 beql noname.41
573 clrl r0
574 cmpl r1,r2
575 bgequ vcg.14
576 incl r0
577vcg.14:
578 movl r0,r6
579noname.41:
580
581 decl 16(ap)
582 bleq noname.36
583noname.42:
584
585 addl3 #16,r5,8(ap)
586
587 addl3 #16,r4,12(ap)
588
589 addl3 #16,r3,4(ap)
590 brw noname.33
591 tstl r0
592noname.36:
593
594 movl r6,r7
595
596noname.32:
597 movl r7,r0
598 ret
599 nop
600
601
602
603;r=4 ;(AP)
604;a=8 ;(AP)
605;b=12 ;(AP)
606;n=16 ;(AP) n by value (input)
607
608 .psect code,nowrt
609
610.entry BN_MUL_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
611 movab -924(sp),sp
612 clrq r8
613
614 clrl r10
615
616 movl 8(ap),r6
617 movzwl 2(r6),r3
618 movl 12(ap),r7
619 bicl3 #-65536,(r7),r2
620 movzwl 2(r7),r0
621 bicl2 #-65536,r0
622 bicl3 #-65536,(r6),-12(fp)
623 bicl3 #-65536,r3,-16(fp)
624 mull3 r0,-12(fp),-4(fp)
625 mull2 r2,-12(fp)
626 mull3 r2,-16(fp),-8(fp)
627 mull2 r0,-16(fp)
628 addl3 -4(fp),-8(fp),r0
629 bicl3 #0,r0,-4(fp)
630 cmpl -4(fp),-8(fp)
631 bgequ noname.45
632 addl2 #65536,-16(fp)
633noname.45:
634 movzwl -2(fp),r0
635 bicl2 #-65536,r0
636 addl2 r0,-16(fp)
637 bicl3 #-65536,-4(fp),r0
638 ashl #16,r0,-8(fp)
639 addl3 -8(fp),-12(fp),r0
640 bicl3 #0,r0,-12(fp)
641 cmpl -12(fp),-8(fp)
642 bgequ noname.46
643 incl -16(fp)
644noname.46:
645 movl -12(fp),r1
646 movl -16(fp),r2
647 addl2 r1,r9
648 bicl2 #0,r9
649 cmpl r9,r1
650 bgequ noname.47
651 incl r2
652noname.47:
653 addl2 r2,r8
654 bicl2 #0,r8
655 cmpl r8,r2
656 bgequ noname.48
657 incl r10
658noname.48:
659
660 movl 4(ap),r11
661 movl r9,(r11)
662
663 clrl r9
664
665 movzwl 2(r6),r2
666 bicl3 #-65536,4(r7),r3
667 movzwl 6(r7),r0
668 bicl2 #-65536,r0
669 bicl3 #-65536,(r6),-28(fp)
670 bicl3 #-65536,r2,-32(fp)
671 mull3 r0,-28(fp),-20(fp)
672 mull2 r3,-28(fp)
673 mull3 r3,-32(fp),-24(fp)
674 mull2 r0,-32(fp)
675 addl3 -20(fp),-24(fp),r0
676 bicl3 #0,r0,-20(fp)
677 cmpl -20(fp),-24(fp)
678 bgequ noname.49
679 addl2 #65536,-32(fp)
680noname.49:
681 movzwl -18(fp),r0
682 bicl2 #-65536,r0
683 addl2 r0,-32(fp)
684 bicl3 #-65536,-20(fp),r0
685 ashl #16,r0,-24(fp)
686 addl3 -24(fp),-28(fp),r0
687 bicl3 #0,r0,-28(fp)
688 cmpl -28(fp),-24(fp)
689 bgequ noname.50
690 incl -32(fp)
691noname.50:
692 movl -28(fp),r1
693 movl -32(fp),r2
694 addl2 r1,r8
695 bicl2 #0,r8
696 cmpl r8,r1
697 bgequ noname.51
698 incl r2
699noname.51:
700 addl2 r2,r10
701 bicl2 #0,r10
702 cmpl r10,r2
703 bgequ noname.52
704 incl r9
705noname.52:
706
707 movzwl 6(r6),r2
708 bicl3 #-65536,(r7),r3
709 movzwl 2(r7),r0
710 bicl2 #-65536,r0
711 bicl3 #-65536,4(r6),-44(fp)
712 bicl3 #-65536,r2,-48(fp)
713 mull3 r0,-44(fp),-36(fp)
714 mull2 r3,-44(fp)
715 mull3 r3,-48(fp),-40(fp)
716 mull2 r0,-48(fp)
717 addl3 -36(fp),-40(fp),r0
718 bicl3 #0,r0,-36(fp)
719 cmpl -36(fp),-40(fp)
720 bgequ noname.53
721 addl2 #65536,-48(fp)
722noname.53:
723 movzwl -34(fp),r0
724 bicl2 #-65536,r0
725 addl2 r0,-48(fp)
726 bicl3 #-65536,-36(fp),r0
727 ashl #16,r0,-40(fp)
728 addl3 -40(fp),-44(fp),r0
729 bicl3 #0,r0,-44(fp)
730 cmpl -44(fp),-40(fp)
731 bgequ noname.54
732 incl -48(fp)
733noname.54:
734 movl -44(fp),r1
735 movl -48(fp),r2
736 addl2 r1,r8
737 bicl2 #0,r8
738 cmpl r8,r1
739 bgequ noname.55
740 incl r2
741noname.55:
742 addl2 r2,r10
743 bicl2 #0,r10
744 cmpl r10,r2
745 bgequ noname.56
746 incl r9
747noname.56:
748
749 movl r8,4(r11)
750
751 clrl r8
752
753 movzwl 10(r6),r2
754 bicl3 #-65536,(r7),r3
755 movzwl 2(r7),r0
756 bicl2 #-65536,r0
757 bicl3 #-65536,8(r6),-60(fp)
758 bicl3 #-65536,r2,-64(fp)
759 mull3 r0,-60(fp),-52(fp)
760 mull2 r3,-60(fp)
761 mull3 r3,-64(fp),-56(fp)
762 mull2 r0,-64(fp)
763 addl3 -52(fp),-56(fp),r0
764 bicl3 #0,r0,-52(fp)
765 cmpl -52(fp),-56(fp)
766 bgequ noname.57
767 addl2 #65536,-64(fp)
768noname.57:
769 movzwl -50(fp),r0
770 bicl2 #-65536,r0
771 addl2 r0,-64(fp)
772 bicl3 #-65536,-52(fp),r0
773 ashl #16,r0,-56(fp)
774 addl3 -56(fp),-60(fp),r0
775 bicl3 #0,r0,-60(fp)
776 cmpl -60(fp),-56(fp)
777 bgequ noname.58
778 incl -64(fp)
779noname.58:
780 movl -60(fp),r1
781 movl -64(fp),r2
782 addl2 r1,r10
783 bicl2 #0,r10
784 cmpl r10,r1
785 bgequ noname.59
786 incl r2
787noname.59:
788 addl2 r2,r9
789 bicl2 #0,r9
790 cmpl r9,r2
791 bgequ noname.60
792 incl r8
793noname.60:
794
795 movzwl 6(r6),r2
796 bicl3 #-65536,4(r7),r3
797 movzwl 6(r7),r0
798 bicl2 #-65536,r0
799 bicl3 #-65536,4(r6),-76(fp)
800 bicl3 #-65536,r2,-80(fp)
801 mull3 r0,-76(fp),-68(fp)
802 mull2 r3,-76(fp)
803 mull3 r3,-80(fp),-72(fp)
804 mull2 r0,-80(fp)
805 addl3 -68(fp),-72(fp),r0
806 bicl3 #0,r0,-68(fp)
807 cmpl -68(fp),-72(fp)
808 bgequ noname.61
809 addl2 #65536,-80(fp)
810noname.61:
811 movzwl -66(fp),r0
812 bicl2 #-65536,r0
813 addl2 r0,-80(fp)
814 bicl3 #-65536,-68(fp),r0
815 ashl #16,r0,-72(fp)
816 addl3 -72(fp),-76(fp),r0
817 bicl3 #0,r0,-76(fp)
818 cmpl -76(fp),-72(fp)
819 bgequ noname.62
820 incl -80(fp)
821noname.62:
822 movl -76(fp),r1
823 movl -80(fp),r2
824 addl2 r1,r10
825 bicl2 #0,r10
826 cmpl r10,r1
827 bgequ noname.63
828 incl r2
829noname.63:
830 addl2 r2,r9
831 bicl2 #0,r9
832 cmpl r9,r2
833 bgequ noname.64
834 incl r8
835noname.64:
836
837 movzwl 2(r6),r2
838 bicl3 #-65536,8(r7),r3
839 movzwl 10(r7),r0
840 bicl2 #-65536,r0
841 bicl3 #-65536,(r6),-92(fp)
842 bicl3 #-65536,r2,-96(fp)
843 mull3 r0,-92(fp),-84(fp)
844 mull2 r3,-92(fp)
845 mull3 r3,-96(fp),-88(fp)
846 mull2 r0,-96(fp)
847 addl3 -84(fp),-88(fp),r0
848 bicl3 #0,r0,-84(fp)
849 cmpl -84(fp),-88(fp)
850 bgequ noname.65
851 addl2 #65536,-96(fp)
852noname.65:
853 movzwl -82(fp),r0
854 bicl2 #-65536,r0
855 addl2 r0,-96(fp)
856 bicl3 #-65536,-84(fp),r0
857 ashl #16,r0,-88(fp)
858 addl3 -88(fp),-92(fp),r0
859 bicl3 #0,r0,-92(fp)
860 cmpl -92(fp),-88(fp)
861 bgequ noname.66
862 incl -96(fp)
863noname.66:
864 movl -92(fp),r1
865 movl -96(fp),r2
866 addl2 r1,r10
867 bicl2 #0,r10
868 cmpl r10,r1
869 bgequ noname.67
870 incl r2
871noname.67:
872 addl2 r2,r9
873 bicl2 #0,r9
874 cmpl r9,r2
875 bgequ noname.68
876 incl r8
877noname.68:
878
879 movl r10,8(r11)
880
881 clrl r10
882
883 movzwl 2(r6),r2
884 bicl3 #-65536,12(r7),r3
885 movzwl 14(r7),r0
886 bicl2 #-65536,r0
887 bicl3 #-65536,(r6),-108(fp)
888 bicl3 #-65536,r2,-112(fp)
889 mull3 r0,-108(fp),-100(fp)
890 mull2 r3,-108(fp)
891 mull3 r3,-112(fp),-104(fp)
892 mull2 r0,-112(fp)
893 addl3 -100(fp),-104(fp),r0
894 bicl3 #0,r0,-100(fp)
895 cmpl -100(fp),-104(fp)
896 bgequ noname.69
897 addl2 #65536,-112(fp)
898noname.69:
899 movzwl -98(fp),r0
900 bicl2 #-65536,r0
901 addl2 r0,-112(fp)
902 bicl3 #-65536,-100(fp),r0
903 ashl #16,r0,-104(fp)
904 addl3 -104(fp),-108(fp),r0
905 bicl3 #0,r0,-108(fp)
906 cmpl -108(fp),-104(fp)
907 bgequ noname.70
908 incl -112(fp)
909noname.70:
910 movl -108(fp),r1
911 movl -112(fp),r2
912 addl2 r1,r9
913 bicl2 #0,r9
914 cmpl r9,r1
915 bgequ noname.71
916 incl r2
917noname.71:
918 addl2 r2,r8
919 bicl2 #0,r8
920 cmpl r8,r2
921 bgequ noname.72
922 incl r10
923noname.72:
924
925 movzwl 6(r6),r2
926 bicl3 #-65536,8(r7),r3
927 movzwl 10(r7),r0
928 bicl2 #-65536,r0
929 bicl3 #-65536,4(r6),-124(fp)
930 bicl3 #-65536,r2,-128(fp)
931 mull3 r0,-124(fp),-116(fp)
932 mull2 r3,-124(fp)
933 mull3 r3,-128(fp),-120(fp)
934 mull2 r0,-128(fp)
935 addl3 -116(fp),-120(fp),r0
936 bicl3 #0,r0,-116(fp)
937 cmpl -116(fp),-120(fp)
938 bgequ noname.73
939 addl2 #65536,-128(fp)
940noname.73:
941 movzwl -114(fp),r0
942 bicl2 #-65536,r0
943 addl2 r0,-128(fp)
944 bicl3 #-65536,-116(fp),r0
945 ashl #16,r0,-120(fp)
946 addl3 -120(fp),-124(fp),r0
947 bicl3 #0,r0,-124(fp)
948 cmpl -124(fp),-120(fp)
949 bgequ noname.74
950 incl -128(fp)
951noname.74:
952 movl -124(fp),r1
953 movl -128(fp),r2
954 addl2 r1,r9
955 bicl2 #0,r9
956 cmpl r9,r1
957 bgequ noname.75
958 incl r2
959noname.75:
960 addl2 r2,r8
961 bicl2 #0,r8
962 cmpl r8,r2
963 bgequ noname.76
964 incl r10
965noname.76:
966
967 movzwl 10(r6),r2
968 bicl3 #-65536,4(r7),r3
969 movzwl 6(r7),r0
970 bicl2 #-65536,r0
971 bicl3 #-65536,8(r6),-140(fp)
972 bicl3 #-65536,r2,-144(fp)
973 mull3 r0,-140(fp),-132(fp)
974 mull2 r3,-140(fp)
975 mull3 r3,-144(fp),-136(fp)
976 mull2 r0,-144(fp)
977 addl3 -132(fp),-136(fp),r0
978 bicl3 #0,r0,-132(fp)
979 cmpl -132(fp),-136(fp)
980 bgequ noname.77
981 addl2 #65536,-144(fp)
982noname.77:
983 movzwl -130(fp),r0
984 bicl2 #-65536,r0
985 addl2 r0,-144(fp)
986 bicl3 #-65536,-132(fp),r0
987 ashl #16,r0,-136(fp)
988 addl3 -136(fp),-140(fp),r0
989 bicl3 #0,r0,-140(fp)
990 cmpl -140(fp),-136(fp)
991 bgequ noname.78
992 incl -144(fp)
993noname.78:
994 movl -140(fp),r1
995 movl -144(fp),r2
996 addl2 r1,r9
997 bicl2 #0,r9
998 cmpl r9,r1
999 bgequ noname.79
1000 incl r2
1001noname.79:
1002 addl2 r2,r8
1003 bicl2 #0,r8
1004 cmpl r8,r2
1005 bgequ noname.80
1006 incl r10
1007noname.80:
1008
1009 movzwl 14(r6),r2
1010 bicl3 #-65536,(r7),r3
1011 movzwl 2(r7),r0
1012 bicl2 #-65536,r0
1013 bicl3 #-65536,12(r6),-156(fp)
1014 bicl3 #-65536,r2,-160(fp)
1015 mull3 r0,-156(fp),-148(fp)
1016 mull2 r3,-156(fp)
1017 mull3 r3,-160(fp),-152(fp)
1018 mull2 r0,-160(fp)
1019 addl3 -148(fp),-152(fp),r0
1020 bicl3 #0,r0,-148(fp)
1021 cmpl -148(fp),-152(fp)
1022 bgequ noname.81
1023 addl2 #65536,-160(fp)
1024noname.81:
1025 movzwl -146(fp),r0
1026 bicl2 #-65536,r0
1027 addl2 r0,-160(fp)
1028 bicl3 #-65536,-148(fp),r0
1029 ashl #16,r0,-152(fp)
1030 addl3 -152(fp),-156(fp),r0
1031 bicl3 #0,r0,-156(fp)
1032 cmpl -156(fp),-152(fp)
1033 bgequ noname.82
1034 incl -160(fp)
1035noname.82:
1036 movl -156(fp),r1
1037 movl -160(fp),r2
1038 addl2 r1,r9
1039 bicl2 #0,r9
1040 cmpl r9,r1
1041 bgequ noname.83
1042 incl r2
1043noname.83:
1044 addl2 r2,r8
1045 bicl2 #0,r8
1046 cmpl r8,r2
1047 bgequ noname.84
1048 incl r10
1049noname.84:
1050
1051 movl r9,12(r11)
1052
1053 clrl r9
1054
1055 movzwl 18(r6),r2
1056 bicl3 #-65536,(r7),r3
1057 movzwl 2(r7),r0
1058 bicl2 #-65536,r0
1059 bicl3 #-65536,16(r6),-172(fp)
1060 bicl3 #-65536,r2,-176(fp)
1061 mull3 r0,-172(fp),-164(fp)
1062 mull2 r3,-172(fp)
1063 mull3 r3,-176(fp),-168(fp)
1064 mull2 r0,-176(fp)
1065 addl3 -164(fp),-168(fp),r0
1066 bicl3 #0,r0,-164(fp)
1067 cmpl -164(fp),-168(fp)
1068 bgequ noname.85
1069 addl2 #65536,-176(fp)
1070noname.85:
1071 movzwl -162(fp),r0
1072 bicl2 #-65536,r0
1073 addl2 r0,-176(fp)
1074 bicl3 #-65536,-164(fp),r0
1075 ashl #16,r0,-168(fp)
1076 addl3 -168(fp),-172(fp),r0
1077 bicl3 #0,r0,-172(fp)
1078 cmpl -172(fp),-168(fp)
1079 bgequ noname.86
1080 incl -176(fp)
1081noname.86:
1082 movl -172(fp),r1
1083 movl -176(fp),r2
1084 addl2 r1,r8
1085 bicl2 #0,r8
1086 cmpl r8,r1
1087 bgequ noname.87
1088 incl r2
1089noname.87:
1090 addl2 r2,r10
1091 bicl2 #0,r10
1092 cmpl r10,r2
1093 bgequ noname.88
1094 incl r9
1095noname.88:
1096
1097 movzwl 14(r6),r2
1098 bicl3 #-65536,4(r7),r3
1099 movzwl 6(r7),r0
1100 bicl2 #-65536,r0
1101 bicl3 #-65536,12(r6),-188(fp)
1102 bicl3 #-65536,r2,-192(fp)
1103 mull3 r0,-188(fp),-180(fp)
1104 mull2 r3,-188(fp)
1105 mull3 r3,-192(fp),-184(fp)
1106 mull2 r0,-192(fp)
1107 addl3 -180(fp),-184(fp),r0
1108 bicl3 #0,r0,-180(fp)
1109 cmpl -180(fp),-184(fp)
1110 bgequ noname.89
1111 addl2 #65536,-192(fp)
1112noname.89:
1113 movzwl -178(fp),r0
1114 bicl2 #-65536,r0
1115 addl2 r0,-192(fp)
1116 bicl3 #-65536,-180(fp),r0
1117 ashl #16,r0,-184(fp)
1118 addl3 -184(fp),-188(fp),r0
1119 bicl3 #0,r0,-188(fp)
1120 cmpl -188(fp),-184(fp)
1121 bgequ noname.90
1122 incl -192(fp)
1123noname.90:
1124 movl -188(fp),r1
1125 movl -192(fp),r2
1126 addl2 r1,r8
1127 bicl2 #0,r8
1128 cmpl r8,r1
1129 bgequ noname.91
1130 incl r2
1131noname.91:
1132 addl2 r2,r10
1133 bicl2 #0,r10
1134 cmpl r10,r2
1135 bgequ noname.92
1136 incl r9
1137noname.92:
1138
1139 movzwl 10(r6),r2
1140 bicl3 #-65536,8(r7),r3
1141 movzwl 10(r7),r0
1142 bicl2 #-65536,r0
1143 bicl3 #-65536,8(r6),-204(fp)
1144 bicl3 #-65536,r2,-208(fp)
1145 mull3 r0,-204(fp),-196(fp)
1146 mull2 r3,-204(fp)
1147 mull3 r3,-208(fp),-200(fp)
1148 mull2 r0,-208(fp)
1149 addl3 -196(fp),-200(fp),r0
1150 bicl3 #0,r0,-196(fp)
1151 cmpl -196(fp),-200(fp)
1152 bgequ noname.93
1153 addl2 #65536,-208(fp)
1154noname.93:
1155 movzwl -194(fp),r0
1156 bicl2 #-65536,r0
1157 addl2 r0,-208(fp)
1158 bicl3 #-65536,-196(fp),r0
1159 ashl #16,r0,-200(fp)
1160 addl3 -200(fp),-204(fp),r0
1161 bicl3 #0,r0,-204(fp)
1162 cmpl -204(fp),-200(fp)
1163 bgequ noname.94
1164 incl -208(fp)
1165noname.94:
1166 movl -204(fp),r1
1167 movl -208(fp),r2
1168 addl2 r1,r8
1169 bicl2 #0,r8
1170 cmpl r8,r1
1171 bgequ noname.95
1172 incl r2
1173noname.95:
1174 addl2 r2,r10
1175 bicl2 #0,r10
1176 cmpl r10,r2
1177 bgequ noname.96
1178 incl r9
1179noname.96:
1180
1181 movzwl 6(r6),r2
1182 bicl3 #-65536,12(r7),r3
1183 movzwl 14(r7),r0
1184 bicl2 #-65536,r0
1185 bicl3 #-65536,4(r6),-220(fp)
1186 bicl3 #-65536,r2,-224(fp)
1187 mull3 r0,-220(fp),-212(fp)
1188 mull2 r3,-220(fp)
1189 mull3 r3,-224(fp),-216(fp)
1190 mull2 r0,-224(fp)
1191 addl3 -212(fp),-216(fp),r0
1192 bicl3 #0,r0,-212(fp)
1193 cmpl -212(fp),-216(fp)
1194 bgequ noname.97
1195 addl2 #65536,-224(fp)
1196noname.97:
1197 movzwl -210(fp),r0
1198 bicl2 #-65536,r0
1199 addl2 r0,-224(fp)
1200 bicl3 #-65536,-212(fp),r0
1201 ashl #16,r0,-216(fp)
1202 addl3 -216(fp),-220(fp),r0
1203 bicl3 #0,r0,-220(fp)
1204 cmpl -220(fp),-216(fp)
1205 bgequ noname.98
1206 incl -224(fp)
1207noname.98:
1208 movl -220(fp),r1
1209 movl -224(fp),r2
1210 addl2 r1,r8
1211 bicl2 #0,r8
1212 cmpl r8,r1
1213 bgequ noname.99
1214 incl r2
1215noname.99:
1216 addl2 r2,r10
1217 bicl2 #0,r10
1218 cmpl r10,r2
1219 bgequ noname.100
1220 incl r9
1221noname.100:
1222
1223 movzwl 2(r6),r2
1224 bicl3 #-65536,16(r7),r3
1225 movzwl 18(r7),r0
1226 bicl2 #-65536,r0
1227 bicl3 #-65536,(r6),-236(fp)
1228 bicl3 #-65536,r2,-240(fp)
1229 mull3 r0,-236(fp),-228(fp)
1230 mull2 r3,-236(fp)
1231 mull3 r3,-240(fp),-232(fp)
1232 mull2 r0,-240(fp)
1233 addl3 -228(fp),-232(fp),r0
1234 bicl3 #0,r0,-228(fp)
1235 cmpl -228(fp),-232(fp)
1236 bgequ noname.101
1237 addl2 #65536,-240(fp)
1238noname.101:
1239 movzwl -226(fp),r0
1240 bicl2 #-65536,r0
1241 addl2 r0,-240(fp)
1242 bicl3 #-65536,-228(fp),r0
1243 ashl #16,r0,-232(fp)
1244 addl3 -232(fp),-236(fp),r0
1245 bicl3 #0,r0,-236(fp)
1246 cmpl -236(fp),-232(fp)
1247 bgequ noname.102
1248 incl -240(fp)
1249noname.102:
1250 movl -236(fp),r1
1251 movl -240(fp),r2
1252 addl2 r1,r8
1253 bicl2 #0,r8
1254 cmpl r8,r1
1255 bgequ noname.103
1256 incl r2
1257noname.103:
1258 addl2 r2,r10
1259 bicl2 #0,r10
1260 cmpl r10,r2
1261 bgequ noname.104
1262 incl r9
1263noname.104:
1264
1265 movl r8,16(r11)
1266
1267 clrl r8
1268
1269 movzwl 2(r6),r2
1270 bicl3 #-65536,20(r7),r3
1271 movzwl 22(r7),r0
1272 bicl2 #-65536,r0
1273 bicl3 #-65536,(r6),-252(fp)
1274 bicl3 #-65536,r2,-256(fp)
1275 mull3 r0,-252(fp),-244(fp)
1276 mull2 r3,-252(fp)
1277 mull3 r3,-256(fp),-248(fp)
1278 mull2 r0,-256(fp)
1279 addl3 -244(fp),-248(fp),r0
1280 bicl3 #0,r0,-244(fp)
1281 cmpl -244(fp),-248(fp)
1282 bgequ noname.105
1283 addl2 #65536,-256(fp)
1284noname.105:
1285 movzwl -242(fp),r0
1286 bicl2 #-65536,r0
1287 addl2 r0,-256(fp)
1288 bicl3 #-65536,-244(fp),r0
1289 ashl #16,r0,-248(fp)
1290 addl3 -248(fp),-252(fp),r0
1291 bicl3 #0,r0,-252(fp)
1292 cmpl -252(fp),-248(fp)
1293 bgequ noname.106
1294 incl -256(fp)
1295noname.106:
1296 movl -252(fp),r1
1297 movl -256(fp),r2
1298 addl2 r1,r10
1299 bicl2 #0,r10
1300 cmpl r10,r1
1301 bgequ noname.107
1302 incl r2
1303noname.107:
1304 addl2 r2,r9
1305 bicl2 #0,r9
1306 cmpl r9,r2
1307 bgequ noname.108
1308 incl r8
1309noname.108:
1310
1311 movzwl 6(r6),r2
1312 bicl3 #-65536,16(r7),r3
1313 movzwl 18(r7),r0
1314 bicl2 #-65536,r0
1315 bicl3 #-65536,4(r6),-268(fp)
1316 bicl3 #-65536,r2,-272(fp)
1317 mull3 r0,-268(fp),-260(fp)
1318 mull2 r3,-268(fp)
1319 mull3 r3,-272(fp),-264(fp)
1320 mull2 r0,-272(fp)
1321 addl3 -260(fp),-264(fp),r0
1322 bicl3 #0,r0,-260(fp)
1323 cmpl -260(fp),-264(fp)
1324 bgequ noname.109
1325 addl2 #65536,-272(fp)
1326noname.109:
1327 movzwl -258(fp),r0
1328 bicl2 #-65536,r0
1329 addl2 r0,-272(fp)
1330 bicl3 #-65536,-260(fp),r0
1331 ashl #16,r0,-264(fp)
1332 addl3 -264(fp),-268(fp),r0
1333 bicl3 #0,r0,-268(fp)
1334 cmpl -268(fp),-264(fp)
1335 bgequ noname.110
1336 incl -272(fp)
1337noname.110:
1338 movl -268(fp),r1
1339 movl -272(fp),r2
1340 addl2 r1,r10
1341 bicl2 #0,r10
1342 cmpl r10,r1
1343 bgequ noname.111
1344 incl r2
1345noname.111:
1346 addl2 r2,r9
1347 bicl2 #0,r9
1348 cmpl r9,r2
1349 bgequ noname.112
1350 incl r8
1351noname.112:
1352
1353 movzwl 10(r6),r2
1354 bicl3 #-65536,12(r7),r3
1355 movzwl 14(r7),r0
1356 bicl2 #-65536,r0
1357 bicl3 #-65536,8(r6),-284(fp)
1358 bicl3 #-65536,r2,-288(fp)
1359 mull3 r0,-284(fp),-276(fp)
1360 mull2 r3,-284(fp)
1361 mull3 r3,-288(fp),-280(fp)
1362 mull2 r0,-288(fp)
1363 addl3 -276(fp),-280(fp),r0
1364 bicl3 #0,r0,-276(fp)
1365 cmpl -276(fp),-280(fp)
1366 bgequ noname.113
1367 addl2 #65536,-288(fp)
1368noname.113:
1369 movzwl -274(fp),r0
1370 bicl2 #-65536,r0
1371 addl2 r0,-288(fp)
1372 bicl3 #-65536,-276(fp),r0
1373 ashl #16,r0,-280(fp)
1374 addl3 -280(fp),-284(fp),r0
1375 bicl3 #0,r0,-284(fp)
1376 cmpl -284(fp),-280(fp)
1377 bgequ noname.114
1378 incl -288(fp)
1379noname.114:
1380 movl -284(fp),r1
1381 movl -288(fp),r2
1382 addl2 r1,r10
1383 bicl2 #0,r10
1384 cmpl r10,r1
1385 bgequ noname.115
1386 incl r2
1387noname.115:
1388 addl2 r2,r9
1389 bicl2 #0,r9
1390 cmpl r9,r2
1391 bgequ noname.116
1392 incl r8
1393noname.116:
1394
1395 movzwl 14(r6),r2
1396 bicl3 #-65536,8(r7),r3
1397 movzwl 10(r7),r0
1398 bicl2 #-65536,r0
1399 bicl3 #-65536,12(r6),-300(fp)
1400 bicl3 #-65536,r2,-304(fp)
1401 mull3 r0,-300(fp),-292(fp)
1402 mull2 r3,-300(fp)
1403 mull3 r3,-304(fp),-296(fp)
1404 mull2 r0,-304(fp)
1405 addl3 -292(fp),-296(fp),r0
1406 bicl3 #0,r0,-292(fp)
1407 cmpl -292(fp),-296(fp)
1408 bgequ noname.117
1409 addl2 #65536,-304(fp)
1410noname.117:
1411 movzwl -290(fp),r0
1412 bicl2 #-65536,r0
1413 addl2 r0,-304(fp)
1414 bicl3 #-65536,-292(fp),r0
1415 ashl #16,r0,-296(fp)
1416 addl3 -296(fp),-300(fp),r0
1417 bicl3 #0,r0,-300(fp)
1418 cmpl -300(fp),-296(fp)
1419 bgequ noname.118
1420 incl -304(fp)
1421noname.118:
1422 movl -300(fp),r1
1423 movl -304(fp),r2
1424 addl2 r1,r10
1425 bicl2 #0,r10
1426 cmpl r10,r1
1427 bgequ noname.119
1428 incl r2
1429noname.119:
1430 addl2 r2,r9
1431 bicl2 #0,r9
1432 cmpl r9,r2
1433 bgequ noname.120
1434 incl r8
1435noname.120:
1436
1437 movzwl 18(r6),r2
1438 bicl3 #-65536,4(r7),r3
1439 movzwl 6(r7),r0
1440 bicl2 #-65536,r0
1441 bicl3 #-65536,16(r6),-316(fp)
1442 bicl3 #-65536,r2,-320(fp)
1443 mull3 r0,-316(fp),-308(fp)
1444 mull2 r3,-316(fp)
1445 mull3 r3,-320(fp),-312(fp)
1446 mull2 r0,-320(fp)
1447 addl3 -308(fp),-312(fp),r0
1448 bicl3 #0,r0,-308(fp)
1449 cmpl -308(fp),-312(fp)
1450 bgequ noname.121
1451 addl2 #65536,-320(fp)
1452noname.121:
1453 movzwl -306(fp),r0
1454 bicl2 #-65536,r0
1455 addl2 r0,-320(fp)
1456 bicl3 #-65536,-308(fp),r0
1457 ashl #16,r0,-312(fp)
1458 addl3 -312(fp),-316(fp),r0
1459 bicl3 #0,r0,-316(fp)
1460 cmpl -316(fp),-312(fp)
1461 bgequ noname.122
1462 incl -320(fp)
1463noname.122:
1464 movl -316(fp),r1
1465 movl -320(fp),r2
1466 addl2 r1,r10
1467 bicl2 #0,r10
1468 cmpl r10,r1
1469 bgequ noname.123
1470 incl r2
1471
1472noname.123:
1473 addl2 r2,r9
1474 bicl2 #0,r9
1475 cmpl r9,r2
1476 bgequ noname.124
1477 incl r8
1478noname.124:
1479
1480 movzwl 22(r6),r2
1481 bicl3 #-65536,(r7),r3
1482 movzwl 2(r7),r0
1483 bicl2 #-65536,r0
1484 bicl3 #-65536,20(r6),-332(fp)
1485 bicl3 #-65536,r2,-336(fp)
1486 mull3 r0,-332(fp),-324(fp)
1487 mull2 r3,-332(fp)
1488 mull3 r3,-336(fp),-328(fp)
1489 mull2 r0,-336(fp)
1490 addl3 -324(fp),-328(fp),r0
1491 bicl3 #0,r0,-324(fp)
1492 cmpl -324(fp),-328(fp)
1493 bgequ noname.125
1494 addl2 #65536,-336(fp)
1495noname.125:
1496 movzwl -322(fp),r0
1497 bicl2 #-65536,r0
1498 addl2 r0,-336(fp)
1499 bicl3 #-65536,-324(fp),r0
1500 ashl #16,r0,-328(fp)
1501 addl3 -328(fp),-332(fp),r0
1502 bicl3 #0,r0,-332(fp)
1503 cmpl -332(fp),-328(fp)
1504 bgequ noname.126
1505 incl -336(fp)
1506noname.126:
1507 movl -332(fp),r1
1508 movl -336(fp),r2
1509 addl2 r1,r10
1510 bicl2 #0,r10
1511 cmpl r10,r1
1512 bgequ noname.127
1513 incl r2
1514noname.127:
1515 addl2 r2,r9
1516 bicl2 #0,r9
1517 cmpl r9,r2
1518 bgequ noname.128
1519 incl r8
1520noname.128:
1521
1522 movl r10,20(r11)
1523
1524 clrl r10
1525
1526 movzwl 26(r6),r2
1527 bicl3 #-65536,(r7),r3
1528 movzwl 2(r7),r0
1529 bicl2 #-65536,r0
1530 bicl3 #-65536,24(r6),-348(fp)
1531 bicl3 #-65536,r2,-352(fp)
1532 mull3 r0,-348(fp),-340(fp)
1533 mull2 r3,-348(fp)
1534 mull3 r3,-352(fp),-344(fp)
1535 mull2 r0,-352(fp)
1536 addl3 -340(fp),-344(fp),r0
1537 bicl3 #0,r0,-340(fp)
1538 cmpl -340(fp),-344(fp)
1539 bgequ noname.129
1540 addl2 #65536,-352(fp)
1541noname.129:
1542 movzwl -338(fp),r0
1543 bicl2 #-65536,r0
1544 addl2 r0,-352(fp)
1545 bicl3 #-65536,-340(fp),r0
1546 ashl #16,r0,-344(fp)
1547 addl3 -344(fp),-348(fp),r0
1548 bicl3 #0,r0,-348(fp)
1549 cmpl -348(fp),-344(fp)
1550 bgequ noname.130
1551 incl -352(fp)
1552noname.130:
1553 movl -348(fp),r1
1554 movl -352(fp),r2
1555 addl2 r1,r9
1556 bicl2 #0,r9
1557 cmpl r9,r1
1558 bgequ noname.131
1559 incl r2
1560noname.131:
1561 addl2 r2,r8
1562 bicl2 #0,r8
1563 cmpl r8,r2
1564 bgequ noname.132
1565 incl r10
1566noname.132:
1567
1568 movzwl 22(r6),r2
1569 bicl3 #-65536,4(r7),r3
1570 movzwl 6(r7),r0
1571 bicl2 #-65536,r0
1572 bicl3 #-65536,20(r6),-364(fp)
1573 bicl3 #-65536,r2,-368(fp)
1574 mull3 r0,-364(fp),-356(fp)
1575 mull2 r3,-364(fp)
1576 mull3 r3,-368(fp),-360(fp)
1577 mull2 r0,-368(fp)
1578 addl3 -356(fp),-360(fp),r0
1579 bicl3 #0,r0,-356(fp)
1580 cmpl -356(fp),-360(fp)
1581 bgequ noname.133
1582 addl2 #65536,-368(fp)
1583noname.133:
1584 movzwl -354(fp),r0
1585 bicl2 #-65536,r0
1586 addl2 r0,-368(fp)
1587 bicl3 #-65536,-356(fp),r0
1588 ashl #16,r0,-360(fp)
1589 addl3 -360(fp),-364(fp),r0
1590 bicl3 #0,r0,-364(fp)
1591 cmpl -364(fp),-360(fp)
1592 bgequ noname.134
1593 incl -368(fp)
1594noname.134:
1595 movl -364(fp),r1
1596 movl -368(fp),r2
1597 addl2 r1,r9
1598 bicl2 #0,r9
1599 cmpl r9,r1
1600 bgequ noname.135
1601 incl r2
1602noname.135:
1603 addl2 r2,r8
1604 bicl2 #0,r8
1605 cmpl r8,r2
1606 bgequ noname.136
1607 incl r10
1608noname.136:
1609
1610 movzwl 18(r6),r2
1611 bicl3 #-65536,8(r7),r3
1612 movzwl 10(r7),r0
1613 bicl2 #-65536,r0
1614 bicl3 #-65536,16(r6),-380(fp)
1615 bicl3 #-65536,r2,-384(fp)
1616 mull3 r0,-380(fp),-372(fp)
1617 mull2 r3,-380(fp)
1618 mull3 r3,-384(fp),-376(fp)
1619 mull2 r0,-384(fp)
1620 addl3 -372(fp),-376(fp),r0
1621 bicl3 #0,r0,-372(fp)
1622 cmpl -372(fp),-376(fp)
1623 bgequ noname.137
1624 addl2 #65536,-384(fp)
1625noname.137:
1626 movzwl -370(fp),r0
1627 bicl2 #-65536,r0
1628 addl2 r0,-384(fp)
1629 bicl3 #-65536,-372(fp),r0
1630 ashl #16,r0,-376(fp)
1631 addl3 -376(fp),-380(fp),r0
1632 bicl3 #0,r0,-380(fp)
1633 cmpl -380(fp),-376(fp)
1634 bgequ noname.138
1635 incl -384(fp)
1636noname.138:
1637 movl -380(fp),r1
1638 movl -384(fp),r2
1639 addl2 r1,r9
1640 bicl2 #0,r9
1641 cmpl r9,r1
1642 bgequ noname.139
1643 incl r2
1644noname.139:
1645 addl2 r2,r8
1646 bicl2 #0,r8
1647 cmpl r8,r2
1648 bgequ noname.140
1649 incl r10
1650noname.140:
1651
1652 movzwl 14(r6),r2
1653 bicl3 #-65536,12(r7),r3
1654 movzwl 14(r7),r0
1655 bicl2 #-65536,r0
1656 bicl3 #-65536,12(r6),-396(fp)
1657 bicl3 #-65536,r2,-400(fp)
1658 mull3 r0,-396(fp),-388(fp)
1659 mull2 r3,-396(fp)
1660 mull3 r3,-400(fp),-392(fp)
1661 mull2 r0,-400(fp)
1662 addl3 -388(fp),-392(fp),r0
1663 bicl3 #0,r0,-388(fp)
1664 cmpl -388(fp),-392(fp)
1665 bgequ noname.141
1666 addl2 #65536,-400(fp)
1667noname.141:
1668 movzwl -386(fp),r0
1669 bicl2 #-65536,r0
1670 addl2 r0,-400(fp)
1671 bicl3 #-65536,-388(fp),r0
1672 ashl #16,r0,-392(fp)
1673 addl3 -392(fp),-396(fp),r0
1674 bicl3 #0,r0,-396(fp)
1675 cmpl -396(fp),-392(fp)
1676 bgequ noname.142
1677 incl -400(fp)
1678noname.142:
1679 movl -396(fp),r1
1680 movl -400(fp),r2
1681 addl2 r1,r9
1682 bicl2 #0,r9
1683 cmpl r9,r1
1684 bgequ noname.143
1685 incl r2
1686noname.143:
1687 addl2 r2,r8
1688 bicl2 #0,r8
1689 cmpl r8,r2
1690 bgequ noname.144
1691 incl r10
1692noname.144:
1693
1694 movzwl 10(r6),r2
1695 bicl3 #-65536,16(r7),r3
1696 movzwl 18(r7),r0
1697 bicl2 #-65536,r0
1698 bicl3 #-65536,8(r6),-412(fp)
1699 bicl3 #-65536,r2,-416(fp)
1700 mull3 r0,-412(fp),-404(fp)
1701 mull2 r3,-412(fp)
1702 mull3 r3,-416(fp),-408(fp)
1703 mull2 r0,-416(fp)
1704 addl3 -404(fp),-408(fp),r0
1705 bicl3 #0,r0,-404(fp)
1706 cmpl -404(fp),-408(fp)
1707 bgequ noname.145
1708 addl2 #65536,-416(fp)
1709noname.145:
1710 movzwl -402(fp),r0
1711 bicl2 #-65536,r0
1712 addl2 r0,-416(fp)
1713 bicl3 #-65536,-404(fp),r0
1714 ashl #16,r0,-408(fp)
1715 addl3 -408(fp),-412(fp),r0
1716 bicl3 #0,r0,-412(fp)
1717 cmpl -412(fp),-408(fp)
1718 bgequ noname.146
1719 incl -416(fp)
1720noname.146:
1721 movl -412(fp),r1
1722 movl -416(fp),r2
1723 addl2 r1,r9
1724 bicl2 #0,r9
1725 cmpl r9,r1
1726 bgequ noname.147
1727 incl r2
1728noname.147:
1729 addl2 r2,r8
1730 bicl2 #0,r8
1731 cmpl r8,r2
1732 bgequ noname.148
1733 incl r10
1734noname.148:
1735
1736 movzwl 6(r6),r2
1737 bicl3 #-65536,20(r7),r3
1738 movzwl 22(r7),r0
1739 bicl2 #-65536,r0
1740 bicl3 #-65536,4(r6),-428(fp)
1741 bicl3 #-65536,r2,-432(fp)
1742 mull3 r0,-428(fp),-420(fp)
1743 mull2 r3,-428(fp)
1744 mull3 r3,-432(fp),-424(fp)
1745 mull2 r0,-432(fp)
1746 addl3 -420(fp),-424(fp),r0
1747 bicl3 #0,r0,-420(fp)
1748 cmpl -420(fp),-424(fp)
1749 bgequ noname.149
1750 addl2 #65536,-432(fp)
1751noname.149:
1752 movzwl -418(fp),r0
1753 bicl2 #-65536,r0
1754 addl2 r0,-432(fp)
1755 bicl3 #-65536,-420(fp),r0
1756 ashl #16,r0,-424(fp)
1757 addl3 -424(fp),-428(fp),r0
1758 bicl3 #0,r0,-428(fp)
1759 cmpl -428(fp),-424(fp)
1760 bgequ noname.150
1761 incl -432(fp)
1762noname.150:
1763 movl -428(fp),r1
1764 movl -432(fp),r2
1765 addl2 r1,r9
1766 bicl2 #0,r9
1767 cmpl r9,r1
1768 bgequ noname.151
1769 incl r2
1770noname.151:
1771 addl2 r2,r8
1772 bicl2 #0,r8
1773 cmpl r8,r2
1774 bgequ noname.152
1775 incl r10
1776noname.152:
1777
1778 movzwl 2(r6),r2
1779 bicl3 #-65536,24(r7),r3
1780 movzwl 26(r7),r0
1781 bicl2 #-65536,r0
1782 bicl3 #-65536,(r6),-444(fp)
1783 bicl3 #-65536,r2,-448(fp)
1784 mull3 r0,-444(fp),-436(fp)
1785 mull2 r3,-444(fp)
1786 mull3 r3,-448(fp),-440(fp)
1787 mull2 r0,-448(fp)
1788 addl3 -436(fp),-440(fp),r0
1789 bicl3 #0,r0,-436(fp)
1790 cmpl -436(fp),-440(fp)
1791 bgequ noname.153
1792 addl2 #65536,-448(fp)
1793noname.153:
1794 movzwl -434(fp),r0
1795 bicl2 #-65536,r0
1796 addl2 r0,-448(fp)
1797 bicl3 #-65536,-436(fp),r0
1798 ashl #16,r0,-440(fp)
1799 addl3 -440(fp),-444(fp),r0
1800 bicl3 #0,r0,-444(fp)
1801 cmpl -444(fp),-440(fp)
1802 bgequ noname.154
1803 incl -448(fp)
1804noname.154:
1805 movl -444(fp),r1
1806 movl -448(fp),r2
1807 addl2 r1,r9
1808 bicl2 #0,r9
1809 cmpl r9,r1
1810 bgequ noname.155
1811 incl r2
1812noname.155:
1813 addl2 r2,r8
1814 bicl2 #0,r8
1815 cmpl r8,r2
1816 bgequ noname.156
1817 incl r10
1818noname.156:
1819
1820 movl r9,24(r11)
1821
1822 clrl r9
1823
1824 movzwl 2(r6),r2
1825 bicl3 #-65536,28(r7),r3
1826 movzwl 30(r7),r0
1827 bicl2 #-65536,r0
1828 bicl3 #-65536,(r6),-460(fp)
1829 bicl3 #-65536,r2,-464(fp)
1830 mull3 r0,-460(fp),-452(fp)
1831 mull2 r3,-460(fp)
1832 mull3 r3,-464(fp),-456(fp)
1833 mull2 r0,-464(fp)
1834 addl3 -452(fp),-456(fp),r0
1835 bicl3 #0,r0,-452(fp)
1836 cmpl -452(fp),-456(fp)
1837 bgequ noname.157
1838 addl2 #65536,-464(fp)
1839noname.157:
1840 movzwl -450(fp),r0
1841 bicl2 #-65536,r0
1842 addl2 r0,-464(fp)
1843 bicl3 #-65536,-452(fp),r0
1844 ashl #16,r0,-456(fp)
1845 addl3 -456(fp),-460(fp),r0
1846 bicl3 #0,r0,-460(fp)
1847 cmpl -460(fp),-456(fp)
1848 bgequ noname.158
1849 incl -464(fp)
1850noname.158:
1851 movl -460(fp),r1
1852 movl -464(fp),r2
1853 addl2 r1,r8
1854 bicl2 #0,r8
1855 cmpl r8,r1
1856 bgequ noname.159
1857 incl r2
1858noname.159:
1859 addl2 r2,r10
1860 bicl2 #0,r10
1861 cmpl r10,r2
1862 bgequ noname.160
1863 incl r9
1864noname.160:
1865
1866 movzwl 6(r6),r2
1867 bicl3 #-65536,24(r7),r3
1868 movzwl 26(r7),r0
1869 bicl2 #-65536,r0
1870 bicl3 #-65536,4(r6),-476(fp)
1871 bicl3 #-65536,r2,-480(fp)
1872 mull3 r0,-476(fp),-468(fp)
1873 mull2 r3,-476(fp)
1874 mull3 r3,-480(fp),-472(fp)
1875 mull2 r0,-480(fp)
1876 addl3 -468(fp),-472(fp),r0
1877 bicl3 #0,r0,-468(fp)
1878 cmpl -468(fp),-472(fp)
1879 bgequ noname.161
1880 addl2 #65536,-480(fp)
1881noname.161:
1882 movzwl -466(fp),r0
1883 bicl2 #-65536,r0
1884 addl2 r0,-480(fp)
1885 bicl3 #-65536,-468(fp),r0
1886 ashl #16,r0,-472(fp)
1887 addl3 -472(fp),-476(fp),r0
1888 bicl3 #0,r0,-476(fp)
1889 cmpl -476(fp),-472(fp)
1890 bgequ noname.162
1891 incl -480(fp)
1892noname.162:
1893 movl -476(fp),r1
1894 movl -480(fp),r2
1895 addl2 r1,r8
1896 bicl2 #0,r8
1897 cmpl r8,r1
1898 bgequ noname.163
1899 incl r2
1900noname.163:
1901 addl2 r2,r10
1902 bicl2 #0,r10
1903 cmpl r10,r2
1904 bgequ noname.164
1905 incl r9
1906noname.164:
1907
1908 movzwl 10(r6),r2
1909 bicl3 #-65536,20(r7),r3
1910 movzwl 22(r7),r0
1911 bicl2 #-65536,r0
1912 bicl3 #-65536,8(r6),-492(fp)
1913 bicl3 #-65536,r2,-496(fp)
1914 mull3 r0,-492(fp),-484(fp)
1915 mull2 r3,-492(fp)
1916 mull3 r3,-496(fp),-488(fp)
1917 mull2 r0,-496(fp)
1918 addl3 -484(fp),-488(fp),r0
1919 bicl3 #0,r0,-484(fp)
1920 cmpl -484(fp),-488(fp)
1921 bgequ noname.165
1922 addl2 #65536,-496(fp)
1923noname.165:
1924 movzwl -482(fp),r0
1925 bicl2 #-65536,r0
1926 addl2 r0,-496(fp)
1927 bicl3 #-65536,-484(fp),r0
1928 ashl #16,r0,-488(fp)
1929 addl3 -488(fp),-492(fp),r0
1930 bicl3 #0,r0,-492(fp)
1931 cmpl -492(fp),-488(fp)
1932 bgequ noname.166
1933 incl -496(fp)
1934noname.166:
1935 movl -492(fp),r1
1936 movl -496(fp),r2
1937 addl2 r1,r8
1938 bicl2 #0,r8
1939 cmpl r8,r1
1940 bgequ noname.167
1941 incl r2
1942noname.167:
1943 addl2 r2,r10
1944 bicl2 #0,r10
1945 cmpl r10,r2
1946 bgequ noname.168
1947 incl r9
1948noname.168:
1949
1950 movzwl 14(r6),r2
1951 bicl3 #-65536,16(r7),r3
1952 movzwl 18(r7),r0
1953 bicl2 #-65536,r0
1954 bicl3 #-65536,12(r6),-508(fp)
1955 bicl3 #-65536,r2,-512(fp)
1956 mull3 r0,-508(fp),-500(fp)
1957 mull2 r3,-508(fp)
1958 mull3 r3,-512(fp),-504(fp)
1959 mull2 r0,-512(fp)
1960 addl3 -500(fp),-504(fp),r0
1961 bicl3 #0,r0,-500(fp)
1962 cmpl -500(fp),-504(fp)
1963 bgequ noname.169
1964 addl2 #65536,-512(fp)
1965noname.169:
1966 movzwl -498(fp),r0
1967 bicl2 #-65536,r0
1968 addl2 r0,-512(fp)
1969 bicl3 #-65536,-500(fp),r0
1970 ashl #16,r0,-504(fp)
1971 addl3 -504(fp),-508(fp),r0
1972 bicl3 #0,r0,-508(fp)
1973 cmpl -508(fp),-504(fp)
1974 bgequ noname.170
1975 incl -512(fp)
1976noname.170:
1977 movl -508(fp),r1
1978 movl -512(fp),r2
1979 addl2 r1,r8
1980 bicl2 #0,r8
1981 cmpl r8,r1
1982 bgequ noname.171
1983 incl r2
1984noname.171:
1985 addl2 r2,r10
1986 bicl2 #0,r10
1987 cmpl r10,r2
1988 bgequ noname.172
1989 incl r9
1990noname.172:
1991
1992 movzwl 18(r6),r2
1993 bicl3 #-65536,12(r7),r3
1994 movzwl 14(r7),r0
1995 bicl2 #-65536,r0
1996 bicl3 #-65536,16(r6),-524(fp)
1997 bicl3 #-65536,r2,-528(fp)
1998 mull3 r0,-524(fp),-516(fp)
1999 mull2 r3,-524(fp)
2000 mull3 r3,-528(fp),-520(fp)
2001 mull2 r0,-528(fp)
2002 addl3 -516(fp),-520(fp),r0
2003 bicl3 #0,r0,-516(fp)
2004 cmpl -516(fp),-520(fp)
2005 bgequ noname.173
2006 addl2 #65536,-528(fp)
2007noname.173:
2008 movzwl -514(fp),r0
2009 bicl2 #-65536,r0
2010 addl2 r0,-528(fp)
2011 bicl3 #-65536,-516(fp),r0
2012 ashl #16,r0,-520(fp)
2013 addl3 -520(fp),-524(fp),r0
2014 bicl3 #0,r0,-524(fp)
2015 cmpl -524(fp),-520(fp)
2016 bgequ noname.174
2017 incl -528(fp)
2018noname.174:
2019 movl -524(fp),r1
2020 movl -528(fp),r2
2021 addl2 r1,r8
2022 bicl2 #0,r8
2023 cmpl r8,r1
2024 bgequ noname.175
2025 incl r2
2026noname.175:
2027 addl2 r2,r10
2028 bicl2 #0,r10
2029 cmpl r10,r2
2030 bgequ noname.176
2031 incl r9
2032noname.176:
2033
2034 movzwl 22(r6),r2
2035 bicl3 #-65536,8(r7),r3
2036 movzwl 10(r7),r0
2037 bicl2 #-65536,r0
2038 bicl3 #-65536,20(r6),-540(fp)
2039 bicl3 #-65536,r2,-544(fp)
2040 mull3 r0,-540(fp),-532(fp)
2041 mull2 r3,-540(fp)
2042 mull3 r3,-544(fp),-536(fp)
2043 mull2 r0,-544(fp)
2044 addl3 -532(fp),-536(fp),r0
2045 bicl3 #0,r0,-532(fp)
2046 cmpl -532(fp),-536(fp)
2047 bgequ noname.177
2048 addl2 #65536,-544(fp)
2049noname.177:
2050 movzwl -530(fp),r0
2051 bicl2 #-65536,r0
2052 addl2 r0,-544(fp)
2053 bicl3 #-65536,-532(fp),r0
2054 ashl #16,r0,-536(fp)
2055 addl3 -536(fp),-540(fp),r0
2056 bicl3 #0,r0,-540(fp)
2057 cmpl -540(fp),-536(fp)
2058 bgequ noname.178
2059 incl -544(fp)
2060noname.178:
2061 movl -540(fp),r1
2062 movl -544(fp),r2
2063 addl2 r1,r8
2064 bicl2 #0,r8
2065 cmpl r8,r1
2066 bgequ noname.179
2067 incl r2
2068noname.179:
2069 addl2 r2,r10
2070 bicl2 #0,r10
2071 cmpl r10,r2
2072 bgequ noname.180
2073 incl r9
2074noname.180:
2075
2076 movzwl 26(r6),r2
2077 bicl3 #-65536,4(r7),r3
2078 movzwl 6(r7),r0
2079 bicl2 #-65536,r0
2080 bicl3 #-65536,24(r6),-556(fp)
2081 bicl3 #-65536,r2,-560(fp)
2082 mull3 r0,-556(fp),-548(fp)
2083 mull2 r3,-556(fp)
2084 mull3 r3,-560(fp),-552(fp)
2085 mull2 r0,-560(fp)
2086 addl3 -548(fp),-552(fp),r0
2087 bicl3 #0,r0,-548(fp)
2088 cmpl -548(fp),-552(fp)
2089 bgequ noname.181
2090 addl2 #65536,-560(fp)
2091noname.181:
2092 movzwl -546(fp),r0
2093 bicl2 #-65536,r0
2094 addl2 r0,-560(fp)
2095 bicl3 #-65536,-548(fp),r0
2096 ashl #16,r0,-552(fp)
2097 addl3 -552(fp),-556(fp),r0
2098 bicl3 #0,r0,-556(fp)
2099 cmpl -556(fp),-552(fp)
2100 bgequ noname.182
2101 incl -560(fp)
2102noname.182:
2103 movl -556(fp),r1
2104 movl -560(fp),r2
2105 addl2 r1,r8
2106 bicl2 #0,r8
2107 cmpl r8,r1
2108 bgequ noname.183
2109 incl r2
2110noname.183:
2111 addl2 r2,r10
2112 bicl2 #0,r10
2113 cmpl r10,r2
2114 bgequ noname.184
2115 incl r9
2116noname.184:
2117
2118 movzwl 30(r6),r2
2119 bicl3 #-65536,(r7),r3
2120 movzwl 2(r7),r0
2121 bicl2 #-65536,r0
2122 bicl3 #-65536,28(r6),-572(fp)
2123 bicl3 #-65536,r2,-576(fp)
2124 mull3 r0,-572(fp),-564(fp)
2125 mull2 r3,-572(fp)
2126 mull3 r3,-576(fp),-568(fp)
2127 mull2 r0,-576(fp)
2128 addl3 -564(fp),-568(fp),r0
2129 bicl3 #0,r0,-564(fp)
2130 cmpl -564(fp),-568(fp)
2131 bgequ noname.185
2132 addl2 #65536,-576(fp)
2133noname.185:
2134 movzwl -562(fp),r0
2135 bicl2 #-65536,r0
2136 addl2 r0,-576(fp)
2137 bicl3 #-65536,-564(fp),r0
2138 ashl #16,r0,-568(fp)
2139 addl3 -568(fp),-572(fp),r0
2140 bicl3 #0,r0,-572(fp)
2141 cmpl -572(fp),-568(fp)
2142 bgequ noname.186
2143 incl -576(fp)
2144noname.186:
2145 movl -572(fp),r1
2146 movl -576(fp),r2
2147 addl2 r1,r8
2148 bicl2 #0,r8
2149 cmpl r8,r1
2150 bgequ noname.187
2151 incl r2
2152noname.187:
2153 addl2 r2,r10
2154 bicl2 #0,r10
2155 cmpl r10,r2
2156 bgequ noname.188
2157 incl r9
2158noname.188:
2159
2160 movl r8,28(r11)
2161
2162 clrl r8
2163
2164 movzwl 30(r6),r2
2165 bicl3 #-65536,4(r7),r3
2166 movzwl 6(r7),r0
2167 bicl2 #-65536,r0
2168 bicl3 #-65536,28(r6),-588(fp)
2169 bicl3 #-65536,r2,-592(fp)
2170 mull3 r0,-588(fp),-580(fp)
2171 mull2 r3,-588(fp)
2172 mull3 r3,-592(fp),-584(fp)
2173 mull2 r0,-592(fp)
2174 addl3 -580(fp),-584(fp),r0
2175 bicl3 #0,r0,-580(fp)
2176 cmpl -580(fp),-584(fp)
2177 bgequ noname.189
2178 addl2 #65536,-592(fp)
2179noname.189:
2180 movzwl -578(fp),r0
2181 bicl2 #-65536,r0
2182 addl2 r0,-592(fp)
2183 bicl3 #-65536,-580(fp),r0
2184 ashl #16,r0,-584(fp)
2185 addl3 -584(fp),-588(fp),r0
2186 bicl3 #0,r0,-588(fp)
2187 cmpl -588(fp),-584(fp)
2188 bgequ noname.190
2189 incl -592(fp)
2190noname.190:
2191 movl -588(fp),r1
2192 movl -592(fp),r2
2193 addl2 r1,r10
2194 bicl2 #0,r10
2195 cmpl r10,r1
2196 bgequ noname.191
2197 incl r2
2198noname.191:
2199 addl2 r2,r9
2200 bicl2 #0,r9
2201 cmpl r9,r2
2202 bgequ noname.192
2203 incl r8
2204noname.192:
2205
2206 movzwl 26(r6),r2
2207 bicl3 #-65536,8(r7),r3
2208 movzwl 10(r7),r0
2209 bicl2 #-65536,r0
2210 bicl3 #-65536,24(r6),-604(fp)
2211 bicl3 #-65536,r2,-608(fp)
2212 mull3 r0,-604(fp),-596(fp)
2213 mull2 r3,-604(fp)
2214 mull3 r3,-608(fp),-600(fp)
2215 mull2 r0,-608(fp)
2216 addl3 -596(fp),-600(fp),r0
2217 bicl3 #0,r0,-596(fp)
2218 cmpl -596(fp),-600(fp)
2219 bgequ noname.193
2220 addl2 #65536,-608(fp)
2221noname.193:
2222 movzwl -594(fp),r0
2223 bicl2 #-65536,r0
2224 addl2 r0,-608(fp)
2225 bicl3 #-65536,-596(fp),r0
2226 ashl #16,r0,-600(fp)
2227 addl3 -600(fp),-604(fp),r0
2228 bicl3 #0,r0,-604(fp)
2229 cmpl -604(fp),-600(fp)
2230 bgequ noname.194
2231 incl -608(fp)
2232noname.194:
2233 movl -604(fp),r1
2234 movl -608(fp),r2
2235 addl2 r1,r10
2236 bicl2 #0,r10
2237 cmpl r10,r1
2238 bgequ noname.195
2239 incl r2
2240noname.195:
2241 addl2 r2,r9
2242 bicl2 #0,r9
2243 cmpl r9,r2
2244 bgequ noname.196
2245 incl r8
2246noname.196:
2247
2248 movzwl 22(r6),r2
2249 bicl3 #-65536,12(r7),r3
2250 movzwl 14(r7),r0
2251 bicl2 #-65536,r0
2252 bicl3 #-65536,20(r6),-620(fp)
2253 bicl3 #-65536,r2,-624(fp)
2254 mull3 r0,-620(fp),-612(fp)
2255 mull2 r3,-620(fp)
2256 mull3 r3,-624(fp),-616(fp)
2257 mull2 r0,-624(fp)
2258 addl3 -612(fp),-616(fp),r0
2259 bicl3 #0,r0,-612(fp)
2260 cmpl -612(fp),-616(fp)
2261 bgequ noname.197
2262 addl2 #65536,-624(fp)
2263noname.197:
2264 movzwl -610(fp),r0
2265 bicl2 #-65536,r0
2266 addl2 r0,-624(fp)
2267 bicl3 #-65536,-612(fp),r0
2268 ashl #16,r0,-616(fp)
2269 addl3 -616(fp),-620(fp),r0
2270 bicl3 #0,r0,-620(fp)
2271 cmpl -620(fp),-616(fp)
2272 bgequ noname.198
2273 incl -624(fp)
2274noname.198:
2275 movl -620(fp),r1
2276 movl -624(fp),r2
2277 addl2 r1,r10
2278 bicl2 #0,r10
2279 cmpl r10,r1
2280 bgequ noname.199
2281 incl r2
2282noname.199:
2283 addl2 r2,r9
2284 bicl2 #0,r9
2285 cmpl r9,r2
2286 bgequ noname.200
2287 incl r8
2288noname.200:
2289
2290 movzwl 18(r6),r2
2291 bicl3 #-65536,16(r7),r3
2292 movzwl 18(r7),r0
2293 bicl2 #-65536,r0
2294 bicl3 #-65536,16(r6),-636(fp)
2295 bicl3 #-65536,r2,-640(fp)
2296 mull3 r0,-636(fp),-628(fp)
2297 mull2 r3,-636(fp)
2298 mull3 r3,-640(fp),-632(fp)
2299 mull2 r0,-640(fp)
2300 addl3 -628(fp),-632(fp),r0
2301 bicl3 #0,r0,-628(fp)
2302 cmpl -628(fp),-632(fp)
2303 bgequ noname.201
2304 addl2 #65536,-640(fp)
2305noname.201:
2306 movzwl -626(fp),r0
2307 bicl2 #-65536,r0
2308 addl2 r0,-640(fp)
2309 bicl3 #-65536,-628(fp),r0
2310 ashl #16,r0,-632(fp)
2311 addl3 -632(fp),-636(fp),r0
2312 bicl3 #0,r0,-636(fp)
2313 cmpl -636(fp),-632(fp)
2314 bgequ noname.202
2315 incl -640(fp)
2316noname.202:
2317 movl -636(fp),r1
2318 movl -640(fp),r2
2319 addl2 r1,r10
2320 bicl2 #0,r10
2321 cmpl r10,r1
2322 bgequ noname.203
2323 incl r2
2324noname.203:
2325 addl2 r2,r9
2326 bicl2 #0,r9
2327 cmpl r9,r2
2328 bgequ noname.204
2329 incl r8
2330noname.204:
2331
2332 movzwl 14(r6),r2
2333 bicl3 #-65536,20(r7),r3
2334 movzwl 22(r7),r0
2335 bicl2 #-65536,r0
2336 bicl3 #-65536,12(r6),-652(fp)
2337 bicl3 #-65536,r2,-656(fp)
2338 mull3 r0,-652(fp),-644(fp)
2339 mull2 r3,-652(fp)
2340 mull3 r3,-656(fp),-648(fp)
2341 mull2 r0,-656(fp)
2342 addl3 -644(fp),-648(fp),r0
2343 bicl3 #0,r0,-644(fp)
2344 cmpl -644(fp),-648(fp)
2345 bgequ noname.205
2346 addl2 #65536,-656(fp)
2347noname.205:
2348 movzwl -642(fp),r0
2349 bicl2 #-65536,r0
2350 addl2 r0,-656(fp)
2351 bicl3 #-65536,-644(fp),r0
2352 ashl #16,r0,-648(fp)
2353 addl3 -648(fp),-652(fp),r0
2354 bicl3 #0,r0,-652(fp)
2355 cmpl -652(fp),-648(fp)
2356 bgequ noname.206
2357 incl -656(fp)
2358noname.206:
2359 movl -652(fp),r1
2360 movl -656(fp),r2
2361 addl2 r1,r10
2362 bicl2 #0,r10
2363 cmpl r10,r1
2364 bgequ noname.207
2365 incl r2
2366noname.207:
2367 addl2 r2,r9
2368 bicl2 #0,r9
2369 cmpl r9,r2
2370 bgequ noname.208
2371 incl r8
2372noname.208:
2373
2374 movzwl 10(r6),r2
2375 bicl3 #-65536,24(r7),r3
2376 movzwl 26(r7),r0
2377 bicl2 #-65536,r0
2378 bicl3 #-65536,8(r6),-668(fp)
2379 bicl3 #-65536,r2,-672(fp)
2380 mull3 r0,-668(fp),-660(fp)
2381 mull2 r3,-668(fp)
2382 mull3 r3,-672(fp),-664(fp)
2383 mull2 r0,-672(fp)
2384 addl3 -660(fp),-664(fp),r0
2385 bicl3 #0,r0,-660(fp)
2386 cmpl -660(fp),-664(fp)
2387 bgequ noname.209
2388 addl2 #65536,-672(fp)
2389noname.209:
2390 movzwl -658(fp),r0
2391 bicl2 #-65536,r0
2392 addl2 r0,-672(fp)
2393 bicl3 #-65536,-660(fp),r0
2394 ashl #16,r0,-664(fp)
2395 addl3 -664(fp),-668(fp),r0
2396 bicl3 #0,r0,-668(fp)
2397 cmpl -668(fp),-664(fp)
2398 bgequ noname.210
2399 incl -672(fp)
2400noname.210:
2401 movl -668(fp),r1
2402 movl -672(fp),r2
2403 addl2 r1,r10
2404 bicl2 #0,r10
2405 cmpl r10,r1
2406 bgequ noname.211
2407 incl r2
2408noname.211:
2409 addl2 r2,r9
2410 bicl2 #0,r9
2411 cmpl r9,r2
2412 bgequ noname.212
2413 incl r8
2414noname.212:
2415
2416 movzwl 6(r6),r2
2417 bicl3 #-65536,28(r7),r3
2418 movzwl 30(r7),r0
2419 bicl2 #-65536,r0
2420 bicl3 #-65536,4(r6),-684(fp)
2421 bicl3 #-65536,r2,-688(fp)
2422 mull3 r0,-684(fp),-676(fp)
2423 mull2 r3,-684(fp)
2424 mull3 r3,-688(fp),-680(fp)
2425 mull2 r0,-688(fp)
2426 addl3 -676(fp),-680(fp),r0
2427 bicl3 #0,r0,-676(fp)
2428 cmpl -676(fp),-680(fp)
2429 bgequ noname.213
2430 addl2 #65536,-688(fp)
2431noname.213:
2432 movzwl -674(fp),r0
2433 bicl2 #-65536,r0
2434 addl2 r0,-688(fp)
2435 bicl3 #-65536,-676(fp),r0
2436 ashl #16,r0,-680(fp)
2437 addl3 -680(fp),-684(fp),r0
2438 bicl3 #0,r0,-684(fp)
2439 cmpl -684(fp),-680(fp)
2440 bgequ noname.214
2441 incl -688(fp)
2442noname.214:
2443 movl -684(fp),r1
2444 movl -688(fp),r2
2445 addl2 r1,r10
2446 bicl2 #0,r10
2447 cmpl r10,r1
2448 bgequ noname.215
2449 incl r2
2450noname.215:
2451 addl2 r2,r9
2452 bicl2 #0,r9
2453 cmpl r9,r2
2454 bgequ noname.216
2455 incl r8
2456noname.216:
2457
2458 movl r10,32(r11)
2459
2460 clrl r10
2461
2462 movzwl 10(r6),r2
2463 bicl3 #-65536,28(r7),r3
2464 movzwl 30(r7),r0
2465 bicl2 #-65536,r0
2466 bicl3 #-65536,8(r6),-700(fp)
2467 bicl3 #-65536,r2,-704(fp)
2468 mull3 r0,-700(fp),-692(fp)
2469 mull2 r3,-700(fp)
2470 mull3 r3,-704(fp),-696(fp)
2471 mull2 r0,-704(fp)
2472 addl3 -692(fp),-696(fp),r0
2473 bicl3 #0,r0,-692(fp)
2474 cmpl -692(fp),-696(fp)
2475 bgequ noname.217
2476 addl2 #65536,-704(fp)
2477noname.217:
2478 movzwl -690(fp),r0
2479 bicl2 #-65536,r0
2480 addl2 r0,-704(fp)
2481 bicl3 #-65536,-692(fp),r0
2482 ashl #16,r0,-696(fp)
2483 addl3 -696(fp),-700(fp),r0
2484 bicl3 #0,r0,-700(fp)
2485 cmpl -700(fp),-696(fp)
2486 bgequ noname.218
2487 incl -704(fp)
2488noname.218:
2489 movl -700(fp),r1
2490 movl -704(fp),r2
2491 addl2 r1,r9
2492 bicl2 #0,r9
2493 cmpl r9,r1
2494 bgequ noname.219
2495 incl r2
2496noname.219:
2497 addl2 r2,r8
2498 bicl2 #0,r8
2499 cmpl r8,r2
2500 bgequ noname.220
2501 incl r10
2502noname.220:
2503
2504 movzwl 14(r6),r2
2505 bicl3 #-65536,24(r7),r3
2506 movzwl 26(r7),r0
2507 bicl2 #-65536,r0
2508 bicl3 #-65536,12(r6),-716(fp)
2509 bicl3 #-65536,r2,-720(fp)
2510 mull3 r0,-716(fp),-708(fp)
2511 mull2 r3,-716(fp)
2512 mull3 r3,-720(fp),-712(fp)
2513 mull2 r0,-720(fp)
2514 addl3 -708(fp),-712(fp),r0
2515 bicl3 #0,r0,-708(fp)
2516 cmpl -708(fp),-712(fp)
2517 bgequ noname.221
2518 addl2 #65536,-720(fp)
2519noname.221:
2520 movzwl -706(fp),r0
2521 bicl2 #-65536,r0
2522 addl2 r0,-720(fp)
2523 bicl3 #-65536,-708(fp),r0
2524 ashl #16,r0,-712(fp)
2525 addl3 -712(fp),-716(fp),r0
2526 bicl3 #0,r0,-716(fp)
2527 cmpl -716(fp),-712(fp)
2528 bgequ noname.222
2529 incl -720(fp)
2530noname.222:
2531 movl -716(fp),r1
2532 movl -720(fp),r2
2533 addl2 r1,r9
2534 bicl2 #0,r9
2535 cmpl r9,r1
2536 bgequ noname.223
2537 incl r2
2538noname.223:
2539 addl2 r2,r8
2540 bicl2 #0,r8
2541 cmpl r8,r2
2542 bgequ noname.224
2543 incl r10
2544noname.224:
2545
2546 movzwl 18(r6),r2
2547 bicl3 #-65536,20(r7),r3
2548 movzwl 22(r7),r0
2549 bicl2 #-65536,r0
2550 bicl3 #-65536,16(r6),-732(fp)
2551 bicl3 #-65536,r2,-736(fp)
2552 mull3 r0,-732(fp),-724(fp)
2553 mull2 r3,-732(fp)
2554 mull3 r3,-736(fp),-728(fp)
2555 mull2 r0,-736(fp)
2556 addl3 -724(fp),-728(fp),r0
2557 bicl3 #0,r0,-724(fp)
2558 cmpl -724(fp),-728(fp)
2559 bgequ noname.225
2560 addl2 #65536,-736(fp)
2561noname.225:
2562 movzwl -722(fp),r0
2563 bicl2 #-65536,r0
2564 addl2 r0,-736(fp)
2565 bicl3 #-65536,-724(fp),r0
2566 ashl #16,r0,-728(fp)
2567 addl3 -728(fp),-732(fp),r0
2568 bicl3 #0,r0,-732(fp)
2569 cmpl -732(fp),-728(fp)
2570 bgequ noname.226
2571 incl -736(fp)
2572noname.226:
2573 movl -732(fp),r1
2574 movl -736(fp),r2
2575 addl2 r1,r9
2576 bicl2 #0,r9
2577 cmpl r9,r1
2578 bgequ noname.227
2579 incl r2
2580noname.227:
2581 addl2 r2,r8
2582 bicl2 #0,r8
2583 cmpl r8,r2
2584 bgequ noname.228
2585 incl r10
2586noname.228:
2587
2588 movzwl 22(r6),r2
2589 bicl3 #-65536,16(r7),r3
2590 movzwl 18(r7),r0
2591 bicl2 #-65536,r0
2592 bicl3 #-65536,20(r6),-748(fp)
2593 bicl3 #-65536,r2,-752(fp)
2594 mull3 r0,-748(fp),-740(fp)
2595 mull2 r3,-748(fp)
2596 mull3 r3,-752(fp),-744(fp)
2597 mull2 r0,-752(fp)
2598 addl3 -740(fp),-744(fp),r0
2599 bicl3 #0,r0,-740(fp)
2600 cmpl -740(fp),-744(fp)
2601 bgequ noname.229
2602 addl2 #65536,-752(fp)
2603noname.229:
2604 movzwl -738(fp),r0
2605 bicl2 #-65536,r0
2606 addl2 r0,-752(fp)
2607 bicl3 #-65536,-740(fp),r0
2608 ashl #16,r0,-744(fp)
2609 addl3 -744(fp),-748(fp),r0
2610 bicl3 #0,r0,-748(fp)
2611 cmpl -748(fp),-744(fp)
2612 bgequ noname.230
2613 incl -752(fp)
2614noname.230:
2615 movl -748(fp),r1
2616 movl -752(fp),r2
2617 addl2 r1,r9
2618 bicl2 #0,r9
2619 cmpl r9,r1
2620 bgequ noname.231
2621 incl r2
2622noname.231:
2623 addl2 r2,r8
2624 bicl2 #0,r8
2625 cmpl r8,r2
2626 bgequ noname.232
2627 incl r10
2628noname.232:
2629
2630 movzwl 26(r6),r2
2631 bicl3 #-65536,12(r7),r3
2632 movzwl 14(r7),r0
2633 bicl2 #-65536,r0
2634 bicl3 #-65536,24(r6),-764(fp)
2635 bicl3 #-65536,r2,-768(fp)
2636 mull3 r0,-764(fp),-756(fp)
2637 mull2 r3,-764(fp)
2638 mull3 r3,-768(fp),-760(fp)
2639 mull2 r0,-768(fp)
2640 addl3 -756(fp),-760(fp),r0
2641 bicl3 #0,r0,-756(fp)
2642 cmpl -756(fp),-760(fp)
2643 bgequ noname.233
2644 addl2 #65536,-768(fp)
2645noname.233:
2646 movzwl -754(fp),r0
2647 bicl2 #-65536,r0
2648 addl2 r0,-768(fp)
2649 bicl3 #-65536,-756(fp),r0
2650 ashl #16,r0,-760(fp)
2651 addl3 -760(fp),-764(fp),r0
2652 bicl3 #0,r0,-764(fp)
2653 cmpl -764(fp),-760(fp)
2654 bgequ noname.234
2655 incl -768(fp)
2656noname.234:
2657 movl -764(fp),r1
2658 movl -768(fp),r2
2659 addl2 r1,r9
2660 bicl2 #0,r9
2661 cmpl r9,r1
2662 bgequ noname.235
2663 incl r2
2664noname.235:
2665 addl2 r2,r8
2666 bicl2 #0,r8
2667 cmpl r8,r2
2668 bgequ noname.236
2669 incl r10
2670noname.236:
2671
2672 bicl3 #-65536,28(r6),r3
2673 movzwl 30(r6),r1
2674 bicl2 #-65536,r1
2675 bicl3 #-65536,8(r7),r2
2676 movzwl 10(r7),r0
2677 bicl2 #-65536,r0
2678 movl r3,r5
2679 movl r1,r4
2680 mull3 r0,r5,-772(fp)
2681 mull2 r2,r5
2682 mull3 r2,r4,-776(fp)
2683 mull2 r0,r4
2684 addl3 -772(fp),-776(fp),r0
2685 bicl3 #0,r0,-772(fp)
2686 cmpl -772(fp),-776(fp)
2687 bgequ noname.237
2688 addl2 #65536,r4
2689noname.237:
2690 movzwl -770(fp),r0
2691 bicl2 #-65536,r0
2692 addl2 r0,r4
2693 bicl3 #-65536,-772(fp),r0
2694 ashl #16,r0,-776(fp)
2695 addl2 -776(fp),r5
2696 bicl2 #0,r5
2697 cmpl r5,-776(fp)
2698 bgequ noname.238
2699 incl r4
2700noname.238:
2701 movl r5,r1
2702 movl r4,r2
2703 addl2 r1,r9
2704 bicl2 #0,r9
2705 cmpl r9,r1
2706 bgequ noname.239
2707 incl r2
2708noname.239:
2709 addl2 r2,r8
2710 bicl2 #0,r8
2711 cmpl r8,r2
2712 bgequ noname.240
2713 incl r10
2714noname.240:
2715
2716 movl r9,36(r11)
2717
2718 clrl r9
2719
2720 bicl3 #-65536,28(r6),r3
2721 movzwl 30(r6),r1
2722 bicl2 #-65536,r1
2723 bicl3 #-65536,12(r7),r2
2724 movzwl 14(r7),r0
2725 bicl2 #-65536,r0
2726 movl r3,r5
2727 movl r1,r4
2728 mull3 r0,r5,-780(fp)
2729 mull2 r2,r5
2730 mull3 r2,r4,-784(fp)
2731 mull2 r0,r4
2732 addl3 -780(fp),-784(fp),r0
2733 bicl3 #0,r0,-780(fp)
2734 cmpl -780(fp),-784(fp)
2735 bgequ noname.241
2736 addl2 #65536,r4
2737noname.241:
2738 movzwl -778(fp),r0
2739 bicl2 #-65536,r0
2740 addl2 r0,r4
2741 bicl3 #-65536,-780(fp),r0
2742 ashl #16,r0,-784(fp)
2743 addl2 -784(fp),r5
2744 bicl2 #0,r5
2745 cmpl r5,-784(fp)
2746 bgequ noname.242
2747 incl r4
2748noname.242:
2749 movl r5,r1
2750 movl r4,r2
2751 addl2 r1,r8
2752 bicl2 #0,r8
2753 cmpl r8,r1
2754 bgequ noname.243
2755 incl r2
2756noname.243:
2757 addl2 r2,r10
2758 bicl2 #0,r10
2759 cmpl r10,r2
2760 bgequ noname.244
2761 incl r9
2762noname.244:
2763
2764 bicl3 #-65536,24(r6),r3
2765 movzwl 26(r6),r1
2766 bicl2 #-65536,r1
2767 bicl3 #-65536,16(r7),r2
2768 movzwl 18(r7),r0
2769 bicl2 #-65536,r0
2770 movl r3,r5
2771 movl r1,r4
2772 mull3 r0,r5,-788(fp)
2773 mull2 r2,r5
2774 mull3 r2,r4,-792(fp)
2775 mull2 r0,r4
2776 addl3 -788(fp),-792(fp),r0
2777 bicl3 #0,r0,-788(fp)
2778 cmpl -788(fp),-792(fp)
2779 bgequ noname.245
2780 addl2 #65536,r4
2781noname.245:
2782 movzwl -786(fp),r0
2783 bicl2 #-65536,r0
2784 addl2 r0,r4
2785 bicl3 #-65536,-788(fp),r0
2786 ashl #16,r0,-792(fp)
2787 addl2 -792(fp),r5
2788 bicl2 #0,r5
2789 cmpl r5,-792(fp)
2790 bgequ noname.246
2791 incl r4
2792noname.246:
2793 movl r5,r1
2794 movl r4,r2
2795 addl2 r1,r8
2796 bicl2 #0,r8
2797 cmpl r8,r1
2798 bgequ noname.247
2799 incl r2
2800noname.247:
2801 addl2 r2,r10
2802 bicl2 #0,r10
2803 cmpl r10,r2
2804 bgequ noname.248
2805 incl r9
2806noname.248:
2807
2808 bicl3 #-65536,20(r6),r3
2809 movzwl 22(r6),r1
2810 bicl2 #-65536,r1
2811 bicl3 #-65536,20(r7),r2
2812 movzwl 22(r7),r0
2813 bicl2 #-65536,r0
2814 movl r3,r5
2815 movl r1,r4
2816 mull3 r0,r5,-796(fp)
2817 mull2 r2,r5
2818 mull3 r2,r4,-800(fp)
2819 mull2 r0,r4
2820 addl3 -796(fp),-800(fp),r0
2821 bicl3 #0,r0,-796(fp)
2822 cmpl -796(fp),-800(fp)
2823 bgequ noname.249
2824 addl2 #65536,r4
2825noname.249:
2826 movzwl -794(fp),r0
2827 bicl2 #-65536,r0
2828 addl2 r0,r4
2829 bicl3 #-65536,-796(fp),r0
2830 ashl #16,r0,-800(fp)
2831 addl2 -800(fp),r5
2832 bicl2 #0,r5
2833 cmpl r5,-800(fp)
2834 bgequ noname.250
2835 incl r4
2836noname.250:
2837 movl r5,r1
2838 movl r4,r2
2839 addl2 r1,r8
2840 bicl2 #0,r8
2841 cmpl r8,r1
2842 bgequ noname.251
2843 incl r2
2844noname.251:
2845 addl2 r2,r10
2846 bicl2 #0,r10
2847 cmpl r10,r2
2848 bgequ noname.252
2849 incl r9
2850noname.252:
2851
2852 bicl3 #-65536,16(r6),r3
2853 movzwl 18(r6),r1
2854 bicl2 #-65536,r1
2855 bicl3 #-65536,24(r7),r2
2856 movzwl 26(r7),r0
2857 bicl2 #-65536,r0
2858 movl r3,r5
2859 movl r1,r4
2860 mull3 r0,r5,-804(fp)
2861 mull2 r2,r5
2862 mull3 r2,r4,-808(fp)
2863 mull2 r0,r4
2864 addl3 -804(fp),-808(fp),r0
2865 bicl3 #0,r0,-804(fp)
2866 cmpl -804(fp),-808(fp)
2867 bgequ noname.253
2868 addl2 #65536,r4
2869noname.253:
2870 movzwl -802(fp),r0
2871 bicl2 #-65536,r0
2872 addl2 r0,r4
2873 bicl3 #-65536,-804(fp),r0
2874 ashl #16,r0,-808(fp)
2875 addl2 -808(fp),r5
2876 bicl2 #0,r5
2877 cmpl r5,-808(fp)
2878 bgequ noname.254
2879 incl r4
2880noname.254:
2881 movl r5,r1
2882 movl r4,r2
2883 addl2 r1,r8
2884 bicl2 #0,r8
2885 cmpl r8,r1
2886 bgequ noname.255
2887 incl r2
2888noname.255:
2889 addl2 r2,r10
2890 bicl2 #0,r10
2891 cmpl r10,r2
2892 bgequ noname.256
2893 incl r9
2894noname.256:
2895
2896 bicl3 #-65536,12(r6),r3
2897 movzwl 14(r6),r1
2898 bicl2 #-65536,r1
2899 bicl3 #-65536,28(r7),r2
2900 movzwl 30(r7),r0
2901 bicl2 #-65536,r0
2902 movl r3,r5
2903 movl r1,r4
2904 mull3 r0,r5,-812(fp)
2905 mull2 r2,r5
2906 mull3 r2,r4,-816(fp)
2907 mull2 r0,r4
2908 addl3 -812(fp),-816(fp),r0
2909 bicl3 #0,r0,-812(fp)
2910 cmpl -812(fp),-816(fp)
2911 bgequ noname.257
2912 addl2 #65536,r4
2913noname.257:
2914 movzwl -810(fp),r0
2915 bicl2 #-65536,r0
2916 addl2 r0,r4
2917 bicl3 #-65536,-812(fp),r0
2918 ashl #16,r0,-816(fp)
2919 addl2 -816(fp),r5
2920 bicl2 #0,r5
2921 cmpl r5,-816(fp)
2922 bgequ noname.258
2923 incl r4
2924noname.258:
2925 movl r5,r1
2926 movl r4,r2
2927 addl2 r1,r8
2928 bicl2 #0,r8
2929 cmpl r8,r1
2930 bgequ noname.259
2931 incl r2
2932noname.259:
2933 addl2 r2,r10
2934 bicl2 #0,r10
2935 cmpl r10,r2
2936 bgequ noname.260
2937 incl r9
2938noname.260:
2939
2940 movl r8,40(r11)
2941
2942 clrl r8
2943
2944 bicl3 #-65536,16(r6),r3
2945 movzwl 18(r6),r2
2946 bicl3 #-65536,28(r7),r1
2947 movzwl 30(r7),r0
2948 bicl2 #-65536,r0
2949 movl r3,r4
2950 bicl3 #-65536,r2,-828(fp)
2951 mull3 r0,r4,-820(fp)
2952 mull2 r1,r4
2953 mull3 r1,-828(fp),-824(fp)
2954 mull2 r0,-828(fp)
2955 addl3 -820(fp),-824(fp),r0
2956 bicl3 #0,r0,-820(fp)
2957 cmpl -820(fp),-824(fp)
2958 bgequ noname.261
2959 addl2 #65536,-828(fp)
2960noname.261:
2961 movzwl -818(fp),r0
2962 bicl2 #-65536,r0
2963 addl2 r0,-828(fp)
2964 bicl3 #-65536,-820(fp),r0
2965 ashl #16,r0,-824(fp)
2966 addl2 -824(fp),r4
2967 bicl2 #0,r4
2968 cmpl r4,-824(fp)
2969 bgequ noname.262
2970 incl -828(fp)
2971noname.262:
2972 movl r4,r1
2973 movl -828(fp),r2
2974 addl2 r1,r10
2975 bicl2 #0,r10
2976 cmpl r10,r1
2977 bgequ noname.263
2978 incl r2
2979noname.263:
2980 addl2 r2,r9
2981 bicl2 #0,r9
2982 cmpl r9,r2
2983 bgequ noname.264
2984 incl r8
2985noname.264:
2986
2987 movzwl 22(r6),r2
2988 bicl3 #-65536,24(r7),r3
2989 movzwl 26(r7),r0
2990 bicl2 #-65536,r0
2991 bicl3 #-65536,20(r6),-840(fp)
2992 bicl3 #-65536,r2,-844(fp)
2993 mull3 r0,-840(fp),-832(fp)
2994 mull2 r3,-840(fp)
2995 mull3 r3,-844(fp),-836(fp)
2996 mull2 r0,-844(fp)
2997 addl3 -832(fp),-836(fp),r0
2998 bicl3 #0,r0,-832(fp)
2999 cmpl -832(fp),-836(fp)
3000 bgequ noname.265
3001 addl2 #65536,-844(fp)
3002noname.265:
3003 movzwl -830(fp),r0
3004 bicl2 #-65536,r0
3005 addl2 r0,-844(fp)
3006 bicl3 #-65536,-832(fp),r0
3007 ashl #16,r0,-836(fp)
3008 addl3 -836(fp),-840(fp),r0
3009 bicl3 #0,r0,-840(fp)
3010 cmpl -840(fp),-836(fp)
3011 bgequ noname.266
3012 incl -844(fp)
3013noname.266:
3014 movl -840(fp),r1
3015 movl -844(fp),r2
3016 addl2 r1,r10
3017 bicl2 #0,r10
3018 cmpl r10,r1
3019 bgequ noname.267
3020 incl r2
3021noname.267:
3022 addl2 r2,r9
3023 bicl2 #0,r9
3024 cmpl r9,r2
3025 bgequ noname.268
3026 incl r8
3027noname.268:
3028
3029 bicl3 #-65536,24(r6),r3
3030 movzwl 26(r6),r1
3031 bicl2 #-65536,r1
3032 bicl3 #-65536,20(r7),r2
3033 movzwl 22(r7),r0
3034 bicl2 #-65536,r0
3035 movl r3,r5
3036 movl r1,r4
3037 mull3 r0,r5,-848(fp)
3038 mull2 r2,r5
3039 mull3 r2,r4,-852(fp)
3040 mull2 r0,r4
3041 addl3 -848(fp),-852(fp),r0
3042 bicl3 #0,r0,-848(fp)
3043 cmpl -848(fp),-852(fp)
3044 bgequ noname.269
3045 addl2 #65536,r4
3046noname.269:
3047 movzwl -846(fp),r0
3048 bicl2 #-65536,r0
3049 addl2 r0,r4
3050 bicl3 #-65536,-848(fp),r0
3051 ashl #16,r0,-852(fp)
3052 addl2 -852(fp),r5
3053 bicl2 #0,r5
3054 cmpl r5,-852(fp)
3055 bgequ noname.270
3056 incl r4
3057noname.270:
3058 movl r5,r1
3059 movl r4,r2
3060 addl2 r1,r10
3061 bicl2 #0,r10
3062 cmpl r10,r1
3063 bgequ noname.271
3064 incl r2
3065noname.271:
3066 addl2 r2,r9
3067 bicl2 #0,r9
3068 cmpl r9,r2
3069 bgequ noname.272
3070 incl r8
3071noname.272:
3072
3073 bicl3 #-65536,28(r6),r3
3074 movzwl 30(r6),r1
3075 bicl2 #-65536,r1
3076 bicl3 #-65536,16(r7),r2
3077 movzwl 18(r7),r0
3078 bicl2 #-65536,r0
3079 movl r3,r5
3080 movl r1,r4
3081 mull3 r0,r5,-856(fp)
3082 mull2 r2,r5
3083 mull3 r2,r4,-860(fp)
3084 mull2 r0,r4
3085 addl3 -856(fp),-860(fp),r0
3086 bicl3 #0,r0,-856(fp)
3087 cmpl -856(fp),-860(fp)
3088 bgequ noname.273
3089 addl2 #65536,r4
3090noname.273:
3091 movzwl -854(fp),r0
3092 bicl2 #-65536,r0
3093 addl2 r0,r4
3094 bicl3 #-65536,-856(fp),r0
3095 ashl #16,r0,-860(fp)
3096 addl2 -860(fp),r5
3097 bicl2 #0,r5
3098 cmpl r5,-860(fp)
3099 bgequ noname.274
3100 incl r4
3101noname.274:
3102 movl r5,r1
3103 movl r4,r2
3104 addl2 r1,r10
3105 bicl2 #0,r10
3106 cmpl r10,r1
3107 bgequ noname.275
3108 incl r2
3109noname.275:
3110 addl2 r2,r9
3111 bicl2 #0,r9
3112 cmpl r9,r2
3113 bgequ noname.276
3114 incl r8
3115noname.276:
3116
3117 movl r10,44(r11)
3118
3119 clrl r10
3120
3121 bicl3 #-65536,28(r6),r3
3122 movzwl 30(r6),r1
3123 bicl2 #-65536,r1
3124 bicl3 #-65536,20(r7),r2
3125 movzwl 22(r7),r0
3126 bicl2 #-65536,r0
3127 movl r3,r5
3128 movl r1,r4
3129 mull3 r0,r5,-864(fp)
3130 mull2 r2,r5
3131 mull3 r2,r4,-868(fp)
3132 mull2 r0,r4
3133 addl3 -864(fp),-868(fp),r0
3134 bicl3 #0,r0,-864(fp)
3135 cmpl -864(fp),-868(fp)
3136 bgequ noname.277
3137 addl2 #65536,r4
3138noname.277:
3139 movzwl -862(fp),r0
3140 bicl2 #-65536,r0
3141 addl2 r0,r4
3142 bicl3 #-65536,-864(fp),r0
3143 ashl #16,r0,-868(fp)
3144 addl2 -868(fp),r5
3145 bicl2 #0,r5
3146 cmpl r5,-868(fp)
3147 bgequ noname.278
3148 incl r4
3149noname.278:
3150 movl r5,r1
3151 movl r4,r2
3152 addl2 r1,r9
3153 bicl2 #0,r9
3154 cmpl r9,r1
3155 bgequ noname.279
3156 incl r2
3157noname.279:
3158 addl2 r2,r8
3159 bicl2 #0,r8
3160 cmpl r8,r2
3161 bgequ noname.280
3162 incl r10
3163noname.280:
3164
3165 bicl3 #-65536,24(r6),r3
3166 movzwl 26(r6),r1
3167 bicl2 #-65536,r1
3168 bicl3 #-65536,24(r7),r2
3169 movzwl 26(r7),r0
3170 bicl2 #-65536,r0
3171 movl r3,r5
3172 movl r1,r4
3173 mull3 r0,r5,-872(fp)
3174 mull2 r2,r5
3175 mull3 r2,r4,-876(fp)
3176 mull2 r0,r4
3177 addl3 -872(fp),-876(fp),r0
3178 bicl3 #0,r0,-872(fp)
3179 cmpl -872(fp),-876(fp)
3180 bgequ noname.281
3181 addl2 #65536,r4
3182noname.281:
3183 movzwl -870(fp),r0
3184 bicl2 #-65536,r0
3185 addl2 r0,r4
3186 bicl3 #-65536,-872(fp),r0
3187 ashl #16,r0,-876(fp)
3188 addl2 -876(fp),r5
3189 bicl2 #0,r5
3190 cmpl r5,-876(fp)
3191 bgequ noname.282
3192 incl r4
3193noname.282:
3194 movl r5,r1
3195 movl r4,r2
3196 addl2 r1,r9
3197 bicl2 #0,r9
3198 cmpl r9,r1
3199 bgequ noname.283
3200 incl r2
3201noname.283:
3202 addl2 r2,r8
3203 bicl2 #0,r8
3204 cmpl r8,r2
3205 bgequ noname.284
3206 incl r10
3207noname.284:
3208
3209 bicl3 #-65536,20(r6),r3
3210 movzwl 22(r6),r1
3211 bicl2 #-65536,r1
3212 bicl3 #-65536,28(r7),r2
3213 movzwl 30(r7),r0
3214 bicl2 #-65536,r0
3215 movl r3,r5
3216 movl r1,r4
3217 mull3 r0,r5,-880(fp)
3218 mull2 r2,r5
3219 mull3 r2,r4,-884(fp)
3220 mull2 r0,r4
3221 addl3 -880(fp),-884(fp),r0
3222 bicl3 #0,r0,-880(fp)
3223 cmpl -880(fp),-884(fp)
3224 bgequ noname.285
3225 addl2 #65536,r4
3226noname.285:
3227 movzwl -878(fp),r0
3228 bicl2 #-65536,r0
3229 addl2 r0,r4
3230 bicl3 #-65536,-880(fp),r0
3231 ashl #16,r0,-884(fp)
3232 addl2 -884(fp),r5
3233 bicl2 #0,r5
3234 cmpl r5,-884(fp)
3235 bgequ noname.286
3236 incl r4
3237noname.286:
3238 movl r5,r1
3239 movl r4,r2
3240 addl2 r1,r9
3241 bicl2 #0,r9
3242 cmpl r9,r1
3243 bgequ noname.287
3244 incl r2
3245noname.287:
3246 addl2 r2,r8
3247 bicl2 #0,r8
3248 cmpl r8,r2
3249 bgequ noname.288
3250 incl r10
3251noname.288:
3252
3253 movl r9,48(r11)
3254
3255 clrl r9
3256
3257 bicl3 #-65536,24(r6),r3
3258 movzwl 26(r6),r1
3259 bicl2 #-65536,r1
3260 bicl3 #-65536,28(r7),r2
3261 movzwl 30(r7),r0
3262 bicl2 #-65536,r0
3263 movl r3,r5
3264 movl r1,r4
3265 mull3 r0,r5,-888(fp)
3266 mull2 r2,r5
3267 mull3 r2,r4,-892(fp)
3268 mull2 r0,r4
3269 addl3 -888(fp),-892(fp),r0
3270 bicl3 #0,r0,-888(fp)
3271 cmpl -888(fp),-892(fp)
3272 bgequ noname.289
3273 addl2 #65536,r4
3274noname.289:
3275 movzwl -886(fp),r0
3276 bicl2 #-65536,r0
3277 addl2 r0,r4
3278 bicl3 #-65536,-888(fp),r0
3279 ashl #16,r0,-892(fp)
3280 addl2 -892(fp),r5
3281 bicl2 #0,r5
3282 cmpl r5,-892(fp)
3283 bgequ noname.290
3284 incl r4
3285noname.290:
3286 movl r5,r1
3287 movl r4,r2
3288 addl2 r1,r8
3289 bicl2 #0,r8
3290 cmpl r8,r1
3291 bgequ noname.291
3292 incl r2
3293noname.291:
3294 addl2 r2,r10
3295 bicl2 #0,r10
3296 cmpl r10,r2
3297 bgequ noname.292
3298 incl r9
3299noname.292:
3300
3301 movzwl 30(r6),r2
3302 bicl3 #-65536,24(r7),r3
3303 movzwl 26(r7),r0
3304 bicl2 #-65536,r0
3305 bicl3 #-65536,28(r6),-904(fp)
3306 bicl3 #-65536,r2,-908(fp)
3307 mull3 r0,-904(fp),-896(fp)
3308 mull2 r3,-904(fp)
3309 mull3 r3,-908(fp),-900(fp)
3310 mull2 r0,-908(fp)
3311 addl3 -896(fp),-900(fp),r0
3312 bicl3 #0,r0,-896(fp)
3313 cmpl -896(fp),-900(fp)
3314 bgequ noname.293
3315 addl2 #65536,-908(fp)
3316noname.293:
3317 movzwl -894(fp),r0
3318 bicl2 #-65536,r0
3319 addl2 r0,-908(fp)
3320 bicl3 #-65536,-896(fp),r0
3321 ashl #16,r0,-900(fp)
3322 addl3 -900(fp),-904(fp),r0
3323 bicl3 #0,r0,-904(fp)
3324 cmpl -904(fp),-900(fp)
3325 bgequ noname.294
3326 incl -908(fp)
3327noname.294:
3328 movl -904(fp),r1
3329 movl -908(fp),r2
3330 addl2 r1,r8
3331 bicl2 #0,r8
3332 cmpl r8,r1
3333 bgequ noname.295
3334 incl r2
3335noname.295:
3336 addl2 r2,r10
3337 bicl2 #0,r10
3338 cmpl r10,r2
3339 bgequ noname.296
3340 incl r9
3341noname.296:
3342
3343 movl r8,52(r11)
3344
3345 clrl r8
3346
3347 movzwl 30(r6),r2
3348 bicl3 #-65536,28(r7),r3
3349 movzwl 30(r7),r0
3350 bicl2 #-65536,r0
3351 bicl3 #-65536,28(r6),-920(fp)
3352 bicl3 #-65536,r2,-924(fp)
3353 mull3 r0,-920(fp),-912(fp)
3354 mull2 r3,-920(fp)
3355 mull3 r3,-924(fp),-916(fp)
3356 mull2 r0,-924(fp)
3357 addl3 -912(fp),-916(fp),r0
3358 bicl3 #0,r0,-912(fp)
3359 cmpl -912(fp),-916(fp)
3360 bgequ noname.297
3361 addl2 #65536,-924(fp)
3362noname.297:
3363 movzwl -910(fp),r0
3364 bicl2 #-65536,r0
3365 addl2 r0,-924(fp)
3366 bicl3 #-65536,-912(fp),r0
3367 ashl #16,r0,-916(fp)
3368 addl3 -916(fp),-920(fp),r0
3369 bicl3 #0,r0,-920(fp)
3370 cmpl -920(fp),-916(fp)
3371 bgequ noname.298
3372 incl -924(fp)
3373noname.298:
3374 movl -920(fp),r1
3375 movl -924(fp),r2
3376 addl2 r1,r10
3377 bicl2 #0,r10
3378 cmpl r10,r1
3379 bgequ noname.299
3380 incl r2
3381noname.299:
3382 addl2 r2,r9
3383 bicl2 #0,r9
3384 cmpl r9,r2
3385 bgequ noname.300
3386 incl r8
3387noname.300:
3388
3389 movl r10,56(r11)
3390
3391 movl r9,60(r11)
3392
3393 ret
3394
3395
3396
3397;r=4 ;(AP)
3398;a=8 ;(AP)
3399;b=12 ;(AP)
3400;n=16 ;(AP) n by value (input)
3401
3402 .psect code,nowrt
3403
3404.entry BN_MUL_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
3405 movab -156(sp),sp
3406
3407 clrq r9
3408
3409 clrl r8
3410
3411 movl 8(ap),r6
3412 bicl3 #-65536,(r6),r3
3413 movzwl 2(r6),r2
3414 bicl2 #-65536,r2
3415 movl 12(ap),r7
3416 bicl3 #-65536,(r7),r1
3417 movzwl 2(r7),r0
3418 bicl2 #-65536,r0
3419 movl r3,r5
3420 movl r2,r4
3421 mull3 r0,r5,-4(fp)
3422 mull2 r1,r5
3423 mull3 r1,r4,-8(fp)
3424 mull2 r0,r4
3425 addl3 -4(fp),-8(fp),r0
3426 bicl3 #0,r0,-4(fp)
3427 cmpl -4(fp),-8(fp)
3428 bgequ noname.303
3429 addl2 #65536,r4
3430noname.303:
3431 movzwl -2(fp),r0
3432 bicl2 #-65536,r0
3433 addl2 r0,r4
3434 bicl3 #-65536,-4(fp),r0
3435 ashl #16,r0,-8(fp)
3436 addl2 -8(fp),r5
3437 bicl2 #0,r5
3438 cmpl r5,-8(fp)
3439 bgequ noname.304
3440 incl r4
3441noname.304:
3442 movl r5,r1
3443 movl r4,r2
3444 addl2 r1,r10
3445 bicl2 #0,r10
3446 cmpl r10,r1
3447 bgequ noname.305
3448 incl r2
3449noname.305:
3450 addl2 r2,r9
3451 bicl2 #0,r9
3452 cmpl r9,r2
3453 bgequ noname.306
3454 incl r8
3455noname.306:
3456
3457 movl 4(ap),r11
3458 movl r10,(r11)
3459
3460 clrl r10
3461
3462 bicl3 #-65536,(r6),r3
3463 movzwl 2(r6),r1
3464 bicl2 #-65536,r1
3465 bicl3 #-65536,4(r7),r2
3466 movzwl 6(r7),r0
3467 bicl2 #-65536,r0
3468 movl r3,r5
3469 movl r1,r4
3470 mull3 r0,r5,-12(fp)
3471 mull2 r2,r5
3472 mull3 r2,r4,-16(fp)
3473 mull2 r0,r4
3474 addl3 -12(fp),-16(fp),r0
3475 bicl3 #0,r0,-12(fp)
3476 cmpl -12(fp),-16(fp)
3477 bgequ noname.307
3478 addl2 #65536,r4
3479noname.307:
3480 movzwl -10(fp),r0
3481 bicl2 #-65536,r0
3482 addl2 r0,r4
3483 bicl3 #-65536,-12(fp),r0
3484 ashl #16,r0,-16(fp)
3485 addl2 -16(fp),r5
3486 bicl2 #0,r5
3487 cmpl r5,-16(fp)
3488 bgequ noname.308
3489 incl r4
3490noname.308:
3491 movl r5,r1
3492 movl r4,r2
3493 addl2 r1,r9
3494 bicl2 #0,r9
3495 cmpl r9,r1
3496 bgequ noname.309
3497 incl r2
3498noname.309:
3499 addl2 r2,r8
3500 bicl2 #0,r8
3501 cmpl r8,r2
3502 bgequ noname.310
3503 incl r10
3504noname.310:
3505
3506 bicl3 #-65536,4(r6),r3
3507 movzwl 6(r6),r1
3508 bicl2 #-65536,r1
3509 bicl3 #-65536,(r7),r2
3510 movzwl 2(r7),r0
3511 bicl2 #-65536,r0
3512 movl r3,r5
3513 movl r1,r4
3514 mull3 r0,r5,-20(fp)
3515 mull2 r2,r5
3516 mull3 r2,r4,-24(fp)
3517 mull2 r0,r4
3518 addl3 -20(fp),-24(fp),r0
3519 bicl3 #0,r0,-20(fp)
3520 cmpl -20(fp),-24(fp)
3521 bgequ noname.311
3522 addl2 #65536,r4
3523noname.311:
3524 movzwl -18(fp),r0
3525 bicl2 #-65536,r0
3526 addl2 r0,r4
3527 bicl3 #-65536,-20(fp),r0
3528 ashl #16,r0,-24(fp)
3529 addl2 -24(fp),r5
3530 bicl2 #0,r5
3531 cmpl r5,-24(fp)
3532 bgequ noname.312
3533 incl r4
3534noname.312:
3535 movl r5,r1
3536 movl r4,r2
3537 addl2 r1,r9
3538 bicl2 #0,r9
3539 cmpl r9,r1
3540 bgequ noname.313
3541 incl r2
3542noname.313:
3543 addl2 r2,r8
3544 bicl2 #0,r8
3545 cmpl r8,r2
3546 bgequ noname.314
3547 incl r10
3548noname.314:
3549
3550 movl r9,4(r11)
3551
3552 clrl r9
3553
3554 bicl3 #-65536,8(r6),r3
3555 movzwl 10(r6),r1
3556 bicl2 #-65536,r1
3557 bicl3 #-65536,(r7),r2
3558 movzwl 2(r7),r0
3559 bicl2 #-65536,r0
3560 movl r3,r5
3561 movl r1,r4
3562 mull3 r0,r5,-28(fp)
3563 mull2 r2,r5
3564 mull3 r2,r4,-32(fp)
3565 mull2 r0,r4
3566 addl3 -28(fp),-32(fp),r0
3567 bicl3 #0,r0,-28(fp)
3568 cmpl -28(fp),-32(fp)
3569 bgequ noname.315
3570 addl2 #65536,r4
3571noname.315:
3572 movzwl -26(fp),r0
3573 bicl2 #-65536,r0
3574 addl2 r0,r4
3575 bicl3 #-65536,-28(fp),r0
3576 ashl #16,r0,-32(fp)
3577 addl2 -32(fp),r5
3578 bicl2 #0,r5
3579 cmpl r5,-32(fp)
3580 bgequ noname.316
3581 incl r4
3582noname.316:
3583 movl r5,r1
3584 movl r4,r2
3585 addl2 r1,r8
3586 bicl2 #0,r8
3587 cmpl r8,r1
3588 bgequ noname.317
3589 incl r2
3590noname.317:
3591 addl2 r2,r10
3592 bicl2 #0,r10
3593 cmpl r10,r2
3594 bgequ noname.318
3595 incl r9
3596noname.318:
3597
3598 bicl3 #-65536,4(r6),r3
3599 movzwl 6(r6),r1
3600 bicl2 #-65536,r1
3601 bicl3 #-65536,4(r7),r2
3602 movzwl 6(r7),r0
3603 bicl2 #-65536,r0
3604 movl r3,r5
3605 movl r1,r4
3606 mull3 r0,r5,-36(fp)
3607 mull2 r2,r5
3608 mull3 r2,r4,-40(fp)
3609 mull2 r0,r4
3610 addl3 -36(fp),-40(fp),r0
3611 bicl3 #0,r0,-36(fp)
3612 cmpl -36(fp),-40(fp)
3613 bgequ noname.319
3614 addl2 #65536,r4
3615noname.319:
3616 movzwl -34(fp),r0
3617 bicl2 #-65536,r0
3618 addl2 r0,r4
3619 bicl3 #-65536,-36(fp),r0
3620 ashl #16,r0,-40(fp)
3621 addl2 -40(fp),r5
3622 bicl2 #0,r5
3623 cmpl r5,-40(fp)
3624 bgequ noname.320
3625 incl r4
3626noname.320:
3627 movl r5,r1
3628 movl r4,r2
3629 addl2 r1,r8
3630 bicl2 #0,r8
3631 cmpl r8,r1
3632 bgequ noname.321
3633 incl r2
3634noname.321:
3635 addl2 r2,r10
3636 bicl2 #0,r10
3637 cmpl r10,r2
3638 bgequ noname.322
3639 incl r9
3640noname.322:
3641
3642 bicl3 #-65536,(r6),r3
3643 movzwl 2(r6),r1
3644 bicl2 #-65536,r1
3645 bicl3 #-65536,8(r7),r2
3646 movzwl 10(r7),r0
3647 bicl2 #-65536,r0
3648 movl r3,r5
3649 movl r1,r4
3650 mull3 r0,r5,-44(fp)
3651 mull2 r2,r5
3652 mull3 r2,r4,-48(fp)
3653 mull2 r0,r4
3654 addl3 -44(fp),-48(fp),r0
3655 bicl3 #0,r0,-44(fp)
3656 cmpl -44(fp),-48(fp)
3657 bgequ noname.323
3658 addl2 #65536,r4
3659noname.323:
3660 movzwl -42(fp),r0
3661 bicl2 #-65536,r0
3662 addl2 r0,r4
3663 bicl3 #-65536,-44(fp),r0
3664 ashl #16,r0,-48(fp)
3665 addl2 -48(fp),r5
3666 bicl2 #0,r5
3667 cmpl r5,-48(fp)
3668 bgequ noname.324
3669 incl r4
3670noname.324:
3671 movl r5,r1
3672 movl r4,r2
3673 addl2 r1,r8
3674 bicl2 #0,r8
3675 cmpl r8,r1
3676 bgequ noname.325
3677 incl r2
3678noname.325:
3679 addl2 r2,r10
3680 bicl2 #0,r10
3681 cmpl r10,r2
3682 bgequ noname.326
3683 incl r9
3684noname.326:
3685
3686 movl r8,8(r11)
3687
3688 clrl r8
3689
3690 bicl3 #-65536,(r6),r3
3691 movzwl 2(r6),r2
3692 bicl3 #-65536,12(r7),r1
3693 movzwl 14(r7),r0
3694 bicl2 #-65536,r0
3695 movl r3,r4
3696 bicl3 #-65536,r2,-60(fp)
3697 mull3 r0,r4,-52(fp)
3698 mull2 r1,r4
3699 mull3 r1,-60(fp),-56(fp)
3700 mull2 r0,-60(fp)
3701 addl3 -52(fp),-56(fp),r0
3702 bicl3 #0,r0,-52(fp)
3703 cmpl -52(fp),-56(fp)
3704 bgequ noname.327
3705 addl2 #65536,-60(fp)
3706noname.327:
3707 movzwl -50(fp),r0
3708 bicl2 #-65536,r0
3709 addl2 r0,-60(fp)
3710 bicl3 #-65536,-52(fp),r0
3711 ashl #16,r0,-56(fp)
3712 addl2 -56(fp),r4
3713 bicl2 #0,r4
3714 cmpl r4,-56(fp)
3715 bgequ noname.328
3716 incl -60(fp)
3717noname.328:
3718 movl r4,r1
3719 movl -60(fp),r2
3720 addl2 r1,r10
3721 bicl2 #0,r10
3722 cmpl r10,r1
3723 bgequ noname.329
3724 incl r2
3725noname.329:
3726 addl2 r2,r9
3727 bicl2 #0,r9
3728 cmpl r9,r2
3729 bgequ noname.330
3730 incl r8
3731noname.330:
3732
3733 movzwl 6(r6),r2
3734 bicl3 #-65536,8(r7),r3
3735 movzwl 10(r7),r0
3736 bicl2 #-65536,r0
3737 bicl3 #-65536,4(r6),-72(fp)
3738 bicl3 #-65536,r2,-76(fp)
3739 mull3 r0,-72(fp),-64(fp)
3740 mull2 r3,-72(fp)
3741 mull3 r3,-76(fp),-68(fp)
3742 mull2 r0,-76(fp)
3743 addl3 -64(fp),-68(fp),r0
3744 bicl3 #0,r0,-64(fp)
3745 cmpl -64(fp),-68(fp)
3746 bgequ noname.331
3747 addl2 #65536,-76(fp)
3748noname.331:
3749 movzwl -62(fp),r0
3750 bicl2 #-65536,r0
3751 addl2 r0,-76(fp)
3752 bicl3 #-65536,-64(fp),r0
3753 ashl #16,r0,-68(fp)
3754 addl3 -68(fp),-72(fp),r0
3755 bicl3 #0,r0,-72(fp)
3756 cmpl -72(fp),-68(fp)
3757 bgequ noname.332
3758 incl -76(fp)
3759noname.332:
3760 movl -72(fp),r1
3761 movl -76(fp),r2
3762 addl2 r1,r10
3763 bicl2 #0,r10
3764 cmpl r10,r1
3765 bgequ noname.333
3766 incl r2
3767noname.333:
3768 addl2 r2,r9
3769 bicl2 #0,r9
3770 cmpl r9,r2
3771 bgequ noname.334
3772 incl r8
3773noname.334:
3774
3775 bicl3 #-65536,8(r6),r3
3776 movzwl 10(r6),r1
3777 bicl2 #-65536,r1
3778 bicl3 #-65536,4(r7),r2
3779 movzwl 6(r7),r0
3780 bicl2 #-65536,r0
3781 movl r3,r5
3782 movl r1,r4
3783 mull3 r0,r5,-80(fp)
3784 mull2 r2,r5
3785 mull3 r2,r4,-84(fp)
3786 mull2 r0,r4
3787 addl3 -80(fp),-84(fp),r0
3788 bicl3 #0,r0,-80(fp)
3789 cmpl -80(fp),-84(fp)
3790 bgequ noname.335
3791 addl2 #65536,r4
3792noname.335:
3793 movzwl -78(fp),r0
3794 bicl2 #-65536,r0
3795 addl2 r0,r4
3796 bicl3 #-65536,-80(fp),r0
3797 ashl #16,r0,-84(fp)
3798 addl2 -84(fp),r5
3799 bicl2 #0,r5
3800 cmpl r5,-84(fp)
3801 bgequ noname.336
3802 incl r4
3803noname.336:
3804 movl r5,r1
3805 movl r4,r2
3806 addl2 r1,r10
3807 bicl2 #0,r10
3808 cmpl r10,r1
3809 bgequ noname.337
3810 incl r2
3811noname.337:
3812 addl2 r2,r9
3813 bicl2 #0,r9
3814 cmpl r9,r2
3815 bgequ noname.338
3816 incl r8
3817noname.338:
3818
3819 bicl3 #-65536,12(r6),r3
3820 movzwl 14(r6),r1
3821 bicl2 #-65536,r1
3822 bicl3 #-65536,(r7),r2
3823 movzwl 2(r7),r0
3824 bicl2 #-65536,r0
3825 movl r3,r5
3826 movl r1,r4
3827 mull3 r0,r5,-88(fp)
3828 mull2 r2,r5
3829 mull3 r2,r4,-92(fp)
3830 mull2 r0,r4
3831 addl3 -88(fp),-92(fp),r0
3832 bicl3 #0,r0,-88(fp)
3833 cmpl -88(fp),-92(fp)
3834 bgequ noname.339
3835 addl2 #65536,r4
3836noname.339:
3837 movzwl -86(fp),r0
3838 bicl2 #-65536,r0
3839 addl2 r0,r4
3840 bicl3 #-65536,-88(fp),r0
3841 ashl #16,r0,-92(fp)
3842 addl2 -92(fp),r5
3843 bicl2 #0,r5
3844 cmpl r5,-92(fp)
3845 bgequ noname.340
3846 incl r4
3847noname.340:
3848 movl r5,r1
3849 movl r4,r2
3850 addl2 r1,r10
3851 bicl2 #0,r10
3852 cmpl r10,r1
3853 bgequ noname.341
3854 incl r2
3855noname.341:
3856 addl2 r2,r9
3857 bicl2 #0,r9
3858 cmpl r9,r2
3859 bgequ noname.342
3860 incl r8
3861noname.342:
3862
3863 movl r10,12(r11)
3864
3865 clrl r10
3866
3867 bicl3 #-65536,12(r6),r3
3868 movzwl 14(r6),r1
3869 bicl2 #-65536,r1
3870 bicl3 #-65536,4(r7),r2
3871 movzwl 6(r7),r0
3872 bicl2 #-65536,r0
3873 movl r3,r5
3874 movl r1,r4
3875 mull3 r0,r5,-96(fp)
3876 mull2 r2,r5
3877 mull3 r2,r4,-100(fp)
3878 mull2 r0,r4
3879 addl3 -96(fp),-100(fp),r0
3880 bicl3 #0,r0,-96(fp)
3881 cmpl -96(fp),-100(fp)
3882 bgequ noname.343
3883 addl2 #65536,r4
3884noname.343:
3885 movzwl -94(fp),r0
3886 bicl2 #-65536,r0
3887 addl2 r0,r4
3888 bicl3 #-65536,-96(fp),r0
3889 ashl #16,r0,-100(fp)
3890 addl2 -100(fp),r5
3891 bicl2 #0,r5
3892 cmpl r5,-100(fp)
3893 bgequ noname.344
3894 incl r4
3895noname.344:
3896 movl r5,r1
3897 movl r4,r2
3898 addl2 r1,r9
3899 bicl2 #0,r9
3900 cmpl r9,r1
3901 bgequ noname.345
3902 incl r2
3903noname.345:
3904 addl2 r2,r8
3905 bicl2 #0,r8
3906 cmpl r8,r2
3907 bgequ noname.346
3908 incl r10
3909noname.346:
3910
3911 bicl3 #-65536,8(r6),r3
3912 movzwl 10(r6),r1
3913 bicl2 #-65536,r1
3914 bicl3 #-65536,8(r7),r2
3915 movzwl 10(r7),r0
3916 bicl2 #-65536,r0
3917 movl r3,r5
3918 movl r1,r4
3919 mull3 r0,r5,-104(fp)
3920 mull2 r2,r5
3921 mull3 r2,r4,-108(fp)
3922 mull2 r0,r4
3923 addl3 -104(fp),-108(fp),r0
3924 bicl3 #0,r0,-104(fp)
3925 cmpl -104(fp),-108(fp)
3926 bgequ noname.347
3927 addl2 #65536,r4
3928noname.347:
3929 movzwl -102(fp),r0
3930 bicl2 #-65536,r0
3931 addl2 r0,r4
3932 bicl3 #-65536,-104(fp),r0
3933 ashl #16,r0,-108(fp)
3934 addl2 -108(fp),r5
3935 bicl2 #0,r5
3936 cmpl r5,-108(fp)
3937 bgequ noname.348
3938 incl r4
3939noname.348:
3940 movl r5,r1
3941 movl r4,r2
3942 addl2 r1,r9
3943 bicl2 #0,r9
3944 cmpl r9,r1
3945 bgequ noname.349
3946 incl r2
3947noname.349:
3948 addl2 r2,r8
3949 bicl2 #0,r8
3950 cmpl r8,r2
3951 bgequ noname.350
3952 incl r10
3953noname.350:
3954
3955 bicl3 #-65536,4(r6),r3
3956 movzwl 6(r6),r1
3957 bicl2 #-65536,r1
3958 bicl3 #-65536,12(r7),r2
3959 movzwl 14(r7),r0
3960 bicl2 #-65536,r0
3961 movl r3,r5
3962 movl r1,r4
3963 mull3 r0,r5,-112(fp)
3964 mull2 r2,r5
3965 mull3 r2,r4,-116(fp)
3966 mull2 r0,r4
3967 addl3 -112(fp),-116(fp),r0
3968 bicl3 #0,r0,-112(fp)
3969 cmpl -112(fp),-116(fp)
3970 bgequ noname.351
3971 addl2 #65536,r4
3972noname.351:
3973 movzwl -110(fp),r0
3974 bicl2 #-65536,r0
3975 addl2 r0,r4
3976 bicl3 #-65536,-112(fp),r0
3977 ashl #16,r0,-116(fp)
3978 addl2 -116(fp),r5
3979 bicl2 #0,r5
3980 cmpl r5,-116(fp)
3981 bgequ noname.352
3982 incl r4
3983noname.352:
3984 movl r5,r1
3985 movl r4,r2
3986 addl2 r1,r9
3987 bicl2 #0,r9
3988 cmpl r9,r1
3989 bgequ noname.353
3990 incl r2
3991noname.353:
3992 addl2 r2,r8
3993 bicl2 #0,r8
3994 cmpl r8,r2
3995 bgequ noname.354
3996 incl r10
3997noname.354:
3998
3999 movl r9,16(r11)
4000
4001 clrl r9
4002
4003 bicl3 #-65536,8(r6),r3
4004 movzwl 10(r6),r1
4005 bicl2 #-65536,r1
4006 bicl3 #-65536,12(r7),r2
4007 movzwl 14(r7),r0
4008 bicl2 #-65536,r0
4009 movl r3,r5
4010 movl r1,r4
4011 mull3 r0,r5,-120(fp)
4012 mull2 r2,r5
4013 mull3 r2,r4,-124(fp)
4014 mull2 r0,r4
4015 addl3 -120(fp),-124(fp),r0
4016 bicl3 #0,r0,-120(fp)
4017 cmpl -120(fp),-124(fp)
4018 bgequ noname.355
4019 addl2 #65536,r4
4020noname.355:
4021 movzwl -118(fp),r0
4022 bicl2 #-65536,r0
4023 addl2 r0,r4
4024 bicl3 #-65536,-120(fp),r0
4025 ashl #16,r0,-124(fp)
4026 addl2 -124(fp),r5
4027 bicl2 #0,r5
4028 cmpl r5,-124(fp)
4029 bgequ noname.356
4030 incl r4
4031noname.356:
4032 movl r5,r1
4033 movl r4,r2
4034 addl2 r1,r8
4035 bicl2 #0,r8
4036 cmpl r8,r1
4037 bgequ noname.357
4038 incl r2
4039noname.357:
4040 addl2 r2,r10
4041 bicl2 #0,r10
4042 cmpl r10,r2
4043 bgequ noname.358
4044 incl r9
4045noname.358:
4046
4047 movzwl 14(r6),r2
4048 bicl3 #-65536,8(r7),r3
4049 movzwl 10(r7),r0
4050 bicl2 #-65536,r0
4051 bicl3 #-65536,12(r6),-136(fp)
4052 bicl3 #-65536,r2,-140(fp)
4053 mull3 r0,-136(fp),-128(fp)
4054 mull2 r3,-136(fp)
4055 mull3 r3,-140(fp),-132(fp)
4056 mull2 r0,-140(fp)
4057 addl3 -128(fp),-132(fp),r0
4058 bicl3 #0,r0,-128(fp)
4059 cmpl -128(fp),-132(fp)
4060 bgequ noname.359
4061 addl2 #65536,-140(fp)
4062noname.359:
4063 movzwl -126(fp),r0
4064 bicl2 #-65536,r0
4065 addl2 r0,-140(fp)
4066 bicl3 #-65536,-128(fp),r0
4067 ashl #16,r0,-132(fp)
4068 addl3 -132(fp),-136(fp),r0
4069 bicl3 #0,r0,-136(fp)
4070 cmpl -136(fp),-132(fp)
4071 bgequ noname.360
4072 incl -140(fp)
4073noname.360:
4074 movl -136(fp),r1
4075 movl -140(fp),r2
4076 addl2 r1,r8
4077 bicl2 #0,r8
4078 cmpl r8,r1
4079 bgequ noname.361
4080 incl r2
4081noname.361:
4082 addl2 r2,r10
4083 bicl2 #0,r10
4084 cmpl r10,r2
4085 bgequ noname.362
4086 incl r9
4087noname.362:
4088
4089 movl r8,20(r11)
4090
4091 clrl r8
4092
4093 movzwl 14(r6),r2
4094 bicl3 #-65536,12(r7),r3
4095 movzwl 14(r7),r0
4096 bicl2 #-65536,r0
4097 bicl3 #-65536,12(r6),-152(fp)
4098 bicl3 #-65536,r2,-156(fp)
4099 mull3 r0,-152(fp),-144(fp)
4100 mull2 r3,-152(fp)
4101 mull3 r3,-156(fp),-148(fp)
4102 mull2 r0,-156(fp)
4103 addl3 -144(fp),-148(fp),r0
4104 bicl3 #0,r0,-144(fp)
4105 cmpl -144(fp),-148(fp)
4106 bgequ noname.363
4107 addl2 #65536,-156(fp)
4108noname.363:
4109 movzwl -142(fp),r0
4110 bicl2 #-65536,r0
4111 addl2 r0,-156(fp)
4112 bicl3 #-65536,-144(fp),r0
4113 ashl #16,r0,-148(fp)
4114 addl3 -148(fp),-152(fp),r0
4115 bicl3 #0,r0,-152(fp)
4116 cmpl -152(fp),-148(fp)
4117 bgequ noname.364
4118 incl -156(fp)
4119noname.364:
4120 movl -152(fp),r1
4121 movl -156(fp),r2
4122 addl2 r1,r10
4123 bicl2 #0,r10
4124 cmpl r10,r1
4125 bgequ noname.365
4126 incl r2
4127noname.365:
4128 addl2 r2,r9
4129 bicl2 #0,r9
4130 cmpl r9,r2
4131 bgequ noname.366
4132 incl r8
4133noname.366:
4134
4135 movl r10,24(r11)
4136
4137 movl r9,28(r11)
4138
4139 ret
4140
4141
4142
4143;r=4 ;(AP)
4144;a=8 ;(AP)
4145;b=12 ;(AP)
4146;n=16 ;(AP) n by value (input)
4147
4148 .psect code,nowrt
4149
4150.entry BN_SQR_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9>
4151 movab -444(sp),sp
4152
4153 clrq r8
4154
4155 clrl r7
4156
4157 movl 8(ap),r4
4158 movl (r4),r3
4159 bicl3 #-65536,r3,-4(fp)
4160 extzv #16,#16,r3,r0
4161 bicl3 #-65536,r0,r3
4162 movl -4(fp),r0
4163 mull3 r0,r3,-8(fp)
4164 mull3 r0,r0,-4(fp)
4165 mull2 r3,r3
4166 bicl3 #32767,-8(fp),r0
4167 extzv #15,#17,r0,r0
4168 addl2 r0,r3
4169 bicl3 #-65536,-8(fp),r0
4170 ashl #17,r0,-8(fp)
4171 addl3 -4(fp),-8(fp),r0
4172 bicl3 #0,r0,-4(fp)
4173 cmpl -4(fp),-8(fp)
4174 bgequ noname.369
4175 incl r3
4176noname.369:
4177 movl -4(fp),r1
4178 movl r3,r2
4179 addl2 r1,r9
4180 bicl2 #0,r9
4181 cmpl r9,r1
4182 bgequ noname.370
4183 incl r2
4184noname.370:
4185 addl2 r2,r8
4186 bicl2 #0,r8
4187 cmpl r8,r2
4188 bgequ noname.371
4189 incl r7
4190noname.371:
4191
4192 movl r9,@4(ap)
4193
4194 clrl r9
4195
4196 movzwl 6(r4),r2
4197 bicl3 #-65536,(r4),r3
4198 movzwl 2(r4),r0
4199 bicl2 #-65536,r0
4200 bicl3 #-65536,4(r4),-20(fp)
4201 bicl3 #-65536,r2,-24(fp)
4202 mull3 r0,-20(fp),-12(fp)
4203 mull2 r3,-20(fp)
4204 mull3 r3,-24(fp),-16(fp)
4205 mull2 r0,-24(fp)
4206 addl3 -12(fp),-16(fp),r0
4207 bicl3 #0,r0,-12(fp)
4208 cmpl -12(fp),-16(fp)
4209 bgequ noname.372
4210 addl2 #65536,-24(fp)
4211noname.372:
4212 movzwl -10(fp),r0
4213 bicl2 #-65536,r0
4214 addl2 r0,-24(fp)
4215 bicl3 #-65536,-12(fp),r0
4216 ashl #16,r0,-16(fp)
4217 addl3 -16(fp),-20(fp),r0
4218 bicl3 #0,r0,-20(fp)
4219 cmpl -20(fp),-16(fp)
4220 bgequ noname.373
4221 incl -24(fp)
4222noname.373:
4223 movl -20(fp),r3
4224 movl -24(fp),r2
4225 bbc #31,r2,noname.374
4226 incl r9
4227noname.374:
4228 addl2 r2,r2
4229 bicl2 #0,r2
4230 bbc #31,r3,noname.375
4231 incl r2
4232noname.375:
4233 addl2 r3,r3
4234 bicl2 #0,r3
4235 addl2 r3,r8
4236 bicl2 #0,r8
4237 cmpl r8,r3
4238 bgequ noname.376
4239 incl r2
4240 bicl3 #0,r2,r0
4241 bneq noname.376
4242 incl r9
4243noname.376:
4244 addl2 r2,r7
4245 bicl2 #0,r7
4246 cmpl r7,r2
4247 bgequ noname.377
4248 incl r9
4249noname.377:
4250
4251 movl 4(ap),r0
4252 movl r8,4(r0)
4253
4254 clrl r8
4255
4256 movl 8(ap),r4
4257 movl 4(r4),r3
4258 bicl3 #-65536,r3,-28(fp)
4259 extzv #16,#16,r3,r0
4260 bicl3 #-65536,r0,r3
4261 movl -28(fp),r0
4262 mull3 r0,r3,-32(fp)
4263 mull3 r0,r0,-28(fp)
4264 mull2 r3,r3
4265 bicl3 #32767,-32(fp),r0
4266 extzv #15,#17,r0,r0
4267 addl2 r0,r3
4268 bicl3 #-65536,-32(fp),r0
4269 ashl #17,r0,-32(fp)
4270 addl3 -28(fp),-32(fp),r0
4271 bicl3 #0,r0,-28(fp)
4272 cmpl -28(fp),-32(fp)
4273 bgequ noname.378
4274 incl r3
4275noname.378:
4276 movl -28(fp),r1
4277 movl r3,r2
4278 addl2 r1,r7
4279 bicl2 #0,r7
4280 cmpl r7,r1
4281 bgequ noname.379
4282 incl r2
4283noname.379:
4284 addl2 r2,r9
4285 bicl2 #0,r9
4286 cmpl r9,r2
4287 bgequ noname.380
4288 incl r8
4289noname.380:
4290
4291 movzwl 10(r4),r2
4292 bicl3 #-65536,(r4),r3
4293 movzwl 2(r4),r0
4294 bicl2 #-65536,r0
4295 bicl3 #-65536,8(r4),-44(fp)
4296 bicl3 #-65536,r2,-48(fp)
4297 mull3 r0,-44(fp),-36(fp)
4298 mull2 r3,-44(fp)
4299 mull3 r3,-48(fp),-40(fp)
4300 mull2 r0,-48(fp)
4301 addl3 -36(fp),-40(fp),r0
4302 bicl3 #0,r0,-36(fp)
4303 cmpl -36(fp),-40(fp)
4304 bgequ noname.381
4305 addl2 #65536,-48(fp)
4306noname.381:
4307 movzwl -34(fp),r0
4308 bicl2 #-65536,r0
4309 addl2 r0,-48(fp)
4310 bicl3 #-65536,-36(fp),r0
4311 ashl #16,r0,-40(fp)
4312 addl3 -40(fp),-44(fp),r0
4313 bicl3 #0,r0,-44(fp)
4314 cmpl -44(fp),-40(fp)
4315 bgequ noname.382
4316 incl -48(fp)
4317noname.382:
4318 movl -44(fp),r3
4319 movl -48(fp),r2
4320 bbc #31,r2,noname.383
4321 incl r8
4322noname.383:
4323 addl2 r2,r2
4324 bicl2 #0,r2
4325 bbc #31,r3,noname.384
4326 incl r2
4327noname.384:
4328 addl2 r3,r3
4329 bicl2 #0,r3
4330 addl2 r3,r7
4331 bicl2 #0,r7
4332 cmpl r7,r3
4333 bgequ noname.385
4334 incl r2
4335 bicl3 #0,r2,r0
4336 bneq noname.385
4337 incl r8
4338noname.385:
4339 addl2 r2,r9
4340 bicl2 #0,r9
4341 cmpl r9,r2
4342 bgequ noname.386
4343 incl r8
4344noname.386:
4345
4346 movl 4(ap),r0
4347 movl r7,8(r0)
4348
4349 clrl r7
4350
4351 movl 8(ap),r0
4352 movzwl 14(r0),r2
4353 bicl3 #-65536,(r0),r3
4354 movzwl 2(r0),r1
4355 bicl2 #-65536,r1
4356 bicl3 #-65536,12(r0),-60(fp)
4357 bicl3 #-65536,r2,-64(fp)
4358 mull3 r1,-60(fp),-52(fp)
4359 mull2 r3,-60(fp)
4360 mull3 r3,-64(fp),-56(fp)
4361 mull2 r1,-64(fp)
4362 addl3 -52(fp),-56(fp),r0
4363 bicl3 #0,r0,-52(fp)
4364 cmpl -52(fp),-56(fp)
4365 bgequ noname.387
4366 addl2 #65536,-64(fp)
4367noname.387:
4368 movzwl -50(fp),r0
4369 bicl2 #-65536,r0
4370 addl2 r0,-64(fp)
4371 bicl3 #-65536,-52(fp),r0
4372 ashl #16,r0,-56(fp)
4373 addl3 -56(fp),-60(fp),r0
4374 bicl3 #0,r0,-60(fp)
4375 cmpl -60(fp),-56(fp)
4376 bgequ noname.388
4377 incl -64(fp)
4378noname.388:
4379 movl -60(fp),r3
4380 movl -64(fp),r2
4381 bbc #31,r2,noname.389
4382 incl r7
4383noname.389:
4384 addl2 r2,r2
4385 bicl2 #0,r2
4386 bbc #31,r3,noname.390
4387 incl r2
4388noname.390:
4389 addl2 r3,r3
4390 bicl2 #0,r3
4391 addl2 r3,r9
4392 bicl2 #0,r9
4393 cmpl r9,r3
4394 bgequ noname.391
4395 incl r2
4396 bicl3 #0,r2,r0
4397 bneq noname.391
4398 incl r7
4399noname.391:
4400 addl2 r2,r8
4401 bicl2 #0,r8
4402 cmpl r8,r2
4403 bgequ noname.392
4404 incl r7
4405noname.392:
4406
4407 movl 8(ap),r0
4408 movzwl 10(r0),r2
4409 bicl3 #-65536,4(r0),r3
4410 movzwl 6(r0),r1
4411 bicl2 #-65536,r1
4412 bicl3 #-65536,8(r0),-76(fp)
4413 bicl3 #-65536,r2,-80(fp)
4414 mull3 r1,-76(fp),-68(fp)
4415 mull2 r3,-76(fp)
4416 mull3 r3,-80(fp),-72(fp)
4417 mull2 r1,-80(fp)
4418 addl3 -68(fp),-72(fp),r0
4419 bicl3 #0,r0,-68(fp)
4420 cmpl -68(fp),-72(fp)
4421 bgequ noname.393
4422 addl2 #65536,-80(fp)
4423noname.393:
4424 movzwl -66(fp),r0
4425 bicl2 #-65536,r0
4426 addl2 r0,-80(fp)
4427 bicl3 #-65536,-68(fp),r0
4428 ashl #16,r0,-72(fp)
4429 addl3 -72(fp),-76(fp),r0
4430 bicl3 #0,r0,-76(fp)
4431 cmpl -76(fp),-72(fp)
4432 bgequ noname.394
4433 incl -80(fp)
4434noname.394:
4435 movl -76(fp),r3
4436 movl -80(fp),r2
4437 bbc #31,r2,noname.395
4438 incl r7
4439noname.395:
4440 addl2 r2,r2
4441 bicl2 #0,r2
4442 bbc #31,r3,noname.396
4443 incl r2
4444noname.396:
4445 addl2 r3,r3
4446 bicl2 #0,r3
4447 addl2 r3,r9
4448 bicl2 #0,r9
4449 cmpl r9,r3
4450 bgequ noname.397
4451 incl r2
4452 bicl3 #0,r2,r0
4453 bneq noname.397
4454 incl r7
4455noname.397:
4456 addl2 r2,r8
4457 bicl2 #0,r8
4458 cmpl r8,r2
4459 bgequ noname.398
4460 incl r7
4461noname.398:
4462
4463 movl 4(ap),r0
4464 movl r9,12(r0)
4465
4466 clrl r9
4467
4468 movl 8(ap),r2
4469 movl 8(r2),r4
4470 bicl3 #-65536,r4,-84(fp)
4471 extzv #16,#16,r4,r0
4472 bicl3 #-65536,r0,r4
4473 movl -84(fp),r0
4474 mull3 r0,r4,-88(fp)
4475 mull3 r0,r0,-84(fp)
4476 mull2 r4,r4
4477 bicl3 #32767,-88(fp),r0
4478 extzv #15,#17,r0,r0
4479 addl2 r0,r4
4480 bicl3 #-65536,-88(fp),r0
4481 ashl #17,r0,-88(fp)
4482 addl3 -84(fp),-88(fp),r0
4483 bicl3 #0,r0,-84(fp)
4484 cmpl -84(fp),-88(fp)
4485 bgequ noname.399
4486 incl r4
4487noname.399:
4488 movl -84(fp),r1
4489 movl r4,r3
4490 addl2 r1,r8
4491 bicl2 #0,r8
4492 cmpl r8,r1
4493 bgequ noname.400
4494 incl r3
4495noname.400:
4496 addl2 r3,r7
4497 bicl2 #0,r7
4498 cmpl r7,r3
4499 bgequ noname.401
4500 incl r9
4501noname.401:
4502
4503 movzwl 14(r2),r3
4504 bicl3 #-65536,4(r2),r1
4505 movzwl 6(r2),r0
4506 bicl2 #-65536,r0
4507 bicl3 #-65536,12(r2),-100(fp)
4508 bicl3 #-65536,r3,-104(fp)
4509 mull3 r0,-100(fp),-92(fp)
4510 mull2 r1,-100(fp)
4511 mull3 r1,-104(fp),-96(fp)
4512 mull2 r0,-104(fp)
4513 addl3 -92(fp),-96(fp),r0
4514 bicl3 #0,r0,-92(fp)
4515 cmpl -92(fp),-96(fp)
4516 bgequ noname.402
4517 addl2 #65536,-104(fp)
4518noname.402:
4519 movzwl -90(fp),r0
4520 bicl2 #-65536,r0
4521 addl2 r0,-104(fp)
4522 bicl3 #-65536,-92(fp),r0
4523 ashl #16,r0,-96(fp)
4524 addl3 -96(fp),-100(fp),r0
4525 bicl3 #0,r0,-100(fp)
4526 cmpl -100(fp),-96(fp)
4527 bgequ noname.403
4528 incl -104(fp)
4529noname.403:
4530 movl -100(fp),r3
4531 movl -104(fp),r2
4532 bbc #31,r2,noname.404
4533 incl r9
4534noname.404:
4535 addl2 r2,r2
4536 bicl2 #0,r2
4537 bbc #31,r3,noname.405
4538 incl r2
4539noname.405:
4540 addl2 r3,r3
4541 bicl2 #0,r3
4542 addl2 r3,r8
4543 bicl2 #0,r8
4544 cmpl r8,r3
4545 bgequ noname.406
4546 incl r2
4547 bicl3 #0,r2,r0
4548 bneq noname.406
4549 incl r9
4550noname.406:
4551 addl2 r2,r7
4552 bicl2 #0,r7
4553 cmpl r7,r2
4554 bgequ noname.407
4555 incl r9
4556noname.407:
4557
4558 movl 8(ap),r0
4559 movzwl 18(r0),r2
4560 bicl3 #-65536,(r0),r3
4561 movzwl 2(r0),r1
4562 bicl2 #-65536,r1
4563 bicl3 #-65536,16(r0),-116(fp)
4564 bicl3 #-65536,r2,-120(fp)
4565 mull3 r1,-116(fp),-108(fp)
4566 mull2 r3,-116(fp)
4567 mull3 r3,-120(fp),-112(fp)
4568 mull2 r1,-120(fp)
4569 addl3 -108(fp),-112(fp),r0
4570 bicl3 #0,r0,-108(fp)
4571 cmpl -108(fp),-112(fp)
4572 bgequ noname.408
4573 addl2 #65536,-120(fp)
4574noname.408:
4575 movzwl -106(fp),r0
4576 bicl2 #-65536,r0
4577 addl2 r0,-120(fp)
4578 bicl3 #-65536,-108(fp),r0
4579 ashl #16,r0,-112(fp)
4580 addl3 -112(fp),-116(fp),r0
4581 bicl3 #0,r0,-116(fp)
4582 cmpl -116(fp),-112(fp)
4583 bgequ noname.409
4584 incl -120(fp)
4585noname.409:
4586 movl -116(fp),r3
4587 movl -120(fp),r2
4588 bbc #31,r2,noname.410
4589 incl r9
4590noname.410:
4591 addl2 r2,r2
4592 bicl2 #0,r2
4593 bbc #31,r3,noname.411
4594 incl r2
4595noname.411:
4596 addl2 r3,r3
4597 bicl2 #0,r3
4598 addl2 r3,r8
4599 bicl2 #0,r8
4600 cmpl r8,r3
4601 bgequ noname.412
4602 incl r2
4603 bicl3 #0,r2,r0
4604 bneq noname.412
4605 incl r9
4606noname.412:
4607 addl2 r2,r7
4608 bicl2 #0,r7
4609 cmpl r7,r2
4610 bgequ noname.413
4611 incl r9
4612noname.413:
4613
4614 movl 4(ap),r0
4615 movl r8,16(r0)
4616
4617 clrl r8
4618
4619 movl 8(ap),r0
4620 movzwl 22(r0),r2
4621 bicl3 #-65536,(r0),r3
4622 movzwl 2(r0),r1
4623 bicl2 #-65536,r1
4624 bicl3 #-65536,20(r0),-132(fp)
4625 bicl3 #-65536,r2,-136(fp)
4626 mull3 r1,-132(fp),-124(fp)
4627 mull2 r3,-132(fp)
4628 mull3 r3,-136(fp),-128(fp)
4629 mull2 r1,-136(fp)
4630 addl3 -124(fp),-128(fp),r0
4631 bicl3 #0,r0,-124(fp)
4632 cmpl -124(fp),-128(fp)
4633 bgequ noname.414
4634 addl2 #65536,-136(fp)
4635noname.414:
4636 movzwl -122(fp),r0
4637 bicl2 #-65536,r0
4638 addl2 r0,-136(fp)
4639 bicl3 #-65536,-124(fp),r0
4640 ashl #16,r0,-128(fp)
4641 addl3 -128(fp),-132(fp),r0
4642 bicl3 #0,r0,-132(fp)
4643 cmpl -132(fp),-128(fp)
4644 bgequ noname.415
4645 incl -136(fp)
4646noname.415:
4647 movl -132(fp),r3
4648 movl -136(fp),r2
4649 bbc #31,r2,noname.416
4650 incl r8
4651noname.416:
4652 addl2 r2,r2
4653 bicl2 #0,r2
4654 bbc #31,r3,noname.417
4655 incl r2
4656noname.417:
4657 addl2 r3,r3
4658 bicl2 #0,r3
4659 addl2 r3,r7
4660 bicl2 #0,r7
4661 cmpl r7,r3
4662 bgequ noname.418
4663 incl r2
4664 bicl3 #0,r2,r0
4665 bneq noname.418
4666 incl r8
4667noname.418:
4668 addl2 r2,r9
4669 bicl2 #0,r9
4670 cmpl r9,r2
4671 bgequ noname.419
4672 incl r8
4673noname.419:
4674
4675 movl 8(ap),r0
4676 movzwl 18(r0),r2
4677 bicl3 #-65536,4(r0),r3
4678 movzwl 6(r0),r1
4679 bicl2 #-65536,r1
4680 bicl3 #-65536,16(r0),-148(fp)
4681 bicl3 #-65536,r2,-152(fp)
4682 mull3 r1,-148(fp),-140(fp)
4683 mull2 r3,-148(fp)
4684 mull3 r3,-152(fp),-144(fp)
4685 mull2 r1,-152(fp)
4686 addl3 -140(fp),-144(fp),r0
4687 bicl3 #0,r0,-140(fp)
4688 cmpl -140(fp),-144(fp)
4689 bgequ noname.420
4690 addl2 #65536,-152(fp)
4691noname.420:
4692 movzwl -138(fp),r0
4693 bicl2 #-65536,r0
4694 addl2 r0,-152(fp)
4695 bicl3 #-65536,-140(fp),r0
4696 ashl #16,r0,-144(fp)
4697 addl3 -144(fp),-148(fp),r0
4698 bicl3 #0,r0,-148(fp)
4699 cmpl -148(fp),-144(fp)
4700 bgequ noname.421
4701 incl -152(fp)
4702noname.421:
4703 movl -148(fp),r3
4704 movl -152(fp),r2
4705 bbc #31,r2,noname.422
4706 incl r8
4707noname.422:
4708 addl2 r2,r2
4709 bicl2 #0,r2
4710 bbc #31,r3,noname.423
4711 incl r2
4712noname.423:
4713 addl2 r3,r3
4714 bicl2 #0,r3
4715 addl2 r3,r7
4716 bicl2 #0,r7
4717 cmpl r7,r3
4718 bgequ noname.424
4719 incl r2
4720 bicl3 #0,r2,r0
4721 bneq noname.424
4722 incl r8
4723noname.424:
4724 addl2 r2,r9
4725 bicl2 #0,r9
4726 cmpl r9,r2
4727 bgequ noname.425
4728 incl r8
4729noname.425:
4730
4731 movl 8(ap),r0
4732 movzwl 14(r0),r2
4733 bicl3 #-65536,8(r0),r3
4734 movzwl 10(r0),r1
4735 bicl2 #-65536,r1
4736 bicl3 #-65536,12(r0),-164(fp)
4737 bicl3 #-65536,r2,-168(fp)
4738 mull3 r1,-164(fp),-156(fp)
4739 mull2 r3,-164(fp)
4740 mull3 r3,-168(fp),-160(fp)
4741 mull2 r1,-168(fp)
4742 addl3 -156(fp),-160(fp),r0
4743 bicl3 #0,r0,-156(fp)
4744 cmpl -156(fp),-160(fp)
4745 bgequ noname.426
4746 addl2 #65536,-168(fp)
4747noname.426:
4748 movzwl -154(fp),r0
4749 bicl2 #-65536,r0
4750 addl2 r0,-168(fp)
4751 bicl3 #-65536,-156(fp),r0
4752 ashl #16,r0,-160(fp)
4753 addl3 -160(fp),-164(fp),r0
4754 bicl3 #0,r0,-164(fp)
4755 cmpl -164(fp),-160(fp)
4756 bgequ noname.427
4757 incl -168(fp)
4758noname.427:
4759 movl -164(fp),r3
4760 movl -168(fp),r2
4761 bbc #31,r2,noname.428
4762 incl r8
4763noname.428:
4764 addl2 r2,r2
4765 bicl2 #0,r2
4766 bbc #31,r3,noname.429
4767 incl r2
4768noname.429:
4769 addl2 r3,r3
4770 bicl2 #0,r3
4771 addl2 r3,r7
4772 bicl2 #0,r7
4773 cmpl r7,r3
4774 bgequ noname.430
4775 incl r2
4776 bicl3 #0,r2,r0
4777 bneq noname.430
4778 incl r8
4779noname.430:
4780 addl2 r2,r9
4781 bicl2 #0,r9
4782 cmpl r9,r2
4783 bgequ noname.431
4784 incl r8
4785noname.431:
4786
4787 movl 4(ap),r0
4788 movl r7,20(r0)
4789
4790 clrl r7
4791
4792 movl 8(ap),r2
4793 movl 12(r2),r4
4794 bicl3 #-65536,r4,-172(fp)
4795 extzv #16,#16,r4,r0
4796 bicl3 #-65536,r0,r4
4797 movl -172(fp),r0
4798 mull3 r0,r4,-176(fp)
4799 mull3 r0,r0,-172(fp)
4800 mull2 r4,r4
4801 bicl3 #32767,-176(fp),r0
4802 extzv #15,#17,r0,r0
4803 addl2 r0,r4
4804 bicl3 #-65536,-176(fp),r0
4805 ashl #17,r0,-176(fp)
4806 addl3 -172(fp),-176(fp),r0
4807 bicl3 #0,r0,-172(fp)
4808 cmpl -172(fp),-176(fp)
4809 bgequ noname.432
4810 incl r4
4811noname.432:
4812 movl -172(fp),r1
4813 movl r4,r3
4814 addl2 r1,r9
4815 bicl2 #0,r9
4816 cmpl r9,r1
4817 bgequ noname.433
4818 incl r3
4819noname.433:
4820 addl2 r3,r8
4821 bicl2 #0,r8
4822 cmpl r8,r3
4823 bgequ noname.434
4824 incl r7
4825noname.434:
4826
4827 movzwl 18(r2),r3
4828 bicl3 #-65536,8(r2),r1
4829 movzwl 10(r2),r0
4830 bicl2 #-65536,r0
4831 bicl3 #-65536,16(r2),-188(fp)
4832 bicl3 #-65536,r3,-192(fp)
4833 mull3 r0,-188(fp),-180(fp)
4834 mull2 r1,-188(fp)
4835 mull3 r1,-192(fp),-184(fp)
4836 mull2 r0,-192(fp)
4837 addl3 -180(fp),-184(fp),r0
4838 bicl3 #0,r0,-180(fp)
4839 cmpl -180(fp),-184(fp)
4840 bgequ noname.435
4841 addl2 #65536,-192(fp)
4842noname.435:
4843 movzwl -178(fp),r0
4844 bicl2 #-65536,r0
4845 addl2 r0,-192(fp)
4846 bicl3 #-65536,-180(fp),r0
4847 ashl #16,r0,-184(fp)
4848 addl3 -184(fp),-188(fp),r0
4849 bicl3 #0,r0,-188(fp)
4850 cmpl -188(fp),-184(fp)
4851 bgequ noname.436
4852 incl -192(fp)
4853noname.436:
4854 movl -188(fp),r3
4855 movl -192(fp),r2
4856 bbc #31,r2,noname.437
4857 incl r7
4858noname.437:
4859 addl2 r2,r2
4860 bicl2 #0,r2
4861 bbc #31,r3,noname.438
4862 incl r2
4863noname.438:
4864 addl2 r3,r3
4865 bicl2 #0,r3
4866 addl2 r3,r9
4867 bicl2 #0,r9
4868 cmpl r9,r3
4869 bgequ noname.439
4870 incl r2
4871 bicl3 #0,r2,r0
4872 bneq noname.439
4873 incl r7
4874noname.439:
4875 addl2 r2,r8
4876 bicl2 #0,r8
4877 cmpl r8,r2
4878 bgequ noname.440
4879 incl r7
4880noname.440:
4881
4882 movl 8(ap),r0
4883 movzwl 22(r0),r2
4884 bicl3 #-65536,4(r0),r3
4885 movzwl 6(r0),r1
4886 bicl2 #-65536,r1
4887 bicl3 #-65536,20(r0),-204(fp)
4888 bicl3 #-65536,r2,-208(fp)
4889 mull3 r1,-204(fp),-196(fp)
4890 mull2 r3,-204(fp)
4891 mull3 r3,-208(fp),-200(fp)
4892 mull2 r1,-208(fp)
4893 addl3 -196(fp),-200(fp),r0
4894 bicl3 #0,r0,-196(fp)
4895 cmpl -196(fp),-200(fp)
4896 bgequ noname.441
4897 addl2 #65536,-208(fp)
4898noname.441:
4899 movzwl -194(fp),r0
4900 bicl2 #-65536,r0
4901 addl2 r0,-208(fp)
4902 bicl3 #-65536,-196(fp),r0
4903 ashl #16,r0,-200(fp)
4904 addl3 -200(fp),-204(fp),r0
4905 bicl3 #0,r0,-204(fp)
4906 cmpl -204(fp),-200(fp)
4907 bgequ noname.442
4908 incl -208(fp)
4909noname.442:
4910 movl -204(fp),r3
4911 movl -208(fp),r2
4912 bbc #31,r2,noname.443
4913 incl r7
4914noname.443:
4915 addl2 r2,r2
4916 bicl2 #0,r2
4917 bbc #31,r3,noname.444
4918 incl r2
4919noname.444:
4920 addl2 r3,r3
4921 bicl2 #0,r3
4922 addl2 r3,r9
4923 bicl2 #0,r9
4924 cmpl r9,r3
4925 bgequ noname.445
4926 incl r2
4927 bicl3 #0,r2,r0
4928 bneq noname.445
4929 incl r7
4930noname.445:
4931 addl2 r2,r8
4932 bicl2 #0,r8
4933 cmpl r8,r2
4934 bgequ noname.446
4935 incl r7
4936noname.446:
4937
4938 movl 8(ap),r0
4939 movzwl 26(r0),r2
4940 bicl3 #-65536,(r0),r3
4941 movzwl 2(r0),r1
4942 bicl2 #-65536,r1
4943 bicl3 #-65536,24(r0),-220(fp)
4944 bicl3 #-65536,r2,-224(fp)
4945 mull3 r1,-220(fp),-212(fp)
4946 mull2 r3,-220(fp)
4947 mull3 r3,-224(fp),-216(fp)
4948 mull2 r1,-224(fp)
4949 addl3 -212(fp),-216(fp),r0
4950 bicl3 #0,r0,-212(fp)
4951 cmpl -212(fp),-216(fp)
4952 bgequ noname.447
4953 addl2 #65536,-224(fp)
4954noname.447:
4955 movzwl -210(fp),r0
4956 bicl2 #-65536,r0
4957 addl2 r0,-224(fp)
4958 bicl3 #-65536,-212(fp),r0
4959 ashl #16,r0,-216(fp)
4960 addl3 -216(fp),-220(fp),r0
4961 bicl3 #0,r0,-220(fp)
4962 cmpl -220(fp),-216(fp)
4963 bgequ noname.448
4964 incl -224(fp)
4965noname.448:
4966 movl -220(fp),r3
4967 movl -224(fp),r2
4968 bbc #31,r2,noname.449
4969 incl r7
4970noname.449:
4971 addl2 r2,r2
4972 bicl2 #0,r2
4973 bbc #31,r3,noname.450
4974 incl r2
4975noname.450:
4976 addl2 r3,r3
4977 bicl2 #0,r3
4978 addl2 r3,r9
4979 bicl2 #0,r9
4980 cmpl r9,r3
4981 bgequ noname.451
4982 incl r2
4983 bicl3 #0,r2,r0
4984 bneq noname.451
4985 incl r7
4986noname.451:
4987 addl2 r2,r8
4988 bicl2 #0,r8
4989 cmpl r8,r2
4990 bgequ noname.452
4991 incl r7
4992noname.452:
4993
4994 movl 4(ap),r0
4995 movl r9,24(r0)
4996
4997 clrl r9
4998
4999 movl 8(ap),r0
5000 movzwl 30(r0),r2
5001 bicl3 #-65536,(r0),r3
5002 movzwl 2(r0),r1
5003 bicl2 #-65536,r1
5004 bicl3 #-65536,28(r0),-236(fp)
5005 bicl3 #-65536,r2,-240(fp)
5006 mull3 r1,-236(fp),-228(fp)
5007 mull2 r3,-236(fp)
5008 mull3 r3,-240(fp),-232(fp)
5009 mull2 r1,-240(fp)
5010 addl3 -228(fp),-232(fp),r0
5011 bicl3 #0,r0,-228(fp)
5012 cmpl -228(fp),-232(fp)
5013 bgequ noname.453
5014 addl2 #65536,-240(fp)
5015noname.453:
5016 movzwl -226(fp),r0
5017 bicl2 #-65536,r0
5018 addl2 r0,-240(fp)
5019 bicl3 #-65536,-228(fp),r0
5020 ashl #16,r0,-232(fp)
5021 addl3 -232(fp),-236(fp),r0
5022 bicl3 #0,r0,-236(fp)
5023 cmpl -236(fp),-232(fp)
5024 bgequ noname.454
5025 incl -240(fp)
5026noname.454:
5027 movl -236(fp),r3
5028 movl -240(fp),r2
5029 bbc #31,r2,noname.455
5030 incl r9
5031noname.455:
5032 addl2 r2,r2
5033 bicl2 #0,r2
5034 bbc #31,r3,noname.456
5035 incl r2
5036noname.456:
5037 addl2 r3,r3
5038 bicl2 #0,r3
5039 addl2 r3,r8
5040 bicl2 #0,r8
5041 cmpl r8,r3
5042 bgequ noname.457
5043 incl r2
5044 bicl3 #0,r2,r0
5045 bneq noname.457
5046 incl r9
5047noname.457:
5048 addl2 r2,r7
5049 bicl2 #0,r7
5050 cmpl r7,r2
5051 bgequ noname.458
5052 incl r9
5053noname.458:
5054
5055 movl 8(ap),r0
5056 movzwl 26(r0),r2
5057 bicl3 #-65536,4(r0),r3
5058 movzwl 6(r0),r1
5059 bicl2 #-65536,r1
5060 bicl3 #-65536,24(r0),-252(fp)
5061 bicl3 #-65536,r2,-256(fp)
5062 mull3 r1,-252(fp),-244(fp)
5063 mull2 r3,-252(fp)
5064 mull3 r3,-256(fp),-248(fp)
5065 mull2 r1,-256(fp)
5066 addl3 -244(fp),-248(fp),r0
5067 bicl3 #0,r0,-244(fp)
5068 cmpl -244(fp),-248(fp)
5069 bgequ noname.459
5070 addl2 #65536,-256(fp)
5071noname.459:
5072 movzwl -242(fp),r0
5073 bicl2 #-65536,r0
5074 addl2 r0,-256(fp)
5075 bicl3 #-65536,-244(fp),r0
5076 ashl #16,r0,-248(fp)
5077 addl3 -248(fp),-252(fp),r0
5078 bicl3 #0,r0,-252(fp)
5079 cmpl -252(fp),-248(fp)
5080 bgequ noname.460
5081 incl -256(fp)
5082noname.460:
5083 movl -252(fp),r3
5084 movl -256(fp),r2
5085 bbc #31,r2,noname.461
5086 incl r9
5087noname.461:
5088 addl2 r2,r2
5089 bicl2 #0,r2
5090 bbc #31,r3,noname.462
5091 incl r2
5092noname.462:
5093 addl2 r3,r3
5094 bicl2 #0,r3
5095 addl2 r3,r8
5096 bicl2 #0,r8
5097 cmpl r8,r3
5098 bgequ noname.463
5099 incl r2
5100 bicl3 #0,r2,r0
5101 bneq noname.463
5102 incl r9
5103noname.463:
5104 addl2 r2,r7
5105 bicl2 #0,r7
5106 cmpl r7,r2
5107 bgequ noname.464
5108 incl r9
5109noname.464:
5110
5111 movl 8(ap),r0
5112 movzwl 22(r0),r2
5113 bicl3 #-65536,8(r0),r3
5114 movzwl 10(r0),r1
5115 bicl2 #-65536,r1
5116 bicl3 #-65536,20(r0),-268(fp)
5117 bicl3 #-65536,r2,-272(fp)
5118 mull3 r1,-268(fp),-260(fp)
5119 mull2 r3,-268(fp)
5120 mull3 r3,-272(fp),-264(fp)
5121 mull2 r1,-272(fp)
5122 addl3 -260(fp),-264(fp),r0
5123 bicl3 #0,r0,-260(fp)
5124 cmpl -260(fp),-264(fp)
5125 bgequ noname.465
5126 addl2 #65536,-272(fp)
5127noname.465:
5128 movzwl -258(fp),r0
5129 bicl2 #-65536,r0
5130 addl2 r0,-272(fp)
5131 bicl3 #-65536,-260(fp),r0
5132 ashl #16,r0,-264(fp)
5133 addl3 -264(fp),-268(fp),r0
5134 bicl3 #0,r0,-268(fp)
5135 cmpl -268(fp),-264(fp)
5136 bgequ noname.466
5137 incl -272(fp)
5138noname.466:
5139 movl -268(fp),r3
5140 movl -272(fp),r2
5141 bbc #31,r2,noname.467
5142 incl r9
5143noname.467:
5144 addl2 r2,r2
5145 bicl2 #0,r2
5146 bbc #31,r3,noname.468
5147 incl r2
5148noname.468:
5149 addl2 r3,r3
5150 bicl2 #0,r3
5151 addl2 r3,r8
5152 bicl2 #0,r8
5153 cmpl r8,r3
5154 bgequ noname.469
5155 incl r2
5156 bicl3 #0,r2,r0
5157 bneq noname.469
5158 incl r9
5159noname.469:
5160 addl2 r2,r7
5161 bicl2 #0,r7
5162 cmpl r7,r2
5163 bgequ noname.470
5164 incl r9
5165noname.470:
5166
5167 movl 8(ap),r0
5168 movzwl 18(r0),r2
5169 bicl3 #-65536,12(r0),r3
5170 movzwl 14(r0),r1
5171 bicl2 #-65536,r1
5172 bicl3 #-65536,16(r0),-284(fp)
5173 bicl3 #-65536,r2,-288(fp)
5174 mull3 r1,-284(fp),-276(fp)
5175 mull2 r3,-284(fp)
5176 mull3 r3,-288(fp),-280(fp)
5177 mull2 r1,-288(fp)
5178 addl3 -276(fp),-280(fp),r0
5179 bicl3 #0,r0,-276(fp)
5180 cmpl -276(fp),-280(fp)
5181 bgequ noname.471
5182 addl2 #65536,-288(fp)
5183noname.471:
5184 movzwl -274(fp),r0
5185 bicl2 #-65536,r0
5186 addl2 r0,-288(fp)
5187 bicl3 #-65536,-276(fp),r0
5188 ashl #16,r0,-280(fp)
5189 addl3 -280(fp),-284(fp),r0
5190 bicl3 #0,r0,-284(fp)
5191 cmpl -284(fp),-280(fp)
5192 bgequ noname.472
5193 incl -288(fp)
5194noname.472:
5195 movl -284(fp),r3
5196 movl -288(fp),r2
5197 bbc #31,r2,noname.473
5198 incl r9
5199noname.473:
5200 addl2 r2,r2
5201 bicl2 #0,r2
5202 bbc #31,r3,noname.474
5203 incl r2
5204noname.474:
5205 addl2 r3,r3
5206 bicl2 #0,r3
5207 addl2 r3,r8
5208 bicl2 #0,r8
5209 cmpl r8,r3
5210 bgequ noname.475
5211 incl r2
5212 bicl3 #0,r2,r0
5213 bneq noname.475
5214 incl r9
5215noname.475:
5216 addl2 r2,r7
5217 bicl2 #0,r7
5218 cmpl r7,r2
5219 bgequ noname.476
5220 incl r9
5221noname.476:
5222
5223 movl 4(ap),r0
5224 movl r8,28(r0)
5225
5226 clrl r8
5227
5228 movl 8(ap),r3
5229 movl 16(r3),r4
5230 bicl3 #-65536,r4,r5
5231 extzv #16,#16,r4,r0
5232 bicl3 #-65536,r0,r4
5233 mull3 r5,r4,-292(fp)
5234 mull2 r5,r5
5235 mull2 r4,r4
5236 bicl3 #32767,-292(fp),r0
5237 extzv #15,#17,r0,r0
5238 addl2 r0,r4
5239 bicl3 #-65536,-292(fp),r0
5240 ashl #17,r0,-292(fp)
5241 addl2 -292(fp),r5
5242 bicl2 #0,r5
5243 cmpl r5,-292(fp)
5244 bgequ noname.477
5245 incl r4
5246noname.477:
5247 movl r5,r1
5248 movl r4,r2
5249 addl2 r1,r7
5250 bicl2 #0,r7
5251 cmpl r7,r1
5252 bgequ noname.478
5253 incl r2
5254noname.478:
5255 addl2 r2,r9
5256 bicl2 #0,r9
5257 cmpl r9,r2
5258 bgequ noname.479
5259 incl r8
5260noname.479:
5261
5262 bicl3 #-65536,20(r3),r4
5263 movzwl 22(r3),r1
5264 bicl2 #-65536,r1
5265 bicl3 #-65536,12(r3),r2
5266 movzwl 14(r3),r0
5267 bicl2 #-65536,r0
5268 movl r4,r6
5269 movl r1,r5
5270 mull3 r0,r6,-296(fp)
5271 mull2 r2,r6
5272 mull3 r2,r5,-300(fp)
5273 mull2 r0,r5
5274 addl3 -296(fp),-300(fp),r0
5275 bicl3 #0,r0,-296(fp)
5276 cmpl -296(fp),-300(fp)
5277 bgequ noname.480
5278 addl2 #65536,r5
5279noname.480:
5280 movzwl -294(fp),r0
5281 bicl2 #-65536,r0
5282 addl2 r0,r5
5283 bicl3 #-65536,-296(fp),r0
5284 ashl #16,r0,-300(fp)
5285 addl2 -300(fp),r6
5286 bicl2 #0,r6
5287 cmpl r6,-300(fp)
5288 bgequ noname.481
5289 incl r5
5290noname.481:
5291 movl r6,r3
5292 movl r5,r2
5293 bbc #31,r2,noname.482
5294 incl r8
5295noname.482:
5296 addl2 r2,r2
5297 bicl2 #0,r2
5298 bbc #31,r3,noname.483
5299 incl r2
5300noname.483:
5301 addl2 r3,r3
5302 bicl2 #0,r3
5303 addl2 r3,r7
5304 bicl2 #0,r7
5305 cmpl r7,r3
5306 bgequ noname.484
5307 incl r2
5308 bicl3 #0,r2,r0
5309 bneq noname.484
5310 incl r8
5311noname.484:
5312 addl2 r2,r9
5313 bicl2 #0,r9
5314 cmpl r9,r2
5315 bgequ noname.485
5316 incl r8
5317noname.485:
5318
5319 movl 8(ap),r0
5320 bicl3 #-65536,24(r0),r3
5321 movzwl 26(r0),r1
5322 bicl2 #-65536,r1
5323 bicl3 #-65536,8(r0),r2
5324 movzwl 10(r0),r0
5325 bicl2 #-65536,r0
5326 movl r3,r5
5327 movl r1,r4
5328 mull3 r0,r5,-304(fp)
5329 mull2 r2,r5
5330 mull3 r2,r4,-308(fp)
5331 mull2 r0,r4
5332 addl3 -304(fp),-308(fp),r0
5333 bicl3 #0,r0,-304(fp)
5334 cmpl -304(fp),-308(fp)
5335 bgequ noname.486
5336 addl2 #65536,r4
5337noname.486:
5338 movzwl -302(fp),r0
5339 bicl2 #-65536,r0
5340 addl2 r0,r4
5341 bicl3 #-65536,-304(fp),r0
5342 ashl #16,r0,-308(fp)
5343 addl2 -308(fp),r5
5344 bicl2 #0,r5
5345 cmpl r5,-308(fp)
5346 bgequ noname.487
5347 incl r4
5348noname.487:
5349 movl r5,r3
5350 movl r4,r2
5351 bbc #31,r2,noname.488
5352 incl r8
5353noname.488:
5354 addl2 r2,r2
5355 bicl2 #0,r2
5356 bbc #31,r3,noname.489
5357 incl r2
5358noname.489:
5359 addl2 r3,r3
5360 bicl2 #0,r3
5361 addl2 r3,r7
5362 bicl2 #0,r7
5363 cmpl r7,r3
5364 bgequ noname.490
5365 incl r2
5366 bicl3 #0,r2,r0
5367 bneq noname.490
5368 incl r8
5369noname.490:
5370 addl2 r2,r9
5371 bicl2 #0,r9
5372 cmpl r9,r2
5373 bgequ noname.491
5374 incl r8
5375noname.491:
5376
5377 movl 8(ap),r0
5378 bicl3 #-65536,28(r0),r3
5379 movzwl 30(r0),r1
5380 bicl2 #-65536,r1
5381 bicl3 #-65536,4(r0),r2
5382 movzwl 6(r0),r0
5383 bicl2 #-65536,r0
5384 movl r3,r5
5385 movl r1,r4
5386 mull3 r0,r5,-312(fp)
5387 mull2 r2,r5
5388 mull3 r2,r4,-316(fp)
5389 mull2 r0,r4
5390 addl3 -312(fp),-316(fp),r0
5391 bicl3 #0,r0,-312(fp)
5392 cmpl -312(fp),-316(fp)
5393 bgequ noname.492
5394 addl2 #65536,r4
5395noname.492:
5396 movzwl -310(fp),r0
5397 bicl2 #-65536,r0
5398 addl2 r0,r4
5399 bicl3 #-65536,-312(fp),r0
5400 ashl #16,r0,-316(fp)
5401 addl2 -316(fp),r5
5402 bicl2 #0,r5
5403 cmpl r5,-316(fp)
5404 bgequ noname.493
5405 incl r4
5406noname.493:
5407 movl r5,r3
5408 movl r4,r2
5409 bbc #31,r2,noname.494
5410 incl r8
5411noname.494:
5412 addl2 r2,r2
5413 bicl2 #0,r2
5414 bbc #31,r3,noname.495
5415 incl r2
5416noname.495:
5417 addl2 r3,r3
5418 bicl2 #0,r3
5419 addl2 r3,r7
5420 bicl2 #0,r7
5421 cmpl r7,r3
5422 bgequ noname.496
5423 incl r2
5424 bicl3 #0,r2,r0
5425 bneq noname.496
5426 incl r8
5427noname.496:
5428 addl2 r2,r9
5429 bicl2 #0,r9
5430 cmpl r9,r2
5431 bgequ noname.497
5432 incl r8
5433noname.497:
5434
5435 movl 4(ap),r0
5436 movl r7,32(r0)
5437
5438 clrl r7
5439
5440 movl 8(ap),r0
5441 bicl3 #-65536,28(r0),r3
5442 movzwl 30(r0),r2
5443 bicl3 #-65536,8(r0),r1
5444 movzwl 10(r0),r0
5445 bicl2 #-65536,r0
5446 movl r3,r4
5447 bicl3 #-65536,r2,-328(fp)
5448 mull3 r0,r4,-320(fp)
5449 mull2 r1,r4
5450 mull3 r1,-328(fp),-324(fp)
5451 mull2 r0,-328(fp)
5452 addl3 -320(fp),-324(fp),r0
5453 bicl3 #0,r0,-320(fp)
5454 cmpl -320(fp),-324(fp)
5455 bgequ noname.498
5456 addl2 #65536,-328(fp)
5457noname.498:
5458 movzwl -318(fp),r0
5459 bicl2 #-65536,r0
5460 addl2 r0,-328(fp)
5461 bicl3 #-65536,-320(fp),r0
5462 ashl #16,r0,-324(fp)
5463 addl2 -324(fp),r4
5464 bicl2 #0,r4
5465 cmpl r4,-324(fp)
5466 bgequ noname.499
5467 incl -328(fp)
5468noname.499:
5469 movl r4,r3
5470 movl -328(fp),r2
5471 bbc #31,r2,noname.500
5472 incl r7
5473noname.500:
5474 addl2 r2,r2
5475 bicl2 #0,r2
5476 bbc #31,r3,noname.501
5477 incl r2
5478noname.501:
5479 addl2 r3,r3
5480 bicl2 #0,r3
5481 addl2 r3,r9
5482 bicl2 #0,r9
5483 cmpl r9,r3
5484 bgequ noname.502
5485 incl r2
5486 bicl3 #0,r2,r0
5487 bneq noname.502
5488 incl r7
5489noname.502:
5490 addl2 r2,r8
5491 bicl2 #0,r8
5492 cmpl r8,r2
5493 bgequ noname.503
5494 incl r7
5495noname.503:
5496
5497 movl 8(ap),r0
5498 movzwl 26(r0),r2
5499 bicl3 #-65536,12(r0),r3
5500 movzwl 14(r0),r1
5501 bicl2 #-65536,r1
5502 bicl3 #-65536,24(r0),-340(fp)
5503 bicl3 #-65536,r2,-344(fp)
5504 mull3 r1,-340(fp),-332(fp)
5505 mull2 r3,-340(fp)
5506 mull3 r3,-344(fp),-336(fp)
5507 mull2 r1,-344(fp)
5508 addl3 -332(fp),-336(fp),r0
5509 bicl3 #0,r0,-332(fp)
5510 cmpl -332(fp),-336(fp)
5511 bgequ noname.504
5512 addl2 #65536,-344(fp)
5513noname.504:
5514 movzwl -330(fp),r0
5515 bicl2 #-65536,r0
5516 addl2 r0,-344(fp)
5517 bicl3 #-65536,-332(fp),r0
5518 ashl #16,r0,-336(fp)
5519 addl3 -336(fp),-340(fp),r0
5520 bicl3 #0,r0,-340(fp)
5521 cmpl -340(fp),-336(fp)
5522 bgequ noname.505
5523 incl -344(fp)
5524noname.505:
5525 movl -340(fp),r3
5526 movl -344(fp),r2
5527 bbc #31,r2,noname.506
5528 incl r7
5529noname.506:
5530 addl2 r2,r2
5531 bicl2 #0,r2
5532 bbc #31,r3,noname.507
5533 incl r2
5534noname.507:
5535 addl2 r3,r3
5536 bicl2 #0,r3
5537 addl2 r3,r9
5538 bicl2 #0,r9
5539 cmpl r9,r3
5540 bgequ noname.508
5541 incl r2
5542 bicl3 #0,r2,r0
5543 bneq noname.508
5544 incl r7
5545noname.508:
5546 addl2 r2,r8
5547 bicl2 #0,r8
5548 cmpl r8,r2
5549 bgequ noname.509
5550 incl r7
5551noname.509:
5552
5553 movl 8(ap),r0
5554 movzwl 22(r0),r2
5555 bicl3 #-65536,16(r0),r3
5556 movzwl 18(r0),r1
5557 bicl2 #-65536,r1
5558 bicl3 #-65536,20(r0),-356(fp)
5559 bicl3 #-65536,r2,-360(fp)
5560 mull3 r1,-356(fp),-348(fp)
5561 mull2 r3,-356(fp)
5562 mull3 r3,-360(fp),-352(fp)
5563 mull2 r1,-360(fp)
5564 addl3 -348(fp),-352(fp),r0
5565 bicl3 #0,r0,-348(fp)
5566 cmpl -348(fp),-352(fp)
5567 bgequ noname.510
5568 addl2 #65536,-360(fp)
5569noname.510:
5570 movzwl -346(fp),r0
5571 bicl2 #-65536,r0
5572 addl2 r0,-360(fp)
5573 bicl3 #-65536,-348(fp),r0
5574 ashl #16,r0,-352(fp)
5575 addl3 -352(fp),-356(fp),r0
5576 bicl3 #0,r0,-356(fp)
5577 cmpl -356(fp),-352(fp)
5578 bgequ noname.511
5579 incl -360(fp)
5580noname.511:
5581 movl -356(fp),r3
5582 movl -360(fp),r2
5583 bbc #31,r2,noname.512
5584 incl r7
5585noname.512:
5586 addl2 r2,r2
5587 bicl2 #0,r2
5588 bbc #31,r3,noname.513
5589 incl r2
5590noname.513:
5591 addl2 r3,r3
5592 bicl2 #0,r3
5593 addl2 r3,r9
5594 bicl2 #0,r9
5595 cmpl r9,r3
5596 bgequ noname.514
5597 incl r2
5598 bicl3 #0,r2,r0
5599 bneq noname.514
5600 incl r7
5601noname.514:
5602 addl2 r2,r8
5603 bicl2 #0,r8
5604 cmpl r8,r2
5605 bgequ noname.515
5606 incl r7
5607noname.515:
5608
5609 movl 4(ap),r0
5610 movl r9,36(r0)
5611
5612 clrl r9
5613
5614 movl 8(ap),r3
5615 movl 20(r3),r4
5616 bicl3 #-65536,r4,-364(fp)
5617 extzv #16,#16,r4,r0
5618 bicl3 #-65536,r0,r4
5619 movl -364(fp),r0
5620 mull3 r0,r4,-368(fp)
5621 mull3 r0,r0,-364(fp)
5622 mull2 r4,r4
5623 bicl3 #32767,-368(fp),r0
5624 extzv #15,#17,r0,r0
5625 addl2 r0,r4
5626 bicl3 #-65536,-368(fp),r0
5627 ashl #17,r0,-368(fp)
5628 addl3 -364(fp),-368(fp),r0
5629 bicl3 #0,r0,-364(fp)
5630 cmpl -364(fp),-368(fp)
5631 bgequ noname.516
5632 incl r4
5633noname.516:
5634 movl -364(fp),r1
5635 movl r4,r2
5636 addl2 r1,r8
5637 bicl2 #0,r8
5638 cmpl r8,r1
5639 bgequ noname.517
5640 incl r2
5641noname.517:
5642 addl2 r2,r7
5643 bicl2 #0,r7
5644 cmpl r7,r2
5645 bgequ noname.518
5646 incl r9
5647noname.518:
5648
5649 bicl3 #-65536,24(r3),r4
5650 movzwl 26(r3),r1
5651 bicl2 #-65536,r1
5652 bicl3 #-65536,16(r3),r2
5653 movzwl 18(r3),r0
5654 bicl2 #-65536,r0
5655 movl r4,r6
5656 movl r1,r5
5657 mull3 r0,r6,-372(fp)
5658 mull2 r2,r6
5659 mull3 r2,r5,-376(fp)
5660 mull2 r0,r5
5661 addl3 -372(fp),-376(fp),r0
5662 bicl3 #0,r0,-372(fp)
5663 cmpl -372(fp),-376(fp)
5664 bgequ noname.519
5665 addl2 #65536,r5
5666noname.519:
5667 movzwl -370(fp),r0
5668 bicl2 #-65536,r0
5669 addl2 r0,r5
5670 bicl3 #-65536,-372(fp),r0
5671 ashl #16,r0,-376(fp)
5672 addl2 -376(fp),r6
5673 bicl2 #0,r6
5674 cmpl r6,-376(fp)
5675 bgequ noname.520
5676 incl r5
5677noname.520:
5678 movl r6,r3
5679 movl r5,r2
5680 bbc #31,r2,noname.521
5681 incl r9
5682noname.521:
5683 addl2 r2,r2
5684 bicl2 #0,r2
5685 bbc #31,r3,noname.522
5686 incl r2
5687noname.522:
5688 addl2 r3,r3
5689 bicl2 #0,r3
5690 addl2 r3,r8
5691 bicl2 #0,r8
5692 cmpl r8,r3
5693 bgequ noname.523
5694 incl r2
5695 bicl3 #0,r2,r0
5696 bneq noname.523
5697 incl r9
5698noname.523:
5699 addl2 r2,r7
5700 bicl2 #0,r7
5701 cmpl r7,r2
5702 bgequ noname.524
5703 incl r9
5704noname.524:
5705
5706 movl 8(ap),r0
5707 bicl3 #-65536,28(r0),r3
5708 movzwl 30(r0),r1
5709 bicl2 #-65536,r1
5710 bicl3 #-65536,12(r0),r2
5711 movzwl 14(r0),r0
5712 bicl2 #-65536,r0
5713 movl r3,r5
5714 movl r1,r4
5715 mull3 r0,r5,-380(fp)
5716 mull2 r2,r5
5717 mull3 r2,r4,-384(fp)
5718 mull2 r0,r4
5719 addl3 -380(fp),-384(fp),r0
5720 bicl3 #0,r0,-380(fp)
5721 cmpl -380(fp),-384(fp)
5722 bgequ noname.525
5723 addl2 #65536,r4
5724noname.525:
5725 movzwl -378(fp),r0
5726 bicl2 #-65536,r0
5727 addl2 r0,r4
5728 bicl3 #-65536,-380(fp),r0
5729 ashl #16,r0,-384(fp)
5730 addl2 -384(fp),r5
5731 bicl2 #0,r5
5732 cmpl r5,-384(fp)
5733 bgequ noname.526
5734 incl r4
5735noname.526:
5736 movl r5,r3
5737 movl r4,r2
5738 bbc #31,r2,noname.527
5739 incl r9
5740noname.527:
5741 addl2 r2,r2
5742 bicl2 #0,r2
5743 bbc #31,r3,noname.528
5744 incl r2
5745noname.528:
5746 addl2 r3,r3
5747 bicl2 #0,r3
5748 addl2 r3,r8
5749 bicl2 #0,r8
5750 cmpl r8,r3
5751 bgequ noname.529
5752 incl r2
5753 bicl3 #0,r2,r0
5754 bneq noname.529
5755 incl r9
5756noname.529:
5757 addl2 r2,r7
5758 bicl2 #0,r7
5759 cmpl r7,r2
5760 bgequ noname.530
5761 incl r9
5762noname.530:
5763 movl 4(ap),r0
5764 movl r8,40(r0)
5765
5766 clrl r8
5767
5768 movl 8(ap),r0
5769 bicl3 #-65536,28(r0),r3
5770 movzwl 30(r0),r1
5771 bicl2 #-65536,r1
5772 bicl3 #-65536,16(r0),r2
5773 movzwl 18(r0),r0
5774 bicl2 #-65536,r0
5775 movl r3,r5
5776 movl r1,r4
5777 mull3 r0,r5,-388(fp)
5778 mull2 r2,r5
5779 mull3 r2,r4,-392(fp)
5780 mull2 r0,r4
5781 addl3 -388(fp),-392(fp),r0
5782 bicl3 #0,r0,-388(fp)
5783 cmpl -388(fp),-392(fp)
5784 bgequ noname.531
5785 addl2 #65536,r4
5786noname.531:
5787 movzwl -386(fp),r0
5788 bicl2 #-65536,r0
5789 addl2 r0,r4
5790 bicl3 #-65536,-388(fp),r0
5791 ashl #16,r0,-392(fp)
5792 addl2 -392(fp),r5
5793 bicl2 #0,r5
5794 cmpl r5,-392(fp)
5795 bgequ noname.532
5796 incl r4
5797noname.532:
5798 movl r5,r3
5799 movl r4,r2
5800 bbc #31,r2,noname.533
5801 incl r8
5802noname.533:
5803 addl2 r2,r2
5804 bicl2 #0,r2
5805 bbc #31,r3,noname.534
5806 incl r2
5807noname.534:
5808 addl2 r3,r3
5809 bicl2 #0,r3
5810 addl2 r3,r7
5811 bicl2 #0,r7
5812 cmpl r7,r3
5813 bgequ noname.535
5814 incl r2
5815 bicl3 #0,r2,r0
5816 bneq noname.535
5817 incl r8
5818noname.535:
5819 addl2 r2,r9
5820 bicl2 #0,r9
5821 cmpl r9,r2
5822 bgequ noname.536
5823 incl r8
5824noname.536:
5825
5826 movl 8(ap),r0
5827 bicl3 #-65536,24(r0),r3
5828 movzwl 26(r0),r1
5829 bicl2 #-65536,r1
5830 bicl3 #-65536,20(r0),r2
5831 movzwl 22(r0),r0
5832 bicl2 #-65536,r0
5833 movl r3,r5
5834 movl r1,r4
5835 mull3 r0,r5,-396(fp)
5836 mull2 r2,r5
5837 mull3 r2,r4,-400(fp)
5838 mull2 r0,r4
5839 addl3 -396(fp),-400(fp),r0
5840 bicl3 #0,r0,-396(fp)
5841 cmpl -396(fp),-400(fp)
5842 bgequ noname.537
5843 addl2 #65536,r4
5844noname.537:
5845 movzwl -394(fp),r0
5846 bicl2 #-65536,r0
5847 addl2 r0,r4
5848 bicl3 #-65536,-396(fp),r0
5849 ashl #16,r0,-400(fp)
5850 addl2 -400(fp),r5
5851 bicl2 #0,r5
5852 cmpl r5,-400(fp)
5853 bgequ noname.538
5854 incl r4
5855noname.538:
5856 movl r5,r3
5857 movl r4,r2
5858 bbc #31,r2,noname.539
5859 incl r8
5860noname.539:
5861 addl2 r2,r2
5862 bicl2 #0,r2
5863 bbc #31,r3,noname.540
5864 incl r2
5865noname.540:
5866 addl2 r3,r3
5867 bicl2 #0,r3
5868 addl2 r3,r7
5869 bicl2 #0,r7
5870 cmpl r7,r3
5871 bgequ noname.541
5872 incl r2
5873 bicl3 #0,r2,r0
5874 bneq noname.541
5875 incl r8
5876noname.541:
5877 addl2 r2,r9
5878 bicl2 #0,r9
5879 cmpl r9,r2
5880 bgequ noname.542
5881 incl r8
5882noname.542:
5883
5884 movl 4(ap),r0
5885 movl r7,44(r0)
5886
5887 clrl r7
5888
5889 movl 8(ap),r3
5890 movl 24(r3),r4
5891 bicl3 #-65536,r4,r5
5892 extzv #16,#16,r4,r0
5893 bicl3 #-65536,r0,r4
5894 mull3 r5,r4,-404(fp)
5895 mull2 r5,r5
5896 mull2 r4,r4
5897 bicl3 #32767,-404(fp),r0
5898 extzv #15,#17,r0,r0
5899 addl2 r0,r4
5900 bicl3 #-65536,-404(fp),r0
5901 ashl #17,r0,-404(fp)
5902 addl2 -404(fp),r5
5903 bicl2 #0,r5
5904 cmpl r5,-404(fp)
5905 bgequ noname.543
5906 incl r4
5907noname.543:
5908 movl r5,r1
5909 movl r4,r2
5910 addl2 r1,r9
5911 bicl2 #0,r9
5912 cmpl r9,r1
5913 bgequ noname.544
5914 incl r2
5915noname.544:
5916 addl2 r2,r8
5917 bicl2 #0,r8
5918 cmpl r8,r2
5919 bgequ noname.545
5920 incl r7
5921noname.545:
5922
5923 movzwl 30(r3),r2
5924 bicl3 #-65536,20(r3),r1
5925 movzwl 22(r3),r0
5926 bicl2 #-65536,r0
5927 bicl3 #-65536,28(r3),-416(fp)
5928 bicl3 #-65536,r2,-420(fp)
5929 mull3 r0,-416(fp),-408(fp)
5930 mull2 r1,-416(fp)
5931 mull3 r1,-420(fp),-412(fp)
5932 mull2 r0,-420(fp)
5933 addl3 -408(fp),-412(fp),r0
5934 bicl3 #0,r0,-408(fp)
5935 cmpl -408(fp),-412(fp)
5936 bgequ noname.546
5937 addl2 #65536,-420(fp)
5938noname.546:
5939 movzwl -406(fp),r0
5940 bicl2 #-65536,r0
5941 addl2 r0,-420(fp)
5942 bicl3 #-65536,-408(fp),r0
5943 ashl #16,r0,-412(fp)
5944 addl3 -412(fp),-416(fp),r0
5945 bicl3 #0,r0,-416(fp)
5946 cmpl -416(fp),-412(fp)
5947 bgequ noname.547
5948 incl -420(fp)
5949noname.547:
5950 movl -416(fp),r3
5951 movl -420(fp),r2
5952 bbc #31,r2,noname.548
5953 incl r7
5954noname.548:
5955 addl2 r2,r2
5956 bicl2 #0,r2
5957 bbc #31,r3,noname.549
5958 incl r2
5959noname.549:
5960 addl2 r3,r3
5961 bicl2 #0,r3
5962 addl2 r3,r9
5963 bicl2 #0,r9
5964 cmpl r9,r3
5965 bgequ noname.550
5966 incl r2
5967 bicl3 #0,r2,r0
5968 bneq noname.550
5969 incl r7
5970noname.550:
5971 addl2 r2,r8
5972 bicl2 #0,r8
5973 cmpl r8,r2
5974 bgequ noname.551
5975 incl r7
5976noname.551:
5977
5978 movl 4(ap),r0
5979 movl r9,48(r0)
5980
5981 clrl r9
5982
5983 movl 8(ap),r0
5984 movzwl 30(r0),r2
5985 bicl3 #-65536,24(r0),r3
5986 movzwl 26(r0),r1
5987 bicl2 #-65536,r1
5988 bicl3 #-65536,28(r0),-432(fp)
5989 bicl3 #-65536,r2,-436(fp)
5990 mull3 r1,-432(fp),-424(fp)
5991 mull2 r3,-432(fp)
5992 mull3 r3,-436(fp),-428(fp)
5993 mull2 r1,-436(fp)
5994 addl3 -424(fp),-428(fp),r0
5995 bicl3 #0,r0,-424(fp)
5996 cmpl -424(fp),-428(fp)
5997 bgequ noname.552
5998 addl2 #65536,-436(fp)
5999noname.552:
6000 movzwl -422(fp),r0
6001 bicl2 #-65536,r0
6002 addl2 r0,-436(fp)
6003 bicl3 #-65536,-424(fp),r0
6004 ashl #16,r0,-428(fp)
6005 addl3 -428(fp),-432(fp),r0
6006 bicl3 #0,r0,-432(fp)
6007 cmpl -432(fp),-428(fp)
6008 bgequ noname.553
6009 incl -436(fp)
6010noname.553:
6011 movl -432(fp),r3
6012 movl -436(fp),r2
6013 bbc #31,r2,noname.554
6014 incl r9
6015noname.554:
6016 addl2 r2,r2
6017 bicl2 #0,r2
6018 bbc #31,r3,noname.555
6019 incl r2
6020noname.555:
6021 addl2 r3,r3
6022 bicl2 #0,r3
6023 addl2 r3,r8
6024 bicl2 #0,r8
6025 cmpl r8,r3
6026 bgequ noname.556
6027 incl r2
6028 bicl3 #0,r2,r0
6029 bneq noname.556
6030 incl r9
6031noname.556:
6032 addl2 r2,r7
6033 bicl2 #0,r7
6034 cmpl r7,r2
6035 bgequ noname.557
6036 incl r9
6037noname.557:
6038
6039 movl 4(ap),r4
6040 movl r8,52(r4)
6041
6042 clrl r8
6043
6044 movl 8(ap),r0
6045 movl 28(r0),r3
6046 bicl3 #-65536,r3,-440(fp)
6047 extzv #16,#16,r3,r0
6048 bicl3 #-65536,r0,r3
6049 movl -440(fp),r0
6050 mull3 r0,r3,-444(fp)
6051 mull3 r0,r0,-440(fp)
6052 mull2 r3,r3
6053 bicl3 #32767,-444(fp),r0
6054 extzv #15,#17,r0,r0
6055 addl2 r0,r3
6056 bicl3 #-65536,-444(fp),r0
6057 ashl #17,r0,-444(fp)
6058 addl3 -440(fp),-444(fp),r0
6059 bicl3 #0,r0,-440(fp)
6060 cmpl -440(fp),-444(fp)
6061 bgequ noname.558
6062 incl r3
6063noname.558:
6064 movl -440(fp),r1
6065 movl r3,r2
6066 addl2 r1,r7
6067 bicl2 #0,r7
6068 cmpl r7,r1
6069 bgequ noname.559
6070 incl r2
6071noname.559:
6072 addl2 r2,r9
6073 bicl2 #0,r9
6074 cmpl r9,r2
6075 bgequ noname.560
6076 incl r8
6077noname.560:
6078
6079 movl r7,56(r4)
6080
6081 movl r9,60(r4)
6082
6083 ret
6084
6085
6086
6087;r=4 ;(AP)
6088;a=8 ;(AP)
6089;b=12 ;(AP)
6090;n=16 ;(AP) n by value (input)
6091
6092 .psect code,nowrt
6093
6094.entry BN_SQR_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
6095 subl2 #44,sp
6096
6097 clrq r8
6098
6099 clrl r10
6100
6101 movl 8(ap),r5
6102 movl (r5),r3
6103 bicl3 #-65536,r3,r4
6104 extzv #16,#16,r3,r0
6105 bicl3 #-65536,r0,r3
6106 mull3 r4,r3,-4(fp)
6107 mull2 r4,r4
6108 mull2 r3,r3
6109 bicl3 #32767,-4(fp),r0
6110 extzv #15,#17,r0,r0
6111 addl2 r0,r3
6112 bicl3 #-65536,-4(fp),r0
6113 ashl #17,r0,-4(fp)
6114 addl2 -4(fp),r4
6115 bicl2 #0,r4
6116 cmpl r4,-4(fp)
6117 bgequ noname.563
6118 incl r3
6119noname.563:
6120 movl r4,r1
6121 movl r3,r2
6122 addl2 r1,r9
6123 bicl2 #0,r9
6124 cmpl r9,r1
6125 bgequ noname.564
6126 incl r2
6127noname.564:
6128 addl2 r2,r8
6129 bicl2 #0,r8
6130 cmpl r8,r2
6131 bgequ noname.565
6132 incl r10
6133noname.565:
6134
6135 movl r9,@4(ap)
6136
6137 clrl r9
6138
6139 bicl3 #-65536,4(r5),r3
6140 movzwl 6(r5),r1
6141 bicl2 #-65536,r1
6142 bicl3 #-65536,(r5),r2
6143 movzwl 2(r5),r0
6144 bicl2 #-65536,r0
6145 movl r3,r6
6146 movl r1,r4
6147 mull3 r0,r6,-8(fp)
6148 mull2 r2,r6
6149 mull2 r4,r2
6150 mull2 r0,r4
6151 addl3 -8(fp),r2,r0
6152 bicl3 #0,r0,-8(fp)
6153 cmpl -8(fp),r2
6154 bgequ noname.566
6155 addl2 #65536,r4
6156noname.566:
6157 movzwl -6(fp),r0
6158 bicl2 #-65536,r0
6159 addl2 r0,r4
6160 bicl3 #-65536,-8(fp),r0
6161 ashl #16,r0,r1
6162 addl2 r1,r6
6163 bicl2 #0,r6
6164 cmpl r6,r1
6165 bgequ noname.567
6166 incl r4
6167noname.567:
6168 movl r6,r3
6169 movl r4,r2
6170 bbc #31,r2,noname.568
6171 incl r9
6172noname.568:
6173 addl2 r2,r2
6174 bicl2 #0,r2
6175 bbc #31,r3,noname.569
6176 incl r2
6177noname.569:
6178 addl2 r3,r3
6179 bicl2 #0,r3
6180 addl2 r3,r8
6181 bicl2 #0,r8
6182 cmpl r8,r3
6183 bgequ noname.570
6184 incl r2
6185 bicl3 #0,r2,r0
6186 bneq noname.570
6187 incl r9
6188noname.570:
6189 addl2 r2,r10
6190 bicl2 #0,r10
6191 cmpl r10,r2
6192 bgequ noname.571
6193 incl r9
6194noname.571:
6195
6196 movl 4(ap),r0
6197 movl r8,4(r0)
6198
6199 clrl r8
6200
6201 movl 8(ap),r4
6202 movl 4(r4),r3
6203 bicl3 #-65536,r3,r5
6204 extzv #16,#16,r3,r0
6205 bicl3 #-65536,r0,r3
6206 mull3 r5,r3,r1
6207 mull2 r5,r5
6208 mull2 r3,r3
6209 bicl3 #32767,r1,r0
6210 extzv #15,#17,r0,r0
6211 addl2 r0,r3
6212 bicl2 #-65536,r1
6213 ashl #17,r1,r1
6214 addl2 r1,r5
6215 bicl2 #0,r5
6216 cmpl r5,r1
6217 bgequ noname.572
6218 incl r3
6219noname.572:
6220 movl r5,r1
6221 movl r3,r2
6222 addl2 r1,r10
6223 bicl2 #0,r10
6224 cmpl r10,r1
6225 bgequ noname.573
6226 incl r2
6227noname.573:
6228 addl2 r2,r9
6229 bicl2 #0,r9
6230 cmpl r9,r2
6231 bgequ noname.574
6232 incl r8
6233noname.574:
6234
6235 bicl3 #-65536,8(r4),r3
6236 movzwl 10(r4),r1
6237 bicl2 #-65536,r1
6238 bicl3 #-65536,(r4),r2
6239 movzwl 2(r4),r0
6240 bicl2 #-65536,r0
6241 movl r3,r6
6242 movl r1,r5
6243 mull3 r0,r6,r7
6244 mull2 r2,r6
6245 mull2 r5,r2
6246 mull2 r0,r5
6247 addl2 r2,r7
6248 bicl2 #0,r7
6249 cmpl r7,r2
6250 bgequ noname.575
6251 addl2 #65536,r5
6252noname.575:
6253 extzv #16,#16,r7,r0
6254 bicl2 #-65536,r0
6255 addl2 r0,r5
6256 bicl3 #-65536,r7,r0
6257 ashl #16,r0,r1
6258 addl2 r1,r6
6259 bicl2 #0,r6
6260 cmpl r6,r1
6261 bgequ noname.576
6262 incl r5
6263noname.576:
6264 movl r6,r3
6265 movl r5,r2
6266 bbc #31,r2,noname.577
6267 incl r8
6268noname.577:
6269 addl2 r2,r2
6270 bicl2 #0,r2
6271 bbc #31,r3,noname.578
6272 incl r2
6273noname.578:
6274 addl2 r3,r3
6275 bicl2 #0,r3
6276 addl2 r3,r10
6277 bicl2 #0,r10
6278 cmpl r10,r3
6279 bgequ noname.579
6280 incl r2
6281 bicl3 #0,r2,r0
6282 bneq noname.579
6283 incl r8
6284noname.579:
6285 addl2 r2,r9
6286 bicl2 #0,r9
6287 cmpl r9,r2
6288 bgequ noname.580
6289 incl r8
6290noname.580:
6291
6292 movl 4(ap),r0
6293 movl r10,8(r0)
6294
6295 clrl r10
6296
6297 movl 8(ap),r0
6298 bicl3 #-65536,12(r0),r3
6299 movzwl 14(r0),r1
6300 bicl2 #-65536,r1
6301 bicl3 #-65536,(r0),r2
6302 movzwl 2(r0),r0
6303 bicl2 #-65536,r0
6304 movl r3,r5
6305 movl r1,r4
6306 mull3 r0,r5,r6
6307 mull2 r2,r5
6308 mull3 r2,r4,-12(fp)
6309 mull2 r0,r4
6310 addl2 -12(fp),r6
6311 bicl2 #0,r6
6312 cmpl r6,-12(fp)
6313 bgequ noname.581
6314 addl2 #65536,r4
6315noname.581:
6316 extzv #16,#16,r6,r0
6317 bicl2 #-65536,r0
6318 addl2 r0,r4
6319 bicl3 #-65536,r6,r0
6320 ashl #16,r0,-12(fp)
6321 addl2 -12(fp),r5
6322 bicl2 #0,r5
6323 cmpl r5,-12(fp)
6324 bgequ noname.582
6325 incl r4
6326noname.582:
6327 movl r5,r3
6328 movl r4,r2
6329 bbc #31,r2,noname.583
6330 incl r10
6331noname.583:
6332 addl2 r2,r2
6333 bicl2 #0,r2
6334 bbc #31,r3,noname.584
6335 incl r2
6336noname.584:
6337 addl2 r3,r3
6338 bicl2 #0,r3
6339 addl2 r3,r9
6340 bicl2 #0,r9
6341 cmpl r9,r3
6342 bgequ noname.585
6343 incl r2
6344 bicl3 #0,r2,r0
6345 bneq noname.585
6346 incl r10
6347noname.585:
6348 addl2 r2,r8
6349 bicl2 #0,r8
6350 cmpl r8,r2
6351 bgequ noname.586
6352 incl r10
6353noname.586:
6354
6355 movl 8(ap),r0
6356 bicl3 #-65536,8(r0),r3
6357 movzwl 10(r0),r1
6358 bicl2 #-65536,r1
6359 bicl3 #-65536,4(r0),r2
6360 movzwl 6(r0),r0
6361 bicl2 #-65536,r0
6362 movl r3,r5
6363 movl r1,r4
6364 mull3 r0,r5,-16(fp)
6365 mull2 r2,r5
6366 mull3 r2,r4,-20(fp)
6367 mull2 r0,r4
6368 addl3 -16(fp),-20(fp),r0
6369 bicl3 #0,r0,-16(fp)
6370 cmpl -16(fp),-20(fp)
6371 bgequ noname.587
6372 addl2 #65536,r4
6373noname.587:
6374 movzwl -14(fp),r0
6375 bicl2 #-65536,r0
6376 addl2 r0,r4
6377 bicl3 #-65536,-16(fp),r0
6378 ashl #16,r0,-20(fp)
6379 addl2 -20(fp),r5
6380 bicl2 #0,r5
6381 cmpl r5,-20(fp)
6382 bgequ noname.588
6383 incl r4
6384noname.588:
6385 movl r5,r3
6386 movl r4,r2
6387 bbc #31,r2,noname.589
6388 incl r10
6389noname.589:
6390 addl2 r2,r2
6391 bicl2 #0,r2
6392 bbc #31,r3,noname.590
6393 incl r2
6394noname.590:
6395 addl2 r3,r3
6396 bicl2 #0,r3
6397 addl2 r3,r9
6398 bicl2 #0,r9
6399 cmpl r9,r3
6400 bgequ noname.591
6401 incl r2
6402 bicl3 #0,r2,r0
6403 bneq noname.591
6404 incl r10
6405noname.591:
6406 addl2 r2,r8
6407 bicl2 #0,r8
6408 cmpl r8,r2
6409 bgequ noname.592
6410 incl r10
6411noname.592:
6412 movl 4(ap),r0
6413 movl r9,12(r0)
6414
6415 clrl r9
6416
6417 movl 8(ap),r3
6418 movl 8(r3),r4
6419 bicl3 #-65536,r4,r5
6420 extzv #16,#16,r4,r0
6421 bicl3 #-65536,r0,r4
6422 mull3 r5,r4,-24(fp)
6423 mull2 r5,r5
6424 mull2 r4,r4
6425 bicl3 #32767,-24(fp),r0
6426 extzv #15,#17,r0,r0
6427 addl2 r0,r4
6428 bicl3 #-65536,-24(fp),r0
6429 ashl #17,r0,-24(fp)
6430 addl2 -24(fp),r5
6431 bicl2 #0,r5
6432 cmpl r5,-24(fp)
6433 bgequ noname.593
6434 incl r4
6435noname.593:
6436 movl r5,r1
6437 movl r4,r2
6438 addl2 r1,r8
6439 bicl2 #0,r8
6440 cmpl r8,r1
6441 bgequ noname.594
6442 incl r2
6443noname.594:
6444 addl2 r2,r10
6445 bicl2 #0,r10
6446 cmpl r10,r2
6447 bgequ noname.595
6448 incl r9
6449noname.595:
6450
6451 bicl3 #-65536,12(r3),r4
6452 movzwl 14(r3),r1
6453 bicl2 #-65536,r1
6454 bicl3 #-65536,4(r3),r2
6455 movzwl 6(r3),r0
6456 bicl2 #-65536,r0
6457 movl r4,r6
6458 movl r1,r5
6459 mull3 r0,r6,-28(fp)
6460 mull2 r2,r6
6461 mull3 r2,r5,-32(fp)
6462 mull2 r0,r5
6463 addl3 -28(fp),-32(fp),r0
6464 bicl3 #0,r0,-28(fp)
6465 cmpl -28(fp),-32(fp)
6466 bgequ noname.596
6467 addl2 #65536,r5
6468noname.596:
6469 movzwl -26(fp),r0
6470 bicl2 #-65536,r0
6471 addl2 r0,r5
6472 bicl3 #-65536,-28(fp),r0
6473 ashl #16,r0,-32(fp)
6474 addl2 -32(fp),r6
6475 bicl2 #0,r6
6476 cmpl r6,-32(fp)
6477 bgequ noname.597
6478 incl r5
6479noname.597:
6480 movl r6,r3
6481 movl r5,r2
6482 bbc #31,r2,noname.598
6483 incl r9
6484noname.598:
6485 addl2 r2,r2
6486 bicl2 #0,r2
6487 bbc #31,r3,noname.599
6488 incl r2
6489noname.599:
6490 addl2 r3,r3
6491 bicl2 #0,r3
6492 addl2 r3,r8
6493 bicl2 #0,r8
6494 cmpl r8,r3
6495 bgequ noname.600
6496 incl r2
6497 bicl3 #0,r2,r0
6498 bneq noname.600
6499 incl r9
6500noname.600:
6501 addl2 r2,r10
6502 bicl2 #0,r10
6503 cmpl r10,r2
6504 bgequ noname.601
6505 incl r9
6506noname.601:
6507
6508 movl 4(ap),r0
6509 movl r8,16(r0)
6510
6511 clrl r8
6512
6513 movl 8(ap),r0
6514 bicl3 #-65536,12(r0),r3
6515 movzwl 14(r0),r1
6516 bicl2 #-65536,r1
6517 bicl3 #-65536,8(r0),r2
6518 movzwl 10(r0),r0
6519 bicl2 #-65536,r0
6520 movl r3,r5
6521 movl r1,r4
6522 mull3 r0,r5,-36(fp)
6523 mull2 r2,r5
6524 mull3 r2,r4,-40(fp)
6525 mull2 r0,r4
6526 addl3 -36(fp),-40(fp),r0
6527 bicl3 #0,r0,-36(fp)
6528 cmpl -36(fp),-40(fp)
6529 bgequ noname.602
6530 addl2 #65536,r4
6531noname.602:
6532 movzwl -34(fp),r0
6533 bicl2 #-65536,r0
6534 addl2 r0,r4
6535 bicl3 #-65536,-36(fp),r0
6536 ashl #16,r0,-40(fp)
6537 addl2 -40(fp),r5
6538 bicl2 #0,r5
6539 cmpl r5,-40(fp)
6540 bgequ noname.603
6541 incl r4
6542noname.603:
6543 movl r5,r3
6544 movl r4,r2
6545 bbc #31,r2,noname.604
6546 incl r8
6547noname.604:
6548 addl2 r2,r2
6549 bicl2 #0,r2
6550 bbc #31,r3,noname.605
6551 incl r2
6552noname.605:
6553 addl2 r3,r3
6554 bicl2 #0,r3
6555 addl2 r3,r10
6556 bicl2 #0,r10
6557 cmpl r10,r3
6558 bgequ noname.606
6559 incl r2
6560 bicl3 #0,r2,r0
6561 bneq noname.606
6562 incl r8
6563noname.606:
6564 addl2 r2,r9
6565 bicl2 #0,r9
6566 cmpl r9,r2
6567 bgequ noname.607
6568 incl r8
6569noname.607:
6570
6571 movl 4(ap),r4
6572 movl r10,20(r4)
6573
6574 clrl r10
6575
6576 movl 8(ap),r0
6577 movl 12(r0),r3
6578 bicl3 #-65536,r3,r5
6579 extzv #16,#16,r3,r0
6580 bicl3 #-65536,r0,r3
6581 mull3 r5,r3,-44(fp)
6582 mull2 r5,r5
6583 mull2 r3,r3
6584 bicl3 #32767,-44(fp),r0
6585 extzv #15,#17,r0,r0
6586 addl2 r0,r3
6587 bicl3 #-65536,-44(fp),r0
6588 ashl #17,r0,-44(fp)
6589 addl2 -44(fp),r5
6590 bicl2 #0,r5
6591 cmpl r5,-44(fp)
6592 bgequ noname.608
6593 incl r3
6594noname.608:
6595 movl r5,r1
6596 movl r3,r2
6597 addl2 r1,r9
6598 bicl2 #0,r9
6599 cmpl r9,r1
6600 bgequ noname.609
6601 incl r2
6602noname.609:
6603 addl2 r2,r8
6604 bicl2 #0,r8
6605 cmpl r8,r2
6606 bgequ noname.610
6607 incl r10
6608noname.610:
6609
6610 movl r9,24(r4)
6611
6612 movl r8,28(r4)
6613
6614 ret
6615
6616; For now, the code below doesn't work, so I end this prematurely.
6617.end
6618
6619 .title vax_bn_div64 division 64/32=>32
6620;
6621; r.l. 16-jan-1998
6622;
6623; unsigned int bn_div64(unsigned long h, unsigned long l, unsigned long d)
6624; return <h,l>/d;
6625;
6626
6627 .psect code,nowrt
6628
6629h=4 ;(AP) by value (input)
6630l=8 ;(AP) by value (input)
6631d=12 ;(AP) by value (input)
6632
6633.entry bn_div64,^m<r2,r3,r4,r5,r6,r7,r8,r9>
6634
6635 movl l(ap),r2 ; l
6636 movl h(ap),r3 ; h
6637 movl d(ap),r4 ; d
6638 clrl r5 ; q
6639 clrl r6 ; r
6640
6641 ; Treat "negative" specially
6642 tstl r3
6643 blss 30$
6644
6645 tstl r4
6646 beql 90$
6647
6648 ediv r4,r2,r5,r6
6649 bvs 666$
6650
6651 movl r5,r0
6652 ret
6653
665430$:
6655 ; The theory here is to do some harmless shifting and a little
6656 ; bit of rounding (brackets are to designate when decimals are
6657 ; cut off):
6658 ;
6659 ; result = 2 * [ ([<h,0>/2] + [d/2]) / d ] + [ l / d ]
6660
6661 movl #0,r7
6662 movl r3,r8 ; copy h
6663 ashq #-1,r7,r7 ; [<h,0>/2] => <r8,r7>
6664 bicl2 #^X80000000,r8 ; Remove "sign"
6665
6666 movl r4,r9 ; copy d
6667 ashl #-1,r9,r9 ; [d/2] => r9
6668 bicl2 #^X80000000,r9 ; Remove "sign"
6669
6670 addl2 r9,r7
6671 adwc #0,r8 ; [<h,0>/2] + [d/2] => <r8,r7>
6672
6673 ediv r4,r7,r5,r6 ; [ ([<h,0>/2] + [d/2]) / d ] => <r5,r6>
6674 bvs 666$
6675
6676 movl #0,r6
6677 ashq #1,r5,r5 ; 2 * [ ([<h,0>/2] + [d/2]) / d ] => r5
6678
6679 movl #0,r3
6680 ediv r4,r2,r8,r9 ; [ l / d ] => <r8,r9>
6681
6682 addl2 r8,r5 ;
6683 bcs 666$
6684
6685 movl r5,r0
6686 ret
6687
668890$:
6689 movl #-1,r0
6690 ret
6691
6692666$:
6693
6694
6695.end
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86.pl b/src/lib/libssl/src/crypto/bn/asm/x86.pl
new file mode 100644
index 0000000000..1bc4f1bb27
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86.pl
@@ -0,0 +1,28 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6require("x86/mul_add.pl");
7require("x86/mul.pl");
8require("x86/sqr.pl");
9require("x86/div.pl");
10require("x86/add.pl");
11require("x86/sub.pl");
12require("x86/comba.pl");
13
14&asm_init($ARGV[0],$0);
15
16&bn_mul_add_words("bn_mul_add_words");
17&bn_mul_words("bn_mul_words");
18&bn_sqr_words("bn_sqr_words");
19&bn_div_words("bn_div_words");
20&bn_add_words("bn_add_words");
21&bn_sub_words("bn_sub_words");
22&bn_mul_comba("bn_mul_comba8",8);
23&bn_mul_comba("bn_mul_comba4",4);
24&bn_sqr_comba("bn_sqr_comba8",8);
25&bn_sqr_comba("bn_sqr_comba4",4);
26
27&asm_finish();
28
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/add.pl b/src/lib/libssl/src/crypto/bn/asm/x86/add.pl
new file mode 100644
index 0000000000..0b5cf583e3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/add.pl
@@ -0,0 +1,76 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &add($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &add($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &add($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &add($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/comba.pl b/src/lib/libssl/src/crypto/bn/asm/x86/comba.pl
new file mode 100644
index 0000000000..2291253629
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/comba.pl
@@ -0,0 +1,277 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub mul_add_c
5 {
6 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
7
8 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
9 # words, and 1 if load return value
10
11 &comment("mul a[$ai]*b[$bi]");
12
13 # "eax" and "edx" will always be pre-loaded.
14 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
15 # &mov("edx",&DWP($bi*4,$b,"",0));
16
17 &mul("edx");
18 &add($c0,"eax");
19 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
20 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
21 ###
22 &adc($c1,"edx");
23 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
24 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
25 ###
26 &adc($c2,0);
27 # is pos > 1, it means it is the last loop
28 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
29 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
30 }
31
32sub sqr_add_c
33 {
34 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
35
36 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
37 # words, and 1 if load return value
38
39 &comment("sqr a[$ai]*a[$bi]");
40
41 # "eax" and "edx" will always be pre-loaded.
42 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
43 # &mov("edx",&DWP($bi*4,$b,"",0));
44
45 if ($ai == $bi)
46 { &mul("eax");}
47 else
48 { &mul("edx");}
49 &add($c0,"eax");
50 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
51 ###
52 &adc($c1,"edx");
53 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
54 ###
55 &adc($c2,0);
56 # is pos > 1, it means it is the last loop
57 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
58 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
59 }
60
61sub sqr_add_c2
62 {
63 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
64
65 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
66 # words, and 1 if load return value
67
68 &comment("sqr a[$ai]*a[$bi]");
69
70 # "eax" and "edx" will always be pre-loaded.
71 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
72 # &mov("edx",&DWP($bi*4,$a,"",0));
73
74 if ($ai == $bi)
75 { &mul("eax");}
76 else
77 { &mul("edx");}
78 &add("eax","eax");
79 ###
80 &adc("edx","edx");
81 ###
82 &adc($c2,0);
83 &add($c0,"eax");
84 &adc($c1,"edx");
85 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
86 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
87 &adc($c2,0);
88 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
89 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
90 ###
91 }
92
93sub bn_mul_comba
94 {
95 local($name,$num)=@_;
96 local($a,$b,$c0,$c1,$c2);
97 local($i,$as,$ae,$bs,$be,$ai,$bi);
98 local($tot,$end);
99
100 &function_begin_B($name,"");
101
102 $c0="ebx";
103 $c1="ecx";
104 $c2="ebp";
105 $a="esi";
106 $b="edi";
107
108 $as=0;
109 $ae=0;
110 $bs=0;
111 $be=0;
112 $tot=$num+$num-1;
113
114 &push("esi");
115 &mov($a,&wparam(1));
116 &push("edi");
117 &mov($b,&wparam(2));
118 &push("ebp");
119 &push("ebx");
120
121 &xor($c0,$c0);
122 &mov("eax",&DWP(0,$a,"",0)); # load the first word
123 &xor($c1,$c1);
124 &mov("edx",&DWP(0,$b,"",0)); # load the first second
125
126 for ($i=0; $i<$tot; $i++)
127 {
128 $ai=$as;
129 $bi=$bs;
130 $end=$be+1;
131
132 &comment("################## Calculate word $i");
133
134 for ($j=$bs; $j<$end; $j++)
135 {
136 &xor($c2,$c2) if ($j == $bs);
137 if (($j+1) == $end)
138 {
139 $v=1;
140 $v=2 if (($i+1) == $tot);
141 }
142 else
143 { $v=0; }
144 if (($j+1) != $end)
145 {
146 $na=($ai-1);
147 $nb=($bi+1);
148 }
149 else
150 {
151 $na=$as+($i < ($num-1));
152 $nb=$bs+($i >= ($num-1));
153 }
154#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
155 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
156 if ($v)
157 {
158 &comment("saved r[$i]");
159 # &mov("eax",&wparam(0));
160 # &mov(&DWP($i*4,"eax","",0),$c0);
161 ($c0,$c1,$c2)=($c1,$c2,$c0);
162 }
163 $ai--;
164 $bi++;
165 }
166 $as++ if ($i < ($num-1));
167 $ae++ if ($i >= ($num-1));
168
169 $bs++ if ($i >= ($num-1));
170 $be++ if ($i < ($num-1));
171 }
172 &comment("save r[$i]");
173 # &mov("eax",&wparam(0));
174 &mov(&DWP($i*4,"eax","",0),$c0);
175
176 &pop("ebx");
177 &pop("ebp");
178 &pop("edi");
179 &pop("esi");
180 &ret();
181 &function_end_B($name);
182 }
183
184sub bn_sqr_comba
185 {
186 local($name,$num)=@_;
187 local($r,$a,$c0,$c1,$c2)=@_;
188 local($i,$as,$ae,$bs,$be,$ai,$bi);
189 local($b,$tot,$end,$half);
190
191 &function_begin_B($name,"");
192
193 $c0="ebx";
194 $c1="ecx";
195 $c2="ebp";
196 $a="esi";
197 $r="edi";
198
199 &push("esi");
200 &push("edi");
201 &push("ebp");
202 &push("ebx");
203 &mov($r,&wparam(0));
204 &mov($a,&wparam(1));
205 &xor($c0,$c0);
206 &xor($c1,$c1);
207 &mov("eax",&DWP(0,$a,"",0)); # load the first word
208
209 $as=0;
210 $ae=0;
211 $bs=0;
212 $be=0;
213 $tot=$num+$num-1;
214
215 for ($i=0; $i<$tot; $i++)
216 {
217 $ai=$as;
218 $bi=$bs;
219 $end=$be+1;
220
221 &comment("############### Calculate word $i");
222 for ($j=$bs; $j<$end; $j++)
223 {
224 &xor($c2,$c2) if ($j == $bs);
225 if (($ai-1) < ($bi+1))
226 {
227 $v=1;
228 $v=2 if ($i+1) == $tot;
229 }
230 else
231 { $v=0; }
232 if (!$v)
233 {
234 $na=$ai-1;
235 $nb=$bi+1;
236 }
237 else
238 {
239 $na=$as+($i < ($num-1));
240 $nb=$bs+($i >= ($num-1));
241 }
242 if ($ai == $bi)
243 {
244 &sqr_add_c($r,$a,$ai,$bi,
245 $c0,$c1,$c2,$v,$i,$na,$nb);
246 }
247 else
248 {
249 &sqr_add_c2($r,$a,$ai,$bi,
250 $c0,$c1,$c2,$v,$i,$na,$nb);
251 }
252 if ($v)
253 {
254 &comment("saved r[$i]");
255 #&mov(&DWP($i*4,$r,"",0),$c0);
256 ($c0,$c1,$c2)=($c1,$c2,$c0);
257 last;
258 }
259 $ai--;
260 $bi++;
261 }
262 $as++ if ($i < ($num-1));
263 $ae++ if ($i >= ($num-1));
264
265 $bs++ if ($i >= ($num-1));
266 $be++ if ($i < ($num-1));
267 }
268 &mov(&DWP($i*4,$r,"",0),$c0);
269 &pop("ebx");
270 &pop("ebp");
271 &pop("edi");
272 &pop("esi");
273 &ret();
274 &function_end_B($name);
275 }
276
2771;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/div.pl b/src/lib/libssl/src/crypto/bn/asm/x86/div.pl
new file mode 100644
index 0000000000..0e90152caa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/div.pl
@@ -0,0 +1,15 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_div_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9 &mov("edx",&wparam(0)); #
10 &mov("eax",&wparam(1)); #
11 &mov("ebx",&wparam(2)); #
12 &div("ebx");
13 &function_end($name);
14 }
151;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/f b/src/lib/libssl/src/crypto/bn/asm/x86/f
new file mode 100644
index 0000000000..22e4112224
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/f
@@ -0,0 +1,3 @@
1#!/usr/local/bin/perl
2# x86 assember
3
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/mul.pl b/src/lib/libssl/src/crypto/bn/asm/x86/mul.pl
new file mode 100644
index 0000000000..674cb9b055
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/mul.pl
@@ -0,0 +1,77 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ecx";
15 $r="edi";
16 $c="esi";
17 $num="ebp";
18
19 &xor($c,$c); # clear carry
20 &mov($r,&wparam(0)); #
21 &mov($a,&wparam(1)); #
22 &mov($num,&wparam(2)); #
23 &mov($w,&wparam(3)); #
24
25 &and($num,0xfffffff8); # num / 8
26 &jz(&label("mw_finish"));
27
28 &set_label("mw_loop",0);
29 for ($i=0; $i<32; $i+=4)
30 {
31 &comment("Round $i");
32
33 &mov("eax",&DWP($i,$a,"",0)); # *a
34 &mul($w); # *a * w
35 &add("eax",$c); # L(t)+=c
36 # XXX
37
38 &adc("edx",0); # H(t)+=carry
39 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
40
41 &mov($c,"edx"); # c= H(t);
42 }
43
44 &comment("");
45 &add($a,32);
46 &add($r,32);
47 &sub($num,8);
48 &jz(&label("mw_finish"));
49 &jmp(&label("mw_loop"));
50
51 &set_label("mw_finish",0);
52 &mov($num,&wparam(2)); # get num
53 &and($num,7);
54 &jnz(&label("mw_finish2"));
55 &jmp(&label("mw_end"));
56
57 &set_label("mw_finish2",1);
58 for ($i=0; $i<7; $i++)
59 {
60 &comment("Tail Round $i");
61 &mov("eax",&DWP($i*4,$a,"",0));# *a
62 &mul($w); # *a * w
63 &add("eax",$c); # L(t)+=c
64 # XXX
65 &adc("edx",0); # H(t)+=carry
66 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
67 &mov($c,"edx"); # c= H(t);
68 &dec($num) if ($i != 7-1);
69 &jz(&label("mw_end")) if ($i != 7-1);
70 }
71 &set_label("mw_end",0);
72 &mov("eax",$c);
73
74 &function_end($name);
75 }
76
771;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/mul_add.pl b/src/lib/libssl/src/crypto/bn/asm/x86/mul_add.pl
new file mode 100644
index 0000000000..61830d3a90
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/mul_add.pl
@@ -0,0 +1,87 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ebp";
15 $r="edi";
16 $c="esi";
17
18 &xor($c,$c); # clear carry
19 &mov($r,&wparam(0)); #
20
21 &mov("ecx",&wparam(2)); #
22 &mov($a,&wparam(1)); #
23
24 &and("ecx",0xfffffff8); # num / 8
25 &mov($w,&wparam(3)); #
26
27 &push("ecx"); # Up the stack for a tmp variable
28
29 &jz(&label("maw_finish"));
30
31 &set_label("maw_loop",0);
32
33 &mov(&swtmp(0),"ecx"); #
34
35 for ($i=0; $i<32; $i+=4)
36 {
37 &comment("Round $i");
38
39 &mov("eax",&DWP($i,$a,"",0)); # *a
40 &mul($w); # *a * w
41 &add("eax",$c); # L(t)+= *r
42 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
43 &adc("edx",0); # H(t)+=carry
44 &add("eax",$c); # L(t)+=c
45 &adc("edx",0); # H(t)+=carry
46 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
47 &mov($c,"edx"); # c= H(t);
48 }
49
50 &comment("");
51 &mov("ecx",&swtmp(0)); #
52 &add($a,32);
53 &add($r,32);
54 &sub("ecx",8);
55 &jnz(&label("maw_loop"));
56
57 &set_label("maw_finish",0);
58 &mov("ecx",&wparam(2)); # get num
59 &and("ecx",7);
60 &jnz(&label("maw_finish2")); # helps branch prediction
61 &jmp(&label("maw_end"));
62
63 &set_label("maw_finish2",1);
64 for ($i=0; $i<7; $i++)
65 {
66 &comment("Tail Round $i");
67 &mov("eax",&DWP($i*4,$a,"",0));# *a
68 &mul($w); # *a * w
69 &add("eax",$c); # L(t)+=c
70 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
71 &adc("edx",0); # H(t)+=carry
72 &add("eax",$c);
73 &adc("edx",0); # H(t)+=carry
74 &dec("ecx") if ($i != 7-1);
75 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
76 &mov($c,"edx"); # c= H(t);
77 &jz(&label("maw_end")) if ($i != 7-1);
78 }
79 &set_label("maw_end",0);
80 &mov("eax",$c);
81
82 &pop("ecx"); # clear variable from
83
84 &function_end($name);
85 }
86
871;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/sqr.pl b/src/lib/libssl/src/crypto/bn/asm/x86/sqr.pl
new file mode 100644
index 0000000000..1f90993cf6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/sqr.pl
@@ -0,0 +1,60 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $r="esi";
12 $a="edi";
13 $num="ebx";
14
15 &mov($r,&wparam(0)); #
16 &mov($a,&wparam(1)); #
17 &mov($num,&wparam(2)); #
18
19 &and($num,0xfffffff8); # num / 8
20 &jz(&label("sw_finish"));
21
22 &set_label("sw_loop",0);
23 for ($i=0; $i<32; $i+=4)
24 {
25 &comment("Round $i");
26 &mov("eax",&DWP($i,$a,"",0)); # *a
27 # XXX
28 &mul("eax"); # *a * *a
29 &mov(&DWP($i*2,$r,"",0),"eax"); #
30 &mov(&DWP($i*2+4,$r,"",0),"edx");#
31 }
32
33 &comment("");
34 &add($a,32);
35 &add($r,64);
36 &sub($num,8);
37 &jnz(&label("sw_loop"));
38
39 &set_label("sw_finish",0);
40 &mov($num,&wparam(2)); # get num
41 &and($num,7);
42 &jz(&label("sw_end"));
43
44 for ($i=0; $i<7; $i++)
45 {
46 &comment("Tail Round $i");
47 &mov("eax",&DWP($i*4,$a,"",0)); # *a
48 # XXX
49 &mul("eax"); # *a * *a
50 &mov(&DWP($i*8,$r,"",0),"eax"); #
51 &dec($num) if ($i != 7-1);
52 &mov(&DWP($i*8+4,$r,"",0),"edx");
53 &jz(&label("sw_end")) if ($i != 7-1);
54 }
55 &set_label("sw_end",0);
56
57 &function_end($name);
58 }
59
601;
diff --git a/src/lib/libssl/src/crypto/bn/asm/x86/sub.pl b/src/lib/libssl/src/crypto/bn/asm/x86/sub.pl
new file mode 100644
index 0000000000..837b0e1b07
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/x86/sub.pl
@@ -0,0 +1,76 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &sub($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &sub($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &sub($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &sub($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libssl/src/crypto/bn/bn.h b/src/lib/libssl/src/crypto/bn/bn.h
new file mode 100644
index 0000000000..f935e1ca79
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn.h
@@ -0,0 +1,467 @@
1/* crypto/bn/bn.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BN_H
60#define HEADER_BN_H
61
62#ifndef WIN16
63#include <stdio.h> /* FILE */
64#endif
65#include <openssl/opensslconf.h>
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#ifdef VMS
72#undef BN_LLONG /* experimental, so far... */
73#endif
74
75#define BN_MUL_COMBA
76#define BN_SQR_COMBA
77#define BN_RECURSION
78#define RECP_MUL_MOD
79#define MONT_MUL_MOD
80
81/* This next option uses the C libraries (2 word)/(1 word) function.
82 * If it is not defined, I use my C version (which is slower).
83 * The reason for this flag is that when the particular C compiler
84 * library routine is used, and the library is linked with a different
85 * compiler, the library is missing. This mostly happens when the
86 * library is built with gcc and then linked using nornal cc. This would
87 * be a common occurance because gcc normally produces code that is
88 * 2 times faster than system compilers for the big number stuff.
89 * For machines with only one compiler (or shared libraries), this should
90 * be on. Again this in only really a problem on machines
91 * using "long long's", are 32bit, and are not using my assember code. */
92#if defined(MSDOS) || defined(WINDOWS) || defined(linux)
93#define BN_DIV2W
94#endif
95
96/* assuming long is 64bit - this is the DEC Alpha
97 * unsigned long long is only 64 bits :-(, don't define
98 * BN_LLONG for the DEC Alpha */
99#ifdef SIXTY_FOUR_BIT_LONG
100#define BN_ULLONG unsigned long long
101#define BN_ULONG unsigned long
102#define BN_LONG long
103#define BN_BITS 128
104#define BN_BYTES 8
105#define BN_BITS2 64
106#define BN_BITS4 32
107#define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
108#define BN_MASK2 (0xffffffffffffffffL)
109#define BN_MASK2l (0xffffffffL)
110#define BN_MASK2h (0xffffffff00000000L)
111#define BN_MASK2h1 (0xffffffff80000000L)
112#define BN_TBIT (0x8000000000000000L)
113#define BN_DEC_CONV (10000000000000000000UL)
114#define BN_DEC_FMT1 "%lu"
115#define BN_DEC_FMT2 "%019lu"
116#define BN_DEC_NUM 19
117#endif
118
119/* This is where the long long data type is 64 bits, but long is 32.
120 * For machines where there are 64bit registers, this is the mode to use.
121 * IRIX, on R4000 and above should use this mode, along with the relevent
122 * assember code :-). Do NOT define BN_LLONG.
123 */
124#ifdef SIXTY_FOUR_BIT
125#undef BN_LLONG
126#undef BN_ULLONG
127#define BN_ULONG unsigned long long
128#define BN_LONG long long
129#define BN_BITS 128
130#define BN_BYTES 8
131#define BN_BITS2 64
132#define BN_BITS4 32
133#define BN_MASK2 (0xffffffffffffffffLL)
134#define BN_MASK2l (0xffffffffL)
135#define BN_MASK2h (0xffffffff00000000LL)
136#define BN_MASK2h1 (0xffffffff80000000LL)
137#define BN_TBIT (0x8000000000000000LL)
138#define BN_DEC_CONV (10000000000000000000LL)
139#define BN_DEC_FMT1 "%llu"
140#define BN_DEC_FMT2 "%019llu"
141#define BN_DEC_NUM 19
142#endif
143
144#ifdef THIRTY_TWO_BIT
145#if defined(WIN32) && !defined(__GNUC__)
146#define BN_ULLONG unsigned _int64
147#else
148#define BN_ULLONG unsigned long long
149#endif
150#define BN_ULONG unsigned long
151#define BN_LONG long
152#define BN_BITS 64
153#define BN_BYTES 4
154#define BN_BITS2 32
155#define BN_BITS4 16
156#ifdef WIN32
157/* VC++ doesn't like the LL suffix */
158#define BN_MASK (0xffffffffffffffffL)
159#else
160#define BN_MASK (0xffffffffffffffffLL)
161#endif
162#define BN_MASK2 (0xffffffffL)
163#define BN_MASK2l (0xffff)
164#define BN_MASK2h1 (0xffff8000L)
165#define BN_MASK2h (0xffff0000L)
166#define BN_TBIT (0x80000000L)
167#define BN_DEC_CONV (1000000000L)
168#define BN_DEC_FMT1 "%lu"
169#define BN_DEC_FMT2 "%09lu"
170#define BN_DEC_NUM 9
171#endif
172
173#ifdef SIXTEEN_BIT
174#ifndef BN_DIV2W
175#define BN_DIV2W
176#endif
177#define BN_ULLONG unsigned long
178#define BN_ULONG unsigned short
179#define BN_LONG short
180#define BN_BITS 32
181#define BN_BYTES 2
182#define BN_BITS2 16
183#define BN_BITS4 8
184#define BN_MASK (0xffffffff)
185#define BN_MASK2 (0xffff)
186#define BN_MASK2l (0xff)
187#define BN_MASK2h1 (0xff80)
188#define BN_MASK2h (0xff00)
189#define BN_TBIT (0x8000)
190#define BN_DEC_CONV (100000)
191#define BN_DEC_FMT1 "%u"
192#define BN_DEC_FMT2 "%05u"
193#define BN_DEC_NUM 5
194#endif
195
196#ifdef EIGHT_BIT
197#ifndef BN_DIV2W
198#define BN_DIV2W
199#endif
200#define BN_ULLONG unsigned short
201#define BN_ULONG unsigned char
202#define BN_LONG char
203#define BN_BITS 16
204#define BN_BYTES 1
205#define BN_BITS2 8
206#define BN_BITS4 4
207#define BN_MASK (0xffff)
208#define BN_MASK2 (0xff)
209#define BN_MASK2l (0xf)
210#define BN_MASK2h1 (0xf8)
211#define BN_MASK2h (0xf0)
212#define BN_TBIT (0x80)
213#define BN_DEC_CONV (100)
214#define BN_DEC_FMT1 "%u"
215#define BN_DEC_FMT2 "%02u"
216#define BN_DEC_NUM 2
217#endif
218
219#define BN_DEFAULT_BITS 1280
220
221#ifdef BIGNUM
222#undef BIGNUM
223#endif
224
225#define BN_FLG_MALLOCED 0x01
226#define BN_FLG_STATIC_DATA 0x02
227#define BN_FLG_FREE 0x8000 /* used for debuging */
228#define BN_set_flags(b,n) ((b)->flags|=(n))
229#define BN_get_flags(b,n) ((b)->flags&(n))
230
231typedef struct bignum_st
232 {
233 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
234 int top; /* Index of last used d +1. */
235 /* The next are internal book keeping for bn_expand. */
236 int max; /* Size of the d array. */
237 int neg; /* one if the number is negative */
238 int flags;
239 } BIGNUM;
240
241/* Used for temp variables */
242#define BN_CTX_NUM 12
243typedef struct bignum_ctx
244 {
245 int tos;
246 BIGNUM bn[BN_CTX_NUM+1];
247 int flags;
248 } BN_CTX;
249
250typedef struct bn_blinding_st
251 {
252 int init;
253 BIGNUM *A;
254 BIGNUM *Ai;
255 BIGNUM *mod; /* just a reference */
256 } BN_BLINDING;
257
258/* Used for montgomery multiplication */
259typedef struct bn_mont_ctx_st
260 {
261 int use_word; /* 0 for word form, 1 for long form */
262 int ri; /* number of bits in R */
263 BIGNUM RR; /* used to convert to montgomery form */
264 BIGNUM N; /* The modulus */
265 BIGNUM Ni; /* The inverse of N */
266 BN_ULONG n0; /* word form of inverse, normally only one of
267 * Ni or n0 is defined */
268 int flags;
269 } BN_MONT_CTX;
270
271/* Used for reciprocal division/mod functions
272 * It cannot be shared between threads
273 */
274typedef struct bn_recp_ctx_st
275 {
276 BIGNUM N; /* the divisor */
277 BIGNUM Nr; /* the reciprocal */
278 int num_bits;
279 int shift;
280 int flags;
281 } BN_RECP_CTX;
282
283#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
284 r,a,&((mont)->RR),(mont),ctx)
285
286#define BN_prime_checks (5)
287
288#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
289#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
290#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0))
291#define BN_is_one(a) (BN_is_word((a),1))
292#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
293#define BN_one(a) (BN_set_word((a),1))
294#define BN_zero(a) (BN_set_word((a),0))
295
296/*#define BN_ascii2bn(a) BN_hex2bn(a) */
297/*#define BN_bn2ascii(a) BN_bn2hex(a) */
298
299#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\
300 (n):bn_expand2((n),(b)/BN_BITS2+1))
301#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b)))
302
303#define bn_fix_top(a) \
304 { \
305 BN_ULONG *ftl; \
306 if ((a)->top > 0) \
307 { \
308 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
309 if (*(ftl--)) break; \
310 } \
311 }
312
313BIGNUM *BN_value_one(void);
314char * BN_options(void);
315BN_CTX *BN_CTX_new(void);
316void BN_CTX_init(BN_CTX *c);
317void BN_CTX_free(BN_CTX *c);
318int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
319int BN_num_bits(const BIGNUM *a);
320int BN_num_bits_word(BN_ULONG);
321BIGNUM *BN_new(void);
322void BN_init(BIGNUM *);
323void BN_clear_free(BIGNUM *a);
324BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
325BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
326int BN_bn2bin(const BIGNUM *a, unsigned char *to);
327BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
328int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
329int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
330int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
331int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
332int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
333int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
334int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
335 BN_CTX *ctx);
336int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx);
337int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx);
338BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w);
339BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
340int BN_mul_word(BIGNUM *a, BN_ULONG w);
341int BN_add_word(BIGNUM *a, BN_ULONG w);
342int BN_sub_word(BIGNUM *a, BN_ULONG w);
343int BN_set_word(BIGNUM *a, BN_ULONG w);
344BN_ULONG BN_get_word(BIGNUM *a);
345int BN_cmp(const BIGNUM *a, const BIGNUM *b);
346void BN_free(BIGNUM *a);
347int BN_is_bit_set(const BIGNUM *a, int n);
348int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
349int BN_lshift1(BIGNUM *r, BIGNUM *a);
350int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx);
351int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
352 const BIGNUM *m,BN_CTX *ctx);
353int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
354 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
355int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
356 BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx);
357int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
358 BIGNUM *m,BN_CTX *ctx);
359int BN_mask_bits(BIGNUM *a,int n);
360int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
361#ifndef WIN16
362int BN_print_fp(FILE *fp, BIGNUM *a);
363#endif
364#ifdef HEADER_BIO_H
365int BN_print(BIO *fp, const BIGNUM *a);
366#else
367int BN_print(char *fp, const BIGNUM *a);
368#endif
369int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
370int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
371int BN_rshift1(BIGNUM *r, BIGNUM *a);
372void BN_clear(BIGNUM *a);
373BIGNUM *bn_expand2(BIGNUM *b, int bits);
374BIGNUM *BN_dup(const BIGNUM *a);
375int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
376int BN_set_bit(BIGNUM *a, int n);
377int BN_clear_bit(BIGNUM *a, int n);
378char * BN_bn2hex(const BIGNUM *a);
379char * BN_bn2dec(const BIGNUM *a);
380int BN_hex2bn(BIGNUM **a, const char *str);
381int BN_dec2bn(BIGNUM **a, const char *str);
382int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
383BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
384BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add,
385 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg);
386int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *),
387 BN_CTX *ctx,void *cb_arg);
388void ERR_load_BN_strings(void );
389
390BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
391BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
392void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
393BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
394BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
395BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
396
397BN_MONT_CTX *BN_MONT_CTX_new(void );
398void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
399int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
400 BN_CTX *ctx);
401int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx);
402void BN_MONT_CTX_free(BN_MONT_CTX *mont);
403int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx);
404BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
405
406BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
407void BN_BLINDING_free(BN_BLINDING *b);
408int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
409int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
410int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
411
412void BN_set_params(int mul,int high,int low,int mont);
413int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
414
415void BN_RECP_CTX_init(BN_RECP_CTX *recp);
416BN_RECP_CTX *BN_RECP_CTX_new(void);
417void BN_RECP_CTX_free(BN_RECP_CTX *recp);
418int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
419int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y,
420 BN_RECP_CTX *recp,BN_CTX *ctx);
421int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
422 const BIGNUM *m, BN_CTX *ctx);
423int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
424 BN_RECP_CTX *recp, BN_CTX *ctx);
425
426
427/* BEGIN ERROR CODES */
428/* The following lines are auto generated by the script mkerr.pl. Any changes
429 * made after this point may be overwritten when the script is next run.
430 */
431
432/* Error codes for the BN functions. */
433
434/* Function codes. */
435#define BN_F_BN_BLINDING_CONVERT 100
436#define BN_F_BN_BLINDING_INVERT 101
437#define BN_F_BN_BLINDING_NEW 102
438#define BN_F_BN_BLINDING_UPDATE 103
439#define BN_F_BN_BN2DEC 104
440#define BN_F_BN_BN2HEX 105
441#define BN_F_BN_CTX_NEW 106
442#define BN_F_BN_DIV 107
443#define BN_F_BN_EXPAND2 108
444#define BN_F_BN_MOD_EXP_MONT 109
445#define BN_F_BN_MOD_INVERSE 110
446#define BN_F_BN_MOD_MUL_RECIPROCAL 111
447#define BN_F_BN_MPI2BN 112
448#define BN_F_BN_NEW 113
449#define BN_F_BN_RAND 114
450#define BN_F_BN_USUB 115
451
452/* Reason codes. */
453#define BN_R_ARG2_LT_ARG3 100
454#define BN_R_BAD_RECIPROCAL 101
455#define BN_R_CALLED_WITH_EVEN_MODULUS 102
456#define BN_R_DIV_BY_ZERO 103
457#define BN_R_ENCODING_ERROR 104
458#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
459#define BN_R_INVALID_LENGTH 106
460#define BN_R_NOT_INITIALIZED 107
461#define BN_R_NO_INVERSE 108
462
463#ifdef __cplusplus
464}
465#endif
466#endif
467
diff --git a/src/lib/libssl/src/crypto/bn/bn.mul b/src/lib/libssl/src/crypto/bn/bn.mul
new file mode 100644
index 0000000000..9728870d38
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn.mul
@@ -0,0 +1,19 @@
1We need
2
3* bn_mul_comba8
4* bn_mul_comba4
5* bn_mul_normal
6* bn_mul_recursive
7
8* bn_sqr_comba8
9* bn_sqr_comba4
10bn_sqr_normal -> BN_sqr
11* bn_sqr_recursive
12
13* bn_mul_low_recursive
14* bn_mul_low_normal
15* bn_mul_high
16
17* bn_mul_part_recursive # symetric but not power of 2
18
19bn_mul_asymetric_recursive # uneven, but do the chop up.
diff --git a/src/lib/libssl/src/crypto/bn/bn_asm.c b/src/lib/libssl/src/crypto/bn/bn_asm.c
new file mode 100644
index 0000000000..4d3da16a0c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_asm.c
@@ -0,0 +1,802 @@
1/* crypto/bn/bn_asm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_LLONG
64
65BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
66 {
67 BN_ULONG c1=0;
68
69 bn_check_num(num);
70 if (num <= 0) return(c1);
71
72 for (;;)
73 {
74 mul_add(rp[0],ap[0],w,c1);
75 if (--num == 0) break;
76 mul_add(rp[1],ap[1],w,c1);
77 if (--num == 0) break;
78 mul_add(rp[2],ap[2],w,c1);
79 if (--num == 0) break;
80 mul_add(rp[3],ap[3],w,c1);
81 if (--num == 0) break;
82 ap+=4;
83 rp+=4;
84 }
85
86 return(c1);
87 }
88
89BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
90 {
91 BN_ULONG c1=0;
92
93 bn_check_num(num);
94 if (num <= 0) return(c1);
95
96 /* for (;;) */
97 while (1) /* circumvent egcs-1.1.2 bug */
98 {
99 mul(rp[0],ap[0],w,c1);
100 if (--num == 0) break;
101 mul(rp[1],ap[1],w,c1);
102 if (--num == 0) break;
103 mul(rp[2],ap[2],w,c1);
104 if (--num == 0) break;
105 mul(rp[3],ap[3],w,c1);
106 if (--num == 0) break;
107 ap+=4;
108 rp+=4;
109 }
110 return(c1);
111 }
112
113void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
114 {
115 bn_check_num(n);
116 if (n <= 0) return;
117 for (;;)
118 {
119 BN_ULLONG t;
120
121 t=(BN_ULLONG)(a[0])*(a[0]);
122 r[0]=Lw(t); r[1]=Hw(t);
123 if (--n == 0) break;
124
125 t=(BN_ULLONG)(a[1])*(a[1]);
126 r[2]=Lw(t); r[3]=Hw(t);
127 if (--n == 0) break;
128
129 t=(BN_ULLONG)(a[2])*(a[2]);
130 r[4]=Lw(t); r[5]=Hw(t);
131 if (--n == 0) break;
132
133 t=(BN_ULLONG)(a[3])*(a[3]);
134 r[6]=Lw(t); r[7]=Hw(t);
135 if (--n == 0) break;
136
137 a+=4;
138 r+=8;
139 }
140 }
141
142#else
143
144BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
145 {
146 BN_ULONG c=0;
147 BN_ULONG bl,bh;
148
149 bn_check_num(num);
150 if (num <= 0) return((BN_ULONG)0);
151
152 bl=LBITS(w);
153 bh=HBITS(w);
154
155 for (;;)
156 {
157 mul_add(rp[0],ap[0],bl,bh,c);
158 if (--num == 0) break;
159 mul_add(rp[1],ap[1],bl,bh,c);
160 if (--num == 0) break;
161 mul_add(rp[2],ap[2],bl,bh,c);
162 if (--num == 0) break;
163 mul_add(rp[3],ap[3],bl,bh,c);
164 if (--num == 0) break;
165 ap+=4;
166 rp+=4;
167 }
168 return(c);
169 }
170
171BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
172 {
173 BN_ULONG carry=0;
174 BN_ULONG bl,bh;
175
176 bn_check_num(num);
177 if (num <= 0) return((BN_ULONG)0);
178
179 bl=LBITS(w);
180 bh=HBITS(w);
181
182 for (;;)
183 {
184 mul(rp[0],ap[0],bl,bh,carry);
185 if (--num == 0) break;
186 mul(rp[1],ap[1],bl,bh,carry);
187 if (--num == 0) break;
188 mul(rp[2],ap[2],bl,bh,carry);
189 if (--num == 0) break;
190 mul(rp[3],ap[3],bl,bh,carry);
191 if (--num == 0) break;
192 ap+=4;
193 rp+=4;
194 }
195 return(carry);
196 }
197
198void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
199 {
200 bn_check_num(n);
201 if (n <= 0) return;
202 for (;;)
203 {
204 sqr64(r[0],r[1],a[0]);
205 if (--n == 0) break;
206
207 sqr64(r[2],r[3],a[1]);
208 if (--n == 0) break;
209
210 sqr64(r[4],r[5],a[2]);
211 if (--n == 0) break;
212
213 sqr64(r[6],r[7],a[3]);
214 if (--n == 0) break;
215
216 a+=4;
217 r+=8;
218 }
219 }
220
221#endif
222
223#if defined(BN_LLONG) && defined(BN_DIV2W)
224
225BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
226 {
227 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
228 }
229
230#else
231
232/* Divide h-l by d and return the result. */
233/* I need to test this some more :-( */
234BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
235 {
236 BN_ULONG dh,dl,q,ret=0,th,tl,t;
237 int i,count=2;
238
239 if (d == 0) return(BN_MASK2);
240
241 i=BN_num_bits_word(d);
242 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
243 {
244#if !defined(NO_STDIO) && !defined(WIN16)
245 fprintf(stderr,"Division would overflow (%d)\n",i);
246#endif
247 abort();
248 }
249 i=BN_BITS2-i;
250 if (h >= d) h-=d;
251
252 if (i)
253 {
254 d<<=i;
255 h=(h<<i)|(l>>(BN_BITS2-i));
256 l<<=i;
257 }
258 dh=(d&BN_MASK2h)>>BN_BITS4;
259 dl=(d&BN_MASK2l);
260 for (;;)
261 {
262 if ((h>>BN_BITS4) == dh)
263 q=BN_MASK2l;
264 else
265 q=h/dh;
266
267 th=q*dh;
268 tl=dl*q;
269 for (;;)
270 {
271 t=h-th;
272 if ((t&BN_MASK2h) ||
273 ((tl) <= (
274 (t<<BN_BITS4)|
275 ((l&BN_MASK2h)>>BN_BITS4))))
276 break;
277 q--;
278 th-=dh;
279 tl-=dl;
280 }
281 t=(tl>>BN_BITS4);
282 tl=(tl<<BN_BITS4)&BN_MASK2h;
283 th+=t;
284
285 if (l < tl) th++;
286 l-=tl;
287 if (h < th)
288 {
289 h+=d;
290 q--;
291 }
292 h-=th;
293
294 if (--count == 0) break;
295
296 ret=q<<BN_BITS4;
297 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
298 l=(l&BN_MASK2l)<<BN_BITS4;
299 }
300 ret|=q;
301 return(ret);
302 }
303#endif
304
305#ifdef BN_LLONG
306BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
307 {
308 BN_ULLONG ll=0;
309
310 bn_check_num(n);
311 if (n <= 0) return((BN_ULONG)0);
312
313 for (;;)
314 {
315 ll+=(BN_ULLONG)a[0]+b[0];
316 r[0]=(BN_ULONG)ll&BN_MASK2;
317 ll>>=BN_BITS2;
318 if (--n <= 0) break;
319
320 ll+=(BN_ULLONG)a[1]+b[1];
321 r[1]=(BN_ULONG)ll&BN_MASK2;
322 ll>>=BN_BITS2;
323 if (--n <= 0) break;
324
325 ll+=(BN_ULLONG)a[2]+b[2];
326 r[2]=(BN_ULONG)ll&BN_MASK2;
327 ll>>=BN_BITS2;
328 if (--n <= 0) break;
329
330 ll+=(BN_ULLONG)a[3]+b[3];
331 r[3]=(BN_ULONG)ll&BN_MASK2;
332 ll>>=BN_BITS2;
333 if (--n <= 0) break;
334
335 a+=4;
336 b+=4;
337 r+=4;
338 }
339 return((BN_ULONG)ll);
340 }
341#else
342BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
343 {
344 BN_ULONG c,l,t;
345
346 bn_check_num(n);
347 if (n <= 0) return((BN_ULONG)0);
348
349 c=0;
350 for (;;)
351 {
352 t=a[0];
353 t=(t+c)&BN_MASK2;
354 c=(t < c);
355 l=(t+b[0])&BN_MASK2;
356 c+=(l < t);
357 r[0]=l;
358 if (--n <= 0) break;
359
360 t=a[1];
361 t=(t+c)&BN_MASK2;
362 c=(t < c);
363 l=(t+b[1])&BN_MASK2;
364 c+=(l < t);
365 r[1]=l;
366 if (--n <= 0) break;
367
368 t=a[2];
369 t=(t+c)&BN_MASK2;
370 c=(t < c);
371 l=(t+b[2])&BN_MASK2;
372 c+=(l < t);
373 r[2]=l;
374 if (--n <= 0) break;
375
376 t=a[3];
377 t=(t+c)&BN_MASK2;
378 c=(t < c);
379 l=(t+b[3])&BN_MASK2;
380 c+=(l < t);
381 r[3]=l;
382 if (--n <= 0) break;
383
384 a+=4;
385 b+=4;
386 r+=4;
387 }
388 return((BN_ULONG)c);
389 }
390#endif
391
392BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
393 {
394 BN_ULONG t1,t2;
395 int c=0;
396
397 bn_check_num(n);
398 if (n <= 0) return((BN_ULONG)0);
399
400 for (;;)
401 {
402 t1=a[0]; t2=b[0];
403 r[0]=(t1-t2-c)&BN_MASK2;
404 if (t1 != t2) c=(t1 < t2);
405 if (--n <= 0) break;
406
407 t1=a[1]; t2=b[1];
408 r[1]=(t1-t2-c)&BN_MASK2;
409 if (t1 != t2) c=(t1 < t2);
410 if (--n <= 0) break;
411
412 t1=a[2]; t2=b[2];
413 r[2]=(t1-t2-c)&BN_MASK2;
414 if (t1 != t2) c=(t1 < t2);
415 if (--n <= 0) break;
416
417 t1=a[3]; t2=b[3];
418 r[3]=(t1-t2-c)&BN_MASK2;
419 if (t1 != t2) c=(t1 < t2);
420 if (--n <= 0) break;
421
422 a+=4;
423 b+=4;
424 r+=4;
425 }
426 return(c);
427 }
428
429#ifdef BN_MUL_COMBA
430
431#undef bn_mul_comba8
432#undef bn_mul_comba4
433#undef bn_sqr_comba8
434#undef bn_sqr_comba4
435
436#ifdef BN_LLONG
437#define mul_add_c(a,b,c0,c1,c2) \
438 t=(BN_ULLONG)a*b; \
439 t1=(BN_ULONG)Lw(t); \
440 t2=(BN_ULONG)Hw(t); \
441 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
442 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
443
444#define mul_add_c2(a,b,c0,c1,c2) \
445 t=(BN_ULLONG)a*b; \
446 tt=(t+t)&BN_MASK; \
447 if (tt < t) c2++; \
448 t1=(BN_ULONG)Lw(tt); \
449 t2=(BN_ULONG)Hw(tt); \
450 c0=(c0+t1)&BN_MASK2; \
451 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
452 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
453
454#define sqr_add_c(a,i,c0,c1,c2) \
455 t=(BN_ULLONG)a[i]*a[i]; \
456 t1=(BN_ULONG)Lw(t); \
457 t2=(BN_ULONG)Hw(t); \
458 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
459 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
460
461#define sqr_add_c2(a,i,j,c0,c1,c2) \
462 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
463#else
464#define mul_add_c(a,b,c0,c1,c2) \
465 t1=LBITS(a); t2=HBITS(a); \
466 bl=LBITS(b); bh=HBITS(b); \
467 mul64(t1,t2,bl,bh); \
468 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
469 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
470
471#define mul_add_c2(a,b,c0,c1,c2) \
472 t1=LBITS(a); t2=HBITS(a); \
473 bl=LBITS(b); bh=HBITS(b); \
474 mul64(t1,t2,bl,bh); \
475 if (t2 & BN_TBIT) c2++; \
476 t2=(t2+t2)&BN_MASK2; \
477 if (t1 & BN_TBIT) t2++; \
478 t1=(t1+t1)&BN_MASK2; \
479 c0=(c0+t1)&BN_MASK2; \
480 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
481 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
482
483#define sqr_add_c(a,i,c0,c1,c2) \
484 sqr64(t1,t2,(a)[i]); \
485 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
486 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
487
488#define sqr_add_c2(a,i,j,c0,c1,c2) \
489 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
490#endif
491
492void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
493 {
494#ifdef BN_LLONG
495 BN_ULLONG t;
496#else
497 BN_ULONG bl,bh;
498#endif
499 BN_ULONG t1,t2;
500 BN_ULONG c1,c2,c3;
501
502 c1=0;
503 c2=0;
504 c3=0;
505 mul_add_c(a[0],b[0],c1,c2,c3);
506 r[0]=c1;
507 c1=0;
508 mul_add_c(a[0],b[1],c2,c3,c1);
509 mul_add_c(a[1],b[0],c2,c3,c1);
510 r[1]=c2;
511 c2=0;
512 mul_add_c(a[2],b[0],c3,c1,c2);
513 mul_add_c(a[1],b[1],c3,c1,c2);
514 mul_add_c(a[0],b[2],c3,c1,c2);
515 r[2]=c3;
516 c3=0;
517 mul_add_c(a[0],b[3],c1,c2,c3);
518 mul_add_c(a[1],b[2],c1,c2,c3);
519 mul_add_c(a[2],b[1],c1,c2,c3);
520 mul_add_c(a[3],b[0],c1,c2,c3);
521 r[3]=c1;
522 c1=0;
523 mul_add_c(a[4],b[0],c2,c3,c1);
524 mul_add_c(a[3],b[1],c2,c3,c1);
525 mul_add_c(a[2],b[2],c2,c3,c1);
526 mul_add_c(a[1],b[3],c2,c3,c1);
527 mul_add_c(a[0],b[4],c2,c3,c1);
528 r[4]=c2;
529 c2=0;
530 mul_add_c(a[0],b[5],c3,c1,c2);
531 mul_add_c(a[1],b[4],c3,c1,c2);
532 mul_add_c(a[2],b[3],c3,c1,c2);
533 mul_add_c(a[3],b[2],c3,c1,c2);
534 mul_add_c(a[4],b[1],c3,c1,c2);
535 mul_add_c(a[5],b[0],c3,c1,c2);
536 r[5]=c3;
537 c3=0;
538 mul_add_c(a[6],b[0],c1,c2,c3);
539 mul_add_c(a[5],b[1],c1,c2,c3);
540 mul_add_c(a[4],b[2],c1,c2,c3);
541 mul_add_c(a[3],b[3],c1,c2,c3);
542 mul_add_c(a[2],b[4],c1,c2,c3);
543 mul_add_c(a[1],b[5],c1,c2,c3);
544 mul_add_c(a[0],b[6],c1,c2,c3);
545 r[6]=c1;
546 c1=0;
547 mul_add_c(a[0],b[7],c2,c3,c1);
548 mul_add_c(a[1],b[6],c2,c3,c1);
549 mul_add_c(a[2],b[5],c2,c3,c1);
550 mul_add_c(a[3],b[4],c2,c3,c1);
551 mul_add_c(a[4],b[3],c2,c3,c1);
552 mul_add_c(a[5],b[2],c2,c3,c1);
553 mul_add_c(a[6],b[1],c2,c3,c1);
554 mul_add_c(a[7],b[0],c2,c3,c1);
555 r[7]=c2;
556 c2=0;
557 mul_add_c(a[7],b[1],c3,c1,c2);
558 mul_add_c(a[6],b[2],c3,c1,c2);
559 mul_add_c(a[5],b[3],c3,c1,c2);
560 mul_add_c(a[4],b[4],c3,c1,c2);
561 mul_add_c(a[3],b[5],c3,c1,c2);
562 mul_add_c(a[2],b[6],c3,c1,c2);
563 mul_add_c(a[1],b[7],c3,c1,c2);
564 r[8]=c3;
565 c3=0;
566 mul_add_c(a[2],b[7],c1,c2,c3);
567 mul_add_c(a[3],b[6],c1,c2,c3);
568 mul_add_c(a[4],b[5],c1,c2,c3);
569 mul_add_c(a[5],b[4],c1,c2,c3);
570 mul_add_c(a[6],b[3],c1,c2,c3);
571 mul_add_c(a[7],b[2],c1,c2,c3);
572 r[9]=c1;
573 c1=0;
574 mul_add_c(a[7],b[3],c2,c3,c1);
575 mul_add_c(a[6],b[4],c2,c3,c1);
576 mul_add_c(a[5],b[5],c2,c3,c1);
577 mul_add_c(a[4],b[6],c2,c3,c1);
578 mul_add_c(a[3],b[7],c2,c3,c1);
579 r[10]=c2;
580 c2=0;
581 mul_add_c(a[4],b[7],c3,c1,c2);
582 mul_add_c(a[5],b[6],c3,c1,c2);
583 mul_add_c(a[6],b[5],c3,c1,c2);
584 mul_add_c(a[7],b[4],c3,c1,c2);
585 r[11]=c3;
586 c3=0;
587 mul_add_c(a[7],b[5],c1,c2,c3);
588 mul_add_c(a[6],b[6],c1,c2,c3);
589 mul_add_c(a[5],b[7],c1,c2,c3);
590 r[12]=c1;
591 c1=0;
592 mul_add_c(a[6],b[7],c2,c3,c1);
593 mul_add_c(a[7],b[6],c2,c3,c1);
594 r[13]=c2;
595 c2=0;
596 mul_add_c(a[7],b[7],c3,c1,c2);
597 r[14]=c3;
598 r[15]=c1;
599 }
600
601void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
602 {
603#ifdef BN_LLONG
604 BN_ULLONG t;
605#else
606 BN_ULONG bl,bh;
607#endif
608 BN_ULONG t1,t2;
609 BN_ULONG c1,c2,c3;
610
611 c1=0;
612 c2=0;
613 c3=0;
614 mul_add_c(a[0],b[0],c1,c2,c3);
615 r[0]=c1;
616 c1=0;
617 mul_add_c(a[0],b[1],c2,c3,c1);
618 mul_add_c(a[1],b[0],c2,c3,c1);
619 r[1]=c2;
620 c2=0;
621 mul_add_c(a[2],b[0],c3,c1,c2);
622 mul_add_c(a[1],b[1],c3,c1,c2);
623 mul_add_c(a[0],b[2],c3,c1,c2);
624 r[2]=c3;
625 c3=0;
626 mul_add_c(a[0],b[3],c1,c2,c3);
627 mul_add_c(a[1],b[2],c1,c2,c3);
628 mul_add_c(a[2],b[1],c1,c2,c3);
629 mul_add_c(a[3],b[0],c1,c2,c3);
630 r[3]=c1;
631 c1=0;
632 mul_add_c(a[3],b[1],c2,c3,c1);
633 mul_add_c(a[2],b[2],c2,c3,c1);
634 mul_add_c(a[1],b[3],c2,c3,c1);
635 r[4]=c2;
636 c2=0;
637 mul_add_c(a[2],b[3],c3,c1,c2);
638 mul_add_c(a[3],b[2],c3,c1,c2);
639 r[5]=c3;
640 c3=0;
641 mul_add_c(a[3],b[3],c1,c2,c3);
642 r[6]=c1;
643 r[7]=c2;
644 }
645
646void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
647 {
648#ifdef BN_LLONG
649 BN_ULLONG t,tt;
650#else
651 BN_ULONG bl,bh;
652#endif
653 BN_ULONG t1,t2;
654 BN_ULONG c1,c2,c3;
655
656 c1=0;
657 c2=0;
658 c3=0;
659 sqr_add_c(a,0,c1,c2,c3);
660 r[0]=c1;
661 c1=0;
662 sqr_add_c2(a,1,0,c2,c3,c1);
663 r[1]=c2;
664 c2=0;
665 sqr_add_c(a,1,c3,c1,c2);
666 sqr_add_c2(a,2,0,c3,c1,c2);
667 r[2]=c3;
668 c3=0;
669 sqr_add_c2(a,3,0,c1,c2,c3);
670 sqr_add_c2(a,2,1,c1,c2,c3);
671 r[3]=c1;
672 c1=0;
673 sqr_add_c(a,2,c2,c3,c1);
674 sqr_add_c2(a,3,1,c2,c3,c1);
675 sqr_add_c2(a,4,0,c2,c3,c1);
676 r[4]=c2;
677 c2=0;
678 sqr_add_c2(a,5,0,c3,c1,c2);
679 sqr_add_c2(a,4,1,c3,c1,c2);
680 sqr_add_c2(a,3,2,c3,c1,c2);
681 r[5]=c3;
682 c3=0;
683 sqr_add_c(a,3,c1,c2,c3);
684 sqr_add_c2(a,4,2,c1,c2,c3);
685 sqr_add_c2(a,5,1,c1,c2,c3);
686 sqr_add_c2(a,6,0,c1,c2,c3);
687 r[6]=c1;
688 c1=0;
689 sqr_add_c2(a,7,0,c2,c3,c1);
690 sqr_add_c2(a,6,1,c2,c3,c1);
691 sqr_add_c2(a,5,2,c2,c3,c1);
692 sqr_add_c2(a,4,3,c2,c3,c1);
693 r[7]=c2;
694 c2=0;
695 sqr_add_c(a,4,c3,c1,c2);
696 sqr_add_c2(a,5,3,c3,c1,c2);
697 sqr_add_c2(a,6,2,c3,c1,c2);
698 sqr_add_c2(a,7,1,c3,c1,c2);
699 r[8]=c3;
700 c3=0;
701 sqr_add_c2(a,7,2,c1,c2,c3);
702 sqr_add_c2(a,6,3,c1,c2,c3);
703 sqr_add_c2(a,5,4,c1,c2,c3);
704 r[9]=c1;
705 c1=0;
706 sqr_add_c(a,5,c2,c3,c1);
707 sqr_add_c2(a,6,4,c2,c3,c1);
708 sqr_add_c2(a,7,3,c2,c3,c1);
709 r[10]=c2;
710 c2=0;
711 sqr_add_c2(a,7,4,c3,c1,c2);
712 sqr_add_c2(a,6,5,c3,c1,c2);
713 r[11]=c3;
714 c3=0;
715 sqr_add_c(a,6,c1,c2,c3);
716 sqr_add_c2(a,7,5,c1,c2,c3);
717 r[12]=c1;
718 c1=0;
719 sqr_add_c2(a,7,6,c2,c3,c1);
720 r[13]=c2;
721 c2=0;
722 sqr_add_c(a,7,c3,c1,c2);
723 r[14]=c3;
724 r[15]=c1;
725 }
726
727void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
728 {
729#ifdef BN_LLONG
730 BN_ULLONG t,tt;
731#else
732 BN_ULONG bl,bh;
733#endif
734 BN_ULONG t1,t2;
735 BN_ULONG c1,c2,c3;
736
737 c1=0;
738 c2=0;
739 c3=0;
740 sqr_add_c(a,0,c1,c2,c3);
741 r[0]=c1;
742 c1=0;
743 sqr_add_c2(a,1,0,c2,c3,c1);
744 r[1]=c2;
745 c2=0;
746 sqr_add_c(a,1,c3,c1,c2);
747 sqr_add_c2(a,2,0,c3,c1,c2);
748 r[2]=c3;
749 c3=0;
750 sqr_add_c2(a,3,0,c1,c2,c3);
751 sqr_add_c2(a,2,1,c1,c2,c3);
752 r[3]=c1;
753 c1=0;
754 sqr_add_c(a,2,c2,c3,c1);
755 sqr_add_c2(a,3,1,c2,c3,c1);
756 r[4]=c2;
757 c2=0;
758 sqr_add_c2(a,3,2,c3,c1,c2);
759 r[5]=c3;
760 c3=0;
761 sqr_add_c(a,3,c1,c2,c3);
762 r[6]=c1;
763 r[7]=c2;
764 }
765#else
766
767/* hmm... is it faster just to do a multiply? */
768#undef bn_sqr_comba4
769void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
770 {
771 BN_ULONG t[8];
772 bn_sqr_normal(r,a,4,t);
773 }
774
775#undef bn_sqr_comba8
776void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
777 {
778 BN_ULONG t[16];
779 bn_sqr_normal(r,a,8,t);
780 }
781
782void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
783 {
784 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
785 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
786 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
787 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
788 }
789
790void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
791 {
792 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
793 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
794 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
795 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
796 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
797 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
798 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
799 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
800 }
801
802#endif /* BN_COMBA */
diff --git a/src/lib/libssl/src/crypto/bn/bn_ctx.c b/src/lib/libssl/src/crypto/bn/bn_ctx.c
new file mode 100644
index 0000000000..46132fd180
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_ctx.c
@@ -0,0 +1,144 @@
1/* crypto/bn/bn_ctx.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#ifndef BN_CTX_DEBUG
58# undef NDEBUG /* avoid conflicting definitions */
59# define NDEBUG
60#endif
61
62#include <stdio.h>
63#include <assert.h>
64#include "cryptlib.h"
65#include <openssl/bn.h>
66
67
68BN_CTX *BN_CTX_new(void)
69 {
70 BN_CTX *ret;
71
72 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
73 if (ret == NULL)
74 {
75 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
76 return(NULL);
77 }
78
79 BN_CTX_init(ret);
80 ret->flags=BN_FLG_MALLOCED;
81 return(ret);
82 }
83
84void BN_CTX_init(BN_CTX *ctx)
85 {
86 int i;
87 ctx->tos = 0;
88 ctx->flags = 0;
89 ctx->depth = 0;
90 ctx->too_many = 0;
91 for (i = 0; i < BN_CTX_NUM; i++)
92 BN_init(&(ctx->bn[i]));
93 }
94
95void BN_CTX_free(BN_CTX *ctx)
96 {
97 int i;
98
99 if (ctx == NULL) return;
100 assert(ctx->depth == 0);
101
102 for (i=0; i < BN_CTX_NUM; i++)
103 BN_clear_free(&(ctx->bn[i]));
104 if (ctx->flags & BN_FLG_MALLOCED)
105 Free(ctx);
106 }
107
108void BN_CTX_start(BN_CTX *ctx)
109 {
110 if (ctx->depth < BN_CTX_NUM_POS)
111 ctx->pos[ctx->depth] = ctx->tos;
112 ctx->depth++;
113 }
114
115BIGNUM *BN_CTX_get(BN_CTX *ctx)
116 {
117 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
118 {
119 if (!ctx->too_many)
120 {
121 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
122 /* disable error code until BN_CTX_end is called: */
123 ctx->too_many = 1;
124 }
125 return NULL;
126 }
127 return (&(ctx->bn[ctx->tos++]));
128 }
129
130void BN_CTX_end(BN_CTX *ctx)
131 {
132 if (ctx == NULL) return;
133 assert(ctx->depth > 0);
134 if (ctx->depth == 0)
135 /* should never happen, but we can tolerate it if not in
136 * debug mode (could be a 'goto err' in the calling function
137 * before BN_CTX_start was reached) */
138 BN_CTX_start(ctx);
139
140 ctx->too_many = 0;
141 ctx->depth--;
142 if (ctx->depth < BN_CTX_NUM_POS)
143 ctx->tos = ctx->pos[ctx->depth];
144 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_exp2.c b/src/lib/libssl/src/crypto/bn/bn_exp2.c
new file mode 100644
index 0000000000..1132d53365
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_exp2.c
@@ -0,0 +1,195 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5/* I've done some timing with different table sizes.
6 * The main hassle is that even with bits set at 3, this requires
7 * 63 BIGNUMs to store the pre-calculated values.
8 * 512 1024
9 * bits=1 75.4% 79.4%
10 * bits=2 61.2% 62.4%
11 * bits=3 61.3% 59.3%
12 * The lack of speed improvment is also a function of the pre-calculation
13 * which could be removed.
14 */
15#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */
16#define EXP2_TABLE_SIZE 4 /* 2 4 8 16 32 */
17
18int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
19 BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
20 {
21 int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;
22 int start=1,ts=0,x,y;
23 BIGNUM *d,*aa1,*aa2,*r;
24 BIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];
25 BN_MONT_CTX *mont=NULL;
26
27 bn_check_top(a1);
28 bn_check_top(p1);
29 bn_check_top(a2);
30 bn_check_top(p2);
31 bn_check_top(m);
32
33 if (!(m->d[0] & 1))
34 {
35 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
36 return(0);
37 }
38 d= &(ctx->bn[ctx->tos++]);
39 r= &(ctx->bn[ctx->tos++]);
40 bits1=BN_num_bits(p1);
41 bits2=BN_num_bits(p2);
42 if ((bits1 == 0) && (bits2 == 0))
43 {
44 BN_one(r);
45 return(1);
46 }
47 bits=(bits1 > bits2)?bits1:bits2;
48
49 /* If this is not done, things will break in the montgomery
50 * part */
51
52 if (in_mont != NULL)
53 mont=in_mont;
54 else
55 {
56 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
57 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
58 }
59
60 BN_init(&(val[0][0]));
61 BN_init(&(val[1][1]));
62 BN_init(&(val[0][1]));
63 BN_init(&(val[1][0]));
64 ts=1;
65 if (BN_ucmp(a1,m) >= 0)
66 {
67 BN_mod(&(val[1][0]),a1,m,ctx);
68 aa1= &(val[1][0]);
69 }
70 else
71 aa1=a1;
72 if (BN_ucmp(a2,m) >= 0)
73 {
74 BN_mod(&(val[0][1]),a2,m,ctx);
75 aa2= &(val[0][1]);
76 }
77 else
78 aa2=a2;
79 if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;
80 if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;
81 if (!BN_mod_mul_montgomery(&(val[1][1]),
82 &(val[1][0]),&(val[0][1]),mont,ctx))
83 goto err;
84
85#if 0
86 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
87 window=1;
88 else if (bits > 250)
89 window=5; /* max size of window */
90 else if (bits >= 120)
91 window=4;
92 else
93 window=3;
94#else
95 window=EXP2_TABLE_BITS;
96#endif
97
98 k=1<<window;
99 for (x=0; x<k; x++)
100 {
101 if (x >= 2)
102 {
103 BN_init(&(val[x][0]));
104 BN_init(&(val[x][1]));
105 if (!BN_mod_mul_montgomery(&(val[x][0]),
106 &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;
107 if (!BN_mod_mul_montgomery(&(val[x][1]),
108 &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;
109 }
110 for (y=2; y<k; y++)
111 {
112 BN_init(&(val[x][y]));
113 if (!BN_mod_mul_montgomery(&(val[x][y]),
114 &(val[x][y-1]),&(val[0][1]),mont,ctx))
115 goto err;
116 }
117 }
118 ts=k;
119
120 start=1; /* This is used to avoid multiplication etc
121 * when there is only the value '1' in the
122 * buffer. */
123 xvalue=0; /* The 'x value' of the window */
124 yvalue=0; /* The 'y value' of the window */
125 wstart=bits-1; /* The top bit of the window */
126 wend=0; /* The bottom bit of the window */
127
128 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
129 for (;;)
130 {
131 xvalue=BN_is_bit_set(p1,wstart);
132 yvalue=BN_is_bit_set(p2,wstart);
133 if (!(xvalue || yvalue))
134 {
135 if (!start)
136 {
137 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
138 goto err;
139 }
140 wstart--;
141 if (wstart < 0) break;
142 continue;
143 }
144 /* We now have wstart on a 'set' bit, we now need to work out
145 * how bit a window to do. To do this we need to scan
146 * forward until the last set bit before the end of the
147 * window */
148 j=wstart;
149 /* xvalue=BN_is_bit_set(p1,wstart); already set */
150 /* yvalue=BN_is_bit_set(p1,wstart); already set */
151 wend=0;
152 for (i=1; i<window; i++)
153 {
154 if (wstart-i < 0) break;
155 xvalue+=xvalue;
156 xvalue|=BN_is_bit_set(p1,wstart-i);
157 yvalue+=yvalue;
158 yvalue|=BN_is_bit_set(p2,wstart-i);
159 }
160
161 /* i is the size of the current window */
162 /* add the 'bytes above' */
163 if (!start)
164 for (j=0; j<i; j++)
165 {
166 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
167 goto err;
168 }
169
170 /* wvalue will be an odd number < 2^window */
171 if (xvalue || yvalue)
172 {
173 if (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),
174 mont,ctx)) goto err;
175 }
176
177 /* move the 'window' down further */
178 wstart-=i;
179 start=0;
180 if (wstart < 0) break;
181 }
182 BN_from_montgomery(rr,r,mont,ctx);
183 ret=1;
184err:
185 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
186 ctx->tos-=2;
187 for (i=0; i<ts; i++)
188 {
189 for (j=0; j<ts; j++)
190 {
191 BN_clear_free(&(val[i][j]));
192 }
193 }
194 return(ret);
195 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_kron.c b/src/lib/libssl/src/crypto/bn/bn_kron.c
new file mode 100644
index 0000000000..49f75594ae
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_kron.c
@@ -0,0 +1,182 @@
1/* crypto/bn/bn_kron.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "bn_lcl.h"
57
58
59/* least significant word */
60#define BN_lsw(n) (((n)->top == 0) ? (BN_ULONG) 0 : (n)->d[0])
61
62/* Returns -2 for errors because both -1 and 0 are valid results. */
63int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
64 {
65 int i;
66 int ret = -2; /* avoid 'uninitialized' warning */
67 int err = 0;
68 BIGNUM *A, *B, *tmp;
69 /* In 'tab', only odd-indexed entries are relevant:
70 * For any odd BIGNUM n,
71 * tab[BN_lsw(n) & 7]
72 * is $(-1)^{(n^2-1)/8}$ (using TeX notation).
73 * Note that the sign of n does not matter.
74 */
75 static const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1};
76
77 BN_CTX_start(ctx);
78 A = BN_CTX_get(ctx);
79 B = BN_CTX_get(ctx);
80 if (B == NULL) goto end;
81
82 err = !BN_copy(A, a);
83 if (err) goto end;
84 err = !BN_copy(B, b);
85 if (err) goto end;
86
87 /*
88 * Kronecker symbol, imlemented according to Henri Cohen,
89 * "A Course in Computational Algebraic Number Theory"
90 * (algorithm 1.4.10).
91 */
92
93 /* Cohen's step 1: */
94
95 if (BN_is_zero(B))
96 {
97 ret = BN_abs_is_word(A, 1);
98 goto end;
99 }
100
101 /* Cohen's step 2: */
102
103 if (!BN_is_odd(A) && !BN_is_odd(B))
104 {
105 ret = 0;
106 goto end;
107 }
108
109 /* now B is non-zero */
110 i = 0;
111 while (!BN_is_bit_set(B, i))
112 i++;
113 err = !BN_rshift(B, B, i);
114 if (err) goto end;
115 if (i & 1)
116 {
117 /* i is odd */
118 /* (thus B was even, thus A must be odd!) */
119
120 /* set 'ret' to $(-1)^{(A^2-1)/8}$ */
121 ret = tab[BN_lsw(A) & 7];
122 }
123 else
124 {
125 /* i is even */
126 ret = 1;
127 }
128
129 if (B->neg)
130 {
131 B->neg = 0;
132 if (A->neg)
133 ret = -ret;
134 }
135
136 /* now B is positive and odd, so what remains to be done is
137 * to compute the Jacobi symbol (A/B) and multiply it by 'ret' */
138
139 while (1)
140 {
141 /* Cohen's step 3: */
142
143 /* B is positive and odd */
144
145 if (BN_is_zero(A))
146 {
147 ret = BN_is_one(B) ? ret : 0;
148 goto end;
149 }
150
151 /* now A is non-zero */
152 i = 0;
153 while (!BN_is_bit_set(A, i))
154 i++;
155 err = !BN_rshift(A, A, i);
156 if (err) goto end;
157 if (i & 1)
158 {
159 /* i is odd */
160 /* multiply 'ret' by $(-1)^{(B^2-1)/8}$ */
161 ret = ret * tab[BN_lsw(B) & 7];
162 }
163
164 /* Cohen's step 4: */
165 /* multiply 'ret' by $(-1)^{(A-1)(B-1)/4}$ */
166 if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)
167 ret = -ret;
168
169 /* (A, B) := (B mod |A|, |A|) */
170 err = !BN_nnmod(B, B, A, ctx);
171 if (err) goto end;
172 tmp = A; A = B; B = tmp;
173 tmp->neg = 0;
174 }
175
176 end:
177 BN_CTX_end(ctx);
178 if (err)
179 return -2;
180 else
181 return ret;
182 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_sqrt.c b/src/lib/libssl/src/crypto/bn/bn_sqrt.c
new file mode 100644
index 0000000000..e2a1105dc8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_sqrt.c
@@ -0,0 +1,387 @@
1/* crypto/bn/bn_mod.c */
2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * and Bodo Moeller for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include "cryptlib.h"
59#include "bn_lcl.h"
60
61
62BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
63/* Returns 'ret' such that
64 * ret^2 == a (mod p),
65 * using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course
66 * in Algebraic Computational Number Theory", algorithm 1.5.1).
67 * 'p' must be prime!
68 * If 'a' is not a square, this is not necessarily detected by
69 * the algorithms; a bogus result must be expected in this case.
70 */
71 {
72 BIGNUM *ret = in;
73 int err = 1;
74 int r;
75 BIGNUM *b, *q, *t, *x, *y;
76 int e, i, j;
77
78 if (!BN_is_odd(p) || BN_abs_is_word(p, 1))
79 {
80 if (BN_abs_is_word(p, 2))
81 {
82 if (ret == NULL)
83 ret = BN_new();
84 if (ret == NULL)
85 goto end;
86 if (!BN_set_word(ret, BN_is_bit_set(a, 0)))
87 {
88 BN_free(ret);
89 return NULL;
90 }
91 return ret;
92 }
93
94 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
95 return(NULL);
96 }
97
98 if (BN_is_zero(a) || BN_is_one(a))
99 {
100 if (ret == NULL)
101 ret = BN_new();
102 if (ret == NULL)
103 goto end;
104 if (!BN_set_word(ret, BN_is_one(a)))
105 {
106 BN_free(ret);
107 return NULL;
108 }
109 return ret;
110 }
111
112#if 0 /* if BN_mod_sqrt is used with correct input, this just wastes time */
113 r = BN_kronecker(a, p, ctx);
114 if (r < -1) return NULL;
115 if (r == -1)
116 {
117 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
118 return(NULL);
119 }
120#endif
121
122 BN_CTX_start(ctx);
123 b = BN_CTX_get(ctx);
124 q = BN_CTX_get(ctx);
125 t = BN_CTX_get(ctx);
126 x = BN_CTX_get(ctx);
127 y = BN_CTX_get(ctx);
128 if (y == NULL) goto end;
129
130 if (ret == NULL)
131 ret = BN_new();
132 if (ret == NULL) goto end;
133
134 /* now write |p| - 1 as 2^e*q where q is odd */
135 e = 1;
136 while (!BN_is_bit_set(p, e))
137 e++;
138 /* we'll set q later (if needed) */
139
140 if (e == 1)
141 {
142 /* The easy case: (|p|-1)/2 is odd, so 2 has an inverse
143 * modulo (|p|-1)/2, and square roots can be computed
144 * directly by modular exponentiation.
145 * We have
146 * 2 * (|p|+1)/4 == 1 (mod (|p|-1)/2),
147 * so we can use exponent (|p|+1)/4, i.e. (|p|-3)/4 + 1.
148 */
149 if (!BN_rshift(q, p, 2)) goto end;
150 q->neg = 0;
151 if (!BN_add_word(q, 1)) goto end;
152 if (!BN_mod_exp(ret, a, q, p, ctx)) goto end;
153 err = 0;
154 goto end;
155 }
156
157 if (e == 2)
158 {
159 /* |p| == 5 (mod 8)
160 *
161 * In this case 2 is always a non-square since
162 * Legendre(2,p) = (-1)^((p^2-1)/8) for any odd prime.
163 * So if a really is a square, then 2*a is a non-square.
164 * Thus for
165 * b := (2*a)^((|p|-5)/8),
166 * i := (2*a)*b^2
167 * we have
168 * i^2 = (2*a)^((1 + (|p|-5)/4)*2)
169 * = (2*a)^((p-1)/2)
170 * = -1;
171 * so if we set
172 * x := a*b*(i-1),
173 * then
174 * x^2 = a^2 * b^2 * (i^2 - 2*i + 1)
175 * = a^2 * b^2 * (-2*i)
176 * = a*(-i)*(2*a*b^2)
177 * = a*(-i)*i
178 * = a.
179 *
180 * (This is due to A.O.L. Atkin,
181 * <URL: http://listserv.nodak.edu/scripts/wa.exe?A2=ind9211&L=nmbrthry&O=T&P=562>,
182 * November 1992.)
183 */
184
185 /* make sure that a is reduced modulo p */
186 if (a->neg || BN_ucmp(a, p) >= 0)
187 {
188 if (!BN_nnmod(x, a, p, ctx)) goto end;
189 a = x; /* use x as temporary variable */
190 }
191
192 /* t := 2*a */
193 if (!BN_mod_lshift1_quick(t, a, p)) goto end;
194
195 /* b := (2*a)^((|p|-5)/8) */
196 if (!BN_rshift(q, p, 3)) goto end;
197 q->neg = 0;
198 if (!BN_mod_exp(b, t, q, p, ctx)) goto end;
199
200 /* y := b^2 */
201 if (!BN_mod_sqr(y, b, p, ctx)) goto end;
202
203 /* t := (2*a)*b^2 - 1*/
204 if (!BN_mod_mul(t, t, y, p, ctx)) goto end;
205 if (!BN_sub_word(t, 1)) goto end;
206
207 /* x = a*b*t */
208 if (!BN_mod_mul(x, a, b, p, ctx)) goto end;
209 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
210
211 if (!BN_copy(ret, x)) goto end;
212 err = 0;
213 goto end;
214 }
215
216 /* e > 2, so we really have to use the Tonelli/Shanks algorithm.
217 * First, find some y that is not a square. */
218 if (!BN_copy(q, p)) goto end; /* use 'q' as temp */
219 q->neg = 0;
220 i = 2;
221 do
222 {
223 /* For efficiency, try small numbers first;
224 * if this fails, try random numbers.
225 */
226 if (i < 22)
227 {
228 if (!BN_set_word(y, i)) goto end;
229 }
230 else
231 {
232 if (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0)) goto end;
233 if (BN_ucmp(y, p) >= 0)
234 {
235 if (!(p->neg ? BN_add : BN_sub)(y, y, p)) goto end;
236 }
237 /* now 0 <= y < |p| */
238 if (BN_is_zero(y))
239 if (!BN_set_word(y, i)) goto end;
240 }
241
242 r = BN_kronecker(y, q, ctx); /* here 'q' is |p| */
243 if (r < -1) goto end;
244 if (r == 0)
245 {
246 /* m divides p */
247 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
248 goto end;
249 }
250 }
251 while (r == 1 && ++i < 82);
252
253 if (r != -1)
254 {
255 /* Many rounds and still no non-square -- this is more likely
256 * a bug than just bad luck.
257 * Even if p is not prime, we should have found some y
258 * such that r == -1.
259 */
260 BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);
261 goto end;
262 }
263
264 /* Here's our actual 'q': */
265 if (!BN_rshift(q, q, e)) goto end;
266
267 /* Now that we have some non-square, we can find an element
268 * of order 2^e by computing its q'th power. */
269 if (!BN_mod_exp(y, y, q, p, ctx)) goto end;
270 if (BN_is_one(y))
271 {
272 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
273 goto end;
274 }
275
276 /* Now we know that (if p is indeed prime) there is an integer
277 * k, 0 <= k < 2^e, such that
278 *
279 * a^q * y^k == 1 (mod p).
280 *
281 * As a^q is a square and y is not, k must be even.
282 * q+1 is even, too, so there is an element
283 *
284 * X := a^((q+1)/2) * y^(k/2),
285 *
286 * and it satisfies
287 *
288 * X^2 = a^q * a * y^k
289 * = a,
290 *
291 * so it is the square root that we are looking for.
292 */
293
294 /* t := (q-1)/2 (note that q is odd) */
295 if (!BN_rshift1(t, q)) goto end;
296
297 /* x := a^((q-1)/2) */
298 if (BN_is_zero(t)) /* special case: p = 2^e + 1 */
299 {
300 if (!BN_nnmod(t, a, p, ctx)) goto end;
301 if (BN_is_zero(t))
302 {
303 /* special case: a == 0 (mod p) */
304 if (!BN_zero(ret)) goto end;
305 err = 0;
306 goto end;
307 }
308 else
309 if (!BN_one(x)) goto end;
310 }
311 else
312 {
313 if (!BN_mod_exp(x, a, t, p, ctx)) goto end;
314 if (BN_is_zero(x))
315 {
316 /* special case: a == 0 (mod p) */
317 if (!BN_zero(ret)) goto end;
318 err = 0;
319 goto end;
320 }
321 }
322
323 /* b := a*x^2 (= a^q) */
324 if (!BN_mod_sqr(b, x, p, ctx)) goto end;
325 if (!BN_mod_mul(b, b, a, p, ctx)) goto end;
326
327 /* x := a*x (= a^((q+1)/2)) */
328 if (!BN_mod_mul(x, x, a, p, ctx)) goto end;
329
330 while (1)
331 {
332 /* Now b is a^q * y^k for some even k (0 <= k < 2^E
333 * where E refers to the original value of e, which we
334 * don't keep in a variable), and x is a^((q+1)/2) * y^(k/2).
335 *
336 * We have a*b = x^2,
337 * y^2^(e-1) = -1,
338 * b^2^(e-1) = 1.
339 */
340
341 if (BN_is_one(b))
342 {
343 if (!BN_copy(ret, x)) goto end;
344 err = 0;
345 goto end;
346 }
347
348
349 /* find smallest i such that b^(2^i) = 1 */
350 i = 1;
351 if (!BN_mod_sqr(t, b, p, ctx)) goto end;
352 while (!BN_is_one(t))
353 {
354 i++;
355 if (i == e)
356 {
357 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
358 goto end;
359 }
360 if (!BN_mod_mul(t, t, t, p, ctx)) goto end;
361 }
362
363
364 /* t := y^2^(e - i - 1) */
365 if (!BN_copy(t, y)) goto end;
366 for (j = e - i - 1; j > 0; j--)
367 {
368 if (!BN_mod_sqr(t, t, p, ctx)) goto end;
369 }
370 if (!BN_mod_mul(y, t, t, p, ctx)) goto end;
371 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
372 if (!BN_mod_mul(b, b, y, p, ctx)) goto end;
373 e = i;
374 }
375
376 end:
377 if (err)
378 {
379 if (ret != NULL && ret != in)
380 {
381 BN_clear_free(ret);
382 }
383 ret = NULL;
384 }
385 BN_CTX_end(ctx);
386 return ret;
387 }
diff --git a/src/lib/libssl/src/crypto/bn/divtest.c b/src/lib/libssl/src/crypto/bn/divtest.c
new file mode 100644
index 0000000000..13ba86e3c4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/divtest.c
@@ -0,0 +1,41 @@
1#include <openssl/bn.h>
2#include <openssl/rand.h>
3
4static int rand(n)
5{
6 unsigned char x[2];
7 RAND_pseudo_bytes(x,2);
8 return (x[0] + 2*x[1]);
9}
10
11static void bug(char *m, BIGNUM *a, BIGNUM *b)
12{
13 printf("%s!\na=",m);
14 BN_print_fp(stdout, a);
15 printf("\nb=");
16 BN_print_fp(stdout, b);
17 printf("\n");
18 fflush(stdout);
19}
20
21main()
22{
23 BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(),
24 *C=BN_new(), *D=BN_new();
25 BN_RECP_CTX *recp=BN_RECP_CTX_new();
26 BN_CTX *ctx=BN_CTX_new();
27
28 for(;;) {
29 BN_pseudo_rand(a,rand(),0,0);
30 BN_pseudo_rand(b,rand(),0,0);
31 if (BN_is_zero(b)) continue;
32
33 BN_RECP_CTX_set(recp,b,ctx);
34 if (BN_div(C,D,a,b,ctx) != 1)
35 bug("BN_div failed",a,b);
36 if (BN_div_recp(c,d,a,recp,ctx) != 1)
37 bug("BN_div_recp failed",a,b);
38 else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0)
39 bug("mismatch",a,b);
40 }
41}
diff --git a/src/lib/libssl/src/crypto/bn/exp.c b/src/lib/libssl/src/crypto/bn/exp.c
new file mode 100644
index 0000000000..ec443459d8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/exp.c
@@ -0,0 +1,60 @@
1#include <stdio.h>
2#include <openssl/tmdiff.h>
3#include "bn_lcl.h"
4
5#define SIZE 256
6#define NUM (8*8*8)
7#define MOD (8*8*8*8*8)
8
9main(argc,argv)
10int argc;
11char *argv[];
12 {
13 BN_CTX ctx;
14 BIGNUM a,b,c,r,rr,t,l;
15 int j,i,size=SIZE,num=NUM,mod=MOD;
16 char *start,*end;
17 BN_MONT_CTX mont;
18 double d,md;
19
20 BN_MONT_CTX_init(&mont);
21 BN_CTX_init(&ctx);
22 BN_init(&a);
23 BN_init(&b);
24 BN_init(&c);
25 BN_init(&r);
26
27 start=ms_time_new();
28 end=ms_time_new();
29 while (size <= 1024*8)
30 {
31 BN_rand(&a,size,0,0);
32 BN_rand(&b,size,1,0);
33 BN_rand(&c,size,0,1);
34
35 BN_mod(&a,&a,&c,&ctx);
36
37 ms_time_get(start);
38 for (i=0; i<10; i++)
39 BN_MONT_CTX_set(&mont,&c,&ctx);
40 ms_time_get(end);
41 md=ms_time_diff(start,end);
42
43 ms_time_get(start);
44 for (i=0; i<num; i++)
45 {
46 /* bn_mull(&r,&a,&b,&ctx); */
47 /* BN_sqr(&r,&a,&ctx); */
48 BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
49 }
50 ms_time_get(end);
51 d=ms_time_diff(start,end)/* *50/33 */;
52 printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
53 d,num,d/num,(int)((d/num)*mod),md/10.0);
54 num/=8;
55 mod/=8;
56 if (num <= 0) num=1;
57 size*=2;
58 }
59
60 }
diff --git a/src/lib/libssl/src/crypto/bn/todo b/src/lib/libssl/src/crypto/bn/todo
new file mode 100644
index 0000000000..e47e381aea
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/todo
@@ -0,0 +1,3 @@
1Cache RECP_CTX values
2make the result argument independant of the inputs.
3split up the _exp_ functions
diff --git a/src/lib/libssl/src/crypto/bn/vms-helper.c b/src/lib/libssl/src/crypto/bn/vms-helper.c
new file mode 100644
index 0000000000..73af337069
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/vms-helper.c
@@ -0,0 +1,66 @@
1/* vms-helper.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include "cryptlib.h"
58#include "bn_lcl.h"
59
60bn_div_words_abort(int i)
61{
62#if !defined(NO_STDIO) && !defined(WIN16)
63 fprintf(stderr,"Division would overflow (%d)\n",i);
64#endif
65 abort();
66}
diff --git a/src/lib/libssl/src/crypto/comp/c_rle.c b/src/lib/libssl/src/crypto/comp/c_rle.c
new file mode 100644
index 0000000000..1a819e3737
--- /dev/null
+++ b/src/lib/libssl/src/crypto/comp/c_rle.c
@@ -0,0 +1,61 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
8 unsigned int olen, unsigned char *in, unsigned int ilen);
9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
10 unsigned int olen, unsigned char *in, unsigned int ilen);
11
12static COMP_METHOD rle_method={
13 NID_rle_compression,
14 LN_rle_compression,
15 NULL,
16 NULL,
17 rle_compress_block,
18 rle_expand_block,
19 NULL,
20 };
21
22COMP_METHOD *COMP_rle(void)
23 {
24 return(&rle_method);
25 }
26
27static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen)
29 {
30 /* int i; */
31
32 if (olen < (ilen+1))
33 {
34 /* ZZZZZZZZZZZZZZZZZZZZZZ */
35 return(-1);
36 }
37
38 *(out++)=0;
39 memcpy(out,in,ilen);
40 return(ilen+1);
41 }
42
43static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen)
45 {
46 int i;
47
48 if (olen < (ilen-1))
49 {
50 /* ZZZZZZZZZZZZZZZZZZZZZZ */
51 return(-1);
52 }
53
54 i= *(in++);
55 if (i == 0)
56 {
57 memcpy(out,in,ilen-1);
58 }
59 return(ilen-1);
60 }
61
diff --git a/src/lib/libssl/src/crypto/comp/c_zlib.c b/src/lib/libssl/src/crypto/comp/c_zlib.c
new file mode 100644
index 0000000000..6684ab4841
--- /dev/null
+++ b/src/lib/libssl/src/crypto/comp/c_zlib.c
@@ -0,0 +1,133 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7COMP_METHOD *COMP_zlib(void );
8
9#ifndef ZLIB
10
11static COMP_METHOD zlib_method={
12 NID_undef,
13 "(null)",
14 NULL,
15 NULL,
16 NULL,
17 NULL,
18 NULL,
19 };
20
21#else
22
23#include <zlib.h>
24
25static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
26 unsigned int olen, unsigned char *in, unsigned int ilen);
27static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
29
30static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
31 uLong sourceLen);
32
33static COMP_METHOD zlib_method={
34 NID_zlib_compression,
35 LN_zlib_compression,
36 NULL,
37 NULL,
38 zlib_compress_block,
39 zlib_expand_block,
40 NULL,
41 };
42
43static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen)
45 {
46 unsigned long l;
47 int i;
48 int clear=1;
49
50 if (ilen > 128)
51 {
52 out[0]=1;
53 l=olen-1;
54 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
55 if (i != Z_OK)
56 return(-1);
57 if (ilen > l)
58 {
59 clear=0;
60 l++;
61 }
62 }
63 if (clear)
64 {
65 out[0]=0;
66 memcpy(&(out[1]),in,ilen);
67 l=ilen+1;
68 }
69fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib");
70 return((int)l);
71 }
72
73static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
74 unsigned int olen, unsigned char *in, unsigned int ilen)
75 {
76 unsigned long l;
77 int i;
78
79 if (in[0])
80 {
81 l=olen;
82 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
83 if (i != Z_OK)
84 return(-1);
85 }
86 else
87 {
88 memcpy(out,&(in[1]),ilen-1);
89 l=ilen-1;
90 }
91 fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear");
92 return((int)l);
93 }
94
95static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
96 uLong sourceLen)
97{
98 z_stream stream;
99 int err;
100
101 stream.next_in = (Bytef*)source;
102 stream.avail_in = (uInt)sourceLen;
103 /* Check for source > 64K on 16-bit machine: */
104 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
105
106 stream.next_out = dest;
107 stream.avail_out = (uInt)*destLen;
108 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
109
110 stream.zalloc = (alloc_func)0;
111 stream.zfree = (free_func)0;
112
113 err = inflateInit(&stream);
114 if (err != Z_OK) return err;
115
116 err = inflate(&stream, Z_FINISH);
117 if (err != Z_STREAM_END) {
118 inflateEnd(&stream);
119 return err;
120 }
121 *destLen = stream.total_out;
122
123 err = inflateEnd(&stream);
124 return err;
125}
126
127#endif
128
129COMP_METHOD *COMP_zlib(void)
130 {
131 return(&zlib_method);
132 }
133
diff --git a/src/lib/libssl/src/crypto/comp/comp.h b/src/lib/libssl/src/crypto/comp/comp.h
new file mode 100644
index 0000000000..93bd9c34c8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/comp/comp.h
@@ -0,0 +1,60 @@
1
2#ifndef HEADER_COMP_H
3#define HEADER_COMP_H
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#include <openssl/crypto.h>
10
11typedef struct comp_method_st
12 {
13 int type; /* NID for compression library */
14 const char *name; /* A text string to identify the library */
15 int (*init)();
16 void (*finish)();
17 int (*compress)();
18 int (*expand)();
19 long (*ctrl)();
20 } COMP_METHOD;
21
22typedef struct comp_ctx_st
23 {
24 COMP_METHOD *meth;
25 unsigned long compress_in;
26 unsigned long compress_out;
27 unsigned long expand_in;
28 unsigned long expand_out;
29
30 CRYPTO_EX_DATA ex_data;
31 } COMP_CTX;
32
33
34COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
35void COMP_CTX_free(COMP_CTX *ctx);
36int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
37 unsigned char *in, int ilen);
38int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
39 unsigned char *in, int ilen);
40COMP_METHOD *COMP_rle(void );
41#ifdef ZLIB
42COMP_METHOD *COMP_zlib(void );
43#endif
44
45/* BEGIN ERROR CODES */
46/* The following lines are auto generated by the script mkerr.pl. Any changes
47 * made after this point may be overwritten when the script is next run.
48 */
49
50/* Error codes for the COMP functions. */
51
52/* Function codes. */
53
54/* Reason codes. */
55
56#ifdef __cplusplus
57}
58#endif
59#endif
60
diff --git a/src/lib/libssl/src/crypto/comp/comp_err.c b/src/lib/libssl/src/crypto/comp/comp_err.c
new file mode 100644
index 0000000000..77a3f7070c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/comp/comp_err.c
@@ -0,0 +1,91 @@
1/* crypto/comp/comp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/comp.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA COMP_str_functs[]=
67 {
68{0,NULL}
69 };
70
71static ERR_STRING_DATA COMP_str_reasons[]=
72 {
73{0,NULL}
74 };
75
76#endif
77
78void ERR_load_COMP_strings(void)
79 {
80 static int init=1;
81
82 if (init)
83 {
84 init=0;
85#ifndef NO_ERR
86 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
87 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
88#endif
89
90 }
91 }
diff --git a/src/lib/libssl/src/crypto/comp/comp_lib.c b/src/lib/libssl/src/crypto/comp/comp_lib.c
new file mode 100644
index 0000000000..a67ef23bc0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/comp/comp_lib.c
@@ -0,0 +1,78 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8 {
9 COMP_CTX *ret;
10
11 if ((ret=(COMP_CTX *)Malloc(sizeof(COMP_CTX))) == NULL)
12 {
13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL);
15 }
16 memset(ret,0,sizeof(COMP_CTX));
17 ret->meth=meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
19 {
20 Free(ret);
21 ret=NULL;
22 }
23#if 0
24 else
25 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
26#endif
27 return(ret);
28 }
29
30void COMP_CTX_free(COMP_CTX *ctx)
31 {
32 /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */
33
34 if(ctx == NULL)
35 return;
36
37 if (ctx->meth->finish != NULL)
38 ctx->meth->finish(ctx);
39
40 Free(ctx);
41 }
42
43int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
44 unsigned char *in, int ilen)
45 {
46 int ret;
47 if (ctx->meth->compress == NULL)
48 {
49 /* ZZZZZZZZZZZZZZZZZ */
50 return(-1);
51 }
52 ret=ctx->meth->compress(ctx,out,olen,in,ilen);
53 if (ret > 0)
54 {
55 ctx->compress_in+=ilen;
56 ctx->compress_out+=ret;
57 }
58 return(ret);
59 }
60
61int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
62 unsigned char *in, int ilen)
63 {
64 int ret;
65
66 if (ctx->meth->expand == NULL)
67 {
68 /* ZZZZZZZZZZZZZZZZZ */
69 return(-1);
70 }
71 ret=ctx->meth->expand(ctx,out,olen,in,ilen);
72 if (ret > 0)
73 {
74 ctx->expand_in+=ilen;
75 ctx->expand_out+=ret;
76 }
77 return(ret);
78 }
diff --git a/src/lib/libssl/src/crypto/conf/README b/src/lib/libssl/src/crypto/conf/README
new file mode 100644
index 0000000000..ca58d0240f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/README
@@ -0,0 +1,78 @@
1WARNING WARNING WARNING!!!
2
3This stuff is experimental, may change radically or be deleted altogether
4before OpenSSL 0.9.7 release. You have been warned!
5
6Configuration modules. These are a set of modules which can perform
7various configuration functions.
8
9Currently the routines should be called at most once when an application
10starts up: that is before it starts any threads.
11
12The routines read a configuration file set up like this:
13
14-----
15#default section
16openssl_init=init_section
17
18[init_section]
19
20module1=value1
21#Second instance of module1
22module1.1=valueX
23module2=value2
24module3=dso_literal
25module4=dso_section
26
27[dso_section]
28
29path=/some/path/to/some/dso.so
30other_stuff=other_value
31----
32
33When this file is loaded a configuration module with the specified
34string (module* in the above example) is looked up and its init
35function called as:
36
37int conf_init_func(CONF_IMODULE *md, CONF *cnf);
38
39The function can then take whatever action is appropriate, for example
40further lookups based on the value. Multiple instances of the same
41config module can be loaded.
42
43When the application closes down the modules are cleaned up by calling
44an optional finish function:
45
46void conf_finish_func(CONF_IMODULE *md);
47
48The finish functions are called in reverse order: that is the last module
49loaded is the first one cleaned up.
50
51If no module exists with a given name then an attempt is made to load
52a DSO with the supplied name. This might mean that "module3" attempts
53to load a DSO called libmodule3.so or module3.dll for example. An explicit
54DSO name can be given by including a separate section as in the module4 example
55above.
56
57The DSO is expected to at least contain an initialization function:
58
59int OPENSSL_init(CONF_IMODULE *md, CONF *cnf);
60
61and may also include a finish function:
62
63void OPENSSL_finish(CONF_IMODULE *md);
64
65Static modules can also be added using,
66
67int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc);
68
69where "name" is the name in the configuration file this function corresponds to.
70
71A set of builtin modules (currently only an ASN1 non functional test module) can be
72added by calling OPENSSL_load_builtin_modules().
73
74The function OPENSSL_config() is intended as a simple configuration function that
75any application can call to perform various default configuration tasks. It uses the
76file openssl.cnf in the usual locations.
77
78
diff --git a/src/lib/libssl/src/crypto/conf/conf_api.c b/src/lib/libssl/src/crypto/conf/conf_api.c
new file mode 100644
index 0000000000..d05a778ff6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_api.c
@@ -0,0 +1,289 @@
1/* conf_api.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#ifndef CONF_DEBUG
62# undef NDEBUG /* avoid conflicting definitions */
63# define NDEBUG
64#endif
65
66#include <assert.h>
67#include <string.h>
68#include <openssl/conf.h>
69#include <openssl/conf_api.h>
70
71static void value_free_hash(CONF_VALUE *a, LHASH *conf);
72static void value_free_stack(CONF_VALUE *a,LHASH *conf);
73static unsigned long hash(CONF_VALUE *v);
74static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b);
75
76/* Up until OpenSSL 0.9.5a, this was get_section */
77CONF_VALUE *_CONF_get_section(CONF *conf, char *section)
78 {
79 CONF_VALUE *v,vv;
80
81 if ((conf == NULL) || (section == NULL)) return(NULL);
82 vv.name=NULL;
83 vv.section=section;
84 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
85 return(v);
86 }
87
88/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
89STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section)
90 {
91 CONF_VALUE *v;
92
93 v=_CONF_get_section(conf,section);
94 if (v != NULL)
95 return((STACK_OF(CONF_VALUE) *)v->value);
96 else
97 return(NULL);
98 }
99
100int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
101 {
102 CONF_VALUE *v = NULL;
103 STACK_OF(CONF_VALUE) *ts;
104
105 ts = (STACK_OF(CONF_VALUE) *)section->value;
106
107 value->section=section->section;
108 if (!sk_CONF_VALUE_push(ts,value))
109 {
110 return 0;
111 }
112
113 v = (CONF_VALUE *)lh_insert(conf->data, value);
114 if (v != NULL)
115 {
116 sk_CONF_VALUE_delete_ptr(ts,v);
117 OPENSSL_free(v->name);
118 OPENSSL_free(v->value);
119 OPENSSL_free(v);
120 }
121 return 1;
122 }
123
124char *_CONF_get_string(CONF *conf, char *section, char *name)
125 {
126 CONF_VALUE *v,vv;
127 char *p;
128
129 if (name == NULL) return(NULL);
130 if (conf != NULL)
131 {
132 if (section != NULL)
133 {
134 vv.name=name;
135 vv.section=section;
136 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
137 if (v != NULL) return(v->value);
138 if (strcmp(section,"ENV") == 0)
139 {
140 p=Getenv(name);
141 if (p != NULL) return(p);
142 }
143 }
144 vv.section="default";
145 vv.name=name;
146 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
147 if (v != NULL)
148 return(v->value);
149 else
150 return(NULL);
151 }
152 else
153 return(Getenv(name));
154 }
155
156long _CONF_get_number(CONF *conf, char *section, char *name)
157 {
158 char *str;
159 long ret=0;
160
161 str=_CONF_get_string(conf,section,name);
162 if (str == NULL) return(0);
163 for (;;)
164 {
165 if (conf->meth->is_number(conf, *str))
166 ret=ret*10+conf->meth->to_int(conf, *str);
167 else
168 return(ret);
169 str++;
170 }
171 }
172
173int _CONF_new_data(CONF *conf)
174 {
175 if (conf == NULL)
176 {
177 return 0;
178 }
179 if (conf->data == NULL)
180 if ((conf->data = lh_new(hash,cmp_conf)) == NULL)
181 {
182 return 0;
183 }
184 return 1;
185 }
186
187void _CONF_free_data(CONF *conf)
188 {
189 if (conf == NULL || conf->data == NULL) return;
190
191 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
192 * works as expected */
193 lh_doall_arg(conf->data,(void (*)())value_free_hash,conf->data);
194
195 /* We now have only 'section' entries in the hash table.
196 * Due to problems with */
197
198 lh_doall_arg(conf->data,(void (*)())value_free_stack,conf->data);
199 lh_free(conf->data);
200 }
201
202static void value_free_hash(CONF_VALUE *a, LHASH *conf)
203 {
204 if (a->name != NULL)
205 {
206 a=(CONF_VALUE *)lh_delete(conf,a);
207 }
208 }
209
210static void value_free_stack(CONF_VALUE *a, LHASH *conf)
211 {
212 CONF_VALUE *vv;
213 STACK *sk;
214 int i;
215
216 if (a->name != NULL) return;
217
218 sk=(STACK *)a->value;
219 for (i=sk_num(sk)-1; i>=0; i--)
220 {
221 vv=(CONF_VALUE *)sk_value(sk,i);
222 OPENSSL_free(vv->value);
223 OPENSSL_free(vv->name);
224 OPENSSL_free(vv);
225 }
226 if (sk != NULL) sk_free(sk);
227 OPENSSL_free(a->section);
228 OPENSSL_free(a);
229 }
230
231static unsigned long hash(CONF_VALUE *v)
232 {
233 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
234 }
235
236static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
237 {
238 int i;
239
240 if (a->section != b->section)
241 {
242 i=strcmp(a->section,b->section);
243 if (i) return(i);
244 }
245
246 if ((a->name != NULL) && (b->name != NULL))
247 {
248 i=strcmp(a->name,b->name);
249 return(i);
250 }
251 else if (a->name == b->name)
252 return(0);
253 else
254 return((a->name == NULL)?-1:1);
255 }
256
257/* Up until OpenSSL 0.9.5a, this was new_section */
258CONF_VALUE *_CONF_new_section(CONF *conf, char *section)
259 {
260 STACK *sk=NULL;
261 int ok=0,i;
262 CONF_VALUE *v=NULL,*vv;
263
264 if ((sk=sk_new_null()) == NULL)
265 goto err;
266 if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
267 goto err;
268 i=strlen(section)+1;
269 if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
270 goto err;
271
272 memcpy(v->section,section,i);
273 v->name=NULL;
274 v->value=(char *)sk;
275
276 vv=(CONF_VALUE *)lh_insert(conf->data,v);
277 assert(vv == NULL);
278 ok=1;
279err:
280 if (!ok)
281 {
282 if (sk != NULL) sk_free(sk);
283 if (v != NULL) OPENSSL_free(v);
284 v=NULL;
285 }
286 return(v);
287 }
288
289IMPLEMENT_STACK_OF(CONF_VALUE)
diff --git a/src/lib/libssl/src/crypto/conf/conf_api.h b/src/lib/libssl/src/crypto/conf/conf_api.h
new file mode 100644
index 0000000000..a5cc17b233
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_api.h
@@ -0,0 +1,87 @@
1/* conf_api.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CONF_API_H
60#define HEADER_CONF_API_H
61
62#include <openssl/lhash.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* Up until OpenSSL 0.9.5a, this was new_section */
70CONF_VALUE *_CONF_new_section(CONF *conf, char *section);
71/* Up until OpenSSL 0.9.5a, this was get_section */
72CONF_VALUE *_CONF_get_section(CONF *conf, char *section);
73/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
74STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section);
75
76int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
77char *_CONF_get_string(CONF *conf, char *section, char *name);
78long _CONF_get_number(CONF *conf, char *section, char *name);
79
80int _CONF_new_data(CONF *conf);
81void _CONF_free_data(CONF *conf);
82
83#ifdef __cplusplus
84}
85#endif
86#endif
87
diff --git a/src/lib/libssl/src/crypto/conf/conf_def.c b/src/lib/libssl/src/crypto/conf/conf_def.c
new file mode 100644
index 0000000000..773df32c68
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_def.c
@@ -0,0 +1,703 @@
1/* crypto/conf/conf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#include <stdio.h>
62#include <string.h>
63#include <openssl/stack.h>
64#include <openssl/lhash.h>
65#include <openssl/conf.h>
66#include <openssl/conf_api.h>
67#include "conf_def.h"
68#include <openssl/buffer.h>
69#include <openssl/err.h>
70
71static char *eat_ws(CONF *conf, char *p);
72static char *eat_alpha_numeric(CONF *conf, char *p);
73static void clear_comments(CONF *conf, char *p);
74static int str_copy(CONF *conf,char *section,char **to, char *from);
75static char *scan_quote(CONF *conf, char *p);
76static char *scan_dquote(CONF *conf, char *p);
77#define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
78
79static CONF *def_create(CONF_METHOD *meth);
80static int def_init_default(CONF *conf);
81static int def_init_WIN32(CONF *conf);
82static int def_destroy(CONF *conf);
83static int def_destroy_data(CONF *conf);
84static int def_load(CONF *conf, BIO *bp, long *eline);
85static int def_dump(CONF *conf, BIO *bp);
86static int def_is_number(CONF *conf, char c);
87static int def_to_int(CONF *conf, char c);
88
89const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
90
91static CONF_METHOD default_method = {
92 "OpenSSL default",
93 def_create,
94 def_init_default,
95 def_destroy,
96 def_destroy_data,
97 def_load,
98 def_dump,
99 def_is_number,
100 def_to_int
101 };
102
103static CONF_METHOD WIN32_method = {
104 "WIN32",
105 def_create,
106 def_init_WIN32,
107 def_destroy,
108 def_destroy_data,
109 def_load,
110 def_dump,
111 def_is_number,
112 def_to_int
113 };
114
115CONF_METHOD *NCONF_default()
116 {
117 return &default_method;
118 }
119CONF_METHOD *NCONF_WIN32()
120 {
121 return &WIN32_method;
122 }
123
124static CONF *def_create(CONF_METHOD *meth)
125 {
126 CONF *ret;
127
128 ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
129 if (ret)
130 if (meth->init(ret) == 0)
131 {
132 OPENSSL_free(ret);
133 ret = NULL;
134 }
135 return ret;
136 }
137
138static int def_init_default(CONF *conf)
139 {
140 if (conf == NULL)
141 return 0;
142
143 conf->meth = &default_method;
144 conf->meth_data = (void *)CONF_type_default;
145 conf->data = NULL;
146
147 return 1;
148 }
149
150static int def_init_WIN32(CONF *conf)
151 {
152 if (conf == NULL)
153 return 0;
154
155 conf->meth = &WIN32_method;
156 conf->meth_data = (void *)CONF_type_win32;
157 conf->data = NULL;
158
159 return 1;
160 }
161
162static int def_destroy(CONF *conf)
163 {
164 if (def_destroy_data(conf))
165 {
166 OPENSSL_free(conf);
167 return 1;
168 }
169 return 0;
170 }
171
172static int def_destroy_data(CONF *conf)
173 {
174 if (conf == NULL)
175 return 0;
176 _CONF_free_data(conf);
177 return 1;
178 }
179
180static int def_load(CONF *conf, BIO *in, long *line)
181 {
182#define BUFSIZE 512
183 char btmp[16];
184 int bufnum=0,i,ii;
185 BUF_MEM *buff=NULL;
186 char *s,*p,*end;
187 int again,n;
188 long eline=0;
189 CONF_VALUE *v=NULL,*tv;
190 CONF_VALUE *sv=NULL;
191 char *section=NULL,*buf;
192 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
193 char *start,*psection,*pname;
194 void *h = (void *)(conf->data);
195
196 if ((buff=BUF_MEM_new()) == NULL)
197 {
198 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
199 goto err;
200 }
201
202 section=(char *)OPENSSL_malloc(10);
203 if (section == NULL)
204 {
205 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
206 goto err;
207 }
208 strcpy(section,"default");
209
210 if (_CONF_new_data(conf) == 0)
211 {
212 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
213 goto err;
214 }
215
216 sv=_CONF_new_section(conf,section);
217 if (sv == NULL)
218 {
219 CONFerr(CONF_F_CONF_LOAD_BIO,
220 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
221 goto err;
222 }
223 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
224
225 bufnum=0;
226 for (;;)
227 {
228 again=0;
229 if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
230 {
231 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
232 goto err;
233 }
234 p= &(buff->data[bufnum]);
235 *p='\0';
236 BIO_gets(in, p, BUFSIZE-1);
237 p[BUFSIZE-1]='\0';
238 ii=i=strlen(p);
239 if (i == 0) break;
240 while (i > 0)
241 {
242 if ((p[i-1] != '\r') && (p[i-1] != '\n'))
243 break;
244 else
245 i--;
246 }
247 /* we removed some trailing stuff so there is a new
248 * line on the end. */
249 if (i == ii)
250 again=1; /* long line */
251 else
252 {
253 p[i]='\0';
254 eline++; /* another input line */
255 }
256
257 /* we now have a line with trailing \r\n removed */
258
259 /* i is the number of bytes */
260 bufnum+=i;
261
262 v=NULL;
263 /* check for line continuation */
264 if (bufnum >= 1)
265 {
266 /* If we have bytes and the last char '\\' and
267 * second last char is not '\\' */
268 p= &(buff->data[bufnum-1]);
269 if (IS_ESC(conf,p[0]) &&
270 ((bufnum <= 1) || !IS_ESC(conf,p[-1])))
271 {
272 bufnum--;
273 again=1;
274 }
275 }
276 if (again) continue;
277 bufnum=0;
278 buf=buff->data;
279
280 clear_comments(conf, buf);
281 n=strlen(buf);
282 s=eat_ws(conf, buf);
283 if (IS_EOF(conf,*s)) continue; /* blank line */
284 if (*s == '[')
285 {
286 char *ss;
287
288 s++;
289 start=eat_ws(conf, s);
290 ss=start;
291again:
292 end=eat_alpha_numeric(conf, ss);
293 p=eat_ws(conf, end);
294 if (*p != ']')
295 {
296 if (*p != '\0')
297 {
298 ss=p;
299 goto again;
300 }
301 CONFerr(CONF_F_CONF_LOAD_BIO,
302 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
303 goto err;
304 }
305 *end='\0';
306 if (!str_copy(conf,NULL,&section,start)) goto err;
307 if ((sv=_CONF_get_section(conf,section)) == NULL)
308 sv=_CONF_new_section(conf,section);
309 if (sv == NULL)
310 {
311 CONFerr(CONF_F_CONF_LOAD_BIO,
312 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
313 goto err;
314 }
315 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
316 continue;
317 }
318 else
319 {
320 pname=s;
321 psection=NULL;
322 end=eat_alpha_numeric(conf, s);
323 if ((end[0] == ':') && (end[1] == ':'))
324 {
325 *end='\0';
326 end+=2;
327 psection=pname;
328 pname=end;
329 end=eat_alpha_numeric(conf, end);
330 }
331 p=eat_ws(conf, end);
332 if (*p != '=')
333 {
334 CONFerr(CONF_F_CONF_LOAD_BIO,
335 CONF_R_MISSING_EQUAL_SIGN);
336 goto err;
337 }
338 *end='\0';
339 p++;
340 start=eat_ws(conf, p);
341 while (!IS_EOF(conf,*p))
342 p++;
343 p--;
344 while ((p != start) && (IS_WS(conf,*p)))
345 p--;
346 p++;
347 *p='\0';
348
349 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
350 {
351 CONFerr(CONF_F_CONF_LOAD_BIO,
352 ERR_R_MALLOC_FAILURE);
353 goto err;
354 }
355 if (psection == NULL) psection=section;
356 v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
357 v->value=NULL;
358 if (v->name == NULL)
359 {
360 CONFerr(CONF_F_CONF_LOAD_BIO,
361 ERR_R_MALLOC_FAILURE);
362 goto err;
363 }
364 strcpy(v->name,pname);
365 if (!str_copy(conf,psection,&(v->value),start)) goto err;
366
367 if (strcmp(psection,section) != 0)
368 {
369 if ((tv=_CONF_get_section(conf,psection))
370 == NULL)
371 tv=_CONF_new_section(conf,psection);
372 if (tv == NULL)
373 {
374 CONFerr(CONF_F_CONF_LOAD_BIO,
375 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
376 goto err;
377 }
378 ts=(STACK_OF(CONF_VALUE) *)tv->value;
379 }
380 else
381 {
382 tv=sv;
383 ts=section_sk;
384 }
385#if 1
386 if (_CONF_add_string(conf, tv, v) == 0)
387 {
388 CONFerr(CONF_F_CONF_LOAD_BIO,
389 ERR_R_MALLOC_FAILURE);
390 goto err;
391 }
392#else
393 v->section=tv->section;
394 if (!sk_CONF_VALUE_push(ts,v))
395 {
396 CONFerr(CONF_F_CONF_LOAD_BIO,
397 ERR_R_MALLOC_FAILURE);
398 goto err;
399 }
400 vv=(CONF_VALUE *)lh_insert(conf->data,v);
401 if (vv != NULL)
402 {
403 sk_CONF_VALUE_delete_ptr(ts,vv);
404 OPENSSL_free(vv->name);
405 OPENSSL_free(vv->value);
406 OPENSSL_free(vv);
407 }
408#endif
409 v=NULL;
410 }
411 }
412 if (buff != NULL) BUF_MEM_free(buff);
413 if (section != NULL) OPENSSL_free(section);
414 return(1);
415err:
416 if (buff != NULL) BUF_MEM_free(buff);
417 if (section != NULL) OPENSSL_free(section);
418 if (line != NULL) *line=eline;
419 sprintf(btmp,"%ld",eline);
420 ERR_add_error_data(2,"line ",btmp);
421 if ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data);
422 if (v != NULL)
423 {
424 if (v->name != NULL) OPENSSL_free(v->name);
425 if (v->value != NULL) OPENSSL_free(v->value);
426 if (v != NULL) OPENSSL_free(v);
427 }
428 return(0);
429 }
430
431static void clear_comments(CONF *conf, char *p)
432 {
433 char *to;
434
435 to=p;
436 for (;;)
437 {
438 if (IS_FCOMMENT(conf,*p))
439 {
440 *p='\0';
441 return;
442 }
443 if (!IS_WS(conf,*p))
444 {
445 break;
446 }
447 p++;
448 }
449
450 for (;;)
451 {
452 if (IS_COMMENT(conf,*p))
453 {
454 *p='\0';
455 return;
456 }
457 if (IS_DQUOTE(conf,*p))
458 {
459 p=scan_dquote(conf, p);
460 continue;
461 }
462 if (IS_QUOTE(conf,*p))
463 {
464 p=scan_quote(conf, p);
465 continue;
466 }
467 if (IS_ESC(conf,*p))
468 {
469 p=scan_esc(conf,p);
470 continue;
471 }
472 if (IS_EOF(conf,*p))
473 return;
474 else
475 p++;
476 }
477 }
478
479static int str_copy(CONF *conf, char *section, char **pto, char *from)
480 {
481 int q,r,rr=0,to=0,len=0;
482 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
483 BUF_MEM *buf;
484
485 if ((buf=BUF_MEM_new()) == NULL) return(0);
486
487 len=strlen(from)+1;
488 if (!BUF_MEM_grow(buf,len)) goto err;
489
490 for (;;)
491 {
492 if (IS_QUOTE(conf,*from))
493 {
494 q= *from;
495 from++;
496 while (!IS_EOF(conf,*from) && (*from != q))
497 {
498 if (IS_ESC(conf,*from))
499 {
500 from++;
501 if (IS_EOF(conf,*from)) break;
502 }
503 buf->data[to++]= *(from++);
504 }
505 if (*from == q) from++;
506 }
507 else if (IS_DQUOTE(conf,*from))
508 {
509 q= *from;
510 from++;
511 while (!IS_EOF(conf,*from))
512 {
513 if (*from == q)
514 {
515 if (*(from+1) == q)
516 {
517 from++;
518 }
519 else
520 {
521 break;
522 }
523 }
524 buf->data[to++]= *(from++);
525 }
526 if (*from == q) from++;
527 }
528 else if (IS_ESC(conf,*from))
529 {
530 from++;
531 v= *(from++);
532 if (IS_EOF(conf,v)) break;
533 else if (v == 'r') v='\r';
534 else if (v == 'n') v='\n';
535 else if (v == 'b') v='\b';
536 else if (v == 't') v='\t';
537 buf->data[to++]= v;
538 }
539 else if (IS_EOF(conf,*from))
540 break;
541 else if (*from == '$')
542 {
543 /* try to expand it */
544 rrp=NULL;
545 s= &(from[1]);
546 if (*s == '{')
547 q='}';
548 else if (*s == '(')
549 q=')';
550 else q=0;
551
552 if (q) s++;
553 cp=section;
554 e=np=s;
555 while (IS_ALPHA_NUMERIC(conf,*e))
556 e++;
557 if ((e[0] == ':') && (e[1] == ':'))
558 {
559 cp=np;
560 rrp=e;
561 rr= *e;
562 *rrp='\0';
563 e+=2;
564 np=e;
565 while (IS_ALPHA_NUMERIC(conf,*e))
566 e++;
567 }
568 r= *e;
569 *e='\0';
570 rp=e;
571 if (q)
572 {
573 if (r != q)
574 {
575 CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
576 goto err;
577 }
578 e++;
579 }
580 /* So at this point we have
581 * ns which is the start of the name string which is
582 * '\0' terminated.
583 * cs which is the start of the section string which is
584 * '\0' terminated.
585 * e is the 'next point after'.
586 * r and s are the chars replaced by the '\0'
587 * rp and sp is where 'r' and 's' came from.
588 */
589 p=_CONF_get_string(conf,cp,np);
590 if (rrp != NULL) *rrp=rr;
591 *rp=r;
592 if (p == NULL)
593 {
594 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
595 goto err;
596 }
597 BUF_MEM_grow(buf,(strlen(p)+len-(e-from)));
598 while (*p)
599 buf->data[to++]= *(p++);
600 from=e;
601 }
602 else
603 buf->data[to++]= *(from++);
604 }
605 buf->data[to]='\0';
606 if (*pto != NULL) OPENSSL_free(*pto);
607 *pto=buf->data;
608 OPENSSL_free(buf);
609 return(1);
610err:
611 if (buf != NULL) BUF_MEM_free(buf);
612 return(0);
613 }
614
615static char *eat_ws(CONF *conf, char *p)
616 {
617 while (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
618 p++;
619 return(p);
620 }
621
622static char *eat_alpha_numeric(CONF *conf, char *p)
623 {
624 for (;;)
625 {
626 if (IS_ESC(conf,*p))
627 {
628 p=scan_esc(conf,p);
629 continue;
630 }
631 if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
632 return(p);
633 p++;
634 }
635 }
636
637static char *scan_quote(CONF *conf, char *p)
638 {
639 int q= *p;
640
641 p++;
642 while (!(IS_EOF(conf,*p)) && (*p != q))
643 {
644 if (IS_ESC(conf,*p))
645 {
646 p++;
647 if (IS_EOF(conf,*p)) return(p);
648 }
649 p++;
650 }
651 if (*p == q) p++;
652 return(p);
653 }
654
655
656static char *scan_dquote(CONF *conf, char *p)
657 {
658 int q= *p;
659
660 p++;
661 while (!(IS_EOF(conf,*p)))
662 {
663 if (*p == q)
664 {
665 if (*(p+1) == q)
666 {
667 p++;
668 }
669 else
670 {
671 break;
672 }
673 }
674 p++;
675 }
676 if (*p == q) p++;
677 return(p);
678 }
679
680static void dump_value(CONF_VALUE *a, BIO *out)
681 {
682 if (a->name)
683 BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
684 else
685 BIO_printf(out, "[[%s]]\n", a->section);
686 }
687
688static int def_dump(CONF *conf, BIO *out)
689 {
690 lh_doall_arg(conf->data, (void (*)())dump_value, out);
691 return 1;
692 }
693
694static int def_is_number(CONF *conf, char c)
695 {
696 return IS_NUMBER(conf,c);
697 }
698
699static int def_to_int(CONF *conf, char c)
700 {
701 return c - '0';
702 }
703
diff --git a/src/lib/libssl/src/crypto/conf/conf_def.h b/src/lib/libssl/src/crypto/conf/conf_def.h
new file mode 100644
index 0000000000..3244d9a331
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_def.h
@@ -0,0 +1,145 @@
1/* crypto/conf/conf_def.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE WAS AUTOMAGICALLY GENERATED!
60 Please modify and use keysets.pl to regenerate it. */
61
62#define CONF_NUMBER 1
63#define CONF_UPPER 2
64#define CONF_LOWER 4
65#define CONF_UNDER 256
66#define CONF_PUNCTUATION 512
67#define CONF_WS 16
68#define CONF_ESC 32
69#define CONF_QUOTE 64
70#define CONF_DQUOTE 1024
71#define CONF_COMMENT 128
72#define CONF_FCOMMENT 2048
73#define CONF_EOF 8
74#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
75#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
76#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
77 CONF_PUNCTUATION)
78
79#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
80#ifndef CHARSET_EBCDIC
81#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT)
82#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT)
83#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF)
84#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC)
85#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER)
86#define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS)
87#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC)
88#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
89 (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
90#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE)
91#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE)
92
93#else /*CHARSET_EBCDIC*/
94
95#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT)
96#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT)
97#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF)
98#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC)
99#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER)
100#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS)
101#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC)
102#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
103 (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
104#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE)
105#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE)
106#endif /*CHARSET_EBCDIC*/
107
108static unsigned short CONF_type_default[128]={
109 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
110 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000,
111 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
112 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
113 0x010,0x200,0x040,0x080,0x000,0x200,0x200,0x040,
114 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200,
115 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001,
116 0x001,0x001,0x000,0x200,0x000,0x000,0x000,0x200,
117 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
118 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
119 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
120 0x002,0x002,0x002,0x000,0x020,0x000,0x200,0x100,
121 0x040,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
122 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
123 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
124 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000,
125 };
126
127static unsigned short CONF_type_win32[128]={
128 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
129 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000,
130 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
131 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
132 0x010,0x200,0x400,0x000,0x000,0x200,0x200,0x000,
133 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200,
134 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001,
135 0x001,0x001,0x000,0xA00,0x000,0x000,0x000,0x200,
136 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
137 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
138 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
139 0x002,0x002,0x002,0x000,0x000,0x000,0x200,0x100,
140 0x000,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
141 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
142 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
143 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000,
144 };
145
diff --git a/src/lib/libssl/src/crypto/conf/conf_lib.c b/src/lib/libssl/src/crypto/conf/conf_lib.c
new file mode 100644
index 0000000000..4c8ca9e9ae
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_lib.c
@@ -0,0 +1,352 @@
1/* conf_lib.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include <openssl/err.h>
62#include <openssl/conf.h>
63#include <openssl/conf_api.h>
64#include <openssl/lhash.h>
65
66const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67
68static CONF_METHOD *default_CONF_method=NULL;
69
70/* The following section contains the "CONF classic" functions,
71 rewritten in terms of the new CONF interface. */
72
73int CONF_set_default_method(CONF_METHOD *meth)
74 {
75 default_CONF_method = meth;
76 return 1;
77 }
78
79LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
80 {
81 LHASH *ltmp;
82 BIO *in=NULL;
83
84#ifdef VMS
85 in=BIO_new_file(file, "r");
86#else
87 in=BIO_new_file(file, "rb");
88#endif
89 if (in == NULL)
90 {
91 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
92 return NULL;
93 }
94
95 ltmp = CONF_load_bio(conf, in, eline);
96 BIO_free(in);
97
98 return ltmp;
99 }
100
101#ifndef NO_FP_API
102LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
103 {
104 BIO *btmp;
105 LHASH *ltmp;
106 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
107 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
108 return NULL;
109 }
110 ltmp = CONF_load_bio(conf, btmp, eline);
111 BIO_free(btmp);
112 return ltmp;
113 }
114#endif
115
116LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
117 {
118 CONF ctmp;
119 int ret;
120
121 if (default_CONF_method == NULL)
122 default_CONF_method = NCONF_default();
123
124 default_CONF_method->init(&ctmp);
125 ctmp.data = conf;
126 ret = NCONF_load_bio(&ctmp, bp, eline);
127 if (ret)
128 return ctmp.data;
129 return NULL;
130 }
131
132STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
133 {
134 CONF ctmp;
135
136 if (default_CONF_method == NULL)
137 default_CONF_method = NCONF_default();
138
139 default_CONF_method->init(&ctmp);
140 ctmp.data = conf;
141 return NCONF_get_section(&ctmp, section);
142 }
143
144char *CONF_get_string(LHASH *conf,char *group,char *name)
145 {
146 CONF ctmp;
147
148 if (default_CONF_method == NULL)
149 default_CONF_method = NCONF_default();
150
151 default_CONF_method->init(&ctmp);
152 ctmp.data = conf;
153 return NCONF_get_string(&ctmp, group, name);
154 }
155
156long CONF_get_number(LHASH *conf,char *group,char *name)
157 {
158 CONF ctmp;
159
160 if (default_CONF_method == NULL)
161 default_CONF_method = NCONF_default();
162
163 default_CONF_method->init(&ctmp);
164 ctmp.data = conf;
165 return NCONF_get_number(&ctmp, group, name);
166 }
167
168void CONF_free(LHASH *conf)
169 {
170 CONF ctmp;
171
172 if (default_CONF_method == NULL)
173 default_CONF_method = NCONF_default();
174
175 default_CONF_method->init(&ctmp);
176 ctmp.data = conf;
177 NCONF_free_data(&ctmp);
178 }
179
180#ifndef NO_FP_API
181int CONF_dump_fp(LHASH *conf, FILE *out)
182 {
183 BIO *btmp;
184 int ret;
185
186 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
187 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
188 return 0;
189 }
190 ret = CONF_dump_bio(conf, btmp);
191 BIO_free(btmp);
192 return ret;
193 }
194#endif
195
196int CONF_dump_bio(LHASH *conf, BIO *out)
197 {
198 CONF ctmp;
199
200 if (default_CONF_method == NULL)
201 default_CONF_method = NCONF_default();
202
203 default_CONF_method->init(&ctmp);
204 ctmp.data = conf;
205 return NCONF_dump_bio(&ctmp, out);
206 }
207
208/* The following section contains the "New CONF" functions. They are
209 completely centralised around a new CONF structure that may contain
210 basically anything, but at least a method pointer and a table of data.
211 These functions are also written in terms of the bridge functions used
212 by the "CONF classic" functions, for consistency. */
213
214CONF *NCONF_new(CONF_METHOD *meth)
215 {
216 CONF *ret;
217
218 if (meth == NULL)
219 meth = NCONF_default();
220
221 ret = meth->create(meth);
222 if (ret == NULL)
223 {
224 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
225 return(NULL);
226 }
227
228 return ret;
229 }
230
231void NCONF_free(CONF *conf)
232 {
233 if (conf == NULL)
234 return;
235 conf->meth->destroy(conf);
236 }
237
238void NCONF_free_data(CONF *conf)
239 {
240 if (conf == NULL)
241 return;
242 conf->meth->destroy_data(conf);
243 }
244
245int NCONF_load(CONF *conf, const char *file, long *eline)
246 {
247 int ret;
248 BIO *in=NULL;
249
250#ifdef VMS
251 in=BIO_new_file(file, "r");
252#else
253 in=BIO_new_file(file, "rb");
254#endif
255 if (in == NULL)
256 {
257 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
258 return 0;
259 }
260
261 ret = NCONF_load_bio(conf, in, eline);
262 BIO_free(in);
263
264 return ret;
265 }
266
267#ifndef NO_FP_API
268int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
269 {
270 BIO *btmp;
271 int ret;
272 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
273 {
274 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
275 return 0;
276 }
277 ret = NCONF_load_bio(conf, btmp, eline);
278 BIO_free(btmp);
279 return ret;
280 }
281#endif
282
283int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
284 {
285 if (conf == NULL)
286 {
287 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
288 return 0;
289 }
290
291 return conf->meth->load(conf, bp, eline);
292 }
293
294STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
295 {
296 if (conf == NULL)
297 {
298 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
299 return NULL;
300 }
301
302 return _CONF_get_section_values(conf, section);
303 }
304
305char *NCONF_get_string(CONF *conf,char *group,char *name)
306 {
307 if (conf == NULL)
308 {
309 CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF);
310 return NULL;
311 }
312
313 return _CONF_get_string(conf, group, name);
314 }
315
316long NCONF_get_number(CONF *conf,char *group,char *name)
317 {
318 if (conf == NULL)
319 {
320 CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF);
321 return 0;
322 }
323
324 return _CONF_get_number(conf, group, name);
325 }
326
327#ifndef NO_FP_API
328int NCONF_dump_fp(CONF *conf, FILE *out)
329 {
330 BIO *btmp;
331 int ret;
332 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
333 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
334 return 0;
335 }
336 ret = NCONF_dump_bio(conf, btmp);
337 BIO_free(btmp);
338 return ret;
339 }
340#endif
341
342int NCONF_dump_bio(CONF *conf, BIO *out)
343 {
344 if (conf == NULL)
345 {
346 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
347 return 0;
348 }
349
350 return conf->meth->dump(conf, out);
351 }
352
diff --git a/src/lib/libssl/src/crypto/conf/conf_mall.c b/src/lib/libssl/src/crypto/conf/conf_mall.c
new file mode 100644
index 0000000000..d702af689b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_mall.c
@@ -0,0 +1,76 @@
1/* conf_mall.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#include <openssl/engine.h>
67
68/* Load all OpenSSL builtin modules */
69
70void OPENSSL_load_builtin_modules(void)
71 {
72 /* Add builtin modules here */
73 ASN1_add_oid_module();
74 ENGINE_add_conf_module();
75 }
76
diff --git a/src/lib/libssl/src/crypto/conf/conf_mod.c b/src/lib/libssl/src/crypto/conf/conf_mod.c
new file mode 100644
index 0000000000..f92babc2e2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_mod.c
@@ -0,0 +1,616 @@
1/* conf_mod.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/dso.h>
65#include <openssl/x509.h>
66
67
68#define DSO_mod_init_name "OPENSSL_init"
69#define DSO_mod_finish_name "OPENSSL_finish"
70
71
72/* This structure contains a data about supported modules.
73 * entries in this table correspond to either dynamic or
74 * static modules.
75 */
76
77struct conf_module_st
78 {
79 /* DSO of this module or NULL if static */
80 DSO *dso;
81 /* Name of the module */
82 char *name;
83 /* Init function */
84 conf_init_func *init;
85 /* Finish function */
86 conf_finish_func *finish;
87 /* Number of successfully initialized modules */
88 int links;
89 void *usr_data;
90 };
91
92
93/* This structure contains information about modules that have been
94 * successfully initialized. There may be more than one entry for a
95 * given module.
96 */
97
98struct conf_imodule_st
99 {
100 CONF_MODULE *pmod;
101 char *name;
102 char *value;
103 unsigned long flags;
104 void *usr_data;
105 };
106
107static STACK_OF(CONF_MODULE) *supported_modules = NULL;
108static STACK_OF(CONF_IMODULE) *initialized_modules = NULL;
109
110static void module_free(CONF_MODULE *md);
111static void module_finish(CONF_IMODULE *imod);
112static int module_run(const CONF *cnf, char *name, char *value,
113 unsigned long flags);
114static CONF_MODULE *module_add(DSO *dso, const char *name,
115 conf_init_func *ifunc, conf_finish_func *ffunc);
116static CONF_MODULE *module_find(char *name);
117static int module_init(CONF_MODULE *pmod, char *name, char *value,
118 const CONF *cnf);
119static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
120 unsigned long flags);
121
122/* Main function: load modules from a CONF structure */
123
124int CONF_modules_load(const CONF *cnf, const char *appname,
125 unsigned long flags)
126 {
127 STACK_OF(CONF_VALUE) *values;
128 CONF_VALUE *vl;
129 char *vsection;
130
131 int ret, i;
132
133 if (!cnf)
134 return 1;
135
136 if (appname == NULL)
137 appname = "openssl_conf";
138
139 vsection = NCONF_get_string(cnf, NULL, appname);
140
141 if (!vsection)
142 {
143 ERR_clear_error();
144 return 1;
145 }
146
147 values = NCONF_get_section(cnf, vsection);
148
149 if (!values)
150 return 0;
151
152 for (i = 0; i < sk_CONF_VALUE_num(values); i++)
153 {
154 vl = sk_CONF_VALUE_value(values, i);
155 ret = module_run(cnf, vl->name, vl->value, flags);
156 if (ret <= 0)
157 if(!(flags & CONF_MFLAGS_IGNORE_ERRORS))
158 return ret;
159 }
160
161 return 1;
162
163 }
164
165int CONF_modules_load_file(const char *filename, const char *appname,
166 unsigned long flags)
167 {
168 char *file = NULL;
169 CONF *conf = NULL;
170 int ret = 0;
171 conf = NCONF_new(NULL);
172 if (!conf)
173 goto err;
174
175 if (filename == NULL)
176 {
177 file = CONF_get1_default_config_file();
178 if (!file)
179 goto err;
180 }
181 else
182 file = (char *)filename;
183
184 if (NCONF_load(conf, file, NULL) <= 0)
185 {
186 if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
187 (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE))
188 {
189 ERR_clear_error();
190 ret = 1;
191 }
192 goto err;
193 }
194
195 ret = CONF_modules_load(conf, appname, flags);
196
197 err:
198 if (filename == NULL)
199 OPENSSL_free(file);
200 NCONF_free(conf);
201
202 return ret;
203 }
204
205static int module_run(const CONF *cnf, char *name, char *value,
206 unsigned long flags)
207 {
208 CONF_MODULE *md;
209 int ret;
210
211 md = module_find(name);
212
213 /* Module not found: try to load DSO */
214 if (!md && !(flags & CONF_MFLAGS_NO_DSO))
215 md = module_load_dso(cnf, name, value, flags);
216
217 if (!md)
218 {
219 if (!(flags & CONF_MFLAGS_SILENT))
220 {
221 CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME);
222 ERR_add_error_data(2, "module=", name);
223 }
224 return -1;
225 }
226
227 ret = module_init(md, name, value, cnf);
228
229 if (ret <= 0)
230 {
231 if (!(flags & CONF_MFLAGS_SILENT))
232 {
233 char rcode[10];
234 CONFerr(CONF_F_CONF_MODULES_LOAD, CONF_R_MODULE_INITIALIZATION_ERROR);
235 sprintf(rcode, "%-8d", ret);
236 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode);
237 }
238 }
239
240 return ret;
241 }
242
243/* Load a module from a DSO */
244static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
245 unsigned long flags)
246 {
247 DSO *dso = NULL;
248 conf_init_func *ifunc;
249 conf_finish_func *ffunc;
250 char *path = NULL;
251 int errcode = 0;
252 CONF_MODULE *md;
253 /* Look for alternative path in module section */
254 path = NCONF_get_string(cnf, value, "path");
255 if (!path)
256 {
257 ERR_get_error();
258 path = name;
259 }
260 dso = DSO_load(NULL, path, NULL, 0);
261 if (!dso)
262 {
263 errcode = CONF_R_ERROR_LOADING_DSO;
264 goto err;
265 }
266 ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
267 if (!ifunc)
268 {
269 errcode = CONF_R_MISSING_INIT_FUNCTION;
270 goto err;
271 }
272 ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
273 /* All OK, add module */
274 md = module_add(dso, name, ifunc, ffunc);
275
276 if (!md)
277 goto err;
278
279 return md;
280
281 err:
282 if (dso)
283 DSO_free(dso);
284 CONFerr(CONF_F_MODULE_LOAD_DSO, errcode);
285 ERR_add_error_data(4, "module=", name, ", path=", path);
286 return NULL;
287 }
288
289/* add module to list */
290static CONF_MODULE *module_add(DSO *dso, const char *name,
291 conf_init_func *ifunc, conf_finish_func *ffunc)
292 {
293 CONF_MODULE *tmod = NULL;
294 if (supported_modules == NULL)
295 supported_modules = sk_CONF_MODULE_new_null();
296 if (supported_modules == NULL)
297 return NULL;
298 tmod = OPENSSL_malloc(sizeof(CONF_MODULE));
299 if (tmod == NULL)
300 return NULL;
301
302 tmod->dso = dso;
303 tmod->name = BUF_strdup(name);
304 tmod->init = ifunc;
305 tmod->finish = ffunc;
306 tmod->links = 0;
307
308 if (!sk_CONF_MODULE_push(supported_modules, tmod))
309 {
310 OPENSSL_free(tmod);
311 return NULL;
312 }
313
314 return tmod;
315 }
316
317/* Find a module from the list. We allow module names of the
318 * form modname.XXXX to just search for modname to allow the
319 * same module to be initialized more than once.
320 */
321
322static CONF_MODULE *module_find(char *name)
323 {
324 CONF_MODULE *tmod;
325 int i, nchar;
326 char *p;
327 p = strrchr(name, '.');
328
329 if (p)
330 nchar = p - name;
331 else
332 nchar = strlen(name);
333
334 for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++)
335 {
336 tmod = sk_CONF_MODULE_value(supported_modules, i);
337 if (!strncmp(tmod->name, name, nchar))
338 return tmod;
339 }
340
341 return NULL;
342
343 }
344
345/* initialize a module */
346static int module_init(CONF_MODULE *pmod, char *name, char *value,
347 const CONF *cnf)
348 {
349 int ret = 1;
350 int init_called = 0;
351 CONF_IMODULE *imod = NULL;
352
353 /* Otherwise add initialized module to list */
354 imod = OPENSSL_malloc(sizeof(CONF_IMODULE));
355 if (!imod)
356 goto err;
357
358 imod->pmod = pmod;
359 imod->name = BUF_strdup(name);
360 imod->value = BUF_strdup(value);
361 imod->usr_data = NULL;
362
363 if (!imod->name || !imod->value)
364 goto memerr;
365
366 /* Try to initialize module */
367 if(pmod->init)
368 {
369 ret = pmod->init(imod, cnf);
370 init_called = 1;
371 /* Error occurred, exit */
372 if (ret <= 0)
373 goto err;
374 }
375
376 if (initialized_modules == NULL)
377 {
378 initialized_modules = sk_CONF_IMODULE_new_null();
379 if (!initialized_modules)
380 {
381 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
382 goto err;
383 }
384 }
385
386 if (!sk_CONF_IMODULE_push(initialized_modules, imod))
387 {
388 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
389 goto err;
390 }
391
392 pmod->links++;
393
394 return ret;
395
396 err:
397
398 /* We've started the module so we'd better finish it */
399 if (pmod->finish && init_called)
400 pmod->finish(imod);
401
402 memerr:
403 if (imod)
404 {
405 if (imod->name)
406 OPENSSL_free(imod->name);
407 if (imod->value)
408 OPENSSL_free(imod->value);
409 OPENSSL_free(imod);
410 }
411
412 return -1;
413
414 }
415
416/* Unload any dynamic modules that have a link count of zero:
417 * i.e. have no active initialized modules. If 'all' is set
418 * then all modules are unloaded including static ones.
419 */
420
421void CONF_modules_unload(int all)
422 {
423 int i;
424 CONF_MODULE *md;
425 CONF_modules_finish();
426 /* unload modules in reverse order */
427 for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--)
428 {
429 md = sk_CONF_MODULE_value(supported_modules, i);
430 /* If static or in use and 'all' not set ignore it */
431 if (((md->links > 0) || !md->dso) && !all)
432 continue;
433 /* Since we're working in reverse this is OK */
434 sk_CONF_MODULE_delete(supported_modules, i);
435 module_free(md);
436 }
437 if (sk_CONF_MODULE_num(supported_modules) == 0)
438 {
439 sk_CONF_MODULE_free(supported_modules);
440 supported_modules = NULL;
441 }
442 }
443
444/* unload a single module */
445static void module_free(CONF_MODULE *md)
446 {
447 if (md->dso)
448 DSO_free(md->dso);
449 OPENSSL_free(md->name);
450 OPENSSL_free(md);
451 }
452
453/* finish and free up all modules instances */
454
455void CONF_modules_finish(void)
456 {
457 CONF_IMODULE *imod;
458 while (sk_CONF_IMODULE_num(initialized_modules) > 0)
459 {
460 imod = sk_CONF_IMODULE_pop(initialized_modules);
461 module_finish(imod);
462 }
463 sk_CONF_IMODULE_free(initialized_modules);
464 initialized_modules = NULL;
465 }
466
467/* finish a module instance */
468
469static void module_finish(CONF_IMODULE *imod)
470 {
471 if (imod->pmod->finish)
472 imod->pmod->finish(imod);
473 imod->pmod->links--;
474 OPENSSL_free(imod->name);
475 OPENSSL_free(imod->value);
476 OPENSSL_free(imod);
477 }
478
479/* Add a static module to OpenSSL */
480
481int CONF_module_add(const char *name, conf_init_func *ifunc,
482 conf_finish_func *ffunc)
483 {
484 if (module_add(NULL, name, ifunc, ffunc))
485 return 1;
486 else
487 return 0;
488 }
489
490void CONF_modules_free(void)
491 {
492 CONF_modules_finish();
493 CONF_modules_unload(1);
494 }
495
496/* Utility functions */
497
498const char *CONF_imodule_get_name(const CONF_IMODULE *md)
499 {
500 return md->name;
501 }
502
503const char *CONF_imodule_get_value(const CONF_IMODULE *md)
504 {
505 return md->value;
506 }
507
508void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
509 {
510 return md->usr_data;
511 }
512
513void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
514 {
515 md->usr_data = usr_data;
516 }
517
518CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
519 {
520 return md->pmod;
521 }
522
523unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
524 {
525 return md->flags;
526 }
527
528void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
529 {
530 md->flags = flags;
531 }
532
533void *CONF_module_get_usr_data(CONF_MODULE *pmod)
534 {
535 return pmod->usr_data;
536 }
537
538void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
539 {
540 pmod->usr_data = usr_data;
541 }
542
543/* Return default config file name */
544
545char *CONF_get1_default_config_file(void)
546 {
547 char *file;
548 int len;
549
550 file = getenv("OPENSSL_CONF");
551 if (file)
552 return BUF_strdup(file);
553
554 len = strlen(X509_get_default_cert_area());
555#ifndef OPENSSL_SYS_VMS
556 len++;
557#endif
558 len += strlen(OPENSSL_CONF);
559
560 file = OPENSSL_malloc(len + 1);
561
562 if (!file)
563 return NULL;
564 strcpy(file,X509_get_default_cert_area());
565#ifndef OPENSSL_SYS_VMS
566 strcat(file,"/");
567#endif
568 strcat(file,OPENSSL_CONF);
569
570 return file;
571 }
572
573/* This function takes a list separated by 'sep' and calls the
574 * callback function giving the start and length of each member
575 * optionally stripping leading and trailing whitespace. This can
576 * be used to parse comma separated lists for example.
577 */
578
579int CONF_parse_list(const char *list, int sep, int nospc,
580 int (*list_cb)(const char *elem, int len, void *usr), void *arg)
581 {
582 int ret;
583 const char *lstart, *tmpend, *p;
584 lstart = list;
585
586 for(;;)
587 {
588 if (nospc)
589 {
590 while(*lstart && isspace((unsigned char)*lstart))
591 lstart++;
592 }
593 p = strchr(lstart, sep);
594 if (p == lstart || !*lstart)
595 ret = list_cb(NULL, 0, arg);
596 else
597 {
598 if (p)
599 tmpend = p - 1;
600 else
601 tmpend = lstart + strlen(lstart) - 1;
602 if (nospc)
603 {
604 while(isspace((unsigned char)*tmpend))
605 tmpend--;
606 }
607 ret = list_cb(lstart, tmpend - lstart + 1, arg);
608 }
609 if (ret <= 0)
610 return ret;
611 if (p == NULL)
612 return 1;
613 lstart = p + 1;
614 }
615 }
616
diff --git a/src/lib/libssl/src/crypto/conf/conf_sap.c b/src/lib/libssl/src/crypto/conf/conf_sap.c
new file mode 100644
index 0000000000..97fb174303
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_sap.c
@@ -0,0 +1,107 @@
1/* conf_sap.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#include <openssl/engine.h>
67
68/* This is the automatic configuration loader: it is called automatically by
69 * OpenSSL when any of a number of standard initialisation functions are called,
70 * unless this is overridden by calling OPENSSL_no_config()
71 */
72
73static int openssl_configured = 0;
74
75void OPENSSL_config(const char *config_name)
76 {
77 if (openssl_configured)
78 return;
79
80 OPENSSL_load_builtin_modules();
81 /* Need to load ENGINEs */
82 ENGINE_load_builtin_engines();
83 /* Add others here? */
84
85
86 ERR_clear_error();
87 if (CONF_modules_load_file(NULL, NULL,
88 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
89 {
90 BIO *bio_err;
91 ERR_load_crypto_strings();
92 if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)
93 {
94 BIO_printf(bio_err,"Auto configuration failed\n");
95 ERR_print_errors(bio_err);
96 BIO_free(bio_err);
97 }
98 exit(1);
99 }
100
101 return;
102 }
103
104void OPENSSL_no_config()
105 {
106 openssl_configured = 1;
107 }
diff --git a/src/lib/libssl/src/crypto/crypto-lib.com b/src/lib/libssl/src/crypto/crypto-lib.com
new file mode 100644
index 0000000000..bf916528eb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/crypto-lib.com
@@ -0,0 +1,1218 @@
1$!
2$! CRYPTO-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB"
11$! library for OpenSSL. The "xxx" denotes the machine architecture of AXP
12$! or VAX.
13$!
14$! It was re-written so it would try to determine what "C" compiler to use
15$! or you can specify which "C" compiler to use.
16$!
17$! Specify RSAREF as P1 to compile with the RSAREF library instead of
18$! the regular one. If you specify NORSAREF it will compile with the
19$! regular RSAREF routines. (Note: If you are in the United States
20$! you MUST compile with RSAREF unless you have a license from RSA).
21$!
22$! Note: The RSAREF libraries are NOT INCLUDED and you have to
23$! download it from "ftp://ftp.rsa.com/rsaref". You have to
24$! get the ".tar-Z" file as the ".zip" file dosen't have the
25$! directory structure stored. You have to extract the file
26$! into the [.RSAREF] directory under the root directory as that
27$! is where the scripts will look for the files.
28$!
29$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger
30$! information.
31$!
32$! Specify which compiler at P3 to try to compile under.
33$!
34$! VAXC For VAX C.
35$! DECC For DEC C.
36$! GNUC For GNU C.
37$!
38$! If you don't speficy a compiler, it will try to determine which
39$! "C" compiler to use.
40$!
41$! P4, if defined, sets a TCP/IP library to use, through one of the following
42$! keywords:
43$!
44$! UCX for UCX
45$! SOCKETSHR for SOCKETSHR+NETLIB
46$!
47$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
48$!
49$! P6, if defined, sets a choice of crypto methods to compile.
50$! WARNING: this should only be done to recompile some part of an already
51$! fully compiled library.
52$!
53$!
54$! Define A TCP/IP Library That We Will Need To Link To.
55$! (That Is, If We Need To Link To One.)
56$!
57$ TCPIP_LIB = ""
58$!
59$! Check Which Architecture We Are Using.
60$!
61$ IF (F$GETSYI("CPU").GE.128)
62$ THEN
63$!
64$! The Architecture Is AXP
65$!
66$ ARCH := AXP
67$!
68$! Else...
69$!
70$ ELSE
71$!
72$! The Architecture Is VAX.
73$!
74$ ARCH := VAX
75$!
76$! End The Architecture Check.
77$!
78$ ENDIF
79$!
80$! Define The Different Encryption Types.
81$!
82$ ENCRYPT_TYPES = ",MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
83 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
84 "BN,RSA,DSA,DH,"+ -
85 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
86 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
87 "CONF,TXT_DB,PKCS7,PKCS12,COMP"
88$!
89$! Check To Make Sure We Have Valid Command Line Parameters.
90$!
91$ GOSUB CHECK_OPTIONS
92$!
93$! Initialise logical names and such
94$!
95$ GOSUB INITIALISE
96$!
97$! Tell The User What Kind of Machine We Run On.
98$!
99$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
100$!
101$! Define The OBJ Directory.
102$!
103$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
104$!
105$! Check To See If The Architecture Specific OBJ Directory Exists.
106$!
107$ IF (F$PARSE(OBJ_DIR).EQS."")
108$ THEN
109$!
110$! It Dosen't Exist, So Create It.
111$!
112$ CREATE/DIR 'OBJ_DIR'
113$!
114$! End The Architecture Specific OBJ Directory Check.
115$!
116$ ENDIF
117$!
118$! Define The EXE Directory.
119$!
120$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
121$!
122$! Check To See If The Architecture Specific Directory Exists.
123$!
124$ IF (F$PARSE(EXE_DIR).EQS."")
125$ THEN
126$!
127$! It Dosen't Exist, So Create It.
128$!
129$ CREATE/DIRECTORY 'EXE_DIR'
130$!
131$! End The Architecture Specific Directory Check.
132$!
133$ ENDIF
134$!
135$! Define The Library Name.
136$!
137$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
138$!
139$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
140$!
141$ IF (F$SEARCH(LIB_NAME).EQS."")
142$ THEN
143$!
144$! Guess Not, Create The Library.
145$!
146$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
147$!
148$! End The Library Check.
149$!
150$ ENDIF
151$!
152$! Define The Different Encryption "library" Strings.
153$!
154$ LIB_ = "cryptlib,mem,cversion,ex_data,tmdiff,cpt_err"
155$ LIB_MD2 = "md2_dgst,md2_one"
156$ LIB_MD5 = "md5_dgst,md5_one"
157$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one"
158$ LIB_MDC2 = "mdc2dgst,mdc2_one"
159$ LIB_HMAC = "hmac"
160$ LIB_RIPEMD = "rmd_dgst,rmd_one"
161$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
162 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
163 "enc_read,enc_writ,ofb64enc,"+ -
164 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
165 "des_enc,fcrypt_b,read2pwd,"+ -
166 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp,ede_cbcm_enc"
167$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64"
168$ LIB_RC4 = "rc4_skey,rc4_enc"
169$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64"
170$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
171$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
172$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
173$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
174$ IF F$TRNLNM("OPENSSL_NO_ASM") .NES. "" THEN LIB_BN_ASM = "bn_asm"
175$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_mul,"+ -
176 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
177 "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ -
178 "bn_mpi,bn_exp2"
179$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
180 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk"
181$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err"
182$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err"
183$ LIB_BUFFER = "buffer,buf_err"
184$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
185 "bss_mem,bss_null,bss_fd,"+ -
186 "bss_file,bss_sock,bss_conn,"+ -
187 "bf_null,bf_buff,b_print,b_dump,"+ -
188 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog
189$ LIB_STACK = "stack"
190$ LIB_LHASH = "lhash,lh_stats"
191$ LIB_RAND = "md_rand,randfile,rand_lib"
192$ LIB_ERR = "err,err_all,err_prn"
193$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
194$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ -
195 "e_ecb_d,e_cbc_d,e_cfb_d,e_ofb_d,"+ -
196 "e_ecb_i,e_cbc_i,e_cfb_i,e_ofb_i,"+ -
197 "e_ecb_3d,e_cbc_3d,e_rc4,names,"+ -
198 "e_cfb_3d,e_ofb_3d,e_xcbc_d,"+ -
199 "e_ecb_r2,e_cbc_r2,e_cfb_r2,e_ofb_r2,"+ -
200 "e_ecb_bf,e_cbc_bf,e_cfb_bf,e_ofb_bf"
201$ LIB_EVP_2 = "e_ecb_c,e_cbc_c,e_cfb_c,e_ofb_c,"+ -
202 "e_ecb_r5,e_cbc_r5,e_cfb_r5,e_ofb_r5,"+ -
203 "m_null,m_md2,m_md5,m_sha,m_sha1,m_dss,m_dss1,m_mdc2,"+ -
204 "m_ripemd,"+ -
205 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
206 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
207 "c_all,evp_lib,bio_ok,evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
208$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
209 "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ -
210 "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,"+ -
211 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ -
212 "x_name,x_cinf,x_x509,x_crl,x_info,x_spki,nsseq,"+ -
213 "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ -
214 "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ -
215 "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
216$ LIB_ASN1_2 = "t_req,t_x509,t_crl,t_pkey,"+ -
217 "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ -
218 "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ -
219 "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ -
220 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
221 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,"+ -
222 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey"
223$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err"
224$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
225 "x509_obj,x509_req,x509_vfy,"+ -
226 "x509_set,x509rset,x509_err,"+ -
227 "x509name,x509_v3,x509_ext,"+ -
228 "x509type,x509_lu,x_all,x509_txt,"+ -
229 "by_file,by_dir"
230$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
231 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ -
232 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld"
233$ LIB_CONF = "conf,conf_err"
234$ LIB_TXT_DB = "txt_db"
235$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit"
236$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ -
237 "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ -
238 "p12_sbag,p12_utl,pk12err"
239$ LIB_COMP = "comp_lib,"+ -
240 "c_rle,c_zlib"
241$!
242$! Setup exceptional compilations
243$!
244$ COMPILEWITH_CC3 = ",bss_rtcp,"
245$ COMPILEWITH_CC4 = ",a_utctm,"
246$ COMPILEWITH_CC5 = ",md2_dgst,md5_dgst,mdc2dgst,sha_dgst,sha1dgst," + -
247 "rmd_dgst,bf_enc,"
248$!
249$! Check To See If We Are Going To Use RSAREF.
250$!
251$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES)
252$ THEN
253$!
254$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There.
255$!
256$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAREF.C").EQS."")
257$ THEN
258$!
259$! Tell The User That The File Dosen't Exist.
260$!
261$ WRITE SYS$OUTPUT ""
262$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAREF.C Dosen't Exist."
263$ WRITE SYS$OUTPUT ""
264$!
265$! Exit The Build.
266$!
267$ GOTO EXIT
268$!
269$! End The [-.RSAREF]RSAREF.C Check.
270$!
271$ ENDIF
272$!
273$! Tell The User We Are Compiling The [-.RSAREF]RSAREF File.
274$!
275$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAREF File."
276$!
277$! Compile [-.RSAREF]RSAREF.C
278$!
279$ CC/OBJECT='OBJ_DIR'RSAREF.OBJ SYS$DISK:[-.RSAREF]RSAREF.C
280$!
281$! Add It To The Library.
282$!
283$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAREF.OBJ
284$!
285$! Delete The Object File.
286$!
287$ DELETE 'OBJ_DIR'RSAREF.OBJ;*
288$!
289$! Check To See If The File [-.RSAREF]RSAR_ERR.C Is Actually There.
290$!
291$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAR_ERR.C").EQS."")
292$ THEN
293$!
294$! Tell The User That The File Dosen't Exist.
295$!
296$ WRITE SYS$OUTPUT ""
297$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAR_ERR.C Dosen't Exist."
298$ WRITE SYS$OUTPUT ""
299$!
300$! Exit The Build.
301$!
302$ GOTO EXIT
303$!
304$! End The [-.RSAREF]RSAR_ERR.C File Check.
305$!
306$ ENDIF
307$!
308$! Tell The User We Are Compiling The [-.RSAREF]RSAR_ERR File.
309$!
310$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAR_ERR File."
311$!
312$! Compile [-.RSAREF]RSAR_ERR.C
313$!
314$ CC/OBJECT='OBJ_DIR'RSAR_ERR.OBJ SYS$DISK:[-.RSAREF]RSAR_ERR.C
315$!
316$! Add It To The Library.
317$!
318$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAR_ERR.OBJ
319$!
320$! Delete The Object File.
321$!
322$ DELETE 'OBJ_DIR'RSAR_ERR.OBJ;*
323$!
324$! End The RSAREF Check.
325$!
326$ ENDIF
327$!
328$! Figure Out What Other Modules We Are To Build.
329$!
330$ BUILD_SET:
331$!
332$! Define A Module Counter.
333$!
334$ MODULE_COUNTER = 0
335$!
336$! Top Of The Loop.
337$!
338$ MODULE_NEXT:
339$!
340$! Extract The Module Name From The Encryption List.
341$!
342$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
343$!
344$! Check To See If We Are At The End Of The Module List.
345$!
346$ IF (MODULE_NAME.EQS.",")
347$ THEN
348$!
349$! We Are At The End Of The Module List, Go To MODULE_DONE.
350$!
351$ GOTO MODULE_DONE
352$!
353$! End The Module List Check.
354$!
355$ ENDIF
356$!
357$! Increment The Moudle Counter.
358$!
359$ MODULE_COUNTER = MODULE_COUNTER + 1
360$!
361$! Tell The User What Module We Are Building.
362$!
363$ IF (MODULE_NAME.NES."")
364$ THEN
365$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME," Files."
366$ ENDIF
367$!
368$! Define A File Counter And Set It To "0".
369$!
370$ FILE_COUNTER = 0
371$!
372$! Create The Library Module Name.
373$!
374$ LIB_MODULE = "LIB_" + MODULE_NAME
375$ IF (MODULE_NAME.EQS."ASN1_2")
376$ THEN
377$ MODULE_NAME = "ASN1"
378$ ENDIF
379$ IF (MODULE_NAME.EQS."EVP_2")
380$ THEN
381$ MODULE_NAME = "EVP"
382$ ENDIF
383$!
384$! Check if the library module name actually is defined
385$!
386$ IF F$TYPE('LIB_MODULE') .EQS. ""
387$ THEN
388$ WRITE SYS$ERROR ""
389$ WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist. Continuing..."
390$ WRITE SYS$ERROR ""
391$ GOTO MODULE_NEXT
392$ ENDIF
393$!
394$! Top Of The File Loop.
395$!
396$ NEXT_FILE:
397$!
398$! O.K, Extract The File Name From The File List.
399$!
400$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
401$!
402$! Check To See If We Are At The End Of The File List.
403$!
404$ IF (FILE_NAME.EQS.",")
405$ THEN
406$!
407$! We Are At The End Of The File List, Goto FILE_DONE.
408$!
409$ GOTO FILE_DONE
410$!
411$! End The File List Check.
412$!
413$ ENDIF
414$!
415$! Increment The Counter.
416$!
417$ FILE_COUNTER = FILE_COUNTER + 1
418$!
419$! Create The Source File Name.
420$!
421$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME)
422$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME
423$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN -
424 FILE_NAME = FILE_NAME + ".c"
425$ IF (MODULE_NAME.NES."")
426$ THEN
427$ SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME
428$ ELSE
429$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME
430$ ENDIF
431$ SOURCE_FILE = SOURCE_FILE - "]["
432$!
433$! Create The Object File Name.
434$!
435$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
436$ ON WARNING THEN GOTO NEXT_FILE
437$!
438$! Check To See If The File We Want To Compile Is Actually There.
439$!
440$ IF (F$SEARCH(SOURCE_FILE).EQS."")
441$ THEN
442$!
443$! Tell The User That The File Dosen't Exist.
444$!
445$ WRITE SYS$OUTPUT ""
446$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
447$ WRITE SYS$OUTPUT ""
448$!
449$! Exit The Build.
450$!
451$ GOTO EXIT
452$!
453$! End The File Exist Check.
454$!
455$ ENDIF
456$!
457$! Tell The User We Are Compiling The File.
458$!
459$ IF (MODULE_NAME.EQS."")
460$ THEN
461 WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File."
462$ ENDIF
463$ IF (MODULE_NAME.NES."")
464$ THEN
465$ WRITE SYS$OUTPUT " ",FILE_NAME,""
466$ ENDIF
467$!
468$! Compile The File.
469$!
470$ ON ERROR THEN GOTO NEXT_FILE
471$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
472$ IF FILE_NAME - ".mar" .NES. FILE_NAME
473$ THEN
474$ MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
475$ ELSE
476$ IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
477$ THEN
478$ CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
479$ ELSE
480$ IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
481$ THEN
482$ CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
483$ ELSE
484$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
485$ THEN
486$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
487$ ELSE
488$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
489$ ENDIF
490$ ENDIF
491$ ENDIF
492$ ENDIF
493$!
494$! Add It To The Library.
495$!
496$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
497$!
498$! Time To Clean Up The Object File.
499$!
500$ DELETE 'OBJECT_FILE';*
501$!
502$! Go Back And Do It Again.
503$!
504$ GOTO NEXT_FILE
505$!
506$! All Done With This Library Part.
507$!
508$ FILE_DONE:
509$!
510$! Go Back And Get The Next Module.
511$!
512$ GOTO MODULE_NEXT
513$!
514$! All Done With This Module.
515$!
516$ MODULE_DONE:
517$!
518$! Tell The User That We Are All Done.
519$!
520$ WRITE SYS$OUTPUT "All Done..."
521$ EXIT:
522$ GOSUB CLEANUP
523$ EXIT
524$!
525$! Check For The Link Option FIle.
526$!
527$ CHECK_OPT_FILE:
528$!
529$! Check To See If We Need To Make A VAX C Option File.
530$!
531$ IF (COMPILER.EQS."VAXC")
532$ THEN
533$!
534$! Check To See If We Already Have A VAX C Linker Option File.
535$!
536$ IF (F$SEARCH(OPT_FILE).EQS."")
537$ THEN
538$!
539$! We Need A VAX C Linker Option File.
540$!
541$ CREATE 'OPT_FILE'
542$DECK
543!
544! Default System Options File To Link Agianst
545! The Sharable VAX C Runtime Library.
546!
547SYS$SHARE:VAXCRTL.EXE/SHARE
548$EOD
549$!
550$! End The Option File Check.
551$!
552$ ENDIF
553$!
554$! End The VAXC Check.
555$!
556$ ENDIF
557$!
558$! Check To See If We Need A GNU C Option File.
559$!
560$ IF (COMPILER.EQS."GNUC")
561$ THEN
562$!
563$! Check To See If We Already Have A GNU C Linker Option File.
564$!
565$ IF (F$SEARCH(OPT_FILE).EQS."")
566$ THEN
567$!
568$! We Need A GNU C Linker Option File.
569$!
570$ CREATE 'OPT_FILE'
571$DECK
572!
573! Default System Options File To Link Agianst
574! The Sharable C Runtime Library.
575!
576GNU_CC:[000000]GCCLIB/LIBRARY
577SYS$SHARE:VAXCRTL/SHARE
578$EOD
579$!
580$! End The Option File Check.
581$!
582$ ENDIF
583$!
584$! End The GNU C Check.
585$!
586$ ENDIF
587$!
588$! Check To See If We Need A DEC C Option File.
589$!
590$ IF (COMPILER.EQS."DECC")
591$ THEN
592$!
593$! Check To See If We Already Have A DEC C Linker Option File.
594$!
595$ IF (F$SEARCH(OPT_FILE).EQS."")
596$ THEN
597$!
598$! Figure Out If We Need An AXP Or A VAX Linker Option File.
599$!
600$ IF ARCH .EQS. "VAX"
601$ THEN
602$!
603$! We Need A DEC C Linker Option File For VAX.
604$!
605$ CREATE 'OPT_FILE'
606$DECK
607!
608! Default System Options File To Link Agianst
609! The Sharable DEC C Runtime Library.
610!
611SYS$SHARE:DECC$SHR.EXE/SHARE
612$EOD
613$!
614$! Else...
615$!
616$ ELSE
617$!
618$! Create The AXP Linker Option File.
619$!
620$ CREATE 'OPT_FILE'
621$DECK
622!
623! Default System Options File For AXP To Link Agianst
624! The Sharable C Runtime Library.
625!
626SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
627SYS$SHARE:CMA$OPEN_RTL/SHARE
628$EOD
629$!
630$! End The VAX/AXP DEC C Option File Check.
631$!
632$ ENDIF
633$!
634$! End The Option File Search.
635$!
636$ ENDIF
637$!
638$! End The DEC C Check.
639$!
640$ ENDIF
641$!
642$! Tell The User What Linker Option File We Are Using.
643$!
644$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
645$!
646$! Time To RETURN.
647$!
648$ RETURN
649$!
650$! Check The User's Options.
651$!
652$ CHECK_OPTIONS:
653$!
654$! Check To See If P1 Is Blank.
655$!
656$ IF (P1.EQS."NORSAREF")
657$ THEN
658$!
659$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries.
660$!
661$ RSAREF = "FALSE"
662$ ELSE
663$!
664$! Check To See If We Are To Use The RSAREF Library.
665$!
666$ IF (P1.EQS."RSAREF")
667$ THEN
668$!
669$! Check To Make Sure We Have The RSAREF Source Code Directory.
670$!
671$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
672$ THEN
673$!
674$! We Don't Have The RSAREF Souce Code Directory, So Tell The
675$! User This.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
679$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
680$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
681$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
682$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
683$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
684$ WRITE SYS$OUTPUT ""
685$!
686$! Time To Exit.
687$!
688$ EXIT
689$!
690$! Else, Compile Using The RSAREF Library.
691$!
692$ ELSE
693$ RSAREF = "TRUE"
694$ ENDIF
695$ ELSE
696$!
697$! They Entered An Invalid Option..
698$!
699$ WRITE SYS$OUTPUT ""
700$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
701$ WRITE SYS$OUTPUT ""
702$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
703$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
704$ WRITE SYS$OUTPUT ""
705$!
706$! Time To EXIT.
707$!
708$ EXIT
709$!
710$! End The Valid Arguement Check.
711$!
712$ ENDIF
713$!
714$! End The P1 Check.
715$!
716$ ENDIF
717$!
718$! Check To See If P2 Is Blank.
719$!
720$ IF (P2.EQS."NODEBUG")
721$ THEN
722$!
723$! P2 Is NODEBUG, So Compile Without The Debugger Information.
724$!
725$ DEBUGGER = "NODEBUG"
726$ TRACEBACK = "NOTRACEBACK"
727$ GCC_OPTIMIZE = "OPTIMIZE"
728$ CC_OPTIMIZE = "OPTIMIZE"
729$ MACRO_OPTIMIZE = "OPTIMIZE"
730$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
731$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
732$ ELSE
733$!
734$! Check To See If We Are To Compile With Debugger Information.
735$!
736$ IF (P2.EQS."DEBUG")
737$ THEN
738$!
739$! Compile With Debugger Information.
740$!
741$ DEBUGGER = "DEBUG"
742$ TRACEBACK = "TRACEBACK"
743$ GCC_OPTIMIZE = "NOOPTIMIZE"
744$ CC_OPTIMIZE = "NOOPTIMIZE"
745$ MACRO_OPTIMIZE = "NOOPTIMIZE"
746$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
747$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
748$ ELSE
749$!
750$! They Entered An Invalid Option..
751$!
752$ WRITE SYS$OUTPUT ""
753$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
754$ WRITE SYS$OUTPUT ""
755$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
756$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
757$ WRITE SYS$OUTPUT ""
758$!
759$! Time To EXIT.
760$!
761$ EXIT
762$!
763$! End The Valid Arguement Check.
764$!
765$ ENDIF
766$!
767$! End The P2 Check.
768$!
769$ ENDIF
770$!
771$! Special Threads For OpenVMS v7.1 Or Later
772$!
773$! Written By: Richard Levitte
774$! richard@levitte.org
775$!
776$!
777$! Check To See If We Have A Option For P5.
778$!
779$ IF (P5.EQS."")
780$ THEN
781$!
782$! Get The Version Of VMS We Are Using.
783$!
784$ ISSEVEN :=
785$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
786$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
787$!
788$! Check To See If The VMS Version Is v7.1 Or Later.
789$!
790$ IF (TMP.GE.71)
791$ THEN
792$!
793$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
794$!
795$ ISSEVEN := ,PTHREAD_USE_D4
796$!
797$! End The VMS Version Check.
798$!
799$ ENDIF
800$!
801$! End The P5 Check.
802$!
803$ ENDIF
804$!
805$! Check To See If P3 Is Blank.
806$!
807$ IF (P3.EQS."")
808$ THEN
809$!
810$! O.K., The User Didn't Specify A Compiler, Let's Try To
811$! Find Out Which One To Use.
812$!
813$! Check To See If We Have GNU C.
814$!
815$ IF (F$TRNLNM("GNU_CC").NES."")
816$ THEN
817$!
818$! Looks Like GNUC, Set To Use GNUC.
819$!
820$ P3 = "GNUC"
821$!
822$! Else...
823$!
824$ ELSE
825$!
826$! Check To See If We Have VAXC Or DECC.
827$!
828$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
829$ THEN
830$!
831$! Looks Like DECC, Set To Use DECC.
832$!
833$ P3 = "DECC"
834$!
835$! Else...
836$!
837$ ELSE
838$!
839$! Looks Like VAXC, Set To Use VAXC.
840$!
841$ P3 = "VAXC"
842$!
843$! End The VAXC Compiler Check.
844$!
845$ ENDIF
846$!
847$! End The DECC & VAXC Compiler Check.
848$!
849$ ENDIF
850$!
851$! End The Compiler Check.
852$!
853$ ENDIF
854$!
855$! Check To See If We Have A Option For P4.
856$!
857$ IF (P4.EQS."")
858$ THEN
859$!
860$! Find out what socket library we have available
861$!
862$ IF F$PARSE("SOCKETSHR:") .NES. ""
863$ THEN
864$!
865$! We have SOCKETSHR, and it is my opinion that it's the best to use.
866$!
867$ P4 = "SOCKETSHR"
868$!
869$! Tell the user
870$!
871$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
872$!
873$! Else, let's look for something else
874$!
875$ ELSE
876$!
877$! Like UCX (the reason to do this before Multinet is that the UCX
878$! emulation is easier to use...)
879$!
880$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
881 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
882 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
883$ THEN
884$!
885$! Last resort: a UCX or UCX-compatible library
886$!
887$ P4 = "UCX"
888$!
889$! Tell the user
890$!
891$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
892$!
893$! That was all...
894$!
895$ ENDIF
896$ ENDIF
897$ ENDIF
898$!
899$! Set Up Initial CC Definitions, Possibly With User Ones
900$!
901$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'"
902$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
903$ CCEXTRAFLAGS = ""
904$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
905$ CCDISABLEWARNINGS = ""
906$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
907 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
908$!
909$! Check To See If The User Entered A Valid Paramter.
910$!
911$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
912$ THEN
913$!
914$! Check To See If The User Wanted DECC.
915$!
916$ IF (P3.EQS."DECC")
917$ THEN
918$!
919$! Looks Like DECC, Set To Use DECC.
920$!
921$ COMPILER = "DECC"
922$!
923$! Tell The User We Are Using DECC.
924$!
925$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
926$!
927$! Use DECC...
928$!
929$ CC = "CC"
930$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
931 THEN CC = "CC/DECC"
932$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
933 "/NOLIST/PREFIX=ALL/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
934$!
935$! Define The Linker Options File Name.
936$!
937$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
938$!
939$! End DECC Check.
940$!
941$ ENDIF
942$!
943$! Check To See If We Are To Use VAXC.
944$!
945$ IF (P3.EQS."VAXC")
946$ THEN
947$!
948$! Looks Like VAXC, Set To Use VAXC.
949$!
950$ COMPILER = "VAXC"
951$!
952$! Tell The User We Are Using VAX C.
953$!
954$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
955$!
956$! Compile Using VAXC.
957$!
958$ CC = "CC"
959$ IF ARCH.EQS."AXP"
960$ THEN
961$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
962$ EXIT
963$ ENDIF
964$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
965$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST/INCLUDE=SYS$DISK:[]" + -
966 CCEXTRAFLAGS
967$ CCDEFS = """VAXC""," + CCDEFS
968$!
969$! Define <sys> As SYS$COMMON:[SYSLIB]
970$!
971$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
972$!
973$! Define The Linker Options File Name.
974$!
975$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
976$!
977$! End VAXC Check
978$!
979$ ENDIF
980$!
981$! Check To See If We Are To Use GNU C.
982$!
983$ IF (P3.EQS."GNUC")
984$ THEN
985$!
986$! Looks Like GNUC, Set To Use GNUC.
987$!
988$ COMPILER = "GNUC"
989$!
990$! Tell The User We Are Using GNUC.
991$!
992$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
993$!
994$! Use GNU C...
995$!
996$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
997 "/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
998$!
999$! Define The Linker Options File Name.
1000$!
1001$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
1002$!
1003$! End The GNU C Check.
1004$!
1005$ ENDIF
1006$!
1007$! Set up default defines
1008$!
1009$ CCDEFS = """FLAT_INC=1""," + CCDEFS
1010$!
1011$! Check To See If We Are To Compile With RSAREF Routines.
1012$!
1013$ IF (RSAREF.EQS."TRUE")
1014$ THEN
1015$!
1016$! Compile With RSAREF.
1017$!
1018$ CCDEFS = CCDEFS + ",""RSAref=1"""
1019$!
1020$! Tell The User This.
1021$!
1022$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
1023$!
1024$! Else, We Don't Care. Compile Without The RSAREF Library.
1025$!
1026$ ELSE
1027$!
1028$! Tell The User We Are Compile Without The RSAREF Routines.
1029$!
1030$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
1031$!
1032$! End The RSAREF Check.
1033$!
1034$ ENDIF
1035$!
1036$! Finish up the definition of CC.
1037$!
1038$ IF COMPILER .EQS. "DECC"
1039$ THEN
1040$ IF CCDISABLEWARNINGS .EQS. ""
1041$ THEN
1042$ CC4DISABLEWARNINGS = "DOLLARID"
1043$ ELSE
1044$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1045$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1046$ ENDIF
1047$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1048$ ELSE
1049$ CCDISABLEWARNINGS = ""
1050$ CC4DISABLEWARNINGS = ""
1051$ ENDIF
1052$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1053$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1054$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
1055$ THEN
1056$ CC5 = CC + "/OPTIMIZE=NODISJOINT"
1057$ ELSE
1058$ CC5 = CC + "/NOOPTIMIZE"
1059$ ENDIF
1060$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1061$!
1062$! Show user the result
1063$!
1064$ WRITE SYS$OUTPUT "Main C Compiling Command: ",CC
1065$!
1066$! Else The User Entered An Invalid Arguement.
1067$!
1068$ ELSE
1069$!
1070$! Tell The User We Don't Know What They Want.
1071$!
1072$ WRITE SYS$OUTPUT ""
1073$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
1074$ WRITE SYS$OUTPUT ""
1075$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1076$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
1077$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
1078$ WRITE SYS$OUTPUT ""
1079$!
1080$! Time To EXIT.
1081$!
1082$ EXIT
1083$!
1084$! End The Valid Arguement Check.
1085$!
1086$ ENDIF
1087$!
1088$! Build a MACRO command for the architecture at hand
1089$!
1090$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
1091$ IF ARCH .EQS. "AXP" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
1092$!
1093$! Show user the result
1094$!
1095$ WRITE SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
1096$!
1097$! Time to check the contents, and to make sure we get the correct library.
1098$!
1099$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX"
1100$ THEN
1101$!
1102$! Check to see if SOCKETSHR was chosen
1103$!
1104$ IF P4.EQS."SOCKETSHR"
1105$ THEN
1106$!
1107$! Set the library to use SOCKETSHR
1108$!
1109$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
1110$!
1111$! Done with SOCKETSHR
1112$!
1113$ ENDIF
1114$!
1115$! Check to see if MULTINET was chosen
1116$!
1117$ IF P4.EQS."MULTINET"
1118$ THEN
1119$!
1120$! Set the library to use UCX emulation.
1121$!
1122$ P4 = "UCX"
1123$!
1124$! Done with MULTINET
1125$!
1126$ ENDIF
1127$!
1128$! Check to see if UCX was chosen
1129$!
1130$ IF P4.EQS."UCX"
1131$ THEN
1132$!
1133$! Set the library to use UCX.
1134$!
1135$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
1136$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1137$ THEN
1138$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1139$ ELSE
1140$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1141 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1142$ ENDIF
1143$!
1144$! Done with UCX
1145$!
1146$ ENDIF
1147$!
1148$! Print info
1149$!
1150$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1151$!
1152$! Else The User Entered An Invalid Arguement.
1153$!
1154$ ELSE
1155$!
1156$! Tell The User We Don't Know What They Want.
1157$!
1158$ WRITE SYS$OUTPUT ""
1159$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1160$ WRITE SYS$OUTPUT ""
1161$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1162$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1163$ WRITE SYS$OUTPUT ""
1164$!
1165$! Time To EXIT.
1166$!
1167$ EXIT
1168$!
1169$! Done with TCP/IP libraries
1170$!
1171$ ENDIF
1172$!
1173$! Check if the user wanted to compile just a subset of all the encryption
1174$! methods.
1175$!
1176$ IF P6 .NES. ""
1177$ THEN
1178$ ENCRYPT_TYPES = P6
1179$ ENDIF
1180$!
1181$! Time To RETURN...
1182$!
1183$ RETURN
1184$!
1185$ INITIALISE:
1186$!
1187$! Save old value of the logical name OPENSSL
1188$!
1189$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1190$!
1191$! Save directory information
1192$!
1193$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1194$ __TOP = __HERE - "CRYPTO]"
1195$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1196$!
1197$! Set up the logical name OPENSSL to point at the include directory
1198$!
1199$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1200$!
1201$! Done
1202$!
1203$ RETURN
1204$!
1205$ CLEANUP:
1206$!
1207$! Restore the logical name OPENSSL if it had a value
1208$!
1209$ IF __SAVE_OPENSSL .EQS. ""
1210$ THEN
1211$ DEASSIGN OPENSSL
1212$ ELSE
1213$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1214$ ENDIF
1215$!
1216$! Done
1217$!
1218$ RETURN
diff --git a/src/lib/libssl/src/crypto/des/des-lib.com b/src/lib/libssl/src/crypto/des/des-lib.com
new file mode 100644
index 0000000000..2aea7a0dea
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des-lib.com
@@ -0,0 +1,1003 @@
1$!
2$! DES-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the
11$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine
12$! architecture of AXP or VAX.
13$!
14$! It was re-written to try to determine which "C" compiler to try to use
15$! or the user can specify a compiler in P3.
16$!
17$! Specify one of the following to build just that part, specify "ALL" to
18$! just build everything.
19$!
20$! ALL To Just Build "Everything".
21$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library.
22$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program.
23$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program.
24$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program.
25$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program.
26$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program.
27$!
28$! Specify either DEBUG or NODEBUG as P2 to compile with or without
29$! debugging information.
30$!
31$! Specify which compiler at P3 to try to compile under.
32$!
33$! VAXC For VAX C.
34$! DECC For DEC C.
35$! GNUC For GNU C.
36$!
37$! If you don't speficy a compiler, it will try to determine which
38$! "C" compiler to try to use.
39$!
40$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
41$!
42$!
43$! Make sure we know what architecture we run on.
44$!
45$!
46$! Check Which Architecture We Are Using.
47$!
48$ IF (F$GETSYI("CPU").GE.128)
49$ THEN
50$!
51$! The Architecture Is AXP.
52$!
53$ ARCH := AXP
54$!
55$! Else...
56$!
57$ ELSE
58$!
59$! The Architecture Is VAX.
60$!
61$ ARCH := VAX
62$!
63$! End The Architecture Check.
64$!
65$ ENDIF
66$!
67$! Check To Make Sure We Have Valid Command Line Parameters.
68$!
69$ GOSUB CHECK_OPTIONS
70$!
71$! Tell The User What Kind of Machine We Run On.
72$!
73$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
74$!
75$! Define The OBJ Directory Name.
76$!
77$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES]
78$!
79$! Check To See If The Architecture Specific OBJ Directory Exists.
80$!
81$ IF (F$PARSE(OBJ_DIR).EQS."")
82$ THEN
83$!
84$! It Dosen't Exist, So Create It.
85$!
86$ CREATE/DIR 'OBJ_DIR'
87$!
88$! End The Architecture Specific OBJ Directory Check.
89$!
90$ ENDIF
91$!
92$! Define The EXE Directory Name.
93$!
94$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES]
95$!
96$! Check To See If The Architecture Specific Directory Exists.
97$!
98$ IF (F$PARSE(EXE_DIR).EQS."")
99$ THEN
100$!
101$! It Dosen't Exist, So Create It.
102$!
103$ CREATE/DIR 'EXE_DIR'
104$!
105$! End The Architecture Specific Directory Check.
106$!
107$ ENDIF
108$!
109$! Define The Library Name.
110$!
111$ LIB_NAME := 'EXE_DIR'LIBDES.OLB
112$!
113$! Check To See What We Are To Do.
114$!
115$ IF (BUILDALL.EQS."TRUE")
116$ THEN
117$!
118$! Since Nothing Special Was Specified, Do Everything.
119$!
120$ GOSUB LIBRARY
121$ GOSUB DESTEST
122$ GOSUB SPEED
123$ GOSUB RPW
124$ GOSUB DES
125$ GOSUB DES_OPTS
126$!
127$! Else...
128$!
129$ ELSE
130$!
131$! Build Just What The User Wants Us To Build.
132$!
133$ GOSUB 'BUILDALL'
134$!
135$! End The BUILDALL Check.
136$!
137$ ENDIF
138$!
139$! Time To EXIT.
140$!
141$ EXIT
142$ LIBRARY:
143$!
144$! Tell The User That We Are Compiling.
145$!
146$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files."
147$!
148$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library...
149$!
150$ IF (F$SEARCH(LIB_NAME).EQS."")
151$ THEN
152$!
153$! Guess Not, Create The Library.
154$!
155$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
156$!
157$! End The Library Exist Check.
158$!
159$ ENDIF
160$!
161$! Define The DES Library Files.
162$!
163$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
164 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
165 "enc_read,enc_writ,ofb64enc,"+ -
166 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
167 "des_enc,fcrypt_b,read2pwd,"+ -
168 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp"
169$!
170$! Define A File Counter And Set It To "0".
171$!
172$ FILE_COUNTER = 0
173$!
174$! Top Of The File Loop.
175$!
176$ NEXT_FILE:
177$!
178$! O.K, Extract The File Name From The File List.
179$!
180$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES)
181$!
182$! Check To See If We Are At The End Of The File List.
183$!
184$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
185$!
186$! Increment The Counter.
187$!
188$ FILE_COUNTER = FILE_COUNTER + 1
189$!
190$! Create The Source File Name.
191$!
192$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
193$!
194$! Tell The User We Are Compiling The Source File.
195$!
196$ WRITE SYS$OUTPUT " ",FILE_NAME,".C"
197$!
198$! Create The Object File Name.
199$!
200$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ"
201$ ON WARNING THEN GOTO NEXT_FILE
202$!
203$! Check To See If The File We Want To Compile Actually Exists.
204$!
205$ IF (F$SEARCH(SOURCE_FILE).EQS."")
206$ THEN
207$!
208$! Tell The User That The File Dosen't Exist.
209$!
210$ WRITE SYS$OUTPUT ""
211$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
212$ WRITE SYS$OUTPUT ""
213$!
214$! Exit The Build.
215$!
216$ EXIT
217$!
218$! End The File Exists Check.
219$!
220$ ENDIF
221$!
222$! Compile The File.
223$!
224$ ON ERROR THEN GOTO NEXT_FILE
225$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
226$!
227$! Add It To The Library.
228$!
229$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE'
230$!
231$! Time To Clean Up The Object File.
232$!
233$ DELETE 'OBJECT_FILE';*
234$!
235$! Go Back And Do It Again.
236$!
237$ GOTO NEXT_FILE
238$!
239$! All Done With This Library Part.
240$!
241$ FILE_DONE:
242$!
243$! Tell The User That We Are All Done.
244$!
245$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built."
246$!
247$! All Done, Time To Return.
248$!
249$ RETURN
250$!
251$! Compile The DESTEST Program.
252$!
253$ DESTEST:
254$!
255$! Check To See If We Have The Proper Libraries.
256$!
257$ GOSUB LIB_CHECK
258$!
259$! Check To See If We Have A Linker Option File.
260$!
261$ GOSUB CHECK_OPT_FILE
262$!
263$! Check To See If The File We Want To Compile Actually Exists.
264$!
265$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."")
266$ THEN
267$!
268$! Tell The User That The File Dosen't Exist.
269$!
270$ WRITE SYS$OUTPUT ""
271$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist."
272$ WRITE SYS$OUTPUT ""
273$!
274$! Exit The Build.
275$!
276$ EXIT
277$!
278$! End The DESTEST.C File Check.
279$!
280$ ENDIF
281$!
282$! Tell The User What We Are Building.
283$!
284$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE"
285$!
286$! Compile The DESTEST Program.
287$!
288$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C
289$!
290$! Link The DESTEST Program.
291$!
292$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE -
293 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
294$!
295$! All Done, Time To Return.
296$!
297$ RETURN
298$!
299$! Compile The SPEED Program.
300$!
301$ SPEED:
302$!
303$! Check To See If We Have The Proper Libraries.
304$!
305$ GOSUB LIB_CHECK
306$!
307$! Check To See If We Have A Linker Option File.
308$!
309$ GOSUB CHECK_OPT_FILE
310$!
311$! Check To See If The File We Want To Compile Actually Exists.
312$!
313$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."")
314$ THEN
315$!
316$! Tell The User That The File Dosen't Exist.
317$!
318$ WRITE SYS$OUTPUT ""
319$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist."
320$ WRITE SYS$OUTPUT ""
321$!
322$! Exit The Build.
323$!
324$ EXIT
325$!
326$! End The SPEED.C File Check.
327$!
328$ ENDIF
329$!
330$! Tell The User What We Are Building.
331$!
332$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE"
333$!
334$! Compile The SPEED Program.
335$!
336$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C
337$!
338$! Link The SPEED Program.
339$!
340$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE -
341 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
342$!
343$! All Done, Time To Return.
344$!
345$ RETURN
346$!
347$! Compile The RPW Program.
348$!
349$ RPW:
350$!
351$! Check To See If We Have The Proper Libraries.
352$!
353$ GOSUB LIB_CHECK
354$!
355$! Check To See If We Have A Linker Option File.
356$!
357$ GOSUB CHECK_OPT_FILE
358$!
359$! Check To See If The File We Want To Compile Actually Exists.
360$!
361$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."")
362$ THEN
363$!
364$! Tell The User That The File Dosen't Exist.
365$!
366$ WRITE SYS$OUTPUT ""
367$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist."
368$ WRITE SYS$OUTPUT ""
369$!
370$! Exit The Build.
371$!
372$ EXIT
373$!
374$! End The RPW.C File Check.
375$!
376$ ENDIF
377$!
378$! Tell The User What We Are Building.
379$!
380$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE"
381$!
382$! Compile The RPW Program.
383$!
384$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C
385$!
386$! Link The RPW Program.
387$!
388$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE -
389 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
390$!
391$! All Done, Time To Return.
392$!
393$ RETURN
394$!
395$! Compile The DES Program.
396$!
397$ DES:
398$!
399$! Check To See If We Have The Proper Libraries.
400$!
401$ GOSUB LIB_CHECK
402$!
403$! Check To See If We Have A Linker Option File.
404$!
405$ GOSUB CHECK_OPT_FILE
406$!
407$! Check To See If The File We Want To Compile Actually Exists.
408$!
409$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."")
410$ THEN
411$!
412$! Tell The User That The File Dosen't Exist.
413$!
414$ WRITE SYS$OUTPUT ""
415$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist."
416$ WRITE SYS$OUTPUT ""
417$!
418$! Exit The Build.
419$!
420$ EXIT
421$!
422$! End The DES.C File Check.
423$!
424$ ENDIF
425$!
426$! Tell The User What We Are Building.
427$!
428$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE"
429$!
430$! Compile The DES Program.
431$!
432$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C
433$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C
434$!
435$! Link The DES Program.
436$!
437$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE -
438 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,-
439 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
440$!
441$! All Done, Time To Return.
442$!
443$ RETURN
444$!
445$! Compile The DES_OPTS Program.
446$!
447$ DES_OPTS:
448$!
449$! Check To See If We Have The Proper Libraries.
450$!
451$ GOSUB LIB_CHECK
452$!
453$! Check To See If We Have A Linker Option File.
454$!
455$ GOSUB CHECK_OPT_FILE
456$!
457$! Check To See If The File We Want To Compile Actually Exists.
458$!
459$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."")
460$ THEN
461$!
462$! Tell The User That The File Dosen't Exist.
463$!
464$ WRITE SYS$OUTPUT ""
465$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist."
466$ WRITE SYS$OUTPUT ""
467$!
468$! Exit The Build.
469$!
470$ EXIT
471$!
472$! End The DES_OPTS.C File Check.
473$!
474$ ENDIF
475$!
476$! Tell The User What We Are Building.
477$!
478$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE"
479$!
480$! Compile The DES_OPTS Program.
481$!
482$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C
483$!
484$! Link The DES_OPTS Program.
485$!
486$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE -
487 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
488$!
489$! All Done, Time To Return.
490$!
491$ RETURN
492$ EXIT
493$!
494$! Check For The Link Option FIle.
495$!
496$ CHECK_OPT_FILE:
497$!
498$! Check To See If We Need To Make A VAX C Option File.
499$!
500$ IF (COMPILER.EQS."VAXC")
501$ THEN
502$!
503$! Check To See If We Already Have A VAX C Linker Option File.
504$!
505$ IF (F$SEARCH(OPT_FILE).EQS."")
506$ THEN
507$!
508$! We Need A VAX C Linker Option File.
509$!
510$ CREATE 'OPT_FILE'
511$DECK
512!
513! Default System Options File To Link Agianst
514! The Sharable VAX C Runtime Library.
515!
516SYS$SHARE:VAXCRTL.EXE/SHARE
517$EOD
518$!
519$! End The Option File Check.
520$!
521$ ENDIF
522$!
523$! End The VAXC Check.
524$!
525$ ENDIF
526$!
527$! Check To See If We Need A GNU C Option File.
528$!
529$ IF (COMPILER.EQS."GNUC")
530$ THEN
531$!
532$! Check To See If We Already Have A GNU C Linker Option File.
533$!
534$ IF (F$SEARCH(OPT_FILE).EQS."")
535$ THEN
536$!
537$! We Need A GNU C Linker Option File.
538$!
539$ CREATE 'OPT_FILE'
540$DECK
541!
542! Default System Options File To Link Agianst
543! The Sharable C Runtime Library.
544!
545GNU_CC:[000000]GCCLIB/LIBRARY
546SYS$SHARE:VAXCRTL/SHARE
547$EOD
548$!
549$! End The Option File Check.
550$!
551$ ENDIF
552$!
553$! End The GNU C Check.
554$!
555$ ENDIF
556$!
557$! Check To See If We Need A DEC C Option File.
558$!
559$ IF (COMPILER.EQS."DECC")
560$ THEN
561$!
562$! Check To See If We Already Have A DEC C Linker Option File.
563$!
564$ IF (F$SEARCH(OPT_FILE).EQS."")
565$ THEN
566$!
567$! Figure Out If We Need An AXP Or A VAX Linker Option File.
568$!
569$ IF (F$GETSYI("CPU").LT.128)
570$ THEN
571$!
572$! We Need A DEC C Linker Option File For VAX.
573$!
574$ CREATE 'OPT_FILE'
575$DECK
576!
577! Default System Options File To Link Agianst
578! The Sharable DEC C Runtime Library.
579!
580SYS$SHARE:DECC$SHR.EXE/SHARE
581$EOD
582$!
583$! Else...
584$!
585$ ELSE
586$!
587$! Create The AXP Linker Option File.
588$!
589$ CREATE 'OPT_FILE'
590$DECK
591!
592! Default System Options File For AXP To Link Agianst
593! The Sharable C Runtime Library.
594!
595SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
596SYS$SHARE:CMA$OPEN_RTL/SHARE
597$EOD
598$!
599$! End The VAX/AXP DEC C Option File Check.
600$!
601$ ENDIF
602$!
603$! End The Option File Search.
604$!
605$ ENDIF
606$!
607$! End The DEC C Check.
608$!
609$ ENDIF
610$!
611$! Tell The User What Linker Option File We Are Using.
612$!
613$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
614$!
615$! Time To RETURN.
616$!
617$ RETURN
618$!
619$! Library Check.
620$!
621$ LIB_CHECK:
622$!
623$! Look For The Library LIBDES.OLB.
624$!
625$ IF (F$SEARCH(LIB_NAME).EQS."")
626$ THEN
627$!
628$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library.
629$!
630$ WRITE SYS$OUTPUT ""
631$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"."
632$ WRITE SYS$OUTPUT "We Can't Link Without It."
633$ WRITE SYS$OUTPUT ""
634$!
635$! Since We Can't Link Without It, Exit.
636$!
637$ EXIT
638$ ENDIF
639$!
640$! Time To Return.
641$!
642$ RETURN
643$!
644$! Check The User's Options.
645$!
646$ CHECK_OPTIONS:
647$!
648$! Check To See If We Are To "Just Build Everything".
649$!
650$ IF (P1.EQS."ALL")
651$ THEN
652$!
653$! P1 Is "ALL", So Build Everything.
654$!
655$ BUILDALL = "TRUE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Else, Check To See If P1 Has A Valid Arguement.
662$!
663$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
664 .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
665$ THEN
666$!
667$! A Valid Arguement.
668$!
669$ BUILDALL = P1
670$!
671$! Else...
672$!
673$ ELSE
674$!
675$! Tell The User We Don't Know What They Want.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
679$ WRITE SYS$OUTPUT ""
680$ WRITE SYS$OUTPUT " ALL : Just Build Everything.
681$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
682$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
683$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
684$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program."
685$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program."
686$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program."
687$ WRITE SYS$OUTPUT ""
688$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: "
689$ WRITE SYS$OUTPUT ""
690$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
691$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
692$ WRITE SYS$OUTPUT ""
693$!
694$! Time To EXIT.
695$!
696$ EXIT
697$!
698$! End The Valid Arguement Check.
699$!
700$ ENDIF
701$!
702$! End The P1 Check.
703$!
704$ ENDIF
705$!
706$! Check To See If We Are To Compile Without Debugger Information.
707$!
708$ IF (P2.EQS."NODEBUG")
709$ THEN
710$!
711$! P2 Is Blank, So Compile Without Debugger Information.
712$!
713$ DEBUGGER = "NODEBUG"
714$ TRACEBACK = "NOTRACEBACK"
715$ GCC_OPTIMIZE = "OPTIMIZE"
716$ CC_OPTIMIZE = "OPTIMIZE"
717$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
718$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
719$!
720$! Else...
721$!
722$ ELSE
723$!
724$! Check To See If We Are To Compile With Debugger Information.
725$!
726$ IF (P2.EQS."DEBUG")
727$ THEN
728$!
729$! Compile With Debugger Information.
730$!
731$ DEBUGGER = "DEBUG"
732$ TRACEBACK = "TRACEBACK"
733$ GCC_OPTIMIZE = "NOOPTIMIZE"
734$ CC_OPTIMIZE = "NOOPTIMIZE"
735$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
736$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
737$!
738$! Else...
739$!
740$ ELSE
741$!
742$! Tell The User Entered An Invalid Option..
743$!
744$ WRITE SYS$OUTPUT ""
745$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
746$ WRITE SYS$OUTPUT ""
747$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
748$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
749$ WRITE SYS$OUTPUT ""
750$!
751$! Time To EXIT.
752$!
753$ EXIT
754$!
755$! End The Valid Arguement Check.
756$!
757$ ENDIF
758$!
759$! End The P2 Check.
760$!
761$ ENDIF
762$!
763$! Special Threads For OpenVMS v7.1 Or Later.
764$!
765$! Written By: Richard Levitte
766$! richard@levitte.org
767$!
768$!
769$! Check To See If We Have A Option For P4.
770$!
771$ IF (P4.EQS."")
772$ THEN
773$!
774$! Get The Version Of VMS We Are Using.
775$!
776$ ISSEVEN := ""
777$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
778$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
779$!
780$! Check To See If The VMS Version Is v7.1 Or Later.
781$!
782$ IF (TMP.GE.71)
783$ THEN
784$!
785$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
786$!
787$ ISSEVEN := ,PTHREAD_USE_D4
788$!
789$! End The VMS Version Check.
790$!
791$ ENDIF
792$!
793$! End The P4 Check.
794$!
795$ ENDIF
796$!
797$! Check To See If P3 Is Blank.
798$!
799$ IF (P3.EQS."")
800$ THEN
801$!
802$! O.K., The User Didn't Specify A Compiler, Let's Try To
803$! Find Out Which One To Use.
804$!
805$! Check To See If We Have GNU C.
806$!
807$ IF (F$TRNLNM("GNU_CC").NES."")
808$ THEN
809$!
810$! Looks Like GNUC, Set To Use GNUC.
811$!
812$ P3 = "GNUC"
813$!
814$! Else...
815$!
816$ ELSE
817$!
818$! Check To See If We Have VAXC Or DECC.
819$!
820$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
821$ THEN
822$!
823$! Looks Like DECC, Set To Use DECC.
824$!
825$ P3 = "DECC"
826$!
827$! Else...
828$!
829$ ELSE
830$!
831$! Looks Like VAXC, Set To Use VAXC.
832$!
833$ P3 = "VAXC"
834$!
835$! End The VAXC Compiler Check.
836$!
837$ ENDIF
838$!
839$! End The DECC & VAXC Compiler Check.
840$!
841$ ENDIF
842$!
843$! End The Compiler Check.
844$!
845$ ENDIF
846$!
847$! Set Up Initial CC Definitions, Possibly With User Ones
848$!
849$ CCDEFS = "VMS=1"
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
851$ CCEXTRAFLAGS = ""
852$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
853$ CCDISABLEWARNINGS = ""
854$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
855 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
856$!
857$! Check To See If The User Entered A Valid Paramter.
858$!
859$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
860$ THEN
861$!
862$! Check To See If The User Wanted DECC.
863$!
864$ IF (P3.EQS."DECC")
865$ THEN
866$!
867$! Looks Like DECC, Set To Use DECC.
868$!
869$ COMPILER = "DECC"
870$!
871$! Tell The User We Are Using DECC.
872$!
873$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
874$!
875$! Use DECC...
876$!
877$ CC = "CC"
878$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
879 THEN CC = "CC/DECC"
880$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
881 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
882$!
883$! Define The Linker Options File Name.
884$!
885$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
886$!
887$! End DECC Check.
888$!
889$ ENDIF
890$!
891$! Check To See If We Are To Use VAXC.
892$!
893$ IF (P3.EQS."VAXC")
894$ THEN
895$!
896$! Looks Like VAXC, Set To Use VAXC.
897$!
898$ COMPILER = "VAXC"
899$!
900$! Tell The User We Are Using VAX C.
901$!
902$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
903$!
904$! Compile Using VAXC.
905$!
906$ CC = "CC"
907$ IF ARCH.EQS."AXP"
908$ THEN
909$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
910$ EXIT
911$ ENDIF
912$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
913$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
914$ CCDEFS = """VAXC""," + CCDEFS
915$!
916$! Define <sys> As SYS$COMMON:[SYSLIB]
917$!
918$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
919$!
920$! Define The Linker Options File Name.
921$!
922$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
923$!
924$! End VAXC Check
925$!
926$ ENDIF
927$!
928$! Check To See If We Are To Use GNU C.
929$!
930$ IF (P3.EQS."GNUC")
931$ THEN
932$!
933$! Looks Like GNUC, Set To Use GNUC.
934$!
935$ COMPILER = "GNUC"
936$!
937$! Tell The User We Are Using GNUC.
938$!
939$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
940$!
941$! Use GNU C...
942$!
943$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
944$!
945$! Define The Linker Options File Name.
946$!
947$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
948$!
949$! End The GNU C Check.
950$!
951$ ENDIF
952$!
953$! Set up default defines
954$!
955$ CCDEFS = """FLAT_INC=1""," + CCDEFS
956$!
957$! Finish up the definition of CC.
958$!
959$ IF COMPILER .EQS. "DECC"
960$ THEN
961$ IF CCDISABLEWARNINGS .EQS. ""
962$ THEN
963$ CC4DISABLEWARNINGS = "DOLLARID"
964$ ELSE
965$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
966$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
967$ ENDIF
968$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
969$ ELSE
970$ CCDISABLEWARNINGS = ""
971$ CC4DISABLEWARNINGS = ""
972$ ENDIF
973$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
974$!
975$! Show user the result
976$!
977$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
978$!
979$! Else The User Entered An Invalid Arguement.
980$!
981$ ELSE
982$!
983$! Tell The User We Don't Know What They Want.
984$!
985$ WRITE SYS$OUTPUT ""
986$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
987$ WRITE SYS$OUTPUT ""
988$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
989$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
990$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
991$ WRITE SYS$OUTPUT ""
992$!
993$! Time To EXIT.
994$!
995$ EXIT
996$!
997$! End The P3 Check.
998$!
999$ ENDIF
1000$!
1001$! Time To RETURN...
1002$!
1003$ RETURN
diff --git a/src/lib/libssl/src/crypto/des/des.h b/src/lib/libssl/src/crypto/des/des.h
new file mode 100644
index 0000000000..67f90aaf17
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des.h
@@ -0,0 +1,249 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_DES
67#error DES is disabled.
68#endif
69
70#ifdef _KERBEROS_DES_H
71#error <openssl/des.h> replaces <kerberos/des.h>.
72#endif
73
74#include <stdio.h>
75#include <openssl/opensslconf.h> /* DES_LONG */
76#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
77
78typedef unsigned char des_cblock[8];
79typedef /* const */ unsigned char const_des_cblock[8];
80/* With "const", gcc 2.8.1 on Solaris thinks that des_cblock *
81 * and const_des_cblock * are incompatible pointer types.
82 * I haven't seen that warning on other systems ... I'll look
83 * what the standard says. */
84
85
86typedef struct des_ks_struct
87 {
88 union {
89 des_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks;
94 int weak_key;
95 } des_key_schedule[16];
96
97#define DES_KEY_SZ (sizeof(des_cblock))
98#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
99
100#define DES_ENCRYPT 1
101#define DES_DECRYPT 0
102
103#define DES_CBC_MODE 0
104#define DES_PCBC_MODE 1
105
106#define des_ecb2_encrypt(i,o,k1,k2,e) \
107 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
108
109#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
110 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
111
112#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
113 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
114
115#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
116 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
117
118OPENSSL_EXTERN int des_check_key; /* defaults to false */
119OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */
120OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */
121
122const char *des_options(void);
123void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
124 des_key_schedule ks1,des_key_schedule ks2,
125 des_key_schedule ks3, int enc);
126DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output,
127 long length,des_key_schedule schedule,
128 const_des_cblock *ivec);
129/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */
130void des_cbc_encrypt(const unsigned char *input,unsigned char *output,
131 long length,des_key_schedule schedule,des_cblock *ivec,
132 int enc);
133void des_ncbc_encrypt(const unsigned char *input,unsigned char *output,
134 long length,des_key_schedule schedule,des_cblock *ivec,
135 int enc);
136void des_xcbc_encrypt(const unsigned char *input,unsigned char *output,
137 long length,des_key_schedule schedule,des_cblock *ivec,
138 const_des_cblock *inw,const_des_cblock *outw,int enc);
139void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
140 long length,des_key_schedule schedule,des_cblock *ivec,
141 int enc);
142void des_ecb_encrypt(const_des_cblock *input,des_cblock *output,
143 des_key_schedule ks,int enc);
144void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
145void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
146void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
147 des_key_schedule ks2, des_key_schedule ks3);
148void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
149 des_key_schedule ks2, des_key_schedule ks3);
150void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
151 long length,
152 des_key_schedule ks1,des_key_schedule ks2,
153 des_key_schedule ks3,des_cblock *ivec,int enc);
154void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
155 long length,
156 des_key_schedule ks1,des_key_schedule ks2,
157 des_key_schedule ks3,
158 des_cblock *ivec1,des_cblock *ivec2,
159 int enc);
160void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
161 long length,des_key_schedule ks1,
162 des_key_schedule ks2,des_key_schedule ks3,
163 des_cblock *ivec,int *num,int enc);
164void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
165 long length,des_key_schedule ks1,
166 des_key_schedule ks2,des_key_schedule ks3,
167 des_cblock *ivec,int *num);
168
169void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white,
170 des_cblock *out_white);
171
172int des_enc_read(int fd,void *buf,int len,des_key_schedule sched,
173 des_cblock *iv);
174int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched,
175 des_cblock *iv);
176char *des_fcrypt(const char *buf,const char *salt, char *ret);
177char *des_crypt(const char *buf,const char *salt);
178#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
179char *crypt(const char *buf,const char *salt);
180#endif
181void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
182 long length,des_key_schedule schedule,des_cblock *ivec);
183void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
184 long length,des_key_schedule schedule,des_cblock *ivec,
185 int enc);
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
187 long length,int out_count,des_cblock *seed);
188void des_random_seed(des_cblock *key);
189void des_random_key(des_cblock *ret);
190int des_read_password(des_cblock *key,const char *prompt,int verify);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2,
192 const char *prompt,int verify);
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
194void des_set_odd_parity(des_cblock *key);
195int des_is_weak_key(const_des_cblock *key);
196int des_set_key(const_des_cblock *key,des_key_schedule schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
198void des_string_to_key(const char *str,des_cblock *key);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
201 des_key_schedule schedule,des_cblock *ivec,int *num,
202 int enc);
203void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
204 des_key_schedule schedule,des_cblock *ivec,int *num);
205int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
206
207/* Extra functions from Mark Murray <mark@grondar.za> */
208void des_cblock_print_file(const_des_cblock *cb, FILE *fp);
209
210/* The following definitions provide compatibility with the MIT Kerberos
211 * library. The des_key_schedule structure is not binary compatible. */
212
213#define _KERBEROS_DES_H
214
215#define KRBDES_ENCRYPT DES_ENCRYPT
216#define KRBDES_DECRYPT DES_DECRYPT
217
218#ifdef KERBEROS
219# define ENCRYPT DES_ENCRYPT
220# define DECRYPT DES_DECRYPT
221#endif
222
223#ifndef NCOMPAT
224# define C_Block des_cblock
225# define Key_schedule des_key_schedule
226# define KEY_SZ DES_KEY_SZ
227# define string_to_key des_string_to_key
228# define read_pw_string des_read_pw_string
229# define random_key des_random_key
230# define pcbc_encrypt des_pcbc_encrypt
231# define set_key des_set_key
232# define key_sched des_key_sched
233# define ecb_encrypt des_ecb_encrypt
234# define cbc_encrypt des_cbc_encrypt
235# define ncbc_encrypt des_ncbc_encrypt
236# define xcbc_encrypt des_xcbc_encrypt
237# define cbc_cksum des_cbc_cksum
238# define quad_cksum des_quad_cksum
239#endif
240
241typedef des_key_schedule bit_64;
242#define des_fixup_key_parity des_set_odd_parity
243#define des_check_key_parity check_parity
244
245#ifdef __cplusplus
246}
247#endif
248
249#endif
diff --git a/src/lib/libssl/src/crypto/des/des.pod b/src/lib/libssl/src/crypto/des/des.pod
new file mode 100644
index 0000000000..bf479e83d2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des.pod
@@ -0,0 +1,217 @@
1=pod
2
3=head1 NAME
4
5des - encrypt or decrypt data using Data Encryption Standard
6
7=head1 SYNOPSIS
8
9B<des>
10(
11B<-e>
12|
13B<-E>
14) | (
15B<-d>
16|
17B<-D>
18) | (
19B<->[B<cC>][B<ckname>]
20) |
21[
22B<-b3hfs>
23] [
24B<-k>
25I<key>
26]
27] [
28B<-u>[I<uuname>]
29[
30I<input-file>
31[
32I<output-file>
33] ]
34
35=head1 NOTE
36
37This page describes the B<des> stand-alone program, not the B<openssl des>
38command.
39
40=head1 DESCRIPTION
41
42B<des>
43encrypts and decrypts data using the
44Data Encryption Standard algorithm.
45One of
46B<-e>, B<-E>
47(for encrypt) or
48B<-d>, B<-D>
49(for decrypt) must be specified.
50It is also possible to use
51B<-c>
52or
53B<-C>
54in conjunction or instead of the a encrypt/decrypt option to generate
55a 16 character hexadecimal checksum, generated via the
56I<des_cbc_cksum>.
57
58Two standard encryption modes are supported by the
59B<des>
60program, Cipher Block Chaining (the default) and Electronic Code Book
61(specified with
62B<-b>).
63
64The key used for the DES
65algorithm is obtained by prompting the user unless the
66B<-k>
67I<key>
68option is given.
69If the key is an argument to the
70B<des>
71command, it is potentially visible to users executing
72ps(1)
73or a derivative. To minimise this possibility,
74B<des>
75takes care to destroy the key argument immediately upon entry.
76If your shell keeps a history file be careful to make sure it is not
77world readable.
78
79Since this program attempts to maintain compatibility with sunOS's
80des(1) command, there are 2 different methods used to convert the user
81supplied key to a des key.
82Whenever and one or more of
83B<-E>, B<-D>, B<-C>
84or
85B<-3>
86options are used, the key conversion procedure will not be compatible
87with the sunOS des(1) version but will use all the user supplied
88character to generate the des key.
89B<des>
90command reads from standard input unless
91I<input-file>
92is specified and writes to standard output unless
93I<output-file>
94is given.
95
96=head1 OPTIONS
97
98=over 4
99
100=item B<-b>
101
102Select ECB
103(eight bytes at a time) encryption mode.
104
105=item B<-3>
106
107Encrypt using triple encryption.
108By default triple cbc encryption is used but if the
109B<-b>
110option is used then triple ECB encryption is performed.
111If the key is less than 8 characters long, the flag has no effect.
112
113=item B<-e>
114
115Encrypt data using an 8 byte key in a manner compatible with sunOS
116des(1).
117
118=item B<-E>
119
120Encrypt data using a key of nearly unlimited length (1024 bytes).
121This will product a more secure encryption.
122
123=item B<-d>
124
125Decrypt data that was encrypted with the B<-e> option.
126
127=item B<-D>
128
129Decrypt data that was encrypted with the B<-E> option.
130
131=item B<-c>
132
133Generate a 16 character hexadecimal cbc checksum and output this to
134stderr.
135If a filename was specified after the
136B<-c>
137option, the checksum is output to that file.
138The checksum is generated using a key generated in a sunOS compatible
139manner.
140
141=item B<-C>
142
143A cbc checksum is generated in the same manner as described for the
144B<-c>
145option but the DES key is generated in the same manner as used for the
146B<-E>
147and
148B<-D>
149options
150
151=item B<-f>
152
153Does nothing - allowed for compatibility with sunOS des(1) command.
154
155=item B<-s>
156
157Does nothing - allowed for compatibility with sunOS des(1) command.
158
159=item B<-k> I<key>
160
161Use the encryption
162I<key>
163specified.
164
165=item B<-h>
166
167The
168I<key>
169is assumed to be a 16 character hexadecimal number.
170If the
171B<-3>
172option is used the key is assumed to be a 32 character hexadecimal
173number.
174
175=item B<-u>
176
177This flag is used to read and write uuencoded files. If decrypting,
178the input file is assumed to contain uuencoded, DES encrypted data.
179If encrypting, the characters following the B<-u> are used as the name of
180the uuencoded file to embed in the begin line of the uuencoded
181output. If there is no name specified after the B<-u>, the name text.des
182will be embedded in the header.
183
184=head1 SEE ALSO
185
186ps(1),
187L<des_crypt(3)|des_crypt(3)>
188
189=head1 BUGS
190
191The problem with using the
192B<-e>
193option is the short key length.
194It would be better to use a real 56-bit key rather than an
195ASCII-based 56-bit pattern. Knowing that the key was derived from ASCII
196radically reduces the time necessary for a brute-force cryptographic attack.
197My attempt to remove this problem is to add an alternative text-key to
198DES-key function. This alternative function (accessed via
199B<-E>, B<-D>, B<-S>
200and
201B<-3>)
202uses DES to help generate the key.
203
204Be carefully when using the B<-u> option. Doing B<des -ud> I<filename> will
205not decrypt filename (the B<-u> option will gobble the B<-d> option).
206
207The VMS operating system operates in a world where files are always a
208multiple of 512 bytes. This causes problems when encrypted data is
209send from Unix to VMS since a 88 byte file will suddenly be padded
210with 424 null bytes. To get around this problem, use the B<-u> option
211to uuencode the data before it is send to the VMS system.
212
213=head1 AUTHOR
214
215Eric Young (eay@cryptsoft.com)
216
217=cut
diff --git a/src/lib/libssl/src/crypto/des/des_locl.h b/src/lib/libssl/src/crypto/des/des_locl.h
new file mode 100644
index 0000000000..d6ea17cb68
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_locl.h
@@ -0,0 +1,408 @@
1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H
61
62#if defined(WIN32) || defined(WIN16)
63#ifndef MSDOS
64#define MSDOS
65#endif
66#endif
67
68#include <stdio.h>
69#include <stdlib.h>
70
71#include <openssl/opensslconf.h>
72
73#ifndef MSDOS
74#if !defined(VMS) || defined(__DECC)
75#include OPENSSL_UNISTD
76#include <math.h>
77#endif
78#endif
79#include <openssl/des.h>
80
81#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
82#include <stdlib.h>
83#include <errno.h>
84#include <time.h>
85#include <io.h>
86#endif
87
88#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
89#include <string.h>
90#endif
91
92#define ITERATIONS 16
93#define HALF_ITERATIONS 8
94
95/* used in des_read and des_write */
96#define MAXWRITE (1024*16)
97#define BSIZE (MAXWRITE+4)
98
99#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
100 l|=((DES_LONG)(*((c)++)))<< 8L, \
101 l|=((DES_LONG)(*((c)++)))<<16L, \
102 l|=((DES_LONG)(*((c)++)))<<24L)
103
104/* NOTE - c is not incremented as per c2l */
105#define c2ln(c,l1,l2,n) { \
106 c+=n; \
107 l1=l2=0; \
108 switch (n) { \
109 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
110 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
111 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
112 case 5: l2|=((DES_LONG)(*(--(c)))); \
113 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
114 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
115 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
116 case 1: l1|=((DES_LONG)(*(--(c)))); \
117 } \
118 }
119
120#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
121 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
122 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
123 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
124
125/* replacements for htonl and ntohl since I have no idea what to do
126 * when faced with machines with 8 byte longs. */
127#define HDRSIZE 4
128
129#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
130 l|=((DES_LONG)(*((c)++)))<<16L, \
131 l|=((DES_LONG)(*((c)++)))<< 8L, \
132 l|=((DES_LONG)(*((c)++))))
133
134#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
135 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
136 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
137 *((c)++)=(unsigned char)(((l) )&0xff))
138
139/* NOTE - c is not incremented as per l2c */
140#define l2cn(l1,l2,c,n) { \
141 c+=n; \
142 switch (n) { \
143 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
144 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
145 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
146 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
147 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
148 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
149 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
150 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
151 } \
152 }
153
154#if defined(WIN32)
155#define ROTATE(a,n) (_lrotr(a,n))
156#else
157#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
158#endif
159
160/* Don't worry about the LOAD_DATA() stuff, that is used by
161 * fcrypt() to add it's little bit to the front */
162
163#ifdef DES_FCRYPT
164
165#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
166 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
167
168#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
169 t=R^(R>>16L); \
170 u=t&E0; t&=E1; \
171 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
172 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
173#else
174#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
175#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
176 u=R^s[S ]; \
177 t=R^s[S+1]
178#endif
179
180/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs.
184 * It does not seem to work on the Alpha, even when DES_LONG is 4
185 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR
187
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there
189 * is no reason to not xor all the sub items together. This potentially
190 * saves a register since things can be xored directly into L */
191
192#if defined(DES_RISC1) || defined(DES_RISC2)
193#ifdef DES_RISC1
194#define D_ENCRYPT(LL,R,S) { \
195 unsigned int u1,u2,u3; \
196 LOAD_DATA(R,S,u,t,E0,E1,u1); \
197 u2=(int)u>>8L; \
198 u1=(int)u&0xfc; \
199 u2&=0xfc; \
200 t=ROTATE(t,4); \
201 u>>=16L; \
202 LL^= *(const DES_LONG *)(des_SP +u1); \
203 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
204 u3=(int)(u>>8L); \
205 u1=(int)u&0xfc; \
206 u3&=0xfc; \
207 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
208 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
209 u2=(int)t>>8L; \
210 u1=(int)t&0xfc; \
211 u2&=0xfc; \
212 t>>=16L; \
213 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
214 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
215 u3=(int)t>>8L; \
216 u1=(int)t&0xfc; \
217 u3&=0xfc; \
218 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
219 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
220#endif
221#ifdef DES_RISC2
222#define D_ENCRYPT(LL,R,S) { \
223 unsigned int u1,u2,s1,s2; \
224 LOAD_DATA(R,S,u,t,E0,E1,u1); \
225 u2=(int)u>>8L; \
226 u1=(int)u&0xfc; \
227 u2&=0xfc; \
228 t=ROTATE(t,4); \
229 LL^= *(const DES_LONG *)(des_SP +u1); \
230 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
231 s1=(int)(u>>16L); \
232 s2=(int)(u>>24L); \
233 s1&=0xfc; \
234 s2&=0xfc; \
235 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
236 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
237 u2=(int)t>>8L; \
238 u1=(int)t&0xfc; \
239 u2&=0xfc; \
240 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
241 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
242 s1=(int)(t>>16L); \
243 s2=(int)(t>>24L); \
244 s1&=0xfc; \
245 s2&=0xfc; \
246 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
247 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
248#endif
249#else
250#define D_ENCRYPT(LL,R,S) { \
251 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
252 t=ROTATE(t,4); \
253 LL^= \
254 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
255 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
256 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
257 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
258 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
259 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
260 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
261 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
262#endif
263
264#else /* original version */
265
266#if defined(DES_RISC1) || defined(DES_RISC2)
267#ifdef DES_RISC1
268#define D_ENCRYPT(LL,R,S) {\
269 unsigned int u1,u2,u3; \
270 LOAD_DATA(R,S,u,t,E0,E1,u1); \
271 u>>=2L; \
272 t=ROTATE(t,6); \
273 u2=(int)u>>8L; \
274 u1=(int)u&0x3f; \
275 u2&=0x3f; \
276 u>>=16L; \
277 LL^=des_SPtrans[0][u1]; \
278 LL^=des_SPtrans[2][u2]; \
279 u3=(int)u>>8L; \
280 u1=(int)u&0x3f; \
281 u3&=0x3f; \
282 LL^=des_SPtrans[4][u1]; \
283 LL^=des_SPtrans[6][u3]; \
284 u2=(int)t>>8L; \
285 u1=(int)t&0x3f; \
286 u2&=0x3f; \
287 t>>=16L; \
288 LL^=des_SPtrans[1][u1]; \
289 LL^=des_SPtrans[3][u2]; \
290 u3=(int)t>>8L; \
291 u1=(int)t&0x3f; \
292 u3&=0x3f; \
293 LL^=des_SPtrans[5][u1]; \
294 LL^=des_SPtrans[7][u3]; }
295#endif
296#ifdef DES_RISC2
297#define D_ENCRYPT(LL,R,S) {\
298 unsigned int u1,u2,s1,s2; \
299 LOAD_DATA(R,S,u,t,E0,E1,u1); \
300 u>>=2L; \
301 t=ROTATE(t,6); \
302 u2=(int)u>>8L; \
303 u1=(int)u&0x3f; \
304 u2&=0x3f; \
305 LL^=des_SPtrans[0][u1]; \
306 LL^=des_SPtrans[2][u2]; \
307 s1=(int)u>>16L; \
308 s2=(int)u>>24L; \
309 s1&=0x3f; \
310 s2&=0x3f; \
311 LL^=des_SPtrans[4][s1]; \
312 LL^=des_SPtrans[6][s2]; \
313 u2=(int)t>>8L; \
314 u1=(int)t&0x3f; \
315 u2&=0x3f; \
316 LL^=des_SPtrans[1][u1]; \
317 LL^=des_SPtrans[3][u2]; \
318 s1=(int)t>>16; \
319 s2=(int)t>>24L; \
320 s1&=0x3f; \
321 s2&=0x3f; \
322 LL^=des_SPtrans[5][s1]; \
323 LL^=des_SPtrans[7][s2]; }
324#endif
325
326#else
327
328#define D_ENCRYPT(LL,R,S) {\
329 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
330 t=ROTATE(t,4); \
331 LL^=\
332 des_SPtrans[0][(u>> 2L)&0x3f]^ \
333 des_SPtrans[2][(u>>10L)&0x3f]^ \
334 des_SPtrans[4][(u>>18L)&0x3f]^ \
335 des_SPtrans[6][(u>>26L)&0x3f]^ \
336 des_SPtrans[1][(t>> 2L)&0x3f]^ \
337 des_SPtrans[3][(t>>10L)&0x3f]^ \
338 des_SPtrans[5][(t>>18L)&0x3f]^ \
339 des_SPtrans[7][(t>>26L)&0x3f]; }
340#endif
341#endif
342
343 /* IP and FP
344 * The problem is more of a geometric problem that random bit fiddling.
345 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
346 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
347 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
348 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
349
350 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
351 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
352 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
353 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
354
355 The output has been subject to swaps of the form
356 0 1 -> 3 1 but the odd and even bits have been put into
357 2 3 2 0
358 different words. The main trick is to remember that
359 t=((l>>size)^r)&(mask);
360 r^=t;
361 l^=(t<<size);
362 can be used to swap and move bits between words.
363
364 So l = 0 1 2 3 r = 16 17 18 19
365 4 5 6 7 20 21 22 23
366 8 9 10 11 24 25 26 27
367 12 13 14 15 28 29 30 31
368 becomes (for size == 2 and mask == 0x3333)
369 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
370 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
371 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
372 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
373
374 Thanks for hints from Richard Outerbridge - he told me IP&FP
375 could be done in 15 xor, 10 shifts and 5 ands.
376 When I finally started to think of the problem in 2D
377 I first got ~42 operations without xors. When I remembered
378 how to use xors :-) I got it to its final state.
379 */
380#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
381 (b)^=(t),\
382 (a)^=((t)<<(n)))
383
384#define IP(l,r) \
385 { \
386 register DES_LONG tt; \
387 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
388 PERM_OP(l,r,tt,16,0x0000ffffL); \
389 PERM_OP(r,l,tt, 2,0x33333333L); \
390 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
391 PERM_OP(r,l,tt, 1,0x55555555L); \
392 }
393
394#define FP(l,r) \
395 { \
396 register DES_LONG tt; \
397 PERM_OP(l,r,tt, 1,0x55555555L); \
398 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
399 PERM_OP(l,r,tt, 2,0x33333333L); \
400 PERM_OP(r,l,tt,16,0x0000ffffL); \
401 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
402 }
403
404OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64];
405
406void fcrypt_body(DES_LONG *out,des_key_schedule ks,
407 DES_LONG Eswap0, DES_LONG Eswap1);
408#endif
diff --git a/src/lib/libssl/src/crypto/des/des_old.c b/src/lib/libssl/src/crypto/des/des_old.c
new file mode 100644
index 0000000000..7e4cd7180d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_old.c
@@ -0,0 +1,271 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with libdes. OpenSSL now provides
7 * functions where "des_" has been replaced with "DES_" in the names,
8 * to make it possible to make incompatible changes that are needed
9 * for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#define OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79const char *_ossl_old_des_options(void)
80 {
81 return DES_options();
82 }
83void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
84 des_key_schedule ks1,des_key_schedule ks2,
85 des_key_schedule ks3, int enc)
86 {
87 DES_ecb3_encrypt((const_DES_cblock *)input, output,
88 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
89 (DES_key_schedule *)ks3, enc);
90 }
91DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
92 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
93 {
94 return DES_cbc_cksum((unsigned char *)input, output, length,
95 (DES_key_schedule *)schedule, ivec);
96 }
97void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
98 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
99 {
100 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
101 length, (DES_key_schedule *)schedule, ivec, enc);
102 }
103void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
104 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
105 {
106 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
107 length, (DES_key_schedule *)schedule, ivec, enc);
108 }
109void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
110 des_key_schedule schedule,_ossl_old_des_cblock *ivec,
111 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc)
112 {
113 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
114 length, (DES_key_schedule *)schedule, ivec, inw, outw, enc);
115 }
116void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
117 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
118 {
119 DES_cfb_encrypt(in, out, numbits, length,
120 (DES_key_schedule *)schedule, ivec, enc);
121 }
122void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
123 des_key_schedule ks,int enc)
124 {
125 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
126 }
127void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc)
128 {
129 DES_encrypt1(data, (DES_key_schedule *)ks, enc);
130 }
131void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc)
132 {
133 DES_encrypt2(data, (DES_key_schedule *)ks, enc);
134 }
135void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
136 des_key_schedule ks2, des_key_schedule ks3)
137 {
138 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
139 (DES_key_schedule *)ks3);
140 }
141void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
142 des_key_schedule ks2, des_key_schedule ks3)
143 {
144 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
145 (DES_key_schedule *)ks3);
146 }
147void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
148 long length, des_key_schedule ks1, des_key_schedule ks2,
149 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc)
150 {
151 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
152 length, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
153 (DES_key_schedule *)ks3, ivec, enc);
154 }
155void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
156 long length, des_key_schedule ks1, des_key_schedule ks2,
157 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc)
158 {
159 DES_ede3_cfb64_encrypt(in, out, length,
160 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
161 (DES_key_schedule *)ks3, ivec, num, enc);
162 }
163void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164 long length, des_key_schedule ks1, des_key_schedule ks2,
165 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num)
166 {
167 DES_ede3_ofb64_encrypt(in, out, length,
168 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
169 (DES_key_schedule *)ks3, ivec, num);
170 }
171
172void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
173 _ossl_old_des_cblock (*out_white))
174 {
175 DES_xwhite_in2out(des_key, in_white, out_white);
176 }
177
178int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
179 _ossl_old_des_cblock *iv)
180 {
181 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
182 }
183int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
184 _ossl_old_des_cblock *iv)
185 {
186 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
187 }
188char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret)
189 {
190 return DES_fcrypt(buf, salt, ret);
191 }
192char *_ossl_old_des_crypt(const char *buf,const char *salt)
193 {
194 return DES_crypt(buf, salt);
195 }
196char *_ossl_old_crypt(const char *buf,const char *salt)
197 {
198 return DES_crypt(buf, salt);
199 }
200void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
201 int numbits,long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
202 {
203 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
204 ivec);
205 }
206void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
207 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
208 {
209 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
210 length, (DES_key_schedule *)schedule, ivec, enc);
211 }
212DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
213 long length,int out_count,_ossl_old_des_cblock *seed)
214 {
215 return DES_quad_cksum((unsigned char *)input, output, length,
216 out_count, seed);
217 }
218void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
219 {
220 RAND_seed(key, sizeof(_ossl_old_des_cblock));
221 }
222void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
223 {
224 DES_random_key((DES_cblock *)ret);
225 }
226int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
227 int verify)
228 {
229 return DES_read_password(key, prompt, verify);
230 }
231int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, _ossl_old_des_cblock *key2,
232 const char *prompt, int verify)
233 {
234 return DES_read_2passwords(key1, key2, prompt, verify);
235 }
236void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
237 {
238 DES_set_odd_parity(key);
239 }
240int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
241 {
242 return DES_is_weak_key(key);
243 }
244int _ossl_old_des_set_key(_ossl_old_des_cblock *key,des_key_schedule schedule)
245 {
246 return DES_set_key(key, (DES_key_schedule *)schedule);
247 }
248int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,des_key_schedule schedule)
249 {
250 return DES_key_sched(key, (DES_key_schedule *)schedule);
251 }
252void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key)
253 {
254 DES_string_to_key(str, key);
255 }
256void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2)
257 {
258 DES_string_to_2keys(str, key1, key2);
259 }
260void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
261 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc)
262 {
263 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
264 ivec, num, enc);
265 }
266void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
267 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num)
268 {
269 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
270 ivec, num);
271 }
diff --git a/src/lib/libssl/src/crypto/des/des_old.h b/src/lib/libssl/src/crypto/des/des_old.h
new file mode 100644
index 0000000000..3778f93c15
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_old.h
@@ -0,0 +1,437 @@
1/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with openssl 0.9.6 and older as
7 * well as libdes. OpenSSL now provides functions where "des_" has
8 * been replaced with "DES_" in the names, to make it possible to
9 * make incompatible changes that are needed for C type security and
10 * other stuff.
11 *
12 * This include files has two compatibility modes:
13 *
14 * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API
15 * that is compatible with libdes and SSLeay.
16 * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an
17 * API that is compatible with OpenSSL 0.9.5x to 0.9.6x.
18 *
19 * Note that these modes break earlier snapshots of OpenSSL, where
20 * libdes compatibility was the only available mode or (later on) the
21 * prefered compatibility mode. However, after much consideration
22 * (and more or less violent discussions with external parties), it
23 * was concluded that OpenSSL should be compatible with earlier versions
24 * of itself before anything else. Also, in all honesty, libdes is
25 * an old beast that shouldn't really be used any more.
26 *
27 * Please consider starting to use the DES_ functions rather than the
28 * des_ ones. The des_ functions will disappear completely before
29 * OpenSSL 1.0!
30 *
31 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 */
33
34/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
35 * project 2001.
36 */
37/* ====================================================================
38 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. All advertising materials mentioning features or use of this
53 * software must display the following acknowledgment:
54 * "This product includes software developed by the OpenSSL Project
55 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
56 *
57 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
58 * endorse or promote products derived from this software without
59 * prior written permission. For written permission, please contact
60 * openssl-core@openssl.org.
61 *
62 * 5. Products derived from this software may not be called "OpenSSL"
63 * nor may "OpenSSL" appear in their names without prior written
64 * permission of the OpenSSL Project.
65 *
66 * 6. Redistributions of any form whatsoever must retain the following
67 * acknowledgment:
68 * "This product includes software developed by the OpenSSL Project
69 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
72 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
75 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
77 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
82 * OF THE POSSIBILITY OF SUCH DAMAGE.
83 * ====================================================================
84 *
85 * This product includes cryptographic software written by Eric Young
86 * (eay@cryptsoft.com). This product includes software written by Tim
87 * Hudson (tjh@cryptsoft.com).
88 *
89 */
90
91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_OLD_H
93
94#ifdef OPENSSL_NO_DES
95#error DES is disabled.
96#endif
97
98#ifndef HEADER_DES_H
99#error You must include des.h, not des_old.h directly.
100#endif
101
102#ifdef _KERBEROS_DES_H
103#error <openssl/des_old.h> replaces <kerberos/des.h>.
104#endif
105
106#include <openssl/opensslconf.h> /* DES_LONG */
107#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
108#include <openssl/symhacks.h>
109
110#ifdef OPENSSL_BUILD_SHLIBCRYPTO
111# undef OPENSSL_EXTERN
112# define OPENSSL_EXTERN OPENSSL_EXPORT
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119typedef unsigned char _ossl_old_des_cblock[8];
120typedef struct _ossl_old_des_ks_struct
121 {
122 union {
123 _ossl_old_des_cblock _;
124 /* make sure things are correct size on machines with
125 * 8 byte longs */
126 DES_LONG pad[2];
127 } ks;
128 } _ossl_old_des_key_schedule[16];
129
130#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
131#define des_cblock DES_cblock
132#define const_des_cblock const_DES_cblock
133#define des_key_schedule DES_key_schedule
134#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
135 DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))
136#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
137 DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))
138#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\
139 DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))
140#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
141 DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))
142#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
143 DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))
144#define des_options()\
145 DES_options()
146#define des_cbc_cksum(i,o,l,k,iv)\
147 DES_cbc_cksum((i),(o),(l),&(k),(iv))
148#define des_cbc_encrypt(i,o,l,k,iv,e)\
149 DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))
150#define des_ncbc_encrypt(i,o,l,k,iv,e)\
151 DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))
152#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
153 DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))
154#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
155 DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))
156#define des_ecb_encrypt(i,o,k,e)\
157 DES_ecb_encrypt((i),(o),&(k),(e))
158#define des_encrypt1(d,k,e)\
159 DES_encrypt1((d),&(k),(e))
160#define des_encrypt2(d,k,e)\
161 DES_encrypt2((d),&(k),(e))
162#define des_encrypt3(d,k1,k2,k3)\
163 DES_encrypt3((d),&(k1),&(k2),&(k3))
164#define des_decrypt3(d,k1,k2,k3)\
165 DES_decrypt3((d),&(k1),&(k2),&(k3))
166#define des_xwhite_in2out(k,i,o)\
167 DES_xwhite_in2out((k),(i),(o))
168#define des_enc_read(f,b,l,k,iv)\
169 DES_enc_read((f),(b),(l),&(k),(iv))
170#define des_enc_write(f,b,l,k,iv)\
171 DES_enc_write((f),(b),(l),&(k),(iv))
172#define des_fcrypt(b,s,r)\
173 DES_fcrypt((b),(s),(r))
174#define des_crypt(b,s)\
175 DES_crypt((b),(s))
176#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
177#define crypt(b,s)\
178 DES_crypt((b),(s))
179#endif
180#define des_ofb_encrypt(i,o,n,l,k,iv)\
181 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
182#define des_pcbc_encrypt(i,o,l,k,iv,e)\
183 DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))
184#define des_quad_cksum(i,o,l,c,s)\
185 DES_quad_cksum((i),(o),(l),(c),(s))
186#define des_random_seed(k)\
187 _ossl_096_des_random_seed((k))
188#define des_random_key(r)\
189 DES_random_key((r))
190#define des_read_password(k,p,v) \
191 DES_read_password((k),(p),(v))
192#define des_read_2passwords(k1,k2,p,v) \
193 DES_read_2passwords((k1),(k2),(p),(v))
194#define des_set_odd_parity(k)\
195 DES_set_odd_parity((k))
196#define des_check_key_parity(k)\
197 DES_check_key_parity((k))
198#define des_is_weak_key(k)\
199 DES_is_weak_key((k))
200#define des_set_key(k,ks)\
201 DES_set_key((k),&(ks))
202#define des_key_sched(k,ks)\
203 DES_key_sched((k),&(ks))
204#define des_set_key_checked(k,ks)\
205 DES_set_key_checked((k),&(ks))
206#define des_set_key_unchecked(k,ks)\
207 DES_set_key_unchecked((k),&(ks))
208#define des_string_to_key(s,k)\
209 DES_string_to_key((s),(k))
210#define des_string_to_2keys(s,k1,k2)\
211 DES_string_to_2keys((s),(k1),(k2))
212#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
213 DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))
214#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
215 DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))
216
217
218#define des_ecb2_encrypt(i,o,k1,k2,e) \
219 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
220
221#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
222 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
223
224#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
225 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
226
227#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
228 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
229
230#define des_check_key DES_check_key
231#define des_rw_mode DES_rw_mode
232#else /* libdes compatibility */
233/* Map all symbol names to _ossl_old_des_* form, so we avoid all
234 clashes with libdes */
235#define des_cblock _ossl_old_des_cblock
236#define des_key_schedule _ossl_old_des_key_schedule
237#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
238 _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
239#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
240 _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
241#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
242 _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))
243#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
244 _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
245#define des_options()\
246 _ossl_old_des_options()
247#define des_cbc_cksum(i,o,l,k,iv)\
248 _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
249#define des_cbc_encrypt(i,o,l,k,iv,e)\
250 _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
251#define des_ncbc_encrypt(i,o,l,k,iv,e)\
252 _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
253#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
254 _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
255#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
256 _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))
257#define des_ecb_encrypt(i,o,k,e)\
258 _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
259#define des_encrypt(d,k,e)\
260 _ossl_old_des_encrypt((d),(k),(e))
261#define des_encrypt2(d,k,e)\
262 _ossl_old_des_encrypt2((d),(k),(e))
263#define des_encrypt3(d,k1,k2,k3)\
264 _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
265#define des_decrypt3(d,k1,k2,k3)\
266 _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
267#define des_xwhite_in2out(k,i,o)\
268 _ossl_old_des_xwhite_in2out((k),(i),(o))
269#define des_enc_read(f,b,l,k,iv)\
270 _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
271#define des_enc_write(f,b,l,k,iv)\
272 _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
273#define des_fcrypt(b,s,r)\
274 _ossl_old_des_fcrypt((b),(s),(r))
275#define des_crypt(b,s)\
276 _ossl_old_des_crypt((b),(s))
277#define crypt(b,s)\
278 _ossl_old_crypt((b),(s))
279#define des_ofb_encrypt(i,o,n,l,k,iv)\
280 _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
281#define des_pcbc_encrypt(i,o,l,k,iv,e)\
282 _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
283#define des_quad_cksum(i,o,l,c,s)\
284 _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
285#define des_random_seed(k)\
286 _ossl_old_des_random_seed((k))
287#define des_random_key(r)\
288 _ossl_old_des_random_key((r))
289#define des_read_password(k,p,v) \
290 _ossl_old_des_read_password((k),(p),(v))
291#define des_read_2passwords(k1,k2,p,v) \
292 _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
293#define des_set_odd_parity(k)\
294 _ossl_old_des_set_odd_parity((k))
295#define des_is_weak_key(k)\
296 _ossl_old_des_is_weak_key((k))
297#define des_set_key(k,ks)\
298 _ossl_old_des_set_key((k),(ks))
299#define des_key_sched(k,ks)\
300 _ossl_old_des_key_sched((k),(ks))
301#define des_string_to_key(s,k)\
302 _ossl_old_des_string_to_key((s),(k))
303#define des_string_to_2keys(s,k1,k2)\
304 _ossl_old_des_string_to_2keys((s),(k1),(k2))
305#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
306 _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
307#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
308 _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
309
310
311#define des_ecb2_encrypt(i,o,k1,k2,e) \
312 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
313
314#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
315 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
316
317#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
318 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
319
320#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
321 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
322
323#define des_check_key DES_check_key
324#define des_rw_mode DES_rw_mode
325#endif
326
327const char *_ossl_old_des_options(void);
328void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
329 _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
330 _ossl_old_des_key_schedule ks3, int enc);
331DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
332 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
333void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
334 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
335void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
336 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
337void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
338 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
339 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
340void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
341 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
342void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
343 _ossl_old_des_key_schedule ks,int enc);
344void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
345void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
346void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
347 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
348void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
349 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
350void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
351 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
352 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
353void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
354 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
355 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
356void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
357 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
358 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
359
360void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
361 _ossl_old_des_cblock (*out_white));
362
363int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
364 _ossl_old_des_cblock *iv);
365int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
366 _ossl_old_des_cblock *iv);
367char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
368char *_ossl_old_des_crypt(const char *buf,const char *salt);
369#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
370char *_ossl_old_crypt(const char *buf,const char *salt);
371#endif
372void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
373 int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
374void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
375 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
376DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
377 long length,int out_count,_ossl_old_des_cblock *seed);
378void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
379void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
380int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
381int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
382 const char *prompt,int verify);
383void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
384int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
385int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
386int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
387void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
388void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
389void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
390 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
391void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
392 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
393
394void _ossl_096_des_random_seed(des_cblock *key);
395
396/* The following definitions provide compatibility with the MIT Kerberos
397 * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
398
399#define _KERBEROS_DES_H
400
401#define KRBDES_ENCRYPT DES_ENCRYPT
402#define KRBDES_DECRYPT DES_DECRYPT
403
404#ifdef KERBEROS
405# define ENCRYPT DES_ENCRYPT
406# define DECRYPT DES_DECRYPT
407#endif
408
409#ifndef NCOMPAT
410# define C_Block des_cblock
411# define Key_schedule des_key_schedule
412# define KEY_SZ DES_KEY_SZ
413# define string_to_key des_string_to_key
414# define read_pw_string des_read_pw_string
415# define random_key des_random_key
416# define pcbc_encrypt des_pcbc_encrypt
417# define set_key des_set_key
418# define key_sched des_key_sched
419# define ecb_encrypt des_ecb_encrypt
420# define cbc_encrypt des_cbc_encrypt
421# define ncbc_encrypt des_ncbc_encrypt
422# define xcbc_encrypt des_xcbc_encrypt
423# define cbc_cksum des_cbc_cksum
424# define quad_cksum des_quad_cksum
425# define check_parity des_check_key_parity
426#endif
427
428#define des_fixup_key_parity DES_fixup_key_parity
429
430#ifdef __cplusplus
431}
432#endif
433
434/* for DES_read_pw_string et al */
435#include <openssl/ui_compat.h>
436
437#endif
diff --git a/src/lib/libssl/src/crypto/des/des_old2.c b/src/lib/libssl/src/crypto/des/des_old2.c
new file mode 100644
index 0000000000..c8fa3ee135
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_old2.c
@@ -0,0 +1,82 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with OpenSSL 0.9.6c. OpenSSL now
7 * provides functions where "des_" has been replaced with "DES_" in
8 * the names, to make it possible to make incompatible changes that
9 * are needed for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#undef OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79void _ossl_096_des_random_seed(DES_cblock *key)
80 {
81 RAND_seed(key, sizeof(DES_cblock));
82 }
diff --git a/src/lib/libssl/src/crypto/des/ede_cbcm_enc.c b/src/lib/libssl/src/crypto/des/ede_cbcm_enc.c
new file mode 100644
index 0000000000..c53062481d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ede_cbcm_enc.c
@@ -0,0 +1,197 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#ifndef NO_DESCBCM
72#include "des_locl.h"
73
74void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, des_key_schedule ks1, des_key_schedule ks2,
76 des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2,
77 int enc)
78 {
79 register DES_LONG tin0,tin1;
80 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
81 register long l=length;
82 DES_LONG tin[2];
83 unsigned char *iv1,*iv2;
84
85 iv1 = &(*ivec1)[0];
86 iv2 = &(*ivec2)[0];
87
88 if (enc)
89 {
90 c2l(iv1,m0);
91 c2l(iv1,m1);
92 c2l(iv2,tout0);
93 c2l(iv2,tout1);
94 for (l-=8; l>=-7; l-=8)
95 {
96 tin[0]=m0;
97 tin[1]=m1;
98 des_encrypt(tin,ks3,1);
99 m0=tin[0];
100 m1=tin[1];
101
102 if(l < 0)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 }
106 else
107 {
108 c2l(in,tin0);
109 c2l(in,tin1);
110 }
111 tin0^=tout0;
112 tin1^=tout1;
113
114 tin[0]=tin0;
115 tin[1]=tin1;
116 des_encrypt(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 des_encrypt(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 des_encrypt(tin,ks1,1);
123 tout0=tin[0];
124 tout1=tin[1];
125
126 l2c(tout0,out);
127 l2c(tout1,out);
128 }
129 iv1=&(*ivec1)[0];
130 l2c(m0,iv1);
131 l2c(m1,iv1);
132
133 iv2=&(*ivec2)[0];
134 l2c(tout0,iv2);
135 l2c(tout1,iv2);
136 }
137 else
138 {
139 register DES_LONG t0,t1;
140
141 c2l(iv1,m0);
142 c2l(iv1,m1);
143 c2l(iv2,xor0);
144 c2l(iv2,xor1);
145 for (l-=8; l>=-7; l-=8)
146 {
147 tin[0]=m0;
148 tin[1]=m1;
149 des_encrypt(tin,ks3,1);
150 m0=tin[0];
151 m1=tin[1];
152
153 c2l(in,tin0);
154 c2l(in,tin1);
155
156 t0=tin0;
157 t1=tin1;
158
159 tin[0]=tin0;
160 tin[1]=tin1;
161 des_encrypt(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 des_encrypt(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 des_encrypt(tin,ks1,0);
168 tout0=tin[0];
169 tout1=tin[1];
170
171 tout0^=xor0;
172 tout1^=xor1;
173 if(l < 0)
174 {
175 l2cn(tout0,tout1,out,l+8);
176 }
177 else
178 {
179 l2c(tout0,out);
180 l2c(tout1,out);
181 }
182 xor0=t0;
183 xor1=t1;
184 }
185
186 iv1=&(*ivec1)[0];
187 l2c(m0,iv1);
188 l2c(m1,iv1);
189
190 iv2=&(*ivec2)[0];
191 l2c(xor0,iv2);
192 l2c(xor1,iv2);
193 }
194 tin0=tin1=tout0=tout1=xor0=xor1=0;
195 tin[0]=tin[1]=0;
196 }
197#endif
diff --git a/src/lib/libssl/src/crypto/dh/dh_asn1.c b/src/lib/libssl/src/crypto/dh/dh_asn1.c
new file mode 100644
index 0000000000..769b5b68c5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_asn1.c
@@ -0,0 +1,87 @@
1/* dh_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65
66/* Override the default free and new methods */
67static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
68{
69 if(operation == ASN1_OP_NEW_PRE) {
70 *pval = (ASN1_VALUE *)DH_new();
71 if(*pval) return 2;
72 return 0;
73 } else if(operation == ASN1_OP_FREE_PRE) {
74 DH_free((DH *)*pval);
75 *pval = NULL;
76 return 2;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DHparams, dh_cb) = {
82 ASN1_SIMPLE(DH, p, BIGNUM),
83 ASN1_SIMPLE(DH, g, BIGNUM),
84 ASN1_OPT(DH, length, ZLONG),
85} ASN1_SEQUENCE_END_cb(DH, DHparams)
86
87IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DH, DHparams, DHparams)
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_asn1.c b/src/lib/libssl/src/crypto/dsa/dsa_asn1.c
new file mode 100644
index 0000000000..7523b21654
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_asn1.c
@@ -0,0 +1,96 @@
1/* crypto/dsa/dsa_asn1.c */
2
3#include <stdio.h>
4#include "cryptlib.h"
5#include <openssl/dsa.h>
6#include <openssl/asn1.h>
7#include <openssl/asn1_mac.h>
8
9DSA_SIG *DSA_SIG_new(void)
10{
11 DSA_SIG *ret;
12
13 ret = Malloc(sizeof(DSA_SIG));
14 if (ret == NULL)
15 {
16 DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE);
17 return(NULL);
18 }
19 ret->r = NULL;
20 ret->s = NULL;
21 return(ret);
22}
23
24void DSA_SIG_free(DSA_SIG *r)
25{
26 if (r == NULL) return;
27 if (r->r) BN_clear_free(r->r);
28 if (r->s) BN_clear_free(r->s);
29 Free(r);
30}
31
32int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp)
33{
34 int t=0,len;
35 ASN1_INTEGER rbs,sbs;
36 unsigned char *p;
37
38 rbs.data=Malloc(BN_num_bits(v->r)/8+1);
39 if (rbs.data == NULL)
40 {
41 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
42 return(0);
43 }
44 rbs.type=V_ASN1_INTEGER;
45 rbs.length=BN_bn2bin(v->r,rbs.data);
46 sbs.data=Malloc(BN_num_bits(v->s)/8+1);
47 if (sbs.data == NULL)
48 {
49 Free(rbs.data);
50 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
51 return(0);
52 }
53 sbs.type=V_ASN1_INTEGER;
54 sbs.length=BN_bn2bin(v->s,sbs.data);
55
56 len=i2d_ASN1_INTEGER(&rbs,NULL);
57 len+=i2d_ASN1_INTEGER(&sbs,NULL);
58
59 if (pp)
60 {
61 p=*pp;
62 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
63 i2d_ASN1_INTEGER(&rbs,&p);
64 i2d_ASN1_INTEGER(&sbs,&p);
65 }
66 t=ASN1_object_size(1,len,V_ASN1_SEQUENCE);
67 Free(rbs.data);
68 Free(sbs.data);
69 return(t);
70}
71
72DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length)
73{
74 int i=ERR_R_NESTED_ASN1_ERROR;
75 ASN1_INTEGER *bs=NULL;
76 M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
81 if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL)
82 goto err_bn;
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL)
85 goto err_bn;
86 ASN1_BIT_STRING_free(bs);
87 M_ASN1_D2I_Finish_2(a);
88
89err_bn:
90 i=ERR_R_BN_LIB;
91err:
92 DSAerr(DSA_F_D2I_DSA_SIG,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret);
94 if (bs != NULL) ASN1_BIT_STRING_free(bs);
95 return(NULL);
96}
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_ossl.c b/src/lib/libssl/src/crypto/dsa/dsa_ossl.c
new file mode 100644
index 0000000000..b51cf6ad8d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_ossl.c
@@ -0,0 +1,321 @@
1/* crypto/dsa/dsa_ossl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
69static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
70static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
71 DSA *dsa);
72static int dsa_init(DSA *dsa);
73static int dsa_finish(DSA *dsa);
74static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
75 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
76 BN_MONT_CTX *in_mont);
77static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
78 const BIGNUM *m, BN_CTX *ctx,
79 BN_MONT_CTX *m_ctx);
80
81static DSA_METHOD openssl_dsa_meth = {
82"OpenSSL DSA method",
83dsa_do_sign,
84dsa_sign_setup,
85dsa_do_verify,
86dsa_mod_exp,
87dsa_bn_mod_exp,
88dsa_init,
89dsa_finish,
900,
91NULL
92};
93
94DSA_METHOD *DSA_OpenSSL(void)
95{
96 return &openssl_dsa_meth;
97}
98
99static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
100 {
101 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
102 BIGNUM m;
103 BIGNUM xr;
104 BN_CTX *ctx=NULL;
105 int i,reason=ERR_R_BN_LIB;
106 DSA_SIG *ret=NULL;
107
108 BN_init(&m);
109 BN_init(&xr);
110 s=BN_new();
111 if (s == NULL) goto err;
112
113 i=BN_num_bytes(dsa->q); /* should be 20 */
114 if ((dlen > i) || (dlen > 50))
115 {
116 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
117 goto err;
118 }
119
120 ctx=BN_CTX_new();
121 if (ctx == NULL) goto err;
122
123 if ((dsa->kinv == NULL) || (dsa->r == NULL))
124 {
125 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
126 }
127 else
128 {
129 kinv=dsa->kinv;
130 dsa->kinv=NULL;
131 r=dsa->r;
132 dsa->r=NULL;
133 }
134
135 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
136
137 /* Compute s = inv(k) (m + xr) mod q */
138 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
139 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
140 if (BN_cmp(s,dsa->q) > 0)
141 BN_sub(s,s,dsa->q);
142 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
143
144 ret=DSA_SIG_new();
145 if (ret == NULL) goto err;
146 ret->r = r;
147 ret->s = s;
148
149err:
150 if (!ret)
151 {
152 DSAerr(DSA_F_DSA_DO_SIGN,reason);
153 BN_free(r);
154 BN_free(s);
155 }
156 if (ctx != NULL) BN_CTX_free(ctx);
157 BN_clear_free(&m);
158 BN_clear_free(&xr);
159 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
160 BN_clear_free(kinv);
161 return(ret);
162 }
163
164static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
165 {
166 BN_CTX *ctx;
167 BIGNUM k,*kinv=NULL,*r=NULL;
168 int ret=0;
169
170 if (ctx_in == NULL)
171 {
172 if ((ctx=BN_CTX_new()) == NULL) goto err;
173 }
174 else
175 ctx=ctx_in;
176
177 BN_init(&k);
178 if ((r=BN_new()) == NULL) goto err;
179 kinv=NULL;
180
181 /* Get random k */
182 for (;;)
183 {
184 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
185 if (BN_cmp(&k,dsa->q) >= 0)
186 BN_sub(&k,&k,dsa->q);
187 if (!BN_is_zero(&k)) break;
188 }
189
190 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
191 {
192 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
193 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
194 dsa->p,ctx)) goto err;
195 }
196
197 /* Compute r = (g^k mod p) mod q */
198 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
199 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
200 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
201
202 /* Compute part of 's = inv(k) (m + xr) mod q' */
203 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
204
205 if (*kinvp != NULL) BN_clear_free(*kinvp);
206 *kinvp=kinv;
207 kinv=NULL;
208 if (*rp != NULL) BN_clear_free(*rp);
209 *rp=r;
210 ret=1;
211err:
212 if (!ret)
213 {
214 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
215 if (kinv != NULL) BN_clear_free(kinv);
216 if (r != NULL) BN_clear_free(r);
217 }
218 if (ctx_in == NULL) BN_CTX_free(ctx);
219 if (kinv != NULL) BN_clear_free(kinv);
220 BN_clear_free(&k);
221 return(ret);
222 }
223
224static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
225 DSA *dsa)
226 {
227 BN_CTX *ctx;
228 BIGNUM u1,u2,t1;
229 BN_MONT_CTX *mont=NULL;
230 int ret = -1;
231
232 if ((ctx=BN_CTX_new()) == NULL) goto err;
233 BN_init(&u1);
234 BN_init(&u2);
235 BN_init(&t1);
236
237 /* Calculate W = inv(S) mod Q
238 * save W in u2 */
239 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
240
241 /* save M in u1 */
242 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
243
244 /* u1 = M * w mod q */
245 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
246
247 /* u2 = r * w mod q */
248 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
249
250 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
251 {
252 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
253 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
254 dsa->p,ctx)) goto err;
255 }
256 mont=(BN_MONT_CTX *)dsa->method_mont_p;
257
258#if 0
259 {
260 BIGNUM t2;
261
262 BN_init(&t2);
263 /* v = ( g^u1 * y^u2 mod p ) mod q */
264 /* let t1 = g ^ u1 mod p */
265 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
266 /* let t2 = y ^ u2 mod p */
267 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
268 /* let u1 = t1 * t2 mod p */
269 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
270 BN_free(&t2);
271 }
272 /* let u1 = u1 mod q */
273 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
274#else
275 {
276 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
277 dsa->p,ctx,mont)) goto err;
278 /* BN_copy(&u1,&t1); */
279 /* let u1 = u1 mod q */
280 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
281 }
282#endif
283 /* V is now in u1. If the signature is correct, it will be
284 * equal to R. */
285 ret=(BN_ucmp(&u1, sig->r) == 0);
286
287 err:
288 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
289 if (ctx != NULL) BN_CTX_free(ctx);
290 BN_free(&u1);
291 BN_free(&u2);
292 BN_free(&t1);
293 return(ret);
294 }
295
296static int dsa_init(DSA *dsa)
297{
298 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
299 return(1);
300}
301
302static int dsa_finish(DSA *dsa)
303{
304 if(dsa->method_mont_p)
305 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
306 return(1);
307}
308
309static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
310 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
311 BN_MONT_CTX *in_mont)
312{
313 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
314}
315
316static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
317 const BIGNUM *m, BN_CTX *ctx,
318 BN_MONT_CTX *m_ctx)
319{
320 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
321}
diff --git a/src/lib/libssl/src/crypto/dso/README b/src/lib/libssl/src/crypto/dso/README
new file mode 100644
index 0000000000..6ba03c5631
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/README
@@ -0,0 +1,24 @@
1TODO
2----
3
4Find a way where name-translation can be done in a way that is
5sensitive to particular methods (ie. generic code could still do
6different path/filename substitutions on win32 to what it does on
7*nix) but doesn't assume some canonical form. Already one case
8exists where the "blah -> (libblah.so,blah.dll)" mapping doesn't
9suffice. I suspect a callback with an enumerated (or string?)
10parameter could be the way to go here ... DSO_ctrl the callback
11into place and it can be invoked to handle name translation with
12some clue to the calling code as to what kind of system it is.
13
14NOTES
15-----
16
17I've checked out HPUX (well, version 11 at least) and shl_t is
18a pointer type so it's safe to use in the way it has been in
19dso_dl.c. On the other hand, HPUX11 support dlfcn too and
20according to their man page, prefer developers to move to that.
21I'll leave Richard's changes there as I guess dso_dl is needed
22for HPUX10.20.
23
24
diff --git a/src/lib/libssl/src/crypto/dso/dso.h b/src/lib/libssl/src/crypto/dso/dso.h
new file mode 100644
index 0000000000..bed7c464a6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso.h
@@ -0,0 +1,250 @@
1/* dso.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_DSO_H
60#define HEADER_DSO_H
61
62#include <openssl/crypto.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/* These values are used as commands to DSO_ctrl() */
69#define DSO_CTRL_GET_FLAGS 1
70#define DSO_CTRL_SET_FLAGS 2
71#define DSO_CTRL_OR_FLAGS 3
72
73/* These flags control the translation of file-names from canonical to
74 * native. Eg. in the CryptoSwift support, the "dl" and "dlfcn"
75 * methods will translate "swift" -> "libswift.so" whereas the "win32"
76 * method will translate "swift" -> "swift.dll". NB: Until I can figure
77 * out how to be more "conventional" with this, the methods will only
78 * honour this flag if it looks like it was passed a file without any
79 * path and if the filename is small enough.
80 */
81#define DSO_FLAG_NAME_TRANSLATION 0x01
82
83/* The following flag controls the translation of symbol names to upper
84 * case. This is currently only being implemented for OpenVMS.
85 */
86#define DSO_FLAG_UPCASE_SYMBOL 0x02
87
88
89typedef void (*DSO_FUNC_TYPE)(void);
90
91typedef struct dso_st DSO;
92
93typedef struct dso_meth_st
94 {
95 const char *name;
96 /* Loads a shared library */
97 int (*dso_load)(DSO *dso, const char *filename);
98 /* Unloads a shared library */
99 int (*dso_unload)(DSO *dso);
100 /* Binds a variable */
101 void *(*dso_bind_var)(DSO *dso, const char *symname);
102 /* Binds a function - assumes a return type of DSO_FUNC_TYPE.
103 * This should be cast to the real function prototype by the
104 * caller. Platforms that don't have compatible representations
105 * for different prototypes (this is possible within ANSI C)
106 * are highly unlikely to have shared libraries at all, let
107 * alone a DSO_METHOD implemented for them. */
108 DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname);
109
110/* I don't think this would actually be used in any circumstances. */
111#if 0
112 /* Unbinds a variable */
113 int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr);
114 /* Unbinds a function */
115 int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
116#endif
117 /* The generic (yuck) "ctrl()" function. NB: Negative return
118 * values (rather than zero) indicate errors. */
119 long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg);
120
121 /* [De]Initialisation handlers. */
122 int (*init)(DSO *dso);
123 int (*finish)(DSO *dso);
124 } DSO_METHOD;
125
126/**********************************************************************/
127/* The low-level handle type used to refer to a loaded shared library */
128
129struct dso_st
130 {
131 DSO_METHOD *meth;
132 /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS
133 * doesn't use anything but will need to cache the filename
134 * for use in the dso_bind handler. All in all, let each
135 * method control its own destiny. "Handles" and such go in
136 * a STACK. */
137 STACK *meth_data;
138 int references;
139 int flags;
140 /* For use by applications etc ... use this for your bits'n'pieces,
141 * don't touch meth_data! */
142 CRYPTO_EX_DATA ex_data;
143 };
144
145
146DSO * DSO_new(void);
147DSO * DSO_new_method(DSO_METHOD *method);
148int DSO_free(DSO *dso);
149int DSO_flags(DSO *dso);
150int DSO_up(DSO *dso);
151long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);
152
153void DSO_set_default_method(DSO_METHOD *meth);
154DSO_METHOD *DSO_get_default_method(void);
155DSO_METHOD *DSO_get_method(DSO *dso);
156DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);
157
158/* The all-singing all-dancing load function, you normally pass NULL
159 * for the first and third parameters. Use DSO_up and DSO_free for
160 * subsequent reference count handling. Any flags passed in will be set
161 * in the constructed DSO after its init() function but before the
162 * load operation. This will be done with;
163 * DSO_ctrl(dso, DSO_CTRL_SET_FLAGS, flags, NULL); */
164DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);
165
166/* This function binds to a variable inside a shared library. */
167void *DSO_bind_var(DSO *dso, const char *symname);
168
169/* This function binds to a function inside a shared library. */
170DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname);
171
172/* This method is the default, but will beg, borrow, or steal whatever
173 * method should be the default on any particular platform (including
174 * DSO_METH_null() if necessary). */
175DSO_METHOD *DSO_METHOD_openssl(void);
176
177/* This method is defined for all platforms - if a platform has no
178 * DSO support then this will be the only method! */
179DSO_METHOD *DSO_METHOD_null(void);
180
181/* If DSO_DLFCN is defined, the standard dlfcn.h-style functions
182 * (dlopen, dlclose, dlsym, etc) will be used and incorporated into
183 * this method. If not, this method will return NULL. */
184DSO_METHOD *DSO_METHOD_dlfcn(void);
185
186/* If DSO_DL is defined, the standard dl.h-style functions (shl_load,
187 * shl_unload, shl_findsym, etc) will be used and incorporated into
188 * this method. If not, this method will return NULL. */
189DSO_METHOD *DSO_METHOD_dl(void);
190
191/* If WIN32 is defined, use DLLs. If not, return NULL. */
192DSO_METHOD *DSO_METHOD_win32(void);
193
194/* If VMS is defined, use shared images. If not, return NULL. */
195DSO_METHOD *DSO_METHOD_vms(void);
196
197void ERR_load_DSO_strings(void);
198
199/* BEGIN ERROR CODES */
200/* The following lines are auto generated by the script mkerr.pl. Any changes
201 * made after this point may be overwritten when the script is next run.
202 */
203
204/* Error codes for the DSO functions. */
205
206/* Function codes. */
207#define DSO_F_DLFCN_BIND_FUNC 100
208#define DSO_F_DLFCN_BIND_VAR 101
209#define DSO_F_DLFCN_CTRL 102
210#define DSO_F_DLFCN_LOAD 103
211#define DSO_F_DLFCN_UNLOAD 104
212#define DSO_F_DL_BIND_FUNC 105
213#define DSO_F_DL_BIND_VAR 106
214#define DSO_F_DL_CTRL 107
215#define DSO_F_DL_LOAD 108
216#define DSO_F_DL_UNLOAD 109
217#define DSO_F_DSO_BIND_FUNC 110
218#define DSO_F_DSO_BIND_VAR 111
219#define DSO_F_DSO_CTRL 112
220#define DSO_F_DSO_FREE 113
221#define DSO_F_DSO_LOAD 114
222#define DSO_F_DSO_NEW_METHOD 115
223#define DSO_F_DSO_UP 116
224#define DSO_F_VMS_BIND_VAR 122
225#define DSO_F_VMS_CTRL 123
226#define DSO_F_VMS_LOAD 124
227#define DSO_F_VMS_UNLOAD 125
228#define DSO_F_WIN32_BIND_FUNC 117
229#define DSO_F_WIN32_BIND_VAR 118
230#define DSO_F_WIN32_CTRL 119
231#define DSO_F_WIN32_LOAD 120
232#define DSO_F_WIN32_UNLOAD 121
233
234/* Reason codes. */
235#define DSO_R_CTRL_FAILED 100
236#define DSO_R_FILENAME_TOO_BIG 109
237#define DSO_R_FINISH_FAILED 101
238#define DSO_R_LOAD_FAILED 102
239#define DSO_R_NULL_HANDLE 103
240#define DSO_R_STACK_ERROR 104
241#define DSO_R_SYM_FAILURE 105
242#define DSO_R_UNKNOWN_COMMAND 106
243#define DSO_R_UNLOAD_FAILED 107
244#define DSO_R_UNSUPPORTED 108
245
246#ifdef __cplusplus
247}
248#endif
249#endif
250
diff --git a/src/lib/libssl/src/crypto/dso/dso_dl.c b/src/lib/libssl/src/crypto/dso/dso_dl.c
new file mode 100644
index 0000000000..69810fc3bb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_dl.c
@@ -0,0 +1,251 @@
1/* dso_dl.c */
2/* Written by Richard Levitte (levitte@openssl.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63#ifndef DSO_DL
64DSO_METHOD *DSO_METHOD_dl(void)
65 {
66 return NULL;
67 }
68#else
69
70#include <dl.h>
71
72/* Part of the hack in "dl_load" ... */
73#define DSO_MAX_TRANSLATED_SIZE 256
74
75static int dl_load(DSO *dso, const char *filename);
76static int dl_unload(DSO *dso);
77static void *dl_bind_var(DSO *dso, const char *symname);
78static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname);
79#if 0
80static int dl_unbind_var(DSO *dso, char *symname, void *symptr);
81static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
82static int dl_init(DSO *dso);
83static int dl_finish(DSO *dso);
84#endif
85static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
86
87static DSO_METHOD dso_meth_dl = {
88 "OpenSSL 'dl' shared library method",
89 dl_load,
90 dl_unload,
91 dl_bind_var,
92 dl_bind_func,
93/* For now, "unbind" doesn't exist */
94#if 0
95 NULL, /* unbind_var */
96 NULL, /* unbind_func */
97#endif
98 dl_ctrl,
99 NULL, /* init */
100 NULL /* finish */
101 };
102
103DSO_METHOD *DSO_METHOD_dl(void)
104 {
105 return(&dso_meth_dl);
106 }
107
108/* For this DSO_METHOD, our meth_data STACK will contain;
109 * (i) the handle (shl_t) returned from shl_load().
110 * NB: I checked on HPUX11 and shl_t is itself a pointer
111 * type so the cast is safe.
112 */
113
114static int dl_load(DSO *dso, const char *filename)
115 {
116 shl_t ptr;
117 char translated[DSO_MAX_TRANSLATED_SIZE];
118 int len;
119
120 /* The same comment as in dlfcn_load applies here. bleurgh. */
121 len = strlen(filename);
122 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
123 (len + 6 < DSO_MAX_TRANSLATED_SIZE) &&
124 (strstr(filename, "/") == NULL))
125 {
126 sprintf(translated, "lib%s.so", filename);
127 ptr = shl_load(translated, BIND_IMMEDIATE, NULL);
128 }
129 else
130 ptr = shl_load(filename, BIND_IMMEDIATE, NULL);
131 if(ptr == NULL)
132 {
133 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
134 return(0);
135 }
136 if(!sk_push(dso->meth_data, (char *)ptr))
137 {
138 DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR);
139 shl_unload(ptr);
140 return(0);
141 }
142 return(1);
143 }
144
145static int dl_unload(DSO *dso)
146 {
147 shl_t ptr;
148 if(dso == NULL)
149 {
150 DSOerr(DSO_F_DL_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
151 return(0);
152 }
153 if(sk_num(dso->meth_data) < 1)
154 return(1);
155 /* Is this statement legal? */
156 ptr = (shl_t)sk_pop(dso->meth_data);
157 if(ptr == NULL)
158 {
159 DSOerr(DSO_F_DL_UNLOAD,DSO_R_NULL_HANDLE);
160 /* Should push the value back onto the stack in
161 * case of a retry. */
162 sk_push(dso->meth_data, (char *)ptr);
163 return(0);
164 }
165 shl_unload(ptr);
166 return(1);
167 }
168
169static void *dl_bind_var(DSO *dso, const char *symname)
170 {
171 shl_t ptr;
172 void *sym;
173
174 if((dso == NULL) || (symname == NULL))
175 {
176 DSOerr(DSO_F_DL_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
177 return(NULL);
178 }
179 if(sk_num(dso->meth_data) < 1)
180 {
181 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_STACK_ERROR);
182 return(NULL);
183 }
184 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
185 if(ptr == NULL)
186 {
187 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_NULL_HANDLE);
188 return(NULL);
189 }
190 if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0)
191 {
192 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE);
193 return(NULL);
194 }
195 return(sym);
196 }
197
198static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
199 {
200 shl_t ptr;
201 void *sym;
202
203 if((dso == NULL) || (symname == NULL))
204 {
205 DSOerr(DSO_F_DL_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
206 return(NULL);
207 }
208 if(sk_num(dso->meth_data) < 1)
209 {
210 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_STACK_ERROR);
211 return(NULL);
212 }
213 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
214 if(ptr == NULL)
215 {
216 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_NULL_HANDLE);
217 return(NULL);
218 }
219 if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0)
220 {
221 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE);
222 return(NULL);
223 }
224 return((DSO_FUNC_TYPE)sym);
225 }
226
227static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg)
228 {
229 if(dso == NULL)
230 {
231 DSOerr(DSO_F_DL_CTRL,ERR_R_PASSED_NULL_PARAMETER);
232 return(-1);
233 }
234 switch(cmd)
235 {
236 case DSO_CTRL_GET_FLAGS:
237 return dso->flags;
238 case DSO_CTRL_SET_FLAGS:
239 dso->flags = (int)larg;
240 return(0);
241 case DSO_CTRL_OR_FLAGS:
242 dso->flags |= (int)larg;
243 return(0);
244 default:
245 break;
246 }
247 DSOerr(DSO_F_DL_CTRL,DSO_R_UNKNOWN_COMMAND);
248 return(-1);
249 }
250
251#endif /* DSO_DL */
diff --git a/src/lib/libssl/src/crypto/dso/dso_dlfcn.c b/src/lib/libssl/src/crypto/dso/dso_dlfcn.c
new file mode 100644
index 0000000000..e709c721cc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_dlfcn.c
@@ -0,0 +1,276 @@
1/* dso_dlfcn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63#ifndef DSO_DLFCN
64DSO_METHOD *DSO_METHOD_dlfcn(void)
65 {
66 return NULL;
67 }
68#else
69
70#ifdef HAVE_DLFCN_H
71#include <dlfcn.h>
72#endif
73
74/* Part of the hack in "dlfcn_load" ... */
75#define DSO_MAX_TRANSLATED_SIZE 256
76
77static int dlfcn_load(DSO *dso, const char *filename);
78static int dlfcn_unload(DSO *dso);
79static void *dlfcn_bind_var(DSO *dso, const char *symname);
80static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname);
81#if 0
82static int dlfcn_unbind(DSO *dso, char *symname, void *symptr);
83static int dlfcn_init(DSO *dso);
84static int dlfcn_finish(DSO *dso);
85#endif
86static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
87
88static DSO_METHOD dso_meth_dlfcn = {
89 "OpenSSL 'dlfcn' shared library method",
90 dlfcn_load,
91 dlfcn_unload,
92 dlfcn_bind_var,
93 dlfcn_bind_func,
94/* For now, "unbind" doesn't exist */
95#if 0
96 NULL, /* unbind_var */
97 NULL, /* unbind_func */
98#endif
99 dlfcn_ctrl,
100 NULL, /* init */
101 NULL /* finish */
102 };
103
104DSO_METHOD *DSO_METHOD_dlfcn(void)
105 {
106 return(&dso_meth_dlfcn);
107 }
108
109/* Prior to using the dlopen() function, we should decide on the flag
110 * we send. There's a few different ways of doing this and it's a
111 * messy venn-diagram to match up which platforms support what. So
112 * as we don't have autoconf yet, I'm implementing a hack that could
113 * be hacked further relatively easily to deal with cases as we find
114 * them. Initially this is to cope with OpenBSD. */
115#ifdef __OpenBSD__
116# ifdef DL_LAZY
117# define DLOPEN_FLAG DL_LAZY
118# else
119# ifdef RTLD_NOW
120# define DLOPEN_FLAG RTLD_NOW
121# else
122# define DLOPEN_FLAG 0
123# endif
124# endif
125#else
126# define DLOPEN_FLAG RTLD_NOW /* Hope this works everywhere else */
127#endif
128
129/* For this DSO_METHOD, our meth_data STACK will contain;
130 * (i) the handle (void*) returned from dlopen().
131 */
132
133static int dlfcn_load(DSO *dso, const char *filename)
134 {
135 void *ptr;
136 char translated[DSO_MAX_TRANSLATED_SIZE];
137 int len;
138
139 /* NB: This is a hideous hack, but I'm not yet sure what
140 * to replace it with. This attempts to convert any filename,
141 * that looks like it has no path information, into a
142 * translated form, e. "blah" -> "libblah.so" */
143 len = strlen(filename);
144 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
145 (len + 6 < DSO_MAX_TRANSLATED_SIZE) &&
146 (strstr(filename, "/") == NULL))
147 {
148 sprintf(translated, "lib%s.so", filename);
149 ptr = dlopen(translated, DLOPEN_FLAG);
150 }
151 else
152 {
153 ptr = dlopen(filename, DLOPEN_FLAG);
154 }
155 if(ptr == NULL)
156 {
157 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED);
158 return(0);
159 }
160 if(!sk_push(dso->meth_data, (char *)ptr))
161 {
162 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR);
163 dlclose(ptr);
164 return(0);
165 }
166 return(1);
167 }
168
169static int dlfcn_unload(DSO *dso)
170 {
171 void *ptr;
172 if(dso == NULL)
173 {
174 DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
175 return(0);
176 }
177 if(sk_num(dso->meth_data) < 1)
178 return(1);
179 ptr = (void *)sk_pop(dso->meth_data);
180 if(ptr == NULL)
181 {
182 DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE);
183 /* Should push the value back onto the stack in
184 * case of a retry. */
185 sk_push(dso->meth_data, (char *)ptr);
186 return(0);
187 }
188 /* For now I'm not aware of any errors associated with dlclose() */
189 dlclose(ptr);
190 return(1);
191 }
192
193static void *dlfcn_bind_var(DSO *dso, const char *symname)
194 {
195 void *ptr, *sym;
196
197 if((dso == NULL) || (symname == NULL))
198 {
199 DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
200 return(NULL);
201 }
202 if(sk_num(dso->meth_data) < 1)
203 {
204 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR);
205 return(NULL);
206 }
207 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
208 if(ptr == NULL)
209 {
210 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE);
211 return(NULL);
212 }
213 sym = dlsym(ptr, symname);
214 if(sym == NULL)
215 {
216 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE);
217 return(NULL);
218 }
219 return(sym);
220 }
221
222static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
223 {
224 void *ptr;
225 DSO_FUNC_TYPE sym;
226
227 if((dso == NULL) || (symname == NULL))
228 {
229 DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
230 return(NULL);
231 }
232 if(sk_num(dso->meth_data) < 1)
233 {
234 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR);
235 return(NULL);
236 }
237 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
238 if(ptr == NULL)
239 {
240 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE);
241 return(NULL);
242 }
243 sym = (DSO_FUNC_TYPE)dlsym(ptr, symname);
244 if(sym == NULL)
245 {
246 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE);
247 return(NULL);
248 }
249 return(sym);
250 }
251
252static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg)
253 {
254 if(dso == NULL)
255 {
256 DSOerr(DSO_F_DLFCN_CTRL,ERR_R_PASSED_NULL_PARAMETER);
257 return(-1);
258 }
259 switch(cmd)
260 {
261 case DSO_CTRL_GET_FLAGS:
262 return dso->flags;
263 case DSO_CTRL_SET_FLAGS:
264 dso->flags = (int)larg;
265 return(0);
266 case DSO_CTRL_OR_FLAGS:
267 dso->flags |= (int)larg;
268 return(0);
269 default:
270 break;
271 }
272 DSOerr(DSO_F_DLFCN_CTRL,DSO_R_UNKNOWN_COMMAND);
273 return(-1);
274 }
275
276#endif /* DSO_DLFCN */
diff --git a/src/lib/libssl/src/crypto/dso/dso_err.c b/src/lib/libssl/src/crypto/dso/dso_err.c
new file mode 100644
index 0000000000..a3d7321c9b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_err.c
@@ -0,0 +1,128 @@
1/* crypto/dso/dso_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dso.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA DSO_str_functs[]=
68 {
69{ERR_PACK(0,DSO_F_DLFCN_BIND_FUNC,0), "DLFCN_BIND_FUNC"},
70{ERR_PACK(0,DSO_F_DLFCN_BIND_VAR,0), "DLFCN_BIND_VAR"},
71{ERR_PACK(0,DSO_F_DLFCN_CTRL,0), "DLFCN_CTRL"},
72{ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"},
73{ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"},
74{ERR_PACK(0,DSO_F_DL_BIND_FUNC,0), "DL_BIND_FUNC"},
75{ERR_PACK(0,DSO_F_DL_BIND_VAR,0), "DL_BIND_VAR"},
76{ERR_PACK(0,DSO_F_DL_CTRL,0), "DL_CTRL"},
77{ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"},
78{ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"},
79{ERR_PACK(0,DSO_F_DSO_BIND_FUNC,0), "DSO_bind_func"},
80{ERR_PACK(0,DSO_F_DSO_BIND_VAR,0), "DSO_bind_var"},
81{ERR_PACK(0,DSO_F_DSO_CTRL,0), "DSO_ctrl"},
82{ERR_PACK(0,DSO_F_DSO_FREE,0), "DSO_free"},
83{ERR_PACK(0,DSO_F_DSO_LOAD,0), "DSO_load"},
84{ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"},
85{ERR_PACK(0,DSO_F_DSO_UP,0), "DSO_up"},
86{ERR_PACK(0,DSO_F_VMS_BIND_VAR,0), "VMS_BIND_VAR"},
87{ERR_PACK(0,DSO_F_VMS_CTRL,0), "VMS_CTRL"},
88{ERR_PACK(0,DSO_F_VMS_LOAD,0), "VMS_LOAD"},
89{ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"},
90{ERR_PACK(0,DSO_F_WIN32_BIND_FUNC,0), "WIN32_BIND_FUNC"},
91{ERR_PACK(0,DSO_F_WIN32_BIND_VAR,0), "WIN32_BIND_VAR"},
92{ERR_PACK(0,DSO_F_WIN32_CTRL,0), "WIN32_CTRL"},
93{ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"},
94{ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"},
95{0,NULL}
96 };
97
98static ERR_STRING_DATA DSO_str_reasons[]=
99 {
100{DSO_R_CTRL_FAILED ,"control command failed"},
101{DSO_R_FILENAME_TOO_BIG ,"filename too big"},
102{DSO_R_FINISH_FAILED ,"cleanup method function failed"},
103{DSO_R_LOAD_FAILED ,"could not load the shared library"},
104{DSO_R_NULL_HANDLE ,"a null shared library handle was used"},
105{DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"},
106{DSO_R_SYM_FAILURE ,"could not bind to the requested symbol name"},
107{DSO_R_UNKNOWN_COMMAND ,"unknown control command"},
108{DSO_R_UNLOAD_FAILED ,"could not unload the shared library"},
109{DSO_R_UNSUPPORTED ,"functionality not supported"},
110{0,NULL}
111 };
112
113#endif
114
115void ERR_load_DSO_strings(void)
116 {
117 static int init=1;
118
119 if (init)
120 {
121 init=0;
122#ifndef NO_ERR
123 ERR_load_strings(ERR_LIB_DSO,DSO_str_functs);
124 ERR_load_strings(ERR_LIB_DSO,DSO_str_reasons);
125#endif
126
127 }
128 }
diff --git a/src/lib/libssl/src/crypto/dso/dso_lib.c b/src/lib/libssl/src/crypto/dso/dso_lib.c
new file mode 100644
index 0000000000..acd166697e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_lib.c
@@ -0,0 +1,306 @@
1/* dso_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64static DSO_METHOD *default_DSO_meth = NULL;
65
66DSO *DSO_new(void)
67 {
68 return(DSO_new_method(NULL));
69 }
70
71void DSO_set_default_method(DSO_METHOD *meth)
72 {
73 default_DSO_meth = meth;
74 }
75
76DSO_METHOD *DSO_get_default_method(void)
77 {
78 return(default_DSO_meth);
79 }
80
81DSO_METHOD *DSO_get_method(DSO *dso)
82 {
83 return(dso->meth);
84 }
85
86DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth)
87 {
88 DSO_METHOD *mtmp;
89 mtmp = dso->meth;
90 dso->meth = meth;
91 return(mtmp);
92 }
93
94DSO *DSO_new_method(DSO_METHOD *meth)
95 {
96 DSO *ret;
97
98 if(default_DSO_meth == NULL)
99 /* We default to DSO_METH_openssl() which in turn defaults
100 * to stealing the "best available" method. Will fallback
101 * to DSO_METH_null() in the worst case. */
102 default_DSO_meth = DSO_METHOD_openssl();
103 ret = (DSO *)OPENSSL_malloc(sizeof(DSO));
104 if(ret == NULL)
105 {
106 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
107 return(NULL);
108 }
109 memset(ret, 0, sizeof(DSO));
110 ret->meth_data = sk_new_null();
111 if((ret->meth_data = sk_new_null()) == NULL)
112 {
113 /* sk_new doesn't generate any errors so we do */
114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 OPENSSL_free(ret);
116 return(NULL);
117 }
118 if(meth == NULL)
119 ret->meth = default_DSO_meth;
120 else
121 ret->meth = meth;
122 ret->references = 1;
123 if((ret->meth->init != NULL) && !ret->meth->init(ret))
124 {
125 OPENSSL_free(ret);
126 ret=NULL;
127 }
128 return(ret);
129 }
130
131int DSO_free(DSO *dso)
132 {
133 int i;
134
135 if(dso == NULL)
136 {
137 DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER);
138 return(0);
139 }
140
141 i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO);
142#ifdef REF_PRINT
143 REF_PRINT("DSO",dso);
144#endif
145 if(i > 0) return(1);
146#ifdef REF_CHECK
147 if(i < 0)
148 {
149 fprintf(stderr,"DSO_free, bad reference count\n");
150 abort();
151 }
152#endif
153
154 if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso))
155 {
156 DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED);
157 return(0);
158 }
159
160 if((dso->meth->finish != NULL) && !dso->meth->finish(dso))
161 {
162 DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED);
163 return(0);
164 }
165
166 sk_free(dso->meth_data);
167
168 OPENSSL_free(dso);
169 return(1);
170 }
171
172int DSO_flags(DSO *dso)
173 {
174 return((dso == NULL) ? 0 : dso->flags);
175 }
176
177
178int DSO_up(DSO *dso)
179 {
180 if (dso == NULL)
181 {
182 DSOerr(DSO_F_DSO_UP,ERR_R_PASSED_NULL_PARAMETER);
183 return(0);
184 }
185
186 CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO);
187 return(1);
188 }
189
190DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
191 {
192 DSO *ret;
193 int allocated = 0;
194
195 if(filename == NULL)
196 {
197 DSOerr(DSO_F_DSO_LOAD,ERR_R_PASSED_NULL_PARAMETER);
198 return(NULL);
199 }
200 if(dso == NULL)
201 {
202 ret = DSO_new_method(meth);
203 if(ret == NULL)
204 {
205 DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
206 return(NULL);
207 }
208 allocated = 1;
209 }
210 else
211 ret = dso;
212 /* Bleurgh ... have to check for negative return values for
213 * errors. <grimace> */
214 if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
215 {
216 DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
217 if(allocated)
218 DSO_free(ret);
219 return(NULL);
220 }
221 if(ret->meth->dso_load == NULL)
222 {
223 DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
224 if(allocated)
225 DSO_free(ret);
226 return(NULL);
227 }
228 if(!ret->meth->dso_load(ret, filename))
229 {
230 DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
231 if(allocated)
232 DSO_free(ret);
233 return(NULL);
234 }
235 /* Load succeeded */
236 return(ret);
237 }
238
239void *DSO_bind_var(DSO *dso, const char *symname)
240 {
241 void *ret = NULL;
242
243 if((dso == NULL) || (symname == NULL))
244 {
245 DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
246 return(NULL);
247 }
248 if(dso->meth->dso_bind_var == NULL)
249 {
250 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED);
251 return(NULL);
252 }
253 if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL)
254 {
255 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE);
256 return(NULL);
257 }
258 /* Success */
259 return(ret);
260 }
261
262DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
263 {
264 DSO_FUNC_TYPE ret = NULL;
265
266 if((dso == NULL) || (symname == NULL))
267 {
268 DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
269 return(NULL);
270 }
271 if(dso->meth->dso_bind_func == NULL)
272 {
273 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED);
274 return(NULL);
275 }
276 if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL)
277 {
278 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE);
279 return(NULL);
280 }
281 /* Success */
282 return(ret);
283 }
284
285/* I don't really like these *_ctrl functions very much to be perfectly
286 * honest. For one thing, I think I have to return a negative value for
287 * any error because possible DSO_ctrl() commands may return values
288 * such as "size"s that can legitimately be zero (making the standard
289 * "if(DSO_cmd(...))" form that works almost everywhere else fail at
290 * odd times. I'd prefer "output" values to be passed by reference and
291 * the return value as success/failure like usual ... but we conform
292 * when we must... :-) */
293long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
294 {
295 if(dso == NULL)
296 {
297 DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
298 return(-1);
299 }
300 if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
301 {
302 DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
303 return(-1);
304 }
305 return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
306 }
diff --git a/src/lib/libssl/src/crypto/dso/dso_null.c b/src/lib/libssl/src/crypto/dso/dso_null.c
new file mode 100644
index 0000000000..fa13a7cb0f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_null.c
@@ -0,0 +1,86 @@
1/* dso_null.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* This "NULL" method is provided as the fallback for systems that have
60 * no appropriate support for "shared-libraries". */
61
62#include <stdio.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65
66static DSO_METHOD dso_meth_null = {
67 "NULL shared library method",
68 NULL, /* load */
69 NULL, /* unload */
70 NULL, /* bind_var */
71 NULL, /* bind_func */
72/* For now, "unbind" doesn't exist */
73#if 0
74 NULL, /* unbind_var */
75 NULL, /* unbind_func */
76#endif
77 NULL, /* ctrl */
78 NULL, /* init */
79 NULL /* finish */
80 };
81
82DSO_METHOD *DSO_METHOD_null(void)
83 {
84 return(&dso_meth_null);
85 }
86
diff --git a/src/lib/libssl/src/crypto/dso/dso_openssl.c b/src/lib/libssl/src/crypto/dso/dso_openssl.c
new file mode 100644
index 0000000000..a4395ebffe
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_openssl.c
@@ -0,0 +1,81 @@
1/* dso_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63/* We just pinch the method from an appropriate "default" method. */
64
65DSO_METHOD *DSO_METHOD_openssl(void)
66 {
67#ifdef DEF_DSO_METHOD
68 return(DEF_DSO_METHOD());
69#elif defined(DSO_DLFCN)
70 return(DSO_METHOD_dlfcn());
71#elif defined(DSO_DL)
72 return(DSO_METHOD_dl());
73#elif defined(DSO_WIN32)
74 return(DSO_METHOD_win32());
75#elif defined(DSO_VMS)
76 return(DSO_METHOD_vms());
77#else
78 return(DSO_METHOD_null());
79#endif
80 }
81
diff --git a/src/lib/libssl/src/crypto/dso/dso_vms.c b/src/lib/libssl/src/crypto/dso/dso_vms.c
new file mode 100644
index 0000000000..8ff7090129
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_vms.c
@@ -0,0 +1,371 @@
1/* dso_vms.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <errno.h>
62#ifdef VMS
63#pragma message disable DOLLARID
64#include <lib$routines.h>
65#include <libfisdef.h>
66#include <stsdef.h>
67#include <descrip.h>
68#include <starlet.h>
69#endif
70#include "cryptlib.h"
71#include <openssl/dso.h>
72
73#ifndef VMS
74DSO_METHOD *DSO_METHOD_vms(void)
75 {
76 return NULL;
77 }
78#else
79#pragma message disable DOLLARID
80
81static int vms_load(DSO *dso, const char *filename);
82static int vms_unload(DSO *dso);
83static void *vms_bind_var(DSO *dso, const char *symname);
84static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
85#if 0
86static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
87static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
88static int vms_init(DSO *dso);
89static int vms_finish(DSO *dso);
90#endif
91static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
92
93static DSO_METHOD dso_meth_vms = {
94 "OpenSSL 'VMS' shared library method",
95 vms_load,
96 NULL, /* unload */
97 vms_bind_var,
98 vms_bind_func,
99/* For now, "unbind" doesn't exist */
100#if 0
101 NULL, /* unbind_var */
102 NULL, /* unbind_func */
103#endif
104 vms_ctrl,
105 NULL, /* init */
106 NULL /* finish */
107 };
108
109/* On VMS, the only "handle" is the file name. LIB$FIND_IMAGE_SYMBOL depends
110 * on the reference to the file name being the same for all calls regarding
111 * one shared image, so we'll just store it in an instance of the following
112 * structure and put a pointer to that instance in the meth_data stack.
113 */
114typedef struct dso_internal_st
115 {
116 /* This should contain the name only, no directory,
117 * no extension, nothing but a name. */
118 struct dsc$descriptor_s filename_dsc;
119 char filename[FILENAME_MAX+1];
120 /* This contains whatever is not in filename, if needed.
121 * Normally not defined. */
122 struct dsc$descriptor_s imagename_dsc;
123 char imagename[FILENAME_MAX+1];
124 } DSO_VMS_INTERNAL;
125
126
127DSO_METHOD *DSO_METHOD_vms(void)
128 {
129 return(&dso_meth_vms);
130 }
131
132static int vms_load(DSO *dso, const char *filename)
133 {
134 DSO_VMS_INTERNAL *p;
135 const char *sp1, *sp2; /* Search result */
136
137 /* A file specification may look like this:
138 *
139 * node::dev:[dir-spec]name.type;ver
140 *
141 * or (for compatibility with TOPS-20):
142 *
143 * node::dev:<dir-spec>name.type;ver
144 *
145 * and the dir-spec uses '.' as separator. Also, a dir-spec
146 * may consist of several parts, with mixed use of [] and <>:
147 *
148 * [dir1.]<dir2>
149 *
150 * We need to split the file specification into the name and
151 * the rest (both before and after the name itself).
152 */
153 /* Start with trying to find the end of a dir-spec, and save the
154 position of the byte after in sp1 */
155 sp1 = strrchr(filename, ']');
156 sp2 = strrchr(filename, '>');
157 if (sp1 == NULL) sp1 = sp2;
158 if (sp2 != NULL && sp2 > sp1) sp1 = sp2;
159 if (sp1 == NULL) sp1 = strrchr(filename, ':');
160 if (sp1 == NULL)
161 sp1 = filename;
162 else
163 sp1++; /* The byte after the found character */
164 /* Now, let's see if there's a type, and save the position in sp2 */
165 sp2 = strchr(sp1, '.');
166 /* If we found it, that's where we'll cut. Otherwise, look for a
167 version number and save the position in sp2 */
168 if (sp2 == NULL) sp2 = strchr(sp1, ';');
169 /* If there was still nothing to find, set sp2 to point at the end of
170 the string */
171 if (sp2 == NULL) sp2 = sp1 + strlen(sp1);
172
173 /* Check that we won't get buffer overflows */
174 if (sp2 - sp1 > FILENAME_MAX
175 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
176 {
177 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
178 return(0);
179 }
180
181 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
182 if(p == NULL)
183 {
184 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
185 return(0);
186 }
187
188 strncpy(p->filename, sp1, sp2-sp1);
189 p->filename[sp2-sp1] = '\0';
190
191 strncpy(p->imagename, filename, sp1-filename);
192 p->imagename[sp1-filename] = '\0';
193 strcat(p->imagename, sp2);
194
195 p->filename_dsc.dsc$w_length = strlen(p->filename);
196 p->filename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
197 p->filename_dsc.dsc$b_class = DSC$K_CLASS_S;
198 p->filename_dsc.dsc$a_pointer = p->filename;
199 p->imagename_dsc.dsc$w_length = strlen(p->imagename);
200 p->imagename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
201 p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
202 p->imagename_dsc.dsc$a_pointer = p->imagename;
203
204 if(!sk_push(dso->meth_data, (char *)p))
205 {
206 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
207 OPENSSL_free(p);
208 return(0);
209 }
210 return(1);
211 }
212
213/* Note that this doesn't actually unload the shared image, as there is no
214 * such thing in VMS. Next time it get loaded again, a new copy will
215 * actually be loaded.
216 */
217static int vms_unload(DSO *dso)
218 {
219 DSO_VMS_INTERNAL *p;
220 if(dso == NULL)
221 {
222 DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
223 return(0);
224 }
225 if(sk_num(dso->meth_data) < 1)
226 return(1);
227 p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
228 if(p == NULL)
229 {
230 DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
231 return(0);
232 }
233 /* Cleanup */
234 OPENSSL_free(p);
235 return(1);
236 }
237
238/* We must do this in a separate function because of the way the exception
239 handler works (it makes this function return */
240static int do_find_symbol(DSO_VMS_INTERNAL *ptr,
241 struct dsc$descriptor_s *symname_dsc, void **sym,
242 unsigned long flags)
243 {
244 /* Make sure that signals are caught and returned instead of
245 aborting the program. The exception handler gets unestablished
246 automatically on return from this function. */
247 lib$establish(lib$sig_to_ret);
248
249 if(ptr->imagename_dsc.dsc$w_length)
250 return lib$find_image_symbol(&ptr->filename_dsc,
251 symname_dsc, sym,
252 &ptr->imagename_dsc, flags);
253 else
254 return lib$find_image_symbol(&ptr->filename_dsc,
255 symname_dsc, sym,
256 0, flags);
257 }
258
259void vms_bind_sym(DSO *dso, const char *symname, void **sym)
260 {
261 DSO_VMS_INTERNAL *ptr;
262 int status;
263 int flags = LIB$M_FIS_MIXEDCASE;
264 struct dsc$descriptor_s symname_dsc;
265 *sym = NULL;
266
267 symname_dsc.dsc$w_length = strlen(symname);
268 symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
269 symname_dsc.dsc$b_class = DSC$K_CLASS_S;
270 symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */
271
272 if((dso == NULL) || (symname == NULL))
273 {
274 DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
275 return;
276 }
277 if(sk_num(dso->meth_data) < 1)
278 {
279 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
280 return;
281 }
282 ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
283 sk_num(dso->meth_data) - 1);
284 if(ptr == NULL)
285 {
286 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
287 return;
288 }
289
290 if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
291
292 status = do_find_symbol(ptr, &symname_dsc, sym, flags);
293
294 if(!$VMS_STATUS_SUCCESS(status))
295 {
296 unsigned short length;
297 char errstring[257];
298 struct dsc$descriptor_s errstring_dsc;
299
300 errstring_dsc.dsc$w_length = sizeof(errstring);
301 errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
302 errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
303 errstring_dsc.dsc$a_pointer = errstring;
304
305 *sym = NULL;
306
307 status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
308
309 if (!$VMS_STATUS_SUCCESS(status))
310 lib$signal(status); /* This is really bad. Abort! */
311 else
312 {
313 errstring[length] = '\0';
314
315 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE);
316 if (ptr->imagename_dsc.dsc$w_length)
317 ERR_add_error_data(9,
318 "Symbol ", symname,
319 " in ", ptr->filename,
320 " (", ptr->imagename, ")",
321 ": ", errstring);
322 else
323 ERR_add_error_data(6,
324 "Symbol ", symname,
325 " in ", ptr->filename,
326 ": ", errstring);
327 }
328 return;
329 }
330 return;
331 }
332
333static void *vms_bind_var(DSO *dso, const char *symname)
334 {
335 void *sym = 0;
336 vms_bind_sym(dso, symname, &sym);
337 return sym;
338 }
339
340static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
341 {
342 DSO_FUNC_TYPE sym = 0;
343 vms_bind_sym(dso, symname, (void **)&sym);
344 return sym;
345 }
346
347static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg)
348 {
349 if(dso == NULL)
350 {
351 DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER);
352 return(-1);
353 }
354 switch(cmd)
355 {
356 case DSO_CTRL_GET_FLAGS:
357 return dso->flags;
358 case DSO_CTRL_SET_FLAGS:
359 dso->flags = (int)larg;
360 return(0);
361 case DSO_CTRL_OR_FLAGS:
362 dso->flags |= (int)larg;
363 return(0);
364 default:
365 break;
366 }
367 DSOerr(DSO_F_VMS_CTRL,DSO_R_UNKNOWN_COMMAND);
368 return(-1);
369 }
370
371#endif /* VMS */
diff --git a/src/lib/libssl/src/crypto/dso/dso_win32.c b/src/lib/libssl/src/crypto/dso/dso_win32.c
new file mode 100644
index 0000000000..7f1d904806
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dso/dso_win32.c
@@ -0,0 +1,273 @@
1/* dso_win32.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64#ifndef WIN32
65DSO_METHOD *DSO_METHOD_win32(void)
66 {
67 return NULL;
68 }
69#else
70
71/* Part of the hack in "win32_load" ... */
72#define DSO_MAX_TRANSLATED_SIZE 256
73
74static int win32_load(DSO *dso, const char *filename);
75static int win32_unload(DSO *dso);
76static void *win32_bind_var(DSO *dso, const char *symname);
77static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
78#if 0
79static int win32_unbind_var(DSO *dso, char *symname, void *symptr);
80static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
81static int win32_init(DSO *dso);
82static int win32_finish(DSO *dso);
83#endif
84static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
85
86static DSO_METHOD dso_meth_win32 = {
87 "OpenSSL 'win32' shared library method",
88 win32_load,
89 win32_unload,
90 win32_bind_var,
91 win32_bind_func,
92/* For now, "unbind" doesn't exist */
93#if 0
94 NULL, /* unbind_var */
95 NULL, /* unbind_func */
96#endif
97 win32_ctrl,
98 NULL, /* init */
99 NULL /* finish */
100 };
101
102DSO_METHOD *DSO_METHOD_win32(void)
103 {
104 return(&dso_meth_win32);
105 }
106
107/* For this DSO_METHOD, our meth_data STACK will contain;
108 * (i) a pointer to the handle (HINSTANCE) returned from
109 * LoadLibrary(), and copied.
110 */
111
112static int win32_load(DSO *dso, const char *filename)
113 {
114 HINSTANCE h, *p;
115 char translated[DSO_MAX_TRANSLATED_SIZE];
116 int len;
117
118 /* NB: This is a hideous hack, but I'm not yet sure what
119 * to replace it with. This attempts to convert any filename,
120 * that looks like it has no path information, into a
121 * translated form, e. "blah" -> "blah.dll" ... I'm more
122 * comfortable putting hacks into win32 code though ;-) */
123 len = strlen(filename);
124 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
125 (len + 4 < DSO_MAX_TRANSLATED_SIZE) &&
126 (strstr(filename, "/") == NULL) &&
127 (strstr(filename, "\\") == NULL) &&
128 (strstr(filename, ":") == NULL))
129 {
130 sprintf(translated, "%s.dll", filename);
131 h = LoadLibrary(translated);
132 }
133 else
134 h = LoadLibrary(filename);
135 if(h == NULL)
136 {
137 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
138 return(0);
139 }
140 p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE));
141 if(p == NULL)
142 {
143 DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE);
144 FreeLibrary(h);
145 return(0);
146 }
147 *p = h;
148 if(!sk_push(dso->meth_data, (char *)p))
149 {
150 DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
151 FreeLibrary(h);
152 OPENSSL_free(p);
153 return(0);
154 }
155 return(1);
156 }
157
158static int win32_unload(DSO *dso)
159 {
160 HINSTANCE *p;
161 if(dso == NULL)
162 {
163 DSOerr(DSO_F_WIN32_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
164 return(0);
165 }
166 if(sk_num(dso->meth_data) < 1)
167 return(1);
168 p = (HINSTANCE *)sk_pop(dso->meth_data);
169 if(p == NULL)
170 {
171 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE);
172 return(0);
173 }
174 if(!FreeLibrary(*p))
175 {
176 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED);
177 /* We should push the value back onto the stack in
178 * case of a retry. */
179 sk_push(dso->meth_data, (char *)p);
180 return(0);
181 }
182 /* Cleanup */
183 OPENSSL_free(p);
184 return(1);
185 }
186
187/* Using GetProcAddress for variables? TODO: Check this out in
188 * the Win32 API docs, there's probably a variant for variables. */
189static void *win32_bind_var(DSO *dso, const char *symname)
190 {
191 HINSTANCE *ptr;
192 void *sym;
193
194 if((dso == NULL) || (symname == NULL))
195 {
196 DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
197 return(NULL);
198 }
199 if(sk_num(dso->meth_data) < 1)
200 {
201 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR);
202 return(NULL);
203 }
204 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
205 if(ptr == NULL)
206 {
207 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE);
208 return(NULL);
209 }
210 sym = GetProcAddress(*ptr, symname);
211 if(sym == NULL)
212 {
213 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE);
214 return(NULL);
215 }
216 return(sym);
217 }
218
219static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
220 {
221 HINSTANCE *ptr;
222 void *sym;
223
224 if((dso == NULL) || (symname == NULL))
225 {
226 DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
227 return(NULL);
228 }
229 if(sk_num(dso->meth_data) < 1)
230 {
231 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR);
232 return(NULL);
233 }
234 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
235 if(ptr == NULL)
236 {
237 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE);
238 return(NULL);
239 }
240 sym = GetProcAddress(*ptr, symname);
241 if(sym == NULL)
242 {
243 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE);
244 return(NULL);
245 }
246 return((DSO_FUNC_TYPE)sym);
247 }
248
249static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg)
250 {
251 if(dso == NULL)
252 {
253 DSOerr(DSO_F_WIN32_CTRL,ERR_R_PASSED_NULL_PARAMETER);
254 return(-1);
255 }
256 switch(cmd)
257 {
258 case DSO_CTRL_GET_FLAGS:
259 return dso->flags;
260 case DSO_CTRL_SET_FLAGS:
261 dso->flags = (int)larg;
262 return(0);
263 case DSO_CTRL_OR_FLAGS:
264 dso->flags |= (int)larg;
265 return(0);
266 default:
267 break;
268 }
269 DSOerr(DSO_F_WIN32_CTRL,DSO_R_UNKNOWN_COMMAND);
270 return(-1);
271 }
272
273#endif /* WIN32 */
diff --git a/src/lib/libssl/src/crypto/ebcdic.c b/src/lib/libssl/src/crypto/ebcdic.c
new file mode 100644
index 0000000000..31397b2add
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ebcdic.c
@@ -0,0 +1,217 @@
1/* crypto/ebcdic.c */
2
3#ifdef CHARSET_EBCDIC
4#include "ebcdic.h"
5/* Initial Port for Apache-1.3 by <Martin.Kraemer@Mch.SNI.De>
6 * Adapted for OpenSSL-0.9.4 by <Martin.Kraemer@Mch.SNI.De>
7 */
8
9#ifdef _OSD_POSIX
10/*
11 "BS2000 OSD" is a POSIX subsystem on a main frame.
12 It is made by Siemens AG, Germany, for their BS2000 mainframe machines.
13 Within the POSIX subsystem, the same character set was chosen as in
14 "native BS2000", namely EBCDIC. (EDF04)
15
16 The name "ASCII" in these routines is misleading: actually, conversion
17 is not between EBCDIC and ASCII, but EBCDIC(EDF04) and ISO-8859.1;
18 that means that (western european) national characters are preserved.
19
20 This table is identical to the one used by rsh/rcp/ftp and other POSIX tools.
21*/
22
23/* Here's the bijective ebcdic-to-ascii table: */
24const unsigned char os_toascii[256] = {
25/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
26 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
27/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
28 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
29/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
30 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
31/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
32 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
33/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
34 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
35/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
36 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
37/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
38 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
39/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
40 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
41/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
42 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
43/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
44 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
45/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
46 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
47/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
48 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
49/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
50 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
51/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
52 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
53/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
54 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
55/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
56 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
57};
58
59
60/* The ascii-to-ebcdic table: */
61const unsigned char os_toebcdic[256] = {
62/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
63 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
64/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
65 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
66/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
67 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
68/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
69 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
70/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
71 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
72/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
73 0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
74/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
75 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
76/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
77 0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
78/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,
79 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
80/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,
81 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
82/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,
83 0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
84/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,
85 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
86/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,
87 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
88/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,
89 0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
90/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,
91 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
92/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,
93 0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
94};
95
96#else /*_OSD_POSIX*/
97
98/*
99This code does basic character mapping for IBM's TPF and OS/390 operating systems.
100It is a modified version of the BS2000 table.
101
102Bijective EBCDIC (character set IBM-1047) to US-ASCII table:
103This table is bijective - there are no ambigous or duplicate characters.
104*/
105const unsigned char os_toascii[256] = {
106 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f, /* 00-0f: */
107 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
108 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97, /* 10-1f: */
109 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
110 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b, /* 20-2f: */
111 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /* ................ */
112 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30-3f: */
113 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /* ................ */
114 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, /* 40-4f: */
115 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* ...........<(+| */
116 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, /* 50-5f: */
117 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, /* &.........!$*);^ */
118 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, /* 60-6f: */
119 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /* -/.........,%_>? */
120 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, /* 70-7f: */
121 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /* .........`:#@'=" */
122 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80-8f: */
123 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /* .abcdefghi...... */
124 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, /* 90-9f: */
125 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /* .jklmnopqr...... */
126 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* a0-af: */
127 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, /* .~stuvwxyz...[.. */
128 0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, /* b0-bf: */
129 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7, /* .............].. */
130 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* c0-cf: */
131 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /* {ABCDEFGHI...... */
132 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, /* d0-df: */
133 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, /* }JKLMNOPQR...... */
134 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* e0-ef: */
135 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /* \.STUVWXYZ...... */
136 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* f0-ff: */
137 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f /* 0123456789...... */
138};
139
140
141/*
142The US-ASCII to EBCDIC (character set IBM-1047) table:
143This table is bijective (no ambiguous or duplicate characters)
144*/
145const unsigned char os_toebcdic[256] = {
146 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, /* 00-0f: */
147 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
148 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, /* 10-1f: */
149 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
150 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, /* 20-2f: */
151 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
152 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 30-3f: */
153 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /* 0123456789:;<=>? */
154 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 40-4f: */
155 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /* @ABCDEFGHIJKLMNO */
156 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, /* 50-5f: */
157 0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, /* PQRSTUVWXYZ[\]^_ */
158 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60-6f: */
159 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* `abcdefghijklmno */
160 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, /* 70-7f: */
161 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, /* pqrstuvwxyz{|}~. */
162 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08, /* 80-8f: */
163 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /* ................ */
164 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17, /* 90-9f: */
165 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0xff, /* ................ */
166 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, /* a0-af: */
167 0xbb, 0xb4, 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, /* ................ */
168 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, /* b0-bf: */
169 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /* ................ */
170 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, /* c0-cf: */
171 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* ................ */
172 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, /* d0-df: */
173 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xba, 0xae, 0x59, /* ................ */
174 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, /* e0-ef: */
175 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* ................ */
176 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff: */
177 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /* ................ */
178};
179#endif /*_OSD_POSIX*/
180
181/* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
182 * dest and srce may be identical, or separate memory blocks, but
183 * should not overlap. These functions intentionally have an interface
184 * compatible to memcpy(3).
185 */
186
187void *
188ebcdic2ascii(void *dest, const void *srce, size_t count)
189{
190 unsigned char *udest = dest;
191 const unsigned char *usrce = srce;
192
193 while (count-- != 0) {
194 *udest++ = os_toascii[*usrce++];
195 }
196
197 return dest;
198}
199
200void *
201ascii2ebcdic(void *dest, const void *srce, size_t count)
202{
203 unsigned char *udest = dest;
204 const unsigned char *usrce = srce;
205
206 while (count-- != 0) {
207 *udest++ = os_toebcdic[*usrce++];
208 }
209
210 return dest;
211}
212
213#else /*CHARSET_EBCDIC*/
214#ifdef PEDANTIC
215static void *dummy=&dummy;
216#endif
217#endif
diff --git a/src/lib/libssl/src/crypto/ebcdic.h b/src/lib/libssl/src/crypto/ebcdic.h
new file mode 100644
index 0000000000..d3b4e98b12
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ebcdic.h
@@ -0,0 +1,17 @@
1#ifndef HEADER_EBCDIC_H
2#define HEADER_EBCDIC_H
3
4#include <sys/types.h>
5
6/* Avoid name clashes with other applications */
7#define os_toascii _eay2000_os_toascii
8#define os_toebcdic _eay2000_os_toebcdic
9#define ebcdic2ascii _eay2000_ebcdic2ascii
10#define ascii2ebcdic _eay2000_ascii2ebcdic
11
12extern const unsigned char os_toascii[256];
13extern const unsigned char os_toebcdic[256];
14void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count);
15void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count);
16
17#endif
diff --git a/src/lib/libssl/src/crypto/ec/ec.h b/src/lib/libssl/src/crypto/ec/ec.h
new file mode 100644
index 0000000000..a52d4edf14
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec.h
@@ -0,0 +1,245 @@
1/* crypto/ec/ec.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#ifndef HEADER_EC_H
57#define HEADER_EC_H
58
59#ifdef OPENSSL_NO_EC
60#error EC is disabled.
61#endif
62
63#include <openssl/bn.h>
64#include <openssl/symhacks.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70
71typedef enum {
72 /* values as defined in X9.62 (ECDSA) and elsewhere */
73 POINT_CONVERSION_COMPRESSED = 2,
74 POINT_CONVERSION_UNCOMPRESSED = 4,
75 POINT_CONVERSION_HYBRID = 6
76} point_conversion_form_t;
77
78
79typedef struct ec_method_st EC_METHOD;
80
81typedef struct ec_group_st
82 /*
83 EC_METHOD *meth;
84 -- field definition
85 -- curve coefficients
86 -- optional generator with associated information (order, cofactor)
87 -- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
88 */
89 EC_GROUP;
90
91typedef struct ec_point_st EC_POINT;
92
93
94/* EC_METHODs for curves over GF(p).
95 * EC_GFp_simple_method provides the basis for the optimized methods.
96 */
97const EC_METHOD *EC_GFp_simple_method(void);
98const EC_METHOD *EC_GFp_mont_method(void);
99#if 0
100const EC_METHOD *EC_GFp_recp_method(void); /* TODO */
101const EC_METHOD *EC_GFp_nist_method(void); /* TODO */
102#endif
103
104
105EC_GROUP *EC_GROUP_new(const EC_METHOD *);
106void EC_GROUP_free(EC_GROUP *);
107void EC_GROUP_clear_free(EC_GROUP *);
108int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
109
110const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
111
112
113/* We don't have types for field specifications and field elements in general.
114 * Otherwise we could declare
115 * int EC_GROUP_set_curve(EC_GROUP *, .....);
116 */
117int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
118int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
119
120/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp()
121 * after choosing an appropriate EC_METHOD */
122EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
123
124int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
125EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
126int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
127int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
128
129EC_POINT *EC_POINT_new(const EC_GROUP *);
130void EC_POINT_free(EC_POINT *);
131void EC_POINT_clear_free(EC_POINT *);
132int EC_POINT_copy(EC_POINT *, const EC_POINT *);
133
134const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
135
136int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
137int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
138 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
139int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
140 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
141int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
142 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
143int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
144 BIGNUM *x, BIGNUM *y, BN_CTX *);
145int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
146 const BIGNUM *x, int y_bit, BN_CTX *);
147
148size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
149 unsigned char *buf, size_t len, BN_CTX *);
150int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
151 const unsigned char *buf, size_t len, BN_CTX *);
152
153int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
154int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
155int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
156
157int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
158int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
159int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
160
161int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
162int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
163
164
165int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
166int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
167int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
168
169
170
171/* BEGIN ERROR CODES */
172/* The following lines are auto generated by the script mkerr.pl. Any changes
173 * made after this point may be overwritten when the script is next run.
174 */
175void ERR_load_EC_strings(void);
176
177/* Error codes for the EC functions. */
178
179/* Function codes. */
180#define EC_F_COMPUTE_WNAF 143
181#define EC_F_EC_GFP_MONT_FIELD_DECODE 133
182#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
183#define EC_F_EC_GFP_MONT_FIELD_MUL 131
184#define EC_F_EC_GFP_MONT_FIELD_SQR 132
185#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
186#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
187#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
188#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
189#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
190#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
191#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
192#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
193#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
194#define EC_F_EC_GROUP_COPY 106
195#define EC_F_EC_GROUP_GET0_GENERATOR 139
196#define EC_F_EC_GROUP_GET_COFACTOR 140
197#define EC_F_EC_GROUP_GET_CURVE_GFP 130
198#define EC_F_EC_GROUP_GET_EXTRA_DATA 107
199#define EC_F_EC_GROUP_GET_ORDER 141
200#define EC_F_EC_GROUP_NEW 108
201#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
202#define EC_F_EC_GROUP_SET_CURVE_GFP 109
203#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
204#define EC_F_EC_GROUP_SET_GENERATOR 111
205#define EC_F_EC_POINTS_MAKE_AFFINE 136
206#define EC_F_EC_POINTS_MUL 138
207#define EC_F_EC_POINT_ADD 112
208#define EC_F_EC_POINT_CMP 113
209#define EC_F_EC_POINT_COPY 114
210#define EC_F_EC_POINT_DBL 115
211#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
212#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
213#define EC_F_EC_POINT_IS_AT_INFINITY 118
214#define EC_F_EC_POINT_IS_ON_CURVE 119
215#define EC_F_EC_POINT_MAKE_AFFINE 120
216#define EC_F_EC_POINT_NEW 121
217#define EC_F_EC_POINT_OCT2POINT 122
218#define EC_F_EC_POINT_POINT2OCT 123
219#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
220#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
221#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
222#define EC_F_EC_POINT_SET_TO_INFINITY 127
223#define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135
224
225/* Reason codes. */
226#define EC_R_BUFFER_TOO_SMALL 100
227#define EC_R_INCOMPATIBLE_OBJECTS 101
228#define EC_R_INVALID_ARGUMENT 112
229#define EC_R_INVALID_COMPRESSED_POINT 110
230#define EC_R_INVALID_COMPRESSION_BIT 109
231#define EC_R_INVALID_ENCODING 102
232#define EC_R_INVALID_FIELD 103
233#define EC_R_INVALID_FORM 104
234#define EC_R_NOT_INITIALIZED 111
235#define EC_R_NO_SUCH_EXTRA_DATA 105
236#define EC_R_POINT_AT_INFINITY 106
237#define EC_R_POINT_IS_NOT_ON_CURVE 107
238#define EC_R_SLOT_FULL 108
239#define EC_R_UNDEFINED_GENERATOR 113
240#define EC_R_UNKNOWN_ORDER 114
241
242#ifdef __cplusplus
243}
244#endif
245#endif
diff --git a/src/lib/libssl/src/crypto/ec/ec_cvt.c b/src/lib/libssl/src/crypto/ec/ec_cvt.c
new file mode 100644
index 0000000000..45b0ec33a0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec_cvt.c
@@ -0,0 +1,80 @@
1/* crypto/ec/ec_cvt.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58
59EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
60 {
61 const EC_METHOD *meth;
62 EC_GROUP *ret;
63
64 /* Finally, this will use EC_GFp_nist_method if 'p' is a special
65 * prime with optimized modular arithmetics (for NIST curves)
66 */
67 meth = EC_GFp_mont_method();
68
69 ret = EC_GROUP_new(meth);
70 if (ret == NULL)
71 return NULL;
72
73 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
74 {
75 EC_GROUP_clear_free(ret);
76 return NULL;
77 }
78
79 return ret;
80 }
diff --git a/src/lib/libssl/src/crypto/ec/ec_err.c b/src/lib/libssl/src/crypto/ec/ec_err.c
new file mode 100644
index 0000000000..394cdc021f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec_err.c
@@ -0,0 +1,151 @@
1/* crypto/ec/ec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ec.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA EC_str_functs[]=
68 {
69{ERR_PACK(0,EC_F_COMPUTE_WNAF,0), "COMPUTE_WNAF"},
70{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_DECODE,0), "ec_GFp_mont_field_decode"},
71{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_ENCODE,0), "ec_GFp_mont_field_encode"},
72{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_MUL,0), "ec_GFp_mont_field_mul"},
73{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_SQR,0), "ec_GFp_mont_field_sqr"},
74{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP,0), "ec_GFp_simple_group_set_curve_GFp"},
75{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "ec_GFp_simple_group_set_generator"},
76{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_MAKE_AFFINE,0), "ec_GFp_simple_make_affine"},
77{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_OCT2POINT,0), "ec_GFp_simple_oct2point"},
78{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT2OCT,0), "ec_GFp_simple_point2oct"},
79{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE,0), "ec_GFp_simple_points_make_affine"},
80{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_get_affine_coordinates_GFp"},
81{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_set_affine_coordinates_GFp"},
82{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP,0), "ec_GFp_simple_set_compressed_coordinates_GFp"},
83{ERR_PACK(0,EC_F_EC_GROUP_COPY,0), "EC_GROUP_copy"},
84{ERR_PACK(0,EC_F_EC_GROUP_GET0_GENERATOR,0), "EC_GROUP_get0_generator"},
85{ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"},
86{ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"},
87{ERR_PACK(0,EC_F_EC_GROUP_GET_EXTRA_DATA,0), "EC_GROUP_get_extra_data"},
88{ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"},
89{ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"},
90{ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"},
91{ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GFP,0), "EC_GROUP_set_curve_GFp"},
92{ERR_PACK(0,EC_F_EC_GROUP_SET_EXTRA_DATA,0), "EC_GROUP_set_extra_data"},
93{ERR_PACK(0,EC_F_EC_GROUP_SET_GENERATOR,0), "EC_GROUP_set_generator"},
94{ERR_PACK(0,EC_F_EC_POINTS_MAKE_AFFINE,0), "EC_POINTs_make_affine"},
95{ERR_PACK(0,EC_F_EC_POINTS_MUL,0), "EC_POINTs_mul"},
96{ERR_PACK(0,EC_F_EC_POINT_ADD,0), "EC_POINT_add"},
97{ERR_PACK(0,EC_F_EC_POINT_CMP,0), "EC_POINT_cmp"},
98{ERR_PACK(0,EC_F_EC_POINT_COPY,0), "EC_POINT_copy"},
99{ERR_PACK(0,EC_F_EC_POINT_DBL,0), "EC_POINT_dbl"},
100{ERR_PACK(0,EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP,0), "EC_POINT_get_affine_coordinates_GFp"},
101{ERR_PACK(0,EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_get_Jprojective_coordinates_GFp"},
102{ERR_PACK(0,EC_F_EC_POINT_IS_AT_INFINITY,0), "EC_POINT_is_at_infinity"},
103{ERR_PACK(0,EC_F_EC_POINT_IS_ON_CURVE,0), "EC_POINT_is_on_curve"},
104{ERR_PACK(0,EC_F_EC_POINT_MAKE_AFFINE,0), "EC_POINT_make_affine"},
105{ERR_PACK(0,EC_F_EC_POINT_NEW,0), "EC_POINT_new"},
106{ERR_PACK(0,EC_F_EC_POINT_OCT2POINT,0), "EC_POINT_oct2point"},
107{ERR_PACK(0,EC_F_EC_POINT_POINT2OCT,0), "EC_POINT_point2oct"},
108{ERR_PACK(0,EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP,0), "EC_POINT_set_affine_coordinates_GFp"},
109{ERR_PACK(0,EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,0), "EC_POINT_set_compressed_coordinates_GFp"},
110{ERR_PACK(0,EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_set_Jprojective_coordinates_GFp"},
111{ERR_PACK(0,EC_F_EC_POINT_SET_TO_INFINITY,0), "EC_POINT_set_to_infinity"},
112{ERR_PACK(0,EC_F_GFP_MONT_GROUP_SET_CURVE_GFP,0), "GFP_MONT_GROUP_SET_CURVE_GFP"},
113{0,NULL}
114 };
115
116static ERR_STRING_DATA EC_str_reasons[]=
117 {
118{EC_R_BUFFER_TOO_SMALL ,"buffer too small"},
119{EC_R_INCOMPATIBLE_OBJECTS ,"incompatible objects"},
120{EC_R_INVALID_ARGUMENT ,"invalid argument"},
121{EC_R_INVALID_COMPRESSED_POINT ,"invalid compressed point"},
122{EC_R_INVALID_COMPRESSION_BIT ,"invalid compression bit"},
123{EC_R_INVALID_ENCODING ,"invalid encoding"},
124{EC_R_INVALID_FIELD ,"invalid field"},
125{EC_R_INVALID_FORM ,"invalid form"},
126{EC_R_NOT_INITIALIZED ,"not initialized"},
127{EC_R_NO_SUCH_EXTRA_DATA ,"no such extra data"},
128{EC_R_POINT_AT_INFINITY ,"point at infinity"},
129{EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"},
130{EC_R_SLOT_FULL ,"slot full"},
131{EC_R_UNDEFINED_GENERATOR ,"undefined generator"},
132{EC_R_UNKNOWN_ORDER ,"unknown order"},
133{0,NULL}
134 };
135
136#endif
137
138void ERR_load_EC_strings(void)
139 {
140 static int init=1;
141
142 if (init)
143 {
144 init=0;
145#ifndef OPENSSL_NO_ERR
146 ERR_load_strings(ERR_LIB_EC,EC_str_functs);
147 ERR_load_strings(ERR_LIB_EC,EC_str_reasons);
148#endif
149
150 }
151 }
diff --git a/src/lib/libssl/src/crypto/ec/ec_lcl.h b/src/lib/libssl/src/crypto/ec/ec_lcl.h
new file mode 100644
index 0000000000..cc4cf27755
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec_lcl.h
@@ -0,0 +1,277 @@
1/* crypto/ec/ec_lcl.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57#include <stdlib.h>
58
59#include <openssl/ec.h>
60
61
62/* Structure details are not part of the exported interface,
63 * so all this may change in future versions. */
64
65struct ec_method_st {
66 /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
67 int (*group_init)(EC_GROUP *);
68 void (*group_finish)(EC_GROUP *);
69 void (*group_clear_finish)(EC_GROUP *);
70 int (*group_copy)(EC_GROUP *, const EC_GROUP *);
71
72 /* used by EC_GROUP_set_curve_GFp and EC_GROUP_get_curve_GFp: */
73 int (*group_set_curve_GFp)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
74 int (*group_get_curve_GFp)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
75
76 /* used by EC_GROUP_set_generator, EC_GROUP_get0_generator,
77 * EC_GROUP_get_order, EC_GROUP_get_cofactor:
78 */
79 int (*group_set_generator)(EC_GROUP *, const EC_POINT *generator,
80 const BIGNUM *order, const BIGNUM *cofactor);
81 EC_POINT *(*group_get0_generator)(const EC_GROUP *);
82 int (*group_get_order)(const EC_GROUP *, BIGNUM *order, BN_CTX *);
83 int (*group_get_cofactor)(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
84
85 /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
86 int (*point_init)(EC_POINT *);
87 void (*point_finish)(EC_POINT *);
88 void (*point_clear_finish)(EC_POINT *);
89 int (*point_copy)(EC_POINT *, const EC_POINT *);
90
91 /* used by EC_POINT_set_to_infinity,
92 * EC_POINT_set_Jprojective_coordinates_GFp, EC_POINT_get_Jprojective_coordinates_GFp,
93 * EC_POINT_set_affine_coordinates_GFp, EC_POINT_get_affine_coordinates_GFp,
94 * EC_POINT_set_compressed_coordinates_GFp:
95 */
96 int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
97 int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
98 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
99 int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
100 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
101 int (*point_set_affine_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
102 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
103 int (*point_get_affine_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
104 BIGNUM *x, BIGNUM *y, BN_CTX *);
105 int (*point_set_compressed_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
106 const BIGNUM *x, int y_bit, BN_CTX *);
107
108 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */
109 size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
110 unsigned char *buf, size_t len, BN_CTX *);
111 int (*oct2point)(const EC_GROUP *, EC_POINT *,
112 const unsigned char *buf, size_t len, BN_CTX *);
113
114 /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */
115 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
116 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
117 int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
118
119 /* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */
120 int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *);
121 int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
122 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
123
124 /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */
125 int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
126 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
127
128
129 /* internal functions */
130
131 /* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
132 * the same implementations of point operations can be used with different
133 * optimized implementations of expensive field operations: */
134 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
135 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
136
137 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
138 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
139 int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *);
140} /* EC_METHOD */;
141
142
143struct ec_group_st {
144 const EC_METHOD *meth;
145
146 void *extra_data;
147 void *(*extra_data_dup_func)(void *);
148 void (*extra_data_free_func)(void *);
149 void (*extra_data_clear_free_func)(void *);
150
151 /* All members except 'meth' and 'extra_data...' are handled by
152 * the method functions, even if they appear generic */
153
154 BIGNUM field; /* Field specification.
155 * For curves over GF(p), this is the modulus. */
156
157 BIGNUM a, b; /* Curve coefficients.
158 * (Here the assumption is that BIGNUMs can be used
159 * or abused for all kinds of fields, not just GF(p).)
160 * For characteristic > 3, the curve is defined
161 * by a Weierstrass equation of the form
162 * y^2 = x^3 + a*x + b.
163 */
164 int a_is_minus3; /* enable optimized point arithmetics for special case */
165
166 EC_POINT *generator; /* optional */
167 BIGNUM order, cofactor;
168
169 void *field_data1; /* method-specific (e.g., Montgomery structure) */
170 void *field_data2; /* method-specific */
171} /* EC_GROUP */;
172
173
174/* Basically a 'mixin' for extra data, but available for EC_GROUPs only
175 * (with visibility limited to 'package' level for now).
176 * We use the function pointers as index for retrieval; this obviates
177 * global ex_data-style index tables.
178 * (Currently, we have one slot only, but is is possible to extend this
179 * if necessary.) */
180int EC_GROUP_set_extra_data(EC_GROUP *, void *extra_data, void *(*extra_data_dup_func)(void *),
181 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
182void *EC_GROUP_get_extra_data(const EC_GROUP *, void *(*extra_data_dup_func)(void *),
183 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
184void EC_GROUP_free_extra_data(EC_GROUP *);
185void EC_GROUP_clear_free_extra_data(EC_GROUP *);
186
187
188
189struct ec_point_st {
190 const EC_METHOD *meth;
191
192 /* All members except 'meth' are handled by the method functions,
193 * even if they appear generic */
194
195 BIGNUM X;
196 BIGNUM Y;
197 BIGNUM Z; /* Jacobian projective coordinates:
198 * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */
199 int Z_is_one; /* enable optimized point arithmetics for special case */
200} /* EC_POINT */;
201
202
203
204/* method functions in ecp_smpl.c */
205int ec_GFp_simple_group_init(EC_GROUP *);
206void ec_GFp_simple_group_finish(EC_GROUP *);
207void ec_GFp_simple_group_clear_finish(EC_GROUP *);
208int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
209int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
210int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
211int ec_GFp_simple_group_set_generator(EC_GROUP *, const EC_POINT *generator,
212 const BIGNUM *order, const BIGNUM *cofactor);
213EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *);
214int ec_GFp_simple_group_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
215int ec_GFp_simple_group_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
216int ec_GFp_simple_point_init(EC_POINT *);
217void ec_GFp_simple_point_finish(EC_POINT *);
218void ec_GFp_simple_point_clear_finish(EC_POINT *);
219int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *);
220int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
221int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
222 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
223int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
224 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
225int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
226 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
227int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
228 BIGNUM *x, BIGNUM *y, BN_CTX *);
229int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
230 const BIGNUM *x, int y_bit, BN_CTX *);
231size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
232 unsigned char *buf, size_t len, BN_CTX *);
233int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *,
234 const unsigned char *buf, size_t len, BN_CTX *);
235int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
236int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
237int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
238int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
239int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
240int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
241int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
242int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
243int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
244int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
245
246
247/* method functions in ecp_mont.c */
248int ec_GFp_mont_group_init(EC_GROUP *);
249int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
250void ec_GFp_mont_group_finish(EC_GROUP *);
251void ec_GFp_mont_group_clear_finish(EC_GROUP *);
252int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
253int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
254int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
255int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
256int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
257int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
258
259
260/* method functions in ecp_recp.c */
261int ec_GFp_recp_group_init(EC_GROUP *);
262int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
263void ec_GFp_recp_group_finish(EC_GROUP *);
264void ec_GFp_recp_group_clear_finish(EC_GROUP *);
265int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
266int ec_GFp_recp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
267int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
268
269
270/* method functions in ecp_nist.c */
271int ec_GFp_nist_group_init(EC_GROUP *);
272int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
273void ec_GFp_nist_group_finish(EC_GROUP *);
274void ec_GFp_nist_group_clear_finish(EC_GROUP *);
275int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
276int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
277int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
diff --git a/src/lib/libssl/src/crypto/ec/ec_lib.c b/src/lib/libssl/src/crypto/ec/ec_lib.c
new file mode 100644
index 0000000000..e0d78d67fb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec_lib.c
@@ -0,0 +1,646 @@
1/* crypto/ec/ec_lib.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57
58#include <openssl/err.h>
59#include <openssl/opensslv.h>
60
61#include "ec_lcl.h"
62
63static const char EC_version[] = "EC" OPENSSL_VERSION_PTEXT;
64
65
66/* functions for EC_GROUP objects */
67
68EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
69 {
70 EC_GROUP *ret;
71
72 if (meth == NULL)
73 {
74 ECerr(EC_F_EC_GROUP_NEW, ERR_R_PASSED_NULL_PARAMETER);
75 return NULL;
76 }
77 if (meth->group_init == 0)
78 {
79 ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
80 return NULL;
81 }
82
83 ret = OPENSSL_malloc(sizeof *ret);
84 if (ret == NULL)
85 {
86 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 ret->meth = meth;
91
92 ret->extra_data = NULL;
93 ret->extra_data_dup_func = 0;
94 ret->extra_data_free_func = 0;
95 ret->extra_data_clear_free_func = 0;
96
97 if (!meth->group_init(ret))
98 {
99 OPENSSL_free(ret);
100 return NULL;
101 }
102
103 return ret;
104 }
105
106
107void EC_GROUP_free(EC_GROUP *group)
108 {
109 if (group->meth->group_finish != 0)
110 group->meth->group_finish(group);
111
112 EC_GROUP_free_extra_data(group);
113
114 OPENSSL_free(group);
115 }
116
117
118void EC_GROUP_clear_free(EC_GROUP *group)
119 {
120 if (group->meth->group_clear_finish != 0)
121 group->meth->group_clear_finish(group);
122 else if (group->meth != NULL && group->meth->group_finish != 0)
123 group->meth->group_finish(group);
124
125 EC_GROUP_clear_free_extra_data(group);
126
127 memset(group, 0, sizeof *group);
128 OPENSSL_free(group);
129 }
130
131
132int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
133 {
134 if (dest->meth->group_copy == 0)
135 {
136 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
137 return 0;
138 }
139 if (dest->meth != src->meth)
140 {
141 ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);
142 return 0;
143 }
144 if (dest == src)
145 return 1;
146
147 EC_GROUP_clear_free_extra_data(dest);
148 if (src->extra_data_dup_func)
149 {
150 if (src->extra_data != NULL)
151 {
152 dest->extra_data = src->extra_data_dup_func(src->extra_data);
153 if (dest->extra_data == NULL)
154 return 0;
155 }
156
157 dest->extra_data_dup_func = src->extra_data_dup_func;
158 dest->extra_data_free_func = src->extra_data_free_func;
159 dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
160 }
161
162 return dest->meth->group_copy(dest, src);
163 }
164
165
166const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
167 {
168 return group->meth;
169 }
170
171
172int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
173 {
174 if (group->meth->group_set_curve_GFp == 0)
175 {
176 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
177 return 0;
178 }
179 return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
180 }
181
182
183int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
184 {
185 if (group->meth->group_get_curve_GFp == 0)
186 {
187 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
188 return 0;
189 }
190 return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
191 }
192
193
194int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
195 {
196 if (group->meth->group_set_generator == 0)
197 {
198 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
199 return 0;
200 }
201 return group->meth->group_set_generator(group, generator, order, cofactor);
202 }
203
204
205EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
206 {
207 if (group->meth->group_get0_generator == 0)
208 {
209 ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
210 return 0;
211 }
212 return group->meth->group_get0_generator(group);
213 }
214
215
216int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
217 {
218 if (group->meth->group_get_order == 0)
219 {
220 ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
221 return 0;
222 }
223 return group->meth->group_get_order(group, order, ctx);
224 }
225
226
227int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
228 {
229 if (group->meth->group_get_cofactor == 0)
230 {
231 ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
232 return 0;
233 }
234 return group->meth->group_get_cofactor(group, cofactor, ctx);
235 }
236
237
238/* this has 'package' visibility */
239int EC_GROUP_set_extra_data(EC_GROUP *group, void *extra_data, void *(*extra_data_dup_func)(void *),
240 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
241 {
242 if ((group->extra_data != NULL)
243 || (group->extra_data_dup_func != 0)
244 || (group->extra_data_free_func != 0)
245 || (group->extra_data_clear_free_func != 0))
246 {
247 ECerr(EC_F_EC_GROUP_SET_EXTRA_DATA, EC_R_SLOT_FULL);
248 return 0;
249 }
250
251 group->extra_data = extra_data;
252 group->extra_data_dup_func = extra_data_dup_func;
253 group->extra_data_free_func = extra_data_free_func;
254 group->extra_data_clear_free_func = extra_data_clear_free_func;
255 return 1;
256 }
257
258
259/* this has 'package' visibility */
260void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func)(void *),
261 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
262 {
263 if ((group->extra_data_dup_func != extra_data_dup_func)
264 || (group->extra_data_free_func != extra_data_free_func)
265 || (group->extra_data_clear_free_func != extra_data_clear_free_func))
266 {
267 ECerr(EC_F_EC_GROUP_GET_EXTRA_DATA, EC_R_NO_SUCH_EXTRA_DATA);
268 return NULL;
269 }
270
271 return group->extra_data;
272 }
273
274
275/* this has 'package' visibility */
276void EC_GROUP_free_extra_data(EC_GROUP *group)
277 {
278 if (group->extra_data_free_func)
279 group->extra_data_free_func(group->extra_data);
280 group->extra_data = NULL;
281 group->extra_data_dup_func = 0;
282 group->extra_data_free_func = 0;
283 group->extra_data_clear_free_func = 0;
284 }
285
286
287/* this has 'package' visibility */
288void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
289 {
290 if (group->extra_data_clear_free_func)
291 group->extra_data_clear_free_func(group->extra_data);
292 else if (group->extra_data_free_func)
293 group->extra_data_free_func(group->extra_data);
294 group->extra_data = NULL;
295 group->extra_data_dup_func = 0;
296 group->extra_data_free_func = 0;
297 group->extra_data_clear_free_func = 0;
298 }
299
300
301
302/* functions for EC_POINT objects */
303
304EC_POINT *EC_POINT_new(const EC_GROUP *group)
305 {
306 EC_POINT *ret;
307
308 if (group == NULL)
309 {
310 ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);
311 return NULL;
312 }
313 if (group->meth->point_init == 0)
314 {
315 ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
316 return NULL;
317 }
318
319 ret = OPENSSL_malloc(sizeof *ret);
320 if (ret == NULL)
321 {
322 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
323 return NULL;
324 }
325
326 ret->meth = group->meth;
327
328 if (!ret->meth->point_init(ret))
329 {
330 OPENSSL_free(ret);
331 return NULL;
332 }
333
334 return ret;
335 }
336
337
338void EC_POINT_free(EC_POINT *point)
339 {
340 if (point->meth->point_finish != 0)
341 point->meth->point_finish(point);
342 OPENSSL_free(point);
343 }
344
345
346void EC_POINT_clear_free(EC_POINT *point)
347 {
348 if (point->meth->point_clear_finish != 0)
349 point->meth->point_clear_finish(point);
350 else if (point->meth != NULL && point->meth->point_finish != 0)
351 point->meth->point_finish(point);
352 memset(point, 0, sizeof *point);
353 OPENSSL_free(point);
354 }
355
356
357int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
358 {
359 if (dest->meth->point_copy == 0)
360 {
361 ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
362 return 0;
363 }
364 if (dest->meth != src->meth)
365 {
366 ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);
367 return 0;
368 }
369 if (dest == src)
370 return 1;
371 return dest->meth->point_copy(dest, src);
372 }
373
374
375const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
376 {
377 return point->meth;
378 }
379
380
381int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
382 {
383 if (group->meth->point_set_to_infinity == 0)
384 {
385 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
386 return 0;
387 }
388 if (group->meth != point->meth)
389 {
390 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
391 return 0;
392 }
393 return group->meth->point_set_to_infinity(group, point);
394 }
395
396
397int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
398 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
399 {
400 if (group->meth->point_set_Jprojective_coordinates_GFp == 0)
401 {
402 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
403 return 0;
404 }
405 if (group->meth != point->meth)
406 {
407 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
408 return 0;
409 }
410 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
411 }
412
413
414int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
415 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
416 {
417 if (group->meth->point_get_Jprojective_coordinates_GFp == 0)
418 {
419 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
420 return 0;
421 }
422 if (group->meth != point->meth)
423 {
424 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
425 return 0;
426 }
427 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
428 }
429
430
431int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
432 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
433 {
434 if (group->meth->point_set_affine_coordinates_GFp == 0)
435 {
436 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
437 return 0;
438 }
439 if (group->meth != point->meth)
440 {
441 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
442 return 0;
443 }
444 return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
445 }
446
447
448int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
449 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
450 {
451 if (group->meth->point_get_affine_coordinates_GFp == 0)
452 {
453 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
454 return 0;
455 }
456 if (group->meth != point->meth)
457 {
458 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
459 return 0;
460 }
461 return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
462 }
463
464
465int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
466 const BIGNUM *x, int y_bit, BN_CTX *ctx)
467 {
468 if (group->meth->point_set_compressed_coordinates_GFp == 0)
469 {
470 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
471 return 0;
472 }
473 if (group->meth != point->meth)
474 {
475 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
476 return 0;
477 }
478 return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
479 }
480
481
482size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
483 unsigned char *buf, size_t len, BN_CTX *ctx)
484 {
485 if (group->meth->point2oct == 0)
486 {
487 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
488 return 0;
489 }
490 if (group->meth != point->meth)
491 {
492 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS);
493 return 0;
494 }
495 return group->meth->point2oct(group, point, form, buf, len, ctx);
496 }
497
498
499int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
500 const unsigned char *buf, size_t len, BN_CTX *ctx)
501 {
502 if (group->meth->oct2point == 0)
503 {
504 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
505 return 0;
506 }
507 if (group->meth != point->meth)
508 {
509 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);
510 return 0;
511 }
512 return group->meth->oct2point(group, point, buf, len, ctx);
513 }
514
515
516int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
517 {
518 if (group->meth->add == 0)
519 {
520 ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
521 return 0;
522 }
523 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth))
524 {
525 ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS);
526 return 0;
527 }
528 return group->meth->add(group, r, a, b, ctx);
529 }
530
531
532int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
533 {
534 if (group->meth->dbl == 0)
535 {
536 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
537 return 0;
538 }
539 if ((group->meth != r->meth) || (r->meth != a->meth))
540 {
541 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
542 return 0;
543 }
544 return group->meth->dbl(group, r, a, ctx);
545 }
546
547
548int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
549 {
550 if (group->meth->dbl == 0)
551 {
552 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
553 return 0;
554 }
555 if (group->meth != a->meth)
556 {
557 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
558 return 0;
559 }
560 return group->meth->invert(group, a, ctx);
561 }
562
563
564int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
565 {
566 if (group->meth->is_at_infinity == 0)
567 {
568 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
569 return 0;
570 }
571 if (group->meth != point->meth)
572 {
573 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
574 return 0;
575 }
576 return group->meth->is_at_infinity(group, point);
577 }
578
579
580int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
581 {
582 if (group->meth->is_on_curve == 0)
583 {
584 ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
585 return 0;
586 }
587 if (group->meth != point->meth)
588 {
589 ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS);
590 return 0;
591 }
592 return group->meth->is_on_curve(group, point, ctx);
593 }
594
595
596int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
597 {
598 if (group->meth->point_cmp == 0)
599 {
600 ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
601 return 0;
602 }
603 if ((group->meth != a->meth) || (a->meth != b->meth))
604 {
605 ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
606 return 0;
607 }
608 return group->meth->point_cmp(group, a, b, ctx);
609 }
610
611
612int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
613 {
614 if (group->meth->make_affine == 0)
615 {
616 ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
617 return 0;
618 }
619 if (group->meth != point->meth)
620 {
621 ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
622 return 0;
623 }
624 return group->meth->make_affine(group, point, ctx);
625 }
626
627
628int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
629 {
630 size_t i;
631
632 if (group->meth->points_make_affine == 0)
633 {
634 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
635 return 0;
636 }
637 for (i = 0; i < num; i++)
638 {
639 if (group->meth != points[i]->meth)
640 {
641 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
642 return 0;
643 }
644 }
645 return group->meth->points_make_affine(group, num, points, ctx);
646 }
diff --git a/src/lib/libssl/src/crypto/ec/ec_mult.c b/src/lib/libssl/src/crypto/ec/ec_mult.c
new file mode 100644
index 0000000000..603ba31b81
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ec_mult.c
@@ -0,0 +1,473 @@
1/* crypto/ec/ec_mult.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61/* TODO: optional precomputation of multiples of the generator */
62
63
64
65/*
66 * wNAF-based interleaving multi-exponentation method
67 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#multiexp>)
68 */
69
70
71/* Determine the width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
72 * This is an array r[] of values that are either zero or odd with an
73 * absolute value less than 2^w satisfying
74 * scalar = \sum_j r[j]*2^j
75 * where at most one of any w+1 consecutive digits is non-zero.
76 */
77static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len, BN_CTX *ctx)
78 {
79 BIGNUM *c;
80 int ok = 0;
81 signed char *r = NULL;
82 int sign = 1;
83 int bit, next_bit, mask;
84 size_t len = 0, j;
85
86 BN_CTX_start(ctx);
87 c = BN_CTX_get(ctx);
88 if (c == NULL) goto err;
89
90 if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */
91 {
92 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
93 goto err;
94 }
95 bit = 1 << w; /* at most 128 */
96 next_bit = bit << 1; /* at most 256 */
97 mask = next_bit - 1; /* at most 255 */
98
99 if (!BN_copy(c, scalar)) goto err;
100 if (c->neg)
101 {
102 sign = -1;
103 c->neg = 0;
104 }
105
106 len = BN_num_bits(c) + 1; /* wNAF may be one digit longer than binary representation */
107 r = OPENSSL_malloc(len);
108 if (r == NULL) goto err;
109
110 j = 0;
111 while (!BN_is_zero(c))
112 {
113 int u = 0;
114
115 if (BN_is_odd(c))
116 {
117 if (c->d == NULL || c->top == 0)
118 {
119 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
120 goto err;
121 }
122 u = c->d[0] & mask;
123 if (u & bit)
124 {
125 u -= next_bit;
126 /* u < 0 */
127 if (!BN_add_word(c, -u)) goto err;
128 }
129 else
130 {
131 /* u > 0 */
132 if (!BN_sub_word(c, u)) goto err;
133 }
134
135 if (u <= -bit || u >= bit || !(u & 1) || c->neg)
136 {
137 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
138 goto err;
139 }
140 }
141
142 r[j++] = sign * u;
143
144 if (BN_is_odd(c))
145 {
146 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
147 goto err;
148 }
149 if (!BN_rshift1(c, c)) goto err;
150 }
151
152 if (j > len)
153 {
154 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
155 goto err;
156 }
157 len = j;
158 ok = 1;
159
160 err:
161 BN_CTX_end(ctx);
162 if (!ok)
163 {
164 OPENSSL_free(r);
165 r = NULL;
166 }
167 if (ok)
168 *ret_len = len;
169 return r;
170 }
171
172
173/* TODO: table should be optimised for the wNAF-based implementation,
174 * sometimes smaller windows will give better performance
175 * (thus the boundaries should be increased)
176 */
177#define EC_window_bits_for_scalar_size(b) \
178 ((b) >= 2000 ? 6 : \
179 (b) >= 800 ? 5 : \
180 (b) >= 300 ? 4 : \
181 (b) >= 70 ? 3 : \
182 (b) >= 20 ? 2 : \
183 1)
184
185/* Compute
186 * \sum scalars[i]*points[i],
187 * also including
188 * scalar*generator
189 * in the addition if scalar != NULL
190 */
191int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
192 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
193 {
194 BN_CTX *new_ctx = NULL;
195 EC_POINT *generator = NULL;
196 EC_POINT *tmp = NULL;
197 size_t totalnum;
198 size_t i, j;
199 int k;
200 int r_is_inverted = 0;
201 int r_is_at_infinity = 1;
202 size_t *wsize = NULL; /* individual window sizes */
203 signed char **wNAF = NULL; /* individual wNAFs */
204 size_t *wNAF_len = NULL;
205 size_t max_len = 0;
206 size_t num_val;
207 EC_POINT **val = NULL; /* precomputation */
208 EC_POINT **v;
209 EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */
210 int ret = 0;
211
212 if (scalar != NULL)
213 {
214 generator = EC_GROUP_get0_generator(group);
215 if (generator == NULL)
216 {
217 ECerr(EC_F_EC_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
218 return 0;
219 }
220 }
221
222 for (i = 0; i < num; i++)
223 {
224 if (group->meth != points[i]->meth)
225 {
226 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
227 return 0;
228 }
229 }
230
231 totalnum = num + (scalar != NULL);
232
233 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);
234 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
235 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);
236 if (wNAF != NULL)
237 {
238 wNAF[0] = NULL; /* preliminary pivot */
239 }
240 if (wsize == NULL || wNAF_len == NULL || wNAF == NULL) goto err;
241
242 /* num_val := total number of points to precompute */
243 num_val = 0;
244 for (i = 0; i < totalnum; i++)
245 {
246 size_t bits;
247
248 bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
249 wsize[i] = EC_window_bits_for_scalar_size(bits);
250 num_val += 1u << (wsize[i] - 1);
251 }
252
253 /* all precomputed points go into a single array 'val',
254 * 'val_sub[i]' is a pointer to the subarray for the i-th point */
255 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);
256 if (val == NULL) goto err;
257 val[num_val] = NULL; /* pivot element */
258
259 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
260 if (val_sub == NULL) goto err;
261
262 /* allocate points for precomputation */
263 v = val;
264 for (i = 0; i < totalnum; i++)
265 {
266 val_sub[i] = v;
267 for (j = 0; j < (1u << (wsize[i] - 1)); j++)
268 {
269 *v = EC_POINT_new(group);
270 if (*v == NULL) goto err;
271 v++;
272 }
273 }
274 if (!(v == val + num_val))
275 {
276 ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);
277 goto err;
278 }
279
280 if (ctx == NULL)
281 {
282 ctx = new_ctx = BN_CTX_new();
283 if (ctx == NULL)
284 goto err;
285 }
286
287 tmp = EC_POINT_new(group);
288 if (tmp == NULL) goto err;
289
290 /* prepare precomputed values:
291 * val_sub[i][0] := points[i]
292 * val_sub[i][1] := 3 * points[i]
293 * val_sub[i][2] := 5 * points[i]
294 * ...
295 */
296 for (i = 0; i < totalnum; i++)
297 {
298 if (i < num)
299 {
300 if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;
301 }
302 else
303 {
304 if (!EC_POINT_copy(val_sub[i][0], generator)) goto err;
305 }
306
307 if (wsize[i] > 1)
308 {
309 if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;
310 for (j = 1; j < (1u << (wsize[i] - 1)); j++)
311 {
312 if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
313 }
314 }
315
316 wNAF[i + 1] = NULL; /* make sure we always have a pivot */
317 wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i], ctx);
318 if (wNAF[i] == NULL) goto err;
319 if (wNAF_len[i] > max_len)
320 max_len = wNAF_len[i];
321 }
322
323#if 1 /* optional; EC_window_bits_for_scalar_size assumes we do this step */
324 if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err;
325#endif
326
327 r_is_at_infinity = 1;
328
329 for (k = max_len - 1; k >= 0; k--)
330 {
331 if (!r_is_at_infinity)
332 {
333 if (!EC_POINT_dbl(group, r, r, ctx)) goto err;
334 }
335
336 for (i = 0; i < totalnum; i++)
337 {
338 if (wNAF_len[i] > (size_t)k)
339 {
340 int digit = wNAF[i][k];
341 int is_neg;
342
343 if (digit)
344 {
345 is_neg = digit < 0;
346
347 if (is_neg)
348 digit = -digit;
349
350 if (is_neg != r_is_inverted)
351 {
352 if (!r_is_at_infinity)
353 {
354 if (!EC_POINT_invert(group, r, ctx)) goto err;
355 }
356 r_is_inverted = !r_is_inverted;
357 }
358
359 /* digit > 0 */
360
361 if (r_is_at_infinity)
362 {
363 if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err;
364 r_is_at_infinity = 0;
365 }
366 else
367 {
368 if (!EC_POINT_add(group, r, r, val_sub[i][digit >> 1], ctx)) goto err;
369 }
370 }
371 }
372 }
373 }
374
375 if (r_is_at_infinity)
376 {
377 if (!EC_POINT_set_to_infinity(group, r)) goto err;
378 }
379 else
380 {
381 if (r_is_inverted)
382 if (!EC_POINT_invert(group, r, ctx)) goto err;
383 }
384
385 ret = 1;
386
387 err:
388 if (new_ctx != NULL)
389 BN_CTX_free(new_ctx);
390 if (tmp != NULL)
391 EC_POINT_free(tmp);
392 if (wsize != NULL)
393 OPENSSL_free(wsize);
394 if (wNAF_len != NULL)
395 OPENSSL_free(wNAF_len);
396 if (wNAF != NULL)
397 {
398 signed char **w;
399
400 for (w = wNAF; *w != NULL; w++)
401 OPENSSL_free(*w);
402
403 OPENSSL_free(wNAF);
404 }
405 if (val != NULL)
406 {
407 for (v = val; *v != NULL; v++)
408 EC_POINT_clear_free(*v);
409
410 OPENSSL_free(val);
411 }
412 if (val_sub != NULL)
413 {
414 OPENSSL_free(val_sub);
415 }
416 return ret;
417 }
418
419
420int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
421 {
422 const EC_POINT *points[1];
423 const BIGNUM *scalars[1];
424
425 points[0] = point;
426 scalars[0] = p_scalar;
427
428 return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
429 }
430
431
432int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
433 {
434 const EC_POINT *generator;
435 BN_CTX *new_ctx = NULL;
436 BIGNUM *order;
437 int ret = 0;
438
439 generator = EC_GROUP_get0_generator(group);
440 if (generator == NULL)
441 {
442 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
443 return 0;
444 }
445
446 if (ctx == NULL)
447 {
448 ctx = new_ctx = BN_CTX_new();
449 if (ctx == NULL)
450 return 0;
451 }
452
453 BN_CTX_start(ctx);
454 order = BN_CTX_get(ctx);
455 if (order == NULL) goto err;
456
457 if (!EC_GROUP_get_order(group, order, ctx)) return 0;
458 if (BN_is_zero(order))
459 {
460 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
461 goto err;
462 }
463
464 /* TODO */
465
466 ret = 1;
467
468 err:
469 BN_CTX_end(ctx);
470 if (new_ctx != NULL)
471 BN_CTX_free(new_ctx);
472 return ret;
473 }
diff --git a/src/lib/libssl/src/crypto/ec/ecp_mont.c b/src/lib/libssl/src/crypto/ec/ecp_mont.c
new file mode 100644
index 0000000000..7b30d4c38a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ecp_mont.c
@@ -0,0 +1,304 @@
1/* crypto/ec/ecp_mont.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61const EC_METHOD *EC_GFp_mont_method(void)
62 {
63 static const EC_METHOD ret = {
64 ec_GFp_mont_group_init,
65 ec_GFp_mont_group_finish,
66 ec_GFp_mont_group_clear_finish,
67 ec_GFp_mont_group_copy,
68 ec_GFp_mont_group_set_curve_GFp,
69 ec_GFp_simple_group_get_curve_GFp,
70 ec_GFp_simple_group_set_generator,
71 ec_GFp_simple_group_get0_generator,
72 ec_GFp_simple_group_get_order,
73 ec_GFp_simple_group_get_cofactor,
74 ec_GFp_simple_point_init,
75 ec_GFp_simple_point_finish,
76 ec_GFp_simple_point_clear_finish,
77 ec_GFp_simple_point_copy,
78 ec_GFp_simple_point_set_to_infinity,
79 ec_GFp_simple_set_Jprojective_coordinates_GFp,
80 ec_GFp_simple_get_Jprojective_coordinates_GFp,
81 ec_GFp_simple_point_set_affine_coordinates_GFp,
82 ec_GFp_simple_point_get_affine_coordinates_GFp,
83 ec_GFp_simple_set_compressed_coordinates_GFp,
84 ec_GFp_simple_point2oct,
85 ec_GFp_simple_oct2point,
86 ec_GFp_simple_add,
87 ec_GFp_simple_dbl,
88 ec_GFp_simple_invert,
89 ec_GFp_simple_is_at_infinity,
90 ec_GFp_simple_is_on_curve,
91 ec_GFp_simple_cmp,
92 ec_GFp_simple_make_affine,
93 ec_GFp_simple_points_make_affine,
94 ec_GFp_mont_field_mul,
95 ec_GFp_mont_field_sqr,
96 ec_GFp_mont_field_encode,
97 ec_GFp_mont_field_decode,
98 ec_GFp_mont_field_set_to_one };
99
100 return &ret;
101 }
102
103
104int ec_GFp_mont_group_init(EC_GROUP *group)
105 {
106 int ok;
107
108 ok = ec_GFp_simple_group_init(group);
109 group->field_data1 = NULL;
110 group->field_data2 = NULL;
111 return ok;
112 }
113
114
115int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
116 {
117 BN_CTX *new_ctx = NULL;
118 BN_MONT_CTX *mont = NULL;
119 BIGNUM *one = NULL;
120 int ret = 0;
121
122 if (group->field_data1 != NULL)
123 {
124 BN_MONT_CTX_free(group->field_data1);
125 group->field_data1 = NULL;
126 }
127 if (group->field_data2 != NULL)
128 {
129 BN_free(group->field_data2);
130 group->field_data2 = NULL;
131 }
132
133 if (ctx == NULL)
134 {
135 ctx = new_ctx = BN_CTX_new();
136 if (ctx == NULL)
137 return 0;
138 }
139
140 mont = BN_MONT_CTX_new();
141 if (mont == NULL) goto err;
142 if (!BN_MONT_CTX_set(mont, p, ctx))
143 {
144 ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP, ERR_R_BN_LIB);
145 goto err;
146 }
147 one = BN_new();
148 if (one == NULL) goto err;
149 if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) goto err;
150
151 group->field_data1 = mont;
152 mont = NULL;
153 group->field_data2 = one;
154 one = NULL;
155
156 ret = ec_GFp_simple_group_set_curve_GFp(group, p, a, b, ctx);
157
158 if (!ret)
159 {
160 BN_MONT_CTX_free(group->field_data1);
161 group->field_data1 = NULL;
162 BN_free(group->field_data2);
163 group->field_data2 = NULL;
164 }
165
166 err:
167 if (new_ctx != NULL)
168 BN_CTX_free(new_ctx);
169 if (mont != NULL)
170 BN_MONT_CTX_free(mont);
171 return ret;
172 }
173
174
175void ec_GFp_mont_group_finish(EC_GROUP *group)
176 {
177 if (group->field_data1 != NULL)
178 {
179 BN_MONT_CTX_free(group->field_data1);
180 group->field_data1 = NULL;
181 }
182 if (group->field_data2 != NULL)
183 {
184 BN_free(group->field_data2);
185 group->field_data2 = NULL;
186 }
187 ec_GFp_simple_group_finish(group);
188 }
189
190
191void ec_GFp_mont_group_clear_finish(EC_GROUP *group)
192 {
193 if (group->field_data1 != NULL)
194 {
195 BN_MONT_CTX_free(group->field_data1);
196 group->field_data1 = NULL;
197 }
198 if (group->field_data2 != NULL)
199 {
200 BN_clear_free(group->field_data2);
201 group->field_data2 = NULL;
202 }
203 ec_GFp_simple_group_clear_finish(group);
204 }
205
206
207int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
208 {
209 if (dest->field_data1 != NULL)
210 {
211 BN_MONT_CTX_free(dest->field_data1);
212 dest->field_data1 = NULL;
213 }
214 if (dest->field_data2 != NULL)
215 {
216 BN_clear_free(dest->field_data2);
217 dest->field_data2 = NULL;
218 }
219
220 if (!ec_GFp_simple_group_copy(dest, src)) return 0;
221
222 if (src->field_data1 != NULL)
223 {
224 dest->field_data1 = BN_MONT_CTX_new();
225 if (dest->field_data1 == NULL) return 0;
226 if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1)) goto err;
227 }
228 if (src->field_data2 != NULL)
229 {
230 dest->field_data2 = BN_dup(src->field_data2);
231 if (dest->field_data2 == NULL) goto err;
232 }
233
234 return 1;
235
236 err:
237 if (dest->field_data1 != NULL)
238 {
239 BN_MONT_CTX_free(dest->field_data1);
240 dest->field_data1 = NULL;
241 }
242 return 0;
243 }
244
245
246int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
247 {
248 if (group->field_data1 == NULL)
249 {
250 ECerr(EC_F_EC_GFP_MONT_FIELD_MUL, EC_R_NOT_INITIALIZED);
251 return 0;
252 }
253
254 return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx);
255 }
256
257
258int ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
259 {
260 if (group->field_data1 == NULL)
261 {
262 ECerr(EC_F_EC_GFP_MONT_FIELD_SQR, EC_R_NOT_INITIALIZED);
263 return 0;
264 }
265
266 return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);
267 }
268
269
270int ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
271 {
272 if (group->field_data1 == NULL)
273 {
274 ECerr(EC_F_EC_GFP_MONT_FIELD_ENCODE, EC_R_NOT_INITIALIZED);
275 return 0;
276 }
277
278 return BN_to_montgomery(r, a, (BN_MONT_CTX *)group->field_data1, ctx);
279 }
280
281
282int ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
283 {
284 if (group->field_data1 == NULL)
285 {
286 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
287 return 0;
288 }
289
290 return BN_from_montgomery(r, a, group->field_data1, ctx);
291 }
292
293
294int ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
295 {
296 if (group->field_data2 == NULL)
297 {
298 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
299 return 0;
300 }
301
302 if (!BN_copy(r, group->field_data2)) return 0;
303 return 1;
304 }
diff --git a/src/lib/libssl/src/crypto/ec/ecp_nist.c b/src/lib/libssl/src/crypto/ec/ecp_nist.c
new file mode 100644
index 0000000000..ed07748675
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ecp_nist.c
@@ -0,0 +1,134 @@
1/* crypto/ec/ecp_nist.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_nist_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_nist_group_init,
63 ec_GFp_nist_group_finish,
64 ec_GFp_nist_group_clear_finish,
65 ec_GFp_nist_group_copy,
66 ec_GFp_nist_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_nist_field_mul,
93 ec_GFp_nist_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102
103int ec_GFp_nist_group_init(EC_GROUP *group)
104 {
105 int ok;
106
107 ok = ec_GFp_simple_group_init(group);
108 group->field_data1 = NULL;
109 return ok;
110 }
111
112
113int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
114/* TODO */
115
116
117void ec_GFp_nist_group_finish(EC_GROUP *group);
118/* TODO */
119
120
121void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
122/* TODO */
123
124
125int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
126/* TODO */
127
128
129int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
130/* TODO */
131
132
133int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
134/* TODO */
diff --git a/src/lib/libssl/src/crypto/ec/ecp_recp.c b/src/lib/libssl/src/crypto/ec/ecp_recp.c
new file mode 100644
index 0000000000..fec843b5c8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ecp_recp.c
@@ -0,0 +1,133 @@
1/* crypto/ec/ecp_recp.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_recp_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_recp_group_init,
63 ec_GFp_recp_group_finish,
64 ec_GFp_recp_group_clear_finish,
65 ec_GFp_recp_group_copy,
66 ec_GFp_recp_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_recp_field_mul,
93 ec_GFp_recp_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102int ec_GFp_recp_group_init(EC_GROUP *group)
103 {
104 int ok;
105
106 ok = ec_GFp_simple_group_init(group);
107 group->field_data1 = NULL;
108 return ok;
109 }
110
111
112int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
113/* TODO */
114
115
116void ec_GFp_recp_group_finish(EC_GROUP *group);
117/* TODO */
118
119
120void ec_GFp_recp_group_clear_finish(EC_GROUP *group);
121/* TODO */
122
123
124int ec_GFp_recp_group_copy(EC_GROUP *dest, const EC_GROUP *src);
125/* TODO */
126
127
128int ec_GFp_recp_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
129/* TODO */
130
131
132int ec_GFp_recp_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
133/* TODO */
diff --git a/src/lib/libssl/src/crypto/ec/ecp_smpl.c b/src/lib/libssl/src/crypto/ec/ecp_smpl.c
new file mode 100644
index 0000000000..4666a052bf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ecp_smpl.c
@@ -0,0 +1,1717 @@
1/* crypto/ec/ecp_smpl.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <openssl/err.h>
59
60#include "ec_lcl.h"
61
62
63const EC_METHOD *EC_GFp_simple_method(void)
64 {
65 static const EC_METHOD ret = {
66 ec_GFp_simple_group_init,
67 ec_GFp_simple_group_finish,
68 ec_GFp_simple_group_clear_finish,
69 ec_GFp_simple_group_copy,
70 ec_GFp_simple_group_set_curve_GFp,
71 ec_GFp_simple_group_get_curve_GFp,
72 ec_GFp_simple_group_set_generator,
73 ec_GFp_simple_group_get0_generator,
74 ec_GFp_simple_group_get_order,
75 ec_GFp_simple_group_get_cofactor,
76 ec_GFp_simple_point_init,
77 ec_GFp_simple_point_finish,
78 ec_GFp_simple_point_clear_finish,
79 ec_GFp_simple_point_copy,
80 ec_GFp_simple_point_set_to_infinity,
81 ec_GFp_simple_set_Jprojective_coordinates_GFp,
82 ec_GFp_simple_get_Jprojective_coordinates_GFp,
83 ec_GFp_simple_point_set_affine_coordinates_GFp,
84 ec_GFp_simple_point_get_affine_coordinates_GFp,
85 ec_GFp_simple_set_compressed_coordinates_GFp,
86 ec_GFp_simple_point2oct,
87 ec_GFp_simple_oct2point,
88 ec_GFp_simple_add,
89 ec_GFp_simple_dbl,
90 ec_GFp_simple_invert,
91 ec_GFp_simple_is_at_infinity,
92 ec_GFp_simple_is_on_curve,
93 ec_GFp_simple_cmp,
94 ec_GFp_simple_make_affine,
95 ec_GFp_simple_points_make_affine,
96 ec_GFp_simple_field_mul,
97 ec_GFp_simple_field_sqr,
98 0 /* field_encode */,
99 0 /* field_decode */,
100 0 /* field_set_to_one */ };
101
102 return &ret;
103 }
104
105
106int ec_GFp_simple_group_init(EC_GROUP *group)
107 {
108 BN_init(&group->field);
109 BN_init(&group->a);
110 BN_init(&group->b);
111 group->a_is_minus3 = 0;
112 group->generator = NULL;
113 BN_init(&group->order);
114 BN_init(&group->cofactor);
115 return 1;
116 }
117
118
119void ec_GFp_simple_group_finish(EC_GROUP *group)
120 {
121 BN_free(&group->field);
122 BN_free(&group->a);
123 BN_free(&group->b);
124 if (group->generator != NULL)
125 EC_POINT_free(group->generator);
126 BN_free(&group->order);
127 BN_free(&group->cofactor);
128 }
129
130
131void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
132 {
133 BN_clear_free(&group->field);
134 BN_clear_free(&group->a);
135 BN_clear_free(&group->b);
136 if (group->generator != NULL)
137 {
138 EC_POINT_clear_free(group->generator);
139 group->generator = NULL;
140 }
141 BN_clear_free(&group->order);
142 BN_clear_free(&group->cofactor);
143 }
144
145
146int ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
147 {
148 if (!BN_copy(&dest->field, &src->field)) return 0;
149 if (!BN_copy(&dest->a, &src->a)) return 0;
150 if (!BN_copy(&dest->b, &src->b)) return 0;
151
152 dest->a_is_minus3 = src->a_is_minus3;
153
154 if (src->generator != NULL)
155 {
156 if (dest->generator == NULL)
157 {
158 dest->generator = EC_POINT_new(dest);
159 if (dest->generator == NULL) return 0;
160 }
161 if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
162 }
163 else
164 {
165 /* src->generator == NULL */
166 if (dest->generator != NULL)
167 {
168 EC_POINT_clear_free(dest->generator);
169 dest->generator = NULL;
170 }
171 }
172
173 if (!BN_copy(&dest->order, &src->order)) return 0;
174 if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
175
176 return 1;
177 }
178
179
180int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *group,
181 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
182 {
183 int ret = 0;
184 BN_CTX *new_ctx = NULL;
185 BIGNUM *tmp_a;
186
187 /* p must be a prime > 3 */
188 if (BN_num_bits(p) <= 2 || !BN_is_odd(p))
189 {
190 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP, EC_R_INVALID_FIELD);
191 return 0;
192 }
193
194 if (ctx == NULL)
195 {
196 ctx = new_ctx = BN_CTX_new();
197 if (ctx == NULL)
198 return 0;
199 }
200
201 BN_CTX_start(ctx);
202 tmp_a = BN_CTX_get(ctx);
203 if (tmp_a == NULL) goto err;
204
205 /* group->field */
206 if (!BN_copy(&group->field, p)) goto err;
207 group->field.neg = 0;
208
209 /* group->a */
210 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
211 if (group->meth->field_encode)
212 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
213 else
214 if (!BN_copy(&group->a, tmp_a)) goto err;
215
216 /* group->b */
217 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
218 if (group->meth->field_encode)
219 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
220
221 /* group->a_is_minus3 */
222 if (!BN_add_word(tmp_a, 3)) goto err;
223 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
224
225 ret = 1;
226
227 err:
228 BN_CTX_end(ctx);
229 if (new_ctx != NULL)
230 BN_CTX_free(new_ctx);
231 return ret;
232 }
233
234
235int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
236 {
237 int ret = 0;
238 BN_CTX *new_ctx = NULL;
239
240 if (p != NULL)
241 {
242 if (!BN_copy(p, &group->field)) return 0;
243 }
244
245 if (a != NULL || b != NULL)
246 {
247 if (group->meth->field_decode)
248 {
249 if (ctx == NULL)
250 {
251 ctx = new_ctx = BN_CTX_new();
252 if (ctx == NULL)
253 return 0;
254 }
255 if (a != NULL)
256 {
257 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
258 }
259 if (b != NULL)
260 {
261 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
262 }
263 }
264 else
265 {
266 if (a != NULL)
267 {
268 if (!BN_copy(a, &group->a)) goto err;
269 }
270 if (b != NULL)
271 {
272 if (!BN_copy(b, &group->b)) goto err;
273 }
274 }
275 }
276
277 ret = 1;
278
279 err:
280 if (new_ctx)
281 BN_CTX_free(new_ctx);
282 return ret;
283 }
284
285
286
287int ec_GFp_simple_group_set_generator(EC_GROUP *group, const EC_POINT *generator,
288 const BIGNUM *order, const BIGNUM *cofactor)
289 {
290 if (generator == NULL)
291 {
292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
293 return 0 ;
294 }
295
296 if (group->generator == NULL)
297 {
298 group->generator = EC_POINT_new(group);
299 if (group->generator == NULL) return 0;
300 }
301 if (!EC_POINT_copy(group->generator, generator)) return 0;
302
303 if (order != NULL)
304 { if (!BN_copy(&group->order, order)) return 0; }
305 else
306 { if (!BN_zero(&group->order)) return 0; }
307
308 if (cofactor != NULL)
309 { if (!BN_copy(&group->cofactor, cofactor)) return 0; }
310 else
311 { if (!BN_zero(&group->cofactor)) return 0; }
312
313 return 1;
314 }
315
316
317EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *group)
318 {
319 return group->generator;
320 }
321
322
323int ec_GFp_simple_group_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
324 {
325 if (!BN_copy(order, &group->order))
326 return 0;
327
328 return !BN_is_zero(&group->order);
329 }
330
331
332int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
333 {
334 if (!BN_copy(cofactor, &group->cofactor))
335 return 0;
336
337 return !BN_is_zero(&group->cofactor);
338 }
339
340
341int ec_GFp_simple_point_init(EC_POINT *point)
342 {
343 BN_init(&point->X);
344 BN_init(&point->Y);
345 BN_init(&point->Z);
346 point->Z_is_one = 0;
347
348 return 1;
349 }
350
351
352void ec_GFp_simple_point_finish(EC_POINT *point)
353 {
354 BN_free(&point->X);
355 BN_free(&point->Y);
356 BN_free(&point->Z);
357 }
358
359
360void ec_GFp_simple_point_clear_finish(EC_POINT *point)
361 {
362 BN_clear_free(&point->X);
363 BN_clear_free(&point->Y);
364 BN_clear_free(&point->Z);
365 point->Z_is_one = 0;
366 }
367
368
369int ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
370 {
371 if (!BN_copy(&dest->X, &src->X)) return 0;
372 if (!BN_copy(&dest->Y, &src->Y)) return 0;
373 if (!BN_copy(&dest->Z, &src->Z)) return 0;
374 dest->Z_is_one = src->Z_is_one;
375
376 return 1;
377 }
378
379
380int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
381 {
382 point->Z_is_one = 0;
383 return (BN_zero(&point->Z));
384 }
385
386
387int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
388 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
389 {
390 BN_CTX *new_ctx = NULL;
391 int ret = 0;
392
393 if (ctx == NULL)
394 {
395 ctx = new_ctx = BN_CTX_new();
396 if (ctx == NULL)
397 return 0;
398 }
399
400 if (x != NULL)
401 {
402 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
403 if (group->meth->field_encode)
404 {
405 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
406 }
407 }
408
409 if (y != NULL)
410 {
411 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
412 if (group->meth->field_encode)
413 {
414 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
415 }
416 }
417
418 if (z != NULL)
419 {
420 int Z_is_one;
421
422 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
423 Z_is_one = BN_is_one(&point->Z);
424 if (group->meth->field_encode)
425 {
426 if (Z_is_one && (group->meth->field_set_to_one != 0))
427 {
428 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
429 }
430 else
431 {
432 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
433 }
434 }
435 point->Z_is_one = Z_is_one;
436 }
437
438 ret = 1;
439
440 err:
441 if (new_ctx != NULL)
442 BN_CTX_free(new_ctx);
443 return ret;
444 }
445
446
447int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
448 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
449 {
450 BN_CTX *new_ctx = NULL;
451 int ret = 0;
452
453 if (group->meth->field_decode != 0)
454 {
455 if (ctx == NULL)
456 {
457 ctx = new_ctx = BN_CTX_new();
458 if (ctx == NULL)
459 return 0;
460 }
461
462 if (x != NULL)
463 {
464 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
465 }
466 if (y != NULL)
467 {
468 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
469 }
470 if (z != NULL)
471 {
472 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
473 }
474 }
475 else
476 {
477 if (x != NULL)
478 {
479 if (!BN_copy(x, &point->X)) goto err;
480 }
481 if (y != NULL)
482 {
483 if (!BN_copy(y, &point->Y)) goto err;
484 }
485 if (z != NULL)
486 {
487 if (!BN_copy(z, &point->Z)) goto err;
488 }
489 }
490
491 ret = 1;
492
493 err:
494 if (new_ctx != NULL)
495 BN_CTX_free(new_ctx);
496 return ret;
497 }
498
499
500int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
501 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
502 {
503 if (x == NULL || y == NULL)
504 {
505 /* unlike for projective coordinates, we do not tolerate this */
506 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_PASSED_NULL_PARAMETER);
507 return 0;
508 }
509
510 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
511 }
512
513
514int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
515 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
516 {
517 BN_CTX *new_ctx = NULL;
518 BIGNUM *X, *Y, *Z, *Z_1, *Z_2, *Z_3;
519 const BIGNUM *X_, *Y_, *Z_;
520 int ret = 0;
521
522 if (EC_POINT_is_at_infinity(group, point))
523 {
524 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_POINT_AT_INFINITY);
525 return 0;
526 }
527
528 if (ctx == NULL)
529 {
530 ctx = new_ctx = BN_CTX_new();
531 if (ctx == NULL)
532 return 0;
533 }
534
535 BN_CTX_start(ctx);
536 X = BN_CTX_get(ctx);
537 Y = BN_CTX_get(ctx);
538 Z = BN_CTX_get(ctx);
539 Z_1 = BN_CTX_get(ctx);
540 Z_2 = BN_CTX_get(ctx);
541 Z_3 = BN_CTX_get(ctx);
542 if (Z_3 == NULL) goto err;
543
544 /* transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3) */
545
546 if (group->meth->field_decode)
547 {
548 if (!group->meth->field_decode(group, X, &point->X, ctx)) goto err;
549 if (!group->meth->field_decode(group, Y, &point->Y, ctx)) goto err;
550 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
551 X_ = X; Y_ = Y; Z_ = Z;
552 }
553 else
554 {
555 X_ = &point->X;
556 Y_ = &point->Y;
557 Z_ = &point->Z;
558 }
559
560 if (BN_is_one(Z_))
561 {
562 if (x != NULL)
563 {
564 if (!BN_copy(x, X_)) goto err;
565 }
566 if (y != NULL)
567 {
568 if (!BN_copy(y, Y_)) goto err;
569 }
570 }
571 else
572 {
573 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
574 {
575 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_BN_LIB);
576 goto err;
577 }
578
579 if (group->meth->field_encode == 0)
580 {
581 /* field_sqr works on standard representation */
582 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
583 }
584 else
585 {
586 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;
587 }
588
589 if (x != NULL)
590 {
591 if (group->meth->field_encode == 0)
592 {
593 /* field_mul works on standard representation */
594 if (!group->meth->field_mul(group, x, X_, Z_2, ctx)) goto err;
595 }
596 else
597 {
598 if (!BN_mod_mul(x, X_, Z_2, &group->field, ctx)) goto err;
599 }
600 }
601
602 if (y != NULL)
603 {
604 if (group->meth->field_encode == 0)
605 {
606 /* field_mul works on standard representation */
607 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
608 if (!group->meth->field_mul(group, y, Y_, Z_3, ctx)) goto err;
609
610 }
611 else
612 {
613 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
614 if (!BN_mod_mul(y, Y_, Z_3, &group->field, ctx)) goto err;
615 }
616 }
617 }
618
619 ret = 1;
620
621 err:
622 BN_CTX_end(ctx);
623 if (new_ctx != NULL)
624 BN_CTX_free(new_ctx);
625 return ret;
626 }
627
628
629int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
630 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
631 {
632 BN_CTX *new_ctx = NULL;
633 BIGNUM *tmp1, *tmp2, *x, *y;
634 int ret = 0;
635
636 if (ctx == NULL)
637 {
638 ctx = new_ctx = BN_CTX_new();
639 if (ctx == NULL)
640 return 0;
641 }
642
643 y_bit = (y_bit != 0);
644
645 BN_CTX_start(ctx);
646 tmp1 = BN_CTX_get(ctx);
647 tmp2 = BN_CTX_get(ctx);
648 x = BN_CTX_get(ctx);
649 y = BN_CTX_get(ctx);
650 if (y == NULL) goto err;
651
652 /* Recover y. We have a Weierstrass equation
653 * y^2 = x^3 + a*x + b,
654 * so y is one of the square roots of x^3 + a*x + b.
655 */
656
657 /* tmp1 := x^3 */
658 if (!BN_nnmod(x, x_, &group->field,ctx)) goto err;
659 if (group->meth->field_decode == 0)
660 {
661 /* field_{sqr,mul} work on standard representation */
662 if (!group->meth->field_sqr(group, tmp2, x_, ctx)) goto err;
663 if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx)) goto err;
664 }
665 else
666 {
667 if (!BN_mod_sqr(tmp2, x_, &group->field, ctx)) goto err;
668 if (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx)) goto err;
669 }
670
671 /* tmp1 := tmp1 + a*x */
672 if (group->a_is_minus3)
673 {
674 if (!BN_mod_lshift1_quick(tmp2, x, &group->field)) goto err;
675 if (!BN_mod_add_quick(tmp2, tmp2, x, &group->field)) goto err;
676 if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
677 }
678 else
679 {
680 if (group->meth->field_decode)
681 {
682 if (!group->meth->field_decode(group, tmp2, &group->a, ctx)) goto err;
683 if (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx)) goto err;
684 }
685 else
686 {
687 /* field_mul works on standard representation */
688 if (!group->meth->field_mul(group, tmp2, &group->a, x, ctx)) goto err;
689 }
690
691 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
692 }
693
694 /* tmp1 := tmp1 + b */
695 if (group->meth->field_decode)
696 {
697 if (!group->meth->field_decode(group, tmp2, &group->b, ctx)) goto err;
698 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
699 }
700 else
701 {
702 if (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field)) goto err;
703 }
704
705 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx))
706 {
707 unsigned long err = ERR_peek_error();
708
709 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)
710 {
711 (void)ERR_get_error();
712 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
713 }
714 else
715 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_BN_LIB);
716 goto err;
717 }
718 /* If tmp1 is not a square (i.e. there is no point on the curve with
719 * our x), then y now is a nonsense value too */
720
721 if (y_bit != BN_is_odd(y))
722 {
723 if (BN_is_zero(y))
724 {
725 int kron;
726
727 kron = BN_kronecker(x, &group->field, ctx);
728 if (kron == -2) goto err;
729
730 if (kron == 1)
731 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSION_BIT);
732 else
733 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
734 goto err;
735 }
736 if (!BN_usub(y, &group->field, y)) goto err;
737 }
738 if (y_bit != BN_is_odd(y))
739 {
740 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_INTERNAL_ERROR);
741 goto err;
742 }
743
744 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
745
746 ret = 1;
747
748 err:
749 BN_CTX_end(ctx);
750 if (new_ctx != NULL)
751 BN_CTX_free(new_ctx);
752 return ret;
753 }
754
755
756size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
757 unsigned char *buf, size_t len, BN_CTX *ctx)
758 {
759 size_t ret;
760 BN_CTX *new_ctx = NULL;
761 int used_ctx = 0;
762 BIGNUM *x, *y;
763 size_t field_len, i, skip;
764
765 if ((form != POINT_CONVERSION_COMPRESSED)
766 && (form != POINT_CONVERSION_UNCOMPRESSED)
767 && (form != POINT_CONVERSION_HYBRID))
768 {
769 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM);
770 goto err;
771 }
772
773 if (EC_POINT_is_at_infinity(group, point))
774 {
775 /* encodes to a single 0 octet */
776 if (buf != NULL)
777 {
778 if (len < 1)
779 {
780 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
781 return 0;
782 }
783 buf[0] = 0;
784 }
785 return 1;
786 }
787
788
789 /* ret := required output buffer length */
790 field_len = BN_num_bytes(&group->field);
791 ret = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
792
793 /* if 'buf' is NULL, just return required length */
794 if (buf != NULL)
795 {
796 if (len < ret)
797 {
798 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
799 goto err;
800 }
801
802 if (ctx == NULL)
803 {
804 ctx = new_ctx = BN_CTX_new();
805 if (ctx == NULL)
806 return 0;
807 }
808
809 BN_CTX_start(ctx);
810 used_ctx = 1;
811 x = BN_CTX_get(ctx);
812 y = BN_CTX_get(ctx);
813 if (y == NULL) goto err;
814
815 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
816
817 if ((form == POINT_CONVERSION_COMPRESSED || form == POINT_CONVERSION_HYBRID) && BN_is_odd(y))
818 buf[0] = form + 1;
819 else
820 buf[0] = form;
821
822 i = 1;
823
824 skip = field_len - BN_num_bytes(x);
825 if (skip > field_len)
826 {
827 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
828 goto err;
829 }
830 while (skip > 0)
831 {
832 buf[i++] = 0;
833 skip--;
834 }
835 skip = BN_bn2bin(x, buf + i);
836 i += skip;
837 if (i != 1 + field_len)
838 {
839 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
840 goto err;
841 }
842
843 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID)
844 {
845 skip = field_len - BN_num_bytes(y);
846 if (skip > field_len)
847 {
848 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
849 goto err;
850 }
851 while (skip > 0)
852 {
853 buf[i++] = 0;
854 skip--;
855 }
856 skip = BN_bn2bin(y, buf + i);
857 i += skip;
858 }
859
860 if (i != ret)
861 {
862 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
863 goto err;
864 }
865 }
866
867 if (used_ctx)
868 BN_CTX_end(ctx);
869 if (new_ctx != NULL)
870 BN_CTX_free(new_ctx);
871 return ret;
872
873 err:
874 if (used_ctx)
875 BN_CTX_end(ctx);
876 if (new_ctx != NULL)
877 BN_CTX_free(new_ctx);
878 return 0;
879 }
880
881
882int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
883 const unsigned char *buf, size_t len, BN_CTX *ctx)
884 {
885 point_conversion_form_t form;
886 int y_bit;
887 BN_CTX *new_ctx = NULL;
888 BIGNUM *x, *y;
889 size_t field_len, enc_len;
890 int ret = 0;
891
892 if (len == 0)
893 {
894 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);
895 return 0;
896 }
897 form = buf[0];
898 y_bit = form & 1;
899 form = form & ~1;
900 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
901 && (form != POINT_CONVERSION_UNCOMPRESSED)
902 && (form != POINT_CONVERSION_HYBRID))
903 {
904 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
905 return 0;
906 }
907 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit)
908 {
909 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
910 return 0;
911 }
912
913 if (form == 0)
914 {
915 if (len != 1)
916 {
917 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
918 return 0;
919 }
920
921 return EC_POINT_set_to_infinity(group, point);
922 }
923
924 field_len = BN_num_bytes(&group->field);
925 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
926
927 if (len != enc_len)
928 {
929 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
930 return 0;
931 }
932
933 if (ctx == NULL)
934 {
935 ctx = new_ctx = BN_CTX_new();
936 if (ctx == NULL)
937 return 0;
938 }
939
940 BN_CTX_start(ctx);
941 x = BN_CTX_get(ctx);
942 y = BN_CTX_get(ctx);
943 if (y == NULL) goto err;
944
945 if (!BN_bin2bn(buf + 1, field_len, x)) goto err;
946 if (BN_ucmp(x, &group->field) >= 0)
947 {
948 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
949 goto err;
950 }
951
952 if (form == POINT_CONVERSION_COMPRESSED)
953 {
954 if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) goto err;
955 }
956 else
957 {
958 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err;
959 if (BN_ucmp(y, &group->field) >= 0)
960 {
961 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
962 goto err;
963 }
964 if (form == POINT_CONVERSION_HYBRID)
965 {
966 if (y_bit != BN_is_odd(y))
967 {
968 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
969 goto err;
970 }
971 }
972
973 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
974 }
975
976 if (!EC_POINT_is_on_curve(group, point, ctx)) /* test required by X9.62 */
977 {
978 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);
979 goto err;
980 }
981
982 ret = 1;
983
984 err:
985 BN_CTX_end(ctx);
986 if (new_ctx != NULL)
987 BN_CTX_free(new_ctx);
988 return ret;
989 }
990
991
992int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
993 {
994 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
995 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
996 const BIGNUM *p;
997 BN_CTX *new_ctx = NULL;
998 BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;
999 int ret = 0;
1000
1001 if (a == b)
1002 return EC_POINT_dbl(group, r, a, ctx);
1003 if (EC_POINT_is_at_infinity(group, a))
1004 return EC_POINT_copy(r, b);
1005 if (EC_POINT_is_at_infinity(group, b))
1006 return EC_POINT_copy(r, a);
1007
1008 field_mul = group->meth->field_mul;
1009 field_sqr = group->meth->field_sqr;
1010 p = &group->field;
1011
1012 if (ctx == NULL)
1013 {
1014 ctx = new_ctx = BN_CTX_new();
1015 if (ctx == NULL)
1016 return 0;
1017 }
1018
1019 BN_CTX_start(ctx);
1020 n0 = BN_CTX_get(ctx);
1021 n1 = BN_CTX_get(ctx);
1022 n2 = BN_CTX_get(ctx);
1023 n3 = BN_CTX_get(ctx);
1024 n4 = BN_CTX_get(ctx);
1025 n5 = BN_CTX_get(ctx);
1026 n6 = BN_CTX_get(ctx);
1027 if (n6 == NULL) goto end;
1028
1029 /* Note that in this function we must not read components of 'a' or 'b'
1030 * once we have written the corresponding components of 'r'.
1031 * ('r' might be one of 'a' or 'b'.)
1032 */
1033
1034 /* n1, n2 */
1035 if (b->Z_is_one)
1036 {
1037 if (!BN_copy(n1, &a->X)) goto end;
1038 if (!BN_copy(n2, &a->Y)) goto end;
1039 /* n1 = X_a */
1040 /* n2 = Y_a */
1041 }
1042 else
1043 {
1044 if (!field_sqr(group, n0, &b->Z, ctx)) goto end;
1045 if (!field_mul(group, n1, &a->X, n0, ctx)) goto end;
1046 /* n1 = X_a * Z_b^2 */
1047
1048 if (!field_mul(group, n0, n0, &b->Z, ctx)) goto end;
1049 if (!field_mul(group, n2, &a->Y, n0, ctx)) goto end;
1050 /* n2 = Y_a * Z_b^3 */
1051 }
1052
1053 /* n3, n4 */
1054 if (a->Z_is_one)
1055 {
1056 if (!BN_copy(n3, &b->X)) goto end;
1057 if (!BN_copy(n4, &b->Y)) goto end;
1058 /* n3 = X_b */
1059 /* n4 = Y_b */
1060 }
1061 else
1062 {
1063 if (!field_sqr(group, n0, &a->Z, ctx)) goto end;
1064 if (!field_mul(group, n3, &b->X, n0, ctx)) goto end;
1065 /* n3 = X_b * Z_a^2 */
1066
1067 if (!field_mul(group, n0, n0, &a->Z, ctx)) goto end;
1068 if (!field_mul(group, n4, &b->Y, n0, ctx)) goto end;
1069 /* n4 = Y_b * Z_a^3 */
1070 }
1071
1072 /* n5, n6 */
1073 if (!BN_mod_sub_quick(n5, n1, n3, p)) goto end;
1074 if (!BN_mod_sub_quick(n6, n2, n4, p)) goto end;
1075 /* n5 = n1 - n3 */
1076 /* n6 = n2 - n4 */
1077
1078 if (BN_is_zero(n5))
1079 {
1080 if (BN_is_zero(n6))
1081 {
1082 /* a is the same point as b */
1083 BN_CTX_end(ctx);
1084 ret = EC_POINT_dbl(group, r, a, ctx);
1085 ctx = NULL;
1086 goto end;
1087 }
1088 else
1089 {
1090 /* a is the inverse of b */
1091 if (!BN_zero(&r->Z)) goto end;
1092 r->Z_is_one = 0;
1093 ret = 1;
1094 goto end;
1095 }
1096 }
1097
1098 /* 'n7', 'n8' */
1099 if (!BN_mod_add_quick(n1, n1, n3, p)) goto end;
1100 if (!BN_mod_add_quick(n2, n2, n4, p)) goto end;
1101 /* 'n7' = n1 + n3 */
1102 /* 'n8' = n2 + n4 */
1103
1104 /* Z_r */
1105 if (a->Z_is_one && b->Z_is_one)
1106 {
1107 if (!BN_copy(&r->Z, n5)) goto end;
1108 }
1109 else
1110 {
1111 if (a->Z_is_one)
1112 { if (!BN_copy(n0, &b->Z)) goto end; }
1113 else if (b->Z_is_one)
1114 { if (!BN_copy(n0, &a->Z)) goto end; }
1115 else
1116 { if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) goto end; }
1117 if (!field_mul(group, &r->Z, n0, n5, ctx)) goto end;
1118 }
1119 r->Z_is_one = 0;
1120 /* Z_r = Z_a * Z_b * n5 */
1121
1122 /* X_r */
1123 if (!field_sqr(group, n0, n6, ctx)) goto end;
1124 if (!field_sqr(group, n4, n5, ctx)) goto end;
1125 if (!field_mul(group, n3, n1, n4, ctx)) goto end;
1126 if (!BN_mod_sub_quick(&r->X, n0, n3, p)) goto end;
1127 /* X_r = n6^2 - n5^2 * 'n7' */
1128
1129 /* 'n9' */
1130 if (!BN_mod_lshift1_quick(n0, &r->X, p)) goto end;
1131 if (!BN_mod_sub_quick(n0, n3, n0, p)) goto end;
1132 /* n9 = n5^2 * 'n7' - 2 * X_r */
1133
1134 /* Y_r */
1135 if (!field_mul(group, n0, n0, n6, ctx)) goto end;
1136 if (!field_mul(group, n5, n4, n5, ctx)) goto end; /* now n5 is n5^3 */
1137 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
1138 if (!BN_mod_sub_quick(n0, n0, n1, p)) goto end;
1139 if (BN_is_odd(n0))
1140 if (!BN_add(n0, n0, p)) goto end;
1141 /* now 0 <= n0 < 2*p, and n0 is even */
1142 if (!BN_rshift1(&r->Y, n0)) goto end;
1143 /* Y_r = (n6 * 'n9' - 'n8' * 'n5^3') / 2 */
1144
1145 ret = 1;
1146
1147 end:
1148 if (ctx) /* otherwise we already called BN_CTX_end */
1149 BN_CTX_end(ctx);
1150 if (new_ctx != NULL)
1151 BN_CTX_free(new_ctx);
1152 return ret;
1153 }
1154
1155
1156int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1157 {
1158 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1159 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1160 const BIGNUM *p;
1161 BN_CTX *new_ctx = NULL;
1162 BIGNUM *n0, *n1, *n2, *n3;
1163 int ret = 0;
1164
1165 if (EC_POINT_is_at_infinity(group, a))
1166 {
1167 if (!BN_zero(&r->Z)) return 0;
1168 r->Z_is_one = 0;
1169 return 1;
1170 }
1171
1172 field_mul = group->meth->field_mul;
1173 field_sqr = group->meth->field_sqr;
1174 p = &group->field;
1175
1176 if (ctx == NULL)
1177 {
1178 ctx = new_ctx = BN_CTX_new();
1179 if (ctx == NULL)
1180 return 0;
1181 }
1182
1183 BN_CTX_start(ctx);
1184 n0 = BN_CTX_get(ctx);
1185 n1 = BN_CTX_get(ctx);
1186 n2 = BN_CTX_get(ctx);
1187 n3 = BN_CTX_get(ctx);
1188 if (n3 == NULL) goto err;
1189
1190 /* Note that in this function we must not read components of 'a'
1191 * once we have written the corresponding components of 'r'.
1192 * ('r' might the same as 'a'.)
1193 */
1194
1195 /* n1 */
1196 if (a->Z_is_one)
1197 {
1198 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1199 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1200 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1201 if (!BN_mod_add_quick(n1, n0, &group->a, p)) goto err;
1202 /* n1 = 3 * X_a^2 + a_curve */
1203 }
1204 else if (group->a_is_minus3)
1205 {
1206 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1207 if (!BN_mod_add_quick(n0, &a->X, n1, p)) goto err;
1208 if (!BN_mod_sub_quick(n2, &a->X, n1, p)) goto err;
1209 if (!field_mul(group, n1, n0, n2, ctx)) goto err;
1210 if (!BN_mod_lshift1_quick(n0, n1, p)) goto err;
1211 if (!BN_mod_add_quick(n1, n0, n1, p)) goto err;
1212 /* n1 = 3 * (X_a + Z_a^2) * (X_a - Z_a^2)
1213 * = 3 * X_a^2 - 3 * Z_a^4 */
1214 }
1215 else
1216 {
1217 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1218 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1219 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1220 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1221 if (!field_sqr(group, n1, n1, ctx)) goto err;
1222 if (!field_mul(group, n1, n1, &group->a, ctx)) goto err;
1223 if (!BN_mod_add_quick(n1, n1, n0, p)) goto err;
1224 /* n1 = 3 * X_a^2 + a_curve * Z_a^4 */
1225 }
1226
1227 /* Z_r */
1228 if (a->Z_is_one)
1229 {
1230 if (!BN_copy(n0, &a->Y)) goto err;
1231 }
1232 else
1233 {
1234 if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) goto err;
1235 }
1236 if (!BN_mod_lshift1_quick(&r->Z, n0, p)) goto err;
1237 r->Z_is_one = 0;
1238 /* Z_r = 2 * Y_a * Z_a */
1239
1240 /* n2 */
1241 if (!field_sqr(group, n3, &a->Y, ctx)) goto err;
1242 if (!field_mul(group, n2, &a->X, n3, ctx)) goto err;
1243 if (!BN_mod_lshift_quick(n2, n2, 2, p)) goto err;
1244 /* n2 = 4 * X_a * Y_a^2 */
1245
1246 /* X_r */
1247 if (!BN_mod_lshift1_quick(n0, n2, p)) goto err;
1248 if (!field_sqr(group, &r->X, n1, ctx)) goto err;
1249 if (!BN_mod_sub_quick(&r->X, &r->X, n0, p)) goto err;
1250 /* X_r = n1^2 - 2 * n2 */
1251
1252 /* n3 */
1253 if (!field_sqr(group, n0, n3, ctx)) goto err;
1254 if (!BN_mod_lshift_quick(n3, n0, 3, p)) goto err;
1255 /* n3 = 8 * Y_a^4 */
1256
1257 /* Y_r */
1258 if (!BN_mod_sub_quick(n0, n2, &r->X, p)) goto err;
1259 if (!field_mul(group, n0, n1, n0, ctx)) goto err;
1260 if (!BN_mod_sub_quick(&r->Y, n0, n3, p)) goto err;
1261 /* Y_r = n1 * (n2 - X_r) - n3 */
1262
1263 ret = 1;
1264
1265 err:
1266 BN_CTX_end(ctx);
1267 if (new_ctx != NULL)
1268 BN_CTX_free(new_ctx);
1269 return ret;
1270 }
1271
1272
1273int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1274 {
1275 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
1276 /* point is its own inverse */
1277 return 1;
1278
1279 return BN_usub(&point->Y, &group->field, &point->Y);
1280 }
1281
1282
1283int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1284 {
1285 return BN_is_zero(&point->Z);
1286 }
1287
1288
1289int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
1290 {
1291 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1292 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1293 const BIGNUM *p;
1294 BN_CTX *new_ctx = NULL;
1295 BIGNUM *rh, *tmp1, *tmp2, *Z4, *Z6;
1296 int ret = -1;
1297
1298 if (EC_POINT_is_at_infinity(group, point))
1299 return 1;
1300
1301 field_mul = group->meth->field_mul;
1302 field_sqr = group->meth->field_sqr;
1303 p = &group->field;
1304
1305 if (ctx == NULL)
1306 {
1307 ctx = new_ctx = BN_CTX_new();
1308 if (ctx == NULL)
1309 return -1;
1310 }
1311
1312 BN_CTX_start(ctx);
1313 rh = BN_CTX_get(ctx);
1314 tmp1 = BN_CTX_get(ctx);
1315 tmp2 = BN_CTX_get(ctx);
1316 Z4 = BN_CTX_get(ctx);
1317 Z6 = BN_CTX_get(ctx);
1318 if (Z6 == NULL) goto err;
1319
1320 /* We have a curve defined by a Weierstrass equation
1321 * y^2 = x^3 + a*x + b.
1322 * The point to consider is given in Jacobian projective coordinates
1323 * where (X, Y, Z) represents (x, y) = (X/Z^2, Y/Z^3).
1324 * Substituting this and multiplying by Z^6 transforms the above equation into
1325 * Y^2 = X^3 + a*X*Z^4 + b*Z^6.
1326 * To test this, we add up the right-hand side in 'rh'.
1327 */
1328
1329 /* rh := X^3 */
1330 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
1331 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1332
1333 if (!point->Z_is_one)
1334 {
1335 if (!field_sqr(group, tmp1, &point->Z, ctx)) goto err;
1336 if (!field_sqr(group, Z4, tmp1, ctx)) goto err;
1337 if (!field_mul(group, Z6, Z4, tmp1, ctx)) goto err;
1338
1339 /* rh := rh + a*X*Z^4 */
1340 if (!field_mul(group, tmp1, &point->X, Z4, ctx)) goto err;
1341 if (group->a_is_minus3)
1342 {
1343 if (!BN_mod_lshift1_quick(tmp2, tmp1, p)) goto err;
1344 if (!BN_mod_add_quick(tmp2, tmp2, tmp1, p)) goto err;
1345 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1346 }
1347 else
1348 {
1349 if (!field_mul(group, tmp2, tmp1, &group->a, ctx)) goto err;
1350 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1351 }
1352
1353 /* rh := rh + b*Z^6 */
1354 if (!field_mul(group, tmp1, &group->b, Z6, ctx)) goto err;
1355 if (!BN_mod_add_quick(rh, rh, tmp1, p)) goto err;
1356 }
1357 else
1358 {
1359 /* point->Z_is_one */
1360
1361 /* rh := rh + a*X */
1362 if (group->a_is_minus3)
1363 {
1364 if (!BN_mod_lshift1_quick(tmp2, &point->X, p)) goto err;
1365 if (!BN_mod_add_quick(tmp2, tmp2, &point->X, p)) goto err;
1366 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1367 }
1368 else
1369 {
1370 if (!field_mul(group, tmp2, &point->X, &group->a, ctx)) goto err;
1371 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1372 }
1373
1374 /* rh := rh + b */
1375 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err;
1376 }
1377
1378 /* 'lh' := Y^2 */
1379 if (!field_sqr(group, tmp1, &point->Y, ctx)) goto err;
1380
1381 ret = (0 == BN_cmp(tmp1, rh));
1382
1383 err:
1384 BN_CTX_end(ctx);
1385 if (new_ctx != NULL)
1386 BN_CTX_free(new_ctx);
1387 return ret;
1388 }
1389
1390
1391int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1392 {
1393 /* return values:
1394 * -1 error
1395 * 0 equal (in affine coordinates)
1396 * 1 not equal
1397 */
1398
1399 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1400 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1401 BN_CTX *new_ctx = NULL;
1402 BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
1403 const BIGNUM *tmp1_, *tmp2_;
1404 int ret = -1;
1405
1406 if (EC_POINT_is_at_infinity(group, a))
1407 {
1408 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1409 }
1410
1411 if (a->Z_is_one && b->Z_is_one)
1412 {
1413 return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1;
1414 }
1415
1416 field_mul = group->meth->field_mul;
1417 field_sqr = group->meth->field_sqr;
1418
1419 if (ctx == NULL)
1420 {
1421 ctx = new_ctx = BN_CTX_new();
1422 if (ctx == NULL)
1423 return -1;
1424 }
1425
1426 BN_CTX_start(ctx);
1427 tmp1 = BN_CTX_get(ctx);
1428 tmp2 = BN_CTX_get(ctx);
1429 Za23 = BN_CTX_get(ctx);
1430 Zb23 = BN_CTX_get(ctx);
1431 if (Zb23 == NULL) goto end;
1432
1433 /* We have to decide whether
1434 * (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
1435 * or equivalently, whether
1436 * (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
1437 */
1438
1439 if (!b->Z_is_one)
1440 {
1441 if (!field_sqr(group, Zb23, &b->Z, ctx)) goto end;
1442 if (!field_mul(group, tmp1, &a->X, Zb23, ctx)) goto end;
1443 tmp1_ = tmp1;
1444 }
1445 else
1446 tmp1_ = &a->X;
1447 if (!a->Z_is_one)
1448 {
1449 if (!field_sqr(group, Za23, &a->Z, ctx)) goto end;
1450 if (!field_mul(group, tmp2, &b->X, Za23, ctx)) goto end;
1451 tmp2_ = tmp2;
1452 }
1453 else
1454 tmp2_ = &b->X;
1455
1456 /* compare X_a*Z_b^2 with X_b*Z_a^2 */
1457 if (BN_cmp(tmp1_, tmp2_) != 0)
1458 {
1459 ret = 1; /* points differ */
1460 goto end;
1461 }
1462
1463
1464 if (!b->Z_is_one)
1465 {
1466 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx)) goto end;
1467 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx)) goto end;
1468 /* tmp1_ = tmp1 */
1469 }
1470 else
1471 tmp1_ = &a->Y;
1472 if (!a->Z_is_one)
1473 {
1474 if (!field_mul(group, Za23, Za23, &a->Z, ctx)) goto end;
1475 if (!field_mul(group, tmp2, &b->Y, Za23, ctx)) goto end;
1476 /* tmp2_ = tmp2 */
1477 }
1478 else
1479 tmp2_ = &b->Y;
1480
1481 /* compare Y_a*Z_b^3 with Y_b*Z_a^3 */
1482 if (BN_cmp(tmp1_, tmp2_) != 0)
1483 {
1484 ret = 1; /* points differ */
1485 goto end;
1486 }
1487
1488 /* points are equal */
1489 ret = 0;
1490
1491 end:
1492 BN_CTX_end(ctx);
1493 if (new_ctx != NULL)
1494 BN_CTX_free(new_ctx);
1495 return ret;
1496 }
1497
1498
1499int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1500 {
1501 BN_CTX *new_ctx = NULL;
1502 BIGNUM *x, *y;
1503 int ret = 0;
1504
1505 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1506 return 1;
1507
1508 if (ctx == NULL)
1509 {
1510 ctx = new_ctx = BN_CTX_new();
1511 if (ctx == NULL)
1512 return 0;
1513 }
1514
1515 BN_CTX_start(ctx);
1516 x = BN_CTX_get(ctx);
1517 y = BN_CTX_get(ctx);
1518 if (y == NULL) goto err;
1519
1520 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1521 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1522 if (!point->Z_is_one)
1523 {
1524 ECerr(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE, ERR_R_INTERNAL_ERROR);
1525 goto err;
1526 }
1527
1528 ret = 1;
1529
1530 err:
1531 BN_CTX_end(ctx);
1532 if (new_ctx != NULL)
1533 BN_CTX_free(new_ctx);
1534 return ret;
1535 }
1536
1537
1538int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1539 {
1540 BN_CTX *new_ctx = NULL;
1541 BIGNUM *tmp0, *tmp1;
1542 size_t pow2 = 0;
1543 BIGNUM **heap = NULL;
1544 size_t i;
1545 int ret = 0;
1546
1547 if (num == 0)
1548 return 1;
1549
1550 if (ctx == NULL)
1551 {
1552 ctx = new_ctx = BN_CTX_new();
1553 if (ctx == NULL)
1554 return 0;
1555 }
1556
1557 BN_CTX_start(ctx);
1558 tmp0 = BN_CTX_get(ctx);
1559 tmp1 = BN_CTX_get(ctx);
1560 if (tmp0 == NULL || tmp1 == NULL) goto err;
1561
1562 /* Before converting the individual points, compute inverses of all Z values.
1563 * Modular inversion is rather slow, but luckily we can do with a single
1564 * explicit inversion, plus about 3 multiplications per input value.
1565 */
1566
1567 pow2 = 1;
1568 while (num > pow2)
1569 pow2 <<= 1;
1570 /* Now pow2 is the smallest power of 2 satifsying pow2 >= num.
1571 * We need twice that. */
1572 pow2 <<= 1;
1573
1574 heap = OPENSSL_malloc(pow2 * sizeof heap[0]);
1575 if (heap == NULL) goto err;
1576
1577 /* The array is used as a binary tree, exactly as in heapsort:
1578 *
1579 * heap[1]
1580 * heap[2] heap[3]
1581 * heap[4] heap[5] heap[6] heap[7]
1582 * heap[8]heap[9] heap[10]heap[11] heap[12]heap[13] heap[14] heap[15]
1583 *
1584 * We put the Z's in the last line;
1585 * then we set each other node to the product of its two child-nodes (where
1586 * empty or 0 entries are treated as ones);
1587 * then we invert heap[1];
1588 * then we invert each other node by replacing it by the product of its
1589 * parent (after inversion) and its sibling (before inversion).
1590 */
1591 heap[0] = NULL;
1592 for (i = pow2/2 - 1; i > 0; i--)
1593 heap[i] = NULL;
1594 for (i = 0; i < num; i++)
1595 heap[pow2/2 + i] = &points[i]->Z;
1596 for (i = pow2/2 + num; i < pow2; i++)
1597 heap[i] = NULL;
1598
1599 /* set each node to the product of its children */
1600 for (i = pow2/2 - 1; i > 0; i--)
1601 {
1602 heap[i] = BN_new();
1603 if (heap[i] == NULL) goto err;
1604
1605 if (heap[2*i] != NULL)
1606 {
1607 if ((heap[2*i + 1] == NULL) || BN_is_zero(heap[2*i + 1]))
1608 {
1609 if (!BN_copy(heap[i], heap[2*i])) goto err;
1610 }
1611 else
1612 {
1613 if (BN_is_zero(heap[2*i]))
1614 {
1615 if (!BN_copy(heap[i], heap[2*i + 1])) goto err;
1616 }
1617 else
1618 {
1619 if (!group->meth->field_mul(group, heap[i],
1620 heap[2*i], heap[2*i + 1], ctx)) goto err;
1621 }
1622 }
1623 }
1624 }
1625
1626 /* invert heap[1] */
1627 if (!BN_is_zero(heap[1]))
1628 {
1629 if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
1630 {
1631 ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
1632 goto err;
1633 }
1634 }
1635 if (group->meth->field_encode != 0)
1636 {
1637 /* in the Montgomery case, we just turned R*H (representing H)
1638 * into 1/(R*H), but we need R*(1/H) (representing 1/H);
1639 * i.e. we have need to multiply by the Montgomery factor twice */
1640 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1641 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1642 }
1643
1644 /* set other heap[i]'s to their inverses */
1645 for (i = 2; i < pow2/2 + num; i += 2)
1646 {
1647 /* i is even */
1648 if ((heap[i + 1] != NULL) && !BN_is_zero(heap[i + 1]))
1649 {
1650 if (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;
1651 if (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;
1652 if (!BN_copy(heap[i], tmp0)) goto err;
1653 if (!BN_copy(heap[i + 1], tmp1)) goto err;
1654 }
1655 else
1656 {
1657 if (!BN_copy(heap[i], heap[i/2])) goto err;
1658 }
1659 }
1660
1661 /* we have replaced all non-zero Z's by their inverses, now fix up all the points */
1662 for (i = 0; i < num; i++)
1663 {
1664 EC_POINT *p = points[i];
1665
1666 if (!BN_is_zero(&p->Z))
1667 {
1668 /* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
1669
1670 if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
1671 if (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;
1672
1673 if (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;
1674 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;
1675
1676 if (group->meth->field_set_to_one != 0)
1677 {
1678 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1679 }
1680 else
1681 {
1682 if (!BN_one(&p->Z)) goto err;
1683 }
1684 p->Z_is_one = 1;
1685 }
1686 }
1687
1688 ret = 1;
1689
1690 err:
1691 BN_CTX_end(ctx);
1692 if (new_ctx != NULL)
1693 BN_CTX_free(new_ctx);
1694 if (heap != NULL)
1695 {
1696 /* heap[pow2/2] .. heap[pow2-1] have not been allocated locally! */
1697 for (i = pow2/2 - 1; i > 0; i--)
1698 {
1699 if (heap[i] != NULL)
1700 BN_clear_free(heap[i]);
1701 }
1702 OPENSSL_free(heap);
1703 }
1704 return ret;
1705 }
1706
1707
1708int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1709 {
1710 return BN_mod_mul(r, a, b, &group->field, ctx);
1711 }
1712
1713
1714int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1715 {
1716 return BN_mod_sqr(r, a, &group->field, ctx);
1717 }
diff --git a/src/lib/libssl/src/crypto/ec/ectest.c b/src/lib/libssl/src/crypto/ec/ectest.c
new file mode 100644
index 0000000000..243cd83fb5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ec/ectest.c
@@ -0,0 +1,634 @@
1/* crypto/ec/ectest.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <time.h>
60
61
62#ifdef OPENSSL_NO_EC
63int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); return 0; }
64#else
65
66
67#include <openssl/ec.h>
68#include <openssl/engine.h>
69#include <openssl/err.h>
70
71#define ABORT do { \
72 fflush(stdout); \
73 fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \
74 ERR_print_errors_fp(stderr); \
75 exit(1); \
76} while (0)
77
78
79void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
80 {
81 clock_t clck;
82 int i, j;
83 BIGNUM *s, *s0;
84 EC_POINT *P;
85
86 s = BN_new();
87 s0 = BN_new();
88 if (s == NULL || s0 == NULL) ABORT;
89
90 if (!EC_GROUP_get_curve_GFp(group, s, NULL, NULL, ctx)) ABORT;
91 fprintf(stdout, "Timings for %d bit prime, ", (int)BN_num_bits(s));
92 if (!EC_GROUP_get_order(group, s, ctx)) ABORT;
93 fprintf(stdout, "%d bit scalars ", (int)BN_num_bits(s));
94 fflush(stdout);
95
96 P = EC_POINT_new(group);
97 if (P == NULL) ABORT;
98 EC_POINT_copy(P, EC_GROUP_get0_generator(group));
99
100 clck = clock();
101 for (i = 0; i < 10; i++)
102 {
103 if (!BN_pseudo_rand(s, BN_num_bits(s), 0, 0)) ABORT;
104 if (multi)
105 {
106 if (!BN_pseudo_rand(s0, BN_num_bits(s), 0, 0)) ABORT;
107 }
108 for (j = 0; j < 10; j++)
109 {
110 if (!EC_POINT_mul(group, P, s, multi ? P : NULL, multi ? s0 : NULL, ctx)) ABORT;
111 }
112 fprintf(stdout, ".");
113 fflush(stdout);
114 }
115 fprintf(stdout, "\n");
116
117 clck = clock() - clck;
118
119#ifdef CLOCKS_PER_SEC
120 /* "To determine the time in seconds, the value returned
121 * by the clock function should be divided by the value
122 * of the macro CLOCKS_PER_SEC."
123 * -- ISO/IEC 9899 */
124# define UNIT "s"
125#else
126 /* "`CLOCKS_PER_SEC' undeclared (first use this function)"
127 * -- cc on NeXTstep/OpenStep */
128# define UNIT "units"
129# define CLOCKS_PER_SEC 1
130#endif
131
132 fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j,
133 multi ? "s*P+t*Q operations" : "point multiplications",
134 (double)clck/CLOCKS_PER_SEC);
135 fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j));
136
137 EC_POINT_free(P);
138 BN_free(s);
139 BN_free(s0);
140 }
141
142
143int main(int argc, char *argv[])
144 {
145 BN_CTX *ctx = NULL;
146 BIGNUM *p, *a, *b;
147 EC_GROUP *group;
148 EC_GROUP *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;
149 EC_POINT *P, *Q, *R;
150 BIGNUM *x, *y, *z;
151 unsigned char buf[100];
152 size_t i, len;
153 int k;
154
155 /* enable memory leak checking unless explicitly disabled */
156 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
157 {
158 CRYPTO_malloc_debug_init();
159 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
160 }
161 else
162 {
163 /* OPENSSL_DEBUG_MEMORY=off */
164 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
165 }
166 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
167 ERR_load_crypto_strings();
168
169#if 1 /* optional */
170 ctx = BN_CTX_new();
171 if (!ctx) ABORT;
172#endif
173
174 p = BN_new();
175 a = BN_new();
176 b = BN_new();
177 if (!p || !a || !b) ABORT;
178
179 if (!BN_hex2bn(&p, "17")) ABORT;
180 if (!BN_hex2bn(&a, "1")) ABORT;
181 if (!BN_hex2bn(&b, "1")) ABORT;
182
183 group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp
184 * so that the library gets to choose the EC_METHOD */
185 if (!group) ABORT;
186
187 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
188
189 {
190 EC_GROUP *tmp;
191 tmp = EC_GROUP_new(EC_GROUP_method_of(group));
192 if (!tmp) ABORT;
193 if (!EC_GROUP_copy(tmp, group));
194 EC_GROUP_free(group);
195 group = tmp;
196 }
197
198 if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) ABORT;
199
200 fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x");
201 BN_print_fp(stdout, p);
202 fprintf(stdout, ")\n a = 0x");
203 BN_print_fp(stdout, a);
204 fprintf(stdout, "\n b = 0x");
205 BN_print_fp(stdout, b);
206 fprintf(stdout, "\n");
207
208 P = EC_POINT_new(group);
209 Q = EC_POINT_new(group);
210 R = EC_POINT_new(group);
211 if (!P || !Q || !R) ABORT;
212
213 if (!EC_POINT_set_to_infinity(group, P)) ABORT;
214 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
215
216 buf[0] = 0;
217 if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT;
218
219 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
220 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
221
222 x = BN_new();
223 y = BN_new();
224 z = BN_new();
225 if (!x || !y || !z) ABORT;
226
227 if (!BN_hex2bn(&x, "D")) ABORT;
228 if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) ABORT;
229 if (!EC_POINT_is_on_curve(group, Q, ctx))
230 {
231 if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) ABORT;
232 fprintf(stderr, "Point is not on curve: x = 0x");
233 BN_print_fp(stderr, x);
234 fprintf(stderr, ", y = 0x");
235 BN_print_fp(stderr, y);
236 fprintf(stderr, "\n");
237 ABORT;
238 }
239
240 fprintf(stdout, "A cyclic subgroup:\n");
241 k = 100;
242 do
243 {
244 if (k-- == 0) ABORT;
245
246 if (EC_POINT_is_at_infinity(group, P))
247 fprintf(stdout, " point at infinity\n");
248 else
249 {
250 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
251
252 fprintf(stdout, " x = 0x");
253 BN_print_fp(stdout, x);
254 fprintf(stdout, ", y = 0x");
255 BN_print_fp(stdout, y);
256 fprintf(stdout, "\n");
257 }
258
259 if (!EC_POINT_copy(R, P)) ABORT;
260 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
261
262#if 0 /* optional */
263 {
264 EC_POINT *points[3];
265
266 points[0] = R;
267 points[1] = Q;
268 points[2] = P;
269 if (!EC_POINTs_make_affine(group, 2, points, ctx)) ABORT;
270 }
271#endif
272
273 }
274 while (!EC_POINT_is_at_infinity(group, P));
275
276 if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT;
277 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
278
279 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx);
280 if (len == 0) ABORT;
281 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
282 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
283 fprintf(stdout, "Generator as octect string, compressed form:\n ");
284 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
285
286 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
287 if (len == 0) ABORT;
288 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
289 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
290 fprintf(stdout, "\nGenerator as octect string, uncompressed form:\n ");
291 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
292
293 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
294 if (len == 0) ABORT;
295 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
296 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
297 fprintf(stdout, "\nGenerator as octect string, hybrid form:\n ");
298 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
299
300 if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) ABORT;
301 fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x");
302 BN_print_fp(stdout, x);
303 fprintf(stdout, ", Y = 0x");
304 BN_print_fp(stdout, y);
305 fprintf(stdout, ", Z = 0x");
306 BN_print_fp(stdout, z);
307 fprintf(stdout, "\n");
308
309 if (!EC_POINT_invert(group, P, ctx)) ABORT;
310 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
311
312
313 /* Curve P-192 (FIPS PUB 186-2, App. 6) */
314
315 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) ABORT;
316 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
317 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) ABORT;
318 if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) ABORT;
319 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
320
321 if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) ABORT;
322 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
323 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
324 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) ABORT;
325 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
326
327 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
328 fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x");
329 BN_print_fp(stdout, x);
330 fprintf(stdout, "\n y = 0x");
331 BN_print_fp(stdout, y);
332 fprintf(stdout, "\n");
333 /* G_y value taken from the standard: */
334 if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT;
335 if (0 != BN_cmp(y, z)) ABORT;
336
337 fprintf(stdout, "verify group order ...");
338 fflush(stdout);
339 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
340 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
341 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
342 fprintf(stdout, ".");
343 fflush(stdout);
344 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
345 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
346 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
347 fprintf(stdout, " ok\n");
348
349 if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
350 if (!EC_GROUP_copy(P_192, group)) ABORT;
351
352
353 /* Curve P-224 (FIPS PUB 186-2, App. 6) */
354
355 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) ABORT;
356 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
357 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) ABORT;
358 if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) ABORT;
359 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
360
361 if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) ABORT;
362 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
363 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
364 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) ABORT;
365 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
366
367 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
368 fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x");
369 BN_print_fp(stdout, x);
370 fprintf(stdout, "\n y = 0x");
371 BN_print_fp(stdout, y);
372 fprintf(stdout, "\n");
373 /* G_y value taken from the standard: */
374 if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT;
375 if (0 != BN_cmp(y, z)) ABORT;
376
377 fprintf(stdout, "verify group order ...");
378 fflush(stdout);
379 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
380 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
381 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
382 fprintf(stdout, ".");
383 fflush(stdout);
384 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
385 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
386 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
387 fprintf(stdout, " ok\n");
388
389 if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
390 if (!EC_GROUP_copy(P_224, group)) ABORT;
391
392
393 /* Curve P-256 (FIPS PUB 186-2, App. 6) */
394
395 if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
396 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
397 if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
398 if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) ABORT;
399 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
400
401 if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) ABORT;
402 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
403 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
404 if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E"
405 "84F3B9CAC2FC632551")) ABORT;
406 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
407
408 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
409 fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x");
410 BN_print_fp(stdout, x);
411 fprintf(stdout, "\n y = 0x");
412 BN_print_fp(stdout, y);
413 fprintf(stdout, "\n");
414 /* G_y value taken from the standard: */
415 if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT;
416 if (0 != BN_cmp(y, z)) ABORT;
417
418 fprintf(stdout, "verify group order ...");
419 fflush(stdout);
420 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
421 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
422 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
423 fprintf(stdout, ".");
424 fflush(stdout);
425 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
426 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
427 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
428 fprintf(stdout, " ok\n");
429
430 if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
431 if (!EC_GROUP_copy(P_256, group)) ABORT;
432
433
434 /* Curve P-384 (FIPS PUB 186-2, App. 6) */
435
436 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
437 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT;
438 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
439 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
440 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT;
441 if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141"
442 "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT;
443 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
444
445 if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B"
446 "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT;
447 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
448 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
449 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
450 "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT;
451 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
452
453 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
454 fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x");
455 BN_print_fp(stdout, x);
456 fprintf(stdout, "\n y = 0x");
457 BN_print_fp(stdout, y);
458 fprintf(stdout, "\n");
459 /* G_y value taken from the standard: */
460 if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14"
461 "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT;
462 if (0 != BN_cmp(y, z)) ABORT;
463
464 fprintf(stdout, "verify group order ...");
465 fflush(stdout);
466 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
467 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
468 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
469 fprintf(stdout, ".");
470 fflush(stdout);
471 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
472 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
473 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
474 fprintf(stdout, " ok\n");
475
476 if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
477 if (!EC_GROUP_copy(P_384, group)) ABORT;
478
479
480 /* Curve P-521 (FIPS PUB 186-2, App. 6) */
481
482 if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
483 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
484 "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
485 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
486 if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
487 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
488 "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
489 if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B"
490 "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573"
491 "DF883D2C34F1EF451FD46B503F00")) ABORT;
492 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
493
494 if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F"
495 "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B"
496 "3C1856A429BF97E7E31C2E5BD66")) ABORT;
497 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
498 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
499 if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
500 "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5"
501 "C9B8899C47AEBB6FB71E91386409")) ABORT;
502 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
503
504 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
505 fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x");
506 BN_print_fp(stdout, x);
507 fprintf(stdout, "\n y = 0x");
508 BN_print_fp(stdout, y);
509 fprintf(stdout, "\n");
510 /* G_y value taken from the standard: */
511 if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579"
512 "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C"
513 "7086A272C24088BE94769FD16650")) ABORT;
514 if (0 != BN_cmp(y, z)) ABORT;
515
516 fprintf(stdout, "verify group order ...");
517 fflush(stdout);
518 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
519 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
520 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
521 fprintf(stdout, ".");
522 fflush(stdout);
523 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
524 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
525 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
526 fprintf(stdout, " ok\n");
527
528 if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
529 if (!EC_GROUP_copy(P_521, group)) ABORT;
530
531
532 /* more tests using the last curve */
533
534 if (!EC_POINT_copy(Q, P)) ABORT;
535 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
536 if (!EC_POINT_dbl(group, P, P, ctx)) ABORT;
537 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
538 if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */
539
540 if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT;
541 if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT;
542 if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */
543
544 {
545 const EC_POINT *points[3];
546 const BIGNUM *scalars[3];
547
548 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
549 points[0] = Q;
550 points[1] = Q;
551 points[2] = Q;
552
553 if (!BN_add(y, z, BN_value_one())) ABORT;
554 if (BN_is_odd(y)) ABORT;
555 if (!BN_rshift1(y, y)) ABORT;
556 scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */
557 scalars[1] = y;
558
559 fprintf(stdout, "combined multiplication ...");
560 fflush(stdout);
561
562 /* z is still the group order */
563 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
564 if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT;
565 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
566 if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT;
567
568 fprintf(stdout, ".");
569 fflush(stdout);
570
571 if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
572 if (!BN_add(z, z, y)) ABORT;
573 z->neg = 1;
574 scalars[0] = y;
575 scalars[1] = z; /* z = -(order + y) */
576
577 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
578 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
579
580 fprintf(stdout, ".");
581 fflush(stdout);
582
583 if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT;
584 if (!BN_add(z, x, y)) ABORT;
585 z->neg = 1;
586 scalars[0] = x;
587 scalars[1] = y;
588 scalars[2] = z; /* z = -(x+y) */
589
590 if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT;
591 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
592
593 fprintf(stdout, " ok\n\n");
594 }
595
596
597#if 0
598 timings(P_192, 0, ctx);
599 timings(P_192, 1, ctx);
600 timings(P_224, 0, ctx);
601 timings(P_224, 1, ctx);
602 timings(P_256, 0, ctx);
603 timings(P_256, 1, ctx);
604 timings(P_384, 0, ctx);
605 timings(P_384, 1, ctx);
606 timings(P_521, 0, ctx);
607 timings(P_521, 1, ctx);
608#endif
609
610
611 if (ctx)
612 BN_CTX_free(ctx);
613 BN_free(p); BN_free(a); BN_free(b);
614 EC_GROUP_free(group);
615 EC_POINT_free(P);
616 EC_POINT_free(Q);
617 EC_POINT_free(R);
618 BN_free(x); BN_free(y); BN_free(z);
619
620 if (P_192) EC_GROUP_free(P_192);
621 if (P_224) EC_GROUP_free(P_224);
622 if (P_256) EC_GROUP_free(P_256);
623 if (P_384) EC_GROUP_free(P_384);
624 if (P_521) EC_GROUP_free(P_521);
625
626 ENGINE_cleanup();
627 CRYPTO_cleanup_all_ex_data();
628 ERR_free_strings();
629 ERR_remove_state(0);
630 CRYPTO_mem_leaks_fp(stderr);
631
632 return 0;
633 }
634#endif
diff --git a/src/lib/libssl/src/crypto/engine/README b/src/lib/libssl/src/crypto/engine/README
new file mode 100644
index 0000000000..96595e6f35
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/README
@@ -0,0 +1,278 @@
1NOTES, THOUGHTS, and EVERYTHING
2-------------------------------
3
4(1) Concurrency and locking ... I made a change to the ENGINE_free code
5 because I spotted a potential hold-up in proceedings (doing too
6 much inside a lock including calling a callback), there may be
7 other bits like this. What do the speed/optimisation freaks think
8 of this aspect of the code and design? There's lots of locking for
9 manipulation functions and I need that to keep things nice and
10 solid, but this manipulation is mostly (de)initialisation, I would
11 think that most run-time locking is purely in the ENGINE_init and
12 ENGINE_finish calls that might be made when getting handles for
13 RSA (and friends') structures. These would be mostly reference
14 count operations as the functional references should always be 1
15 or greater at run-time to prevent init/deinit thrashing.
16
17(2) nCipher support, via the HWCryptoHook API, is now in the code.
18 Apparently this hasn't been tested too much yet, but it looks
19 good. :-) Atalla support has been added too, but shares a lot in
20 common with Ben's original hooks in bn_exp.c (although it has been
21 ENGINE-ified, and error handling wrapped around it) and it's also
22 had some low-volume testing, so it should be usable.
23
24(3) Of more concern, we need to work out (a) how to put together usable
25 RAND_METHODs for units that just have one "get n or less random
26 bytes" function, (b) we also need to determine how to hook the code
27 in crypto/rand/ to use the ENGINE defaults in a way similar to what
28 has been done in crypto/rsa/, crypto/dsa/, etc.
29
30(4) ENGINE should really grow to encompass more than 3 public key
31 algorithms and randomness gathering. The structure/data level of
32 the engine code is hidden from code outside the crypto/engine/
33 directory so change shouldn't be too viral. More important though
34 is how things should evolve ... this needs thought and discussion.
35
36
37-----------------------------------==*==-----------------------------------
38
39More notes 2000-08-01
40---------------------
41
42Geoff Thorpe, who designed the engine part, wrote a pretty good description
43of the thoughts he had when he built it, good enough to include verbatim here
44(with his permission) -- Richard Levitte
45
46
47Date: Tue, 1 Aug 2000 16:54:08 +0100 (BST)
48From: Geoff Thorpe
49Subject: Re: The thoughts to merge BRANCH_engine into the main trunk are
50 emerging
51
52Hi there,
53
54I'm going to try and do some justice to this, but I'm a little short on
55time and the there is an endless amount that could be discussed on this
56subject. sigh ... please bear with me :-)
57
58> The changes in BRANCH_engine dig deep into the core of OpenSSL, for example
59> into the RSA and RAND routines, adding a level of indirection which is needed
60> to keep the abstraction, as far as I understand. It would be a good thing if
61> those who do play with those things took a look at the changes that have been
62> done in the branch and say out loud how much (or hopefully little) we've made
63> fools of ourselves.
64
65The point here is that the code that has emerged in the BRANCH_engine
66branch was based on some initial requirements of mine that I went in and
67addressed, and Richard has picked up the ball and run with it too. It
68would be really useful to get some review of the approach we've taken, but
69first I think I need to describe as best I can the reasons behind what has
70been done so far, in particular what issues we have tried to address when
71doing this, and what issues we have intentionally (or necessarily) tried
72to avoid.
73
74methods, engines, and evps
75--------------------------
76
77There has been some dicussion, particularly with Steve, about where this
78ENGINE stuff might fit into the conceptual picture as/when we start to
79abstract algorithms a little bit to make the library more extensible. In
80particular, it would desirable to have algorithms (symmetric, hash, pkc,
81etc) abstracted in some way that allows them to be just objects sitting in
82a list (or database) ... it'll just happen that the "DSA" object doesn't
83support encryption whereas the "RSA" object does. This requires a lot of
84consideration to begin to know how to tackle it; in particular how
85encapsulated should these things be? If the objects also understand their
86own ASN1 encodings and what-not, then it would for example be possible to
87add support for elliptic-curve DSA in as a new algorithm and automatically
88have ECC-DSA certificates supported in SSL applications. Possible, but not
89easy. :-)
90
91Whatever, it seems that the way to go (if I've grok'd Steve's comments on
92this in the past) is to amalgamate these things in EVP as is already done
93(I think) for ciphers or hashes (Steve, please correct/elaborate). I
94certainly think something should be done in this direction because right
95now we have different source directories, types, functions, and methods
96for each algorithm - even when conceptually they are very much different
97feathers of the same bird. (This is certainly all true for the public-key
98stuff, and may be partially true for the other parts.)
99
100ENGINE was *not* conceived as a way of solving this, far from it. Nor was
101it conceived as a way of replacing the various "***_METHOD"s. It was
102conceived as an abstraction of a sort of "virtual crypto device". If we
103lived in a world where "EVP_ALGO"s (or something like them) encapsulated
104particular algorithms like RSA,DSA,MD5,RC4,etc, and "***_METHOD"s
105encapsulated interfaces to algorithms (eg. some algo's might support a
106PKC_METHOD, a HASH_METHOD, or a CIPHER_METHOD, who knows?), then I would
107think that ENGINE would encapsulate an implementation of arbitrarily many
108of those algorithms - perhaps as alternatives to existing algorithms
109and/or perhaps as new previously unimplemented algorithms. An ENGINE could
110be used to contain an alternative software implementation, a wrapper for a
111hardware acceleration and/or key-management unit, a comms-wrapper for
112distributing cryptographic operations to remote machines, or any other
113"devices" your imagination can dream up.
114
115However, what has been done in the ENGINE branch so far is nothing more
116than starting to get our toes wet. I had a couple of self-imposed
117requirements when putting the initial abstraction together, and I may have
118already posed these in one form or another on the list, but briefly;
119
120 (i) only bother with public key algorithms for now, and maybe RAND too
121 (motivated by the need to get hardware support going and the fact
122 this was a comparitively easy subset to address to begin with).
123
124 (ii) don't change (if at all possible) the existing crypto code, ie. the
125 implementations, the way the ***_METHODs work, etc.
126
127 (iii) ensure that if no function from the ENGINE code is ever called then
128 things work the way they always did, and there is no memory
129 allocation (otherwise the failure to cleanup would be a problem -
130 this is part of the reason no STACKs were used, the other part of
131 the reason being I found them inappropriate).
132
133 (iv) ensure that all the built-in crypto was encapsulated by one of
134 these "ENGINE"s and that this engine was automatically selected as
135 the default.
136
137 (v) provide the minimum hooking possible in the existing crypto code
138 so that global functions (eg. RSA_public_encrypt) do not need any
139 extra parameter, yet will use whatever the current default ENGINE
140 for that RSA key is, and that the default can be set "per-key"
141 and globally (new keys will assume the global default, and keys
142 without their own default will be operated on using the global
143 default). NB: Try and make (v) conflict as little as possible with
144 (ii). :-)
145
146 (vi) wrap the ENGINE code up in duct tape so you can't even see the
147 corners. Ie. expose no structures at all, just black-box pointers.
148
149 (v) maintain internally a list of ENGINEs on which a calling
150 application can iterate, interrogate, etc. Allow a calling
151 application to hook in new ENGINEs, remove ENGINEs from the list,
152 and enforce uniqueness within the global list of each ENGINE's
153 "unique id".
154
155 (vi) keep reference counts for everything - eg. this includes storing a
156 reference inside each RSA structure to the ENGINE that it uses.
157 This is freed when the RSA structure is destroyed, or has its
158 ENGINE explicitly changed. The net effect needs to be that at any
159 time, it is deterministic to know whether an ENGINE is in use or
160 can be safely removed (or unloaded in the case of the other type
161 of reference) without invalidating function pointers that may or
162 may not be used indavertently in the future. This was actually
163 one of the biggest problems to overcome in the existing OpenSSL
164 code - implementations had always been assumed to be ever-present,
165 so there was no trivial way to get round this.
166
167 (vii) distinguish between structural references and functional
168 references.
169
170A *little* detail
171-----------------
172
173While my mind is on it; I'll illustrate the bit in item (vii). This idea
174turned out to be very handy - the ENGINEs themselves need to be operated
175on and manipulated simply as objects without necessarily trying to
176"enable" them for use. Eg. most host machines will not have the necessary
177hardware or software to support all the engines one might compile into
178OpenSSL, yet it needs to be possible to iterate across the ENGINEs,
179querying their names, properties, etc - all happening in a thread-safe
180manner that uses reference counts (if you imagine two threads iterating
181through a list and one thread removing the ENGINE the other is currently
182looking at - you can see the gotcha waiting to happen). For all of this,
183*structural references* are used and operate much like the other reference
184counts in OpenSSL.
185
186The other kind of reference count is for *functional* references - these
187indicate a reference on which the caller can actually assume the
188particular ENGINE to be initialised and usable to perform the operations
189it implements. Any increment or decrement of the functional reference
190count automatically invokes a corresponding change in the structural
191reference count, as it is fairly obvious that a functional reference is a
192restricted case of a structural reference. So struct_ref >= funct_ref at
193all times. NB: functional references are usually obtained by a call to
194ENGINE_init(), but can also be created implicitly by calls that require a
195new functional reference to be created, eg. ENGINE_set_default(). Either
196way the only time the underlying ENGINE's "init" function is really called
197is when the (functional) reference count increases to 1, similarly the
198underlying "finish" handler is only called as the count goes down to 0.
199The effect of this, for example, is that if you set the default ENGINE for
200RSA operations to be "cswift", then its functional reference count will
201already be at least 1 so the CryptoSwift shared-library and the card will
202stay loaded and initialised until such time as all RSA keys using the
203cswift ENGINE are changed or destroyed and the default ENGINE for RSA
204operations has been changed. This prevents repeated thrashing of init and
205finish handling if the count keeps getting down as far as zero.
206
207Otherwise, the way the ENGINE code has been put together I think pretty
208much reflects the above points. The reason for the ENGINE structure having
209individual RSA_METHOD, DSA_METHOD, etc pointers is simply that it was the
210easiest way to go about things for now, to hook it all into the raw
211RSA,DSA,etc code, and I was trying to the keep the structure invisible
212anyway so that the way this is internally managed could be easily changed
213later on when we start to work out what's to be done about these other
214abstractions.
215
216Down the line, if some EVP-based technique emerges for adequately
217encapsulating algorithms and all their various bits and pieces, then I can
218imagine that "ENGINE" would turn into a reference-counting database of
219these EVP things, of which the default "openssl" ENGINE would be the
220library's own object database of pre-built software implemented algorithms
221(and such). It would also be cool to see the idea of "METHOD"s detached
222from the algorithms themselves ... so RSA, DSA, ElGamal, etc can all
223expose essentially the same METHOD (aka interface), which would include
224any querying/flagging stuff to identify what the algorithm can/can't do,
225its name, and other stuff like max/min block sizes, key sizes, etc. This
226would result in ENGINE similarly detaching its internal database of
227algorithm implementations from the function definitions that return
228interfaces to them. I think ...
229
230As for DSOs etc. Well the DSO code is pretty handy (but could be made much
231more so) for loading vendor's driver-libraries and talking to them in some
232generic way, but right now there's still big problems associated with
233actually putting OpenSSL code (ie. new ENGINEs, or anything else for that
234matter) in dynamically loadable libraries. These problems won't go away in
235a hurry so I don't think we should expect to have any kind of
236shared-library extensions any time soon - but solving the problems is a
237good thing to aim for, and would as a side-effect probably help make
238OpenSSL more usable as a shared-library itself (looking at the things
239needed to do this will show you why).
240
241One of the problems is that if you look at any of the ENGINE
242implementations, eg. hw_cswift.c or hw_ncipher.c, you'll see how it needs
243a variety of functionality and definitions from various areas of OpenSSL,
244including crypto/bn/, crypto/err/, crypto/ itself (locking for example),
245crypto/dso/, crypto/engine/, crypto/rsa, etc etc etc. So if similar code
246were to be suctioned off into shared libraries, the shared libraries would
247either have to duplicate all the definitions and code and avoid loader
248conflicts, or OpenSSL would have to somehow expose all that functionality
249to the shared-library. If this isn't a big enough problem, the issue of
250binary compatibility will be - anyone writing Apache modules can tell you
251that (Ralf? Ben? :-). However, I don't think OpenSSL would need to be
252quite so forgiving as Apache should be, so OpenSSL could simply tell its
253version to the DSO and leave the DSO with the problem of deciding whether
254to proceed or bail out for fear of binary incompatibilities.
255
256Certainly one thing that would go a long way to addressing this is to
257embark on a bit of an opaqueness mission. I've set the ENGINE code up with
258this in mind - it's so draconian that even to declare your own ENGINE, you
259have to get the engine code to create the underlying ENGINE structure, and
260then feed in the new ENGINE's function/method pointers through various
261"set" functions. The more of the code that takes on such a black-box
262approach, the more of the code that will be (a) easy to expose to shared
263libraries that need it, and (b) easy to expose to applications wanting to
264use OpenSSL itself as a shared-library. From my own explorations in
265OpenSSL, the biggest leviathan I've seen that is a problem in this respect
266is the BIGNUM code. Trying to "expose" the bignum code through any kind of
267organised "METHODs", let alone do all the necessary bignum operations
268solely through functions rather than direct access to the structures and
269macros, will be a massive pain in the "r"s.
270
271Anyway, I'm done for now - hope it was readable. Thoughts?
272
273Cheers,
274Geoff
275
276
277-----------------------------------==*==-----------------------------------
278
diff --git a/src/lib/libssl/src/crypto/engine/eng_all.c b/src/lib/libssl/src/crypto/engine/eng_all.c
new file mode 100644
index 0000000000..a35b3db9e8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_all.c
@@ -0,0 +1,118 @@
1/* crypto/engine/eng_all.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/err.h>
60#include <openssl/engine.h>
61#include "eng_int.h"
62
63#ifdef __OpenBSD__
64static int openbsd_default_loaded = 0;
65#endif
66
67void ENGINE_load_builtin_engines(void)
68 {
69 /* There's no longer any need for an "openssl" ENGINE unless, one day,
70 * it is the *only* way for standard builtin implementations to be be
71 * accessed (ie. it would be possible to statically link binaries with
72 * *no* builtin implementations). */
73#if 0
74 ENGINE_load_openssl();
75#endif
76 ENGINE_load_dynamic();
77#ifndef OPENSSL_NO_HW
78#ifndef OPENSSL_NO_HW_CSWIFT
79 ENGINE_load_cswift();
80#endif
81#ifndef OPENSSL_NO_HW_NCIPHER
82 ENGINE_load_chil();
83#endif
84#ifndef OPENSSL_NO_HW_ATALLA
85 ENGINE_load_atalla();
86#endif
87#ifndef OPENSSL_NO_HW_NURON
88 ENGINE_load_nuron();
89#endif
90#ifndef OPENSSL_NO_HW_UBSEC
91 ENGINE_load_ubsec();
92#endif
93#ifndef OPENSSL_NO_HW_AEP
94 ENGINE_load_aep();
95#endif
96#ifndef OPENSSL_NO_HW_SUREWARE
97 ENGINE_load_sureware();
98#endif
99#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
100 ENGINE_load_openbsd_dev_crypto();
101#endif
102#ifdef __OpenBSD__
103 ENGINE_load_cryptodev();
104#endif
105#endif
106 }
107
108#ifdef __OpenBSD__
109void ENGINE_setup_openbsd(void) {
110 if (!openbsd_default_loaded) {
111 ENGINE_load_cryptodev();
112 ENGINE_register_all_complete();
113 }
114 openbsd_default_loaded=1;
115}
116#endif
117
118
diff --git a/src/lib/libssl/src/crypto/engine/eng_cnf.c b/src/lib/libssl/src/crypto/engine/eng_cnf.c
new file mode 100644
index 0000000000..8c0ae8a1ad
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_cnf.c
@@ -0,0 +1,242 @@
1/* eng_cnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/engine.h>
64
65/* #define ENGINE_CONF_DEBUG */
66
67/* ENGINE config module */
68
69static char *skip_dot(char *name)
70 {
71 char *p;
72 p = strchr(name, '.');
73 if (p)
74 return p + 1;
75 return name;
76 }
77
78static STACK_OF(ENGINE) *initialized_engines = NULL;
79
80static int int_engine_init(ENGINE *e)
81 {
82 if (!ENGINE_init(e))
83 return 0;
84 if (!initialized_engines)
85 initialized_engines = sk_ENGINE_new_null();
86 if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e))
87 {
88 ENGINE_finish(e);
89 return 0;
90 }
91 return 1;
92 }
93
94
95int int_engine_configure(char *name, char *value, const CONF *cnf)
96 {
97 int i;
98 int ret = 0;
99 long do_init = -1;
100 STACK_OF(CONF_VALUE) *ecmds;
101 CONF_VALUE *ecmd;
102 char *ctrlname, *ctrlvalue;
103 ENGINE *e = NULL;
104 name = skip_dot(name);
105#ifdef ENGINE_CONF_DEBUG
106 fprintf(stderr, "Configuring engine %s\n", name);
107#endif
108 /* Value is a section containing ENGINE commands */
109 ecmds = NCONF_get_section(cnf, value);
110
111 if (!ecmds)
112 {
113 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
114 return 0;
115 }
116
117 for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
118 {
119 ecmd = sk_CONF_VALUE_value(ecmds, i);
120 ctrlname = skip_dot(ecmd->name);
121 ctrlvalue = ecmd->value;
122#ifdef ENGINE_CONF_DEBUG
123 fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
124#endif
125
126 /* First handle some special pseudo ctrls */
127
128 /* Override engine name to use */
129 if (!strcmp(ctrlname, "engine_id"))
130 name = ctrlvalue;
131 /* Load a dynamic ENGINE */
132 else if (!strcmp(ctrlname, "dynamic_path"))
133 {
134 e = ENGINE_by_id("dynamic");
135 if (!e)
136 goto err;
137 if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
138 goto err;
139 if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
140 goto err;
141 if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
142 goto err;
143 }
144 /* ... add other pseudos here ... */
145 else
146 {
147 /* At this point we need an ENGINE structural reference
148 * if we don't already have one.
149 */
150 if (!e)
151 {
152 e = ENGINE_by_id(name);
153 if (!e)
154 return 0;
155 }
156 /* Allow "EMPTY" to mean no value: this allows a valid
157 * "value" to be passed to ctrls of type NO_INPUT
158 */
159 if (!strcmp(ctrlvalue, "EMPTY"))
160 ctrlvalue = NULL;
161 else if (!strcmp(ctrlname, "init"))
162 {
163 if (!NCONF_get_number_e(cnf, value, "init", &do_init))
164 goto err;
165 if (do_init == 1)
166 {
167 if (!int_engine_init(e))
168 goto err;
169 }
170 else if (do_init != 0)
171 {
172 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
173 goto err;
174 }
175 }
176 else if (!strcmp(ctrlname, "default_algorithms"))
177 {
178 if (!ENGINE_set_default_string(e, ctrlvalue))
179 goto err;
180 }
181 else if (!ENGINE_ctrl_cmd_string(e,
182 ctrlname, ctrlvalue, 0))
183 return 0;
184 }
185
186
187
188 }
189 if (e && (do_init == -1) && !int_engine_init(e))
190 goto err;
191 ret = 1;
192 err:
193 if (e)
194 ENGINE_free(e);
195 return ret;
196 }
197
198
199static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
200 {
201 STACK_OF(CONF_VALUE) *elist;
202 CONF_VALUE *cval;
203 int i;
204#ifdef ENGINE_CONF_DEBUG
205 fprintf(stderr, "Called engine module: name %s, value %s\n",
206 CONF_imodule_get_name(md), CONF_imodule_get_value(md));
207#endif
208 /* Value is a section containing ENGINEs to configure */
209 elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
210
211 if (!elist)
212 {
213 ENGINEerr(ENGINE_F_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
214 return 0;
215 }
216
217 for (i = 0; i < sk_CONF_VALUE_num(elist); i++)
218 {
219 cval = sk_CONF_VALUE_value(elist, i);
220 if (!int_engine_configure(cval->name, cval->value, cnf))
221 return 0;
222 }
223
224 return 1;
225 }
226
227static void int_engine_module_finish(CONF_IMODULE *md)
228 {
229 ENGINE *e;
230 while ((e = sk_ENGINE_pop(initialized_engines)))
231 ENGINE_finish(e);
232 sk_ENGINE_free(initialized_engines);
233 initialized_engines = NULL;
234 }
235
236
237void ENGINE_add_conf_module(void)
238 {
239 CONF_module_add("engines",
240 int_engine_module_init,
241 int_engine_module_finish);
242 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_ctrl.c b/src/lib/libssl/src/crypto/engine/eng_ctrl.c
new file mode 100644
index 0000000000..ad3858395b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_ctrl.c
@@ -0,0 +1,387 @@
1/* crypto/engine/eng_ctrl.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* When querying a ENGINE-specific control command's 'description', this string
62 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
63static const char *int_no_description = "";
64
65/* These internal functions handle 'CMD'-related control commands when the
66 * ENGINE in question has asked us to take care of it (ie. the ENGINE did not
67 * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
68
69static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
70 {
71 if((defn->cmd_num == 0) || (defn->cmd_name == NULL))
72 return 1;
73 return 0;
74 }
75
76static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
77 {
78 int idx = 0;
79 while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0))
80 {
81 idx++;
82 defn++;
83 }
84 if(int_ctrl_cmd_is_null(defn))
85 /* The given name wasn't found */
86 return -1;
87 return idx;
88 }
89
90static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
91 {
92 int idx = 0;
93 /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
94 * our searches don't need to take any longer than necessary. */
95 while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num))
96 {
97 idx++;
98 defn++;
99 }
100 if(defn->cmd_num == num)
101 return idx;
102 /* The given cmd_num wasn't found */
103 return -1;
104 }
105
106static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
107 {
108 int idx;
109 char *s = (char *)p;
110 /* Take care of the easy one first (eg. it requires no searches) */
111 if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE)
112 {
113 if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns))
114 return 0;
115 return e->cmd_defns->cmd_num;
116 }
117 /* One or two commands require that "p" be a valid string buffer */
118 if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
119 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
120 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD))
121 {
122 if(s == NULL)
123 {
124 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
125 ERR_R_PASSED_NULL_PARAMETER);
126 return -1;
127 }
128 }
129 /* Now handle cmd_name -> cmd_num conversion */
130 if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
131 {
132 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name(
133 e->cmd_defns, s)) < 0))
134 {
135 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
136 ENGINE_R_INVALID_CMD_NAME);
137 return -1;
138 }
139 return e->cmd_defns[idx].cmd_num;
140 }
141 /* For the rest of the commands, the 'long' argument must specify a
142 * valie command number - so we need to conduct a search. */
143 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns,
144 (unsigned int)i)) < 0))
145 {
146 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
147 ENGINE_R_INVALID_CMD_NUMBER);
148 return -1;
149 }
150 /* Now the logic splits depending on command type */
151 switch(cmd)
152 {
153 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
154 idx++;
155 if(int_ctrl_cmd_is_null(e->cmd_defns + idx))
156 /* end-of-list */
157 return 0;
158 else
159 return e->cmd_defns[idx].cmd_num;
160 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
161 return strlen(e->cmd_defns[idx].cmd_name);
162 case ENGINE_CTRL_GET_NAME_FROM_CMD:
163 return sprintf(s, "%s", e->cmd_defns[idx].cmd_name);
164 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
165 if(e->cmd_defns[idx].cmd_desc)
166 return strlen(e->cmd_defns[idx].cmd_desc);
167 return strlen(int_no_description);
168 case ENGINE_CTRL_GET_DESC_FROM_CMD:
169 if(e->cmd_defns[idx].cmd_desc)
170 return sprintf(s, "%s", e->cmd_defns[idx].cmd_desc);
171 return sprintf(s, "%s", int_no_description);
172 case ENGINE_CTRL_GET_CMD_FLAGS:
173 return e->cmd_defns[idx].cmd_flags;
174 }
175 /* Shouldn't really be here ... */
176 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR);
177 return -1;
178 }
179
180int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
181 {
182 int ctrl_exists, ref_exists;
183 if(e == NULL)
184 {
185 ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
186 return 0;
187 }
188 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
189 ref_exists = ((e->struct_ref > 0) ? 1 : 0);
190 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
191 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
192 if(!ref_exists)
193 {
194 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
195 return 0;
196 }
197 /* Intercept any "root-level" commands before trying to hand them on to
198 * ctrl() handlers. */
199 switch(cmd)
200 {
201 case ENGINE_CTRL_HAS_CTRL_FUNCTION:
202 return ctrl_exists;
203 case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
204 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
205 case ENGINE_CTRL_GET_CMD_FROM_NAME:
206 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
207 case ENGINE_CTRL_GET_NAME_FROM_CMD:
208 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
209 case ENGINE_CTRL_GET_DESC_FROM_CMD:
210 case ENGINE_CTRL_GET_CMD_FLAGS:
211 if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
212 return int_ctrl_helper(e,cmd,i,p,f);
213 if(!ctrl_exists)
214 {
215 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
216 /* For these cmd-related functions, failure is indicated
217 * by a -1 return value (because 0 is used as a valid
218 * return in some places). */
219 return -1;
220 }
221 default:
222 break;
223 }
224 /* Anything else requires a ctrl() handler to exist. */
225 if(!ctrl_exists)
226 {
227 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
228 return 0;
229 }
230 return e->ctrl(e, cmd, i, p, f);
231 }
232
233int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
234 {
235 int flags;
236 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0)
237 {
238 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
239 ENGINE_R_INVALID_CMD_NUMBER);
240 return 0;
241 }
242 if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
243 !(flags & ENGINE_CMD_FLAG_NUMERIC) &&
244 !(flags & ENGINE_CMD_FLAG_STRING))
245 return 0;
246 return 1;
247 }
248
249int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
250 long i, void *p, void (*f)(), int cmd_optional)
251 {
252 int num;
253
254 if((e == NULL) || (cmd_name == NULL))
255 {
256 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
257 ERR_R_PASSED_NULL_PARAMETER);
258 return 0;
259 }
260 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
261 ENGINE_CTRL_GET_CMD_FROM_NAME,
262 0, (void *)cmd_name, NULL)) <= 0))
263 {
264 /* If the command didn't *have* to be supported, we fake
265 * success. This allows certain settings to be specified for
266 * multiple ENGINEs and only require a change of ENGINE id
267 * (without having to selectively apply settings). Eg. changing
268 * from a hardware device back to the regular software ENGINE
269 * without editing the config file, etc. */
270 if(cmd_optional)
271 {
272 ERR_clear_error();
273 return 1;
274 }
275 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
276 ENGINE_R_INVALID_CMD_NAME);
277 return 0;
278 }
279 /* Force the result of the control command to 0 or 1, for the reasons
280 * mentioned before. */
281 if (ENGINE_ctrl(e, num, i, p, f))
282 return 1;
283 return 0;
284 }
285
286int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
287 int cmd_optional)
288 {
289 int num, flags;
290 long l;
291 char *ptr;
292 if((e == NULL) || (cmd_name == NULL))
293 {
294 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
295 ERR_R_PASSED_NULL_PARAMETER);
296 return 0;
297 }
298 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
299 ENGINE_CTRL_GET_CMD_FROM_NAME,
300 0, (void *)cmd_name, NULL)) <= 0))
301 {
302 /* If the command didn't *have* to be supported, we fake
303 * success. This allows certain settings to be specified for
304 * multiple ENGINEs and only require a change of ENGINE id
305 * (without having to selectively apply settings). Eg. changing
306 * from a hardware device back to the regular software ENGINE
307 * without editing the config file, etc. */
308 if(cmd_optional)
309 {
310 ERR_clear_error();
311 return 1;
312 }
313 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
314 ENGINE_R_INVALID_CMD_NAME);
315 return 0;
316 }
317 if(!ENGINE_cmd_is_executable(e, num))
318 {
319 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
320 ENGINE_R_CMD_NOT_EXECUTABLE);
321 return 0;
322 }
323 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0)
324 {
325 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
326 * returned success. */
327 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
328 ENGINE_R_INTERNAL_LIST_ERROR);
329 return 0;
330 }
331 /* If the command takes no input, there must be no input. And vice
332 * versa. */
333 if(flags & ENGINE_CMD_FLAG_NO_INPUT)
334 {
335 if(arg != NULL)
336 {
337 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
338 ENGINE_R_COMMAND_TAKES_NO_INPUT);
339 return 0;
340 }
341 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
342 * rather than returning it as "return data". This is to ensure
343 * usage of these commands is consistent across applications and
344 * that certain applications don't understand it one way, and
345 * others another. */
346 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
347 return 1;
348 return 0;
349 }
350 /* So, we require input */
351 if(arg == NULL)
352 {
353 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
354 ENGINE_R_COMMAND_TAKES_INPUT);
355 return 0;
356 }
357 /* If it takes string input, that's easy */
358 if(flags & ENGINE_CMD_FLAG_STRING)
359 {
360 /* Same explanation as above */
361 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
362 return 1;
363 return 0;
364 }
365 /* If it doesn't take numeric either, then it is unsupported for use in
366 * a config-setting situation, which is what this function is for. This
367 * should never happen though, because ENGINE_cmd_is_executable() was
368 * used. */
369 if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
370 {
371 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
372 ENGINE_R_INTERNAL_LIST_ERROR);
373 return 0;
374 }
375 l = strtol(arg, &ptr, 10);
376 if((arg == ptr) || (*ptr != '\0'))
377 {
378 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
379 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
380 return 0;
381 }
382 /* Force the result of the control command to 0 or 1, for the reasons
383 * mentioned before. */
384 if(ENGINE_ctrl(e, num, l, NULL, NULL))
385 return 1;
386 return 0;
387 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_dyn.c b/src/lib/libssl/src/crypto/engine/eng_dyn.c
new file mode 100644
index 0000000000..4fefcc0cae
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_dyn.c
@@ -0,0 +1,446 @@
1/* crypto/engine/eng_dyn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include "eng_int.h"
64#include <openssl/engine.h>
65#include <openssl/dso.h>
66
67/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader
68 * should implement the hook-up functions with the following prototypes. */
69
70/* Our ENGINE handlers */
71static int dynamic_init(ENGINE *e);
72static int dynamic_finish(ENGINE *e);
73static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
74/* Predeclare our context type */
75typedef struct st_dynamic_data_ctx dynamic_data_ctx;
76/* The implementation for the important control command */
77static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
78
79#define DYNAMIC_CMD_SO_PATH ENGINE_CMD_BASE
80#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1)
81#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2)
82#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3)
83#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 4)
84
85/* The constants used when creating the ENGINE */
86static const char *engine_dynamic_id = "dynamic";
87static const char *engine_dynamic_name = "Dynamic engine loading support";
88static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = {
89 {DYNAMIC_CMD_SO_PATH,
90 "SO_PATH",
91 "Specifies the path to the new ENGINE shared library",
92 ENGINE_CMD_FLAG_STRING},
93 {DYNAMIC_CMD_NO_VCHECK,
94 "NO_VCHECK",
95 "Specifies to continue even if version checking fails (boolean)",
96 ENGINE_CMD_FLAG_NUMERIC},
97 {DYNAMIC_CMD_ID,
98 "ID",
99 "Specifies an ENGINE id name for loading",
100 ENGINE_CMD_FLAG_STRING},
101 {DYNAMIC_CMD_LIST_ADD,
102 "LIST_ADD",
103 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
104 ENGINE_CMD_FLAG_NUMERIC},
105 {DYNAMIC_CMD_LOAD,
106 "LOAD",
107 "Load up the ENGINE specified by other settings",
108 ENGINE_CMD_FLAG_NO_INPUT},
109 {0, NULL, NULL, 0}
110 };
111static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = {
112 {0, NULL, NULL, 0}
113 };
114
115/* Loading code stores state inside the ENGINE structure via the "ex_data"
116 * element. We load all our state into a single structure and use that as a
117 * single context in the "ex_data" stack. */
118struct st_dynamic_data_ctx
119 {
120 /* The DSO object we load that supplies the ENGINE code */
121 DSO *dynamic_dso;
122 /* The function pointer to the version checking shared library function */
123 dynamic_v_check_fn v_check;
124 /* The function pointer to the engine-binding shared library function */
125 dynamic_bind_engine bind_engine;
126 /* The default name/path for loading the shared library */
127 const char *DYNAMIC_LIBNAME;
128 /* Whether to continue loading on a version check failure */
129 int no_vcheck;
130 /* If non-NULL, stipulates the 'id' of the ENGINE to be loaded */
131 const char *engine_id;
132 /* If non-zero, a successfully loaded ENGINE should be added to the internal
133 * ENGINE list. If 2, the add must succeed or the entire load should fail. */
134 int list_add_value;
135 /* The symbol name for the version checking function */
136 const char *DYNAMIC_F1;
137 /* The symbol name for the "initialise ENGINE structure" function */
138 const char *DYNAMIC_F2;
139 };
140
141/* This is the "ex_data" index we obtain and reserve for use with our context
142 * structure. */
143static int dynamic_ex_data_idx = -1;
144
145/* Because our ex_data element may or may not get allocated depending on whether
146 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
147 * problem to solve. We can't declare a "new" handler for the ex_data as we
148 * don't want a dynamic_data_ctx in *all* ENGINE structures of all types (this
149 * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free"
150 * handler and that will get called if an ENGINE is being destroyed and there
151 * was an ex_data element corresponding to our context type. */
152static void dynamic_data_ctx_free_func(void *parent, void *ptr,
153 CRYPTO_EX_DATA *ad, int idx, long argl, void *argp)
154 {
155 if(ptr)
156 {
157 dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
158 if(ctx->dynamic_dso)
159 DSO_free(ctx->dynamic_dso);
160 OPENSSL_free(ctx);
161 }
162 }
163
164/* Construct the per-ENGINE context. We create it blindly and then use a lock to
165 * check for a race - if so, all but one of the threads "racing" will have
166 * wasted their time. The alternative involves creating everything inside the
167 * lock which is far worse. */
168static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
169 {
170 dynamic_data_ctx *c;
171 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
172 if(!ctx)
173 {
174 ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
175 return 0;
176 }
177 memset(c, 0, sizeof(dynamic_data_ctx));
178 c->dynamic_dso = NULL;
179 c->v_check = NULL;
180 c->bind_engine = NULL;
181 c->DYNAMIC_LIBNAME = NULL;
182 c->no_vcheck = 0;
183 c->engine_id = NULL;
184 c->list_add_value = 0;
185 c->DYNAMIC_F1 = "v_check";
186 c->DYNAMIC_F2 = "bind_engine";
187 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
188 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
189 dynamic_ex_data_idx)) == NULL)
190 {
191 /* Good, we're the first */
192 ENGINE_set_ex_data(e, dynamic_ex_data_idx, c);
193 *ctx = c;
194 c = NULL;
195 }
196 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
197 /* If we lost the race to set the context, c is non-NULL and *ctx is the
198 * context of the thread that won. */
199 if(c)
200 OPENSSL_free(c);
201 return 1;
202 }
203
204/* This function retrieves the context structure from an ENGINE's "ex_data", or
205 * if it doesn't exist yet, sets it up. */
206static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e)
207 {
208 dynamic_data_ctx *ctx;
209 if(dynamic_ex_data_idx < 0)
210 {
211 /* Create and register the ENGINE ex_data, and associate our
212 * "free" function with it to ensure any allocated contexts get
213 * freed when an ENGINE goes underground. */
214 int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL,
215 dynamic_data_ctx_free_func);
216 if(new_idx == -1)
217 {
218 ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX,ENGINE_R_NO_INDEX);
219 return NULL;
220 }
221 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
222 /* Avoid a race by checking again inside this lock */
223 if(dynamic_ex_data_idx < 0)
224 {
225 /* Good, someone didn't beat us to it */
226 dynamic_ex_data_idx = new_idx;
227 new_idx = -1;
228 }
229 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
230 /* In theory we could "give back" the index here if
231 * (new_idx>-1), but it's not possible and wouldn't gain us much
232 * if it were. */
233 }
234 ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx);
235 /* Check if the context needs to be created */
236 if((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx))
237 /* "set_data" will set errors if necessary */
238 return NULL;
239 return ctx;
240 }
241
242static ENGINE *engine_dynamic(void)
243 {
244 ENGINE *ret = ENGINE_new();
245 if(!ret)
246 return NULL;
247 if(!ENGINE_set_id(ret, engine_dynamic_id) ||
248 !ENGINE_set_name(ret, engine_dynamic_name) ||
249 !ENGINE_set_init_function(ret, dynamic_init) ||
250 !ENGINE_set_finish_function(ret, dynamic_finish) ||
251 !ENGINE_set_ctrl_function(ret, dynamic_ctrl) ||
252 !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) ||
253 !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns))
254 {
255 ENGINE_free(ret);
256 return NULL;
257 }
258 return ret;
259 }
260
261void ENGINE_load_dynamic(void)
262 {
263 ENGINE *toadd = engine_dynamic();
264 if(!toadd) return;
265 ENGINE_add(toadd);
266 /* If the "add" worked, it gets a structural reference. So either way,
267 * we release our just-created reference. */
268 ENGINE_free(toadd);
269 /* If the "add" didn't work, it was probably a conflict because it was
270 * already added (eg. someone calling ENGINE_load_blah then calling
271 * ENGINE_load_builtin_engines() perhaps). */
272 ERR_clear_error();
273 }
274
275static int dynamic_init(ENGINE *e)
276 {
277 /* We always return failure - the "dyanamic" engine itself can't be used
278 * for anything. */
279 return 0;
280 }
281
282static int dynamic_finish(ENGINE *e)
283 {
284 /* This should never be called on account of "dynamic_init" always
285 * failing. */
286 return 0;
287 }
288
289static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
290 {
291 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
292 int initialised;
293
294 if(!ctx)
295 {
296 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_NOT_LOADED);
297 return 0;
298 }
299 initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
300 /* All our control commands require the ENGINE to be uninitialised */
301 if(initialised)
302 {
303 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
304 ENGINE_R_ALREADY_LOADED);
305 return 0;
306 }
307 switch(cmd)
308 {
309 case DYNAMIC_CMD_SO_PATH:
310 /* a NULL 'p' or a string of zero-length is the same thing */
311 if(p && (strlen((const char *)p) < 1))
312 p = NULL;
313 ctx->DYNAMIC_LIBNAME = (const char *)p;
314 return 1;
315 case DYNAMIC_CMD_NO_VCHECK:
316 ctx->no_vcheck = ((i == 0) ? 0 : 1);
317 return 1;
318 case DYNAMIC_CMD_ID:
319 /* a NULL 'p' or a string of zero-length is the same thing */
320 if(p && (strlen((const char *)p) < 1))
321 p = NULL;
322 ctx->engine_id = (const char *)p;
323 return 1;
324 case DYNAMIC_CMD_LIST_ADD:
325 if((i < 0) || (i > 2))
326 {
327 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
328 ENGINE_R_INVALID_ARGUMENT);
329 return 0;
330 }
331 ctx->list_add_value = (int)i;
332 return 1;
333 case DYNAMIC_CMD_LOAD:
334 return dynamic_load(e, ctx);
335 default:
336 break;
337 }
338 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
339 return 0;
340 }
341
342static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
343 {
344 ENGINE cpy;
345 dynamic_fns fns;
346
347 if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL,
348 ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL))
349 {
350 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
351 ENGINE_R_DSO_NOT_FOUND);
352 return 0;
353 }
354 /* We have to find a bind function otherwise it'll always end badly */
355 if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func(
356 ctx->dynamic_dso, ctx->DYNAMIC_F2)))
357 {
358 ctx->bind_engine = NULL;
359 DSO_free(ctx->dynamic_dso);
360 ctx->dynamic_dso = NULL;
361 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
362 ENGINE_R_DSO_FAILURE);
363 return 0;
364 }
365 /* Do we perform version checking? */
366 if(!ctx->no_vcheck)
367 {
368 unsigned long vcheck_res = 0;
369 /* Now we try to find a version checking function and decide how
370 * to cope with failure if/when it fails. */
371 ctx->v_check = (dynamic_v_check_fn)DSO_bind_func(
372 ctx->dynamic_dso, ctx->DYNAMIC_F1);
373 if(ctx->v_check)
374 vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION);
375 /* We fail if the version checker veto'd the load *or* if it is
376 * deferring to us (by returning its version) and we think it is
377 * too old. */
378 if(vcheck_res < OSSL_DYNAMIC_OLDEST)
379 {
380 /* Fail */
381 ctx->bind_engine = NULL;
382 ctx->v_check = NULL;
383 DSO_free(ctx->dynamic_dso);
384 ctx->dynamic_dso = NULL;
385 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
386 ENGINE_R_VERSION_INCOMPATIBILITY);
387 return 0;
388 }
389 }
390 /* First binary copy the ENGINE structure so that we can roll back if
391 * the hand-over fails */
392 memcpy(&cpy, e, sizeof(ENGINE));
393 /* Provide the ERR, "ex_data", memory, and locking callbacks so the
394 * loaded library uses our state rather than its own. FIXME: As noted in
395 * engine.h, much of this would be simplified if each area of code
396 * provided its own "summary" structure of all related callbacks. It
397 * would also increase opaqueness. */
398 fns.err_fns = ERR_get_implementation();
399 fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
400 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
401 &fns.mem_fns.realloc_cb,
402 &fns.mem_fns.free_cb);
403 fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
404 fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
405 fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
406 fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
407 fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
408 /* Now that we've loaded the dynamic engine, make sure no "dynamic"
409 * ENGINE elements will show through. */
410 engine_set_all_null(e);
411
412 /* Try to bind the ENGINE onto our own ENGINE structure */
413 if(!ctx->bind_engine(e, ctx->engine_id, &fns))
414 {
415 ctx->bind_engine = NULL;
416 ctx->v_check = NULL;
417 DSO_free(ctx->dynamic_dso);
418 ctx->dynamic_dso = NULL;
419 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED);
420 /* Copy the original ENGINE structure back */
421 memcpy(e, &cpy, sizeof(ENGINE));
422 return 0;
423 }
424 /* Do we try to add this ENGINE to the internal list too? */
425 if(ctx->list_add_value > 0)
426 {
427 if(!ENGINE_add(e))
428 {
429 /* Do we tolerate this or fail? */
430 if(ctx->list_add_value > 1)
431 {
432 /* Fail - NB: By this time, it's too late to
433 * rollback, and trying to do so allows the
434 * bind_engine() code to have created leaks. We
435 * just have to fail where we are, after the
436 * ENGINE has changed. */
437 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
438 ENGINE_R_CONFLICTING_ENGINE_ID);
439 return 0;
440 }
441 /* Tolerate */
442 ERR_clear_error();
443 }
444 }
445 return 1;
446 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_err.c b/src/lib/libssl/src/crypto/engine/eng_err.c
new file mode 100644
index 0000000000..f6c5630395
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_err.c
@@ -0,0 +1,165 @@
1/* crypto/engine/eng_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/engine.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ENGINE_str_functs[]=
68 {
69{ERR_PACK(0,ENGINE_F_DYNAMIC_CTRL,0), "DYNAMIC_CTRL"},
70{ERR_PACK(0,ENGINE_F_DYNAMIC_GET_DATA_CTX,0), "DYNAMIC_GET_DATA_CTX"},
71{ERR_PACK(0,ENGINE_F_DYNAMIC_LOAD,0), "DYNAMIC_LOAD"},
72{ERR_PACK(0,ENGINE_F_ENGINE_ADD,0), "ENGINE_add"},
73{ERR_PACK(0,ENGINE_F_ENGINE_BY_ID,0), "ENGINE_by_id"},
74{ERR_PACK(0,ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,0), "ENGINE_cmd_is_executable"},
75{ERR_PACK(0,ENGINE_F_ENGINE_CTRL,0), "ENGINE_ctrl"},
76{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD,0), "ENGINE_ctrl_cmd"},
77{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD_STRING,0), "ENGINE_ctrl_cmd_string"},
78{ERR_PACK(0,ENGINE_F_ENGINE_FINISH,0), "ENGINE_finish"},
79{ERR_PACK(0,ENGINE_F_ENGINE_FREE,0), "ENGINE_free"},
80{ERR_PACK(0,ENGINE_F_ENGINE_GET_CIPHER,0), "ENGINE_get_cipher"},
81{ERR_PACK(0,ENGINE_F_ENGINE_GET_DEFAULT_TYPE,0), "ENGINE_GET_DEFAULT_TYPE"},
82{ERR_PACK(0,ENGINE_F_ENGINE_GET_DIGEST,0), "ENGINE_get_digest"},
83{ERR_PACK(0,ENGINE_F_ENGINE_GET_NEXT,0), "ENGINE_get_next"},
84{ERR_PACK(0,ENGINE_F_ENGINE_GET_PREV,0), "ENGINE_get_prev"},
85{ERR_PACK(0,ENGINE_F_ENGINE_INIT,0), "ENGINE_init"},
86{ERR_PACK(0,ENGINE_F_ENGINE_LIST_ADD,0), "ENGINE_LIST_ADD"},
87{ERR_PACK(0,ENGINE_F_ENGINE_LIST_REMOVE,0), "ENGINE_LIST_REMOVE"},
88{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,0), "ENGINE_load_private_key"},
89{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,0), "ENGINE_load_public_key"},
90{ERR_PACK(0,ENGINE_F_ENGINE_MODULE_INIT,0), "ENGINE_MODULE_INIT"},
91{ERR_PACK(0,ENGINE_F_ENGINE_NEW,0), "ENGINE_new"},
92{ERR_PACK(0,ENGINE_F_ENGINE_REMOVE,0), "ENGINE_remove"},
93{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_STRING,0), "ENGINE_set_default_string"},
94{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_TYPE,0), "ENGINE_SET_DEFAULT_TYPE"},
95{ERR_PACK(0,ENGINE_F_ENGINE_SET_ID,0), "ENGINE_set_id"},
96{ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"},
97{ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"},
98{ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"},
99{ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"},
100{ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"},
101{ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"},
102{ERR_PACK(0,ENGINE_F_SET_DATA_CTX,0), "SET_DATA_CTX"},
103{0,NULL}
104 };
105
106static ERR_STRING_DATA ENGINE_str_reasons[]=
107 {
108{ENGINE_R_ALREADY_LOADED ,"already loaded"},
109{ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER ,"argument is not a number"},
110{ENGINE_R_CMD_NOT_EXECUTABLE ,"cmd not executable"},
111{ENGINE_R_COMMAND_TAKES_INPUT ,"command takes input"},
112{ENGINE_R_COMMAND_TAKES_NO_INPUT ,"command takes no input"},
113{ENGINE_R_CONFLICTING_ENGINE_ID ,"conflicting engine id"},
114{ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
115{ENGINE_R_DH_NOT_IMPLEMENTED ,"dh not implemented"},
116{ENGINE_R_DSA_NOT_IMPLEMENTED ,"dsa not implemented"},
117{ENGINE_R_DSO_FAILURE ,"DSO failure"},
118{ENGINE_R_DSO_NOT_FOUND ,"dso not found"},
119{ENGINE_R_ENGINES_SECTION_ERROR ,"engines section error"},
120{ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"},
121{ENGINE_R_ENGINE_SECTION_ERROR ,"engine section error"},
122{ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
123{ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
124{ENGINE_R_FINISH_FAILED ,"finish failed"},
125{ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"},
126{ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"},
127{ENGINE_R_INIT_FAILED ,"init failed"},
128{ENGINE_R_INTERNAL_LIST_ERROR ,"internal list error"},
129{ENGINE_R_INVALID_ARGUMENT ,"invalid argument"},
130{ENGINE_R_INVALID_CMD_NAME ,"invalid cmd name"},
131{ENGINE_R_INVALID_CMD_NUMBER ,"invalid cmd number"},
132{ENGINE_R_INVALID_INIT_VALUE ,"invalid init value"},
133{ENGINE_R_INVALID_STRING ,"invalid string"},
134{ENGINE_R_NOT_INITIALISED ,"not initialised"},
135{ENGINE_R_NOT_LOADED ,"not loaded"},
136{ENGINE_R_NO_CONTROL_FUNCTION ,"no control function"},
137{ENGINE_R_NO_INDEX ,"no index"},
138{ENGINE_R_NO_LOAD_FUNCTION ,"no load function"},
139{ENGINE_R_NO_REFERENCE ,"no reference"},
140{ENGINE_R_NO_SUCH_ENGINE ,"no such engine"},
141{ENGINE_R_NO_UNLOAD_FUNCTION ,"no unload function"},
142{ENGINE_R_PROVIDE_PARAMETERS ,"provide parameters"},
143{ENGINE_R_RSA_NOT_IMPLEMENTED ,"rsa not implemented"},
144{ENGINE_R_UNIMPLEMENTED_CIPHER ,"unimplemented cipher"},
145{ENGINE_R_UNIMPLEMENTED_DIGEST ,"unimplemented digest"},
146{ENGINE_R_VERSION_INCOMPATIBILITY ,"version incompatibility"},
147{0,NULL}
148 };
149
150#endif
151
152void ERR_load_ENGINE_strings(void)
153 {
154 static int init=1;
155
156 if (init)
157 {
158 init=0;
159#ifndef OPENSSL_NO_ERR
160 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_functs);
161 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_reasons);
162#endif
163
164 }
165 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_fat.c b/src/lib/libssl/src/crypto/engine/eng_fat.c
new file mode 100644
index 0000000000..af918b1499
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_fat.c
@@ -0,0 +1,148 @@
1/* crypto/engine/eng_fat.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60#include <openssl/conf.h>
61
62int ENGINE_set_default(ENGINE *e, unsigned int flags)
63 {
64 if((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
65 return 0;
66 if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
67 return 0;
68#ifndef OPENSSL_NO_RSA
69 if((flags & ENGINE_METHOD_RSA) & !ENGINE_set_default_RSA(e))
70 return 0;
71#endif
72#ifndef OPENSSL_NO_DSA
73 if((flags & ENGINE_METHOD_DSA) & !ENGINE_set_default_DSA(e))
74 return 0;
75#endif
76#ifndef OPENSSL_NO_DH
77 if((flags & ENGINE_METHOD_DH) & !ENGINE_set_default_DH(e))
78 return 0;
79#endif
80 if((flags & ENGINE_METHOD_RAND) & !ENGINE_set_default_RAND(e))
81 return 0;
82 return 1;
83 }
84
85/* Set default algorithms using a string */
86
87int int_def_cb(const char *alg, int len, void *arg)
88 {
89 unsigned int *pflags = arg;
90 if (!strncmp(alg, "ALL", len))
91 *pflags |= ENGINE_METHOD_ALL;
92 else if (!strncmp(alg, "RSA", len))
93 *pflags |= ENGINE_METHOD_RSA;
94 else if (!strncmp(alg, "DSA", len))
95 *pflags |= ENGINE_METHOD_DSA;
96 else if (!strncmp(alg, "DH", len))
97 *pflags |= ENGINE_METHOD_DH;
98 else if (!strncmp(alg, "RAND", len))
99 *pflags |= ENGINE_METHOD_RAND;
100 else if (!strncmp(alg, "CIPHERS", len))
101 *pflags |= ENGINE_METHOD_CIPHERS;
102 else if (!strncmp(alg, "DIGESTS", len))
103 *pflags |= ENGINE_METHOD_DIGESTS;
104 else
105 return 0;
106 return 1;
107 }
108
109
110int ENGINE_set_default_string(ENGINE *e, const char *list)
111 {
112 unsigned int flags = 0;
113 if (!CONF_parse_list(list, ',', 1, int_def_cb, &flags))
114 {
115 ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING,
116 ENGINE_R_INVALID_STRING);
117 ERR_add_error_data(2, "str=",list);
118 return 0;
119 }
120 return ENGINE_set_default(e, flags);
121 }
122
123int ENGINE_register_complete(ENGINE *e)
124 {
125 ENGINE_register_ciphers(e);
126 ENGINE_register_digests(e);
127#ifndef OPENSSL_NO_RSA
128 ENGINE_register_RSA(e);
129#endif
130#ifndef OPENSSL_NO_DSA
131 ENGINE_register_DSA(e);
132#endif
133#ifndef OPENSSL_NO_DH
134 ENGINE_register_DH(e);
135#endif
136 ENGINE_register_RAND(e);
137 return 1;
138 }
139
140int ENGINE_register_all_complete(void)
141 {
142 ENGINE *e;
143
144 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) {
145 ENGINE_register_complete(e);
146 }
147 return 1;
148 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_init.c b/src/lib/libssl/src/crypto/engine/eng_init.c
new file mode 100644
index 0000000000..cc9396e863
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_init.c
@@ -0,0 +1,158 @@
1/* crypto/engine/eng_init.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Initialise a engine type for use (or up its functional reference count
62 * if it's already in use). This version is only used internally. */
63int engine_unlocked_init(ENGINE *e)
64 {
65 int to_return = 1;
66
67 if((e->funct_ref == 0) && e->init)
68 /* This is the first functional reference and the engine
69 * requires initialisation so we do it now. */
70 to_return = e->init(e);
71 if(to_return)
72 {
73 /* OK, we return a functional reference which is also a
74 * structural reference. */
75 e->struct_ref++;
76 e->funct_ref++;
77 engine_ref_debug(e, 0, 1)
78 engine_ref_debug(e, 1, 1)
79 }
80 return to_return;
81 }
82
83/* Free a functional reference to a engine type. This version is only used
84 * internally. */
85int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
86 {
87 int to_return = 1;
88
89 /* Reduce the functional reference count here so if it's the terminating
90 * case, we can release the lock safely and call the finish() handler
91 * without risk of a race. We get a race if we leave the count until
92 * after and something else is calling "finish" at the same time -
93 * there's a chance that both threads will together take the count from
94 * 2 to 0 without either calling finish(). */
95 e->funct_ref--;
96 engine_ref_debug(e, 1, -1);
97 if((e->funct_ref == 0) && e->finish)
98 {
99 if(unlock_for_handlers)
100 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
101 to_return = e->finish(e);
102 if(unlock_for_handlers)
103 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
104 if(!to_return)
105 return 0;
106 }
107#ifdef REF_CHECK
108 if(e->funct_ref < 0)
109 {
110 fprintf(stderr,"ENGINE_finish, bad functional reference count\n");
111 abort();
112 }
113#endif
114 /* Release the structural reference too */
115 if(!engine_free_util(e, 0))
116 {
117 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
118 return 0;
119 }
120 return to_return;
121 }
122
123/* The API (locked) version of "init" */
124int ENGINE_init(ENGINE *e)
125 {
126 int ret;
127 if(e == NULL)
128 {
129 ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER);
130 return 0;
131 }
132 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
133 ret = engine_unlocked_init(e);
134 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
135 return ret;
136 }
137
138/* The API (locked) version of "finish" */
139int ENGINE_finish(ENGINE *e)
140 {
141 int to_return = 1;
142
143 if(e == NULL)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER);
146 return 0;
147 }
148 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
149 to_return = engine_unlocked_finish(e, 1);
150 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
151 if(!to_return)
152 {
153 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
154 return 0;
155 }
156 return to_return;
157 }
158
diff --git a/src/lib/libssl/src/crypto/engine/eng_int.h b/src/lib/libssl/src/crypto/engine/eng_int.h
new file mode 100644
index 0000000000..38335f99cd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_int.h
@@ -0,0 +1,185 @@
1/* crypto/engine/eng_int.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_INT_H
60#define HEADER_ENGINE_INT_H
61
62/* Take public definitions from engine.h */
63#include <openssl/engine.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* If we compile with this symbol defined, then both reference counts in the
70 * ENGINE structure will be monitored with a line of output on stderr for each
71 * change. This prints the engine's pointer address (truncated to unsigned int),
72 * "struct" or "funct" to indicate the reference type, the before and after
73 * reference count, and the file:line-number pair. The "engine_ref_debug"
74 * statements must come *after* the change. */
75#ifdef ENGINE_REF_COUNT_DEBUG
76
77#define engine_ref_debug(e, isfunct, diff) \
78 fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
79 (unsigned int)(e), (isfunct ? "funct" : "struct"), \
80 ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
81 ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
82 (__FILE__), (__LINE__));
83
84#else
85
86#define engine_ref_debug(e, isfunct, diff)
87
88#endif
89
90/* Any code that will need cleanup operations should use these functions to
91 * register callbacks. ENGINE_cleanup() will call all registered callbacks in
92 * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be
93 * held (in "write" mode). */
94typedef void (ENGINE_CLEANUP_CB)(void);
95typedef struct st_engine_cleanup_item
96 {
97 ENGINE_CLEANUP_CB *cb;
98 } ENGINE_CLEANUP_ITEM;
99DECLARE_STACK_OF(ENGINE_CLEANUP_ITEM)
100void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
101void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
102
103/* We need stacks of ENGINEs for use in eng_table.c */
104DECLARE_STACK_OF(ENGINE)
105
106/* If this symbol is defined then engine_table_select(), the function that is
107 * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults and
108 * functional references (etc), will display debugging summaries to stderr. */
109/* #define ENGINE_TABLE_DEBUG */
110
111/* This represents an implementation table. Dependent code should instantiate it
112 * as a (ENGINE_TABLE *) pointer value set initially to NULL. */
113typedef struct st_engine_table ENGINE_TABLE;
114int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
115 ENGINE *e, const int *nids, int num_nids, int setdefault);
116void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
117void engine_table_cleanup(ENGINE_TABLE **table);
118#ifndef ENGINE_TABLE_DEBUG
119ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
120#else
121ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l);
122#define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__)
123#endif
124
125/* Internal versions of API functions that have control over locking. These are
126 * used between C files when functionality needs to be shared but the caller may
127 * already be controlling of the CRYPTO_LOCK_ENGINE lock. */
128int engine_unlocked_init(ENGINE *e);
129int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
130int engine_free_util(ENGINE *e, int locked);
131
132/* This function will reset all "set"able values in an ENGINE to NULL. This
133 * won't touch reference counts or ex_data, but is equivalent to calling all the
134 * ENGINE_set_***() functions with a NULL value. */
135void engine_set_all_null(ENGINE *e);
136
137/* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
138 * in engine.h. */
139
140/* This is a structure for storing implementations of various crypto
141 * algorithms and functions. */
142struct engine_st
143 {
144 const char *id;
145 const char *name;
146 const RSA_METHOD *rsa_meth;
147 const DSA_METHOD *dsa_meth;
148 const DH_METHOD *dh_meth;
149 const RAND_METHOD *rand_meth;
150 /* Cipher handling is via this callback */
151 ENGINE_CIPHERS_PTR ciphers;
152 /* Digest handling is via this callback */
153 ENGINE_DIGESTS_PTR digests;
154
155
156 ENGINE_GEN_INT_FUNC_PTR destroy;
157
158 ENGINE_GEN_INT_FUNC_PTR init;
159 ENGINE_GEN_INT_FUNC_PTR finish;
160 ENGINE_CTRL_FUNC_PTR ctrl;
161 ENGINE_LOAD_KEY_PTR load_privkey;
162 ENGINE_LOAD_KEY_PTR load_pubkey;
163
164 const ENGINE_CMD_DEFN *cmd_defns;
165 int flags;
166 /* reference count on the structure itself */
167 int struct_ref;
168 /* reference count on usability of the engine type. NB: This
169 * controls the loading and initialisation of any functionlity
170 * required by this engine, whereas the previous count is
171 * simply to cope with (de)allocation of this structure. Hence,
172 * running_ref <= struct_ref at all times. */
173 int funct_ref;
174 /* A place to store per-ENGINE data */
175 CRYPTO_EX_DATA ex_data;
176 /* Used to maintain the linked-list of engines. */
177 struct engine_st *prev;
178 struct engine_st *next;
179 };
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* HEADER_ENGINE_INT_H */
diff --git a/src/lib/libssl/src/crypto/engine/eng_lib.c b/src/lib/libssl/src/crypto/engine/eng_lib.c
new file mode 100644
index 0000000000..a66d0f08af
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_lib.c
@@ -0,0 +1,321 @@
1/* crypto/engine/eng_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/rand.h> /* FIXME: This shouldn't be needed */
63#include <openssl/engine.h>
64
65/* The "new"/"free" stuff first */
66
67ENGINE *ENGINE_new(void)
68 {
69 ENGINE *ret;
70
71 ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE));
72 if(ret == NULL)
73 {
74 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
75 return NULL;
76 }
77 memset(ret, 0, sizeof(ENGINE));
78 ret->struct_ref = 1;
79 engine_ref_debug(ret, 0, 1)
80 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data);
81 return ret;
82 }
83
84/* Placed here (close proximity to ENGINE_new) so that modifications to the
85 * elements of the ENGINE structure are more likely to be caught and changed
86 * here. */
87void engine_set_all_null(ENGINE *e)
88 {
89 e->id = NULL;
90 e->name = NULL;
91 e->rsa_meth = NULL;
92 e->dsa_meth = NULL;
93 e->dh_meth = NULL;
94 e->rand_meth = NULL;
95 e->ciphers = NULL;
96 e->digests = NULL;
97 e->destroy = NULL;
98 e->init = NULL;
99 e->finish = NULL;
100 e->ctrl = NULL;
101 e->load_privkey = NULL;
102 e->load_pubkey = NULL;
103 e->cmd_defns = NULL;
104 e->flags = 0;
105 }
106
107int engine_free_util(ENGINE *e, int locked)
108 {
109 int i;
110
111 if(e == NULL)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_FREE,
114 ERR_R_PASSED_NULL_PARAMETER);
115 return 0;
116 }
117 if(locked)
118 i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
119 else
120 i = --e->struct_ref;
121 engine_ref_debug(e, 0, -1)
122 if (i > 0) return 1;
123#ifdef REF_CHECK
124 if (i < 0)
125 {
126 fprintf(stderr,"ENGINE_free, bad structural reference count\n");
127 abort();
128 }
129#endif
130 /* Give the ENGINE a chance to do any structural cleanup corresponding
131 * to allocation it did in its constructor (eg. unload error strings) */
132 if(e->destroy)
133 e->destroy(e);
134 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
135 OPENSSL_free(e);
136 return 1;
137 }
138
139int ENGINE_free(ENGINE *e)
140 {
141 return engine_free_util(e, 1);
142 }
143
144/* Cleanup stuff */
145
146/* ENGINE_cleanup() is coded such that anything that does work that will need
147 * cleanup can register a "cleanup" callback here. That way we don't get linker
148 * bloat by referring to all *possible* cleanups, but any linker bloat into code
149 * "X" will cause X's cleanup function to end up here. */
150static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL;
151static int int_cleanup_check(int create)
152 {
153 if(cleanup_stack) return 1;
154 if(!create) return 0;
155 cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null();
156 return (cleanup_stack ? 1 : 0);
157 }
158static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
159 {
160 ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof(
161 ENGINE_CLEANUP_ITEM));
162 if(!item) return NULL;
163 item->cb = cb;
164 return item;
165 }
166void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)
167 {
168 ENGINE_CLEANUP_ITEM *item;
169 if(!int_cleanup_check(1)) return;
170 item = int_cleanup_item(cb);
171 if(item)
172 sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0);
173 }
174void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
175 {
176 ENGINE_CLEANUP_ITEM *item;
177 if(!int_cleanup_check(1)) return;
178 item = int_cleanup_item(cb);
179 if(item)
180 sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item);
181 }
182/* The API function that performs all cleanup */
183static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)
184 {
185 (*(item->cb))();
186 OPENSSL_free(item);
187 }
188void ENGINE_cleanup(void)
189 {
190 if(int_cleanup_check(0))
191 {
192 sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack,
193 engine_cleanup_cb_free);
194 cleanup_stack = NULL;
195 }
196 /* FIXME: This should be handled (somehow) through RAND, eg. by it
197 * registering a cleanup callback. */
198 RAND_set_rand_method(NULL);
199 }
200
201/* Now the "ex_data" support */
202
203int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
204 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
205 {
206 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp,
207 new_func, dup_func, free_func);
208 }
209
210int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
211 {
212 return(CRYPTO_set_ex_data(&e->ex_data, idx, arg));
213 }
214
215void *ENGINE_get_ex_data(const ENGINE *e, int idx)
216 {
217 return(CRYPTO_get_ex_data(&e->ex_data, idx));
218 }
219
220/* Functions to get/set an ENGINE's elements - mainly to avoid exposing the
221 * ENGINE structure itself. */
222
223int ENGINE_set_id(ENGINE *e, const char *id)
224 {
225 if(id == NULL)
226 {
227 ENGINEerr(ENGINE_F_ENGINE_SET_ID,
228 ERR_R_PASSED_NULL_PARAMETER);
229 return 0;
230 }
231 e->id = id;
232 return 1;
233 }
234
235int ENGINE_set_name(ENGINE *e, const char *name)
236 {
237 if(name == NULL)
238 {
239 ENGINEerr(ENGINE_F_ENGINE_SET_NAME,
240 ERR_R_PASSED_NULL_PARAMETER);
241 return 0;
242 }
243 e->name = name;
244 return 1;
245 }
246
247int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f)
248 {
249 e->destroy = destroy_f;
250 return 1;
251 }
252
253int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f)
254 {
255 e->init = init_f;
256 return 1;
257 }
258
259int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f)
260 {
261 e->finish = finish_f;
262 return 1;
263 }
264
265int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)
266 {
267 e->ctrl = ctrl_f;
268 return 1;
269 }
270
271int ENGINE_set_flags(ENGINE *e, int flags)
272 {
273 e->flags = flags;
274 return 1;
275 }
276
277int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns)
278 {
279 e->cmd_defns = defns;
280 return 1;
281 }
282
283const char *ENGINE_get_id(const ENGINE *e)
284 {
285 return e->id;
286 }
287
288const char *ENGINE_get_name(const ENGINE *e)
289 {
290 return e->name;
291 }
292
293ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e)
294 {
295 return e->destroy;
296 }
297
298ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e)
299 {
300 return e->init;
301 }
302
303ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e)
304 {
305 return e->finish;
306 }
307
308ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e)
309 {
310 return e->ctrl;
311 }
312
313int ENGINE_get_flags(const ENGINE *e)
314 {
315 return e->flags;
316 }
317
318const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
319 {
320 return e->cmd_defns;
321 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_list.c b/src/lib/libssl/src/crypto/engine/eng_list.c
new file mode 100644
index 0000000000..ce48d2255a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_list.c
@@ -0,0 +1,383 @@
1/* crypto/engine/eng_list.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/engine.h>
63
64/* The linked-list of pointers to engine types. engine_list_head
65 * incorporates an implicit structural reference but engine_list_tail
66 * does not - the latter is a computational niceity and only points
67 * to something that is already pointed to by its predecessor in the
68 * list (or engine_list_head itself). In the same way, the use of the
69 * "prev" pointer in each ENGINE is to save excessive list iteration,
70 * it doesn't correspond to an extra structural reference. Hence,
71 * engine_list_head, and each non-null "next" pointer account for
72 * the list itself assuming exactly 1 structural reference on each
73 * list member. */
74static ENGINE *engine_list_head = NULL;
75static ENGINE *engine_list_tail = NULL;
76
77/* This cleanup function is only needed internally. If it should be called, we
78 * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */
79
80static void engine_list_cleanup(void)
81 {
82 ENGINE *iterator = engine_list_head;
83
84 while(iterator != NULL)
85 {
86 ENGINE_remove(iterator);
87 iterator = engine_list_head;
88 }
89 return;
90 }
91
92/* These static functions starting with a lower case "engine_" always
93 * take place when CRYPTO_LOCK_ENGINE has been locked up. */
94static int engine_list_add(ENGINE *e)
95 {
96 int conflict = 0;
97 ENGINE *iterator = NULL;
98
99 if(e == NULL)
100 {
101 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
102 ERR_R_PASSED_NULL_PARAMETER);
103 return 0;
104 }
105 iterator = engine_list_head;
106 while(iterator && !conflict)
107 {
108 conflict = (strcmp(iterator->id, e->id) == 0);
109 iterator = iterator->next;
110 }
111 if(conflict)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
114 ENGINE_R_CONFLICTING_ENGINE_ID);
115 return 0;
116 }
117 if(engine_list_head == NULL)
118 {
119 /* We are adding to an empty list. */
120 if(engine_list_tail)
121 {
122 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
123 ENGINE_R_INTERNAL_LIST_ERROR);
124 return 0;
125 }
126 engine_list_head = e;
127 e->prev = NULL;
128 /* The first time the list allocates, we should register the
129 * cleanup. */
130 engine_cleanup_add_last(engine_list_cleanup);
131 }
132 else
133 {
134 /* We are adding to the tail of an existing list. */
135 if((engine_list_tail == NULL) ||
136 (engine_list_tail->next != NULL))
137 {
138 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
139 ENGINE_R_INTERNAL_LIST_ERROR);
140 return 0;
141 }
142 engine_list_tail->next = e;
143 e->prev = engine_list_tail;
144 }
145 /* Having the engine in the list assumes a structural
146 * reference. */
147 e->struct_ref++;
148 engine_ref_debug(e, 0, 1)
149 /* However it came to be, e is the last item in the list. */
150 engine_list_tail = e;
151 e->next = NULL;
152 return 1;
153 }
154
155static int engine_list_remove(ENGINE *e)
156 {
157 ENGINE *iterator;
158
159 if(e == NULL)
160 {
161 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
162 ERR_R_PASSED_NULL_PARAMETER);
163 return 0;
164 }
165 /* We need to check that e is in our linked list! */
166 iterator = engine_list_head;
167 while(iterator && (iterator != e))
168 iterator = iterator->next;
169 if(iterator == NULL)
170 {
171 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
172 ENGINE_R_ENGINE_IS_NOT_IN_LIST);
173 return 0;
174 }
175 /* un-link e from the chain. */
176 if(e->next)
177 e->next->prev = e->prev;
178 if(e->prev)
179 e->prev->next = e->next;
180 /* Correct our head/tail if necessary. */
181 if(engine_list_head == e)
182 engine_list_head = e->next;
183 if(engine_list_tail == e)
184 engine_list_tail = e->prev;
185 engine_free_util(e, 0);
186 return 1;
187 }
188
189/* Get the first/last "ENGINE" type available. */
190ENGINE *ENGINE_get_first(void)
191 {
192 ENGINE *ret;
193
194 CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
195 ret = engine_list_head;
196 if(ret)
197 {
198 ret->struct_ref++;
199 engine_ref_debug(ret, 0, 1)
200 }
201 CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
202 return ret;
203 }
204
205ENGINE *ENGINE_get_last(void)
206 {
207 ENGINE *ret;
208
209 CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
210 ret = engine_list_tail;
211 if(ret)
212 {
213 ret->struct_ref++;
214 engine_ref_debug(ret, 0, 1)
215 }
216 CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
217 return ret;
218 }
219
220/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
221ENGINE *ENGINE_get_next(ENGINE *e)
222 {
223 ENGINE *ret = NULL;
224 if(e == NULL)
225 {
226 ENGINEerr(ENGINE_F_ENGINE_GET_NEXT,
227 ERR_R_PASSED_NULL_PARAMETER);
228 return 0;
229 }
230 CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
231 ret = e->next;
232 if(ret)
233 {
234 /* Return a valid structural refernce to the next ENGINE */
235 ret->struct_ref++;
236 engine_ref_debug(ret, 0, 1)
237 }
238 CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
239 /* Release the structural reference to the previous ENGINE */
240 ENGINE_free(e);
241 return ret;
242 }
243
244ENGINE *ENGINE_get_prev(ENGINE *e)
245 {
246 ENGINE *ret = NULL;
247 if(e == NULL)
248 {
249 ENGINEerr(ENGINE_F_ENGINE_GET_PREV,
250 ERR_R_PASSED_NULL_PARAMETER);
251 return 0;
252 }
253 CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
254 ret = e->prev;
255 if(ret)
256 {
257 /* Return a valid structural reference to the next ENGINE */
258 ret->struct_ref++;
259 engine_ref_debug(ret, 0, 1)
260 }
261 CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
262 /* Release the structural reference to the previous ENGINE */
263 ENGINE_free(e);
264 return ret;
265 }
266
267/* Add another "ENGINE" type into the list. */
268int ENGINE_add(ENGINE *e)
269 {
270 int to_return = 1;
271 if(e == NULL)
272 {
273 ENGINEerr(ENGINE_F_ENGINE_ADD,
274 ERR_R_PASSED_NULL_PARAMETER);
275 return 0;
276 }
277 if((e->id == NULL) || (e->name == NULL))
278 {
279 ENGINEerr(ENGINE_F_ENGINE_ADD,
280 ENGINE_R_ID_OR_NAME_MISSING);
281 }
282 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
283 if(!engine_list_add(e))
284 {
285 ENGINEerr(ENGINE_F_ENGINE_ADD,
286 ENGINE_R_INTERNAL_LIST_ERROR);
287 to_return = 0;
288 }
289 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
290 return to_return;
291 }
292
293/* Remove an existing "ENGINE" type from the array. */
294int ENGINE_remove(ENGINE *e)
295 {
296 int to_return = 1;
297 if(e == NULL)
298 {
299 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
300 ERR_R_PASSED_NULL_PARAMETER);
301 return 0;
302 }
303 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
304 if(!engine_list_remove(e))
305 {
306 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
307 ENGINE_R_INTERNAL_LIST_ERROR);
308 to_return = 0;
309 }
310 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
311 return to_return;
312 }
313
314static void engine_cpy(ENGINE *dest, const ENGINE *src)
315 {
316 dest->id = src->id;
317 dest->name = src->name;
318#ifndef OPENSSL_NO_RSA
319 dest->rsa_meth = src->rsa_meth;
320#endif
321#ifndef OPENSSL_NO_DSA
322 dest->dsa_meth = src->dsa_meth;
323#endif
324#ifndef OPENSSL_NO_DH
325 dest->dh_meth = src->dh_meth;
326#endif
327 dest->rand_meth = src->rand_meth;
328 dest->ciphers = src->ciphers;
329 dest->digests = src->digests;
330 dest->destroy = src->destroy;
331 dest->init = src->init;
332 dest->finish = src->finish;
333 dest->ctrl = src->ctrl;
334 dest->load_privkey = src->load_privkey;
335 dest->load_pubkey = src->load_pubkey;
336 dest->cmd_defns = src->cmd_defns;
337 dest->flags = src->flags;
338 }
339
340ENGINE *ENGINE_by_id(const char *id)
341 {
342 ENGINE *iterator;
343 if(id == NULL)
344 {
345 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return NULL;
348 }
349 CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
350 iterator = engine_list_head;
351 while(iterator && (strcmp(id, iterator->id) != 0))
352 iterator = iterator->next;
353 if(iterator)
354 {
355 /* We need to return a structural reference. If this is an
356 * ENGINE type that returns copies, make a duplicate - otherwise
357 * increment the existing ENGINE's reference count. */
358 if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY)
359 {
360 ENGINE *cp = ENGINE_new();
361 if(!cp)
362 iterator = NULL;
363 else
364 {
365 engine_cpy(cp, iterator);
366 iterator = cp;
367 }
368 }
369 else
370 {
371 iterator->struct_ref++;
372 engine_ref_debug(iterator, 0, 1)
373 }
374 }
375 CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
376 if(iterator == NULL)
377 {
378 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
379 ENGINE_R_NO_SUCH_ENGINE);
380 ERR_add_error_data(2, "id=", id);
381 }
382 return iterator;
383 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_openssl.c b/src/lib/libssl/src/crypto/engine/eng_openssl.c
new file mode 100644
index 0000000000..e9d976f46b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_openssl.c
@@ -0,0 +1,347 @@
1/* crypto/engine/eng_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/engine.h>
64#include <openssl/dso.h>
65#include <openssl/pem.h>
66
67/* This testing gunk is implemented (and explained) lower down. It also assumes
68 * the application explicitly calls "ENGINE_load_openssl()" because this is no
69 * longer automatic in ENGINE_load_builtin_engines(). */
70#define TEST_ENG_OPENSSL_RC4
71#define TEST_ENG_OPENSSL_PKEY
72/* #define TEST_ENG_OPENSSL_RC4_OTHERS */
73#define TEST_ENG_OPENSSL_RC4_P_INIT
74/* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
75#define TEST_ENG_OPENSSL_SHA
76/* #define TEST_ENG_OPENSSL_SHA_OTHERS */
77/* #define TEST_ENG_OPENSSL_SHA_P_INIT */
78/* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
79/* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
80
81#ifdef TEST_ENG_OPENSSL_RC4
82static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
83 const int **nids, int nid);
84#endif
85#ifdef TEST_ENG_OPENSSL_SHA
86static int openssl_digests(ENGINE *e, const EVP_MD **digest,
87 const int **nids, int nid);
88#endif
89
90#ifdef TEST_ENG_OPENSSL_PKEY
91static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
92 UI_METHOD *ui_method, void *callback_data);
93#endif
94
95/* The constants used when creating the ENGINE */
96static const char *engine_openssl_id = "openssl";
97static const char *engine_openssl_name = "Software engine support";
98
99/* This internal function is used by ENGINE_openssl() and possibly by the
100 * "dynamic" ENGINE support too */
101static int bind_helper(ENGINE *e)
102 {
103 if(!ENGINE_set_id(e, engine_openssl_id)
104 || !ENGINE_set_name(e, engine_openssl_name)
105#ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
106#ifndef OPENSSL_NO_RSA
107 || !ENGINE_set_RSA(e, RSA_get_default_method())
108#endif
109#ifndef OPENSSL_NO_DSA
110 || !ENGINE_set_DSA(e, DSA_get_default_method())
111#endif
112#ifndef OPENSSL_NO_DH
113 || !ENGINE_set_DH(e, DH_get_default_method())
114#endif
115 || !ENGINE_set_RAND(e, RAND_SSLeay())
116#ifdef TEST_ENG_OPENSSL_RC4
117 || !ENGINE_set_ciphers(e, openssl_ciphers)
118#endif
119#ifdef TEST_ENG_OPENSSL_SHA
120 || !ENGINE_set_digests(e, openssl_digests)
121#endif
122#endif
123#ifdef TEST_ENG_OPENSSL_PKEY
124 || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
125#endif
126 )
127 return 0;
128 /* If we add errors to this ENGINE, ensure the error handling is setup here */
129 /* openssl_load_error_strings(); */
130 return 1;
131 }
132
133static ENGINE *engine_openssl(void)
134 {
135 ENGINE *ret = ENGINE_new();
136 if(!ret)
137 return NULL;
138 if(!bind_helper(ret))
139 {
140 ENGINE_free(ret);
141 return NULL;
142 }
143 return ret;
144 }
145
146void ENGINE_load_openssl(void)
147 {
148 ENGINE *toadd = engine_openssl();
149 if(!toadd) return;
150 ENGINE_add(toadd);
151 /* If the "add" worked, it gets a structural reference. So either way,
152 * we release our just-created reference. */
153 ENGINE_free(toadd);
154 ERR_clear_error();
155 }
156
157/* This stuff is needed if this ENGINE is being compiled into a self-contained
158 * shared-library. */
159#ifdef ENGINE_DYNAMIC_SUPPORT
160static int bind_fn(ENGINE *e, const char *id)
161 {
162 if(id && (strcmp(id, engine_openssl_id) != 0))
163 return 0;
164 if(!bind_helper(e))
165 return 0;
166 return 1;
167 }
168IMPLEMENT_DYNAMIC_CHECK_FN()
169IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
170#endif /* ENGINE_DYNAMIC_SUPPORT */
171
172#ifdef TEST_ENG_OPENSSL_RC4
173/* This section of code compiles an "alternative implementation" of two modes of
174 * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
175 * should under normal circumstances go via this support rather than the default
176 * EVP support. There are other symbols to tweak the testing;
177 * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
178 * we're asked for a cipher we don't support (should not happen).
179 * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
180 * the "init_key" handler is called.
181 * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
182 */
183#include <openssl/evp.h>
184#include <openssl/rc4.h>
185#define TEST_RC4_KEY_SIZE 16
186static int test_cipher_nids[] = {NID_rc4,NID_rc4_40};
187static int test_cipher_nids_number = 2;
188typedef struct {
189 unsigned char key[TEST_RC4_KEY_SIZE];
190 RC4_KEY ks;
191 } TEST_RC4_KEY;
192#define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
193static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
194 const unsigned char *iv, int enc)
195 {
196#ifdef TEST_ENG_OPENSSL_RC4_P_INIT
197 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
198#endif
199 memcpy(&test(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
200 RC4_set_key(&test(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
201 test(ctx)->key);
202 return 1;
203 }
204static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
205 const unsigned char *in, unsigned int inl)
206 {
207#ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
208 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
209#endif
210 RC4(&test(ctx)->ks,inl,in,out);
211 return 1;
212 }
213static const EVP_CIPHER test_r4_cipher=
214 {
215 NID_rc4,
216 1,TEST_RC4_KEY_SIZE,0,
217 EVP_CIPH_VARIABLE_LENGTH,
218 test_rc4_init_key,
219 test_rc4_cipher,
220 NULL,
221 sizeof(TEST_RC4_KEY),
222 NULL,
223 NULL,
224 NULL
225 };
226static const EVP_CIPHER test_r4_40_cipher=
227 {
228 NID_rc4_40,
229 1,5 /* 40 bit */,0,
230 EVP_CIPH_VARIABLE_LENGTH,
231 test_rc4_init_key,
232 test_rc4_cipher,
233 NULL,
234 sizeof(TEST_RC4_KEY),
235 NULL,
236 NULL,
237 NULL
238 };
239static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
240 const int **nids, int nid)
241 {
242 if(!cipher)
243 {
244 /* We are returning a list of supported nids */
245 *nids = test_cipher_nids;
246 return test_cipher_nids_number;
247 }
248 /* We are being asked for a specific cipher */
249 if(nid == NID_rc4)
250 *cipher = &test_r4_cipher;
251 else if(nid == NID_rc4_40)
252 *cipher = &test_r4_40_cipher;
253 else
254 {
255#ifdef TEST_ENG_OPENSSL_RC4_OTHERS
256 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
257 "nid %d\n", nid);
258#endif
259 *cipher = NULL;
260 return 0;
261 }
262 return 1;
263 }
264#endif
265
266#ifdef TEST_ENG_OPENSSL_SHA
267/* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
268#include <openssl/evp.h>
269#include <openssl/sha.h>
270static int test_digest_nids[] = {NID_sha1};
271static int test_digest_nids_number = 1;
272static int test_sha1_init(EVP_MD_CTX *ctx)
273 {
274#ifdef TEST_ENG_OPENSSL_SHA_P_INIT
275 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
276#endif
277 return SHA1_Init(ctx->md_data);
278 }
279static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
280 {
281#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
282 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
283#endif
284 return SHA1_Update(ctx->md_data,data,count);
285 }
286static int test_sha1_final(EVP_MD_CTX *ctx,unsigned char *md)
287 {
288#ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
289 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
290#endif
291 return SHA1_Final(md,ctx->md_data);
292 }
293static const EVP_MD test_sha_md=
294 {
295 NID_sha1,
296 NID_sha1WithRSAEncryption,
297 SHA_DIGEST_LENGTH,
298 0,
299 test_sha1_init,
300 test_sha1_update,
301 test_sha1_final,
302 NULL,
303 NULL,
304 EVP_PKEY_RSA_method,
305 SHA_CBLOCK,
306 sizeof(EVP_MD *)+sizeof(SHA_CTX),
307 };
308static int openssl_digests(ENGINE *e, const EVP_MD **digest,
309 const int **nids, int nid)
310 {
311 if(!digest)
312 {
313 /* We are returning a list of supported nids */
314 *nids = test_digest_nids;
315 return test_digest_nids_number;
316 }
317 /* We are being asked for a specific digest */
318 if(nid == NID_sha1)
319 *digest = &test_sha_md;
320 else
321 {
322#ifdef TEST_ENG_OPENSSL_SHA_OTHERS
323 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
324 "nid %d\n", nid);
325#endif
326 *digest = NULL;
327 return 0;
328 }
329 return 1;
330 }
331#endif
332
333#ifdef TEST_ENG_OPENSSL_PKEY
334static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
335 UI_METHOD *ui_method, void *callback_data)
336 {
337 BIO *in;
338 EVP_PKEY *key;
339 fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
340 in = BIO_new_file(key_id, "r");
341 if (!in)
342 return NULL;
343 key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
344 BIO_free(in);
345 return key;
346 }
347#endif
diff --git a/src/lib/libssl/src/crypto/engine/eng_pkey.c b/src/lib/libssl/src/crypto/engine/eng_pkey.c
new file mode 100644
index 0000000000..8c69171511
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_pkey.c
@@ -0,0 +1,157 @@
1/* crypto/engine/eng_pkey.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Basic get/set stuff */
62
63int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f)
64 {
65 e->load_privkey = loadpriv_f;
66 return 1;
67 }
68
69int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
70 {
71 e->load_pubkey = loadpub_f;
72 return 1;
73 }
74
75ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
76 {
77 return e->load_privkey;
78 }
79
80ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
81 {
82 return e->load_pubkey;
83 }
84
85/* API functions to load public/private keys */
86
87EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
88 UI_METHOD *ui_method, void *callback_data)
89 {
90 EVP_PKEY *pkey;
91
92 if(e == NULL)
93 {
94 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
95 ERR_R_PASSED_NULL_PARAMETER);
96 return 0;
97 }
98 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
99 if(e->funct_ref == 0)
100 {
101 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
102 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
103 ENGINE_R_NOT_INITIALISED);
104 return 0;
105 }
106 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
107 if (!e->load_privkey)
108 {
109 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
110 ENGINE_R_NO_LOAD_FUNCTION);
111 return 0;
112 }
113 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
114 if (!pkey)
115 {
116 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
117 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
118 return 0;
119 }
120 return pkey;
121 }
122
123EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
124 UI_METHOD *ui_method, void *callback_data)
125 {
126 EVP_PKEY *pkey;
127
128 if(e == NULL)
129 {
130 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
131 ERR_R_PASSED_NULL_PARAMETER);
132 return 0;
133 }
134 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
135 if(e->funct_ref == 0)
136 {
137 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
138 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
139 ENGINE_R_NOT_INITIALISED);
140 return 0;
141 }
142 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
143 if (!e->load_pubkey)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
146 ENGINE_R_NO_LOAD_FUNCTION);
147 return 0;
148 }
149 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
150 if (!pkey)
151 {
152 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
153 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
154 return 0;
155 }
156 return pkey;
157 }
diff --git a/src/lib/libssl/src/crypto/engine/eng_table.c b/src/lib/libssl/src/crypto/engine/eng_table.c
new file mode 100644
index 0000000000..c69a84a8bf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/eng_table.c
@@ -0,0 +1,361 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* This is the type of item in the 'implementation' table. Each 'nid' hashes to
60 * a (potentially NULL) ENGINE_PILE structure which contains a stack of ENGINE*
61 * pointers. These pointers aren't references, because they're inserted and
62 * removed during ENGINE creation and ENGINE destruction. They point to ENGINEs
63 * that *exist* (ie. have a structural reference count greater than zero) rather
64 * than ENGINEs that are *functional*. Each pointer in those stacks are to
65 * ENGINEs that implements the algorithm corresponding to each 'nid'. */
66
67/* The type of the items in the table */
68typedef struct st_engine_pile
69 {
70 /* The 'nid' of the algorithm/mode this ENGINE_PILE structure represents
71 * */
72 int nid;
73 /* A stack of ENGINE pointers for ENGINEs that support this
74 * algorithm/mode. In the event that 'funct' is NULL, the first entry in
75 * this stack that initialises will be set as 'funct' and assumed as the
76 * default for operations of this type. */
77 STACK_OF(ENGINE) *sk;
78 /* The default ENGINE to perform this algorithm/mode. */
79 ENGINE *funct;
80 /* This value optimises engine_table_select(). If it is called it sets
81 * this value to 1. Any changes to this ENGINE_PILE resets it to zero.
82 * As such, no ENGINE_init() thrashing is done unless ENGINEs
83 * continually register (and/or unregister). */
84 int uptodate;
85 } ENGINE_PILE;
86
87/* The type of the hash table of ENGINE_PILE structures such that each are
88 * unique and keyed by the 'nid' value. */
89struct st_engine_table
90 {
91 LHASH piles;
92 }; /* ENGINE_TABLE */
93
94/* This value stores global options controlling behaviour of (mostly) the
95 * engine_table_select() function. It's a bitmask of flag values of the form
96 * ENGINE_TABLE_FLAG_*** (as defined in engine.h) and is controlled by the
97 * ENGINE_[get|set]_table_flags() function. */
98static unsigned int table_flags = 0;
99
100/* API function manipulating 'table_flags' */
101unsigned int ENGINE_get_table_flags(void)
102 {
103 return table_flags;
104 }
105void ENGINE_set_table_flags(unsigned int flags)
106 {
107 table_flags = flags;
108 }
109
110/* Internal functions for the "piles" hash table */
111static unsigned long engine_pile_hash(const ENGINE_PILE *c)
112 {
113 return c->nid;
114 }
115static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)
116 {
117 return a->nid - b->nid;
118 }
119static IMPLEMENT_LHASH_HASH_FN(engine_pile_hash, const ENGINE_PILE *)
120static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
121static int int_table_check(ENGINE_TABLE **t, int create)
122 {
123 LHASH *lh;
124 if(*t)
125 return 1;
126 if(!create)
127 return 0;
128 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
129 LHASH_COMP_FN(engine_pile_cmp))) == NULL)
130 return 0;
131 *t = (ENGINE_TABLE *)lh;
132 return 1;
133 }
134
135/* Privately exposed (via eng_int.h) functions for adding and/or removing
136 * ENGINEs from the implementation table */
137int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
138 ENGINE *e, const int *nids, int num_nids, int setdefault)
139 {
140 int ret = 0, added = 0;
141 ENGINE_PILE tmplate, *fnd;
142 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
143 if(!(*table))
144 added = 1;
145 if(!int_table_check(table, 1))
146 goto end;
147 if(added)
148 /* The cleanup callback needs to be added */
149 engine_cleanup_add_first(cleanup);
150 while(num_nids--)
151 {
152 tmplate.nid = *nids;
153 fnd = lh_retrieve(&(*table)->piles, &tmplate);
154 if(!fnd)
155 {
156 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
157 if(!fnd)
158 goto end;
159 fnd->uptodate = 1;
160 fnd->nid = *nids;
161 fnd->sk = sk_ENGINE_new_null();
162 if(!fnd->sk)
163 {
164 OPENSSL_free(fnd);
165 goto end;
166 }
167 fnd->funct= NULL;
168 lh_insert(&(*table)->piles, fnd);
169 }
170 /* A registration shouldn't add duplciate entries */
171 sk_ENGINE_delete_ptr(fnd->sk, e);
172 /* if 'setdefault', this ENGINE goes to the head of the list */
173 if(!sk_ENGINE_push(fnd->sk, e))
174 goto end;
175 /* "touch" this ENGINE_PILE */
176 fnd->uptodate = 0;
177 if(setdefault)
178 {
179 if(!engine_unlocked_init(e))
180 {
181 ENGINEerr(ENGINE_F_ENGINE_TABLE_REGISTER,
182 ENGINE_R_INIT_FAILED);
183 goto end;
184 }
185 if(fnd->funct)
186 engine_unlocked_finish(fnd->funct, 0);
187 fnd->funct = e;
188 }
189 nids++;
190 }
191 ret = 1;
192end:
193 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
194 return ret;
195 }
196static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
197 {
198 int n;
199 /* Iterate the 'c->sk' stack removing any occurance of 'e' */
200 while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
201 {
202 sk_ENGINE_delete(pile->sk, n);
203 /* "touch" this ENGINE_CIPHER */
204 pile->uptodate = 0;
205 }
206 if(pile->funct == e)
207 {
208 engine_unlocked_finish(e, 0);
209 pile->funct = NULL;
210 }
211 }
212static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
213void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)
214 {
215 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
216 if(int_table_check(table, 0))
217 lh_doall_arg(&(*table)->piles,
218 LHASH_DOALL_ARG_FN(int_unregister_cb), e);
219 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
220 }
221
222static void int_cleanup_cb(ENGINE_PILE *p)
223 {
224 sk_ENGINE_free(p->sk);
225 if(p->funct)
226 engine_unlocked_finish(p->funct, 0);
227 OPENSSL_free(p);
228 }
229static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb,ENGINE_PILE *)
230void engine_table_cleanup(ENGINE_TABLE **table)
231 {
232 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
233 if(*table)
234 {
235 lh_doall(&(*table)->piles, LHASH_DOALL_FN(int_cleanup_cb));
236 lh_free(&(*table)->piles);
237 *table = NULL;
238 }
239 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
240 }
241
242/* Exposed API function to get a functional reference from the implementation
243 * table (ie. try to get a functional reference from the tabled structural
244 * references) for a given cipher 'nid' */
245#ifndef ENGINE_TABLE_DEBUG
246ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
247#else
248ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l)
249#endif
250 {
251 ENGINE *ret = NULL;
252 ENGINE_PILE tmplate, *fnd=NULL;
253 int initres, loop = 0;
254
255 /* If 'engine_ciphers' is NULL, then it's absolutely *sure* that no
256 * ENGINEs have registered any implementations! */
257 if(!(*table))
258 {
259#ifdef ENGINE_TABLE_DEBUG
260 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
261 "registered for anything!\n", f, l, nid);
262#endif
263 return NULL;
264 }
265 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
266 /* Check again inside the lock otherwise we could race against cleanup
267 * operations. But don't worry about a fprintf(stderr). */
268 if(!int_table_check(table, 0))
269 goto end;
270 tmplate.nid = nid;
271 fnd = lh_retrieve(&(*table)->piles, &tmplate);
272 if(!fnd)
273 goto end;
274 if(fnd->funct && engine_unlocked_init(fnd->funct))
275 {
276#ifdef ENGINE_TABLE_DEBUG
277 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
278 "ENGINE '%s' cached\n", f, l, nid, fnd->funct->id);
279#endif
280 ret = fnd->funct;
281 goto end;
282 }
283 if(fnd->uptodate)
284 {
285 ret = fnd->funct;
286 goto end;
287 }
288trynext:
289 ret = sk_ENGINE_value(fnd->sk, loop++);
290 if(!ret)
291 {
292#ifdef ENGINE_TABLE_DEBUG
293 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
294 "registered implementations would initialise\n",
295 f, l, nid);
296#endif
297 goto end;
298 }
299#if 0
300 /* Don't need to get a reference if we hold the lock. If the locking has
301 * to change in future, that would be different ... */
302 ret->struct_ref++; engine_ref_debug(ret, 0, 1)
303#endif
304 /* Try and initialise the ENGINE if it's already functional *or* if the
305 * ENGINE_TABLE_FLAG_NOINIT flag is not set. */
306 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))
307 initres = engine_unlocked_init(ret);
308 else
309 initres = 0;
310#if 0
311 /* Release the structural reference */
312 ret->struct_ref--; engine_ref_debug(ret, 0, -1);
313#endif
314 if(initres)
315 {
316 /* If we didn't have a default (functional reference) for this
317 * 'nid' (or we had one but for whatever reason we're now
318 * initialising a different one), use this opportunity to set
319 * 'funct'. */
320 if((fnd->funct != ret) && engine_unlocked_init(ret))
321 {
322 /* If there was a previous default we release it. */
323 if(fnd->funct)
324 engine_unlocked_finish(fnd->funct, 0);
325 /* We got an extra functional reference for the
326 * per-'nid' default */
327 fnd->funct = ret;
328#ifdef ENGINE_TABLE_DEBUG
329 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
330 "setting default to '%s'\n", f, l, nid, ret->id);
331#endif
332 }
333#ifdef ENGINE_TABLE_DEBUG
334 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
335 "newly initialised '%s'\n", f, l, nid, ret->id);
336#endif
337 goto end;
338 }
339 goto trynext;
340end:
341 /* Whatever happened - we should "untouch" our uptodate file seeing as
342 * we have tried our best to find a functional reference for 'nid'. If
343 * it failed, it is unlikely to succeed again until some future
344 * registrations (or unregistrations) have taken place that affect that
345 * 'nid'. */
346 if(fnd)
347 fnd->uptodate = 1;
348#ifdef ENGINE_TABLE_DEBUG
349 if(ret)
350 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
351 "ENGINE '%s'\n", f, l, nid, ret->id);
352 else
353 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
354 "'no matching ENGINE'\n", f, l, nid);
355#endif
356 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
357 /* Whatever happened, any failed init()s are not failures in this
358 * context, so clear our error state. */
359 ERR_clear_error();
360 return ret;
361 }
diff --git a/src/lib/libssl/src/crypto/engine/engine.h b/src/lib/libssl/src/crypto/engine/engine.h
new file mode 100644
index 0000000000..2983f47034
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/engine.h
@@ -0,0 +1,398 @@
1/* openssl/engine.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_H
60#define HEADER_ENGINE_H
61
62#include <openssl/bn.h>
63#include <openssl/rsa.h>
64#include <openssl/dsa.h>
65#include <openssl/dh.h>
66#include <openssl/rand.h>
67#include <openssl/evp.h>
68#include <openssl/symhacks.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* These flags are used to control combinations of algorithm (methods)
75 * by bitwise "OR"ing. */
76#define ENGINE_METHOD_RSA (unsigned int)0x0001
77#define ENGINE_METHOD_DSA (unsigned int)0x0002
78#define ENGINE_METHOD_DH (unsigned int)0x0004
79#define ENGINE_METHOD_RAND (unsigned int)0x0008
80#define ENGINE_METHOD_BN_MOD_EXP (unsigned int)0x0010
81#define ENGINE_METHOD_BN_MOD_EXP_CRT (unsigned int)0x0020
82/* Obvious all-or-nothing cases. */
83#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
84#define ENGINE_METHOD_NONE (unsigned int)0x0000
85
86/* These flags are used to tell the ctrl function what should be done.
87 * All command numbers are shared between all engines, even if some don't
88 * make sense to some engines. In such a case, they do nothing but return
89 * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */
90#define ENGINE_CTRL_SET_LOGSTREAM 1
91#define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2
92/* Flags specific to the nCipher "chil" engine */
93#define ENGINE_CTRL_CHIL_SET_FORKCHECK 100
94 /* Depending on the value of the (long)i argument, this sets or
95 * unsets the SimpleForkCheck flag in the CHIL API to enable or
96 * disable checking and workarounds for applications that fork().
97 */
98#define ENGINE_CTRL_CHIL_NO_LOCKING 101
99 /* This prevents the initialisation function from providing mutex
100 * callbacks to the nCipher library. */
101
102/* As we're missing a BIGNUM_METHOD, we need a couple of locally
103 * defined function types that engines can implement. */
104
105#ifndef HEADER_ENGINE_INT_H
106/* mod_exp operation, calculates; r = a ^ p mod m
107 * NB: ctx can be NULL, but if supplied, the implementation may use
108 * it if it wishes. */
109typedef int (*BN_MOD_EXP)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
110 const BIGNUM *m, BN_CTX *ctx);
111
112/* private key operation for RSA, provided seperately in case other
113 * RSA implementations wish to use it. */
114typedef int (*BN_MOD_EXP_CRT)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
115 const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
116 const BIGNUM *iqmp, BN_CTX *ctx);
117
118/* Generic function pointer */
119typedef void (*ENGINE_GEN_FUNC_PTR)();
120/* Generic function pointer taking no arguments */
121typedef void (*ENGINE_GEN_INT_FUNC_PTR)(void);
122/* Specific control function pointer */
123typedef int (*ENGINE_CTRL_FUNC_PTR)(int cmd, long i, void *p, void (*f)());
124
125/* The list of "engine" types is a static array of (const ENGINE*)
126 * pointers (not dynamic because static is fine for now and we otherwise
127 * have to hook an appropriate load/unload function in to initialise and
128 * cleanup). */
129typedef struct engine_st ENGINE;
130#endif
131
132/* STRUCTURE functions ... all of these functions deal with pointers to
133 * ENGINE structures where the pointers have a "structural reference".
134 * This means that their reference is to allow access to the structure
135 * but it does not imply that the structure is functional. To simply
136 * increment or decrement the structural reference count, use ENGINE_new
137 * and ENGINE_free. NB: This is not required when iterating using
138 * ENGINE_get_next as it will automatically decrement the structural
139 * reference count of the "current" ENGINE and increment the structural
140 * reference count of the ENGINE it returns (unless it is NULL). */
141
142/* Get the first/last "ENGINE" type available. */
143ENGINE *ENGINE_get_first(void);
144ENGINE *ENGINE_get_last(void);
145/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
146ENGINE *ENGINE_get_next(ENGINE *e);
147ENGINE *ENGINE_get_prev(ENGINE *e);
148/* Add another "ENGINE" type into the array. */
149int ENGINE_add(ENGINE *e);
150/* Remove an existing "ENGINE" type from the array. */
151int ENGINE_remove(ENGINE *e);
152/* Retrieve an engine from the list by its unique "id" value. */
153ENGINE *ENGINE_by_id(const char *id);
154
155/* These functions are useful for manufacturing new ENGINE
156 * structures. They don't address reference counting at all -
157 * one uses them to populate an ENGINE structure with personalised
158 * implementations of things prior to using it directly or adding
159 * it to the builtin ENGINE list in OpenSSL. These are also here
160 * so that the ENGINE structure doesn't have to be exposed and
161 * break binary compatibility!
162 *
163 * NB: I'm changing ENGINE_new to force the ENGINE structure to
164 * be allocated from within OpenSSL. See the comment for
165 * ENGINE_get_struct_size().
166 */
167#if 0
168ENGINE *ENGINE_new(ENGINE *e);
169#else
170ENGINE *ENGINE_new(void);
171#endif
172int ENGINE_free(ENGINE *e);
173int ENGINE_set_id(ENGINE *e, const char *id);
174int ENGINE_set_name(ENGINE *e, const char *name);
175int ENGINE_set_RSA(ENGINE *e, RSA_METHOD *rsa_meth);
176int ENGINE_set_DSA(ENGINE *e, DSA_METHOD *dsa_meth);
177int ENGINE_set_DH(ENGINE *e, DH_METHOD *dh_meth);
178int ENGINE_set_RAND(ENGINE *e, RAND_METHOD *rand_meth);
179int ENGINE_set_BN_mod_exp(ENGINE *e, BN_MOD_EXP bn_mod_exp);
180int ENGINE_set_BN_mod_exp_crt(ENGINE *e, BN_MOD_EXP_CRT bn_mod_exp_crt);
181int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
182int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
183int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
184
185/* These return values from within the ENGINE structure. These can
186 * be useful with functional references as well as structural
187 * references - it depends which you obtained. Using the result
188 * for functional purposes if you only obtained a structural
189 * reference may be problematic! */
190const char *ENGINE_get_id(ENGINE *e);
191const char *ENGINE_get_name(ENGINE *e);
192RSA_METHOD *ENGINE_get_RSA(ENGINE *e);
193DSA_METHOD *ENGINE_get_DSA(ENGINE *e);
194DH_METHOD *ENGINE_get_DH(ENGINE *e);
195RAND_METHOD *ENGINE_get_RAND(ENGINE *e);
196BN_MOD_EXP ENGINE_get_BN_mod_exp(ENGINE *e);
197BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(ENGINE *e);
198ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(ENGINE *e);
199ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(ENGINE *e);
200ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(ENGINE *e);
201
202/* ENGINE_new is normally passed a NULL in the first parameter because
203 * the calling code doesn't have access to the definition of the ENGINE
204 * structure (for good reason). However, if the caller wishes to use
205 * its own memory allocation or use a static array, the following call
206 * should be used to check the amount of memory the ENGINE structure
207 * will occupy. This will make the code more future-proof.
208 *
209 * NB: I'm "#if 0"-ing this out because it's better to force the use of
210 * internally allocated memory. See similar change in ENGINE_new().
211 */
212#if 0
213int ENGINE_get_struct_size(void);
214#endif
215
216/* FUNCTIONAL functions. These functions deal with ENGINE structures
217 * that have (or will) be initialised for use. Broadly speaking, the
218 * structural functions are useful for iterating the list of available
219 * engine types, creating new engine types, and other "list" operations.
220 * These functions actually deal with ENGINEs that are to be used. As
221 * such these functions can fail (if applicable) when particular
222 * engines are unavailable - eg. if a hardware accelerator is not
223 * attached or not functioning correctly. Each ENGINE has 2 reference
224 * counts; structural and functional. Every time a functional reference
225 * is obtained or released, a corresponding structural reference is
226 * automatically obtained or released too. */
227
228/* Initialise a engine type for use (or up its reference count if it's
229 * already in use). This will fail if the engine is not currently
230 * operational and cannot initialise. */
231int ENGINE_init(ENGINE *e);
232/* Free a functional reference to a engine type. This does not require
233 * a corresponding call to ENGINE_free as it also releases a structural
234 * reference. */
235int ENGINE_finish(ENGINE *e);
236/* Send control parametrised commands to the engine. The possibilities
237 * to send down an integer, a pointer to data or a function pointer are
238 * provided. Any of the parameters may or may not be NULL, depending
239 * on the command number */
240/* WARNING: This is currently experimental and may change radically! */
241int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
242
243/* The following functions handle keys that are stored in some secondary
244 * location, handled by the engine. The storage may be on a card or
245 * whatever. */
246EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
247 const char *passphrase);
248EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
249 const char *passphrase);
250
251/* This returns a pointer for the current ENGINE structure that
252 * is (by default) performing any RSA operations. The value returned
253 * is an incremented reference, so it should be free'd (ENGINE_finish)
254 * before it is discarded. */
255ENGINE *ENGINE_get_default_RSA(void);
256/* Same for the other "methods" */
257ENGINE *ENGINE_get_default_DSA(void);
258ENGINE *ENGINE_get_default_DH(void);
259ENGINE *ENGINE_get_default_RAND(void);
260ENGINE *ENGINE_get_default_BN_mod_exp(void);
261ENGINE *ENGINE_get_default_BN_mod_exp_crt(void);
262
263/* This sets a new default ENGINE structure for performing RSA
264 * operations. If the result is non-zero (success) then the ENGINE
265 * structure will have had its reference count up'd so the caller
266 * should still free their own reference 'e'. */
267int ENGINE_set_default_RSA(ENGINE *e);
268/* Same for the other "methods" */
269int ENGINE_set_default_DSA(ENGINE *e);
270int ENGINE_set_default_DH(ENGINE *e);
271int ENGINE_set_default_RAND(ENGINE *e);
272int ENGINE_set_default_BN_mod_exp(ENGINE *e);
273int ENGINE_set_default_BN_mod_exp_crt(ENGINE *e);
274
275/* The combination "set" - the flags are bitwise "OR"d from the
276 * ENGINE_METHOD_*** defines above. */
277int ENGINE_set_default(ENGINE *e, unsigned int flags);
278
279/* Obligatory error function. */
280void ERR_load_ENGINE_strings(void);
281
282/*
283 * Error codes for all engine functions. NB: We use "generic"
284 * function names instead of per-implementation ones because this
285 * levels the playing field for externally implemented bootstrapped
286 * support code. As the filename and line number is included, it's
287 * more important to indicate the type of function, so that
288 * bootstrapped code (that can't easily add its own errors in) can
289 * use the same error codes too.
290 */
291
292/* BEGIN ERROR CODES */
293/* The following lines are auto generated by the script mkerr.pl. Any changes
294 * made after this point may be overwritten when the script is next run.
295 */
296
297/* Error codes for the ENGINE functions. */
298
299/* Function codes. */
300#define ENGINE_F_ATALLA_FINISH 135
301#define ENGINE_F_ATALLA_INIT 136
302#define ENGINE_F_ATALLA_MOD_EXP 137
303#define ENGINE_F_ATALLA_RSA_MOD_EXP 138
304#define ENGINE_F_CSWIFT_DSA_SIGN 133
305#define ENGINE_F_CSWIFT_DSA_VERIFY 134
306#define ENGINE_F_CSWIFT_FINISH 100
307#define ENGINE_F_CSWIFT_INIT 101
308#define ENGINE_F_CSWIFT_MOD_EXP 102
309#define ENGINE_F_CSWIFT_MOD_EXP_CRT 103
310#define ENGINE_F_CSWIFT_RSA_MOD_EXP 104
311#define ENGINE_F_ENGINE_ADD 105
312#define ENGINE_F_ENGINE_BY_ID 106
313#define ENGINE_F_ENGINE_CTRL 142
314#define ENGINE_F_ENGINE_FINISH 107
315#define ENGINE_F_ENGINE_FREE 108
316#define ENGINE_F_ENGINE_GET_BN_MOD_EXP 109
317#define ENGINE_F_ENGINE_GET_BN_MOD_EXP_CRT 110
318#define ENGINE_F_ENGINE_GET_CTRL_FUNCTION 144
319#define ENGINE_F_ENGINE_GET_DH 111
320#define ENGINE_F_ENGINE_GET_DSA 112
321#define ENGINE_F_ENGINE_GET_FINISH_FUNCTION 145
322#define ENGINE_F_ENGINE_GET_ID 113
323#define ENGINE_F_ENGINE_GET_INIT_FUNCTION 146
324#define ENGINE_F_ENGINE_GET_NAME 114
325#define ENGINE_F_ENGINE_GET_NEXT 115
326#define ENGINE_F_ENGINE_GET_PREV 116
327#define ENGINE_F_ENGINE_GET_RAND 117
328#define ENGINE_F_ENGINE_GET_RSA 118
329#define ENGINE_F_ENGINE_INIT 119
330#define ENGINE_F_ENGINE_LIST_ADD 120
331#define ENGINE_F_ENGINE_LIST_REMOVE 121
332#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
333#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
334#define ENGINE_F_ENGINE_NEW 122
335#define ENGINE_F_ENGINE_REMOVE 123
336#define ENGINE_F_ENGINE_SET_BN_MOD_EXP 124
337#define ENGINE_F_ENGINE_SET_BN_MOD_EXP_CRT 125
338#define ENGINE_F_ENGINE_SET_CTRL_FUNCTION 147
339#define ENGINE_F_ENGINE_SET_DEFAULT_TYPE 126
340#define ENGINE_F_ENGINE_SET_DH 127
341#define ENGINE_F_ENGINE_SET_DSA 128
342#define ENGINE_F_ENGINE_SET_FINISH_FUNCTION 148
343#define ENGINE_F_ENGINE_SET_ID 129
344#define ENGINE_F_ENGINE_SET_INIT_FUNCTION 149
345#define ENGINE_F_ENGINE_SET_NAME 130
346#define ENGINE_F_ENGINE_SET_RAND 131
347#define ENGINE_F_ENGINE_SET_RSA 132
348#define ENGINE_F_ENGINE_UNLOAD_KEY 152
349#define ENGINE_F_HWCRHK_CTRL 143
350#define ENGINE_F_HWCRHK_FINISH 135
351#define ENGINE_F_HWCRHK_GET_PASS 155
352#define ENGINE_F_HWCRHK_INIT 136
353#define ENGINE_F_HWCRHK_LOAD_PRIVKEY 153
354#define ENGINE_F_HWCRHK_LOAD_PUBKEY 154
355#define ENGINE_F_HWCRHK_MOD_EXP 137
356#define ENGINE_F_HWCRHK_MOD_EXP_CRT 138
357#define ENGINE_F_HWCRHK_RAND_BYTES 139
358#define ENGINE_F_HWCRHK_RSA_MOD_EXP 140
359#define ENGINE_F_LOG_MESSAGE 141
360
361/* Reason codes. */
362#define ENGINE_R_ALREADY_LOADED 100
363#define ENGINE_R_BIO_WAS_FREED 121
364#define ENGINE_R_BN_CTX_FULL 101
365#define ENGINE_R_BN_EXPAND_FAIL 102
366#define ENGINE_R_CHIL_ERROR 123
367#define ENGINE_R_CONFLICTING_ENGINE_ID 103
368#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119
369#define ENGINE_R_DSO_FAILURE 104
370#define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105
371#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128
372#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129
373#define ENGINE_R_FINISH_FAILED 106
374#define ENGINE_R_GET_HANDLE_FAILED 107
375#define ENGINE_R_ID_OR_NAME_MISSING 108
376#define ENGINE_R_INIT_FAILED 109
377#define ENGINE_R_INTERNAL_LIST_ERROR 110
378#define ENGINE_R_MISSING_KEY_COMPONENTS 111
379#define ENGINE_R_NOT_INITIALISED 117
380#define ENGINE_R_NOT_LOADED 112
381#define ENGINE_R_NO_CALLBACK 127
382#define ENGINE_R_NO_CONTROL_FUNCTION 120
383#define ENGINE_R_NO_KEY 124
384#define ENGINE_R_NO_LOAD_FUNCTION 125
385#define ENGINE_R_NO_REFERENCE 130
386#define ENGINE_R_NO_SUCH_ENGINE 116
387#define ENGINE_R_NO_UNLOAD_FUNCTION 126
388#define ENGINE_R_PROVIDE_PARAMETERS 113
389#define ENGINE_R_REQUEST_FAILED 114
390#define ENGINE_R_REQUEST_FALLBACK 118
391#define ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 122
392#define ENGINE_R_UNIT_FAILURE 115
393
394#ifdef __cplusplus
395}
396#endif
397#endif
398
diff --git a/src/lib/libssl/src/crypto/engine/enginetest.c b/src/lib/libssl/src/crypto/engine/enginetest.c
new file mode 100644
index 0000000000..a5a3c47fcb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/enginetest.c
@@ -0,0 +1,251 @@
1/* crypto/engine/enginetest.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/engine.h>
62#include <openssl/err.h>
63
64static void display_engine_list()
65 {
66 ENGINE *h;
67 int loop;
68
69 h = ENGINE_get_first();
70 loop = 0;
71 printf("listing available engine types\n");
72 while(h)
73 {
74 printf("engine %i, id = \"%s\", name = \"%s\"\n",
75 loop++, ENGINE_get_id(h), ENGINE_get_name(h));
76 h = ENGINE_get_next(h);
77 }
78 printf("end of list\n");
79 }
80
81int main(int argc, char *argv[])
82 {
83 ENGINE *block[512];
84 char buf[256];
85 const char *id, *name;
86 ENGINE *ptr;
87 int loop;
88 int to_return = 1;
89 ENGINE *new_h1 = NULL;
90 ENGINE *new_h2 = NULL;
91 ENGINE *new_h3 = NULL;
92 ENGINE *new_h4 = NULL;
93
94 ERR_load_crypto_strings();
95
96 memset(block, 0, 512 * sizeof(ENGINE *));
97 if(((new_h1 = ENGINE_new()) == NULL) ||
98 !ENGINE_set_id(new_h1, "test_id0") ||
99 !ENGINE_set_name(new_h1, "First test item") ||
100 ((new_h2 = ENGINE_new()) == NULL) ||
101 !ENGINE_set_id(new_h2, "test_id1") ||
102 !ENGINE_set_name(new_h2, "Second test item") ||
103 ((new_h3 = ENGINE_new()) == NULL) ||
104 !ENGINE_set_id(new_h3, "test_id2") ||
105 !ENGINE_set_name(new_h3, "Third test item") ||
106 ((new_h4 = ENGINE_new()) == NULL) ||
107 !ENGINE_set_id(new_h4, "test_id3") ||
108 !ENGINE_set_name(new_h4, "Fourth test item"))
109 {
110 printf("Couldn't set up test ENGINE structures\n");
111 goto end;
112 }
113 printf("\nenginetest beginning\n\n");
114 display_engine_list();
115 if(!ENGINE_add(new_h1))
116 {
117 printf("Add failed!\n");
118 goto end;
119 }
120 display_engine_list();
121 ptr = ENGINE_get_first();
122 if(!ENGINE_remove(ptr))
123 {
124 printf("Remove failed!\n");
125 goto end;
126 }
127 display_engine_list();
128 if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2))
129 {
130 printf("Add failed!\n");
131 goto end;
132 }
133 display_engine_list();
134 if(!ENGINE_remove(new_h2))
135 {
136 printf("Remove failed!\n");
137 goto end;
138 }
139 display_engine_list();
140 if(!ENGINE_add(new_h4))
141 {
142 printf("Add failed!\n");
143 goto end;
144 }
145 display_engine_list();
146 if(ENGINE_add(new_h3))
147 {
148 printf("Add *should* have failed but didn't!\n");
149 goto end;
150 }
151 else
152 printf("Add that should fail did.\n");
153 ERR_clear_error();
154 if(ENGINE_remove(new_h2))
155 {
156 printf("Remove *should* have failed but didn't!\n");
157 goto end;
158 }
159 else
160 printf("Remove that should fail did.\n");
161 if(!ENGINE_remove(new_h1))
162 {
163 printf("Remove failed!\n");
164 goto end;
165 }
166 display_engine_list();
167 if(!ENGINE_remove(new_h3))
168 {
169 printf("Remove failed!\n");
170 goto end;
171 }
172 display_engine_list();
173 if(!ENGINE_remove(new_h4))
174 {
175 printf("Remove failed!\n");
176 goto end;
177 }
178 display_engine_list();
179 /* Depending on whether there's any hardware support compiled
180 * in, this remove may be destined to fail. */
181 ptr = ENGINE_get_first();
182 if(ptr)
183 if(!ENGINE_remove(ptr))
184 printf("Remove failed!i - probably no hardware "
185 "support present.\n");
186 display_engine_list();
187 if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1))
188 {
189 printf("Couldn't add and remove to an empty list!\n");
190 goto end;
191 }
192 else
193 printf("Successfully added and removed to an empty list!\n");
194 printf("About to beef up the engine-type list\n");
195 for(loop = 0; loop < 512; loop++)
196 {
197 sprintf(buf, "id%i", loop);
198 id = strdup(buf);
199 sprintf(buf, "Fake engine type %i", loop);
200 name = strdup(buf);
201 if(((block[loop] = ENGINE_new()) == NULL) ||
202 !ENGINE_set_id(block[loop], id) ||
203 !ENGINE_set_name(block[loop], name))
204 {
205 printf("Couldn't create block of ENGINE structures.\n"
206 "I'll probably also core-dump now, damn.\n");
207 goto end;
208 }
209 }
210 for(loop = 0; loop < 512; loop++)
211 {
212 if(!ENGINE_add(block[loop]))
213 {
214 printf("\nAdding stopped at %i, (%s,%s)\n",
215 loop, ENGINE_get_id(block[loop]),
216 ENGINE_get_name(block[loop]));
217 goto cleanup_loop;
218 }
219 else
220 printf("."); fflush(stdout);
221 }
222cleanup_loop:
223 printf("\nAbout to empty the engine-type list\n");
224 while((ptr = ENGINE_get_first()) != NULL)
225 {
226 if(!ENGINE_remove(ptr))
227 {
228 printf("\nRemove failed!\n");
229 goto end;
230 }
231 printf("."); fflush(stdout);
232 }
233 for(loop = 0; loop < 512; loop++)
234 {
235 free((char *)(ENGINE_get_id(block[loop])));
236 free((char *)(ENGINE_get_name(block[loop])));
237 }
238 printf("\nTests completed happily\n");
239 to_return = 0;
240end:
241 if(to_return)
242 ERR_print_errors_fp(stderr);
243 if(new_h1) ENGINE_free(new_h1);
244 if(new_h2) ENGINE_free(new_h2);
245 if(new_h3) ENGINE_free(new_h3);
246 if(new_h4) ENGINE_free(new_h4);
247 for(loop = 0; loop < 512; loop++)
248 if(block[loop])
249 ENGINE_free(block[loop]);
250 return to_return;
251 }
diff --git a/src/lib/libssl/src/crypto/engine/hw.ec b/src/lib/libssl/src/crypto/engine/hw.ec
new file mode 100644
index 0000000000..5481a43918
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw.ec
@@ -0,0 +1,8 @@
1L AEPHK hw_aep_err.h hw_aep_err.c
2L ATALLA hw_atalla_err.h hw_atalla_err.c
3L CSWIFT hw_cswift_err.h hw_cswift_err.c
4L HWCRHK hw_ncipher_err.h hw_ncipher_err.c
5L NURON hw_nuron_err.h hw_nuron_err.c
6L SUREWARE hw_sureware_err.h hw_sureware_err.c
7L UBSEC hw_ubsec_err.h hw_ubsec_err.c
8L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c
diff --git a/src/lib/libssl/src/crypto/engine/hw_4758_cca.c b/src/lib/libssl/src/crypto/engine/hw_4758_cca.c
new file mode 100644
index 0000000000..959d8f1a61
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_4758_cca.c
@@ -0,0 +1,950 @@
1/* Author: Maurice Gittens <maurice@gittens.nl> */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include <openssl/crypto.h>
58/* #include <openssl/pem.h> */
59#include "cryptlib.h"
60#include <openssl/dso.h>
61#include <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/engine.h>
64
65#ifndef OPENSSL_NO_HW
66#ifndef OPENSSL_NO_HW_4758_CCA
67
68#ifdef FLAT_INC
69#include "hw_4758_cca.h"
70#else
71#include "vendor_defns/hw_4758_cca.h"
72#endif
73
74#include "hw_4758_cca_err.c"
75
76static int ibm_4758_cca_destroy(ENGINE *e);
77static int ibm_4758_cca_init(ENGINE *e);
78static int ibm_4758_cca_finish(ENGINE *e);
79static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
80
81/* rsa functions */
82/*---------------*/
83#ifndef OPENSSL_NO_RSA
84static int cca_rsa_pub_enc(int flen, const unsigned char *from,
85 unsigned char *to, RSA *rsa,int padding);
86static int cca_rsa_priv_dec(int flen, const unsigned char *from,
87 unsigned char *to, RSA *rsa,int padding);
88static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
89 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
90static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
91 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
92
93/* utility functions */
94/*-----------------------*/
95static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*,
96 UI_METHOD *ui_method, void *callback_data);
97static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*,
98 UI_METHOD *ui_method, void *callback_data);
99
100static int getModulusAndExponent(const unsigned char *token, long *exponentLength,
101 unsigned char *exponent, long *modulusLength,
102 long *modulusFieldLength, unsigned char *modulus);
103#endif
104
105/* RAND number functions */
106/*-----------------------*/
107static int cca_get_random_bytes(unsigned char*, int );
108static int cca_random_status(void);
109
110static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
111 int idx,long argl, void *argp);
112
113/* Function pointers for CCA verbs */
114/*---------------------------------*/
115#ifndef OPENSSL_NO_RSA
116static F_KEYRECORDREAD keyRecordRead;
117static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate;
118static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify;
119static F_PUBLICKEYEXTRACT publicKeyExtract;
120static F_PKAENCRYPT pkaEncrypt;
121static F_PKADECRYPT pkaDecrypt;
122#endif
123static F_RANDOMNUMBERGENERATE randomNumberGenerate;
124
125/* static variables */
126/*------------------*/
127static const char def_CCA4758_LIB_NAME[] = CCA_LIB_NAME;
128static const char *CCA4758_LIB_NAME = def_CCA4758_LIB_NAME;
129#ifndef OPENSSL_NO_RSA
130static const char* n_keyRecordRead = CSNDKRR;
131static const char* n_digitalSignatureGenerate = CSNDDSG;
132static const char* n_digitalSignatureVerify = CSNDDSV;
133static const char* n_publicKeyExtract = CSNDPKX;
134static const char* n_pkaEncrypt = CSNDPKE;
135static const char* n_pkaDecrypt = CSNDPKD;
136#endif
137static const char* n_randomNumberGenerate = CSNBRNG;
138
139static int hndidx = -1;
140static DSO *dso = NULL;
141
142/* openssl engine initialization structures */
143/*------------------------------------------*/
144
145#define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE
146static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = {
147 {CCA4758_CMD_SO_PATH,
148 "SO_PATH",
149 "Specifies the path to the '4758cca' shared library",
150 ENGINE_CMD_FLAG_STRING},
151 {0, NULL, NULL, 0}
152 };
153
154#ifndef OPENSSL_NO_RSA
155static RSA_METHOD ibm_4758_cca_rsa =
156 {
157 "IBM 4758 CCA RSA method",
158 cca_rsa_pub_enc,
159 NULL,
160 NULL,
161 cca_rsa_priv_dec,
162 NULL, /*rsa_mod_exp,*/
163 NULL, /*mod_exp_mont,*/
164 NULL, /* init */
165 NULL, /* finish */
166 RSA_FLAG_SIGN_VER, /* flags */
167 NULL, /* app_data */
168 cca_rsa_sign, /* rsa_sign */
169 cca_rsa_verify /* rsa_verify */
170 };
171#endif
172
173static RAND_METHOD ibm_4758_cca_rand =
174 {
175 /* "IBM 4758 RAND method", */
176 NULL, /* seed */
177 cca_get_random_bytes, /* get random bytes from the card */
178 NULL, /* cleanup */
179 NULL, /* add */
180 cca_get_random_bytes, /* pseudo rand */
181 cca_random_status, /* status */
182 };
183
184static const char *engine_4758_cca_id = "4758cca";
185static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
186
187/* engine implementation */
188/*-----------------------*/
189static int bind_helper(ENGINE *e)
190 {
191 if(!ENGINE_set_id(e, engine_4758_cca_id) ||
192 !ENGINE_set_name(e, engine_4758_cca_name) ||
193#ifndef OPENSSL_NO_RSA
194 !ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
195#endif
196 !ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
197 !ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
198 !ENGINE_set_init_function(e, ibm_4758_cca_init) ||
199 !ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
200 !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
201 !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
202 !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
203 !ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
204 return 0;
205 /* Ensure the error handling is set up */
206 ERR_load_CCA4758_strings();
207 return 1;
208 }
209
210static ENGINE *engine_4758_cca(void)
211 {
212 ENGINE *ret = ENGINE_new();
213 if(!ret)
214 return NULL;
215 if(!bind_helper(ret))
216 {
217 ENGINE_free(ret);
218 return NULL;
219 }
220 return ret;
221 }
222
223void ENGINE_load_4758cca(void)
224 {
225 ENGINE *e_4758 = engine_4758_cca();
226 if (!e_4758) return;
227 ENGINE_add(e_4758);
228 ENGINE_free(e_4758);
229 ERR_clear_error();
230 }
231
232static int ibm_4758_cca_destroy(ENGINE *e)
233 {
234 ERR_unload_CCA4758_strings();
235 return 1;
236 }
237
238static int ibm_4758_cca_init(ENGINE *e)
239 {
240 if(dso)
241 {
242 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED);
243 goto err;
244 }
245
246 dso = DSO_load(NULL, CCA4758_LIB_NAME , NULL, 0);
247 if(!dso)
248 {
249 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
250 goto err;
251 }
252
253#ifndef OPENSSL_NO_RSA
254 if(!(keyRecordRead = (F_KEYRECORDREAD)
255 DSO_bind_func(dso, n_keyRecordRead)) ||
256 !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
257 DSO_bind_func(dso, n_randomNumberGenerate)) ||
258 !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)
259 DSO_bind_func(dso, n_digitalSignatureGenerate)) ||
260 !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)
261 DSO_bind_func(dso, n_digitalSignatureVerify)) ||
262 !(publicKeyExtract = (F_PUBLICKEYEXTRACT)
263 DSO_bind_func(dso, n_publicKeyExtract)) ||
264 !(pkaEncrypt = (F_PKAENCRYPT)
265 DSO_bind_func(dso, n_pkaEncrypt)) ||
266 !(pkaDecrypt = (F_PKADECRYPT)
267 DSO_bind_func(dso, n_pkaDecrypt)))
268 {
269 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
270 goto err;
271 }
272#else
273 if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
274 DSO_bind_func(dso, n_randomNumberGenerate)))
275 {
276 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
277 goto err;
278 }
279#endif
280
281 hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
282 NULL, NULL, cca_ex_free);
283
284 return 1;
285err:
286 if(dso)
287 DSO_free(dso);
288 dso = NULL;
289
290 keyRecordRead = (F_KEYRECORDREAD)NULL;
291 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)NULL;
292 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)NULL;
293 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)NULL;
294 publicKeyExtract = (F_PUBLICKEYEXTRACT)NULL;
295 pkaEncrypt = (F_PKAENCRYPT)NULL;
296 pkaDecrypt = (F_PKADECRYPT)NULL;
297 return 0;
298 }
299
300static int ibm_4758_cca_finish(ENGINE *e)
301 {
302 if(dso)
303 {
304 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
305 CCA4758_R_NOT_LOADED);
306 return 0;
307 }
308 if(!DSO_free(dso))
309 {
310 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
311 CCA4758_R_UNIT_FAILURE);
312 return 0;
313 }
314 dso = NULL;
315 keyRecordRead = (F_KEYRECORDREAD)NULL;
316 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)NULL;
317 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)NULL;
318 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)NULL;
319 publicKeyExtract = (F_PUBLICKEYEXTRACT)NULL;
320 pkaEncrypt = (F_PKAENCRYPT)NULL;
321 pkaDecrypt = (F_PKADECRYPT)NULL;
322 return 1;
323 }
324
325static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
326 {
327 int initialised = ((dso == NULL) ? 0 : 1);
328 switch(cmd)
329 {
330 case CCA4758_CMD_SO_PATH:
331 if(p == NULL)
332 {
333 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
334 ERR_R_PASSED_NULL_PARAMETER);
335 return 0;
336 }
337 if(initialised)
338 {
339 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
340 CCA4758_R_ALREADY_LOADED);
341 return 0;
342 }
343 CCA4758_LIB_NAME = (const char *)p;
344 return 1;
345 default:
346 break;
347 }
348 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
349 CCA4758_R_COMMAND_NOT_IMPLEMENTED);
350 return 0;
351 }
352
353#ifndef OPENSSL_NO_RSA
354
355#define MAX_CCA_PKA_TOKEN_SIZE 2500
356
357static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
358 UI_METHOD *ui_method, void *callback_data)
359 {
360 RSA *rtmp = NULL;
361 EVP_PKEY *res = NULL;
362 unsigned char* keyToken = NULL;
363 unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
364 long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
365 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
366 long returnCode;
367 long reasonCode;
368 long exitDataLength = 0;
369 long ruleArrayLength = 0;
370 unsigned char exitData[8];
371 unsigned char ruleArray[8];
372 unsigned char keyLabel[64];
373 long keyLabelLength = strlen(key_id);
374 unsigned char modulus[256];
375 long modulusFieldLength = sizeof(modulus);
376 long modulusLength = 0;
377 unsigned char exponent[256];
378 long exponentLength = sizeof(exponent);
379
380 if (keyLabelLength > sizeof(keyLabel))
381 {
382 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
383 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
384 return NULL;
385 }
386
387 memset(keyLabel,' ', sizeof(keyLabel));
388 memcpy(keyLabel, key_id, keyLabelLength);
389
390 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
391 if (!keyToken)
392 {
393 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
394 ERR_R_MALLOC_FAILURE);
395 goto err;
396 }
397
398 keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
399 exitData, &ruleArrayLength, ruleArray, keyLabel,
400 &keyTokenLength, keyToken+sizeof(long));
401
402 if (returnCode)
403 {
404 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
405 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
406 goto err;
407 }
408
409 publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
410 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
411 keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
412
413 if (returnCode)
414 {
415 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
416 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
417 goto err;
418 }
419
420 if (!getModulusAndExponent(pubKeyToken, &exponentLength,
421 exponent, &modulusLength, &modulusFieldLength,
422 modulus))
423 {
424 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
425 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
426 goto err;
427 }
428
429 (*(long*)keyToken) = keyTokenLength;
430 rtmp = RSA_new_method(e);
431 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
432
433 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
434 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
435 rtmp->flags |= RSA_FLAG_EXT_PKEY;
436
437 res = EVP_PKEY_new();
438 EVP_PKEY_assign_RSA(res, rtmp);
439
440 return res;
441err:
442 if (keyToken)
443 OPENSSL_free(keyToken);
444 if (res)
445 EVP_PKEY_free(res);
446 if (rtmp)
447 RSA_free(rtmp);
448 return NULL;
449 }
450
451static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
452 UI_METHOD *ui_method, void *callback_data)
453 {
454 RSA *rtmp = NULL;
455 EVP_PKEY *res = NULL;
456 unsigned char* keyToken = NULL;
457 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
458 long returnCode;
459 long reasonCode;
460 long exitDataLength = 0;
461 long ruleArrayLength = 0;
462 unsigned char exitData[8];
463 unsigned char ruleArray[8];
464 unsigned char keyLabel[64];
465 long keyLabelLength = strlen(key_id);
466 unsigned char modulus[512];
467 long modulusFieldLength = sizeof(modulus);
468 long modulusLength = 0;
469 unsigned char exponent[512];
470 long exponentLength = sizeof(exponent);
471
472 if (keyLabelLength > sizeof(keyLabel))
473 {
474 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
475 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
476 return NULL;
477 }
478
479 memset(keyLabel,' ', sizeof(keyLabel));
480 memcpy(keyLabel, key_id, keyLabelLength);
481
482 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
483 if (!keyToken)
484 {
485 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
486 ERR_R_MALLOC_FAILURE);
487 goto err;
488 }
489
490 keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
491 &ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
492 keyToken+sizeof(long));
493
494 if (returnCode)
495 {
496 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
497 ERR_R_MALLOC_FAILURE);
498 goto err;
499 }
500
501 if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
502 exponent, &modulusLength, &modulusFieldLength, modulus))
503 {
504 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
505 CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
506 goto err;
507 }
508
509 (*(long*)keyToken) = keyTokenLength;
510 rtmp = RSA_new_method(e);
511 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
512 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
513 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
514 rtmp->flags |= RSA_FLAG_EXT_PKEY;
515 res = EVP_PKEY_new();
516 EVP_PKEY_assign_RSA(res, rtmp);
517
518 return res;
519err:
520 if (keyToken)
521 OPENSSL_free(keyToken);
522 if (res)
523 EVP_PKEY_free(res);
524 if (rtmp)
525 RSA_free(rtmp);
526 return NULL;
527 }
528
529static int cca_rsa_pub_enc(int flen, const unsigned char *from,
530 unsigned char *to, RSA *rsa,int padding)
531 {
532 long returnCode;
533 long reasonCode;
534 long lflen = flen;
535 long exitDataLength = 0;
536 unsigned char exitData[8];
537 long ruleArrayLength = 1;
538 unsigned char ruleArray[8] = "PKCS-1.2";
539 long dataStructureLength = 0;
540 unsigned char dataStructure[8];
541 long outputLength = RSA_size(rsa);
542 long keyTokenLength;
543 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
544
545 keyTokenLength = *(long*)keyToken;
546 keyToken+=sizeof(long);
547
548 pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
549 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
550 &dataStructureLength, dataStructure, &keyTokenLength,
551 keyToken, &outputLength, to);
552
553 if (returnCode || reasonCode)
554 return -(returnCode << 16 | reasonCode);
555 return outputLength;
556 }
557
558static int cca_rsa_priv_dec(int flen, const unsigned char *from,
559 unsigned char *to, RSA *rsa,int padding)
560 {
561 long returnCode;
562 long reasonCode;
563 long lflen = flen;
564 long exitDataLength = 0;
565 unsigned char exitData[8];
566 long ruleArrayLength = 1;
567 unsigned char ruleArray[8] = "PKCS-1.2";
568 long dataStructureLength = 0;
569 unsigned char dataStructure[8];
570 long outputLength = RSA_size(rsa);
571 long keyTokenLength;
572 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
573
574 keyTokenLength = *(long*)keyToken;
575 keyToken+=sizeof(long);
576
577 pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
578 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
579 &dataStructureLength, dataStructure, &keyTokenLength,
580 keyToken, &outputLength, to);
581
582 return (returnCode | reasonCode) ? 0 : 1;
583 }
584
585#define SSL_SIG_LEN 36
586
587static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
588 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
589 {
590 long returnCode;
591 long reasonCode;
592 long lsiglen = siglen;
593 long exitDataLength = 0;
594 unsigned char exitData[8];
595 long ruleArrayLength = 1;
596 unsigned char ruleArray[8] = "PKCS-1.1";
597 long keyTokenLength;
598 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
599 long length = SSL_SIG_LEN;
600 long keyLength ;
601 unsigned char *hashBuffer = NULL;
602 X509_SIG sig;
603 ASN1_TYPE parameter;
604 X509_ALGOR algorithm;
605 ASN1_OCTET_STRING digest;
606
607 keyTokenLength = *(long*)keyToken;
608 keyToken+=sizeof(long);
609
610 if (type == NID_md5 || type == NID_sha1)
611 {
612 sig.algor = &algorithm;
613 algorithm.algorithm = OBJ_nid2obj(type);
614
615 if (!algorithm.algorithm)
616 {
617 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
618 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
619 return 0;
620 }
621
622 if (!algorithm.algorithm->length)
623 {
624 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
625 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
626 return 0;
627 }
628
629 parameter.type = V_ASN1_NULL;
630 parameter.value.ptr = NULL;
631 algorithm.parameter = &parameter;
632
633 sig.digest = &digest;
634 sig.digest->data = (unsigned char*)m;
635 sig.digest->length = m_len;
636
637 length = i2d_X509_SIG(&sig, NULL);
638 }
639
640 keyLength = RSA_size(rsa);
641
642 if (length - RSA_PKCS1_PADDING > keyLength)
643 {
644 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
645 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
646 return 0;
647 }
648
649 switch (type)
650 {
651 case NID_md5_sha1 :
652 if (m_len != SSL_SIG_LEN)
653 {
654 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
655 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
656 return 0;
657 }
658
659 hashBuffer = (unsigned char *)m;
660 length = m_len;
661 break;
662 case NID_md5 :
663 {
664 unsigned char *ptr;
665 ptr = hashBuffer = OPENSSL_malloc(
666 (unsigned int)keyLength+1);
667 if (!hashBuffer)
668 {
669 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
670 ERR_R_MALLOC_FAILURE);
671 return 0;
672 }
673
674 i2d_X509_SIG(&sig, &ptr);
675 }
676 break;
677 case NID_sha1 :
678 {
679 unsigned char *ptr;
680 ptr = hashBuffer = OPENSSL_malloc(
681 (unsigned int)keyLength+1);
682 if (!hashBuffer)
683 {
684 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
685 ERR_R_MALLOC_FAILURE);
686 return 0;
687 }
688 i2d_X509_SIG(&sig, &ptr);
689 }
690 break;
691 default:
692 return 0;
693 }
694
695 digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
696 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
697 keyToken, &length, hashBuffer, &lsiglen, sigbuf);
698
699 if (type == NID_sha1 || type == NID_md5)
700 {
701 memset(hashBuffer, keyLength+1, 0);
702 OPENSSL_free(hashBuffer);
703 }
704
705 return ((returnCode || reasonCode) ? 0 : 1);
706 }
707
708#define SSL_SIG_LEN 36
709
710static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
711 unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
712 {
713 long returnCode;
714 long reasonCode;
715 long exitDataLength = 0;
716 unsigned char exitData[8];
717 long ruleArrayLength = 1;
718 unsigned char ruleArray[8] = "PKCS-1.1";
719 long outputLength=256;
720 long outputBitLength;
721 long keyTokenLength;
722 unsigned char *hashBuffer = NULL;
723 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
724 long length = SSL_SIG_LEN;
725 long keyLength ;
726 X509_SIG sig;
727 ASN1_TYPE parameter;
728 X509_ALGOR algorithm;
729 ASN1_OCTET_STRING digest;
730
731 keyTokenLength = *(long*)keyToken;
732 keyToken+=sizeof(long);
733
734 if (type == NID_md5 || type == NID_sha1)
735 {
736 sig.algor = &algorithm;
737 algorithm.algorithm = OBJ_nid2obj(type);
738
739 if (!algorithm.algorithm)
740 {
741 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
742 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
743 return 0;
744 }
745
746 if (!algorithm.algorithm->length)
747 {
748 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
749 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
750 return 0;
751 }
752
753 parameter.type = V_ASN1_NULL;
754 parameter.value.ptr = NULL;
755 algorithm.parameter = &parameter;
756
757 sig.digest = &digest;
758 sig.digest->data = (unsigned char*)m;
759 sig.digest->length = m_len;
760
761 length = i2d_X509_SIG(&sig, NULL);
762 }
763
764 keyLength = RSA_size(rsa);
765
766 if (length - RSA_PKCS1_PADDING > keyLength)
767 {
768 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
769 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
770 return 0;
771 }
772
773 switch (type)
774 {
775 case NID_md5_sha1 :
776 if (m_len != SSL_SIG_LEN)
777 {
778 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
779 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
780 return 0;
781 }
782 hashBuffer = (unsigned char*)m;
783 length = m_len;
784 break;
785 case NID_md5 :
786 {
787 unsigned char *ptr;
788 ptr = hashBuffer = OPENSSL_malloc(
789 (unsigned int)keyLength+1);
790 if (!hashBuffer)
791 {
792 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
793 ERR_R_MALLOC_FAILURE);
794 return 0;
795 }
796 i2d_X509_SIG(&sig, &ptr);
797 }
798 break;
799 case NID_sha1 :
800 {
801 unsigned char *ptr;
802 ptr = hashBuffer = OPENSSL_malloc(
803 (unsigned int)keyLength+1);
804 if (!hashBuffer)
805 {
806 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
807 ERR_R_MALLOC_FAILURE);
808 return 0;
809 }
810 i2d_X509_SIG(&sig, &ptr);
811 }
812 break;
813 default:
814 return 0;
815 }
816
817 digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
818 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
819 keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
820 sigret);
821
822 if (type == NID_sha1 || type == NID_md5)
823 {
824 memset(hashBuffer, keyLength+1, 0);
825 OPENSSL_free(hashBuffer);
826 }
827
828 *siglen = outputLength;
829
830 return ((returnCode || reasonCode) ? 0 : 1);
831 }
832
833static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
834 unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
835 unsigned char *modulus)
836 {
837 unsigned long len;
838
839 if (*token++ != (char)0x1E) /* internal PKA token? */
840 return 0;
841
842 if (*token++) /* token version must be zero */
843 return 0;
844
845 len = *token++;
846 len = len << 8;
847 len |= (unsigned char)*token++;
848
849 token += 4; /* skip reserved bytes */
850
851 if (*token++ == (char)0x04)
852 {
853 if (*token++) /* token version must be zero */
854 return 0;
855
856 len = *token++;
857 len = len << 8;
858 len |= (unsigned char)*token++;
859
860 token+=2; /* skip reserved section */
861
862 len = *token++;
863 len = len << 8;
864 len |= (unsigned char)*token++;
865
866 *exponentLength = len;
867
868 len = *token++;
869 len = len << 8;
870 len |= (unsigned char)*token++;
871
872 *modulusLength = len;
873
874 len = *token++;
875 len = len << 8;
876 len |= (unsigned char)*token++;
877
878 *modulusFieldLength = len;
879
880 memcpy(exponent, token, *exponentLength);
881 token+= *exponentLength;
882
883 memcpy(modulus, token, *modulusFieldLength);
884 return 1;
885 }
886 return 0;
887 }
888
889#endif /* OPENSSL_NO_RSA */
890
891static int cca_random_status(void)
892 {
893 return 1;
894 }
895
896static int cca_get_random_bytes(unsigned char* buf, int num)
897 {
898 long ret_code;
899 long reason_code;
900 long exit_data_length;
901 unsigned char exit_data[4];
902 unsigned char form[] = "RANDOM ";
903 unsigned char rand_buf[8];
904
905 while(num >= sizeof(rand_buf))
906 {
907 randomNumberGenerate(&ret_code, &reason_code, &exit_data_length,
908 exit_data, form, rand_buf);
909 if (ret_code)
910 return 0;
911 num -= sizeof(rand_buf);
912 memcpy(buf, rand_buf, sizeof(rand_buf));
913 buf += sizeof(rand_buf);
914 }
915
916 if (num)
917 {
918 randomNumberGenerate(&ret_code, &reason_code, NULL, NULL,
919 form, rand_buf);
920 if (ret_code)
921 return 0;
922 memcpy(buf, rand_buf, num);
923 }
924
925 return 1;
926 }
927
928static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
929 long argl, void *argp)
930 {
931 if (item)
932 OPENSSL_free(item);
933 }
934
935/* Goo to handle building as a dynamic engine */
936#ifdef ENGINE_DYNAMIC_SUPPORT
937static int bind_fn(ENGINE *e, const char *id)
938 {
939 if(id && (strcmp(id, engine_cswift_id) != 0))
940 return 0;
941 if(!bind_helper(e))
942 return 0;
943 return 1;
944 }
945IMPLEMENT_DYNAMIC_CHECK_FN()
946IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
947#endif /* ENGINE_DYNAMIC_SUPPORT */
948
949#endif /* !OPENSSL_NO_HW_4758_CCA */
950#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.c b/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.c
new file mode 100644
index 0000000000..7ea5c63707
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.c
@@ -0,0 +1,149 @@
1/* hw_4758_cca_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_4758_cca_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CCA4758_str_functs[]=
68 {
69{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"},
70{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"},
71{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"},
72{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"},
73{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"},
74{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"},
75{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA CCA4758_str_reasons[]=
80 {
81{CCA4758_R_ALREADY_LOADED ,"already loaded"},
82{CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"},
83{CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"},
84{CCA4758_R_DSO_FAILURE ,"dso failure"},
85{CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
86{CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
87{CCA4758_R_NOT_LOADED ,"not loaded"},
88{CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
89{CCA4758_R_UNIT_FAILURE ,"unit failure"},
90{CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CCA4758_LIB_NAME
97static ERR_STRING_DATA CCA4758_lib_name[]=
98 {
99{0 ,CCA4758_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CCA4758_lib_error_code=0;
106static int CCA4758_error_init=1;
107
108static void ERR_load_CCA4758_strings(void)
109 {
110 if (CCA4758_lib_error_code == 0)
111 CCA4758_lib_error_code=ERR_get_next_error_library();
112
113 if (CCA4758_error_init)
114 {
115 CCA4758_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_functs);
118 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
119#endif
120
121#ifdef CCA4758_LIB_NAME
122 CCA4758_lib_name->error = ERR_PACK(CCA4758_lib_error_code,0,0);
123 ERR_load_strings(0,CCA4758_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CCA4758_strings(void)
129 {
130 if (CCA4758_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_functs);
134 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
135#endif
136
137#ifdef CCA4758_LIB_NAME
138 ERR_unload_strings(0,CCA4758_lib_name);
139#endif
140 CCA4758_error_init=1;
141 }
142 }
143
144static void ERR_CCA4758_error(int function, int reason, char *file, int line)
145 {
146 if (CCA4758_lib_error_code == 0)
147 CCA4758_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.h b/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.h
new file mode 100644
index 0000000000..2fc563ab11
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_4758_cca_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_CCA4758_ERR_H
56#define HEADER_CCA4758_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CCA4758_strings(void);
63static void ERR_unload_CCA4758_strings(void);
64static void ERR_CCA4758_error(int function, int reason, char *file, int line);
65#define CCA4758err(f,r) ERR_CCA4758_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CCA4758 functions. */
68
69/* Function codes. */
70#define CCA4758_F_IBM_4758_CCA_CTRL 100
71#define CCA4758_F_IBM_4758_CCA_FINISH 101
72#define CCA4758_F_IBM_4758_CCA_INIT 102
73#define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103
74#define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104
75#define CCA4758_F_IBM_4758_CCA_SIGN 105
76#define CCA4758_F_IBM_4758_CCA_VERIFY 106
77
78/* Reason codes. */
79#define CCA4758_R_ALREADY_LOADED 100
80#define CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD 101
81#define CCA4758_R_COMMAND_NOT_IMPLEMENTED 102
82#define CCA4758_R_DSO_FAILURE 103
83#define CCA4758_R_FAILED_LOADING_PRIVATE_KEY 104
84#define CCA4758_R_FAILED_LOADING_PUBLIC_KEY 105
85#define CCA4758_R_NOT_LOADED 106
86#define CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
87#define CCA4758_R_UNIT_FAILURE 108
88#define CCA4758_R_UNKNOWN_ALGORITHM_TYPE 109
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_aep.c b/src/lib/libssl/src/crypto/engine/hw_aep.c
new file mode 100644
index 0000000000..cf4507cff1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_aep.c
@@ -0,0 +1,1101 @@
1/* crypto/engine/hw_aep.c */
2/*
3 */
4/* ====================================================================
5 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <stdio.h>
59#include <openssl/bn.h>
60#include <string.h>
61
62#include <openssl/e_os2.h>
63#ifndef OPENSSL_SYS_MSDOS
64#include <sys/types.h>
65#include <unistd.h>
66#else
67#include <process.h>
68typedef int pid_t;
69#endif
70
71#include <openssl/crypto.h>
72#include <openssl/dso.h>
73#include <openssl/engine.h>
74
75#ifndef OPENSSL_NO_HW
76#ifndef OPENSSL_NO_HW_AEP
77#ifdef FLAT_INC
78#include "aep.h"
79#else
80#include "vendor_defns/aep.h"
81#endif
82
83#define AEP_LIB_NAME "aep engine"
84#define FAIL_TO_SW 0x10101010
85
86#include "hw_aep_err.c"
87
88static int aep_init(ENGINE *e);
89static int aep_finish(ENGINE *e);
90static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
91static int aep_destroy(ENGINE *e);
92
93static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection);
94static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection);
95static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection);
96static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use);
97
98/* BIGNUM stuff */
99static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
100 const BIGNUM *m, BN_CTX *ctx);
101
102static AEP_RV aep_mod_exp_crt(BIGNUM *r,const BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *q, const BIGNUM *dmp1,const BIGNUM *dmq1,
104 const BIGNUM *iqmp, BN_CTX *ctx);
105
106/* RSA stuff */
107#ifndef OPENSSL_NO_RSA
108static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
109#endif
110
111/* This function is aliased to mod_exp (with the mont stuff dropped). */
112static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
113 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
114
115/* DSA stuff */
116#ifndef OPENSSL_NO_DSA
117static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
118 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
119 BN_CTX *ctx, BN_MONT_CTX *in_mont);
120
121static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
122 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
123 BN_MONT_CTX *m_ctx);
124#endif
125
126/* DH stuff */
127/* This function is aliased to mod_exp (with the DH and mont dropped). */
128#ifndef OPENSSL_NO_DH
129static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
130 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
131#endif
132
133/* rand stuff */
134#ifdef AEPRAND
135static int aep_rand(unsigned char *buf, int num);
136static int aep_rand_status(void);
137#endif
138
139/* Bignum conversion stuff */
140static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize);
141static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
142 unsigned char* AEP_BigNum);
143static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
144 unsigned char* AEP_BigNum);
145
146/* The definitions for control commands specific to this engine */
147#define AEP_CMD_SO_PATH ENGINE_CMD_BASE
148static const ENGINE_CMD_DEFN aep_cmd_defns[] =
149 {
150 { AEP_CMD_SO_PATH,
151 "SO_PATH",
152 "Specifies the path to the 'aep' shared library",
153 ENGINE_CMD_FLAG_STRING
154 },
155 {0, NULL, NULL, 0}
156 };
157
158#ifndef OPENSSL_NO_RSA
159/* Our internal RSA_METHOD that we provide pointers to */
160static RSA_METHOD aep_rsa =
161 {
162 "Aep RSA method",
163 NULL, /*rsa_pub_encrypt*/
164 NULL, /*rsa_pub_decrypt*/
165 NULL, /*rsa_priv_encrypt*/
166 NULL, /*rsa_priv_encrypt*/
167 aep_rsa_mod_exp, /*rsa_mod_exp*/
168 aep_mod_exp_mont, /*bn_mod_exp*/
169 NULL, /*init*/
170 NULL, /*finish*/
171 0, /*flags*/
172 NULL, /*app_data*/
173 NULL, /*rsa_sign*/
174 NULL /*rsa_verify*/
175 };
176#endif
177
178#ifndef OPENSSL_NO_DSA
179/* Our internal DSA_METHOD that we provide pointers to */
180static DSA_METHOD aep_dsa =
181 {
182 "Aep DSA method",
183 NULL, /* dsa_do_sign */
184 NULL, /* dsa_sign_setup */
185 NULL, /* dsa_do_verify */
186 aep_dsa_mod_exp, /* dsa_mod_exp */
187 aep_mod_exp_dsa, /* bn_mod_exp */
188 NULL, /* init */
189 NULL, /* finish */
190 0, /* flags */
191 NULL /* app_data */
192 };
193#endif
194
195#ifndef OPENSSL_NO_DH
196/* Our internal DH_METHOD that we provide pointers to */
197static DH_METHOD aep_dh =
198 {
199 "Aep DH method",
200 NULL,
201 NULL,
202 aep_mod_exp_dh,
203 NULL,
204 NULL,
205 0,
206 NULL
207 };
208#endif
209
210#ifdef AEPRAND
211/* our internal RAND_method that we provide pointers to */
212static RAND_METHOD aep_random =
213 {
214 /*"AEP RAND method", */
215 NULL,
216 aep_rand,
217 NULL,
218 NULL,
219 aep_rand,
220 aep_rand_status,
221 };
222#endif
223
224/*Define an array of structures to hold connections*/
225static AEP_CONNECTION_ENTRY aep_app_conn_table[MAX_PROCESS_CONNECTIONS];
226
227/*Used to determine if this is a new process*/
228static pid_t recorded_pid = 0;
229
230#ifdef AEPRAND
231static AEP_U8 rand_block[RAND_BLK_SIZE];
232static AEP_U32 rand_block_bytes = 0;
233#endif
234
235/* Constants used when creating the ENGINE */
236static const char *engine_aep_id = "aep";
237static const char *engine_aep_name = "Aep hardware engine support";
238
239static int max_key_len = 2176;
240
241
242/* This internal function is used by ENGINE_aep() and possibly by the
243 * "dynamic" ENGINE support too */
244static int bind_aep(ENGINE *e)
245 {
246#ifndef OPENSSL_NO_RSA
247 const RSA_METHOD *meth1;
248#endif
249#ifndef OPENSSL_NO_DSA
250 const DSA_METHOD *meth2;
251#endif
252#ifndef OPENSSL_NO_DH
253 const DH_METHOD *meth3;
254#endif
255
256 if(!ENGINE_set_id(e, engine_aep_id) ||
257 !ENGINE_set_name(e, engine_aep_name) ||
258#ifndef OPENSSL_NO_RSA
259 !ENGINE_set_RSA(e, &aep_rsa) ||
260#endif
261#ifndef OPENSSL_NO_DSA
262 !ENGINE_set_DSA(e, &aep_dsa) ||
263#endif
264#ifndef OPENSSL_NO_DH
265 !ENGINE_set_DH(e, &aep_dh) ||
266#endif
267#ifdef AEPRAND
268 !ENGINE_set_RAND(e, &aep_random) ||
269#endif
270 !ENGINE_set_init_function(e, aep_init) ||
271 !ENGINE_set_destroy_function(e, aep_destroy) ||
272 !ENGINE_set_finish_function(e, aep_finish) ||
273 !ENGINE_set_ctrl_function(e, aep_ctrl) ||
274 !ENGINE_set_cmd_defns(e, aep_cmd_defns))
275 return 0;
276
277#ifndef OPENSSL_NO_RSA
278 /* We know that the "PKCS1_SSLeay()" functions hook properly
279 * to the aep-specific mod_exp and mod_exp_crt so we use
280 * those functions. NB: We don't use ENGINE_openssl() or
281 * anything "more generic" because something like the RSAref
282 * code may not hook properly, and if you own one of these
283 * cards then you have the right to do RSA operations on it
284 * anyway! */
285 meth1 = RSA_PKCS1_SSLeay();
286 aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
287 aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
288 aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
289 aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
290#endif
291
292
293#ifndef OPENSSL_NO_DSA
294 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
295 * bits. */
296 meth2 = DSA_OpenSSL();
297 aep_dsa.dsa_do_sign = meth2->dsa_do_sign;
298 aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
299 aep_dsa.dsa_do_verify = meth2->dsa_do_verify;
300
301 aep_dsa = *DSA_get_default_method();
302 aep_dsa.dsa_mod_exp = aep_dsa_mod_exp;
303 aep_dsa.bn_mod_exp = aep_mod_exp_dsa;
304#endif
305
306#ifndef OPENSSL_NO_DH
307 /* Much the same for Diffie-Hellman */
308 meth3 = DH_OpenSSL();
309 aep_dh.generate_key = meth3->generate_key;
310 aep_dh.compute_key = meth3->compute_key;
311 aep_dh.bn_mod_exp = meth3->bn_mod_exp;
312#endif
313
314 /* Ensure the aep error handling is set up */
315 ERR_load_AEPHK_strings();
316
317 return 1;
318}
319
320#ifdef ENGINE_DYNAMIC_SUPPORT
321static int bind_helper(ENGINE *e, const char *id)
322 {
323 if(id && (strcmp(id, engine_aep_id) != 0))
324 return 0;
325 if(!bind_aep(e))
326 return 0;
327 return 1;
328 }
329IMPLEMENT_DYNAMIC_CHECK_FN()
330IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
331#else
332static ENGINE *engine_aep(void)
333 {
334 ENGINE *ret = ENGINE_new();
335 if(!ret)
336 return NULL;
337 if(!bind_aep(ret))
338 {
339 ENGINE_free(ret);
340 return NULL;
341 }
342 return ret;
343 }
344
345void ENGINE_load_aep(void)
346 {
347 /* Copied from eng_[openssl|dyn].c */
348 ENGINE *toadd = engine_aep();
349 if(!toadd) return;
350 ENGINE_add(toadd);
351 ENGINE_free(toadd);
352 ERR_clear_error();
353 }
354#endif
355
356/* This is a process-global DSO handle used for loading and unloading
357 * the Aep library. NB: This is only set (or unset) during an
358 * init() or finish() call (reference counts permitting) and they're
359 * operating with global locks, so this should be thread-safe
360 * implicitly. */
361static DSO *aep_dso = NULL;
362
363/* These are the static string constants for the DSO file name and the function
364 * symbol names to bind to.
365*/
366static const char *AEP_LIBNAME = "aep";
367
368static const char *AEP_F1 = "AEP_ModExp";
369static const char *AEP_F2 = "AEP_ModExpCrt";
370#ifdef AEPRAND
371static const char *AEP_F3 = "AEP_GenRandom";
372#endif
373static const char *AEP_F4 = "AEP_Finalize";
374static const char *AEP_F5 = "AEP_Initialize";
375static const char *AEP_F6 = "AEP_OpenConnection";
376static const char *AEP_F7 = "AEP_SetBNCallBacks";
377static const char *AEP_F8 = "AEP_CloseConnection";
378
379/* These are the function pointers that are (un)set when the library has
380 * successfully (un)loaded. */
381static t_AEP_OpenConnection *p_AEP_OpenConnection = NULL;
382static t_AEP_CloseConnection *p_AEP_CloseConnection = NULL;
383static t_AEP_ModExp *p_AEP_ModExp = NULL;
384static t_AEP_ModExpCrt *p_AEP_ModExpCrt = NULL;
385#ifdef AEPRAND
386static t_AEP_GenRandom *p_AEP_GenRandom = NULL;
387#endif
388static t_AEP_Initialize *p_AEP_Initialize = NULL;
389static t_AEP_Finalize *p_AEP_Finalize = NULL;
390static t_AEP_SetBNCallBacks *p_AEP_SetBNCallBacks = NULL;
391
392/* (de)initialisation functions. */
393static int aep_init(ENGINE *e)
394 {
395 t_AEP_ModExp *p1;
396 t_AEP_ModExpCrt *p2;
397#ifdef AEPRAND
398 t_AEP_GenRandom *p3;
399#endif
400 t_AEP_Finalize *p4;
401 t_AEP_Initialize *p5;
402 t_AEP_OpenConnection *p6;
403 t_AEP_SetBNCallBacks *p7;
404 t_AEP_CloseConnection *p8;
405
406 int to_return = 0;
407
408 if(aep_dso != NULL)
409 {
410 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED);
411 goto err;
412 }
413 /* Attempt to load libaep.so. */
414
415 aep_dso = DSO_load(NULL, AEP_LIBNAME, NULL, 0);
416
417 if(aep_dso == NULL)
418 {
419 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
420 goto err;
421 }
422
423 if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) ||
424 !(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) ||
425#ifdef AEPRAND
426 !(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) ||
427#endif
428 !(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) ||
429 !(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) ||
430 !(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) ||
431 !(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) ||
432 !(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8)))
433 {
434 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
435 goto err;
436 }
437
438 /* Copy the pointers */
439
440 p_AEP_ModExp = p1;
441 p_AEP_ModExpCrt = p2;
442#ifdef AEPRAND
443 p_AEP_GenRandom = p3;
444#endif
445 p_AEP_Finalize = p4;
446 p_AEP_Initialize = p5;
447 p_AEP_OpenConnection = p6;
448 p_AEP_SetBNCallBacks = p7;
449 p_AEP_CloseConnection = p8;
450
451 to_return = 1;
452
453 return to_return;
454
455 err:
456
457 if(aep_dso)
458 DSO_free(aep_dso);
459
460 p_AEP_OpenConnection = NULL;
461 p_AEP_ModExp = NULL;
462 p_AEP_ModExpCrt = NULL;
463#ifdef AEPRAND
464 p_AEP_GenRandom = NULL;
465#endif
466 p_AEP_Initialize = NULL;
467 p_AEP_Finalize = NULL;
468 p_AEP_SetBNCallBacks = NULL;
469 p_AEP_CloseConnection = NULL;
470
471 return to_return;
472 }
473
474/* Destructor (complements the "ENGINE_aep()" constructor) */
475static int aep_destroy(ENGINE *e)
476 {
477 ERR_unload_AEPHK_strings();
478 return 1;
479 }
480
481static int aep_finish(ENGINE *e)
482 {
483 int to_return = 0, in_use;
484 AEP_RV rv;
485
486 if(aep_dso == NULL)
487 {
488 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED);
489 goto err;
490 }
491
492 rv = aep_close_all_connections(0, &in_use);
493 if (rv != AEP_R_OK)
494 {
495 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CLOSE_HANDLES_FAILED);
496 goto err;
497 }
498 if (in_use)
499 {
500 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CONNECTIONS_IN_USE);
501 goto err;
502 }
503
504 rv = p_AEP_Finalize();
505 if (rv != AEP_R_OK)
506 {
507 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_FINALIZE_FAILED);
508 goto err;
509 }
510
511 if(!DSO_free(aep_dso))
512 {
513 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_UNIT_FAILURE);
514 goto err;
515 }
516
517 aep_dso = NULL;
518 p_AEP_CloseConnection = NULL;
519 p_AEP_OpenConnection = NULL;
520 p_AEP_ModExp = NULL;
521 p_AEP_ModExpCrt = NULL;
522#ifdef AEPRAND
523 p_AEP_GenRandom = NULL;
524#endif
525 p_AEP_Initialize = NULL;
526 p_AEP_Finalize = NULL;
527 p_AEP_SetBNCallBacks = NULL;
528
529 to_return = 1;
530 err:
531 return to_return;
532 }
533
534static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
535 {
536 int initialised = ((aep_dso == NULL) ? 0 : 1);
537 switch(cmd)
538 {
539 case AEP_CMD_SO_PATH:
540 if(p == NULL)
541 {
542 AEPHKerr(AEPHK_F_AEP_CTRL,
543 ERR_R_PASSED_NULL_PARAMETER);
544 return 0;
545 }
546 if(initialised)
547 {
548 AEPHKerr(AEPHK_F_AEP_CTRL,
549 AEPHK_R_ALREADY_LOADED);
550 return 0;
551 }
552 AEP_LIBNAME = (const char *)p;
553 return 1;
554 default:
555 break;
556 }
557 AEPHKerr(AEPHK_F_AEP_CTRL,AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED);
558 return 0;
559 }
560
561static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
562 const BIGNUM *m, BN_CTX *ctx)
563 {
564 int to_return = 0;
565 int r_len = 0;
566 AEP_CONNECTION_HNDL hConnection;
567 AEP_RV rv;
568
569 r_len = BN_num_bits(m);
570
571 /* Perform in software if modulus is too large for hardware. */
572
573 if (r_len > max_key_len){
574 AEPHKerr(AEPHK_F_AEP_MOD_EXP, AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
575 return BN_mod_exp(r, a, p, m, ctx);
576 }
577
578 /*Grab a connection from the pool*/
579 rv = aep_get_connection(&hConnection);
580 if (rv != AEP_R_OK)
581 {
582 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_GET_HANDLE_FAILED);
583 return BN_mod_exp(r, a, p, m, ctx);
584 }
585
586 /*To the card with the mod exp*/
587 rv = p_AEP_ModExp(hConnection,(void*)a, (void*)p,(void*)m, (void*)r,NULL);
588
589 if (rv != AEP_R_OK)
590 {
591 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_MOD_EXP_FAILED);
592 rv = aep_close_connection(hConnection);
593 return BN_mod_exp(r, a, p, m, ctx);
594 }
595
596 /*Return the connection to the pool*/
597 rv = aep_return_connection(hConnection);
598 if (rv != AEP_R_OK)
599 {
600 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
601 goto err;
602 }
603
604 to_return = 1;
605 err:
606 return to_return;
607 }
608
609static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
610 const BIGNUM *q, const BIGNUM *dmp1,
611 const BIGNUM *dmq1,const BIGNUM *iqmp, BN_CTX *ctx)
612 {
613 AEP_RV rv = AEP_R_OK;
614 AEP_CONNECTION_HNDL hConnection;
615
616 /*Grab a connection from the pool*/
617 rv = aep_get_connection(&hConnection);
618 if (rv != AEP_R_OK)
619 {
620 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_GET_HANDLE_FAILED);
621 return FAIL_TO_SW;
622 }
623
624 /*To the card with the mod exp*/
625 rv = p_AEP_ModExpCrt(hConnection,(void*)a, (void*)p, (void*)q, (void*)dmp1,(void*)dmq1,
626 (void*)iqmp,(void*)r,NULL);
627 if (rv != AEP_R_OK)
628 {
629 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_MOD_EXP_CRT_FAILED);
630 rv = aep_close_connection(hConnection);
631 return FAIL_TO_SW;
632 }
633
634 /*Return the connection to the pool*/
635 rv = aep_return_connection(hConnection);
636 if (rv != AEP_R_OK)
637 {
638 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
639 goto err;
640 }
641
642 err:
643 return rv;
644 }
645
646
647#ifdef AEPRAND
648static int aep_rand(unsigned char *buf,int len )
649 {
650 AEP_RV rv = AEP_R_OK;
651 AEP_CONNECTION_HNDL hConnection;
652
653 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
654
655 /*Can the request be serviced with what's already in the buffer?*/
656 if (len <= rand_block_bytes)
657 {
658 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
659 rand_block_bytes -= len;
660 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
661 }
662 else
663 /*If not the get another block of random bytes*/
664 {
665 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
666
667 rv = aep_get_connection(&hConnection);
668 if (rv != AEP_R_OK)
669 {
670 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_HANDLE_FAILED);
671 goto err_nounlock;
672 }
673
674 if (len > RAND_BLK_SIZE)
675 {
676 rv = p_AEP_GenRandom(hConnection, len, 2, buf, NULL);
677 if (rv != AEP_R_OK)
678 {
679 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
680 goto err_nounlock;
681 }
682 }
683 else
684 {
685 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
686
687 rv = p_AEP_GenRandom(hConnection, RAND_BLK_SIZE, 2, &rand_block[0], NULL);
688 if (rv != AEP_R_OK)
689 {
690 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
691
692 goto err;
693 }
694
695 rand_block_bytes = RAND_BLK_SIZE;
696
697 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
698 rand_block_bytes -= len;
699
700 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
701 }
702
703 rv = aep_return_connection(hConnection);
704 if (rv != AEP_R_OK)
705 {
706 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
707
708 goto err_nounlock;
709 }
710 }
711
712 return 1;
713 err:
714 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
715 err_nounlock:
716 return 0;
717 }
718
719static int aep_rand_status(void)
720{
721 return 1;
722}
723#endif
724
725#ifndef OPENSSL_NO_RSA
726static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
727 {
728 BN_CTX *ctx = NULL;
729 int to_return = 0;
730 AEP_RV rv = AEP_R_OK;
731
732 if ((ctx = BN_CTX_new()) == NULL)
733 goto err;
734
735 if (!aep_dso)
736 {
737 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED);
738 goto err;
739 }
740
741 /*See if we have all the necessary bits for a crt*/
742 if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp)
743 {
744 rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx);
745
746 if (rv == FAIL_TO_SW){
747 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
748 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
749 goto err;
750 }
751 else if (rv != AEP_R_OK)
752 goto err;
753 }
754 else
755 {
756 if (!rsa->d || !rsa->n)
757 {
758 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS);
759 goto err;
760 }
761
762 rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx);
763 if (rv != AEP_R_OK)
764 goto err;
765
766 }
767
768 to_return = 1;
769
770 err:
771 if(ctx)
772 BN_CTX_free(ctx);
773 return to_return;
774}
775#endif
776
777#ifndef OPENSSL_NO_DSA
778static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
779 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
780 BN_CTX *ctx, BN_MONT_CTX *in_mont)
781 {
782 BIGNUM t;
783 int to_return = 0;
784 BN_init(&t);
785
786 /* let rr = a1 ^ p1 mod m */
787 if (!aep_mod_exp(rr,a1,p1,m,ctx)) goto end;
788 /* let t = a2 ^ p2 mod m */
789 if (!aep_mod_exp(&t,a2,p2,m,ctx)) goto end;
790 /* let rr = rr * t mod m */
791 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
792 to_return = 1;
793 end:
794 BN_free(&t);
795 return to_return;
796 }
797
798static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
799 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
800 BN_MONT_CTX *m_ctx)
801 {
802 return aep_mod_exp(r, a, p, m, ctx);
803 }
804#endif
805
806/* This function is aliased to mod_exp (with the mont stuff dropped). */
807static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
808 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
809 {
810 return aep_mod_exp(r, a, p, m, ctx);
811 }
812
813#ifndef OPENSSL_NO_DH
814/* This function is aliased to mod_exp (with the dh and mont dropped). */
815static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
816 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
817 BN_MONT_CTX *m_ctx)
818 {
819 return aep_mod_exp(r, a, p, m, ctx);
820 }
821#endif
822
823static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)
824 {
825 int count;
826 AEP_RV rv = AEP_R_OK;
827
828 /*Get the current process id*/
829 pid_t curr_pid;
830
831 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
832
833 curr_pid = getpid();
834
835 /*Check if this is the first time this is being called from the current
836 process*/
837 if (recorded_pid != curr_pid)
838 {
839 /*Remember our pid so we can check if we're in a new process*/
840 recorded_pid = curr_pid;
841
842 /*Call Finalize to make sure we have not inherited some data
843 from a parent process*/
844 p_AEP_Finalize();
845
846 /*Initialise the AEP API*/
847 rv = p_AEP_Initialize(NULL);
848
849 if (rv != AEP_R_OK)
850 {
851 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_INIT_FAILURE);
852 recorded_pid = 0;
853 goto end;
854 }
855
856 /*Set the AEP big num call back functions*/
857 rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum,
858 &ConvertAEPBigNum);
859
860 if (rv != AEP_R_OK)
861 {
862 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE);
863 recorded_pid = 0;
864 goto end;
865 }
866
867#ifdef AEPRAND
868 /*Reset the rand byte count*/
869 rand_block_bytes = 0;
870#endif
871
872 /*Init the structures*/
873 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
874 {
875 aep_app_conn_table[count].conn_state = NotConnected;
876 aep_app_conn_table[count].conn_hndl = 0;
877 }
878
879 /*Open a connection*/
880 rv = p_AEP_OpenConnection(phConnection);
881
882 if (rv != AEP_R_OK)
883 {
884 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
885 recorded_pid = 0;
886 goto end;
887 }
888
889 aep_app_conn_table[0].conn_state = InUse;
890 aep_app_conn_table[0].conn_hndl = *phConnection;
891 goto end;
892 }
893 /*Check the existing connections to see if we can find a free one*/
894 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
895 {
896 if (aep_app_conn_table[count].conn_state == Connected)
897 {
898 aep_app_conn_table[count].conn_state = InUse;
899 *phConnection = aep_app_conn_table[count].conn_hndl;
900 goto end;
901 }
902 }
903 /*If no connections available, we're going to have to try
904 to open a new one*/
905 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
906 {
907 if (aep_app_conn_table[count].conn_state == NotConnected)
908 {
909 /*Open a connection*/
910 rv = p_AEP_OpenConnection(phConnection);
911
912 if (rv != AEP_R_OK)
913 {
914 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
915 goto end;
916 }
917
918 aep_app_conn_table[count].conn_state = InUse;
919 aep_app_conn_table[count].conn_hndl = *phConnection;
920 goto end;
921 }
922 }
923 rv = AEP_R_GENERAL_ERROR;
924 end:
925 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
926 return rv;
927 }
928
929
930static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection)
931 {
932 int count;
933
934 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
935
936 /*Find the connection item that matches this connection handle*/
937 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
938 {
939 if (aep_app_conn_table[count].conn_hndl == hConnection)
940 {
941 aep_app_conn_table[count].conn_state = Connected;
942 break;
943 }
944 }
945
946 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
947
948 return AEP_R_OK;
949 }
950
951static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection)
952 {
953 int count;
954 AEP_RV rv = AEP_R_OK;
955
956 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
957
958 /*Find the connection item that matches this connection handle*/
959 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
960 {
961 if (aep_app_conn_table[count].conn_hndl == hConnection)
962 {
963 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
964 if (rv != AEP_R_OK)
965 goto end;
966 aep_app_conn_table[count].conn_state = NotConnected;
967 aep_app_conn_table[count].conn_hndl = 0;
968 break;
969 }
970 }
971
972 end:
973 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
974 return rv;
975 }
976
977static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use)
978 {
979 int count;
980 AEP_RV rv = AEP_R_OK;
981
982 *in_use = 0;
983 if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
984 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
985 {
986 switch (aep_app_conn_table[count].conn_state)
987 {
988 case Connected:
989 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
990 if (rv != AEP_R_OK)
991 goto end;
992 aep_app_conn_table[count].conn_state = NotConnected;
993 aep_app_conn_table[count].conn_hndl = 0;
994 break;
995 case InUse:
996 (*in_use)++;
997 break;
998 case NotConnected:
999 break;
1000 }
1001 }
1002 end:
1003 if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
1004 return rv;
1005 }
1006
1007/*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums.
1008 Note only 32bit Openssl build support*/
1009
1010static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize)
1011 {
1012 BIGNUM* bn;
1013
1014 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1015 bn = (BIGNUM*) ArbBigNum;
1016
1017#ifdef SIXTY_FOUR_BIT_LONG
1018 *BigNumSize = bn->top << 3;
1019#else
1020 /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit
1021 words) multiplies by 4*/
1022 *BigNumSize = bn->top << 2;
1023#endif
1024
1025 return AEP_R_OK;
1026 }
1027
1028static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
1029 unsigned char* AEP_BigNum)
1030 {
1031 BIGNUM* bn;
1032
1033#ifndef SIXTY_FOUR_BIT_LONG
1034 unsigned char* buf;
1035 int i;
1036#endif
1037
1038 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1039 bn = (BIGNUM*) ArbBigNum;
1040
1041#ifdef SIXTY_FOUR_BIT_LONG
1042 memcpy(AEP_BigNum, bn->d, BigNumSize);
1043#else
1044 /*Must copy data into a (monotone) least significant byte first format
1045 performing endian conversion if necessary*/
1046 for(i=0;i<bn->top;i++)
1047 {
1048 buf = (unsigned char*)&bn->d[i];
1049
1050 *((AEP_U32*)AEP_BigNum) = (AEP_U32)
1051 ((unsigned) buf[1] << 8 | buf[0]) |
1052 ((unsigned) buf[3] << 8 | buf[2]) << 16;
1053
1054 AEP_BigNum += 4;
1055 }
1056#endif
1057
1058 return AEP_R_OK;
1059 }
1060
1061/*Turn an AEP Big Num back to a user big num*/
1062static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
1063 unsigned char* AEP_BigNum)
1064 {
1065 BIGNUM* bn;
1066#ifndef SIXTY_FOUR_BIT_LONG
1067 int i;
1068#endif
1069
1070 bn = (BIGNUM*)ArbBigNum;
1071
1072 /*Expand the result bn so that it can hold our big num.
1073 Size is in bits*/
1074 bn_expand(bn, (int)(BigNumSize << 3));
1075
1076#ifdef SIXTY_FOUR_BIT_LONG
1077 bn->top = BigNumSize >> 3;
1078
1079 if((BigNumSize & 7) != 0)
1080 bn->top++;
1081
1082 memset(bn->d, 0, bn->top << 3);
1083
1084 memcpy(bn->d, AEP_BigNum, BigNumSize);
1085#else
1086 bn->top = BigNumSize >> 2;
1087
1088 for(i=0;i<bn->top;i++)
1089 {
1090 bn->d[i] = (AEP_U32)
1091 ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 |
1092 ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]);
1093 AEP_BigNum += 4;
1094 }
1095#endif
1096
1097 return AEP_R_OK;
1098}
1099
1100#endif /* !OPENSSL_NO_HW_AEP */
1101#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_aep_err.c b/src/lib/libssl/src/crypto/engine/hw_aep_err.c
new file mode 100644
index 0000000000..092f532946
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_aep_err.c
@@ -0,0 +1,157 @@
1/* hw_aep_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_aep_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA AEPHK_str_functs[]=
68 {
69{ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"},
70{ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"},
71{ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"},
72{ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"},
73{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"},
74{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"},
75{ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"},
76{ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA AEPHK_str_reasons[]=
81 {
82{AEPHK_R_ALREADY_LOADED ,"already loaded"},
83{AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"},
84{AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"},
85{AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
86{AEPHK_R_FINALIZE_FAILED ,"finalize failed"},
87{AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"},
88{AEPHK_R_GET_RANDOM_FAILED ,"get random failed"},
89{AEPHK_R_INIT_FAILURE ,"init failure"},
90{AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
91{AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"},
92{AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"},
93{AEPHK_R_NOT_LOADED ,"not loaded"},
94{AEPHK_R_OK ,"ok"},
95{AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"},
96{AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"},
97{AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
98{AEPHK_R_UNIT_FAILURE ,"unit failure"},
99{0,NULL}
100 };
101
102#endif
103
104#ifdef AEPHK_LIB_NAME
105static ERR_STRING_DATA AEPHK_lib_name[]=
106 {
107{0 ,AEPHK_LIB_NAME},
108{0,NULL}
109 };
110#endif
111
112
113static int AEPHK_lib_error_code=0;
114static int AEPHK_error_init=1;
115
116static void ERR_load_AEPHK_strings(void)
117 {
118 if (AEPHK_lib_error_code == 0)
119 AEPHK_lib_error_code=ERR_get_next_error_library();
120
121 if (AEPHK_error_init)
122 {
123 AEPHK_error_init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs);
126 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
127#endif
128
129#ifdef AEPHK_LIB_NAME
130 AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0);
131 ERR_load_strings(0,AEPHK_lib_name);
132#endif
133 }
134 }
135
136static void ERR_unload_AEPHK_strings(void)
137 {
138 if (AEPHK_error_init == 0)
139 {
140#ifndef OPENSSL_NO_ERR
141 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs);
142 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
143#endif
144
145#ifdef AEPHK_LIB_NAME
146 ERR_unload_strings(0,AEPHK_lib_name);
147#endif
148 AEPHK_error_init=1;
149 }
150 }
151
152static void ERR_AEPHK_error(int function, int reason, char *file, int line)
153 {
154 if (AEPHK_lib_error_code == 0)
155 AEPHK_lib_error_code=ERR_get_next_error_library();
156 ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line);
157 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_aep_err.h b/src/lib/libssl/src/crypto/engine/hw_aep_err.h
new file mode 100644
index 0000000000..8fe4cf921f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_aep_err.h
@@ -0,0 +1,101 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_AEPHK_ERR_H
56#define HEADER_AEPHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_AEPHK_strings(void);
63static void ERR_unload_AEPHK_strings(void);
64static void ERR_AEPHK_error(int function, int reason, char *file, int line);
65#define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the AEPHK functions. */
68
69/* Function codes. */
70#define AEPHK_F_AEP_CTRL 100
71#define AEPHK_F_AEP_FINISH 101
72#define AEPHK_F_AEP_GET_CONNECTION 102
73#define AEPHK_F_AEP_INIT 103
74#define AEPHK_F_AEP_MOD_EXP 104
75#define AEPHK_F_AEP_MOD_EXP_CRT 105
76#define AEPHK_F_AEP_RAND 106
77#define AEPHK_F_AEP_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define AEPHK_R_ALREADY_LOADED 100
81#define AEPHK_R_CLOSE_HANDLES_FAILED 101
82#define AEPHK_R_CONNECTIONS_IN_USE 102
83#define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
84#define AEPHK_R_FINALIZE_FAILED 104
85#define AEPHK_R_GET_HANDLE_FAILED 105
86#define AEPHK_R_GET_RANDOM_FAILED 106
87#define AEPHK_R_INIT_FAILURE 107
88#define AEPHK_R_MISSING_KEY_COMPONENTS 108
89#define AEPHK_R_MOD_EXP_CRT_FAILED 109
90#define AEPHK_R_MOD_EXP_FAILED 110
91#define AEPHK_R_NOT_LOADED 111
92#define AEPHK_R_OK 112
93#define AEPHK_R_RETURN_CONNECTION_FAILED 113
94#define AEPHK_R_SETBNCALLBACK_FAILURE 114
95#define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116
96#define AEPHK_R_UNIT_FAILURE 115
97
98#ifdef __cplusplus
99}
100#endif
101#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_atalla.c b/src/lib/libssl/src/crypto/engine/hw_atalla.c
new file mode 100644
index 0000000000..3bb992a193
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_atalla.c
@@ -0,0 +1,444 @@
1/* crypto/engine/hw_atalla.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include "engine_int.h"
64#include <openssl/engine.h>
65
66#ifndef NO_HW
67#ifndef NO_HW_ATALLA
68
69#ifdef FLAT_INC
70#include "atalla.h"
71#else
72#include "vendor_defns/atalla.h"
73#endif
74
75static int atalla_init(void);
76static int atalla_finish(void);
77
78/* BIGNUM stuff */
79static int atalla_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
80 const BIGNUM *m, BN_CTX *ctx);
81
82/* RSA stuff */
83static int atalla_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
84/* This function is aliased to mod_exp (with the mont stuff dropped). */
85static int atalla_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
86 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
87
88/* DSA stuff */
89static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
90 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
91 BN_CTX *ctx, BN_MONT_CTX *in_mont);
92static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
93 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
94 BN_MONT_CTX *m_ctx);
95
96/* DH stuff */
97/* This function is alised to mod_exp (with the DH and mont dropped). */
98static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
99 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
100
101
102/* Our internal RSA_METHOD that we provide pointers to */
103static RSA_METHOD atalla_rsa =
104 {
105 "Atalla RSA method",
106 NULL,
107 NULL,
108 NULL,
109 NULL,
110 atalla_rsa_mod_exp,
111 atalla_mod_exp_mont,
112 NULL,
113 NULL,
114 0,
115 NULL,
116 NULL,
117 NULL
118 };
119
120/* Our internal DSA_METHOD that we provide pointers to */
121static DSA_METHOD atalla_dsa =
122 {
123 "Atalla DSA method",
124 NULL, /* dsa_do_sign */
125 NULL, /* dsa_sign_setup */
126 NULL, /* dsa_do_verify */
127 atalla_dsa_mod_exp, /* dsa_mod_exp */
128 atalla_mod_exp_dsa, /* bn_mod_exp */
129 NULL, /* init */
130 NULL, /* finish */
131 0, /* flags */
132 NULL /* app_data */
133 };
134
135/* Our internal DH_METHOD that we provide pointers to */
136static DH_METHOD atalla_dh =
137 {
138 "Atalla DH method",
139 NULL,
140 NULL,
141 atalla_mod_exp_dh,
142 NULL,
143 NULL,
144 0,
145 NULL
146 };
147
148/* Our ENGINE structure. */
149static ENGINE engine_atalla =
150 {
151 "atalla",
152 "Atalla hardware engine support",
153 &atalla_rsa,
154 &atalla_dsa,
155 &atalla_dh,
156 NULL,
157 atalla_mod_exp,
158 NULL,
159 atalla_init,
160 atalla_finish,
161 NULL, /* no ctrl() */
162 NULL, /* no load_privkey() */
163 NULL, /* no load_pubkey() */
164 0, /* no flags */
165 0, 0, /* no references */
166 NULL, NULL /* unlinked */
167 };
168
169/* As this is only ever called once, there's no need for locking
170 * (indeed - the lock will already be held by our caller!!!) */
171ENGINE *ENGINE_atalla()
172 {
173 RSA_METHOD *meth1;
174 DSA_METHOD *meth2;
175 DH_METHOD *meth3;
176
177 /* We know that the "PKCS1_SSLeay()" functions hook properly
178 * to the atalla-specific mod_exp and mod_exp_crt so we use
179 * those functions. NB: We don't use ENGINE_openssl() or
180 * anything "more generic" because something like the RSAref
181 * code may not hook properly, and if you own one of these
182 * cards then you have the right to do RSA operations on it
183 * anyway! */
184 meth1 = RSA_PKCS1_SSLeay();
185 atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
186 atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
187 atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
188 atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
189
190 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
191 * bits. */
192 meth2 = DSA_OpenSSL();
193 atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
194 atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
195 atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
196
197 /* Much the same for Diffie-Hellman */
198 meth3 = DH_OpenSSL();
199 atalla_dh.generate_key = meth3->generate_key;
200 atalla_dh.compute_key = meth3->compute_key;
201 return &engine_atalla;
202 }
203
204/* This is a process-global DSO handle used for loading and unloading
205 * the Atalla library. NB: This is only set (or unset) during an
206 * init() or finish() call (reference counts permitting) and they're
207 * operating with global locks, so this should be thread-safe
208 * implicitly. */
209static DSO *atalla_dso = NULL;
210
211/* These are the function pointers that are (un)set when the library has
212 * successfully (un)loaded. */
213static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
214static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
215static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
216
217/* (de)initialisation functions. */
218static int atalla_init()
219 {
220 tfnASI_GetHardwareConfig *p1;
221 tfnASI_RSAPrivateKeyOpFn *p2;
222 tfnASI_GetPerformanceStatistics *p3;
223 /* Not sure of the origin of this magic value, but Ben's code had it
224 * and it seemed to have been working for a few people. :-) */
225 unsigned int config_buf[1024];
226
227 if(atalla_dso != NULL)
228 {
229 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_ALREADY_LOADED);
230 goto err;
231 }
232 /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
233 * changed unfortunately because the Atalla drivers don't have
234 * standard library names that can be platform-translated well. */
235 /* TODO: Work out how to actually map to the names the Atalla
236 * drivers really use - for now a symbollic link needs to be
237 * created on the host system from libatasi.so to atasi.so on
238 * unix variants. */
239 atalla_dso = DSO_load(NULL, ATALLA_LIBNAME, NULL,
240 DSO_FLAG_NAME_TRANSLATION);
241 if(atalla_dso == NULL)
242 {
243 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_DSO_FAILURE);
244 goto err;
245 }
246 if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
247 atalla_dso, ATALLA_F1)) ||
248 !(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
249 atalla_dso, ATALLA_F2)) ||
250 !(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
251 atalla_dso, ATALLA_F3)))
252 {
253 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_DSO_FAILURE);
254 goto err;
255 }
256 /* Copy the pointers */
257 p_Atalla_GetHardwareConfig = p1;
258 p_Atalla_RSAPrivateKeyOpFn = p2;
259 p_Atalla_GetPerformanceStatistics = p3;
260 /* Perform a basic test to see if there's actually any unit
261 * running. */
262 if(p1(0L, config_buf) != 0)
263 {
264 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_UNIT_FAILURE);
265 goto err;
266 }
267 /* Everything's fine. */
268 return 1;
269err:
270 if(atalla_dso)
271 DSO_free(atalla_dso);
272 p_Atalla_GetHardwareConfig = NULL;
273 p_Atalla_RSAPrivateKeyOpFn = NULL;
274 p_Atalla_GetPerformanceStatistics = NULL;
275 return 0;
276 }
277
278static int atalla_finish()
279 {
280 if(atalla_dso == NULL)
281 {
282 ENGINEerr(ENGINE_F_ATALLA_FINISH,ENGINE_R_NOT_LOADED);
283 return 0;
284 }
285 if(!DSO_free(atalla_dso))
286 {
287 ENGINEerr(ENGINE_F_ATALLA_FINISH,ENGINE_R_DSO_FAILURE);
288 return 0;
289 }
290 atalla_dso = NULL;
291 p_Atalla_GetHardwareConfig = NULL;
292 p_Atalla_RSAPrivateKeyOpFn = NULL;
293 p_Atalla_GetPerformanceStatistics = NULL;
294 return 1;
295 }
296
297static int atalla_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
298 const BIGNUM *m, BN_CTX *ctx)
299 {
300 /* I need somewhere to store temporary serialised values for
301 * use with the Atalla API calls. A neat cheat - I'll use
302 * BIGNUMs from the BN_CTX but access their arrays directly as
303 * byte arrays <grin>. This way I don't have to clean anything
304 * up. */
305 BIGNUM *modulus;
306 BIGNUM *exponent;
307 BIGNUM *argument;
308 BIGNUM *result;
309 RSAPrivateKey keydata;
310 int to_return, numbytes;
311
312 modulus = exponent = argument = result = NULL;
313 to_return = 0; /* expect failure */
314
315 if(!atalla_dso)
316 {
317 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_NOT_LOADED);
318 goto err;
319 }
320 /* Prepare the params */
321 modulus = BN_CTX_get(ctx);
322 exponent = BN_CTX_get(ctx);
323 argument = BN_CTX_get(ctx);
324 result = BN_CTX_get(ctx);
325 if(!modulus || !exponent || !argument || !result)
326 {
327 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_CTX_FULL);
328 goto err;
329 }
330 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) ||
331 !bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top))
332 {
333 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_EXPAND_FAIL);
334 goto err;
335 }
336 /* Prepare the key-data */
337 memset(&keydata, 0,sizeof keydata);
338 numbytes = BN_num_bytes(m);
339 memset(exponent->d, 0, numbytes);
340 memset(modulus->d, 0, numbytes);
341 BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p));
342 BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m));
343 keydata.privateExponent.data = (unsigned char *)exponent->d;
344 keydata.privateExponent.len = numbytes;
345 keydata.modulus.data = (unsigned char *)modulus->d;
346 keydata.modulus.len = numbytes;
347 /* Prepare the argument */
348 memset(argument->d, 0, numbytes);
349 memset(result->d, 0, numbytes);
350 BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a));
351 /* Perform the operation */
352 if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d,
353 (unsigned char *)argument->d,
354 keydata.modulus.len) != 0)
355 {
356 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
357 goto err;
358 }
359 /* Convert the response */
360 BN_bin2bn((unsigned char *)result->d, numbytes, r);
361 to_return = 1;
362err:
363 if(modulus) ctx->tos--;
364 if(exponent) ctx->tos--;
365 if(argument) ctx->tos--;
366 if(result) ctx->tos--;
367 return to_return;
368 }
369
370static int atalla_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
371 {
372 BN_CTX *ctx = NULL;
373 int to_return = 0;
374
375 if(!atalla_dso)
376 {
377 ENGINEerr(ENGINE_F_ATALLA_RSA_MOD_EXP,ENGINE_R_NOT_LOADED);
378 goto err;
379 }
380 if((ctx = BN_CTX_new()) == NULL)
381 goto err;
382 if(!rsa->d || !rsa->n)
383 {
384 ENGINEerr(ENGINE_F_ATALLA_RSA_MOD_EXP,ENGINE_R_MISSING_KEY_COMPONENTS);
385 goto err;
386 }
387 to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx);
388err:
389 if(ctx)
390 BN_CTX_free(ctx);
391 return to_return;
392 }
393
394/* This code was liberated and adapted from the commented-out code in
395 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
396 * (it doesn't have a CRT form for RSA), this function means that an
397 * Atalla system running with a DSA server certificate can handshake
398 * around 5 or 6 times faster/more than an equivalent system running with
399 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
400 * of "openssl speed -engine atalla dsa1024 rsa1024". */
401static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
402 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
403 BN_CTX *ctx, BN_MONT_CTX *in_mont)
404 {
405 BIGNUM t;
406 int to_return = 0;
407
408 BN_init(&t);
409 /* let rr = a1 ^ p1 mod m */
410 if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
411 /* let t = a2 ^ p2 mod m */
412 if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
413 /* let rr = rr * t mod m */
414 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
415 to_return = 1;
416end:
417 BN_free(&t);
418 return to_return;
419 }
420
421
422static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
423 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
424 BN_MONT_CTX *m_ctx)
425 {
426 return atalla_mod_exp(r, a, p, m, ctx);
427 }
428
429/* This function is aliased to mod_exp (with the mont stuff dropped). */
430static int atalla_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
431 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
432 {
433 return atalla_mod_exp(r, a, p, m, ctx);
434 }
435
436/* This function is aliased to mod_exp (with the dh and mont dropped). */
437static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
438 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
439 {
440 return atalla_mod_exp(r, a, p, m, ctx);
441 }
442
443#endif /* !NO_HW_ATALLA */
444#endif /* !NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_atalla_err.c b/src/lib/libssl/src/crypto/engine/hw_atalla_err.c
new file mode 100644
index 0000000000..1df9c4570c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_atalla_err.c
@@ -0,0 +1,145 @@
1/* hw_atalla_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_atalla_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ATALLA_str_functs[]=
68 {
69{ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"},
70{ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"},
71{ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"},
72{ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"},
73{ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"},
74{0,NULL}
75 };
76
77static ERR_STRING_DATA ATALLA_str_reasons[]=
78 {
79{ATALLA_R_ALREADY_LOADED ,"already loaded"},
80{ATALLA_R_BN_CTX_FULL ,"bn ctx full"},
81{ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"},
82{ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
83{ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"},
84{ATALLA_R_NOT_LOADED ,"not loaded"},
85{ATALLA_R_REQUEST_FAILED ,"request failed"},
86{ATALLA_R_UNIT_FAILURE ,"unit failure"},
87{0,NULL}
88 };
89
90#endif
91
92#ifdef ATALLA_LIB_NAME
93static ERR_STRING_DATA ATALLA_lib_name[]=
94 {
95{0 ,ATALLA_LIB_NAME},
96{0,NULL}
97 };
98#endif
99
100
101static int ATALLA_lib_error_code=0;
102static int ATALLA_error_init=1;
103
104static void ERR_load_ATALLA_strings(void)
105 {
106 if (ATALLA_lib_error_code == 0)
107 ATALLA_lib_error_code=ERR_get_next_error_library();
108
109 if (ATALLA_error_init)
110 {
111 ATALLA_error_init=0;
112#ifndef OPENSSL_NO_ERR
113 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs);
114 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
115#endif
116
117#ifdef ATALLA_LIB_NAME
118 ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0);
119 ERR_load_strings(0,ATALLA_lib_name);
120#endif
121 }
122 }
123
124static void ERR_unload_ATALLA_strings(void)
125 {
126 if (ATALLA_error_init == 0)
127 {
128#ifndef OPENSSL_NO_ERR
129 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs);
130 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
131#endif
132
133#ifdef ATALLA_LIB_NAME
134 ERR_unload_strings(0,ATALLA_lib_name);
135#endif
136 ATALLA_error_init=1;
137 }
138 }
139
140static void ERR_ATALLA_error(int function, int reason, char *file, int line)
141 {
142 if (ATALLA_lib_error_code == 0)
143 ATALLA_lib_error_code=ERR_get_next_error_library();
144 ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line);
145 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_atalla_err.h b/src/lib/libssl/src/crypto/engine/hw_atalla_err.h
new file mode 100644
index 0000000000..cdac052d8c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_atalla_err.h
@@ -0,0 +1,89 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_ATALLA_ERR_H
56#define HEADER_ATALLA_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_ATALLA_strings(void);
63static void ERR_unload_ATALLA_strings(void);
64static void ERR_ATALLA_error(int function, int reason, char *file, int line);
65#define ATALLAerr(f,r) ERR_ATALLA_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the ATALLA functions. */
68
69/* Function codes. */
70#define ATALLA_F_ATALLA_CTRL 100
71#define ATALLA_F_ATALLA_FINISH 101
72#define ATALLA_F_ATALLA_INIT 102
73#define ATALLA_F_ATALLA_MOD_EXP 103
74#define ATALLA_F_ATALLA_RSA_MOD_EXP 104
75
76/* Reason codes. */
77#define ATALLA_R_ALREADY_LOADED 100
78#define ATALLA_R_BN_CTX_FULL 101
79#define ATALLA_R_BN_EXPAND_FAIL 102
80#define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
81#define ATALLA_R_MISSING_KEY_COMPONENTS 104
82#define ATALLA_R_NOT_LOADED 105
83#define ATALLA_R_REQUEST_FAILED 106
84#define ATALLA_R_UNIT_FAILURE 107
85
86#ifdef __cplusplus
87}
88#endif
89#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c
new file mode 100644
index 0000000000..7c3728f395
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c
@@ -0,0 +1,926 @@
1/*
2 * Copyright (c) 2002 Bob Beck <beck@openbsd.org>
3 * Copyright (c) 2002 Theo de Raadt
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31#include <sys/types.h>
32#include <sys/param.h>
33#include <crypto/cryptodev.h>
34#include <sys/ioctl.h>
35#include <errno.h>
36#include <stdio.h>
37#include <unistd.h>
38#include <fcntl.h>
39#include <syslog.h>
40#include <stdarg.h>
41#include <ssl/objects.h>
42#include <ssl/engine.h>
43#include <ssl/evp.h>
44
45static int cryptodev_fd = -1;
46static int cryptodev_sessions = 0;
47static u_int32_t cryptodev_symfeat = 0;
48
49static int bn2crparam(const BIGNUM *a, struct crparam *crp);
50static int crparam2bn(struct crparam *crp, BIGNUM *a);
51static void zapparams(struct crypt_kop *kop);
52
53static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
54static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
55 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
56static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
57 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
58static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst,
59 int dlen, DSA *dsa);
60static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len,
61 DSA_SIG *sig, DSA *dsa);
62static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
63 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
64 BN_MONT_CTX *m_ctx);
65static int cryptodev_dh_compute_key(unsigned char *key,
66 const BIGNUM *pub_key, DH *dh);
67
68static const ENGINE_CMD_DEFN cryptodev_defns[] = {
69 { 0, NULL, NULL, 0 }
70};
71
72static struct {
73 int id;
74 int nid;
75 int ivmax;
76 int keylen;
77} ciphers[] = {
78 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
79 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
80 { CRYPTO_AES_CBC, NID_undef, 8, 24, },
81 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
82 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 8, },
83 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
84 { CRYPTO_ARC4, NID_rc4, 8, 16, },
85 { 0, NID_undef, 0, 0, },
86};
87
88static struct {
89 int id;
90 int nid;
91} digests[] = {
92 { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, },
93 { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, },
94 { CRYPTO_MD5_KPDK, NID_undef, },
95 { CRYPTO_SHA1_KPDK, NID_undef, },
96 { CRYPTO_MD5, NID_md5, },
97 { CRYPTO_SHA1, NID_undef, },
98 { 0, NID_undef, },
99};
100
101/*
102 * Return 1 if /dev/crypto seems usable, 0 otherwise , also
103 * does most of the work of initting the device, if not already
104 * done.. This should leave is with global fd initialized with CRIOGET.
105 */
106static int
107check_dev_crypto()
108{
109 int fd;
110
111 if (cryptodev_fd == -1) {
112 if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
113 return (0);
114 if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1) {
115 close(fd);
116 return (0);
117 }
118 close(fd);
119 /* close on exec */
120 if (fcntl(cryptodev_fd, F_SETFD, 1) == -1) {
121 close(cryptodev_fd);
122 cryptodev_fd = -1;
123 return (0);
124 }
125 }
126 ioctl(cryptodev_fd, CIOCSYMFEAT, &cryptodev_symfeat);
127
128 return (1);
129}
130
131/*
132 * XXXX this needs to be set for each alg - and determined from
133 * a running card.
134 */
135static int
136cryptodev_max_iv(int cipher)
137{
138 int i;
139
140 for (i = 0; ciphers[i].id; i++)
141 if (ciphers[i].id == cipher)
142 return (ciphers[i].ivmax);
143 return (0);
144}
145
146/*
147 * XXXX this needs to be set for each alg - and determined from
148 * a running card. For now, fake it out - but most of these
149 * for real devices should return 1 for the supported key
150 * sizes the device can handle.
151 */
152static int
153cryptodev_key_length_valid(int cipher, int len)
154{
155 int i;
156
157 for (i = 0; ciphers[i].id; i++)
158 if (ciphers[i].id == cipher)
159 return (ciphers[i].keylen == len);
160 return (0);
161}
162
163/* convert libcrypto nids to cryptodev */
164static int
165cipher_nid_to_cryptodev(int nid)
166{
167 int i;
168
169 for (i = 0; ciphers[i].id; i++)
170 if (ciphers[i].nid == nid)
171 return (ciphers[i].id);
172 return (0);
173}
174
175/*
176 * Find out what ciphers /dev/crypto will let us have a session for.
177 * XXX note, that some of these openssl doesn't deal with yet!
178 * returning them here is harmless, as long as we return NULL
179 * when asked for a handler in the cryptodev_engine_ciphers routine
180 */
181static int
182get_cryptodev_ciphers(const int **cnids)
183{
184 static int nids[CRYPTO_ALGORITHM_MAX];
185 struct session_op sess;
186 int i, count = 0;
187
188 memset(&sess, 0, sizeof(sess));
189 sess.key = (caddr_t)"123456781234567812345678";
190
191 for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
192 if (ciphers[i].nid == NID_undef)
193 continue;
194 sess.cipher = ciphers[i].id;
195 sess.keylen = ciphers[i].keylen;
196 sess.mac = 0;
197 if (ioctl(cryptodev_fd, CIOCGSESSION, &sess) != -1 &&
198 ioctl(cryptodev_fd, CIOCFSESSION, &sess.ses) != -1)
199 nids[count++] = ciphers[i].nid;
200 }
201 if (count > 0)
202 *cnids = nids;
203 else
204 *cnids = NULL;
205 return (count);
206}
207
208/*
209 * Find out what digests /dev/crypto will let us have a session for.
210 * XXX note, that some of these openssl doesn't deal with yet!
211 * returning them here is harmless, as long as we return NULL
212 * when asked for a handler in the cryptodev_engine_digests routine
213 */
214static int
215get_cryptodev_digests(const int **cnids)
216{
217 static int nids[CRYPTO_ALGORITHM_MAX];
218 struct session_op sess;
219 int i, count = 0;
220
221 memset(&sess, 0, sizeof(sess));
222 for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
223 if (digests[i].nid == NID_undef)
224 continue;
225 sess.mac = digests[i].id;
226 sess.cipher = 0;
227 if (ioctl(cryptodev_fd, CIOCGSESSION, &sess) != -1 &&
228 ioctl(cryptodev_fd, CIOCFSESSION, &sess.ses) != -1)
229 nids[count++] = digests[i].nid;
230 }
231 if (count > 0)
232 *cnids = nids;
233 else
234 *cnids = NULL;
235 return (count);
236}
237
238/*
239 * Find the useable ciphers|digests from dev/crypto - this is the first
240 * thing called by the engine init crud which determines what it
241 * can use for ciphers from this engine. We want to return
242 * only what we can do, anythine else is handled by software.
243 *
244 * If we can't initialize the device to do anything useful for
245 * any reason, we want to return a NULL array, and 0 length,
246 * which forces everything to be done is software. By putting
247 * the initalization of the device in here, we ensure we can
248 * use this engine as the default, and if for whatever reason
249 * /dev/crypto won't do what we want it will just be done in
250 * software
251 *
252 * This can (should) be greatly expanded to perhaps take into
253 * account speed of the device, and what we want to do.
254 * (although the disabling of particular alg's could be controlled
255 * by the device driver with sysctl's.) - this is where we
256 * want most of the decisions made about what we actually want
257 * to use from /dev/crypto.
258 */
259int
260cryptodev_usable_ciphers(const int **nids)
261{
262 if (!check_dev_crypto()) {
263 *nids = NULL;
264 return (0);
265 }
266
267 /* find what the device can do. Unfortunately, we don't
268 * necessarily want all of these yet, because we aren't
269 * yet set up to do them
270 */
271 return (get_cryptodev_ciphers(nids));
272}
273
274int
275cryptodev_usable_digests(const int **nids)
276{
277#if 1
278 /*
279 * XXXX just disable all digests for now, because it sucks.
280 * we need a better way to decide this - i.e. I may not
281 * want digests on slow cards like hifn on fast machines,
282 * but might want them on slow or loaded machines, etc.
283 * will also want them when using crypto cards that don't
284 * suck moose gonads - would be nice to be able to decide something
285 * as reasonable default without having hackery that's card dependent.
286 * of course, the default should probably be just do everything,
287 * with perhaps a sysctl to turn algoritms off (or have them off
288 * by default) on cards that generally suck like the hifn.
289 */
290 *nids = NULL;
291 return (0);
292#endif
293
294 if (!check_dev_crypto()) {
295 *nids = NULL;
296 return (0);
297 }
298 return (get_cryptodev_digests(nids));
299}
300
301
302int
303cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
304 const unsigned char *in, unsigned int inl)
305{
306 struct crypt_op cryp;
307 struct session_op *sess = ctx->cipher_data;
308 void *iiv;
309 unsigned char save_iv[EVP_MAX_IV_LENGTH];
310 struct syslog_data sd = SYSLOG_DATA_INIT;
311
312 if (cryptodev_fd == -1)
313 return (0);
314 if (sess == NULL)
315 return (0);
316 if (!inl)
317 return (1);
318 if ((inl % ctx->cipher->block_size) != 0)
319 return (0);
320
321 memset(&cryp, 0, sizeof(cryp));
322
323 cryp.ses = sess->ses;
324 cryp.flags = 0;
325 cryp.len = inl;
326 cryp.src = (caddr_t) in;
327 cryp.dst = (caddr_t) out;
328 cryp.mac = 0;
329
330 cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
331
332 if (ctx->cipher->iv_len) {
333 cryp.iv = (caddr_t) ctx->iv;
334 if (!ctx->encrypt) {
335 iiv = (void *) in + inl - ctx->cipher->iv_len;
336 memcpy(save_iv, iiv, ctx->cipher->iv_len);
337 }
338 } else
339 cryp.iv = NULL;
340
341 if (ioctl(cryptodev_fd, CIOCCRYPT, &cryp) == -1) {
342 /* XXX need better errror handling
343 * this can fail for a number of different reasons.
344 */
345 syslog_r(LOG_ERR, &sd, "CIOCCRYPT failed (%m)");
346 return (0);
347 }
348
349 if (ctx->cipher->iv_len) {
350 if (ctx->encrypt)
351 iiv = (void *) out + inl - ctx->cipher->iv_len;
352 else
353 iiv = save_iv;
354 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
355 }
356 return (1);
357}
358
359int
360cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
361 const unsigned char *iv, int enc)
362{
363 struct session_op *sess = ctx->cipher_data;
364 struct syslog_data sd = SYSLOG_DATA_INIT;
365 int cipher;
366
367 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
368 return (0);
369
370 if (!check_dev_crypto())
371 return (0);
372
373 if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
374 return (0);
375
376 if (!cryptodev_key_length_valid(cipher, ctx->key_len))
377 return (0);
378
379 memset(sess, 0, sizeof(struct session_op));
380
381 sess->key = (unsigned char *)key;
382 sess->keylen = ctx->key_len;
383 sess->cipher = cipher;
384
385 if (ioctl(cryptodev_fd, CIOCGSESSION, sess) == -1) {
386 syslog_r(LOG_ERR, &sd, "CIOCGSESSION failed (%m)");
387 return (0);
388 }
389 cryptodev_sessions++;
390 return (1);
391}
392
393/*
394 * free anything we allocated earlier when initting a
395 * session, and close the session.
396 */
397int
398cryptodev_cleanup(EVP_CIPHER_CTX *ctx)
399{
400 int ret = 0;
401 struct session_op *sess = ctx->cipher_data;
402 struct syslog_data sd = SYSLOG_DATA_INIT;
403
404 if (sess == NULL)
405 return (0);
406
407 /* XXX if this ioctl fails, someting's wrong. the invoker
408 * may have called us with a bogus ctx, or we could
409 * have a device that for whatever reason just doesn't
410 * want to play ball - it's not clear what's right
411 * here - should this be an error? should it just
412 * increase a counter, hmm. For right now, we return
413 * 0 - I don't believe that to be "right". we could
414 * call the gorpy openssl lib error handlers that
415 * print messages to users of the library. hmm..
416 */
417
418 if (ioctl(cryptodev_fd, CIOCFSESSION, &sess->ses) == -1) {
419 syslog_r(LOG_ERR, &sd, "CIOCFSESSION failed (%m)");
420 ret = 0;
421 } else {
422 cryptodev_sessions--;
423 ret = 1;
424 }
425 if (cryptodev_sessions == 0 && cryptodev_fd != -1 ) {
426 close(cryptodev_fd); /* XXX should this be closed? */
427 cryptodev_fd = -1;
428 }
429 return (ret);
430}
431
432/*
433 * libcrypto EVP stuff - this is how we get wired to EVP so the engine
434 * gets called when libcrypto requests a cipher NID.
435 */
436
437/* ARC4 (16 byte key) */
438const EVP_CIPHER cryptodev_arc4_cipher = {
439 NID_rc4,
440 1, 16, 0,
441 EVP_CIPH_VARIABLE_LENGTH,
442 cryptodev_init_key,
443 cryptodev_cipher,
444 cryptodev_cleanup,
445 sizeof(struct session_op),
446 NULL,
447 NULL,
448 NULL
449};
450
451/* DES CBC EVP */
452const EVP_CIPHER cryptodev_des_cbc = {
453 NID_des_cbc,
454 8, 8, 8,
455 EVP_CIPH_CBC_MODE,
456 cryptodev_init_key,
457 cryptodev_cipher,
458 cryptodev_cleanup,
459 sizeof(struct session_op),
460 EVP_CIPHER_set_asn1_iv,
461 EVP_CIPHER_get_asn1_iv,
462 NULL
463};
464
465/* 3DES CBC EVP */
466const EVP_CIPHER cryptodev_3des_cbc = {
467 NID_des_ede3_cbc,
468 8, 24, 8,
469 EVP_CIPH_CBC_MODE,
470 cryptodev_init_key,
471 cryptodev_cipher,
472 cryptodev_cleanup,
473 sizeof(struct session_op),
474 EVP_CIPHER_set_asn1_iv,
475 EVP_CIPHER_get_asn1_iv,
476 NULL
477};
478
479
480/*
481 * Registered by the ENGINE when used to find out how to deal with
482 * a particular NID in the ENGINE. this says what we'll do at the
483 * top level - note, that list is restricted by what we answer with
484 */
485int
486cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
487 const int **nids, int nid)
488{
489 if (!cipher)
490 return (cryptodev_usable_ciphers(nids));
491
492 switch (nid) {
493 case NID_rc4:
494 *cipher = &cryptodev_arc4_cipher;
495 break;
496 case NID_des_ede3_cbc:
497 *cipher = &cryptodev_3des_cbc;
498 break;
499 case NID_des_cbc:
500 *cipher = &cryptodev_des_cbc;
501 break;
502 default:
503 *cipher = NULL;
504 break;
505 }
506 return (*cipher != NULL);
507}
508
509int
510cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
511 const int **nids, int nid)
512{
513 if (!digest)
514 return (cryptodev_usable_digests(nids));
515
516 switch (nid) {
517 case NID_md5:
518 *digest = NULL; /* need to make a clean md5 critter */
519 break;
520 default:
521 *digest = NULL;
522 break;
523 }
524 return (*digest != NULL);
525}
526
527
528/*
529 * Convert a BIGNUM to the representation that /dev/crypto needs.
530 * Upon completion of use, the caller is responsible for freeing
531 * crp->crp_p.
532 */
533static int
534bn2crparam(const BIGNUM *a, struct crparam *crp)
535{
536 int i, j, n;
537 ssize_t words, bytes, bits;
538 u_char *b;
539
540 crp->crp_p = NULL;
541 crp->crp_nbits = 0;
542
543 bits = BN_num_bits(a);
544 bytes = (bits + 7) / 8;
545
546 b = malloc(bytes);
547 if (b == NULL)
548 return (1);
549
550 crp->crp_p = b;
551 crp->crp_nbits = bits;
552
553 words = (bits + BN_BITS2 - 1) / BN_BITS2;
554
555 n = 0;
556 for (i = 0; i < words && n < bytes; i++) {
557 BN_ULONG word;
558
559 word = a->d[i];
560 for (j = 0 ; j < BN_BYTES && n < bytes; j++, n++) {
561 *b++ = (word & 0xff);
562 word >>= 8;
563 }
564 }
565 return (0);
566}
567
568/* Convert a /dev/crypto parameter to a BIGNUM */
569static int
570crparam2bn(struct crparam *crp, BIGNUM *a)
571{
572 int i, bytes;
573
574 bytes = (crp->crp_nbits + 7)/8;
575
576 BN_zero(a);
577 for (i = bytes - 1; i >= 0; i--) {
578 BN_lshift(a, a, 8);
579 BN_add_word(a, (u_char)crp->crp_p[i]);
580 }
581
582 return (0);
583}
584
585static void
586zapparams(struct crypt_kop *kop)
587{
588 int i;
589
590 for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
591 if (kop->crk_param[i].crp_p)
592 free(kop->crk_param[i].crp_p);
593 kop->crk_param[i].crp_p = NULL;
594 kop->crk_param[i].crp_nbits = 0;
595 }
596}
597
598static int
599cryptodev_sym(struct crypt_kop *kop, BIGNUM *r, BIGNUM *s)
600{
601 int ret = -1;
602
603 if (r) {
604 kop->crk_param[kop->crk_iparams].crp_p = malloc(256);
605 kop->crk_param[kop->crk_iparams].crp_nbits = 256 * 8;
606 kop->crk_oparams++;
607 }
608 if (s) {
609 kop->crk_param[kop->crk_iparams+1].crp_p = malloc(256);
610 kop->crk_param[kop->crk_iparams+1].crp_nbits = 256 * 8;
611 kop->crk_oparams++;
612 }
613
614 if (ioctl(cryptodev_fd, CIOCKEY, &kop) == 0) {
615 crparam2bn(&kop->crk_param[3], r);
616 ret = 0;
617 }
618 return (ret);
619}
620
621static int
622cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
623 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
624{
625 struct crypt_kop kop;
626 int ret = 0;
627
628 memset(&kop, 0, sizeof kop);
629 kop.crk_op = CRK_MOD_EXP;
630
631 /* inputs: a m p */
632 if (bn2crparam(a, &kop.crk_param[0]))
633 goto err;
634 if (bn2crparam(m, &kop.crk_param[1]))
635 goto err;
636 if (bn2crparam(p, &kop.crk_param[2]))
637 goto err;
638 kop.crk_iparams = 3;
639
640 if (cryptodev_sym(&kop, r, NULL) == -1) {
641 ret = BN_mod_exp(r, a, p, m, ctx);
642 }
643err:
644 zapparams(&kop);
645 return (ret);
646}
647
648
649static int
650cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
651{
652 struct crypt_kop kop;
653 int ret = 0;
654
655 if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
656 /* XXX 0 means failure?? */
657 goto err;
658 }
659
660 memset(&kop, 0, sizeof kop);
661 kop.crk_op = CRK_MOD_EXP_CRT;
662 /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
663 if (bn2crparam(rsa->p, &kop.crk_param[0]))
664 goto err;
665 if (bn2crparam(rsa->q, &kop.crk_param[1]))
666 goto err;
667 if (bn2crparam(I, &kop.crk_param[2]))
668 goto err;
669 if (bn2crparam(rsa->dmp1, &kop.crk_param[3]))
670 goto err;
671 if (bn2crparam(rsa->dmq1, &kop.crk_param[4]))
672 goto err;
673 if (bn2crparam(rsa->iqmp, &kop.crk_param[5]))
674 goto err;
675 kop.crk_iparams = 6;
676
677 if (cryptodev_sym(&kop, r0, NULL) == -1) {
678 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
679
680 ret = (*meth->rsa_mod_exp)(r0, I, rsa);
681 }
682err:
683 zapparams(&kop);
684 return (ret);
685}
686
687static RSA_METHOD cryptodev_rsa = {
688 "cryptodev RSA method",
689 NULL, /* rsa_pub_enc */
690 NULL, /* rsa_pub_dec */
691 NULL, /* rsa_priv_enc */
692 NULL, /* rsa_priv_dec */
693 cryptodev_rsa_mod_exp, /* rsa_mod_exp */
694 cryptodev_bn_mod_exp, /* bn_mod_exp */
695 NULL, /* init */
696 NULL, /* finish */
697 0, /* flags */
698 NULL, /* app_data */
699 NULL, /* rsa_sign */
700 NULL /* rsa_verify */
701};
702
703static int
704cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
705 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
706{
707 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
708}
709
710static DSA_SIG *
711cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
712{
713 struct crypt_kop kop;
714 BIGNUM *r = NULL, *s = NULL;
715 DSA_SIG *dsaret = NULL;
716
717 if ((r = BN_new()) == NULL)
718 goto err;
719 if ((s = BN_new()) == NULL) {
720 BN_free(r);
721 goto err;
722 }
723
724 memset(&kop, 0, sizeof kop);
725 kop.crk_op = CRK_DSA_SIGN;
726
727 /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */
728 kop.crk_param[0].crp_p = (caddr_t)dgst;
729 kop.crk_param[0].crp_nbits = dlen * 8;
730 if (bn2crparam(dsa->p, &kop.crk_param[1]))
731 goto err;
732 if (bn2crparam(dsa->q, &kop.crk_param[2]))
733 goto err;
734 if (bn2crparam(dsa->g, &kop.crk_param[3]))
735 goto err;
736 if (bn2crparam(dsa->priv_key, &kop.crk_param[4]))
737 goto err;
738 kop.crk_iparams = 5;
739
740 if (cryptodev_sym(&kop, r, s) == 0) {
741 dsaret = DSA_SIG_new();
742 dsaret->r = r;
743 dsaret->s = s;
744 } else {
745 const DSA_METHOD *meth = DSA_OpenSSL();
746
747 BN_free(r);
748 BN_free(s);
749 dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa);
750 }
751err:
752 kop.crk_param[0].crp_p = NULL;
753 zapparams(&kop);
754 return (dsaret);
755}
756
757static int
758cryptodev_dsa_verify(const unsigned char *dgst, int dlen,
759 DSA_SIG *sig, DSA *dsa)
760{
761 struct crypt_kop kop;
762 int dsaret = 0;
763
764 memset(&kop, 0, sizeof kop);
765 kop.crk_op = CRK_DSA_VERIFY;
766
767 /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */
768 kop.crk_param[0].crp_p = (caddr_t)dgst;
769 kop.crk_param[0].crp_nbits = dlen * 8;
770 if (bn2crparam(dsa->p, &kop.crk_param[1]))
771 goto err;
772 if (bn2crparam(dsa->q, &kop.crk_param[2]))
773 goto err;
774 if (bn2crparam(dsa->g, &kop.crk_param[3]))
775 goto err;
776 if (bn2crparam(dsa->pub_key, &kop.crk_param[4]))
777 goto err;
778 if (bn2crparam(sig->r, &kop.crk_param[5]))
779 goto err;
780 if (bn2crparam(sig->s, &kop.crk_param[6]))
781 goto err;
782 kop.crk_iparams = 7;
783
784 if (cryptodev_sym(&kop, NULL, NULL) == 0) {
785 dsaret = kop.crk_status;
786 } else {
787 const DSA_METHOD *meth = DSA_OpenSSL();
788
789 dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa);
790 }
791err:
792 kop.crk_param[0].crp_p = NULL;
793 zapparams(&kop);
794 return (dsaret);
795}
796
797static DSA_METHOD cryptodev_dsa = {
798 "cryptodev DSA method",
799 cryptodev_dsa_do_sign,
800 NULL, /* dsa_sign_setup */
801 cryptodev_dsa_verify,
802 NULL, /* dsa_mod_exp */
803 cryptodev_dsa_bn_mod_exp, /* bn_mod_exp */
804 NULL, /* init */
805 NULL, /* finish */
806 0, /* flags */
807 NULL /* app_data */
808};
809
810static int
811cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
812 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
813 BN_MONT_CTX *m_ctx)
814{
815 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
816}
817
818static int
819cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
820{
821 struct crypt_kop kop;
822 int dhret = 0;
823 int keylen;
824
825 keylen = BN_num_bits(dh->p);
826
827 memset(&kop, 0, sizeof kop);
828 kop.crk_op = CRK_DH_COMPUTE_KEY;
829
830 /* inputs: dh->priv_key pub_key dh->p key */
831 if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
832 goto err;
833 if (bn2crparam(pub_key, &kop.crk_param[1]))
834 goto err;
835 if (bn2crparam(dh->p, &kop.crk_param[2]))
836 goto err;
837 kop.crk_iparams = 3;
838
839 kop.crk_param[3].crp_p = key;
840 kop.crk_param[3].crp_nbits = keylen * 8;
841 kop.crk_oparams = 1;
842
843 if (ioctl(cryptodev_fd, CIOCKEY, &kop) == -1) {
844 const DH_METHOD *meth = DH_OpenSSL();
845
846 dhret = (meth->compute_key)(key, pub_key, dh);
847 }
848err:
849 kop.crk_param[3].crp_p = NULL;
850 zapparams(&kop);
851 return (dhret);
852}
853
854static DH_METHOD cryptodev_dh = {
855 "cryptodev DH method",
856 NULL, /* cryptodev_dh_generate_key */
857 cryptodev_dh_compute_key,
858 cryptodev_mod_exp_dh,
859 NULL,
860 NULL,
861 0, /* flags */
862 NULL /* app_data */
863};
864
865/*
866 * ctrl right now is just a wrapper that doesn't do much
867 * but I expect we'll want some options soon.
868 */
869static int
870cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
871{
872 struct syslog_data sd = SYSLOG_DATA_INIT;
873
874 switch (cmd) {
875 default:
876 syslog_r(LOG_ERR, &sd,
877 "cryptodev_ctrl: unknown command %d", cmd);
878 break;
879 }
880 return (1);
881}
882
883void
884ENGINE_load_cryptodev(void)
885{
886 ENGINE *engine = ENGINE_new();
887 const RSA_METHOD *rsa_meth;
888 const DH_METHOD *dh_meth;
889
890 if (engine == NULL)
891 return;
892
893 if (!ENGINE_set_id(engine, "cryptodev") ||
894 !ENGINE_set_name(engine, "OpenBSD cryptodev engine") ||
895 !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) ||
896 !ENGINE_set_digests(engine, cryptodev_engine_digests) ||
897 !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) ||
898 !ENGINE_set_cmd_defns(engine, cryptodev_defns)) {
899 ENGINE_free(engine);
900 return;
901 }
902
903 if ((cryptodev_symfeat & CRSFEAT_RSA) &&
904 ENGINE_set_RSA(engine, &cryptodev_rsa)) {
905 rsa_meth = RSA_PKCS1_SSLeay();
906 cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc;
907 cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec;
908 cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_dec;
909 cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec;
910 }
911
912 if ((cryptodev_symfeat & CRSFEAT_DSA) &&
913 ENGINE_set_DSA(engine, &cryptodev_dsa)) {
914 }
915
916 if ((cryptodev_symfeat & CRSFEAT_DH) &&
917 ENGINE_set_DH(engine, &cryptodev_dh)) {
918 dh_meth = DH_OpenSSL();
919 cryptodev_dh.generate_key = dh_meth->generate_key;
920 cryptodev_dh.compute_key = dh_meth->compute_key;
921 }
922
923 ENGINE_add(engine);
924 ENGINE_free(engine);
925 ERR_clear_error();
926}
diff --git a/src/lib/libssl/src/crypto/engine/hw_cswift.c b/src/lib/libssl/src/crypto/engine/hw_cswift.c
new file mode 100644
index 0000000000..77608b8983
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_cswift.c
@@ -0,0 +1,807 @@
1/* crypto/engine/hw_cswift.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include "engine_int.h"
64#include <openssl/engine.h>
65
66#ifndef NO_HW
67#ifndef NO_HW_CSWIFT
68
69/* Attribution notice: Rainbow have generously allowed me to reproduce
70 * the necessary definitions here from their API. This means the support
71 * can build independently of whether application builders have the
72 * API or hardware. This will allow developers to easily produce software
73 * that has latent hardware support for any users that have accelerators
74 * installed, without the developers themselves needing anything extra.
75 *
76 * I have only clipped the parts from the CryptoSwift header files that
77 * are (or seem) relevant to the CryptoSwift support code. This is
78 * simply to keep the file sizes reasonable.
79 * [Geoff]
80 */
81#ifdef FLAT_INC
82#include "cswift.h"
83#else
84#include "vendor_defns/cswift.h"
85#endif
86
87static int cswift_init(void);
88static int cswift_finish(void);
89
90/* BIGNUM stuff */
91static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
92 const BIGNUM *m, BN_CTX *ctx);
93static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
94 const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
95 const BIGNUM *iqmp, BN_CTX *ctx);
96
97/* RSA stuff */
98static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
99/* This function is aliased to mod_exp (with the mont stuff dropped). */
100static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
101 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
102
103/* DSA stuff */
104static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa);
105static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107
108/* DH stuff */
109/* This function is alised to mod_exp (with the DH and mont dropped). */
110static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
111 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
112
113
114/* Our internal RSA_METHOD that we provide pointers to */
115static RSA_METHOD cswift_rsa =
116 {
117 "CryptoSwift RSA method",
118 NULL,
119 NULL,
120 NULL,
121 NULL,
122 cswift_rsa_mod_exp,
123 cswift_mod_exp_mont,
124 NULL,
125 NULL,
126 0,
127 NULL,
128 NULL,
129 NULL
130 };
131
132/* Our internal DSA_METHOD that we provide pointers to */
133static DSA_METHOD cswift_dsa =
134 {
135 "CryptoSwift DSA method",
136 cswift_dsa_sign,
137 NULL, /* dsa_sign_setup */
138 cswift_dsa_verify,
139 NULL, /* dsa_mod_exp */
140 NULL, /* bn_mod_exp */
141 NULL, /* init */
142 NULL, /* finish */
143 0, /* flags */
144 NULL /* app_data */
145 };
146
147/* Our internal DH_METHOD that we provide pointers to */
148static DH_METHOD cswift_dh =
149 {
150 "CryptoSwift DH method",
151 NULL,
152 NULL,
153 cswift_mod_exp_dh,
154 NULL,
155 NULL,
156 0,
157 NULL
158 };
159
160/* Our ENGINE structure. */
161static ENGINE engine_cswift =
162 {
163 "cswift",
164 "CryptoSwift hardware engine support",
165 &cswift_rsa,
166 &cswift_dsa,
167 &cswift_dh,
168 NULL,
169 cswift_mod_exp,
170 cswift_mod_exp_crt,
171 cswift_init,
172 cswift_finish,
173 NULL, /* no ctrl() */
174 NULL, /* no load_privkey() */
175 NULL, /* no load_pubkey() */
176 0, /* no flags */
177 0, 0, /* no references */
178 NULL, NULL /* unlinked */
179 };
180
181/* As this is only ever called once, there's no need for locking
182 * (indeed - the lock will already be held by our caller!!!) */
183ENGINE *ENGINE_cswift()
184 {
185 RSA_METHOD *meth1;
186 DH_METHOD *meth2;
187
188 /* We know that the "PKCS1_SSLeay()" functions hook properly
189 * to the cswift-specific mod_exp and mod_exp_crt so we use
190 * those functions. NB: We don't use ENGINE_openssl() or
191 * anything "more generic" because something like the RSAref
192 * code may not hook properly, and if you own one of these
193 * cards then you have the right to do RSA operations on it
194 * anyway! */
195 meth1 = RSA_PKCS1_SSLeay();
196 cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
197 cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
198 cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
199 cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
200
201 /* Much the same for Diffie-Hellman */
202 meth2 = DH_OpenSSL();
203 cswift_dh.generate_key = meth2->generate_key;
204 cswift_dh.compute_key = meth2->compute_key;
205 return &engine_cswift;
206 }
207
208/* This is a process-global DSO handle used for loading and unloading
209 * the CryptoSwift library. NB: This is only set (or unset) during an
210 * init() or finish() call (reference counts permitting) and they're
211 * operating with global locks, so this should be thread-safe
212 * implicitly. */
213static DSO *cswift_dso = NULL;
214
215/* These are the function pointers that are (un)set when the library has
216 * successfully (un)loaded. */
217t_swAcquireAccContext *p_CSwift_AcquireAccContext = NULL;
218t_swAttachKeyParam *p_CSwift_AttachKeyParam = NULL;
219t_swSimpleRequest *p_CSwift_SimpleRequest = NULL;
220t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL;
221
222/* Used in the DSO operations. */
223static const char *CSWIFT_LIBNAME = "swift";
224static const char *CSWIFT_F1 = "swAcquireAccContext";
225static const char *CSWIFT_F2 = "swAttachKeyParam";
226static const char *CSWIFT_F3 = "swSimpleRequest";
227static const char *CSWIFT_F4 = "swReleaseAccContext";
228
229
230/* CryptoSwift library functions and mechanics - these are used by the
231 * higher-level functions further down. NB: As and where there's no
232 * error checking, take a look lower down where these functions are
233 * called, the checking and error handling is probably down there. */
234
235/* utility function to obtain a context */
236static int get_context(SW_CONTEXT_HANDLE *hac)
237 {
238 SW_STATUS status;
239
240 status = p_CSwift_AcquireAccContext(hac);
241 if(status != SW_OK)
242 return 0;
243 return 1;
244 }
245
246/* similarly to release one. */
247static void release_context(SW_CONTEXT_HANDLE hac)
248 {
249 p_CSwift_ReleaseAccContext(hac);
250 }
251
252/* (de)initialisation functions. */
253static int cswift_init()
254 {
255 SW_CONTEXT_HANDLE hac;
256 t_swAcquireAccContext *p1;
257 t_swAttachKeyParam *p2;
258 t_swSimpleRequest *p3;
259 t_swReleaseAccContext *p4;
260
261 if(cswift_dso != NULL)
262 {
263 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_ALREADY_LOADED);
264 goto err;
265 }
266 /* Attempt to load libswift.so/swift.dll/whatever. */
267 cswift_dso = DSO_load(NULL, CSWIFT_LIBNAME, NULL,
268 DSO_FLAG_NAME_TRANSLATION);
269 if(cswift_dso == NULL)
270 {
271 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_DSO_FAILURE);
272 goto err;
273 }
274 if(!(p1 = (t_swAcquireAccContext *)
275 DSO_bind_func(cswift_dso, CSWIFT_F1)) ||
276 !(p2 = (t_swAttachKeyParam *)
277 DSO_bind_func(cswift_dso, CSWIFT_F2)) ||
278 !(p3 = (t_swSimpleRequest *)
279 DSO_bind_func(cswift_dso, CSWIFT_F3)) ||
280 !(p4 = (t_swReleaseAccContext *)
281 DSO_bind_func(cswift_dso, CSWIFT_F4)))
282 {
283 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_DSO_FAILURE);
284 goto err;
285 }
286 /* Copy the pointers */
287 p_CSwift_AcquireAccContext = p1;
288 p_CSwift_AttachKeyParam = p2;
289 p_CSwift_SimpleRequest = p3;
290 p_CSwift_ReleaseAccContext = p4;
291 /* Try and get a context - if not, we may have a DSO but no
292 * accelerator! */
293 if(!get_context(&hac))
294 {
295 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_UNIT_FAILURE);
296 goto err;
297 }
298 release_context(hac);
299 /* Everything's fine. */
300 return 1;
301err:
302 if(cswift_dso)
303 DSO_free(cswift_dso);
304 p_CSwift_AcquireAccContext = NULL;
305 p_CSwift_AttachKeyParam = NULL;
306 p_CSwift_SimpleRequest = NULL;
307 p_CSwift_ReleaseAccContext = NULL;
308 return 0;
309 }
310
311static int cswift_finish()
312 {
313 if(cswift_dso == NULL)
314 {
315 ENGINEerr(ENGINE_F_CSWIFT_FINISH,ENGINE_R_NOT_LOADED);
316 return 0;
317 }
318 if(!DSO_free(cswift_dso))
319 {
320 ENGINEerr(ENGINE_F_CSWIFT_FINISH,ENGINE_R_DSO_FAILURE);
321 return 0;
322 }
323 cswift_dso = NULL;
324 p_CSwift_AcquireAccContext = NULL;
325 p_CSwift_AttachKeyParam = NULL;
326 p_CSwift_SimpleRequest = NULL;
327 p_CSwift_ReleaseAccContext = NULL;
328 return 1;
329 }
330
331/* Un petit mod_exp */
332static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
333 const BIGNUM *m, BN_CTX *ctx)
334 {
335 /* I need somewhere to store temporary serialised values for
336 * use with the CryptoSwift API calls. A neat cheat - I'll use
337 * BIGNUMs from the BN_CTX but access their arrays directly as
338 * byte arrays <grin>. This way I don't have to clean anything
339 * up. */
340 BIGNUM *modulus;
341 BIGNUM *exponent;
342 BIGNUM *argument;
343 BIGNUM *result;
344 SW_STATUS sw_status;
345 SW_LARGENUMBER arg, res;
346 SW_PARAM sw_param;
347 SW_CONTEXT_HANDLE hac;
348 int to_return, acquired;
349
350 modulus = exponent = argument = result = NULL;
351 to_return = 0; /* expect failure */
352 acquired = 0;
353
354 if(!get_context(&hac))
355 {
356 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_GET_HANDLE_FAILED);
357 goto err;
358 }
359 acquired = 1;
360 /* Prepare the params */
361 modulus = BN_CTX_get(ctx);
362 exponent = BN_CTX_get(ctx);
363 argument = BN_CTX_get(ctx);
364 result = BN_CTX_get(ctx);
365 if(!modulus || !exponent || !argument || !result)
366 {
367 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_BN_CTX_FULL);
368 goto err;
369 }
370 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, p->top) ||
371 !bn_wexpand(argument, a->top) || !bn_wexpand(result, m->top))
372 {
373 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_BN_EXPAND_FAIL);
374 goto err;
375 }
376 sw_param.type = SW_ALG_EXP;
377 sw_param.up.exp.modulus.nbytes = BN_bn2bin(m,
378 (unsigned char *)modulus->d);
379 sw_param.up.exp.modulus.value = (unsigned char *)modulus->d;
380 sw_param.up.exp.exponent.nbytes = BN_bn2bin(p,
381 (unsigned char *)exponent->d);
382 sw_param.up.exp.exponent.value = (unsigned char *)exponent->d;
383 /* Attach the key params */
384 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
385 switch(sw_status)
386 {
387 case SW_OK:
388 break;
389 case SW_ERR_INPUT_SIZE:
390 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,
391 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
392 goto err;
393 default:
394 {
395 char tmpbuf[20];
396 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_REQUEST_FAILED);
397 sprintf(tmpbuf, "%ld", sw_status);
398 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
399 }
400 goto err;
401 }
402 /* Prepare the argument and response */
403 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
404 arg.value = (unsigned char *)argument->d;
405 res.nbytes = BN_num_bytes(m);
406 memset(result->d, 0, res.nbytes);
407 res.value = (unsigned char *)result->d;
408 /* Perform the operation */
409 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1,
410 &res, 1)) != SW_OK)
411 {
412 char tmpbuf[20];
413 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_REQUEST_FAILED);
414 sprintf(tmpbuf, "%ld", sw_status);
415 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
416 goto err;
417 }
418 /* Convert the response */
419 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
420 to_return = 1;
421err:
422 if(acquired)
423 release_context(hac);
424 if(modulus) ctx->tos--;
425 if(exponent) ctx->tos--;
426 if(argument) ctx->tos--;
427 if(result) ctx->tos--;
428 return to_return;
429 }
430
431/* Un petit mod_exp chinois */
432static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
433 const BIGNUM *q, const BIGNUM *dmp1,
434 const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
435 {
436 SW_STATUS sw_status;
437 SW_LARGENUMBER arg, res;
438 SW_PARAM sw_param;
439 SW_CONTEXT_HANDLE hac;
440 BIGNUM *rsa_p = NULL;
441 BIGNUM *rsa_q = NULL;
442 BIGNUM *rsa_dmp1 = NULL;
443 BIGNUM *rsa_dmq1 = NULL;
444 BIGNUM *rsa_iqmp = NULL;
445 BIGNUM *argument = NULL;
446 BIGNUM *result = NULL;
447 int to_return = 0; /* expect failure */
448 int acquired = 0;
449
450 if(!get_context(&hac))
451 {
452 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_GET_HANDLE_FAILED);
453 goto err;
454 }
455 acquired = 1;
456 /* Prepare the params */
457 rsa_p = BN_CTX_get(ctx);
458 rsa_q = BN_CTX_get(ctx);
459 rsa_dmp1 = BN_CTX_get(ctx);
460 rsa_dmq1 = BN_CTX_get(ctx);
461 rsa_iqmp = BN_CTX_get(ctx);
462 argument = BN_CTX_get(ctx);
463 result = BN_CTX_get(ctx);
464 if(!rsa_p || !rsa_q || !rsa_dmp1 || !rsa_dmq1 || !rsa_iqmp ||
465 !argument || !result)
466 {
467 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_CTX_FULL);
468 goto err;
469 }
470 if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) ||
471 !bn_wexpand(rsa_dmp1, dmp1->top) ||
472 !bn_wexpand(rsa_dmq1, dmq1->top) ||
473 !bn_wexpand(rsa_iqmp, iqmp->top) ||
474 !bn_wexpand(argument, a->top) ||
475 !bn_wexpand(result, p->top + q->top))
476 {
477 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_EXPAND_FAIL);
478 goto err;
479 }
480 sw_param.type = SW_ALG_CRT;
481 sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d);
482 sw_param.up.crt.p.value = (unsigned char *)rsa_p->d;
483 sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d);
484 sw_param.up.crt.q.value = (unsigned char *)rsa_q->d;
485 sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1,
486 (unsigned char *)rsa_dmp1->d);
487 sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d;
488 sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1,
489 (unsigned char *)rsa_dmq1->d);
490 sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d;
491 sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp,
492 (unsigned char *)rsa_iqmp->d);
493 sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d;
494 /* Attach the key params */
495 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
496 switch(sw_status)
497 {
498 case SW_OK:
499 break;
500 case SW_ERR_INPUT_SIZE:
501 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,
502 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
503 goto err;
504 default:
505 {
506 char tmpbuf[20];
507 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_REQUEST_FAILED);
508 sprintf(tmpbuf, "%ld", sw_status);
509 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
510 }
511 goto err;
512 }
513 /* Prepare the argument and response */
514 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
515 arg.value = (unsigned char *)argument->d;
516 res.nbytes = 2 * BN_num_bytes(p);
517 memset(result->d, 0, res.nbytes);
518 res.value = (unsigned char *)result->d;
519 /* Perform the operation */
520 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1,
521 &res, 1)) != SW_OK)
522 {
523 char tmpbuf[20];
524 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_REQUEST_FAILED);
525 sprintf(tmpbuf, "%ld", sw_status);
526 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
527 goto err;
528 }
529 /* Convert the response */
530 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
531 to_return = 1;
532err:
533 if(acquired)
534 release_context(hac);
535 if(rsa_p) ctx->tos--;
536 if(rsa_q) ctx->tos--;
537 if(rsa_dmp1) ctx->tos--;
538 if(rsa_dmq1) ctx->tos--;
539 if(rsa_iqmp) ctx->tos--;
540 if(argument) ctx->tos--;
541 if(result) ctx->tos--;
542 return to_return;
543 }
544
545static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
546 {
547 BN_CTX *ctx;
548 int to_return = 0;
549
550 if((ctx = BN_CTX_new()) == NULL)
551 goto err;
552 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
553 {
554 ENGINEerr(ENGINE_F_CSWIFT_RSA_MOD_EXP,ENGINE_R_MISSING_KEY_COMPONENTS);
555 goto err;
556 }
557 to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
558 rsa->dmq1, rsa->iqmp, ctx);
559err:
560 if(ctx)
561 BN_CTX_free(ctx);
562 return to_return;
563 }
564
565/* This function is aliased to mod_exp (with the mont stuff dropped). */
566static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
567 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
568 {
569 return cswift_mod_exp(r, a, p, m, ctx);
570 }
571
572static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa)
573 {
574 SW_CONTEXT_HANDLE hac;
575 SW_PARAM sw_param;
576 SW_STATUS sw_status;
577 SW_LARGENUMBER arg, res;
578 unsigned char *ptr;
579 BN_CTX *ctx;
580 BIGNUM *dsa_p = NULL;
581 BIGNUM *dsa_q = NULL;
582 BIGNUM *dsa_g = NULL;
583 BIGNUM *dsa_key = NULL;
584 BIGNUM *result = NULL;
585 DSA_SIG *to_return = NULL;
586 int acquired = 0;
587
588 if((ctx = BN_CTX_new()) == NULL)
589 goto err;
590 if(!get_context(&hac))
591 {
592 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_GET_HANDLE_FAILED);
593 goto err;
594 }
595 acquired = 1;
596 /* Prepare the params */
597 dsa_p = BN_CTX_get(ctx);
598 dsa_q = BN_CTX_get(ctx);
599 dsa_g = BN_CTX_get(ctx);
600 dsa_key = BN_CTX_get(ctx);
601 result = BN_CTX_get(ctx);
602 if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !result)
603 {
604 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_CTX_FULL);
605 goto err;
606 }
607 if(!bn_wexpand(dsa_p, dsa->p->top) ||
608 !bn_wexpand(dsa_q, dsa->q->top) ||
609 !bn_wexpand(dsa_g, dsa->g->top) ||
610 !bn_wexpand(dsa_key, dsa->priv_key->top) ||
611 !bn_wexpand(result, dsa->p->top))
612 {
613 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_EXPAND_FAIL);
614 goto err;
615 }
616 sw_param.type = SW_ALG_DSA;
617 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
618 (unsigned char *)dsa_p->d);
619 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
620 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
621 (unsigned char *)dsa_q->d);
622 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
623 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
624 (unsigned char *)dsa_g->d);
625 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
626 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->priv_key,
627 (unsigned char *)dsa_key->d);
628 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
629 /* Attach the key params */
630 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
631 switch(sw_status)
632 {
633 case SW_OK:
634 break;
635 case SW_ERR_INPUT_SIZE:
636 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,
637 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
638 goto err;
639 default:
640 {
641 char tmpbuf[20];
642 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_REQUEST_FAILED);
643 sprintf(tmpbuf, "%ld", sw_status);
644 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
645 }
646 goto err;
647 }
648 /* Prepare the argument and response */
649 arg.nbytes = dlen;
650 arg.value = (unsigned char *)dgst;
651 res.nbytes = BN_num_bytes(dsa->p);
652 memset(result->d, 0, res.nbytes);
653 res.value = (unsigned char *)result->d;
654 /* Perform the operation */
655 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_SIGN, &arg, 1,
656 &res, 1);
657 if(sw_status != SW_OK)
658 {
659 char tmpbuf[20];
660 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_REQUEST_FAILED);
661 sprintf(tmpbuf, "%ld", sw_status);
662 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
663 goto err;
664 }
665 /* Convert the response */
666 ptr = (unsigned char *)result->d;
667 if((to_return = DSA_SIG_new()) == NULL)
668 goto err;
669 to_return->r = BN_bin2bn((unsigned char *)result->d, 20, NULL);
670 to_return->s = BN_bin2bn((unsigned char *)result->d + 20, 20, NULL);
671
672err:
673 if(acquired)
674 release_context(hac);
675 if(dsa_p) ctx->tos--;
676 if(dsa_q) ctx->tos--;
677 if(dsa_g) ctx->tos--;
678 if(dsa_key) ctx->tos--;
679 if(result) ctx->tos--;
680 if(ctx)
681 BN_CTX_free(ctx);
682 return to_return;
683 }
684
685static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
686 DSA_SIG *sig, DSA *dsa)
687 {
688 SW_CONTEXT_HANDLE hac;
689 SW_PARAM sw_param;
690 SW_STATUS sw_status;
691 SW_LARGENUMBER arg[2], res;
692 unsigned long sig_result;
693 BN_CTX *ctx;
694 BIGNUM *dsa_p = NULL;
695 BIGNUM *dsa_q = NULL;
696 BIGNUM *dsa_g = NULL;
697 BIGNUM *dsa_key = NULL;
698 BIGNUM *argument = NULL;
699 int to_return = -1;
700 int acquired = 0;
701
702 if((ctx = BN_CTX_new()) == NULL)
703 goto err;
704 if(!get_context(&hac))
705 {
706 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_GET_HANDLE_FAILED);
707 goto err;
708 }
709 acquired = 1;
710 /* Prepare the params */
711 dsa_p = BN_CTX_get(ctx);
712 dsa_q = BN_CTX_get(ctx);
713 dsa_g = BN_CTX_get(ctx);
714 dsa_key = BN_CTX_get(ctx);
715 argument = BN_CTX_get(ctx);
716 if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !argument)
717 {
718 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_CTX_FULL);
719 goto err;
720 }
721 if(!bn_wexpand(dsa_p, dsa->p->top) ||
722 !bn_wexpand(dsa_q, dsa->q->top) ||
723 !bn_wexpand(dsa_g, dsa->g->top) ||
724 !bn_wexpand(dsa_key, dsa->pub_key->top) ||
725 !bn_wexpand(argument, 40))
726 {
727 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_EXPAND_FAIL);
728 goto err;
729 }
730 sw_param.type = SW_ALG_DSA;
731 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
732 (unsigned char *)dsa_p->d);
733 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
734 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
735 (unsigned char *)dsa_q->d);
736 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
737 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
738 (unsigned char *)dsa_g->d);
739 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
740 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key,
741 (unsigned char *)dsa_key->d);
742 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
743 /* Attach the key params */
744 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
745 switch(sw_status)
746 {
747 case SW_OK:
748 break;
749 case SW_ERR_INPUT_SIZE:
750 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,
751 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
752 goto err;
753 default:
754 {
755 char tmpbuf[20];
756 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_REQUEST_FAILED);
757 sprintf(tmpbuf, "%ld", sw_status);
758 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
759 }
760 goto err;
761 }
762 /* Prepare the argument and response */
763 arg[0].nbytes = dgst_len;
764 arg[0].value = (unsigned char *)dgst;
765 arg[1].nbytes = 40;
766 arg[1].value = (unsigned char *)argument->d;
767 memset(arg[1].value, 0, 40);
768 BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
769 BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
770 res.nbytes = 4; /* unsigned long */
771 res.value = (unsigned char *)(&sig_result);
772 /* Perform the operation */
773 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2,
774 &res, 1);
775 if(sw_status != SW_OK)
776 {
777 char tmpbuf[20];
778 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_REQUEST_FAILED);
779 sprintf(tmpbuf, "%ld", sw_status);
780 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
781 goto err;
782 }
783 /* Convert the response */
784 to_return = ((sig_result == 0) ? 0 : 1);
785
786err:
787 if(acquired)
788 release_context(hac);
789 if(dsa_p) ctx->tos--;
790 if(dsa_q) ctx->tos--;
791 if(dsa_g) ctx->tos--;
792 if(dsa_key) ctx->tos--;
793 if(argument) ctx->tos--;
794 if(ctx)
795 BN_CTX_free(ctx);
796 return to_return;
797 }
798
799/* This function is aliased to mod_exp (with the dh and mont dropped). */
800static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
801 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
802 {
803 return cswift_mod_exp(r, a, p, m, ctx);
804 }
805
806#endif /* !NO_HW_CSWIFT */
807#endif /* !NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_cswift_err.c b/src/lib/libssl/src/crypto/engine/hw_cswift_err.c
new file mode 100644
index 0000000000..684f53bf27
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_cswift_err.c
@@ -0,0 +1,149 @@
1/* hw_cswift_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_cswift_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CSWIFT_str_functs[]=
68 {
69{ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"},
70{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"},
71{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"},
72{ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"},
73{ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"},
74{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"},
75{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"},
76{ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA CSWIFT_str_reasons[]=
81 {
82{CSWIFT_R_ALREADY_LOADED ,"already loaded"},
83{CSWIFT_R_BAD_KEY_SIZE ,"bad key size"},
84{CSWIFT_R_BN_CTX_FULL ,"bn ctx full"},
85{CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{CSWIFT_R_NOT_LOADED ,"not loaded"},
89{CSWIFT_R_REQUEST_FAILED ,"request failed"},
90{CSWIFT_R_UNIT_FAILURE ,"unit failure"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CSWIFT_LIB_NAME
97static ERR_STRING_DATA CSWIFT_lib_name[]=
98 {
99{0 ,CSWIFT_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CSWIFT_lib_error_code=0;
106static int CSWIFT_error_init=1;
107
108static void ERR_load_CSWIFT_strings(void)
109 {
110 if (CSWIFT_lib_error_code == 0)
111 CSWIFT_lib_error_code=ERR_get_next_error_library();
112
113 if (CSWIFT_error_init)
114 {
115 CSWIFT_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
118 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
119#endif
120
121#ifdef CSWIFT_LIB_NAME
122 CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0);
123 ERR_load_strings(0,CSWIFT_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CSWIFT_strings(void)
129 {
130 if (CSWIFT_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
134 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
135#endif
136
137#ifdef CSWIFT_LIB_NAME
138 ERR_unload_strings(0,CSWIFT_lib_name);
139#endif
140 CSWIFT_error_init=1;
141 }
142 }
143
144static void ERR_CSWIFT_error(int function, int reason, char *file, int line)
145 {
146 if (CSWIFT_lib_error_code == 0)
147 CSWIFT_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_cswift_err.h b/src/lib/libssl/src/crypto/engine/hw_cswift_err.h
new file mode 100644
index 0000000000..7120c3216f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_cswift_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_CSWIFT_ERR_H
56#define HEADER_CSWIFT_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CSWIFT_strings(void);
63static void ERR_unload_CSWIFT_strings(void);
64static void ERR_CSWIFT_error(int function, int reason, char *file, int line);
65#define CSWIFTerr(f,r) ERR_CSWIFT_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CSWIFT functions. */
68
69/* Function codes. */
70#define CSWIFT_F_CSWIFT_CTRL 100
71#define CSWIFT_F_CSWIFT_DSA_SIGN 101
72#define CSWIFT_F_CSWIFT_DSA_VERIFY 102
73#define CSWIFT_F_CSWIFT_FINISH 103
74#define CSWIFT_F_CSWIFT_INIT 104
75#define CSWIFT_F_CSWIFT_MOD_EXP 105
76#define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106
77#define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define CSWIFT_R_ALREADY_LOADED 100
81#define CSWIFT_R_BAD_KEY_SIZE 101
82#define CSWIFT_R_BN_CTX_FULL 102
83#define CSWIFT_R_BN_EXPAND_FAIL 103
84#define CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED 104
85#define CSWIFT_R_MISSING_KEY_COMPONENTS 105
86#define CSWIFT_R_NOT_LOADED 106
87#define CSWIFT_R_REQUEST_FAILED 107
88#define CSWIFT_R_UNIT_FAILURE 108
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_ncipher.c b/src/lib/libssl/src/crypto/engine/hw_ncipher.c
new file mode 100644
index 0000000000..41f5900676
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ncipher.c
@@ -0,0 +1,1019 @@
1/* crypto/engine/hw_ncipher.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe
3 * (geoff@geoffthorpe.net) and Dr Stephen N Henson (shenson@bigfoot.com)
4 * for the OpenSSL project 2000.
5 */
6/* ====================================================================
7 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include <openssl/pem.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65#include "engine_int.h"
66#include <openssl/engine.h>
67
68#ifndef NO_HW
69#ifndef NO_HW_NCIPHER
70
71/* Attribution notice: nCipher have said several times that it's OK for
72 * us to implement a general interface to their boxes, and recently declared
73 * their HWCryptoHook to be public, and therefore available for us to use.
74 * Thanks, nCipher.
75 *
76 * The hwcryptohook.h included here is from May 2000.
77 * [Richard Levitte]
78 */
79#ifdef FLAT_INC
80#include "hwcryptohook.h"
81#else
82#include "vendor_defns/hwcryptohook.h"
83#endif
84
85static int hwcrhk_init(void);
86static int hwcrhk_finish(void);
87static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)());
88
89/* Functions to handle mutexes */
90static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
91static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*);
92static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*);
93static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*);
94
95/* BIGNUM stuff */
96static int hwcrhk_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
97 const BIGNUM *m, BN_CTX *ctx);
98
99/* RSA stuff */
100static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa);
101/* This function is aliased to mod_exp (with the mont stuff dropped). */
102static int hwcrhk_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
104
105/* DH stuff */
106/* This function is alised to mod_exp (with the DH and mont dropped). */
107static int hwcrhk_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
108 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
109
110/* RAND stuff */
111static int hwcrhk_rand_bytes(unsigned char *buf, int num);
112static int hwcrhk_rand_status(void);
113
114/* KM stuff */
115static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
116 const char *passphrase);
117static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id,
118 const char *passphrase);
119static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
120 int index,long argl, void *argp);
121
122/* Interaction stuff */
123static int hwcrhk_get_pass(const char *prompt_info,
124 int *len_io, char *buf,
125 HWCryptoHook_PassphraseContext *ppctx,
126 HWCryptoHook_CallerContext *cactx);
127static void hwcrhk_log_message(void *logstream, const char *message);
128
129/* Our internal RSA_METHOD that we provide pointers to */
130static RSA_METHOD hwcrhk_rsa =
131 {
132 "nCipher RSA method",
133 NULL,
134 NULL,
135 NULL,
136 NULL,
137 hwcrhk_rsa_mod_exp,
138 hwcrhk_mod_exp_mont,
139 NULL,
140 NULL,
141 0,
142 NULL,
143 NULL,
144 NULL
145 };
146
147/* Our internal DH_METHOD that we provide pointers to */
148static DH_METHOD hwcrhk_dh =
149 {
150 "nCipher DH method",
151 NULL,
152 NULL,
153 hwcrhk_mod_exp_dh,
154 NULL,
155 NULL,
156 0,
157 NULL
158 };
159
160static RAND_METHOD hwcrhk_rand =
161 {
162 /* "nCipher RAND method", */
163 NULL,
164 hwcrhk_rand_bytes,
165 NULL,
166 NULL,
167 hwcrhk_rand_bytes,
168 hwcrhk_rand_status,
169 };
170
171/* Our ENGINE structure. */
172static ENGINE engine_hwcrhk =
173 {
174 "chil",
175 "nCipher hardware engine support",
176 &hwcrhk_rsa,
177 NULL,
178 &hwcrhk_dh,
179 &hwcrhk_rand,
180 hwcrhk_mod_exp,
181 NULL,
182 hwcrhk_init,
183 hwcrhk_finish,
184 hwcrhk_ctrl,
185 hwcrhk_load_privkey,
186 hwcrhk_load_pubkey,
187 0, /* no flags */
188 0, 0, /* no references */
189 NULL, NULL /* unlinked */
190 };
191
192/* Internal stuff for HWCryptoHook */
193
194/* Some structures needed for proper use of thread locks */
195/* hwcryptohook.h has some typedefs that turn struct HWCryptoHook_MutexValue
196 into HWCryptoHook_Mutex */
197struct HWCryptoHook_MutexValue
198 {
199 int lockid;
200 };
201
202/* hwcryptohook.h has some typedefs that turn
203 struct HWCryptoHook_PassphraseContextValue
204 into HWCryptoHook_PassphraseContext */
205struct HWCryptoHook_PassphraseContextValue
206 {
207 void *any;
208 };
209
210/* hwcryptohook.h has some typedefs that turn
211 struct HWCryptoHook_CallerContextValue
212 into HWCryptoHook_CallerContext */
213struct HWCryptoHook_CallerContextValue
214 {
215 void *any;
216 };
217
218/* The MPI structure in HWCryptoHook is pretty compatible with OpenSSL
219 BIGNUM's, so lets define a couple of conversion macros */
220#define BN2MPI(mp, bn) \
221 {mp.size = bn->top * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
222#define MPI2BN(bn, mp) \
223 {mp.size = bn->dmax * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
224
225#if 0 /* Card and password management is not yet supported */
226/* HWCryptoHook callbacks. insert_card() and get_pass() are not yet
227 defined, because we haven't quite decided on the proper form yet.
228 log_message() just adds an entry in the error stack. I don't know
229 if that's good or bad... */
230static int insert_card(const char *prompt_info,
231 const char *wrong_info,
232 HWCryptoHook_PassphraseContext *ppctx,
233 HWCryptoHook_CallerContext *cactx);
234static int get_pass(const char *prompt_info,
235 int *len_io, char *buf,
236 HWCryptoHook_PassphraseContext *ppctx,
237 HWCryptoHook_CallerContext *cactx);
238#endif
239
240static BIO *logstream = NULL;
241static pem_password_cb *password_callback = NULL;
242#if 0
243static void *password_callback_userdata = NULL;
244#endif
245static int disable_mutex_callbacks = 0;
246
247/* Stuff to pass to the HWCryptoHook library */
248static HWCryptoHook_InitInfo hwcrhk_globals = {
249 0, /* Flags */
250 &logstream, /* logstream */
251 sizeof(BN_ULONG), /* limbsize */
252 0, /* mslimb first: false for BNs */
253 -1, /* msbyte first: use native */
254 0, /* Max mutexes, 0 = no small limit */
255 0, /* Max simultaneous, 0 = default */
256
257 /* The next few are mutex stuff: we write wrapper functions
258 around the OS mutex functions. We initialise them to 0
259 here, and change that to actual function pointers in hwcrhk_init()
260 if dynamic locks are supported (that is, if the application
261 programmer has made sure of setting up callbacks bafore starting
262 this engine) *and* if disable_mutex_callbacks hasn't been set by
263 a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */
264 sizeof(HWCryptoHook_Mutex),
265 0,
266 0,
267 0,
268 0,
269
270 /* The next few are condvar stuff: we write wrapper functions
271 round the OS functions. Currently not implemented and not
272 and absolute necessity even in threaded programs, therefore
273 0'ed. Will hopefully be implemented some day, since it
274 enhances the efficiency of HWCryptoHook. */
275 0, /* sizeof(HWCryptoHook_CondVar), */
276 0, /* hwcrhk_cv_init, */
277 0, /* hwcrhk_cv_wait, */
278 0, /* hwcrhk_cv_signal, */
279 0, /* hwcrhk_cv_broadcast, */
280 0, /* hwcrhk_cv_destroy, */
281
282 hwcrhk_get_pass, /* pass phrase */
283 0, /* insert_card, */ /* insert a card */
284 hwcrhk_log_message /* Log message */
285};
286
287
288/* Now, to our own code */
289
290/* As this is only ever called once, there's no need for locking
291 * (indeed - the lock will already be held by our caller!!!) */
292ENGINE *ENGINE_ncipher()
293 {
294 RSA_METHOD *meth1;
295 DH_METHOD *meth2;
296
297 /* We know that the "PKCS1_SSLeay()" functions hook properly
298 * to the cswift-specific mod_exp and mod_exp_crt so we use
299 * those functions. NB: We don't use ENGINE_openssl() or
300 * anything "more generic" because something like the RSAref
301 * code may not hook properly, and if you own one of these
302 * cards then you have the right to do RSA operations on it
303 * anyway! */
304 meth1 = RSA_PKCS1_SSLeay();
305 hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
306 hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
307 hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
308 hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
309
310 /* Much the same for Diffie-Hellman */
311 meth2 = DH_OpenSSL();
312 hwcrhk_dh.generate_key = meth2->generate_key;
313 hwcrhk_dh.compute_key = meth2->compute_key;
314 return &engine_hwcrhk;
315 }
316
317/* This is a process-global DSO handle used for loading and unloading
318 * the HWCryptoHook library. NB: This is only set (or unset) during an
319 * init() or finish() call (reference counts permitting) and they're
320 * operating with global locks, so this should be thread-safe
321 * implicitly. */
322static DSO *hwcrhk_dso = NULL;
323static HWCryptoHook_ContextHandle hwcrhk_context = 0;
324static int hndidx = -1; /* Index for KM handle. Not really used yet. */
325
326/* These are the function pointers that are (un)set when the library has
327 * successfully (un)loaded. */
328static HWCryptoHook_Init_t *p_hwcrhk_Init = NULL;
329static HWCryptoHook_Finish_t *p_hwcrhk_Finish = NULL;
330static HWCryptoHook_ModExp_t *p_hwcrhk_ModExp = NULL;
331static HWCryptoHook_RSA_t *p_hwcrhk_RSA = NULL;
332static HWCryptoHook_RandomBytes_t *p_hwcrhk_RandomBytes = NULL;
333static HWCryptoHook_RSALoadKey_t *p_hwcrhk_RSALoadKey = NULL;
334static HWCryptoHook_RSAGetPublicKey_t *p_hwcrhk_RSAGetPublicKey = NULL;
335static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL;
336static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL;
337
338/* Used in the DSO operations. */
339static const char *HWCRHK_LIBNAME = "nfhwcrhk";
340static const char *n_hwcrhk_Init = "HWCryptoHook_Init";
341static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish";
342static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp";
343static const char *n_hwcrhk_RSA = "HWCryptoHook_RSA";
344static const char *n_hwcrhk_RandomBytes = "HWCryptoHook_RandomBytes";
345static const char *n_hwcrhk_RSALoadKey = "HWCryptoHook_RSALoadKey";
346static const char *n_hwcrhk_RSAGetPublicKey = "HWCryptoHook_RSAGetPublicKey";
347static const char *n_hwcrhk_RSAUnloadKey = "HWCryptoHook_RSAUnloadKey";
348static const char *n_hwcrhk_ModExpCRT = "HWCryptoHook_ModExpCRT";
349
350/* HWCryptoHook library functions and mechanics - these are used by the
351 * higher-level functions further down. NB: As and where there's no
352 * error checking, take a look lower down where these functions are
353 * called, the checking and error handling is probably down there. */
354
355/* utility function to obtain a context */
356static int get_context(HWCryptoHook_ContextHandle *hac)
357 {
358 char tempbuf[1024];
359 HWCryptoHook_ErrMsgBuf rmsg;
360
361 rmsg.buf = tempbuf;
362 rmsg.size = 1024;
363
364 *hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
365 NULL);
366 if (!*hac)
367 return 0;
368 return 1;
369 }
370
371/* similarly to release one. */
372static void release_context(HWCryptoHook_ContextHandle hac)
373 {
374 p_hwcrhk_Finish(hac);
375 }
376
377/* (de)initialisation functions. */
378static int hwcrhk_init()
379 {
380 HWCryptoHook_Init_t *p1;
381 HWCryptoHook_Finish_t *p2;
382 HWCryptoHook_ModExp_t *p3;
383 HWCryptoHook_RSA_t *p4;
384 HWCryptoHook_RSALoadKey_t *p5;
385 HWCryptoHook_RSAGetPublicKey_t *p6;
386 HWCryptoHook_RSAUnloadKey_t *p7;
387 HWCryptoHook_RandomBytes_t *p8;
388 HWCryptoHook_ModExpCRT_t *p9;
389
390 if(hwcrhk_dso != NULL)
391 {
392 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_ALREADY_LOADED);
393 goto err;
394 }
395 /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
396 hwcrhk_dso = DSO_load(NULL, HWCRHK_LIBNAME, NULL,
397 DSO_FLAG_NAME_TRANSLATION);
398 if(hwcrhk_dso == NULL)
399 {
400 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_DSO_FAILURE);
401 goto err;
402 }
403 if(!(p1 = (HWCryptoHook_Init_t *)
404 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) ||
405 !(p2 = (HWCryptoHook_Finish_t *)
406 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) ||
407 !(p3 = (HWCryptoHook_ModExp_t *)
408 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) ||
409 !(p4 = (HWCryptoHook_RSA_t *)
410 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) ||
411 !(p5 = (HWCryptoHook_RSALoadKey_t *)
412 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) ||
413 !(p6 = (HWCryptoHook_RSAGetPublicKey_t *)
414 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) ||
415 !(p7 = (HWCryptoHook_RSAUnloadKey_t *)
416 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) ||
417 !(p8 = (HWCryptoHook_RandomBytes_t *)
418 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) ||
419 !(p9 = (HWCryptoHook_ModExpCRT_t *)
420 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT)))
421 {
422 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_DSO_FAILURE);
423 goto err;
424 }
425 /* Copy the pointers */
426 p_hwcrhk_Init = p1;
427 p_hwcrhk_Finish = p2;
428 p_hwcrhk_ModExp = p3;
429 p_hwcrhk_RSA = p4;
430 p_hwcrhk_RSALoadKey = p5;
431 p_hwcrhk_RSAGetPublicKey = p6;
432 p_hwcrhk_RSAUnloadKey = p7;
433 p_hwcrhk_RandomBytes = p8;
434 p_hwcrhk_ModExpCRT = p9;
435
436 /* Check if the application decided to support dynamic locks,
437 and if it does, use them. */
438 if (disable_mutex_callbacks == 0 &&
439 CRYPTO_get_dynlock_create_callback() != NULL &&
440 CRYPTO_get_dynlock_lock_callback() != NULL &&
441 CRYPTO_get_dynlock_destroy_callback() != NULL)
442 {
443 hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
444 hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
445 hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
446 hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
447 }
448
449 /* Try and get a context - if not, we may have a DSO but no
450 * accelerator! */
451 if(!get_context(&hwcrhk_context))
452 {
453 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_UNIT_FAILURE);
454 goto err;
455 }
456 /* Everything's fine. */
457 if (hndidx == -1)
458 hndidx = RSA_get_ex_new_index(0,
459 "nFast HWCryptoHook RSA key handle",
460 NULL, NULL, hwcrhk_ex_free);
461 return 1;
462err:
463 if(hwcrhk_dso)
464 DSO_free(hwcrhk_dso);
465 hwcrhk_dso = NULL;
466 p_hwcrhk_Init = NULL;
467 p_hwcrhk_Finish = NULL;
468 p_hwcrhk_ModExp = NULL;
469 p_hwcrhk_RSA = NULL;
470 p_hwcrhk_RSALoadKey = NULL;
471 p_hwcrhk_RSAGetPublicKey = NULL;
472 p_hwcrhk_RSAUnloadKey = NULL;
473 p_hwcrhk_ModExpCRT = NULL;
474 p_hwcrhk_RandomBytes = NULL;
475 return 0;
476 }
477
478static int hwcrhk_finish()
479 {
480 int to_return = 1;
481 if(hwcrhk_dso == NULL)
482 {
483 ENGINEerr(ENGINE_F_HWCRHK_FINISH,ENGINE_R_NOT_LOADED);
484 to_return = 0;
485 goto err;
486 }
487 release_context(hwcrhk_context);
488 if(!DSO_free(hwcrhk_dso))
489 {
490 ENGINEerr(ENGINE_F_HWCRHK_FINISH,ENGINE_R_DSO_FAILURE);
491 to_return = 0;
492 goto err;
493 }
494 err:
495 if (logstream)
496 BIO_free(logstream);
497 hwcrhk_dso = NULL;
498 p_hwcrhk_Init = NULL;
499 p_hwcrhk_Finish = NULL;
500 p_hwcrhk_ModExp = NULL;
501 p_hwcrhk_RSA = NULL;
502 p_hwcrhk_RSALoadKey = NULL;
503 p_hwcrhk_RSAGetPublicKey = NULL;
504 p_hwcrhk_RSAUnloadKey = NULL;
505 p_hwcrhk_ModExpCRT = NULL;
506 p_hwcrhk_RandomBytes = NULL;
507 return to_return;
508 }
509
510static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)())
511 {
512 int to_return = 1;
513
514 switch(cmd)
515 {
516 case ENGINE_CTRL_SET_LOGSTREAM:
517 {
518 BIO *bio = (BIO *)p;
519
520 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
521 if (logstream)
522 {
523 BIO_free(logstream);
524 logstream = NULL;
525 }
526 if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1)
527 logstream = bio;
528 else
529 ENGINEerr(ENGINE_F_HWCRHK_CTRL,ENGINE_R_BIO_WAS_FREED);
530 }
531 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
532 break;
533 case ENGINE_CTRL_SET_PASSWORD_CALLBACK:
534 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
535 password_callback = (pem_password_cb *)f;
536 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
537 break;
538 /* this enables or disables the "SimpleForkCheck" flag used in the
539 * initialisation structure. */
540 case ENGINE_CTRL_CHIL_SET_FORKCHECK:
541 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
542 if(i)
543 hwcrhk_globals.flags |=
544 HWCryptoHook_InitFlags_SimpleForkCheck;
545 else
546 hwcrhk_globals.flags &=
547 ~HWCryptoHook_InitFlags_SimpleForkCheck;
548 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
549 break;
550 /* This will prevent the initialisation function from "installing"
551 * the mutex-handling callbacks, even if they are available from
552 * within the library (or were provided to the library from the
553 * calling application). This is to remove any baggage for
554 * applications not using multithreading. */
555 case ENGINE_CTRL_CHIL_NO_LOCKING:
556 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
557 disable_mutex_callbacks = 1;
558 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
559 break;
560
561 /* The command isn't understood by this engine */
562 default:
563 ENGINEerr(ENGINE_F_HWCRHK_CTRL,
564 ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
565 to_return = 0;
566 break;
567 }
568
569 return to_return;
570 }
571
572static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
573 const char *passphrase)
574 {
575 RSA *rtmp = NULL;
576 EVP_PKEY *res = NULL;
577 HWCryptoHook_MPI e, n;
578 HWCryptoHook_RSAKeyHandle *hptr;
579 HWCryptoHook_ErrMsgBuf rmsg;
580
581 if(!hwcrhk_context)
582 {
583 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
584 ENGINE_R_NOT_INITIALISED);
585 goto err;
586 }
587 hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));
588 if (!hptr)
589 {
590 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
591 ERR_R_MALLOC_FAILURE);
592 goto err;
593 }
594 if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,
595 &rmsg, NULL))
596 {
597 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
598 ENGINE_R_CHIL_ERROR);
599 ERR_add_error_data(1,rmsg.buf);
600 goto err;
601 }
602 if (!*hptr)
603 {
604 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
605 ENGINE_R_NO_KEY);
606 goto err;
607 }
608 rtmp = RSA_new_method(&engine_hwcrhk);
609 RSA_set_ex_data(rtmp, hndidx, (char *)hptr);
610 rtmp->e = BN_new();
611 rtmp->n = BN_new();
612 rtmp->flags |= RSA_FLAG_EXT_PKEY;
613 MPI2BN(rtmp->e, e);
614 MPI2BN(rtmp->n, n);
615 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)
616 != HWCRYPTOHOOK_ERROR_MPISIZE)
617 {
618 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,ENGINE_R_CHIL_ERROR);
619 ERR_add_error_data(1,rmsg.buf);
620 goto err;
621 }
622
623 bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));
624 bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));
625 MPI2BN(rtmp->e, e);
626 MPI2BN(rtmp->n, n);
627
628 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))
629 {
630 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
631 ENGINE_R_CHIL_ERROR);
632 ERR_add_error_data(1,rmsg.buf);
633 goto err;
634 }
635 rtmp->e->top = e.size / sizeof(BN_ULONG);
636 bn_fix_top(rtmp->e);
637 rtmp->n->top = n.size / sizeof(BN_ULONG);
638 bn_fix_top(rtmp->n);
639
640 res = EVP_PKEY_new();
641 EVP_PKEY_assign_RSA(res, rtmp);
642
643 return res;
644 err:
645 if (res)
646 EVP_PKEY_free(res);
647 if (rtmp)
648 RSA_free(rtmp);
649 return NULL;
650 }
651
652static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id, const char *passphrase)
653 {
654 EVP_PKEY *res = hwcrhk_load_privkey(key_id, passphrase);
655
656 if (res)
657 switch(res->type)
658 {
659 case EVP_PKEY_RSA:
660 {
661 RSA *rsa = NULL;
662
663 CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);
664 rsa = res->pkey.rsa;
665 res->pkey.rsa = RSA_new();
666 res->pkey.rsa->n = rsa->n;
667 res->pkey.rsa->e = rsa->e;
668 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
669 RSA_free(rsa);
670 }
671 default:
672 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
673 ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
674 goto err;
675 }
676
677 return res;
678 err:
679 if (res)
680 EVP_PKEY_free(res);
681 return NULL;
682 }
683
684/* A little mod_exp */
685static int hwcrhk_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
686 const BIGNUM *m, BN_CTX *ctx)
687 {
688 char tempbuf[1024];
689 HWCryptoHook_ErrMsgBuf rmsg;
690 /* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's,
691 we use them directly, plus a little macro magic. We only
692 thing we need to make sure of is that enough space is allocated. */
693 HWCryptoHook_MPI m_a, m_p, m_n, m_r;
694 int to_return, ret;
695
696 to_return = 0; /* expect failure */
697 rmsg.buf = tempbuf;
698 rmsg.size = 1024;
699
700 if(!hwcrhk_context)
701 {
702 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
703 goto err;
704 }
705 /* Prepare the params */
706 bn_expand2(r, m->top); /* Check for error !! */
707 BN2MPI(m_a, a);
708 BN2MPI(m_p, p);
709 BN2MPI(m_n, m);
710 MPI2BN(r, m_r);
711
712 /* Perform the operation */
713 ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg);
714
715 /* Convert the response */
716 r->top = m_r.size / sizeof(BN_ULONG);
717 bn_fix_top(r);
718
719 if (ret < 0)
720 {
721 /* FIXME: When this error is returned, HWCryptoHook is
722 telling us that falling back to software computation
723 might be a good thing. */
724 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
725 {
726 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
727 }
728 else
729 {
730 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_REQUEST_FAILED);
731 }
732 ERR_add_error_data(1,rmsg.buf);
733 goto err;
734 }
735
736 to_return = 1;
737err:
738 return to_return;
739 }
740
741static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa)
742 {
743 char tempbuf[1024];
744 HWCryptoHook_ErrMsgBuf rmsg;
745 HWCryptoHook_RSAKeyHandle *hptr;
746 int to_return = 0, ret;
747
748 if(!hwcrhk_context)
749 {
750 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
751 goto err;
752 }
753
754 /* This provides support for nForce keys. Since that's opaque data
755 all we do is provide a handle to the proper key and let HWCryptoHook
756 take care of the rest. */
757 if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx))
758 != NULL)
759 {
760 HWCryptoHook_MPI m_a, m_r;
761
762 if(!rsa->n)
763 {
764 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,
765 ENGINE_R_MISSING_KEY_COMPONENTS);
766 goto err;
767 }
768
769 rmsg.buf = tempbuf;
770 rmsg.size = 1024;
771
772 /* Prepare the params */
773 bn_expand2(r, rsa->n->top); /* Check for error !! */
774 BN2MPI(m_a, I);
775 MPI2BN(r, m_r);
776
777 /* Perform the operation */
778 ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg);
779
780 /* Convert the response */
781 r->top = m_r.size / sizeof(BN_ULONG);
782 bn_fix_top(r);
783
784 if (ret < 0)
785 {
786 /* FIXME: When this error is returned, HWCryptoHook is
787 telling us that falling back to software computation
788 might be a good thing. */
789 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
790 {
791 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
792 }
793 else
794 {
795 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
796 }
797 ERR_add_error_data(1,rmsg.buf);
798 goto err;
799 }
800 }
801 else
802 {
803 HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r;
804
805 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
806 {
807 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,
808 ENGINE_R_MISSING_KEY_COMPONENTS);
809 goto err;
810 }
811
812 rmsg.buf = tempbuf;
813 rmsg.size = 1024;
814
815 /* Prepare the params */
816 bn_expand2(r, rsa->n->top); /* Check for error !! */
817 BN2MPI(m_a, I);
818 BN2MPI(m_p, rsa->p);
819 BN2MPI(m_q, rsa->q);
820 BN2MPI(m_dmp1, rsa->dmp1);
821 BN2MPI(m_dmq1, rsa->dmq1);
822 BN2MPI(m_iqmp, rsa->iqmp);
823 MPI2BN(r, m_r);
824
825 /* Perform the operation */
826 ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q,
827 m_dmp1, m_dmq1, m_iqmp, &m_r, NULL);
828
829 /* Convert the response */
830 r->top = m_r.size / sizeof(BN_ULONG);
831 bn_fix_top(r);
832
833 if (ret < 0)
834 {
835 /* FIXME: When this error is returned, HWCryptoHook is
836 telling us that falling back to software computation
837 might be a good thing. */
838 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
839 {
840 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
841 }
842 else
843 {
844 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
845 }
846 ERR_add_error_data(1,rmsg.buf);
847 goto err;
848 }
849 }
850 /* If we're here, we must be here with some semblance of success :-) */
851 to_return = 1;
852err:
853 return to_return;
854 }
855
856/* This function is aliased to mod_exp (with the mont stuff dropped). */
857static int hwcrhk_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
858 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
859 {
860 return hwcrhk_mod_exp(r, a, p, m, ctx);
861 }
862
863/* This function is aliased to mod_exp (with the dh and mont dropped). */
864static int hwcrhk_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
865 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
866 {
867 return hwcrhk_mod_exp(r, a, p, m, ctx);
868 }
869
870/* Random bytes are good */
871static int hwcrhk_rand_bytes(unsigned char *buf, int num)
872 {
873 char tempbuf[1024];
874 HWCryptoHook_ErrMsgBuf rmsg;
875 int to_return = 0; /* assume failure */
876 int ret;
877
878 rmsg.buf = tempbuf;
879 rmsg.size = 1024;
880
881 if(!hwcrhk_context)
882 {
883 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_NOT_INITIALISED);
884 goto err;
885 }
886
887 ret = p_hwcrhk_RandomBytes(hwcrhk_context, buf, num, &rmsg);
888 if (ret < 0)
889 {
890 /* FIXME: When this error is returned, HWCryptoHook is
891 telling us that falling back to software computation
892 might be a good thing. */
893 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
894 {
895 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_REQUEST_FALLBACK);
896 }
897 else
898 {
899 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_REQUEST_FAILED);
900 }
901 ERR_add_error_data(1,rmsg.buf);
902 goto err;
903 }
904 to_return = 1;
905 err:
906 return to_return;
907 }
908
909static int hwcrhk_rand_status(void)
910 {
911 return 1;
912 }
913
914/* This cleans up an RSA KM key, called when ex_data is freed */
915
916static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
917 int index,long argl, void *argp)
918{
919 char tempbuf[1024];
920 HWCryptoHook_ErrMsgBuf rmsg;
921 HWCryptoHook_RSAKeyHandle *hptr;
922 int ret;
923
924 rmsg.buf = tempbuf;
925 rmsg.size = 1024;
926
927 hptr = (HWCryptoHook_RSAKeyHandle *) item;
928 if(!hptr) return;
929 ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL);
930 OPENSSL_free(hptr);
931}
932
933/* Mutex calls: since the HWCryptoHook model closely follows the POSIX model
934 * these just wrap the POSIX functions and add some logging.
935 */
936
937static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
938 HWCryptoHook_CallerContext *cactx)
939 {
940 mt->lockid = CRYPTO_get_new_dynlockid();
941 if (mt->lockid == 0)
942 return 0;
943 return 1;
944 }
945
946static int hwcrhk_mutex_lock(HWCryptoHook_Mutex *mt)
947 {
948 CRYPTO_w_lock(mt->lockid);
949 return 1;
950 }
951
952void hwcrhk_mutex_unlock(HWCryptoHook_Mutex * mt)
953 {
954 CRYPTO_w_unlock(mt->lockid);
955 }
956
957static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt)
958 {
959 CRYPTO_destroy_dynlockid(mt->lockid);
960 }
961
962static int hwcrhk_get_pass(const char *prompt_info,
963 int *len_io, char *buf,
964 HWCryptoHook_PassphraseContext *ppctx,
965 HWCryptoHook_CallerContext *cactx)
966 {
967 int l = 0;
968 char prompt[1024];
969
970 if (password_callback == NULL)
971 {
972 ENGINEerr(ENGINE_F_HWCRHK_GET_PASS,ENGINE_R_NO_CALLBACK);
973 return -1;
974 }
975 if (prompt_info)
976 {
977 strncpy(prompt, "Card: \"", sizeof(prompt));
978 l += 5;
979 strncpy(prompt + l, prompt_info, sizeof(prompt) - l);
980 l += strlen(prompt_info);
981 if (l + 2 < sizeof(prompt))
982 {
983 strncpy(prompt + l, "\"\n", sizeof(prompt) - l);
984 l += 2;
985 }
986 }
987 if (l < sizeof(prompt) - 1)
988 {
989 strncpy(prompt, "Enter Passphrase <enter to cancel>:",
990 sizeof(prompt) - l);
991 l += 35;
992 }
993 prompt[l] = '\0';
994
995 /* I know, passing on the prompt instead of the user data *is*
996 a bad thing. However, that's all we have right now.
997 -- Richard Levitte */
998 *len_io = password_callback(buf, *len_io, 0, prompt);
999 if(!*len_io)
1000 return -1;
1001 return 0;
1002 }
1003
1004static void hwcrhk_log_message(void *logstream, const char *message)
1005 {
1006 BIO *lstream = NULL;
1007
1008 CRYPTO_w_lock(CRYPTO_LOCK_BIO);
1009 if (logstream)
1010 lstream=*(BIO **)logstream;
1011 if (lstream)
1012 {
1013 BIO_write(lstream, message, strlen(message));
1014 }
1015 CRYPTO_w_unlock(CRYPTO_LOCK_BIO);
1016 }
1017
1018#endif /* !NO_HW_NCIPHER */
1019#endif /* !NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_ncipher_err.c b/src/lib/libssl/src/crypto/engine/hw_ncipher_err.c
new file mode 100644
index 0000000000..24024cfc6f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ncipher_err.c
@@ -0,0 +1,156 @@
1/* hw_ncipher_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ncipher_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA HWCRHK_str_functs[]=
68 {
69{ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"},
70{ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"},
71{ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"},
72{ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"},
73{ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"},
74{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"},
75{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"},
76{ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"},
77{ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"},
78{ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA HWCRHK_str_reasons[]=
83 {
84{HWCRHK_R_ALREADY_LOADED ,"already loaded"},
85{HWCRHK_R_BIO_WAS_FREED ,"bio was freed"},
86{HWCRHK_R_CHIL_ERROR ,"chil error"},
87{HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
88{HWCRHK_R_DSO_FAILURE ,"dso failure"},
89{HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
90{HWCRHK_R_NOT_INITIALISED ,"not initialised"},
91{HWCRHK_R_NOT_LOADED ,"not loaded"},
92{HWCRHK_R_NO_CALLBACK ,"no callback"},
93{HWCRHK_R_NO_KEY ,"no key"},
94{HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"},
95{HWCRHK_R_REQUEST_FAILED ,"request failed"},
96{HWCRHK_R_REQUEST_FALLBACK ,"request fallback"},
97{HWCRHK_R_UNIT_FAILURE ,"unit failure"},
98{0,NULL}
99 };
100
101#endif
102
103#ifdef HWCRHK_LIB_NAME
104static ERR_STRING_DATA HWCRHK_lib_name[]=
105 {
106{0 ,HWCRHK_LIB_NAME},
107{0,NULL}
108 };
109#endif
110
111
112static int HWCRHK_lib_error_code=0;
113static int HWCRHK_error_init=1;
114
115static void ERR_load_HWCRHK_strings(void)
116 {
117 if (HWCRHK_lib_error_code == 0)
118 HWCRHK_lib_error_code=ERR_get_next_error_library();
119
120 if (HWCRHK_error_init)
121 {
122 HWCRHK_error_init=0;
123#ifndef OPENSSL_NO_ERR
124 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
125 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
126#endif
127
128#ifdef HWCRHK_LIB_NAME
129 HWCRHK_lib_name->error = ERR_PACK(HWCRHK_lib_error_code,0,0);
130 ERR_load_strings(0,HWCRHK_lib_name);
131#endif
132 }
133 }
134
135static void ERR_unload_HWCRHK_strings(void)
136 {
137 if (HWCRHK_error_init == 0)
138 {
139#ifndef OPENSSL_NO_ERR
140 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
141 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
142#endif
143
144#ifdef HWCRHK_LIB_NAME
145 ERR_unload_strings(0,HWCRHK_lib_name);
146#endif
147 HWCRHK_error_init=1;
148 }
149 }
150
151static void ERR_HWCRHK_error(int function, int reason, char *file, int line)
152 {
153 if (HWCRHK_lib_error_code == 0)
154 HWCRHK_lib_error_code=ERR_get_next_error_library();
155 ERR_PUT_error(HWCRHK_lib_error_code,function,reason,file,line);
156 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_ncipher_err.h b/src/lib/libssl/src/crypto/engine/hw_ncipher_err.h
new file mode 100644
index 0000000000..4d65b1d470
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ncipher_err.h
@@ -0,0 +1,100 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_HWCRHK_ERR_H
56#define HEADER_HWCRHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_HWCRHK_strings(void);
63static void ERR_unload_HWCRHK_strings(void);
64static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
65#define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the HWCRHK functions. */
68
69/* Function codes. */
70#define HWCRHK_F_HWCRHK_CTRL 100
71#define HWCRHK_F_HWCRHK_FINISH 101
72#define HWCRHK_F_HWCRHK_GET_PASS 102
73#define HWCRHK_F_HWCRHK_INIT 103
74#define HWCRHK_F_HWCRHK_INSERT_CARD 104
75#define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105
76#define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106
77#define HWCRHK_F_HWCRHK_MOD_EXP 107
78#define HWCRHK_F_HWCRHK_RAND_BYTES 108
79#define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109
80
81/* Reason codes. */
82#define HWCRHK_R_ALREADY_LOADED 100
83#define HWCRHK_R_BIO_WAS_FREED 101
84#define HWCRHK_R_CHIL_ERROR 102
85#define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
86#define HWCRHK_R_DSO_FAILURE 104
87#define HWCRHK_R_MISSING_KEY_COMPONENTS 105
88#define HWCRHK_R_NOT_INITIALISED 106
89#define HWCRHK_R_NOT_LOADED 107
90#define HWCRHK_R_NO_CALLBACK 108
91#define HWCRHK_R_NO_KEY 109
92#define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110
93#define HWCRHK_R_REQUEST_FAILED 111
94#define HWCRHK_R_REQUEST_FALLBACK 112
95#define HWCRHK_R_UNIT_FAILURE 113
96
97#ifdef __cplusplus
98}
99#endif
100#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_nuron.c b/src/lib/libssl/src/crypto/engine/hw_nuron.c
new file mode 100644
index 0000000000..2672012154
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_nuron.c
@@ -0,0 +1,399 @@
1/* crypto/engine/hw_nuron.c */
2/* Written by Ben Laurie for the OpenSSL Project, leaning heavily on Geoff
3 * Thorpe's Atalla implementation.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include <openssl/engine.h>
64
65
66#ifndef OPENSSL_NO_HW
67#ifndef OPENSSL_NO_HW_NURON
68
69#define NURON_LIB_NAME "nuron engine"
70#include "hw_nuron_err.c"
71
72static const char def_NURON_LIBNAME[] = "nuronssl";
73static const char *NURON_LIBNAME = def_NURON_LIBNAME;
74static const char *NURON_F1 = "nuron_mod_exp";
75
76/* The definitions for control commands specific to this engine */
77#define NURON_CMD_SO_PATH ENGINE_CMD_BASE
78static const ENGINE_CMD_DEFN nuron_cmd_defns[] = {
79 {NURON_CMD_SO_PATH,
80 "SO_PATH",
81 "Specifies the path to the 'nuronssl' shared library",
82 ENGINE_CMD_FLAG_STRING},
83 {0, NULL, NULL, 0}
84 };
85
86typedef int tfnModExp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,const BIGNUM *m);
87static tfnModExp *pfnModExp = NULL;
88
89static DSO *pvDSOHandle = NULL;
90
91static int nuron_destroy(ENGINE *e)
92 {
93 ERR_unload_NURON_strings();
94 return 1;
95 }
96
97static int nuron_init(ENGINE *e)
98 {
99 if(pvDSOHandle != NULL)
100 {
101 NURONerr(NURON_F_NURON_INIT,NURON_R_ALREADY_LOADED);
102 return 0;
103 }
104
105 pvDSOHandle = DSO_load(NULL, NURON_LIBNAME, NULL,
106 DSO_FLAG_NAME_TRANSLATION_EXT_ONLY);
107 if(!pvDSOHandle)
108 {
109 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_NOT_FOUND);
110 return 0;
111 }
112
113 pfnModExp = (tfnModExp *)DSO_bind_func(pvDSOHandle, NURON_F1);
114 if(!pfnModExp)
115 {
116 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_FUNCTION_NOT_FOUND);
117 return 0;
118 }
119
120 return 1;
121 }
122
123static int nuron_finish(ENGINE *e)
124 {
125 if(pvDSOHandle == NULL)
126 {
127 NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
128 return 0;
129 }
130 if(!DSO_free(pvDSOHandle))
131 {
132 NURONerr(NURON_F_NURON_FINISH,NURON_R_DSO_FAILURE);
133 return 0;
134 }
135 pvDSOHandle=NULL;
136 pfnModExp=NULL;
137 return 1;
138 }
139
140static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
141 {
142 int initialised = ((pvDSOHandle == NULL) ? 0 : 1);
143 switch(cmd)
144 {
145 case NURON_CMD_SO_PATH:
146 if(p == NULL)
147 {
148 NURONerr(NURON_F_NURON_CTRL,ERR_R_PASSED_NULL_PARAMETER);
149 return 0;
150 }
151 if(initialised)
152 {
153 NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED);
154 return 0;
155 }
156 NURON_LIBNAME = (const char *)p;
157 return 1;
158 default:
159 break;
160 }
161 NURONerr(NURON_F_NURON_CTRL,NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED);
162 return 0;
163}
164
165static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,
166 const BIGNUM *m,BN_CTX *ctx)
167 {
168 if(!pvDSOHandle)
169 {
170 NURONerr(NURON_F_NURON_MOD_EXP,NURON_R_NOT_LOADED);
171 return 0;
172 }
173 return pfnModExp(r,a,p,m);
174 }
175
176#ifndef OPENSSL_NO_RSA
177static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
178 {
179 return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL);
180 }
181#endif
182
183#ifndef OPENSSL_NO_DSA
184/* This code was liberated and adapted from the commented-out code in
185 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
186 * (it doesn't have a CRT form for RSA), this function means that an
187 * Atalla system running with a DSA server certificate can handshake
188 * around 5 or 6 times faster/more than an equivalent system running with
189 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
190 * of "openssl speed -engine atalla dsa1024 rsa1024". */
191static int nuron_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
192 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
193 BN_CTX *ctx, BN_MONT_CTX *in_mont)
194 {
195 BIGNUM t;
196 int to_return = 0;
197
198 BN_init(&t);
199 /* let rr = a1 ^ p1 mod m */
200 if (!nuron_mod_exp(rr,a1,p1,m,ctx))
201 goto end;
202 /* let t = a2 ^ p2 mod m */
203 if (!nuron_mod_exp(&t,a2,p2,m,ctx))
204 goto end;
205 /* let rr = rr * t mod m */
206 if (!BN_mod_mul(rr,rr,&t,m,ctx))
207 goto end;
208 to_return = 1;
209end:
210 BN_free(&t);
211 return to_return;
212 }
213
214
215static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
216 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
217 BN_MONT_CTX *m_ctx)
218 {
219 return nuron_mod_exp(r, a, p, m, ctx);
220 }
221#endif
222
223/* This function is aliased to mod_exp (with the mont stuff dropped). */
224static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
225 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
226 {
227 return nuron_mod_exp(r, a, p, m, ctx);
228 }
229
230#ifndef OPENSSL_NO_DH
231/* This function is aliased to mod_exp (with the dh and mont dropped). */
232static int nuron_mod_exp_dh(const DH *dh, BIGNUM *r,
233 const BIGNUM *a, const BIGNUM *p,
234 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
235 {
236 return nuron_mod_exp(r, a, p, m, ctx);
237 }
238#endif
239
240#ifndef OPENSSL_NO_RSA
241static RSA_METHOD nuron_rsa =
242 {
243 "Nuron RSA method",
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 nuron_rsa_mod_exp,
249 nuron_mod_exp_mont,
250 NULL,
251 NULL,
252 0,
253 NULL,
254 NULL,
255 NULL
256 };
257#endif
258
259#ifndef OPENSSL_NO_DSA
260static DSA_METHOD nuron_dsa =
261 {
262 "Nuron DSA method",
263 NULL, /* dsa_do_sign */
264 NULL, /* dsa_sign_setup */
265 NULL, /* dsa_do_verify */
266 nuron_dsa_mod_exp, /* dsa_mod_exp */
267 nuron_mod_exp_dsa, /* bn_mod_exp */
268 NULL, /* init */
269 NULL, /* finish */
270 0, /* flags */
271 NULL /* app_data */
272 };
273#endif
274
275#ifndef OPENSSL_NO_DH
276static DH_METHOD nuron_dh =
277 {
278 "Nuron DH method",
279 NULL,
280 NULL,
281 nuron_mod_exp_dh,
282 NULL,
283 NULL,
284 0,
285 NULL
286 };
287#endif
288
289/* Constants used when creating the ENGINE */
290static const char *engine_nuron_id = "nuron";
291static const char *engine_nuron_name = "Nuron hardware engine support";
292
293/* This internal function is used by ENGINE_nuron() and possibly by the
294 * "dynamic" ENGINE support too */
295static int bind_helper(ENGINE *e)
296 {
297#ifndef OPENSSL_NO_RSA
298 const RSA_METHOD *meth1;
299#endif
300#ifndef OPENSSL_NO_DSA
301 const DSA_METHOD *meth2;
302#endif
303#ifndef OPENSSL_NO_DH
304 const DH_METHOD *meth3;
305#endif
306 if(!ENGINE_set_id(e, engine_nuron_id) ||
307 !ENGINE_set_name(e, engine_nuron_name) ||
308#ifndef OPENSSL_NO_RSA
309 !ENGINE_set_RSA(e, &nuron_rsa) ||
310#endif
311#ifndef OPENSSL_NO_DSA
312 !ENGINE_set_DSA(e, &nuron_dsa) ||
313#endif
314#ifndef OPENSSL_NO_DH
315 !ENGINE_set_DH(e, &nuron_dh) ||
316#endif
317 !ENGINE_set_destroy_function(e, nuron_destroy) ||
318 !ENGINE_set_init_function(e, nuron_init) ||
319 !ENGINE_set_finish_function(e, nuron_finish) ||
320 !ENGINE_set_ctrl_function(e, nuron_ctrl) ||
321 !ENGINE_set_cmd_defns(e, nuron_cmd_defns))
322 return 0;
323
324#ifndef OPENSSL_NO_RSA
325 /* We know that the "PKCS1_SSLeay()" functions hook properly
326 * to the nuron-specific mod_exp and mod_exp_crt so we use
327 * those functions. NB: We don't use ENGINE_openssl() or
328 * anything "more generic" because something like the RSAref
329 * code may not hook properly, and if you own one of these
330 * cards then you have the right to do RSA operations on it
331 * anyway! */
332 meth1=RSA_PKCS1_SSLeay();
333 nuron_rsa.rsa_pub_enc=meth1->rsa_pub_enc;
334 nuron_rsa.rsa_pub_dec=meth1->rsa_pub_dec;
335 nuron_rsa.rsa_priv_enc=meth1->rsa_priv_enc;
336 nuron_rsa.rsa_priv_dec=meth1->rsa_priv_dec;
337#endif
338
339#ifndef OPENSSL_NO_DSA
340 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
341 * bits. */
342 meth2=DSA_OpenSSL();
343 nuron_dsa.dsa_do_sign=meth2->dsa_do_sign;
344 nuron_dsa.dsa_sign_setup=meth2->dsa_sign_setup;
345 nuron_dsa.dsa_do_verify=meth2->dsa_do_verify;
346#endif
347
348#ifndef OPENSSL_NO_DH
349 /* Much the same for Diffie-Hellman */
350 meth3=DH_OpenSSL();
351 nuron_dh.generate_key=meth3->generate_key;
352 nuron_dh.compute_key=meth3->compute_key;
353#endif
354
355 /* Ensure the nuron error handling is set up */
356 ERR_load_NURON_strings();
357 return 1;
358 }
359
360static ENGINE *engine_nuron(void)
361 {
362 ENGINE *ret = ENGINE_new();
363 if(!ret)
364 return NULL;
365 if(!bind_helper(ret))
366 {
367 ENGINE_free(ret);
368 return NULL;
369 }
370 return ret;
371 }
372
373void ENGINE_load_nuron(void)
374 {
375 /* Copied from eng_[openssl|dyn].c */
376 ENGINE *toadd = engine_nuron();
377 if(!toadd) return;
378 ENGINE_add(toadd);
379 ENGINE_free(toadd);
380 ERR_clear_error();
381 }
382
383/* This stuff is needed if this ENGINE is being compiled into a self-contained
384 * shared-library. */
385#ifdef ENGINE_DYNAMIC_SUPPORT
386static int bind_fn(ENGINE *e, const char *id)
387 {
388 if(id && (strcmp(id, engine_nuron_id) != 0))
389 return 0;
390 if(!bind_helper(e))
391 return 0;
392 return 1;
393 }
394IMPLEMENT_DYNAMIC_CHECK_FN()
395IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
396#endif /* ENGINE_DYNAMIC_SUPPORT */
397
398#endif /* !OPENSSL_NO_HW_NURON */
399#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_nuron_err.c b/src/lib/libssl/src/crypto/engine/hw_nuron_err.c
new file mode 100644
index 0000000000..df9d7bde76
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_nuron_err.c
@@ -0,0 +1,142 @@
1/* hw_nuron_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_nuron_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA NURON_str_functs[]=
68 {
69{ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"},
70{ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"},
71{ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"},
72{ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"},
73{0,NULL}
74 };
75
76static ERR_STRING_DATA NURON_str_reasons[]=
77 {
78{NURON_R_ALREADY_LOADED ,"already loaded"},
79{NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
80{NURON_R_DSO_FAILURE ,"dso failure"},
81{NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"},
82{NURON_R_DSO_NOT_FOUND ,"dso not found"},
83{NURON_R_NOT_LOADED ,"not loaded"},
84{0,NULL}
85 };
86
87#endif
88
89#ifdef NURON_LIB_NAME
90static ERR_STRING_DATA NURON_lib_name[]=
91 {
92{0 ,NURON_LIB_NAME},
93{0,NULL}
94 };
95#endif
96
97
98static int NURON_lib_error_code=0;
99static int NURON_error_init=1;
100
101static void ERR_load_NURON_strings(void)
102 {
103 if (NURON_lib_error_code == 0)
104 NURON_lib_error_code=ERR_get_next_error_library();
105
106 if (NURON_error_init)
107 {
108 NURON_error_init=0;
109#ifndef OPENSSL_NO_ERR
110 ERR_load_strings(NURON_lib_error_code,NURON_str_functs);
111 ERR_load_strings(NURON_lib_error_code,NURON_str_reasons);
112#endif
113
114#ifdef NURON_LIB_NAME
115 NURON_lib_name->error = ERR_PACK(NURON_lib_error_code,0,0);
116 ERR_load_strings(0,NURON_lib_name);
117#endif
118 }
119 }
120
121static void ERR_unload_NURON_strings(void)
122 {
123 if (NURON_error_init == 0)
124 {
125#ifndef OPENSSL_NO_ERR
126 ERR_unload_strings(NURON_lib_error_code,NURON_str_functs);
127 ERR_unload_strings(NURON_lib_error_code,NURON_str_reasons);
128#endif
129
130#ifdef NURON_LIB_NAME
131 ERR_unload_strings(0,NURON_lib_name);
132#endif
133 NURON_error_init=1;
134 }
135 }
136
137static void ERR_NURON_error(int function, int reason, char *file, int line)
138 {
139 if (NURON_lib_error_code == 0)
140 NURON_lib_error_code=ERR_get_next_error_library();
141 ERR_PUT_error(NURON_lib_error_code,function,reason,file,line);
142 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_nuron_err.h b/src/lib/libssl/src/crypto/engine/hw_nuron_err.h
new file mode 100644
index 0000000000..a56bfdf303
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_nuron_err.h
@@ -0,0 +1,86 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_NURON_ERR_H
56#define HEADER_NURON_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_NURON_strings(void);
63static void ERR_unload_NURON_strings(void);
64static void ERR_NURON_error(int function, int reason, char *file, int line);
65#define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the NURON functions. */
68
69/* Function codes. */
70#define NURON_F_NURON_CTRL 100
71#define NURON_F_NURON_FINISH 101
72#define NURON_F_NURON_INIT 102
73#define NURON_F_NURON_MOD_EXP 103
74
75/* Reason codes. */
76#define NURON_R_ALREADY_LOADED 100
77#define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101
78#define NURON_R_DSO_FAILURE 102
79#define NURON_R_DSO_FUNCTION_NOT_FOUND 103
80#define NURON_R_DSO_NOT_FOUND 104
81#define NURON_R_NOT_LOADED 105
82
83#ifdef __cplusplus
84}
85#endif
86#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_sureware_err.c b/src/lib/libssl/src/crypto/engine/hw_sureware_err.c
new file mode 100644
index 0000000000..69955dadbb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_sureware_err.c
@@ -0,0 +1,150 @@
1/* hw_sureware_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_sureware_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA SUREWARE_str_functs[]=
68 {
69{ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"},
70{ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"},
71{ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"},
72{ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"},
73{ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"},
74{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"},
75{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"},
76{ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"},
77{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"},
78{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"},
79{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"},
80{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA SUREWARE_str_reasons[]=
85 {
86{SUREWARE_R_BIO_WAS_FREED ,"bio was freed"},
87{SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{SUREWARE_R_REQUEST_FAILED ,"request failed"},
89{SUREWARE_R_REQUEST_FALLBACK ,"request fallback"},
90{SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
91{SUREWARE_R_UNIT_FAILURE ,"unit failure"},
92{0,NULL}
93 };
94
95#endif
96
97#ifdef SUREWARE_LIB_NAME
98static ERR_STRING_DATA SUREWARE_lib_name[]=
99 {
100{0 ,SUREWARE_LIB_NAME},
101{0,NULL}
102 };
103#endif
104
105
106static int SUREWARE_lib_error_code=0;
107static int SUREWARE_error_init=1;
108
109static void ERR_load_SUREWARE_strings(void)
110 {
111 if (SUREWARE_lib_error_code == 0)
112 SUREWARE_lib_error_code=ERR_get_next_error_library();
113
114 if (SUREWARE_error_init)
115 {
116 SUREWARE_error_init=0;
117#ifndef OPENSSL_NO_ERR
118 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
119 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
120#endif
121
122#ifdef SUREWARE_LIB_NAME
123 SUREWARE_lib_name->error = ERR_PACK(SUREWARE_lib_error_code,0,0);
124 ERR_load_strings(0,SUREWARE_lib_name);
125#endif
126 }
127 }
128
129static void ERR_unload_SUREWARE_strings(void)
130 {
131 if (SUREWARE_error_init == 0)
132 {
133#ifndef OPENSSL_NO_ERR
134 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
135 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
136#endif
137
138#ifdef SUREWARE_LIB_NAME
139 ERR_unload_strings(0,SUREWARE_lib_name);
140#endif
141 SUREWARE_error_init=1;
142 }
143 }
144
145static void ERR_SUREWARE_error(int function, int reason, char *file, int line)
146 {
147 if (SUREWARE_lib_error_code == 0)
148 SUREWARE_lib_error_code=ERR_get_next_error_library();
149 ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line);
150 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_sureware_err.h b/src/lib/libssl/src/crypto/engine/hw_sureware_err.h
new file mode 100644
index 0000000000..bc52af5e05
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_sureware_err.h
@@ -0,0 +1,94 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SUREWARE_ERR_H
56#define HEADER_SUREWARE_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_SUREWARE_strings(void);
63static void ERR_unload_SUREWARE_strings(void);
64static void ERR_SUREWARE_error(int function, int reason, char *file, int line);
65#define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the SUREWARE functions. */
68
69/* Function codes. */
70#define SUREWARE_F_SUREWAREHK_CTRL 100
71#define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101
72#define SUREWARE_F_SUREWAREHK_EX_FREE 102
73#define SUREWARE_F_SUREWAREHK_FINISH 103
74#define SUREWARE_F_SUREWAREHK_INIT 104
75#define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105
76#define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106
77#define SUREWARE_F_SUREWAREHK_MOD_EXP 107
78#define SUREWARE_F_SUREWAREHK_RAND_BYTES 108
79#define SUREWARE_F_SUREWAREHK_RAND_SEED 109
80#define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110
81#define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111
82
83/* Reason codes. */
84#define SUREWARE_R_BIO_WAS_FREED 100
85#define SUREWARE_R_MISSING_KEY_COMPONENTS 105
86#define SUREWARE_R_REQUEST_FAILED 101
87#define SUREWARE_R_REQUEST_FALLBACK 102
88#define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103
89#define SUREWARE_R_UNIT_FAILURE 104
90
91#ifdef __cplusplus
92}
93#endif
94#endif
diff --git a/src/lib/libssl/src/crypto/engine/hw_ubsec.c b/src/lib/libssl/src/crypto/engine/hw_ubsec.c
new file mode 100644
index 0000000000..743c06043c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ubsec.c
@@ -0,0 +1,1041 @@
1/* crypto/engine/hw_ubsec.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 *
5 * Cloned shamelessly by Joe Tardo.
6 */
7/* ====================================================================
8 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * licensing@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60
61#include <stdio.h>
62#include <openssl/crypto.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65#include <openssl/engine.h>
66
67#ifndef OPENSSL_NO_HW
68#ifndef OPENSSL_NO_HW_UBSEC
69
70#ifdef FLAT_INC
71#include "hw_ubsec.h"
72#else
73#include "vendor_defns/hw_ubsec.h"
74#endif
75
76#define UBSEC_LIB_NAME "ubsec engine"
77#include "hw_ubsec_err.c"
78
79#define FAIL_TO_SOFTWARE -15
80
81static int ubsec_destroy(ENGINE *e);
82static int ubsec_init(ENGINE *e);
83static int ubsec_finish(ENGINE *e);
84static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
85static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
86 const BIGNUM *m, BN_CTX *ctx);
87static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
88 const BIGNUM *q, const BIGNUM *dp,
89 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx);
90#ifndef OPENSSL_NO_RSA
91static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
92#endif
93static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
94 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
95#ifndef OPENSSL_NO_DSA
96#if NOT_USED
97static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
98 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
99 BN_CTX *ctx, BN_MONT_CTX *in_mont);
100static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
101 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
102 BN_MONT_CTX *m_ctx);
103#endif
104static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
105static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107#endif
108#ifndef OPENSSL_NO_DH
109static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
110 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
111 BN_MONT_CTX *m_ctx);
112static int ubsec_dh_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
113static int ubsec_dh_generate_key(DH *dh);
114#endif
115
116#if NOT_USED
117static int ubsec_rand_bytes(unsigned char *buf, int num);
118static int ubsec_rand_status(void);
119#endif
120
121#define UBSEC_CMD_SO_PATH ENGINE_CMD_BASE
122static const ENGINE_CMD_DEFN ubsec_cmd_defns[] = {
123 {UBSEC_CMD_SO_PATH,
124 "SO_PATH",
125 "Specifies the path to the 'ubsec' shared library",
126 ENGINE_CMD_FLAG_STRING},
127 {0, NULL, NULL, 0}
128 };
129
130#ifndef OPENSSL_NO_RSA
131/* Our internal RSA_METHOD that we provide pointers to */
132static RSA_METHOD ubsec_rsa =
133 {
134 "UBSEC RSA method",
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 ubsec_rsa_mod_exp,
140 ubsec_mod_exp_mont,
141 NULL,
142 NULL,
143 0,
144 NULL,
145 NULL,
146 NULL
147 };
148#endif
149
150#ifndef OPENSSL_NO_DSA
151/* Our internal DSA_METHOD that we provide pointers to */
152static DSA_METHOD ubsec_dsa =
153 {
154 "UBSEC DSA method",
155 ubsec_dsa_do_sign, /* dsa_do_sign */
156 NULL, /* dsa_sign_setup */
157 ubsec_dsa_verify, /* dsa_do_verify */
158 NULL, /* ubsec_dsa_mod_exp */ /* dsa_mod_exp */
159 NULL, /* ubsec_mod_exp_dsa */ /* bn_mod_exp */
160 NULL, /* init */
161 NULL, /* finish */
162 0, /* flags */
163 NULL /* app_data */
164 };
165#endif
166
167#ifndef OPENSSL_NO_DH
168/* Our internal DH_METHOD that we provide pointers to */
169static DH_METHOD ubsec_dh =
170 {
171 "UBSEC DH method",
172 ubsec_dh_generate_key,
173 ubsec_dh_compute_key,
174 ubsec_mod_exp_dh,
175 NULL,
176 NULL,
177 0,
178 NULL
179 };
180#endif
181
182/* Constants used when creating the ENGINE */
183static const char *engine_ubsec_id = "ubsec";
184static const char *engine_ubsec_name = "UBSEC hardware engine support";
185
186/* This internal function is used by ENGINE_ubsec() and possibly by the
187 * "dynamic" ENGINE support too */
188static int bind_helper(ENGINE *e)
189 {
190#ifndef OPENSSL_NO_RSA
191 const RSA_METHOD *meth1;
192#endif
193#ifndef OPENSSL_NO_DH
194#ifndef HAVE_UBSEC_DH
195 const DH_METHOD *meth3;
196#endif /* HAVE_UBSEC_DH */
197#endif
198 if(!ENGINE_set_id(e, engine_ubsec_id) ||
199 !ENGINE_set_name(e, engine_ubsec_name) ||
200#ifndef OPENSSL_NO_RSA
201 !ENGINE_set_RSA(e, &ubsec_rsa) ||
202#endif
203#ifndef OPENSSL_NO_DSA
204 !ENGINE_set_DSA(e, &ubsec_dsa) ||
205#endif
206#ifndef OPENSSL_NO_DH
207 !ENGINE_set_DH(e, &ubsec_dh) ||
208#endif
209 !ENGINE_set_destroy_function(e, ubsec_destroy) ||
210 !ENGINE_set_init_function(e, ubsec_init) ||
211 !ENGINE_set_finish_function(e, ubsec_finish) ||
212 !ENGINE_set_ctrl_function(e, ubsec_ctrl) ||
213 !ENGINE_set_cmd_defns(e, ubsec_cmd_defns))
214 return 0;
215
216#ifndef OPENSSL_NO_RSA
217 /* We know that the "PKCS1_SSLeay()" functions hook properly
218 * to the Broadcom-specific mod_exp and mod_exp_crt so we use
219 * those functions. NB: We don't use ENGINE_openssl() or
220 * anything "more generic" because something like the RSAref
221 * code may not hook properly, and if you own one of these
222 * cards then you have the right to do RSA operations on it
223 * anyway! */
224 meth1 = RSA_PKCS1_SSLeay();
225 ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
226 ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
227 ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
228 ubsec_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
229#endif
230
231#ifndef OPENSSL_NO_DH
232#ifndef HAVE_UBSEC_DH
233 /* Much the same for Diffie-Hellman */
234 meth3 = DH_OpenSSL();
235 ubsec_dh.generate_key = meth3->generate_key;
236 ubsec_dh.compute_key = meth3->compute_key;
237#endif /* HAVE_UBSEC_DH */
238#endif
239
240 /* Ensure the ubsec error handling is set up */
241 ERR_load_UBSEC_strings();
242 return 1;
243 }
244
245static ENGINE *engine_ubsec(void)
246 {
247 ENGINE *ret = ENGINE_new();
248 if(!ret)
249 return NULL;
250 if(!bind_helper(ret))
251 {
252 ENGINE_free(ret);
253 return NULL;
254 }
255 return ret;
256 }
257
258void ENGINE_load_ubsec(void)
259 {
260 /* Copied from eng_[openssl|dyn].c */
261 ENGINE *toadd = engine_ubsec();
262 if(!toadd) return;
263 ENGINE_add(toadd);
264 ENGINE_free(toadd);
265 ERR_clear_error();
266 }
267
268/* This is a process-global DSO handle used for loading and unloading
269 * the UBSEC library. NB: This is only set (or unset) during an
270 * init() or finish() call (reference counts permitting) and they're
271 * operating with global locks, so this should be thread-safe
272 * implicitly. */
273
274static DSO *ubsec_dso = NULL;
275
276/* These are the function pointers that are (un)set when the library has
277 * successfully (un)loaded. */
278
279static t_UBSEC_ubsec_bytes_to_bits *p_UBSEC_ubsec_bytes_to_bits = NULL;
280static t_UBSEC_ubsec_bits_to_bytes *p_UBSEC_ubsec_bits_to_bytes = NULL;
281static t_UBSEC_ubsec_open *p_UBSEC_ubsec_open = NULL;
282static t_UBSEC_ubsec_close *p_UBSEC_ubsec_close = NULL;
283#ifndef OPENSSL_NO_DH
284static t_UBSEC_diffie_hellman_generate_ioctl
285 *p_UBSEC_diffie_hellman_generate_ioctl = NULL;
286static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL;
287#endif
288/* #ifndef OPENSSL_NO_RSA */
289static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL;
290static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
291/* #endif */
292#ifndef OPENSSL_NO_DSA
293static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL;
294static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL;
295#endif
296static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL;
297static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL;
298static t_UBSEC_max_key_len_ioctl *p_UBSEC_max_key_len_ioctl = NULL;
299
300static int max_key_len = 1024; /* ??? */
301
302/*
303 * These are the static string constants for the DSO file name and the function
304 * symbol names to bind to.
305 */
306
307static const char *UBSEC_LIBNAME = "ubsec";
308static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
309static const char *UBSEC_F2 = "ubsec_bits_to_bytes";
310static const char *UBSEC_F3 = "ubsec_open";
311static const char *UBSEC_F4 = "ubsec_close";
312#ifndef OPENSSL_NO_DH
313static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl";
314static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl";
315#endif
316/* #ifndef OPENSSL_NO_RSA */
317static const char *UBSEC_F7 = "rsa_mod_exp_ioctl";
318static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl";
319/* #endif */
320#ifndef OPENSSL_NO_DSA
321static const char *UBSEC_F9 = "dsa_sign_ioctl";
322static const char *UBSEC_F10 = "dsa_verify_ioctl";
323#endif
324static const char *UBSEC_F11 = "math_accelerate_ioctl";
325static const char *UBSEC_F12 = "rng_ioctl";
326static const char *UBSEC_F13 = "ubsec_max_key_len_ioctl";
327
328/* Destructor (complements the "ENGINE_ubsec()" constructor) */
329static int ubsec_destroy(ENGINE *e)
330 {
331 ERR_unload_UBSEC_strings();
332 return 1;
333 }
334
335/* (de)initialisation functions. */
336static int ubsec_init(ENGINE *e)
337 {
338 t_UBSEC_ubsec_bytes_to_bits *p1;
339 t_UBSEC_ubsec_bits_to_bytes *p2;
340 t_UBSEC_ubsec_open *p3;
341 t_UBSEC_ubsec_close *p4;
342#ifndef OPENSSL_NO_DH
343 t_UBSEC_diffie_hellman_generate_ioctl *p5;
344 t_UBSEC_diffie_hellman_agree_ioctl *p6;
345#endif
346/* #ifndef OPENSSL_NO_RSA */
347 t_UBSEC_rsa_mod_exp_ioctl *p7;
348 t_UBSEC_rsa_mod_exp_crt_ioctl *p8;
349/* #endif */
350#ifndef OPENSSL_NO_DSA
351 t_UBSEC_dsa_sign_ioctl *p9;
352 t_UBSEC_dsa_verify_ioctl *p10;
353#endif
354 t_UBSEC_math_accelerate_ioctl *p11;
355 t_UBSEC_rng_ioctl *p12;
356 t_UBSEC_max_key_len_ioctl *p13;
357 int fd = 0;
358
359 if(ubsec_dso != NULL)
360 {
361 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_ALREADY_LOADED);
362 goto err;
363 }
364 /*
365 * Attempt to load libubsec.so/ubsec.dll/whatever.
366 */
367 ubsec_dso = DSO_load(NULL, UBSEC_LIBNAME, NULL, 0);
368 if(ubsec_dso == NULL)
369 {
370 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
371 goto err;
372 }
373
374 if (
375 !(p1 = (t_UBSEC_ubsec_bytes_to_bits *) DSO_bind_func(ubsec_dso, UBSEC_F1)) ||
376 !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) DSO_bind_func(ubsec_dso, UBSEC_F2)) ||
377 !(p3 = (t_UBSEC_ubsec_open *) DSO_bind_func(ubsec_dso, UBSEC_F3)) ||
378 !(p4 = (t_UBSEC_ubsec_close *) DSO_bind_func(ubsec_dso, UBSEC_F4)) ||
379#ifndef OPENSSL_NO_DH
380 !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *)
381 DSO_bind_func(ubsec_dso, UBSEC_F5)) ||
382 !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *)
383 DSO_bind_func(ubsec_dso, UBSEC_F6)) ||
384#endif
385/* #ifndef OPENSSL_NO_RSA */
386 !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F7)) ||
387 !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F8)) ||
388/* #endif */
389#ifndef OPENSSL_NO_DSA
390 !(p9 = (t_UBSEC_dsa_sign_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F9)) ||
391 !(p10 = (t_UBSEC_dsa_verify_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F10)) ||
392#endif
393 !(p11 = (t_UBSEC_math_accelerate_ioctl *)
394 DSO_bind_func(ubsec_dso, UBSEC_F11)) ||
395 !(p12 = (t_UBSEC_rng_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F12)) ||
396 !(p13 = (t_UBSEC_max_key_len_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F13)))
397 {
398 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
399 goto err;
400 }
401
402 /* Copy the pointers */
403 p_UBSEC_ubsec_bytes_to_bits = p1;
404 p_UBSEC_ubsec_bits_to_bytes = p2;
405 p_UBSEC_ubsec_open = p3;
406 p_UBSEC_ubsec_close = p4;
407#ifndef OPENSSL_NO_DH
408 p_UBSEC_diffie_hellman_generate_ioctl = p5;
409 p_UBSEC_diffie_hellman_agree_ioctl = p6;
410#endif
411#ifndef OPENSSL_NO_RSA
412 p_UBSEC_rsa_mod_exp_ioctl = p7;
413 p_UBSEC_rsa_mod_exp_crt_ioctl = p8;
414#endif
415#ifndef OPENSSL_NO_DSA
416 p_UBSEC_dsa_sign_ioctl = p9;
417 p_UBSEC_dsa_verify_ioctl = p10;
418#endif
419 p_UBSEC_math_accelerate_ioctl = p11;
420 p_UBSEC_rng_ioctl = p12;
421 p_UBSEC_max_key_len_ioctl = p13;
422
423 /* Perform an open to see if there's actually any unit running. */
424 if (((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) > 0) && (p_UBSEC_max_key_len_ioctl(fd, &max_key_len) == 0))
425 {
426 p_UBSEC_ubsec_close(fd);
427 return 1;
428 }
429 else
430 {
431 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
432 }
433
434err:
435 if(ubsec_dso)
436 DSO_free(ubsec_dso);
437 p_UBSEC_ubsec_bytes_to_bits = NULL;
438 p_UBSEC_ubsec_bits_to_bytes = NULL;
439 p_UBSEC_ubsec_open = NULL;
440 p_UBSEC_ubsec_close = NULL;
441#ifndef OPENSSL_NO_DH
442 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
443 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
444#endif
445#ifndef OPENSSL_NO_RSA
446 p_UBSEC_rsa_mod_exp_ioctl = NULL;
447 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
448#endif
449#ifndef OPENSSL_NO_DSA
450 p_UBSEC_dsa_sign_ioctl = NULL;
451 p_UBSEC_dsa_verify_ioctl = NULL;
452#endif
453 p_UBSEC_math_accelerate_ioctl = NULL;
454 p_UBSEC_rng_ioctl = NULL;
455 p_UBSEC_max_key_len_ioctl = NULL;
456
457 return 0;
458 }
459
460static int ubsec_finish(ENGINE *e)
461 {
462 if(ubsec_dso == NULL)
463 {
464 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED);
465 return 0;
466 }
467 if(!DSO_free(ubsec_dso))
468 {
469 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_DSO_FAILURE);
470 return 0;
471 }
472 ubsec_dso = NULL;
473 p_UBSEC_ubsec_bytes_to_bits = NULL;
474 p_UBSEC_ubsec_bits_to_bytes = NULL;
475 p_UBSEC_ubsec_open = NULL;
476 p_UBSEC_ubsec_close = NULL;
477#ifndef OPENSSL_NO_DH
478 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
479 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
480#endif
481#ifndef OPENSSL_NO_RSA
482 p_UBSEC_rsa_mod_exp_ioctl = NULL;
483 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
484#endif
485#ifndef OPENSSL_NO_DSA
486 p_UBSEC_dsa_sign_ioctl = NULL;
487 p_UBSEC_dsa_verify_ioctl = NULL;
488#endif
489 p_UBSEC_math_accelerate_ioctl = NULL;
490 p_UBSEC_rng_ioctl = NULL;
491 p_UBSEC_max_key_len_ioctl = NULL;
492 return 1;
493 }
494
495static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
496 {
497 int initialised = ((ubsec_dso == NULL) ? 0 : 1);
498 switch(cmd)
499 {
500 case UBSEC_CMD_SO_PATH:
501 if(p == NULL)
502 {
503 UBSECerr(UBSEC_F_UBSEC_CTRL,ERR_R_PASSED_NULL_PARAMETER);
504 return 0;
505 }
506 if(initialised)
507 {
508 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED);
509 return 0;
510 }
511 UBSEC_LIBNAME = (const char *)p;
512 return 1;
513 default:
514 break;
515 }
516 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED);
517 return 0;
518 }
519
520static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
521 const BIGNUM *m, BN_CTX *ctx)
522 {
523 int y_len = 0;
524 int fd;
525
526 if(ubsec_dso == NULL)
527 {
528 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_NOT_LOADED);
529 return 0;
530 }
531
532 /* Check if hardware can't handle this argument. */
533 y_len = BN_num_bits(m);
534 if (y_len > max_key_len) {
535 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
536 return BN_mod_exp(r, a, p, m, ctx);
537 }
538
539 if(!bn_wexpand(r, m->top))
540 {
541 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_BN_EXPAND_FAIL);
542 return 0;
543 }
544 memset(r->d, 0, BN_num_bytes(m));
545
546 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
547 fd = 0;
548 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
549 return BN_mod_exp(r, a, p, m, ctx);
550 }
551
552 if (p_UBSEC_rsa_mod_exp_ioctl(fd, (unsigned char *)a->d, BN_num_bits(a),
553 (unsigned char *)m->d, BN_num_bits(m), (unsigned char *)p->d,
554 BN_num_bits(p), (unsigned char *)r->d, &y_len) != 0)
555 {
556 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
557 p_UBSEC_ubsec_close(fd);
558
559 return BN_mod_exp(r, a, p, m, ctx);
560 }
561
562 p_UBSEC_ubsec_close(fd);
563
564 r->top = (BN_num_bits(m)+BN_BITS2-1)/BN_BITS2;
565 return 1;
566 }
567
568#ifndef OPENSSL_NO_RSA
569static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
570 {
571 BN_CTX *ctx;
572 int to_return = 0;
573
574 if((ctx = BN_CTX_new()) == NULL)
575 goto err;
576
577 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
578 {
579 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS);
580 goto err;
581 }
582
583 to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
584 rsa->dmq1, rsa->iqmp, ctx);
585 if (to_return == FAIL_TO_SOFTWARE)
586 {
587 /*
588 * Do in software as hardware failed.
589 */
590 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
591 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
592 }
593err:
594 if(ctx)
595 BN_CTX_free(ctx);
596 return to_return;
597 }
598#endif
599
600static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
601 const BIGNUM *q, const BIGNUM *dp,
602 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx)
603 {
604 int y_len,
605 m_len,
606 fd;
607
608 m_len = BN_num_bytes(p) + BN_num_bytes(q) + 1;
609 y_len = BN_num_bits(p) + BN_num_bits(q);
610
611 /* Check if hardware can't handle this argument. */
612 if (y_len > max_key_len) {
613 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
614 return FAIL_TO_SOFTWARE;
615 }
616
617 if (!bn_wexpand(r, p->top + q->top + 1)) {
618 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT, UBSEC_R_BN_EXPAND_FAIL);
619 return 0;
620 }
621
622 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
623 fd = 0;
624 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
625 return FAIL_TO_SOFTWARE;
626 }
627
628 if (p_UBSEC_rsa_mod_exp_crt_ioctl(fd,
629 (unsigned char *)a->d, BN_num_bits(a),
630 (unsigned char *)qinv->d, BN_num_bits(qinv),
631 (unsigned char *)dp->d, BN_num_bits(dp),
632 (unsigned char *)p->d, BN_num_bits(p),
633 (unsigned char *)dq->d, BN_num_bits(dq),
634 (unsigned char *)q->d, BN_num_bits(q),
635 (unsigned char *)r->d, &y_len) != 0) {
636 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
637 p_UBSEC_ubsec_close(fd);
638 return FAIL_TO_SOFTWARE;
639 }
640
641 p_UBSEC_ubsec_close(fd);
642
643 r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2;
644 return 1;
645}
646
647#ifndef OPENSSL_NO_DSA
648#if NOT_USED
649static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
650 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
651 BN_CTX *ctx, BN_MONT_CTX *in_mont)
652 {
653 BIGNUM t;
654 int to_return = 0;
655
656 BN_init(&t);
657 /* let rr = a1 ^ p1 mod m */
658 if (!ubsec_mod_exp(rr,a1,p1,m,ctx)) goto end;
659 /* let t = a2 ^ p2 mod m */
660 if (!ubsec_mod_exp(&t,a2,p2,m,ctx)) goto end;
661 /* let rr = rr * t mod m */
662 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
663 to_return = 1;
664end:
665 BN_free(&t);
666 return to_return;
667 }
668
669static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
670 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
671 BN_MONT_CTX *m_ctx)
672 {
673 return ubsec_mod_exp(r, a, p, m, ctx);
674 }
675#endif
676#endif
677
678/*
679 * This function is aliased to mod_exp (with the mont stuff dropped).
680 */
681static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
682 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
683 {
684 int ret = 0;
685
686#ifndef OPENSSL_NO_RSA
687 /* Do in software if the key is too large for the hardware. */
688 if (BN_num_bits(m) > max_key_len)
689 {
690 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
691 ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx);
692 }
693 else
694#endif
695 {
696 ret = ubsec_mod_exp(r, a, p, m, ctx);
697 }
698
699 return ret;
700 }
701
702#ifndef OPENSSL_NO_DH
703/* This function is aliased to mod_exp (with the dh and mont dropped). */
704static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
705 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
706 BN_MONT_CTX *m_ctx)
707 {
708 return ubsec_mod_exp(r, a, p, m, ctx);
709 }
710#endif
711
712#ifndef OPENSSL_NO_DSA
713static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
714 {
715 DSA_SIG *to_return = NULL;
716 int s_len = 160, r_len = 160, d_len, fd;
717 BIGNUM m, *r=NULL, *s=NULL;
718
719 BN_init(&m);
720
721 s = BN_new();
722 r = BN_new();
723 if ((s == NULL) || (r==NULL))
724 goto err;
725
726 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dlen);
727
728 if(!bn_wexpand(r, (160+BN_BITS2-1)/BN_BITS2) ||
729 (!bn_wexpand(s, (160+BN_BITS2-1)/BN_BITS2))) {
730 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
731 goto err;
732 }
733
734 if (BN_bin2bn(dgst,dlen,&m) == NULL) {
735 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
736 goto err;
737 }
738
739 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
740 const DSA_METHOD *meth;
741 fd = 0;
742 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
743 meth = DSA_OpenSSL();
744 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
745 goto err;
746 }
747
748 if (p_UBSEC_dsa_sign_ioctl(fd, 0, /* compute hash before signing */
749 (unsigned char *)dgst, d_len,
750 NULL, 0, /* compute random value */
751 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
752 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
753 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
754 (unsigned char *)dsa->priv_key->d, BN_num_bits(dsa->priv_key),
755 (unsigned char *)r->d, &r_len,
756 (unsigned char *)s->d, &s_len ) != 0) {
757 const DSA_METHOD *meth;
758
759 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_REQUEST_FAILED);
760 p_UBSEC_ubsec_close(fd);
761 meth = DSA_OpenSSL();
762 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
763
764 goto err;
765 }
766
767 p_UBSEC_ubsec_close(fd);
768
769 r->top = (160+BN_BITS2-1)/BN_BITS2;
770 s->top = (160+BN_BITS2-1)/BN_BITS2;
771
772 to_return = DSA_SIG_new();
773 if(to_return == NULL) {
774 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
775 goto err;
776 }
777
778 to_return->r = r;
779 to_return->s = s;
780
781err:
782 if (!to_return) {
783 if (r) BN_free(r);
784 if (s) BN_free(s);
785 }
786 BN_clear_free(&m);
787 return to_return;
788}
789
790static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
791 DSA_SIG *sig, DSA *dsa)
792 {
793 int v_len, d_len;
794 int to_return = 0;
795 int fd;
796 BIGNUM v;
797
798 BN_init(&v);
799
800 if(!bn_wexpand(&v, dsa->p->top)) {
801 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY ,UBSEC_R_BN_EXPAND_FAIL);
802 goto err;
803 }
804
805 v_len = BN_num_bits(dsa->p);
806
807 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dgst_len);
808
809 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
810 const DSA_METHOD *meth;
811 fd = 0;
812 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
813 meth = DSA_OpenSSL();
814 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
815 goto err;
816 }
817
818 if (p_UBSEC_dsa_verify_ioctl(fd, 0, /* compute hash before signing */
819 (unsigned char *)dgst, d_len,
820 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
821 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
822 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
823 (unsigned char *)dsa->pub_key->d, BN_num_bits(dsa->pub_key),
824 (unsigned char *)sig->r->d, BN_num_bits(sig->r),
825 (unsigned char *)sig->s->d, BN_num_bits(sig->s),
826 (unsigned char *)v.d, &v_len) != 0) {
827 const DSA_METHOD *meth;
828 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY , UBSEC_R_REQUEST_FAILED);
829 p_UBSEC_ubsec_close(fd);
830
831 meth = DSA_OpenSSL();
832 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
833
834 goto err;
835 }
836
837 p_UBSEC_ubsec_close(fd);
838
839 to_return = 1;
840err:
841 BN_clear_free(&v);
842 return to_return;
843 }
844#endif
845
846#ifndef OPENSSL_NO_DH
847static int ubsec_dh_compute_key (unsigned char *key,const BIGNUM *pub_key,DH *dh)
848 {
849 int ret = -1,
850 k_len,
851 fd;
852
853 k_len = BN_num_bits(dh->p);
854
855 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
856 {
857 const DH_METHOD *meth;
858 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
859 meth = DH_OpenSSL();
860 ret = meth->compute_key(key, pub_key, dh);
861 goto err;
862 }
863
864 if (p_UBSEC_diffie_hellman_agree_ioctl(fd,
865 (unsigned char *)dh->priv_key->d, BN_num_bits(dh->priv_key),
866 (unsigned char *)pub_key->d, BN_num_bits(pub_key),
867 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
868 key, &k_len) != 0)
869 {
870 /* Hardware's a no go, failover to software */
871 const DH_METHOD *meth;
872 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
873 p_UBSEC_ubsec_close(fd);
874
875 meth = DH_OpenSSL();
876 ret = meth->compute_key(key, pub_key, dh);
877
878 goto err;
879 }
880
881 p_UBSEC_ubsec_close(fd);
882
883 ret = p_UBSEC_ubsec_bits_to_bytes(k_len);
884err:
885 return ret;
886 }
887
888static int ubsec_dh_generate_key (DH *dh)
889 {
890 int ret = 0,
891 random_bits = 0,
892 pub_key_len = 0,
893 priv_key_len = 0,
894 fd;
895 BIGNUM *pub_key = NULL;
896 BIGNUM *priv_key = NULL;
897
898 /*
899 * How many bits should Random x be? dh_key.c
900 * sets the range from 0 to num_bits(modulus) ???
901 */
902
903 if (dh->priv_key == NULL)
904 {
905 priv_key = BN_new();
906 if (priv_key == NULL) goto err;
907 priv_key_len = BN_num_bits(dh->p);
908 bn_wexpand(priv_key, dh->p->top);
909 do
910 if (!BN_rand_range(priv_key, dh->p)) goto err;
911 while (BN_is_zero(priv_key));
912 random_bits = BN_num_bits(priv_key);
913 }
914 else
915 {
916 priv_key = dh->priv_key;
917 }
918
919 if (dh->pub_key == NULL)
920 {
921 pub_key = BN_new();
922 pub_key_len = BN_num_bits(dh->p);
923 bn_wexpand(pub_key, dh->p->top);
924 if(pub_key == NULL) goto err;
925 }
926 else
927 {
928 pub_key = dh->pub_key;
929 }
930
931 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
932 {
933 const DH_METHOD *meth;
934 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
935 meth = DH_OpenSSL();
936 ret = meth->generate_key(dh);
937 goto err;
938 }
939
940 if (p_UBSEC_diffie_hellman_generate_ioctl(fd,
941 (unsigned char *)priv_key->d, &priv_key_len,
942 (unsigned char *)pub_key->d, &pub_key_len,
943 (unsigned char *)dh->g->d, BN_num_bits(dh->g),
944 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
945 0, 0, random_bits) != 0)
946 {
947 /* Hardware's a no go, failover to software */
948 const DH_METHOD *meth;
949
950 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
951 p_UBSEC_ubsec_close(fd);
952
953 meth = DH_OpenSSL();
954 ret = meth->generate_key(dh);
955
956 goto err;
957 }
958
959 p_UBSEC_ubsec_close(fd);
960
961 dh->pub_key = pub_key;
962 dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2;
963 dh->priv_key = priv_key;
964 dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2;
965
966 ret = 1;
967err:
968 return ret;
969 }
970#endif
971
972#if NOT_USED
973static int ubsec_rand_bytes(unsigned char * buf,
974 int num)
975 {
976 int ret = 0,
977 fd;
978
979 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
980 {
981 const RAND_METHOD *meth;
982 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
983 num = p_UBSEC_ubsec_bits_to_bytes(num);
984 meth = RAND_SSLeay();
985 meth->seed(buf, num);
986 ret = meth->bytes(buf, num);
987 goto err;
988 }
989
990 num *= 8; /* bytes to bits */
991
992 if (p_UBSEC_rng_ioctl(fd,
993 UBSEC_RNG_DIRECT,
994 buf,
995 &num) != 0)
996 {
997 /* Hardware's a no go, failover to software */
998 const RAND_METHOD *meth;
999
1000 ENGINEerr(UBSEC_F_UBSEC_RNG_BYTES, UBSEC_R_REQUEST_FAILED);
1001 p_UBSEC_ubsec_close(fd);
1002
1003 num = p_UBSEC_ubsec_bits_to_bytes(num);
1004 meth = RAND_SSLeay();
1005 meth->seed(buf, num);
1006 ret = meth->bytes(buf, num);
1007
1008 goto err;
1009 }
1010
1011 p_UBSEC_ubsec_close(fd);
1012
1013 ret = 1;
1014err:
1015 return(ret);
1016 }
1017
1018
1019static int ubsec_rand_status(void)
1020 {
1021 return 0;
1022 }
1023#endif
1024
1025/* This stuff is needed if this ENGINE is being compiled into a self-contained
1026 * shared-library. */
1027#ifdef ENGINE_DYNAMIC_SUPPORT
1028static int bind_fn(ENGINE *e, const char *id)
1029 {
1030 if(id && (strcmp(id, engine_ubsec_id) != 0))
1031 return 0;
1032 if(!bind_helper(e))
1033 return 0;
1034 return 1;
1035 }
1036IMPLEMENT_DYNAMIC_CHECK_FN()
1037IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
1038#endif /* ENGINE_DYNAMIC_SUPPORT */
1039
1040#endif /* !OPENSSL_NO_HW_UBSEC */
1041#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libssl/src/crypto/engine/hw_ubsec_err.c b/src/lib/libssl/src/crypto/engine/hw_ubsec_err.c
new file mode 100644
index 0000000000..d707331fc2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ubsec_err.c
@@ -0,0 +1,151 @@
1/* hw_ubsec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ubsec_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UBSEC_str_functs[]=
68 {
69{ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"},
70{ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"},
71{ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"},
72{ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"},
73{ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"},
74{ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"},
75{ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"},
76{ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"},
77{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"},
78{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA UBSEC_str_reasons[]=
83 {
84{UBSEC_R_ALREADY_LOADED ,"already loaded"},
85{UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{UBSEC_R_DSO_FAILURE ,"dso failure"},
88{UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"},
89{UBSEC_R_NOT_LOADED ,"not loaded"},
90{UBSEC_R_REQUEST_FAILED ,"request failed"},
91{UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
92{UBSEC_R_UNIT_FAILURE ,"unit failure"},
93{0,NULL}
94 };
95
96#endif
97
98#ifdef UBSEC_LIB_NAME
99static ERR_STRING_DATA UBSEC_lib_name[]=
100 {
101{0 ,UBSEC_LIB_NAME},
102{0,NULL}
103 };
104#endif
105
106
107static int UBSEC_lib_error_code=0;
108static int UBSEC_error_init=1;
109
110static void ERR_load_UBSEC_strings(void)
111 {
112 if (UBSEC_lib_error_code == 0)
113 UBSEC_lib_error_code=ERR_get_next_error_library();
114
115 if (UBSEC_error_init)
116 {
117 UBSEC_error_init=0;
118#ifndef OPENSSL_NO_ERR
119 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_functs);
120 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
121#endif
122
123#ifdef UBSEC_LIB_NAME
124 UBSEC_lib_name->error = ERR_PACK(UBSEC_lib_error_code,0,0);
125 ERR_load_strings(0,UBSEC_lib_name);
126#endif
127 }
128 }
129
130static void ERR_unload_UBSEC_strings(void)
131 {
132 if (UBSEC_error_init == 0)
133 {
134#ifndef OPENSSL_NO_ERR
135 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_functs);
136 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
137#endif
138
139#ifdef UBSEC_LIB_NAME
140 ERR_unload_strings(0,UBSEC_lib_name);
141#endif
142 UBSEC_error_init=1;
143 }
144 }
145
146static void ERR_UBSEC_error(int function, int reason, char *file, int line)
147 {
148 if (UBSEC_lib_error_code == 0)
149 UBSEC_lib_error_code=ERR_get_next_error_library();
150 ERR_PUT_error(UBSEC_lib_error_code,function,reason,file,line);
151 }
diff --git a/src/lib/libssl/src/crypto/engine/hw_ubsec_err.h b/src/lib/libssl/src/crypto/engine/hw_ubsec_err.h
new file mode 100644
index 0000000000..023d3be771
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/hw_ubsec_err.h
@@ -0,0 +1,95 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_UBSEC_ERR_H
56#define HEADER_UBSEC_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_UBSEC_strings(void);
63static void ERR_unload_UBSEC_strings(void);
64static void ERR_UBSEC_error(int function, int reason, char *file, int line);
65#define UBSECerr(f,r) ERR_UBSEC_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the UBSEC functions. */
68
69/* Function codes. */
70#define UBSEC_F_UBSEC_CTRL 100
71#define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101
72#define UBSEC_F_UBSEC_DSA_SIGN 102
73#define UBSEC_F_UBSEC_DSA_VERIFY 103
74#define UBSEC_F_UBSEC_FINISH 104
75#define UBSEC_F_UBSEC_INIT 105
76#define UBSEC_F_UBSEC_MOD_EXP 106
77#define UBSEC_F_UBSEC_RNG_BYTES 107
78#define UBSEC_F_UBSEC_RSA_MOD_EXP 108
79#define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109
80
81/* Reason codes. */
82#define UBSEC_R_ALREADY_LOADED 100
83#define UBSEC_R_BN_EXPAND_FAIL 101
84#define UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED 102
85#define UBSEC_R_DSO_FAILURE 103
86#define UBSEC_R_MISSING_KEY_COMPONENTS 104
87#define UBSEC_R_NOT_LOADED 105
88#define UBSEC_R_REQUEST_FAILED 106
89#define UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
90#define UBSEC_R_UNIT_FAILURE 108
91
92#ifdef __cplusplus
93}
94#endif
95#endif
diff --git a/src/lib/libssl/src/crypto/engine/tb_cipher.c b/src/lib/libssl/src/crypto/engine/tb_cipher.c
new file mode 100644
index 0000000000..c5a50fc910
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_cipher.c
@@ -0,0 +1,145 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that
60 * is used by EVP to hook in cipher code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_CIPHER_DEBUG */
63
64static ENGINE_TABLE *cipher_table = NULL;
65
66void ENGINE_unregister_ciphers(ENGINE *e)
67 {
68 engine_table_unregister(&cipher_table, e);
69 }
70
71static void engine_unregister_all_ciphers(void)
72 {
73 engine_table_cleanup(&cipher_table);
74 }
75
76int ENGINE_register_ciphers(ENGINE *e)
77 {
78 if(e->ciphers)
79 {
80 const int *nids;
81 int num_nids = e->ciphers(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&cipher_table,
84 &engine_unregister_all_ciphers, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_ciphers()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_ciphers(e);
96 }
97
98int ENGINE_set_default_ciphers(ENGINE *e)
99 {
100 if(e->ciphers)
101 {
102 const int *nids;
103 int num_nids = e->ciphers(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&cipher_table,
106 &engine_unregister_all_ciphers, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given cipher 'nid' */
115ENGINE *ENGINE_get_cipher_engine(int nid)
116 {
117 return engine_table_select(&cipher_table, nid);
118 }
119
120/* Obtains a cipher implementation from an ENGINE functional reference */
121const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid)
122 {
123 const EVP_CIPHER *ret;
124 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
128 ENGINE_R_UNIMPLEMENTED_CIPHER);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the cipher callback from an ENGINE structure */
135ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e)
136 {
137 return e->ciphers;
138 }
139
140/* Sets the cipher callback in an ENGINE structure */
141int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)
142 {
143 e->ciphers = f;
144 return 1;
145 }
diff --git a/src/lib/libssl/src/crypto/engine/tb_dh.c b/src/lib/libssl/src/crypto/engine/tb_dh.c
new file mode 100644
index 0000000000..c9347235ea
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_dh.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DH(), the function that is
60 * used by DH to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DH_DEBUG */
63
64static ENGINE_TABLE *dh_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DH(ENGINE *e)
68 {
69 engine_table_unregister(&dh_table, e);
70 }
71
72static void engine_unregister_all_DH(void)
73 {
74 engine_table_cleanup(&dh_table);
75 }
76
77int ENGINE_register_DH(ENGINE *e)
78 {
79 if(e->dh_meth)
80 return engine_table_register(&dh_table,
81 &engine_unregister_all_DH, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DH()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DH(e);
91 }
92
93int ENGINE_set_default_DH(ENGINE *e)
94 {
95 if(e->dh_meth)
96 return engine_table_register(&dh_table,
97 &engine_unregister_all_DH, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DH(void)
105 {
106 return engine_table_select(&dh_table, dummy_nid);
107 }
108
109/* Obtains an DH implementation from an ENGINE functional reference */
110const DH_METHOD *ENGINE_get_DH(const ENGINE *e)
111 {
112 return e->dh_meth;
113 }
114
115/* Sets an DH implementation in an ENGINE structure */
116int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
117 {
118 e->dh_meth = dh_meth;
119 return 1;
120 }
diff --git a/src/lib/libssl/src/crypto/engine/tb_digest.c b/src/lib/libssl/src/crypto/engine/tb_digest.c
new file mode 100644
index 0000000000..2c4dd6f796
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_digest.c
@@ -0,0 +1,145 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_digest_engine(), the function that
60 * is used by EVP to hook in digest code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DIGEST_DEBUG */
63
64static ENGINE_TABLE *digest_table = NULL;
65
66void ENGINE_unregister_digests(ENGINE *e)
67 {
68 engine_table_unregister(&digest_table, e);
69 }
70
71static void engine_unregister_all_digests(void)
72 {
73 engine_table_cleanup(&digest_table);
74 }
75
76int ENGINE_register_digests(ENGINE *e)
77 {
78 if(e->digests)
79 {
80 const int *nids;
81 int num_nids = e->digests(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&digest_table,
84 &engine_unregister_all_digests, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_digests()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_digests(e);
96 }
97
98int ENGINE_set_default_digests(ENGINE *e)
99 {
100 if(e->digests)
101 {
102 const int *nids;
103 int num_nids = e->digests(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&digest_table,
106 &engine_unregister_all_digests, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given digest 'nid' */
115ENGINE *ENGINE_get_digest_engine(int nid)
116 {
117 return engine_table_select(&digest_table, nid);
118 }
119
120/* Obtains a digest implementation from an ENGINE functional reference */
121const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid)
122 {
123 const EVP_MD *ret;
124 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST,
128 ENGINE_R_UNIMPLEMENTED_DIGEST);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the digest callback from an ENGINE structure */
135ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e)
136 {
137 return e->digests;
138 }
139
140/* Sets the digest callback in an ENGINE structure */
141int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
142 {
143 e->digests = f;
144 return 1;
145 }
diff --git a/src/lib/libssl/src/crypto/engine/tb_dsa.c b/src/lib/libssl/src/crypto/engine/tb_dsa.c
new file mode 100644
index 0000000000..e9209476b8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_dsa.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
60 * used by DSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DSA_DEBUG */
63
64static ENGINE_TABLE *dsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DSA(ENGINE *e)
68 {
69 engine_table_unregister(&dsa_table, e);
70 }
71
72static void engine_unregister_all_DSA(void)
73 {
74 engine_table_cleanup(&dsa_table);
75 }
76
77int ENGINE_register_DSA(ENGINE *e)
78 {
79 if(e->dsa_meth)
80 return engine_table_register(&dsa_table,
81 &engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DSA(e);
91 }
92
93int ENGINE_set_default_DSA(ENGINE *e)
94 {
95 if(e->dsa_meth)
96 return engine_table_register(&dsa_table,
97 &engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DSA(void)
105 {
106 return engine_table_select(&dsa_table, dummy_nid);
107 }
108
109/* Obtains an DSA implementation from an ENGINE functional reference */
110const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
111 {
112 return e->dsa_meth;
113 }
114
115/* Sets an DSA implementation in an ENGINE structure */
116int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
117 {
118 e->dsa_meth = dsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libssl/src/crypto/engine/tb_rand.c b/src/lib/libssl/src/crypto/engine/tb_rand.c
new file mode 100644
index 0000000000..0b1d031f1e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_rand.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is
60 * used by RAND to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RAND_DEBUG */
63
64static ENGINE_TABLE *rand_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RAND(ENGINE *e)
68 {
69 engine_table_unregister(&rand_table, e);
70 }
71
72static void engine_unregister_all_RAND(void)
73 {
74 engine_table_cleanup(&rand_table);
75 }
76
77int ENGINE_register_RAND(ENGINE *e)
78 {
79 if(e->rand_meth)
80 return engine_table_register(&rand_table,
81 &engine_unregister_all_RAND, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RAND()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RAND(e);
91 }
92
93int ENGINE_set_default_RAND(ENGINE *e)
94 {
95 if(e->rand_meth)
96 return engine_table_register(&rand_table,
97 &engine_unregister_all_RAND, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RAND(void)
105 {
106 return engine_table_select(&rand_table, dummy_nid);
107 }
108
109/* Obtains an RAND implementation from an ENGINE functional reference */
110const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
111 {
112 return e->rand_meth;
113 }
114
115/* Sets an RAND implementation in an ENGINE structure */
116int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
117 {
118 e->rand_meth = rand_meth;
119 return 1;
120 }
diff --git a/src/lib/libssl/src/crypto/engine/tb_rsa.c b/src/lib/libssl/src/crypto/engine/tb_rsa.c
new file mode 100644
index 0000000000..f84fea3968
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/tb_rsa.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is
60 * used by RSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RSA_DEBUG */
63
64static ENGINE_TABLE *rsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RSA(ENGINE *e)
68 {
69 engine_table_unregister(&rsa_table, e);
70 }
71
72static void engine_unregister_all_RSA(void)
73 {
74 engine_table_cleanup(&rsa_table);
75 }
76
77int ENGINE_register_RSA(ENGINE *e)
78 {
79 if(e->rsa_meth)
80 return engine_table_register(&rsa_table,
81 &engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RSA(e);
91 }
92
93int ENGINE_set_default_RSA(ENGINE *e)
94 {
95 if(e->rsa_meth)
96 return engine_table_register(&rsa_table,
97 &engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RSA(void)
105 {
106 return engine_table_select(&rsa_table, dummy_nid);
107 }
108
109/* Obtains an RSA implementation from an ENGINE functional reference */
110const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
111 {
112 return e->rsa_meth;
113 }
114
115/* Sets an RSA implementation in an ENGINE structure */
116int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
117 {
118 e->rsa_meth = rsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libssl/src/crypto/engine/vendor_defns/aep.h b/src/lib/libssl/src/crypto/engine/vendor_defns/aep.h
new file mode 100644
index 0000000000..2b2792d2d6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/vendor_defns/aep.h
@@ -0,0 +1,178 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities, and rnd number generation of the AEP card.
3 *
4 */
5
6/*
7 *
8 * Some AEP defines
9 *
10 */
11
12/*Successful return value*/
13#define AEP_R_OK 0x00000000
14
15/*Miscelleanous unsuccessful return value*/
16#define AEP_R_GENERAL_ERROR 0x10000001
17
18/*Insufficient host memory*/
19#define AEP_R_HOST_MEMORY 0x10000002
20
21#define AEP_R_FUNCTION_FAILED 0x10000006
22
23/*Invalid arguments in function call*/
24#define AEP_R_ARGUMENTS_BAD 0x10020000
25
26#define AEP_R_NO_TARGET_RESOURCES 0x10030000
27
28/*Error occuring on socket operation*/
29#define AEP_R_SOCKERROR 0x10000010
30
31/*Socket has been closed from the other end*/
32#define AEP_R_SOCKEOF 0x10000011
33
34/*Invalid handles*/
35#define AEP_R_CONNECTION_HANDLE_INVALID 0x100000B3
36
37#define AEP_R_TRANSACTION_HANDLE_INVALID 0x10040000
38
39/*Transaction has not yet returned from accelerator*/
40#define AEP_R_TRANSACTION_NOT_READY 0x00010000
41
42/*There is already a thread waiting on this transaction*/
43#define AEP_R_TRANSACTION_CLAIMED 0x10050000
44
45/*The transaction timed out*/
46#define AEP_R_TIMED_OUT 0x10060000
47
48#define AEP_R_FXN_NOT_IMPLEMENTED 0x10070000
49
50#define AEP_R_TARGET_ERROR 0x10080000
51
52/*Error in the AEP daemon process*/
53#define AEP_R_DAEMON_ERROR 0x10090000
54
55/*Invalid ctx id*/
56#define AEP_R_INVALID_CTX_ID 0x10009000
57
58#define AEP_R_NO_KEY_MANAGER 0x1000a000
59
60/*Error obtaining a mutex*/
61#define AEP_R_MUTEX_BAD 0x000001A0
62
63/*Fxn call before AEP_Initialise ot after AEP_Finialise*/
64#define AEP_R_AEPAPI_NOT_INITIALIZED 0x10000190
65
66/*AEP_Initialise has already been called*/
67#define AEP_R_AEPAPI_ALREADY_INITIALIZED 0x10000191
68
69/*Maximum number of connections to daemon reached*/
70#define AEP_R_NO_MORE_CONNECTION_HNDLS 0x10000200
71
72/*
73 *
74 * Some AEP Type definitions
75 *
76 */
77
78/* an unsigned 8-bit value */
79typedef unsigned char AEP_U8;
80
81/* an unsigned 8-bit character */
82typedef char AEP_CHAR;
83
84/* a BYTE-sized Boolean flag */
85typedef AEP_U8 AEP_BBOOL;
86
87/*Unsigned value, at least 16 bits long*/
88typedef unsigned short AEP_U16;
89
90/* an unsigned value, at least 32 bits long */
91#ifdef SIXTY_FOUR_BIT_LONG
92typedef unsigned int AEP_U32;
93#else
94typedef unsigned long AEP_U32;
95#endif
96
97#ifdef SIXTY_FOUR_BIT_LONG
98typedef unsigned long AEP_U64;
99#else
100typedef struct { unsigned long l1, l2; } AEP_U64;
101#endif
102
103/* at least 32 bits; each bit is a Boolean flag */
104typedef AEP_U32 AEP_FLAGS;
105
106typedef AEP_U8 *AEP_U8_PTR;
107typedef AEP_CHAR *AEP_CHAR_PTR;
108typedef AEP_U32 *AEP_U32_PTR;
109typedef AEP_U64 *AEP_U64_PTR;
110typedef void *AEP_VOID_PTR;
111
112/* Pointer to a AEP_VOID_PTR-- i.e., pointer to pointer to void */
113typedef AEP_VOID_PTR *AEP_VOID_PTR_PTR;
114
115/*Used to identify an AEP connection handle*/
116typedef AEP_U32 AEP_CONNECTION_HNDL;
117
118/*Pointer to an AEP connection handle*/
119typedef AEP_CONNECTION_HNDL *AEP_CONNECTION_HNDL_PTR;
120
121/*Used by an application (in conjunction with the apps process id) to
122identify an individual transaction*/
123typedef AEP_U32 AEP_TRANSACTION_ID;
124
125/*Pointer to an applications transaction identifier*/
126typedef AEP_TRANSACTION_ID *AEP_TRANSACTION_ID_PTR;
127
128/*Return value type*/
129typedef AEP_U32 AEP_RV;
130
131#define MAX_PROCESS_CONNECTIONS 256
132
133#define RAND_BLK_SIZE 1024
134
135typedef enum{
136 NotConnected= 0,
137 Connected= 1,
138 InUse= 2
139} AEP_CONNECTION_STATE;
140
141
142typedef struct AEP_CONNECTION_ENTRY{
143 AEP_CONNECTION_STATE conn_state;
144 AEP_CONNECTION_HNDL conn_hndl;
145} AEP_CONNECTION_ENTRY;
146
147
148typedef AEP_RV t_AEP_OpenConnection(AEP_CONNECTION_HNDL_PTR phConnection);
149typedef AEP_RV t_AEP_CloseConnection(AEP_CONNECTION_HNDL hConnection);
150
151typedef AEP_RV t_AEP_ModExp(AEP_CONNECTION_HNDL hConnection,
152 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
153 AEP_VOID_PTR pN,
154 AEP_VOID_PTR pResult,
155 AEP_TRANSACTION_ID* pidTransID);
156
157typedef AEP_RV t_AEP_ModExpCrt(AEP_CONNECTION_HNDL hConnection,
158 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
159 AEP_VOID_PTR pQ,
160 AEP_VOID_PTR pDmp1, AEP_VOID_PTR pDmq1,
161 AEP_VOID_PTR pIqmp,
162 AEP_VOID_PTR pResult,
163 AEP_TRANSACTION_ID* pidTransID);
164
165#ifdef AEPRAND
166typedef AEP_RV t_AEP_GenRandom(AEP_CONNECTION_HNDL hConnection,
167 AEP_U32 Len,
168 AEP_U32 Type,
169 AEP_VOID_PTR pResult,
170 AEP_TRANSACTION_ID* pidTransID);
171#endif
172
173typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs);
174typedef AEP_RV t_AEP_Finalize();
175typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(),
176 AEP_RV (*MakeAEPBigNumFunc)(),
177 AEP_RV (*ConverAEPBigNumFunc)());
178
diff --git a/src/lib/libssl/src/crypto/engine/vendor_defns/atalla.h b/src/lib/libssl/src/crypto/engine/vendor_defns/atalla.h
new file mode 100644
index 0000000000..8111649c54
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/vendor_defns/atalla.h
@@ -0,0 +1,61 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities of Atalla cards. The only cryptographic operation
3 * is performed by "ASI_RSAPrivateKeyOpFn" and this takes a structure that
4 * defines an "RSA private key". However, it is really only performing a
5 * regular mod_exp using the supplied modulus and exponent - no CRT form is
6 * being used. Hence, it is a generic mod_exp function in disguise, and we use
7 * it as such.
8 *
9 * Thanks to the people at Atalla for letting me know these definitions are
10 * fine and that they can be reproduced here.
11 *
12 * Geoff.
13 */
14
15typedef struct ItemStr
16 {
17 unsigned char *data;
18 int len;
19 } Item;
20
21typedef struct RSAPrivateKeyStr
22 {
23 void *reserved;
24 Item version;
25 Item modulus;
26 Item publicExponent;
27 Item privateExponent;
28 Item prime[2];
29 Item exponent[2];
30 Item coefficient;
31 } RSAPrivateKey;
32
33/* Predeclare the function pointer types that we dynamically load from the DSO.
34 * These use the same names and form that Ben's original support code had (in
35 * crypto/bn/bn_exp.c) unless of course I've inadvertently changed the style
36 * somewhere along the way!
37 */
38
39typedef int tfnASI_GetPerformanceStatistics(int reset_flag,
40 unsigned int *ret_buf);
41
42typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf);
43
44typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey,
45 unsigned char *output,
46 unsigned char *input,
47 unsigned int modulus_len);
48
49/* These are the static string constants for the DSO file name and the function
50 * symbol names to bind to. Regrettably, the DSO name on *nix appears to be
51 * "atasi.so" rather than something more consistent like "libatasi.so". At the
52 * time of writing, I'm not sure what the file name on win32 is but clearly
53 * native name translation is not possible (eg libatasi.so on *nix, and
54 * atasi.dll on win32). For the purposes of testing, I have created a symbollic
55 * link called "libatasi.so" so that we can use native name-translation - a
56 * better solution will be needed. */
57static const char *ATALLA_LIBNAME = "atasi";
58static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
59static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
60static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
61
diff --git a/src/lib/libssl/src/crypto/engine/vendor_defns/cswift.h b/src/lib/libssl/src/crypto/engine/vendor_defns/cswift.h
new file mode 100644
index 0000000000..0af14a1a92
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/vendor_defns/cswift.h
@@ -0,0 +1,213 @@
1/* Attribution notice: Rainbow have generously allowed me to reproduce
2 * the necessary definitions here from their API. This means the support
3 * can build independently of whether application builders have the
4 * API or hardware. This will allow developers to easily produce software
5 * that has latent hardware support for any users that have accelertors
6 * installed, without the developers themselves needing anything extra.
7 *
8 * I have only clipped the parts from the CryptoSwift header files that
9 * are (or seem) relevant to the CryptoSwift support code. This is
10 * simply to keep the file sizes reasonable.
11 * [Geoff]
12 */
13
14
15/* NB: These type widths do *not* seem right in general, in particular
16 * they're not terribly friendly to 64-bit architectures (unsigned long)
17 * will be 64-bit on IA-64 for a start. I'm leaving these alone as they
18 * agree with Rainbow's API and this will only be called into question
19 * on platforms with Rainbow support anyway! ;-) */
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25typedef long SW_STATUS; /* status */
26typedef unsigned char SW_BYTE; /* 8 bit byte */
27typedef unsigned short SW_U16; /* 16 bit number */
28#if defined(_IRIX)
29#include <sgidefs.h>
30typedef __uint32_t SW_U32;
31#else
32typedef unsigned long SW_U32; /* 32 bit integer */
33#endif
34
35#if defined(WIN32)
36 typedef struct _SW_U64 {
37 SW_U32 low32;
38 SW_U32 high32;
39 } SW_U64; /* 64 bit integer */
40#elif defined(MAC)
41 typedef longlong SW_U64
42#else /* Unix variants */
43 typedef struct _SW_U64 {
44 SW_U32 low32;
45 SW_U32 high32;
46 } SW_U64; /* 64 bit integer */
47#endif
48
49/* status codes */
50#define SW_OK (0L)
51#define SW_ERR_BASE (-10000L)
52#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */
53#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */
54 /* up yet */
55#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */
56 /* time out */
57#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */
58 /* execute the command */
59#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */
60 /* NULL */
61#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */
62 /* small, too large. */
63#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */
64 /* handle */
65#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */
66 /* standing at this */
67 /* context handle */
68#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */
69#define SW_ERR_NO_PENDING (SW_ERR_BASE-10)/* No request is pending. */
70#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11)/* Not enough memory */
71#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12)/* Invalid algorithm type */
72 /* in SW_PARAM structure */
73#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13)/* No key is associated with */
74 /* context. */
75 /* swAttachKeyParam() is */
76 /* not called. */
77#define SW_ERR_KEY_CMD_MISMATCH \
78 (SW_ERR_BASE-14)/* Cannot perform requested */
79 /* SW_COMMAND_CODE since */
80 /* key attached via */
81 /* swAttachKeyParam() */
82 /* cannot be used for this*/
83 /* SW_COMMAND_CODE. */
84#define SW_ERR_NOT_IMPLEMENTED \
85 (SW_ERR_BASE-15)/* Not implemented */
86#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16)/* Bad command code */
87#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17)/* too small or too large in */
88 /* the "initems" or */
89 /* "outitems". */
90#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18)/* Bad accelerator number */
91#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19)/* At least one of the self */
92 /* test fail, look at the */
93 /* selfTestBitmap in */
94 /* SW_ACCELERATOR_INFO for*/
95 /* details. */
96#define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/
97 /* key materials aligned */
98 /* in certain order, e.g. */
99 /* 128 bit for CRT */
100#define SW_ERR_OUTPUT_NULL_PTR \
101 (SW_ERR_BASE-21)/* a required pointer is */
102 /* NULL */
103#define SW_ERR_OUTPUT_SIZE \
104 (SW_ERR_BASE-22)/* size is invalid, too */
105 /* small, too large. */
106#define SW_ERR_FIRMWARE_CHECKSUM \
107 (SW_ERR_BASE-23)/* firmware checksum mismatch*/
108 /* download failed. */
109#define SW_ERR_UNKNOWN_FIRMWARE \
110 (SW_ERR_BASE-24)/* unknown firmware error */
111#define SW_ERR_INTERRUPT (SW_ERR_BASE-25)/* request is abort when */
112 /* it's waiting to be */
113 /* completed. */
114#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26)/* error in writing to Non- */
115 /* volatile memory */
116#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27)/* out of range error in */
117 /* writing to NV memory */
118#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28)/* Random Number Generation */
119 /* failure */
120#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29)/* DSS Sign or Verify failure*/
121#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30)/* Failure in various math */
122 /* calculations */
123#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */
124 /* board memory */
125#define SW_ERR_FIRMWARE_VERSION \
126 (SW_ERR_BASE-32)/* Wrong version in firmware */
127 /* update */
128#define SW_ERR_ZERO_WORKING_ACCELERATOR \
129 (SW_ERR_BASE-44)/* All accelerators are bad */
130
131
132 /* algorithm type */
133#define SW_ALG_CRT 1
134#define SW_ALG_EXP 2
135#define SW_ALG_DSA 3
136#define SW_ALG_NVDATA 4
137
138 /* command code */
139#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */
140 /* Chinese Remainder Theorem (CRT) */
141#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */
142#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */
143#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */
144#define SW_CMD_RAND 5 /* perform random number generation */
145#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */
146#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */
147
148typedef SW_U32 SW_ALGTYPE; /* alogrithm type */
149typedef SW_U32 SW_STATE; /* state */
150typedef SW_U32 SW_COMMAND_CODE; /* command code */
151typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */
152
153typedef struct _SW_LARGENUMBER {
154 SW_U32 nbytes; /* number of bytes in the buffer "value" */
155 SW_BYTE* value; /* the large integer as a string of */
156 /* bytes in network (big endian) order */
157} SW_LARGENUMBER;
158
159typedef struct _SW_CRT {
160 SW_LARGENUMBER p; /* prime number p */
161 SW_LARGENUMBER q; /* prime number q */
162 SW_LARGENUMBER dmp1; /* exponent1 */
163 SW_LARGENUMBER dmq1; /* exponent2 */
164 SW_LARGENUMBER iqmp; /* CRT coefficient */
165} SW_CRT;
166
167typedef struct _SW_EXP {
168 SW_LARGENUMBER modulus; /* modulus */
169 SW_LARGENUMBER exponent;/* exponent */
170} SW_EXP;
171
172typedef struct _SW_DSA {
173 SW_LARGENUMBER p; /* */
174 SW_LARGENUMBER q; /* */
175 SW_LARGENUMBER g; /* */
176 SW_LARGENUMBER key; /* private/public key */
177} SW_DSA;
178
179typedef struct _SW_NVDATA {
180 SW_U32 accnum; /* accelerator board number */
181 SW_U32 offset; /* offset in byte */
182} SW_NVDATA;
183
184typedef struct _SW_PARAM {
185 SW_ALGTYPE type; /* type of the alogrithm */
186 union {
187 SW_CRT crt;
188 SW_EXP exp;
189 SW_DSA dsa;
190 SW_NVDATA nvdata;
191 } up;
192} SW_PARAM;
193
194typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */
195
196
197/* Now the OpenSSL bits, these function types are the for the function
198 * pointers that will bound into the Rainbow shared libraries. */
199typedef SW_STATUS t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac);
200typedef SW_STATUS t_swAttachKeyParam(SW_CONTEXT_HANDLE hac,
201 SW_PARAM *key_params);
202typedef SW_STATUS t_swSimpleRequest(SW_CONTEXT_HANDLE hac,
203 SW_COMMAND_CODE cmd,
204 SW_LARGENUMBER pin[],
205 SW_U32 pin_count,
206 SW_LARGENUMBER pout[],
207 SW_U32 pout_count);
208typedef SW_STATUS t_swReleaseAccContext(SW_CONTEXT_HANDLE hac);
209
210#ifdef __cplusplus
211}
212#endif /* __cplusplus */
213
diff --git a/src/lib/libssl/src/crypto/engine/vendor_defns/hw_4758_cca.h b/src/lib/libssl/src/crypto/engine/vendor_defns/hw_4758_cca.h
new file mode 100644
index 0000000000..296636e81a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/engine/vendor_defns/hw_4758_cca.h
@@ -0,0 +1,149 @@
1/**********************************************************************/
2/* */
3/* Prototypes of the CCA verbs used by the 4758 CCA openssl driver */
4/* */
5/* Maurice Gittens <maurice@gittens.nl> */
6/* */
7/**********************************************************************/
8
9#ifndef __HW_4758_CCA__
10#define __HW_4758_CCA__
11
12/*
13 * Only WIN32 support for now
14 */
15#if defined(WIN32)
16
17 #define CCA_LIB_NAME "CSUNSAPI"
18
19 #define CSNDPKX "CSNDPKX_32"
20 #define CSNDKRR "CSNDKRR_32"
21 #define CSNDPKE "CSNDPKE_32"
22 #define CSNDPKD "CSNDPKD_32"
23 #define CSNDDSV "CSNDDSV_32"
24 #define CSNDDSG "CSNDDSG_32"
25 #define CSNBRNG "CSNBRNG_32"
26
27 #define SECURITYAPI __stdcall
28#else
29 /* Fixme!!
30 Find out the values of these constants for other platforms.
31 */
32 #define CCA_LIB_NAME "CSUNSAPI"
33
34 #define CSNDPKX "CSNDPKX"
35 #define CSNDKRR "CSNDKRR"
36 #define CSNDPKE "CSNDPKE"
37 #define CSNDPKD "CSNDPKD"
38 #define CSNDDSV "CSNDDSV"
39 #define CSNDDSG "CSNDDSG"
40 #define CSNBRNG "CSNBRNG"
41
42 #define SECURITYAPI
43#endif
44
45/*
46 * security API prototypes
47 */
48
49/* PKA Key Record Read */
50typedef void (SECURITYAPI *F_KEYRECORDREAD)
51 (long * return_code,
52 long * reason_code,
53 long * exit_data_length,
54 unsigned char * exit_data,
55 long * rule_array_count,
56 unsigned char * rule_array,
57 unsigned char * key_label,
58 long * key_token_length,
59 unsigned char * key_token);
60
61/* Random Number Generate */
62typedef void (SECURITYAPI *F_RANDOMNUMBERGENERATE)
63 (long * return_code,
64 long * reason_code,
65 long * exit_data_length,
66 unsigned char * exit_data,
67 unsigned char * form,
68 unsigned char * random_number);
69
70/* Digital Signature Generate */
71typedef void (SECURITYAPI *F_DIGITALSIGNATUREGENERATE)
72 (long * return_code,
73 long * reason_code,
74 long * exit_data_length,
75 unsigned char * exit_data,
76 long * rule_array_count,
77 unsigned char * rule_array,
78 long * PKA_private_key_id_length,
79 unsigned char * PKA_private_key_id,
80 long * hash_length,
81 unsigned char * hash,
82 long * signature_field_length,
83 long * signature_bit_length,
84 unsigned char * signature_field);
85
86/* Digital Signature Verify */
87typedef void (SECURITYAPI *F_DIGITALSIGNATUREVERIFY)(
88 long * return_code,
89 long * reason_code,
90 long * exit_data_length,
91 unsigned char * exit_data,
92 long * rule_array_count,
93 unsigned char * rule_array,
94 long * PKA_public_key_id_length,
95 unsigned char * PKA_public_key_id,
96 long * hash_length,
97 unsigned char * hash,
98 long * signature_field_length,
99 unsigned char * signature_field);
100
101/* PKA Public Key Extract */
102typedef void (SECURITYAPI *F_PUBLICKEYEXTRACT)(
103 long * return_code,
104 long * reason_code,
105 long * exit_data_length,
106 unsigned char * exit_data,
107 long * rule_array_count,
108 unsigned char * rule_array,
109 long * source_key_identifier_length,
110 unsigned char * source_key_identifier,
111 long * target_key_token_length,
112 unsigned char * target_key_token);
113
114/* PKA Encrypt */
115typedef void (SECURITYAPI *F_PKAENCRYPT)
116 (long * return_code,
117 long * reason_code,
118 long * exit_data_length,
119 unsigned char * exit_data,
120 long * rule_array_count,
121 unsigned char * rule_array,
122 long * key_value_length,
123 unsigned char * key_value,
124 long * data_struct_length,
125 unsigned char * data_struct,
126 long * RSA_public_key_length,
127 unsigned char * RSA_public_key,
128 long * RSA_encipher_length,
129 unsigned char * RSA_encipher );
130
131/* PKA Decrypt */
132typedef void (SECURITYAPI *F_PKADECRYPT)
133 (long * return_code,
134 long * reason_code,
135 long * exit_data_length,
136 unsigned char * exit_data,
137 long * rule_array_count,
138 unsigned char * rule_array,
139 long * enciphered_key_length,
140 unsigned char * enciphered_key,
141 long * data_struct_length,
142 unsigned char * data_struct,
143 long * RSA_private_key_length,
144 unsigned char * RSA_private_key,
145 long * key_value_length,
146 unsigned char * key_value );
147
148
149#endif
diff --git a/src/lib/libssl/src/crypto/err/openssl.ec b/src/lib/libssl/src/crypto/err/openssl.ec
new file mode 100644
index 0000000000..c2a8acff0c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/err/openssl.ec
@@ -0,0 +1,71 @@
1L ERR NONE NONE
2L CRYPTO crypto/crypto.h crypto/cpt_err.c
3L BN crypto/bn/bn.h crypto/bn/bn_err.c
4L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
5L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
6L DH crypto/dh/dh.h crypto/dh/dh_err.c
7L EVP crypto/evp/evp.h crypto/evp/evp_err.c
8L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
9L BIO crypto/bio/bio.h crypto/bio/bio_err.c
10L OBJ crypto/objects/objects.h crypto/objects/obj_err.c
11L PEM crypto/pem/pem.h crypto/pem/pem_err.c
12L X509 crypto/x509/x509.h crypto/x509/x509_err.c
13L NONE crypto/x509/x509_vfy.h NONE
14L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c
15#L METH crypto/meth/meth.h crypto/meth/meth_err.c
16L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c
17L CONF crypto/conf/conf.h crypto/conf/conf_err.c
18#L PROXY crypto/proxy/proxy.h crypto/proxy/proxy_err.c
19L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c
20L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
21L RSAREF rsaref/rsaref.h rsaref/rsar_err.c
22L SSL ssl/ssl.h ssl/ssl_err.c
23L COMP crypto/comp/comp.h crypto/comp/comp_err.c
24
25
26F RSAREF_F_RSA_BN2BIN
27F RSAREF_F_RSA_PRIVATE_DECRYPT
28F RSAREF_F_RSA_PRIVATE_ENCRYPT
29F RSAREF_F_RSA_PUBLIC_DECRYPT
30F RSAREF_F_RSA_PUBLIC_ENCRYPT
31#F SSL_F_CLIENT_CERTIFICATE
32
33R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
34R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
35R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
36R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
37R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
38R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
39R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
40R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
41R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
42R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
43R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
44R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
45R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
46R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
47R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
48R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
49R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
50R SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060
51R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
52R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
53R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
54R SSL_R_TLSV1_ALERT_USER_CANCLED 1090
55R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
56
57R RSAREF_R_CONTENT_ENCODING 0x0400
58R RSAREF_R_DATA 0x0401
59R RSAREF_R_DIGEST_ALGORITHM 0x0402
60R RSAREF_R_ENCODING 0x0403
61R RSAREF_R_KEY 0x0404
62R RSAREF_R_KEY_ENCODING 0x0405
63R RSAREF_R_LEN 0x0406
64R RSAREF_R_MODULUS_LEN 0x0407
65R RSAREF_R_NEED_RANDOM 0x0408
66R RSAREF_R_PRIVATE_KEY 0x0409
67R RSAREF_R_PUBLIC_KEY 0x040a
68R RSAREF_R_SIGNATURE 0x040b
69R RSAREF_R_SIGNATURE_ENCODING 0x040c
70R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
71
diff --git a/src/lib/libssl/src/crypto/evp/bio_ok.c b/src/lib/libssl/src/crypto/evp/bio_ok.c
new file mode 100644
index 0000000000..101275d648
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/bio_ok.c
@@ -0,0 +1,552 @@
1/* crypto/evp/bio_ok.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 From: Arne Ansper <arne@cyber.ee>
61
62 Why BIO_f_reliable?
63
64 I wrote function which took BIO* as argument, read data from it
65 and processed it. Then I wanted to store the input file in
66 encrypted form. OK I pushed BIO_f_cipher to the BIO stack
67 and everything was OK. BUT if user types wrong password
68 BIO_f_cipher outputs only garbage and my function crashes. Yes
69 I can and I should fix my function, but BIO_f_cipher is
70 easy way to add encryption support to many exisiting applications
71 and it's hard to debug and fix them all.
72
73 So I wanted another BIO which would catch the incorrect passwords and
74 file damages which cause garbage on BIO_f_cipher's output.
75
76 The easy way is to push the BIO_f_md and save the checksum at
77 the end of the file. However there are several problems with this
78 approach:
79
80 1) you must somehow separate checksum from actual data.
81 2) you need lot's of memory when reading the file, because you
82 must read to the end of the file and verify the checksum before
83 leting the application to read the data.
84
85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitraly long streams using only fixed amount
87 of memory.
88
89 BIO_f_reliable splits data stream into blocks. Each block is prefixed
90 with it's length and suffixed with it's digest. So you need only
91 several Kbytes of memory to buffer single block before verifying
92 it's digest.
93
94 BIO_f_reliable goes futher and adds several important capabilities:
95
96 1) the digest of the block is computed over the whole stream
97 -- so nobody can rearrange the blocks or remove or replace them.
98
99 2) to detect invalid passwords right at the start BIO_f_reliable
100 adds special prefix to the stream. In order to avoid known plain-text
101 attacks this prefix is generated as follows:
102
103 *) digest is initialized with random seed instead of
104 standardized one.
105 *) same seed is written to ouput
106 *) well-known text is then hashed and the output
107 of the digest is also written to output.
108
109 reader can now read the seed from stream, hash the same string
110 and then compare the digest output.
111
112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
113 initialy wrote and tested this code on x86 machine and wrote the
114 digests out in machine-dependent order :( There are people using
115 this code and I cannot change this easily without making existing
116 data files unreadable.
117
118*/
119
120#include <stdio.h>
121#include <errno.h>
122#include "cryptlib.h"
123#include <openssl/buffer.h>
124#include <openssl/bio.h>
125#include <openssl/evp.h>
126#include <openssl/rand.h>
127
128static int ok_write(BIO *h,char *buf,int num);
129static int ok_read(BIO *h,char *buf,int size);
130static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2);
131static int ok_new(BIO *h);
132static int ok_free(BIO *data);
133static void sig_out(BIO* b);
134static void sig_in(BIO* b);
135static void block_out(BIO* b);
136static void block_in(BIO* b);
137#define OK_BLOCK_SIZE (1024*4)
138#define OK_BLOCK_BLOCK 4
139#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
140#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
141
142#ifndef L_ENDIAN
143#define swapem(x) \
144 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
145 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
146 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
147 (((unsigned long int)(x) & 0xff000000U) >> 24)))
148#else
149#define swapem(x) (x)
150#endif
151
152typedef struct ok_struct
153 {
154 int buf_len;
155 int buf_off;
156 int buf_len_save;
157 int buf_off_save;
158 int cont; /* <= 0 when finished */
159 int finished;
160 EVP_MD_CTX md;
161 int blockout; /* output block is ready */
162 int sigio; /* must process signature */
163 char buf[IOBS];
164 } BIO_OK_CTX;
165
166static BIO_METHOD methods_ok=
167 {
168 BIO_TYPE_CIPHER,"reliable",
169 ok_write,
170 ok_read,
171 NULL, /* ok_puts, */
172 NULL, /* ok_gets, */
173 ok_ctrl,
174 ok_new,
175 ok_free,
176 };
177
178BIO_METHOD *BIO_f_reliable(void)
179 {
180 return(&methods_ok);
181 }
182
183static int ok_new(BIO *bi)
184 {
185 BIO_OK_CTX *ctx;
186
187 ctx=(BIO_OK_CTX *)Malloc(sizeof(BIO_OK_CTX));
188 if (ctx == NULL) return(0);
189
190 ctx->buf_len=0;
191 ctx->buf_off=0;
192 ctx->buf_len_save=0;
193 ctx->buf_off_save=0;
194 ctx->cont=1;
195 ctx->finished=0;
196 ctx->blockout= 0;
197 ctx->sigio=1;
198
199 bi->init=0;
200 bi->ptr=(char *)ctx;
201 bi->flags=0;
202 return(1);
203 }
204
205static int ok_free(BIO *a)
206 {
207 if (a == NULL) return(0);
208 memset(a->ptr,0,sizeof(BIO_OK_CTX));
209 Free(a->ptr);
210 a->ptr=NULL;
211 a->init=0;
212 a->flags=0;
213 return(1);
214 }
215
216static int ok_read(BIO *b, char *out, int outl)
217 {
218 int ret=0,i,n;
219 BIO_OK_CTX *ctx;
220
221 if (out == NULL) return(0);
222 ctx=(BIO_OK_CTX *)b->ptr;
223
224 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
225
226 while(outl > 0)
227 {
228
229 /* copy clean bytes to output buffer */
230 if (ctx->blockout)
231 {
232 i=ctx->buf_len-ctx->buf_off;
233 if (i > outl) i=outl;
234 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
235 ret+=i;
236 out+=i;
237 outl-=i;
238 ctx->buf_off+=i;
239
240 /* all clean bytes are out */
241 if (ctx->buf_len == ctx->buf_off)
242 {
243 ctx->buf_off=0;
244
245 /* copy start of the next block into proper place */
246 if(ctx->buf_len_save- ctx->buf_off_save > 0)
247 {
248 ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
249 memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
250 ctx->buf_len);
251 }
252 else
253 {
254 ctx->buf_len=0;
255 }
256 ctx->blockout= 0;
257 }
258 }
259
260 /* output buffer full -- cancel */
261 if (outl == 0) break;
262
263 /* no clean bytes in buffer -- fill it */
264 n=IOBS- ctx->buf_len;
265 i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
266
267 if (i <= 0) break; /* nothing new */
268
269 ctx->buf_len+= i;
270
271 /* no signature yet -- check if we got one */
272 if (ctx->sigio == 1) sig_in(b);
273
274 /* signature ok -- check if we got block */
275 if (ctx->sigio == 0) block_in(b);
276
277 /* invalid block -- cancel */
278 if (ctx->cont <= 0) break;
279
280 }
281
282 BIO_clear_retry_flags(b);
283 BIO_copy_next_retry(b);
284 return(ret);
285 }
286
287static int ok_write(BIO *b, char *in, int inl)
288 {
289 int ret=0,n,i;
290 BIO_OK_CTX *ctx;
291
292 ctx=(BIO_OK_CTX *)b->ptr;
293 ret=inl;
294
295 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
296
297 if(ctx->sigio) sig_out(b);
298
299 do{
300 BIO_clear_retry_flags(b);
301 n=ctx->buf_len-ctx->buf_off;
302 while (ctx->blockout && n > 0)
303 {
304 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
305 if (i <= 0)
306 {
307 BIO_copy_next_retry(b);
308 if(!BIO_should_retry(b))
309 ctx->cont= 0;
310 return(i);
311 }
312 ctx->buf_off+=i;
313 n-=i;
314 }
315
316 /* at this point all pending data has been written */
317 ctx->blockout= 0;
318 if (ctx->buf_len == ctx->buf_off)
319 {
320 ctx->buf_len=OK_BLOCK_BLOCK;
321 ctx->buf_off=0;
322 }
323
324 if ((in == NULL) || (inl <= 0)) return(0);
325
326 n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
327 OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl;
328
329 memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
330 ctx->buf_len+= n;
331 inl-=n;
332 in+=n;
333
334 if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
335 {
336 block_out(b);
337 }
338 }while(inl > 0);
339
340 BIO_clear_retry_flags(b);
341 BIO_copy_next_retry(b);
342 return(ret);
343 }
344
345static long ok_ctrl(BIO *b, int cmd, long num, char *ptr)
346 {
347 BIO_OK_CTX *ctx;
348 EVP_MD *md;
349 const EVP_MD **ppmd;
350 long ret=1;
351 int i;
352
353 ctx=(BIO_OK_CTX *)b->ptr;
354
355 switch (cmd)
356 {
357 case BIO_CTRL_RESET:
358 ctx->buf_len=0;
359 ctx->buf_off=0;
360 ctx->buf_len_save=0;
361 ctx->buf_off_save=0;
362 ctx->cont=1;
363 ctx->finished=0;
364 ctx->blockout= 0;
365 ctx->sigio=1;
366 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
367 break;
368 case BIO_CTRL_EOF: /* More to read */
369 if (ctx->cont <= 0)
370 ret=1;
371 else
372 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
373 break;
374 case BIO_CTRL_PENDING: /* More to read in buffer */
375 case BIO_CTRL_WPENDING: /* More to read in buffer */
376 ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
377 if (ret <= 0)
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 break;
380 case BIO_CTRL_FLUSH:
381 /* do a final write */
382 if(ctx->blockout == 0)
383 block_out(b);
384
385 while (ctx->blockout)
386 {
387 i=ok_write(b,NULL,0);
388 if (i < 0)
389 {
390 ret=i;
391 break;
392 }
393 }
394
395 ctx->finished=1;
396 ctx->buf_off=ctx->buf_len=0;
397 ctx->cont=(int)ret;
398
399 /* Finally flush the underlying BIO */
400 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
401 break;
402 case BIO_C_DO_STATE_MACHINE:
403 BIO_clear_retry_flags(b);
404 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
405 BIO_copy_next_retry(b);
406 break;
407 case BIO_CTRL_INFO:
408 ret=(long)ctx->cont;
409 break;
410 case BIO_C_SET_MD:
411 md=(EVP_MD *)ptr;
412 EVP_DigestInit(&(ctx->md),md);
413 b->init=1;
414 break;
415 case BIO_C_GET_MD:
416 if (b->init)
417 {
418 ppmd=(const EVP_MD **)ptr;
419 *ppmd=ctx->md.digest;
420 }
421 else
422 ret=0;
423 break;
424 default:
425 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
426 break;
427 }
428 return(ret);
429 }
430
431static void longswap(void *_ptr, int len)
432{
433#ifndef L_ENDIAN
434 int i;
435 char *ptr=_ptr;
436
437 for(i= 0;i < len;i+= 4){
438 *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i])));
439 }
440#endif
441}
442
443static void sig_out(BIO* b)
444 {
445 BIO_OK_CTX *ctx;
446 EVP_MD_CTX *md;
447
448 ctx=(BIO_OK_CTX *)b->ptr;
449 md= &(ctx->md);
450
451 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
452
453 EVP_DigestInit(md, md->digest);
454 RAND_bytes(&(md->md.base[0]), md->digest->md_size);
455 memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size);
456 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
457 ctx->buf_len+= md->digest->md_size;
458
459 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
460 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
461 ctx->buf_len+= md->digest->md_size;
462 ctx->blockout= 1;
463 ctx->sigio= 0;
464 }
465
466static void sig_in(BIO* b)
467 {
468 BIO_OK_CTX *ctx;
469 EVP_MD_CTX *md;
470 unsigned char tmp[EVP_MAX_MD_SIZE];
471 int ret= 0;
472
473 ctx=(BIO_OK_CTX *)b->ptr;
474 md= &(ctx->md);
475
476 if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return;
477
478 EVP_DigestInit(md, md->digest);
479 memcpy(&(md->md.base[0]), &(ctx->buf[ctx->buf_off]), md->digest->md_size);
480 longswap(&(md->md.base[0]), md->digest->md_size);
481 ctx->buf_off+= md->digest->md_size;
482
483 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
484 md->digest->final(tmp, &(md->md.base[0]));
485 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
486 ctx->buf_off+= md->digest->md_size;
487 if(ret == 1)
488 {
489 ctx->sigio= 0;
490 if(ctx->buf_len != ctx->buf_off)
491 {
492 memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
493 }
494 ctx->buf_len-= ctx->buf_off;
495 ctx->buf_off= 0;
496 }
497 else
498 {
499 ctx->cont= 0;
500 }
501 }
502
503static void block_out(BIO* b)
504 {
505 BIO_OK_CTX *ctx;
506 EVP_MD_CTX *md;
507 unsigned long tl;
508
509 ctx=(BIO_OK_CTX *)b->ptr;
510 md= &(ctx->md);
511
512 tl= ctx->buf_len- OK_BLOCK_BLOCK;
513 tl= swapem(tl);
514 memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK);
515 tl= swapem(tl);
516 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
517 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
518 ctx->buf_len+= md->digest->md_size;
519 ctx->blockout= 1;
520 }
521
522static void block_in(BIO* b)
523 {
524 BIO_OK_CTX *ctx;
525 EVP_MD_CTX *md;
526 long tl= 0;
527 unsigned char tmp[EVP_MAX_MD_SIZE];
528
529 ctx=(BIO_OK_CTX *)b->ptr;
530 md= &(ctx->md);
531
532 memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK);
533 tl= swapem(tl);
534 if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return;
535
536 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
537 md->digest->final(tmp, &(md->md.base[0]));
538 if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
539 {
540 /* there might be parts from next block lurking around ! */
541 ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
542 ctx->buf_len_save= ctx->buf_len;
543 ctx->buf_off= OK_BLOCK_BLOCK;
544 ctx->buf_len= tl+ OK_BLOCK_BLOCK;
545 ctx->blockout= 1;
546 }
547 else
548 {
549 ctx->cont= 0;
550 }
551 }
552
diff --git a/src/lib/libssl/src/crypto/evp/c_allc.c b/src/lib/libssl/src/crypto/evp/c_allc.c
new file mode 100644
index 0000000000..f24d3756c9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/c_allc.c
@@ -0,0 +1,149 @@
1/* crypto/evp/c_allc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_ciphers(void)
66 {
67#ifndef NO_DES
68 EVP_add_cipher(EVP_des_cfb());
69 EVP_add_cipher(EVP_des_ede_cfb());
70 EVP_add_cipher(EVP_des_ede3_cfb());
71
72 EVP_add_cipher(EVP_des_ofb());
73 EVP_add_cipher(EVP_des_ede_ofb());
74 EVP_add_cipher(EVP_des_ede3_ofb());
75
76 EVP_add_cipher(EVP_desx_cbc());
77 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
78 EVP_add_cipher_alias(SN_desx_cbc,"desx");
79
80 EVP_add_cipher(EVP_des_cbc());
81 EVP_add_cipher_alias(SN_des_cbc,"DES");
82 EVP_add_cipher_alias(SN_des_cbc,"des");
83 EVP_add_cipher(EVP_des_ede_cbc());
84 EVP_add_cipher(EVP_des_ede3_cbc());
85 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
86 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
87
88 EVP_add_cipher(EVP_des_ecb());
89 EVP_add_cipher(EVP_des_ede());
90 EVP_add_cipher(EVP_des_ede3());
91#endif
92
93#ifndef NO_RC4
94 EVP_add_cipher(EVP_rc4());
95 EVP_add_cipher(EVP_rc4_40());
96#endif
97
98#ifndef NO_IDEA
99 EVP_add_cipher(EVP_idea_ecb());
100 EVP_add_cipher(EVP_idea_cfb());
101 EVP_add_cipher(EVP_idea_ofb());
102 EVP_add_cipher(EVP_idea_cbc());
103 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
104 EVP_add_cipher_alias(SN_idea_cbc,"idea");
105#endif
106
107#ifndef NO_RC2
108 EVP_add_cipher(EVP_rc2_ecb());
109 EVP_add_cipher(EVP_rc2_cfb());
110 EVP_add_cipher(EVP_rc2_ofb());
111 EVP_add_cipher(EVP_rc2_cbc());
112 EVP_add_cipher(EVP_rc2_40_cbc());
113 EVP_add_cipher(EVP_rc2_64_cbc());
114 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
115 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
116#endif
117
118#ifndef NO_BF
119 EVP_add_cipher(EVP_bf_ecb());
120 EVP_add_cipher(EVP_bf_cfb());
121 EVP_add_cipher(EVP_bf_ofb());
122 EVP_add_cipher(EVP_bf_cbc());
123 EVP_add_cipher_alias(SN_bf_cbc,"BF");
124 EVP_add_cipher_alias(SN_bf_cbc,"bf");
125 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
126#endif
127
128#ifndef NO_CAST
129 EVP_add_cipher(EVP_cast5_ecb());
130 EVP_add_cipher(EVP_cast5_cfb());
131 EVP_add_cipher(EVP_cast5_ofb());
132 EVP_add_cipher(EVP_cast5_cbc());
133 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
134 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
135 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
136 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
137#endif
138
139#ifndef NO_RC5
140 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
141 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
142 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
143 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
144 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
145 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
146#endif
147 PKCS12_PBE_add();
148 PKCS5_PBE_add();
149 }
diff --git a/src/lib/libssl/src/crypto/evp/c_alld.c b/src/lib/libssl/src/crypto/evp/c_alld.c
new file mode 100644
index 0000000000..febe51a3ee
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/c_alld.c
@@ -0,0 +1,100 @@
1/* crypto/evp/c_alld.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_digests(void)
66 {
67#ifndef NO_MD2
68 EVP_add_digest(EVP_md2());
69#endif
70#ifndef NO_MD5
71 EVP_add_digest(EVP_md5());
72 EVP_add_digest_alias(SN_md5,"ssl2-md5");
73 EVP_add_digest_alias(SN_md5,"ssl3-md5");
74#endif
75#ifndef NO_SHA
76 EVP_add_digest(EVP_sha());
77#ifndef NO_DSA
78 EVP_add_digest(EVP_dss());
79#endif
80#endif
81#ifndef NO_SHA
82 EVP_add_digest(EVP_sha1());
83 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
84 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
85#ifndef NO_DSA
86 EVP_add_digest(EVP_dss1());
87 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
88 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
89 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
90#endif
91#endif
92#if !defined(NO_MDC2) && !defined(NO_DES)
93 EVP_add_digest(EVP_mdc2());
94#endif
95#ifndef NO_RIPEMD
96 EVP_add_digest(EVP_ripemd160());
97 EVP_add_digest_alias(SN_ripemd160,"ripemd");
98 EVP_add_digest_alias(SN_ripemd160,"rmd160");
99#endif
100 }
diff --git a/src/lib/libssl/src/crypto/evp/e_aes.c b/src/lib/libssl/src/crypto/evp/e_aes.c
new file mode 100644
index 0000000000..9d03a9602f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_aes.c
@@ -0,0 +1,99 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 */
50
51#ifndef OPENSSL_NO_AES
52#include <openssl/evp.h>
53#include <openssl/err.h>
54#include <string.h>
55#include <assert.h>
56#include <openssl/aes.h>
57#include "evp_locl.h"
58
59static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
60 const unsigned char *iv, int enc);
61
62typedef struct
63 {
64 AES_KEY ks;
65 } EVP_AES_KEY;
66
67#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
68
69IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
70 NID_aes_128, 16, 16, 16, 128,
71 0, aes_init_key, NULL,
72 EVP_CIPHER_set_asn1_iv,
73 EVP_CIPHER_get_asn1_iv,
74 NULL)
75IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
76 NID_aes_192, 16, 24, 16, 128,
77 0, aes_init_key, NULL,
78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
80 NULL)
81IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
82 NID_aes_256, 16, 32, 16, 128,
83 0, aes_init_key, NULL,
84 EVP_CIPHER_set_asn1_iv,
85 EVP_CIPHER_get_asn1_iv,
86 NULL)
87
88static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
89 const unsigned char *iv, int enc) {
90
91 if (enc)
92 AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
93 else
94 AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
95
96 return 1;
97}
98
99#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_bf.c b/src/lib/libssl/src/crypto/evp/e_bf.c
new file mode 100644
index 0000000000..72047f64da
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_bf.c
@@ -0,0 +1,80 @@
1/* crypto/evp/e_bf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_BF
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65
66static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv, int enc);
68
69IMPLEMENT_BLOCK_CIPHER(bf, bf_ks, BF, bf_ks, NID_bf, 8, 16, 8,
70 0, bf_init_key, NULL,
71 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
72
73static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
74 const unsigned char *iv, int enc)
75 {
76 BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
77 return 1;
78 }
79
80#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_cast.c b/src/lib/libssl/src/crypto/evp/e_cast.c
new file mode 100644
index 0000000000..e5af7fb4ed
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_cast.c
@@ -0,0 +1,82 @@
1/* crypto/evp/e_cast.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_CAST
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66
67static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69
70IMPLEMENT_BLOCK_CIPHER(cast5, cast_ks, CAST, cast_ks,
71 NID_cast5, 8, EVP_CAST5_KEY_SIZE, 8,
72 EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL,
73 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
74
75static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
76 const unsigned char *iv, int enc)
77 {
78 CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
79 return 1;
80 }
81
82#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_des.c b/src/lib/libssl/src/crypto/evp/e_des.c
new file mode 100644
index 0000000000..f4e998b81c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_des.c
@@ -0,0 +1,118 @@
1/* crypto/evp/e_des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65
66static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv, int enc);
68
69/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
70
71static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
72 const unsigned char *in, unsigned int inl)
73{
74 BLOCK_CIPHER_ecb_loop()
75 des_ecb_encrypt((des_cblock *)(in + i), (des_cblock *)(out + i), ctx->c.des_ks, ctx->encrypt);
76 return 1;
77}
78
79static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
80 const unsigned char *in, unsigned int inl)
81{
82 des_ofb64_encrypt(in, out, (long)inl, ctx->c.des_ks, (des_cblock *)ctx->iv, &ctx->num);
83 return 1;
84}
85
86static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
87 const unsigned char *in, unsigned int inl)
88{
89 des_ncbc_encrypt(in, out, (long)inl, ctx->c.des_ks,
90 (des_cblock *)ctx->iv, ctx->encrypt);
91 return 1;
92}
93
94static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
95 const unsigned char *in, unsigned int inl)
96{
97 des_cfb64_encrypt(in, out, (long)inl, ctx->c.des_ks,
98 (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
99 return 1;
100}
101
102BLOCK_CIPHER_defs(des, des_ks, NID_des, 8, 8, 8,
103 0, des_init_key, NULL,
104 EVP_CIPHER_set_asn1_iv,
105 EVP_CIPHER_get_asn1_iv,
106 NULL)
107
108
109static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
110 const unsigned char *iv, int enc)
111 {
112 des_cblock *deskey = (des_cblock *)key;
113
114 des_set_key_unchecked(deskey,ctx->c.des_ks);
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_des3.c b/src/lib/libssl/src/crypto/evp/e_des3.c
new file mode 100644
index 0000000000..a9aba4ae70
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_des3.c
@@ -0,0 +1,165 @@
1/* crypto/evp/e_des3.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65
66static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv,int enc);
68
69static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
70 const unsigned char *iv,int enc);
71
72/* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
73
74static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
75 const unsigned char *in, unsigned int inl)
76{
77 BLOCK_CIPHER_ecb_loop()
78 des_ecb3_encrypt((des_cblock *)(in + i), (des_cblock *)(out + i),
79 ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
80 ctx->encrypt);
81 return 1;
82}
83
84static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
85 const unsigned char *in, unsigned int inl)
86{
87 des_ede3_ofb64_encrypt(in, out, (long)inl,
88 ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
89 (des_cblock *)ctx->iv, &ctx->num);
90 return 1;
91}
92
93static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
94 const unsigned char *in, unsigned int inl)
95{
96 des_ede3_cbc_encrypt(in, out, (long)inl,
97 ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
98 (des_cblock *)ctx->iv, ctx->encrypt);
99 return 1;
100}
101
102static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
103 const unsigned char *in, unsigned int inl)
104{
105 des_ede3_cfb64_encrypt(in, out, (long)inl,
106 ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
107 (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
108 return 1;
109}
110
111#define NID_des_ede_ecb NID_des_ede
112
113BLOCK_CIPHER_defs(des_ede, des_ede, NID_des_ede, 8, 16, 8,
114 0, des_ede_init_key, NULL,
115 EVP_CIPHER_set_asn1_iv,
116 EVP_CIPHER_get_asn1_iv,
117 NULL)
118
119#define NID_des_ede3_ecb NID_des_ede3
120#define des_ede3_cfb_cipher des_ede_cfb_cipher
121#define des_ede3_ofb_cipher des_ede_ofb_cipher
122#define des_ede3_cbc_cipher des_ede_cbc_cipher
123#define des_ede3_ecb_cipher des_ede_ecb_cipher
124
125BLOCK_CIPHER_defs(des_ede3, des_ede, NID_des_ede3, 8, 24, 8,
126 0, des_ede3_init_key, NULL,
127 EVP_CIPHER_set_asn1_iv,
128 EVP_CIPHER_get_asn1_iv,
129 NULL)
130
131static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
132 const unsigned char *iv, int enc)
133 {
134 des_cblock *deskey = (des_cblock *)key;
135
136 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
137 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
138 memcpy( (char *)ctx->c.des_ede.ks3,
139 (char *)ctx->c.des_ede.ks1,
140 sizeof(ctx->c.des_ede.ks1));
141 return 1;
142 }
143
144static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
145 const unsigned char *iv, int enc)
146 {
147 des_cblock *deskey = (des_cblock *)key;
148
149 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
150 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
151 des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
152
153 return 1;
154 }
155
156EVP_CIPHER *EVP_des_ede(void)
157{
158 return &des_ede_ecb;
159}
160
161EVP_CIPHER *EVP_des_ede3(void)
162{
163 return &des_ede3_ecb;
164}
165#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_idea.c b/src/lib/libssl/src/crypto/evp/e_idea.c
new file mode 100644
index 0000000000..8d3c88deb7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_idea.c
@@ -0,0 +1,112 @@
1/* crypto/evp/e_idea.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_IDEA
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66
67static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69
70/* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special
71 * case
72 */
73
74static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
75 const unsigned char *in, unsigned int inl)
76{
77 BLOCK_CIPHER_ecb_loop()
78 idea_ecb_encrypt(in + i, out + i, &ctx->c.idea_ks);
79 return 1;
80}
81
82/* Can't use IMPLEMENT_BLOCK_CIPHER because idea_ecb_encrypt is different */
83
84BLOCK_CIPHER_func_cbc(idea, idea, idea_ks)
85BLOCK_CIPHER_func_ofb(idea, idea, idea_ks)
86BLOCK_CIPHER_func_cfb(idea, idea, idea_ks)
87
88BLOCK_CIPHER_defs(idea, idea_ks, NID_idea, 8, 16, 8,
89 0, idea_init_key, NULL,
90 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
91
92static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
93 const unsigned char *iv, int enc)
94 {
95 if(!enc) {
96 if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1;
97 else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1;
98 }
99 if (enc) idea_set_encrypt_key(key,&(ctx->c.idea_ks));
100 else
101 {
102 IDEA_KEY_SCHEDULE tmp;
103
104 idea_set_encrypt_key(key,&tmp);
105 idea_set_decrypt_key(&tmp,&(ctx->c.idea_ks));
106 memset((unsigned char *)&tmp,0,
107 sizeof(IDEA_KEY_SCHEDULE));
108 }
109 return 1;
110 }
111
112#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_rc2.c b/src/lib/libssl/src/crypto/evp/e_rc2.c
new file mode 100644
index 0000000000..3955c3ef84
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_rc2.c
@@ -0,0 +1,222 @@
1/* crypto/evp/e_rc2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RC2
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66
67static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx);
70static int rc2_magic_to_meth(int i);
71static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
72static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
73static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
74
75IMPLEMENT_BLOCK_CIPHER(rc2, rc2.ks, RC2, rc2, NID_rc2,
76 8,
77 EVP_RC2_KEY_SIZE, 8,
78 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
79 rc2_init_key, NULL,
80 rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv,
81 rc2_ctrl)
82
83#define RC2_40_MAGIC 0xa0
84#define RC2_64_MAGIC 0x78
85#define RC2_128_MAGIC 0x3a
86
87static EVP_CIPHER r2_64_cbc_cipher=
88 {
89 NID_rc2_64_cbc,
90 8,8 /* 64 bit */,8,
91 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
92 rc2_init_key,
93 rc2_cbc_cipher,
94 NULL,
95 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
96 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)),
97 rc2_set_asn1_type_and_iv,
98 rc2_get_asn1_type_and_iv,
99 rc2_ctrl,
100 NULL
101 };
102
103static EVP_CIPHER r2_40_cbc_cipher=
104 {
105 NID_rc2_40_cbc,
106 8,5 /* 40 bit */,8,
107 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
108 rc2_init_key,
109 rc2_cbc_cipher,
110 NULL,
111 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
112 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)),
113 rc2_set_asn1_type_and_iv,
114 rc2_get_asn1_type_and_iv,
115 rc2_ctrl,
116 NULL
117 };
118
119EVP_CIPHER *EVP_rc2_64_cbc(void)
120 {
121 return(&r2_64_cbc_cipher);
122 }
123
124EVP_CIPHER *EVP_rc2_40_cbc(void)
125 {
126 return(&r2_40_cbc_cipher);
127 }
128
129static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
130 const unsigned char *iv, int enc)
131 {
132 RC2_set_key(&(ctx->c.rc2.ks),EVP_CIPHER_CTX_key_length(ctx),
133 key,ctx->c.rc2.key_bits);
134 return 1;
135 }
136
137static int rc2_meth_to_magic(EVP_CIPHER_CTX *e)
138 {
139 int i;
140
141 EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
142 if (i == 128) return(RC2_128_MAGIC);
143 else if (i == 64) return(RC2_64_MAGIC);
144 else if (i == 40) return(RC2_40_MAGIC);
145 else return(0);
146 }
147
148static int rc2_magic_to_meth(int i)
149 {
150 if (i == RC2_128_MAGIC) return 128;
151 else if (i == RC2_64_MAGIC) return 64;
152 else if (i == RC2_40_MAGIC) return 40;
153 else
154 {
155 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
156 return(0);
157 }
158 }
159
160static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
161 {
162 long num=0;
163 int i=0,l;
164 int key_bits;
165 unsigned char iv[EVP_MAX_IV_LENGTH];
166
167 if (type != NULL)
168 {
169 l=EVP_CIPHER_CTX_iv_length(c);
170 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
171 if (i != l)
172 return(-1);
173 key_bits =rc2_magic_to_meth((int)num);
174 if (!key_bits)
175 return(-1);
176 if(i > 0) EVP_CipherInit(c, NULL, NULL, iv, -1);
177 EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
178 EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
179 }
180 return(i);
181 }
182
183static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
184 {
185 long num;
186 int i=0,j;
187
188 if (type != NULL)
189 {
190 num=rc2_meth_to_magic(c);
191 j=EVP_CIPHER_CTX_iv_length(c);
192 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
193 }
194 return(i);
195 }
196
197static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
198 {
199 switch(type) {
200
201 case EVP_CTRL_INIT:
202 c->c.rc2.key_bits = EVP_CIPHER_CTX_key_length(c) * 8;
203 return 1;
204
205 case EVP_CTRL_GET_RC2_KEY_BITS:
206 *(int *)ptr = c->c.rc2.key_bits;
207 return 1;
208
209
210 case EVP_CTRL_SET_RC2_KEY_BITS:
211 if(arg > 0) {
212 c->c.rc2.key_bits = arg;
213 return 1;
214 }
215 return 0;
216
217 default:
218 return -1;
219 }
220 }
221
222#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_rc5.c b/src/lib/libssl/src/crypto/evp/e_rc5.c
new file mode 100644
index 0000000000..5885f1826b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_rc5.c
@@ -0,0 +1,118 @@
1/* crypto/evp/e_rc5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RC5
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66
67static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
70
71IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, rc5.ks, RC5_32, rc5, NID_rc5,
72 8, EVP_RC5_32_12_16_KEY_SIZE, 8,
73 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
74 r_32_12_16_init_key, NULL,
75 NULL, NULL, rc5_ctrl)
76
77
78
79static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
80 {
81 switch(type) {
82
83 case EVP_CTRL_INIT:
84 c->c.rc5.rounds = RC5_12_ROUNDS;
85 return 1;
86
87 case EVP_CTRL_GET_RC5_ROUNDS:
88 *(int *)ptr = c->c.rc5.rounds;
89 return 1;
90
91
92 case EVP_CTRL_SET_RC5_ROUNDS:
93 switch(arg) {
94 case RC5_8_ROUNDS:
95 case RC5_12_ROUNDS:
96 case RC5_16_ROUNDS:
97 c->c.rc5.rounds = arg;
98 return 1;
99
100 default:
101 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
102 return 0;
103 }
104
105 default:
106 return -1;
107 }
108 }
109
110static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc)
112 {
113 RC5_32_set_key(&(ctx->c.rc5.ks),EVP_CIPHER_CTX_key_length(ctx),
114 key,ctx->c.rc5.rounds);
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libssl/src/crypto/evp/evp_acnf.c b/src/lib/libssl/src/crypto/evp/evp_acnf.c
new file mode 100644
index 0000000000..a68b979bdb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_acnf.c
@@ -0,0 +1,74 @@
1/* evp_acnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include "cryptlib.h"
60#include <openssl/evp.h>
61#include <openssl/conf.h>
62#include <openssl/engine.h>
63
64
65/* Load all algorithms and configure OpenSSL.
66 * This function is called automatically when
67 * OPENSSL_LOAD_CONF is set.
68 */
69
70void OPENSSL_add_all_algorithms_conf(void)
71 {
72 OPENSSL_add_all_algorithms_noconf();
73 OPENSSL_config(NULL);
74 }
diff --git a/src/lib/libssl/src/crypto/evp/evp_locl.h b/src/lib/libssl/src/crypto/evp/evp_locl.h
new file mode 100644
index 0000000000..ce49d5b7d8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_locl.h
@@ -0,0 +1,168 @@
1/* evp_locl.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Macros to code block cipher wrappers */
60
61/* Wrapper functions for each cipher mode */
62
63#define BLOCK_CIPHER_ecb_loop() \
64 unsigned int i; \
65 if(inl < 8) return 1;\
66 inl -= 8; \
67 for(i=0; i <= inl; i+=8) \
68
69#define BLOCK_CIPHER_func_ecb(cname, cprefix, kname) \
70static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
71{\
72 BLOCK_CIPHER_ecb_loop() \
73 cprefix##_ecb_encrypt(in + i, out + i, &ctx->c.kname, ctx->encrypt);\
74 return 1;\
75}
76
77#define BLOCK_CIPHER_func_ofb(cname, cprefix, kname) \
78static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
79{\
80 cprefix##_ofb64_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, &ctx->num);\
81 return 1;\
82}
83
84#define BLOCK_CIPHER_func_cbc(cname, cprefix, kname) \
85static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
86{\
87 cprefix##_cbc_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, ctx->encrypt);\
88 return 1;\
89}
90
91#define BLOCK_CIPHER_func_cfb(cname, cprefix, kname) \
92static int cname##_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
93{\
94 cprefix##_cfb64_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, &ctx->num, ctx->encrypt);\
95 return 1;\
96}
97
98#define BLOCK_CIPHER_all_funcs(cname, cprefix, kname) \
99 BLOCK_CIPHER_func_cbc(cname, cprefix, kname) \
100 BLOCK_CIPHER_func_cfb(cname, cprefix, kname) \
101 BLOCK_CIPHER_func_ecb(cname, cprefix, kname) \
102 BLOCK_CIPHER_func_ofb(cname, cprefix, kname)
103
104#define BLOCK_CIPHER_defs(cname, kstruct, \
105 nid, block_size, key_len, iv_len, flags,\
106 init_key, cleanup, set_asn1, get_asn1, ctrl)\
107static EVP_CIPHER cname##_cbc = {\
108 nid##_cbc, block_size, key_len, iv_len, \
109 flags | EVP_CIPH_CBC_MODE,\
110 init_key,\
111 cname##_cbc_cipher,\
112 cleanup,\
113 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
114 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
115 set_asn1, get_asn1,\
116 ctrl, \
117 NULL \
118};\
119EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
120static EVP_CIPHER cname##_cfb = {\
121 nid##_cfb64, 1, key_len, iv_len, \
122 flags | EVP_CIPH_CFB_MODE,\
123 init_key,\
124 cname##_cfb_cipher,\
125 cleanup,\
126 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
127 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
128 set_asn1, get_asn1,\
129 ctrl,\
130 NULL \
131};\
132EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
133static EVP_CIPHER cname##_ofb = {\
134 nid##_ofb64, 1, key_len, iv_len, \
135 flags | EVP_CIPH_OFB_MODE,\
136 init_key,\
137 cname##_ofb_cipher,\
138 cleanup,\
139 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
140 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
141 set_asn1, get_asn1,\
142 ctrl,\
143 NULL \
144};\
145EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
146static EVP_CIPHER cname##_ecb = {\
147 nid##_ecb, block_size, key_len, iv_len, \
148 flags | EVP_CIPH_ECB_MODE,\
149 init_key,\
150 cname##_ecb_cipher,\
151 cleanup,\
152 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
153 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
154 set_asn1, get_asn1,\
155 ctrl,\
156 NULL \
157};\
158EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
159
160
161
162#define IMPLEMENT_BLOCK_CIPHER(cname, kname, cprefix, kstruct, \
163 nid, block_size, key_len, iv_len, flags, \
164 init_key, cleanup, set_asn1, get_asn1, ctrl) \
165 BLOCK_CIPHER_all_funcs(cname, cprefix, kname) \
166 BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, flags,\
167 init_key, cleanup, set_asn1, get_asn1, ctrl)
168
diff --git a/src/lib/libssl/src/crypto/evp/evp_pbe.c b/src/lib/libssl/src/crypto/evp/evp_pbe.c
new file mode 100644
index 0000000000..353c3ad667
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_pbe.c
@@ -0,0 +1,134 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/evp.h>
61#include <openssl/x509.h>
62#include "cryptlib.h"
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72EVP_CIPHER *cipher;
73EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) strcpy (obj_tmp, "NULL");
91 else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if (passlen == -1) passlen = strlen(pass);
96 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
97 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
98 pbetmp->md, en_de);
99 if (!i) {
100 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
101 return 0;
102 }
103 return 1;
104}
105
106static int pbe_cmp (EVP_PBE_CTL **pbe1, EVP_PBE_CTL **pbe2)
107{
108 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
109}
110
111/* Add a PBE algorithm */
112
113int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md,
114 EVP_PBE_KEYGEN *keygen)
115{
116 EVP_PBE_CTL *pbe_tmp;
117 if (!pbe_algs) pbe_algs = sk_new (pbe_cmp);
118 if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) {
119 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 pbe_tmp->pbe_nid = nid;
123 pbe_tmp->cipher = cipher;
124 pbe_tmp->md = md;
125 pbe_tmp->keygen = keygen;
126 sk_push (pbe_algs, (char *)pbe_tmp);
127 return 1;
128}
129
130void EVP_PBE_cleanup(void)
131{
132 sk_pop_free(pbe_algs, FreeFunc);
133 pbe_algs = NULL;
134}
diff --git a/src/lib/libssl/src/crypto/evp/evp_pkey.c b/src/lib/libssl/src/crypto/evp/evp_pkey.c
new file mode 100644
index 0000000000..421e452db1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_pkey.c
@@ -0,0 +1,298 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* Extract a private key from a PKCS8 structure */
66
67EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
68{
69 EVP_PKEY *pkey;
70#ifndef NO_RSA
71 RSA *rsa;
72#endif
73#ifndef NO_DSA
74 DSA *dsa;
75 ASN1_INTEGER *dsapriv;
76 STACK *ndsa;
77 BN_CTX *ctx;
78 int plen;
79#endif
80 X509_ALGOR *a;
81 unsigned char *p;
82 int pkeylen;
83 char obj_tmp[80];
84
85 switch (p8->broken) {
86 case PKCS8_OK:
87 p = p8->pkey->value.octet_string->data;
88 pkeylen = p8->pkey->value.octet_string->length;
89 break;
90
91 case PKCS8_NO_OCTET:
92 p = p8->pkey->value.sequence->data;
93 pkeylen = p8->pkey->value.sequence->length;
94 break;
95
96 default:
97 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
98 return NULL;
99 break;
100 }
101 if (!(pkey = EVP_PKEY_new())) {
102 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
103 return NULL;
104 }
105 a = p8->pkeyalg;
106 switch (OBJ_obj2nid(a->algorithm))
107 {
108#ifndef NO_RSA
109 case NID_rsaEncryption:
110 if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken Netscape Database DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
127 (char *(*)())d2i_ASN1_INTEGER,
128 ASN1_STRING_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 return NULL;
131 }
132 if(sk_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 sk_pop_free(ndsa, ASN1_STRING_free);
135 return NULL;
136 }
137 dsapriv = (ASN1_INTEGER *) sk_pop(ndsa);
138 sk_pop_free(ndsa, ASN1_STRING_free);
139 } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
140 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
141 return NULL;
142 }
143 /* Retrieve parameters */
144 if (a->parameter->type != V_ASN1_SEQUENCE) {
145 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS);
146 return NULL;
147 }
148 p = a->parameter->value.sequence->data;
149 plen = a->parameter->value.sequence->length;
150 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 return NULL;
153 }
154 /* We have parameters now set private key */
155 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
157 DSA_free (dsa);
158 return NULL;
159 }
160 /* Calculate public key (ouch!) */
161 if (!(dsa->pub_key = BN_new())) {
162 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
163 DSA_free (dsa);
164 return NULL;
165 }
166 if (!(ctx = BN_CTX_new())) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
168 DSA_free (dsa);
169 return NULL;
170 }
171
172 if (!BN_mod_exp(dsa->pub_key, dsa->g,
173 dsa->priv_key, dsa->p, ctx)) {
174
175 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
176 BN_CTX_free (ctx);
177 DSA_free (dsa);
178 return NULL;
179 }
180
181 EVP_PKEY_assign_DSA (pkey, dsa);
182 BN_CTX_free (ctx);
183 break;
184#endif
185 default:
186 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
187 if (!a->algorithm) strcpy (obj_tmp, "NULL");
188 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
189 ERR_add_error_data(2, "TYPE=", obj_tmp);
190 EVP_PKEY_free (pkey);
191 return NULL;
192 }
193 return pkey;
194}
195
196/* Turn a private key into a PKCS8 structure */
197
198PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
199{
200 PKCS8_PRIV_KEY_INFO *p8;
201#ifndef NO_DSA
202 ASN1_INTEGER *dpkey;
203 unsigned char *p, *q;
204 int len;
205#endif
206 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
207 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
208 return NULL;
209 }
210 ASN1_INTEGER_set (p8->version, 0);
211 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
212 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
213 PKCS8_PRIV_KEY_INFO_free (p8);
214 return NULL;
215 }
216 switch (EVP_PKEY_type(pkey->type)) {
217#ifndef NO_RSA
218 case EVP_PKEY_RSA:
219
220 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
221 p8->pkeyalg->parameter->type = V_ASN1_NULL;
222 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
223 &p8->pkey->value.octet_string)) {
224 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
225 PKCS8_PRIV_KEY_INFO_free (p8);
226 return NULL;
227 }
228 break;
229#endif
230#ifndef NO_DSA
231 case EVP_PKEY_DSA:
232 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
233
234 /* get paramaters and place in AlgorithmIdentifier */
235 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
236 if (!(p = Malloc(len))) {
237 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
238 PKCS8_PRIV_KEY_INFO_free (p8);
239 return NULL;
240 }
241 q = p;
242 i2d_DSAparams (pkey->pkey.dsa, &q);
243 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
244 p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();
245 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);
246 Free(p);
247 /* Get private key into an integer and pack */
248 if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
249 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
250 PKCS8_PRIV_KEY_INFO_free (p8);
251 return NULL;
252 }
253
254 if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,
255 &p8->pkey->value.octet_string)) {
256 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
257 ASN1_INTEGER_free (dpkey);
258 PKCS8_PRIV_KEY_INFO_free (p8);
259 return NULL;
260 }
261 ASN1_INTEGER_free (dpkey);
262 break;
263#endif
264 default:
265 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
266 PKCS8_PRIV_KEY_INFO_free (p8);
267 return NULL;
268 }
269 p8->pkey->type = V_ASN1_OCTET_STRING;
270 RAND_seed (p8->pkey->value.octet_string->data,
271 p8->pkey->value.octet_string->length);
272 return p8;
273}
274
275PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
276{
277 switch (broken) {
278
279 case PKCS8_OK:
280 p8->broken = PKCS8_OK;
281 return p8;
282 break;
283
284 case PKCS8_NO_OCTET:
285 p8->broken = PKCS8_NO_OCTET;
286 p8->pkey->type = V_ASN1_SEQUENCE;
287 return p8;
288 break;
289
290 default:
291 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
292 return NULL;
293 break;
294
295 }
296}
297
298
diff --git a/src/lib/libssl/src/crypto/evp/evp_test.c b/src/lib/libssl/src/crypto/evp/evp_test.c
new file mode 100644
index 0000000000..3607fe7776
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_test.c
@@ -0,0 +1,365 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <stdio.h>
51#include <string.h>
52#include <openssl/evp.h>
53#include <openssl/engine.h>
54#include <openssl/conf.h>
55
56static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
57 {
58 int n=0;
59
60 fprintf(f,"%s",title);
61 for( ; n < l ; ++n)
62 {
63 if((n%16) == 0)
64 fprintf(f,"\n%04x",n);
65 fprintf(f," %02x",s[n]);
66 }
67 fprintf(f,"\n");
68 }
69
70static int convert(unsigned char *s)
71 {
72 unsigned char *d;
73
74 for(d=s ; *s ; s+=2,++d)
75 {
76 unsigned int n;
77
78 if(!s[1])
79 {
80 fprintf(stderr,"Odd number of hex digits!");
81 exit(4);
82 }
83 sscanf((char *)s,"%2x",&n);
84 *d=(unsigned char)n;
85 }
86 return s-d;
87 }
88
89static char *sstrsep(char **string, const char *delim)
90 {
91 char isdelim[256];
92 char *token = *string;
93
94 if (**string == 0)
95 return NULL;
96
97 memset(isdelim, 0, 256);
98 isdelim[0] = 1;
99
100 while (*delim)
101 {
102 isdelim[(unsigned char)(*delim)] = 1;
103 delim++;
104 }
105
106 while (!isdelim[(unsigned char)(**string)])
107 {
108 (*string)++;
109 }
110
111 if (**string)
112 {
113 **string = 0;
114 (*string)++;
115 }
116
117 return token;
118 }
119
120static unsigned char *ustrsep(char **p,const char *sep)
121 { return (unsigned char *)sstrsep((char **)p,sep); }
122
123static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
124 const unsigned char *iv,int in,
125 const unsigned char *plaintext,int pn,
126 const unsigned char *ciphertext,int cn)
127 {
128 EVP_CIPHER_CTX ctx;
129 unsigned char out[4096];
130 int outl,outl2;
131
132 printf("Testing cipher %s\n",EVP_CIPHER_name(c));
133 hexdump(stdout,"Key",key,kn);
134 if(in)
135 hexdump(stdout,"IV",iv,in);
136 hexdump(stdout,"Plaintext",plaintext,pn);
137 hexdump(stdout,"Ciphertext",ciphertext,cn);
138
139 if(kn != c->key_len)
140 {
141 fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn,
142 c->key_len);
143 exit(5);
144 }
145 EVP_CIPHER_CTX_init(&ctx);
146 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
147 {
148 fprintf(stderr,"EncryptInit failed\n");
149 exit(10);
150 }
151 EVP_CIPHER_CTX_set_padding(&ctx,0);
152
153 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn))
154 {
155 fprintf(stderr,"Encrypt failed\n");
156 exit(6);
157 }
158 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
159 {
160 fprintf(stderr,"EncryptFinal failed\n");
161 exit(7);
162 }
163
164 if(outl+outl2 != cn)
165 {
166 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
167 outl+outl2,cn);
168 exit(8);
169 }
170
171 if(memcmp(out,ciphertext,cn))
172 {
173 fprintf(stderr,"Ciphertext mismatch\n");
174 hexdump(stderr,"Got",out,cn);
175 hexdump(stderr,"Expected",ciphertext,cn);
176 exit(9);
177 }
178
179 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
180 {
181 fprintf(stderr,"DecryptInit failed\n");
182 exit(11);
183 }
184 EVP_CIPHER_CTX_set_padding(&ctx,0);
185
186 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,pn))
187 {
188 fprintf(stderr,"Decrypt failed\n");
189 exit(6);
190 }
191 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
192 {
193 fprintf(stderr,"DecryptFinal failed\n");
194 exit(7);
195 }
196
197 if(outl+outl2 != cn)
198 {
199 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
200 outl+outl2,cn);
201 exit(8);
202 }
203
204 if(memcmp(out,plaintext,cn))
205 {
206 fprintf(stderr,"Plaintext mismatch\n");
207 hexdump(stderr,"Got",out,cn);
208 hexdump(stderr,"Expected",plaintext,cn);
209 exit(9);
210 }
211
212 printf("\n");
213 }
214
215static int test_cipher(const char *cipher,const unsigned char *key,int kn,
216 const unsigned char *iv,int in,
217 const unsigned char *plaintext,int pn,
218 const unsigned char *ciphertext,int cn)
219 {
220 const EVP_CIPHER *c;
221
222 c=EVP_get_cipherbyname(cipher);
223 if(!c)
224 return 0;
225
226 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn);
227
228 return 1;
229 }
230
231static int test_digest(const char *digest,
232 const unsigned char *plaintext,int pn,
233 const unsigned char *ciphertext, unsigned int cn)
234 {
235 const EVP_MD *d;
236 EVP_MD_CTX ctx;
237 unsigned char md[EVP_MAX_MD_SIZE];
238 unsigned int mdn;
239
240 d=EVP_get_digestbyname(digest);
241 if(!d)
242 return 0;
243
244 printf("Testing digest %s\n",EVP_MD_name(d));
245 hexdump(stdout,"Plaintext",plaintext,pn);
246 hexdump(stdout,"Digest",ciphertext,cn);
247
248 EVP_MD_CTX_init(&ctx);
249 if(!EVP_DigestInit_ex(&ctx,d, NULL))
250 {
251 fprintf(stderr,"DigestInit failed\n");
252 exit(100);
253 }
254 if(!EVP_DigestUpdate(&ctx,plaintext,pn))
255 {
256 fprintf(stderr,"DigestUpdate failed\n");
257 exit(101);
258 }
259 if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
260 {
261 fprintf(stderr,"DigestFinal failed\n");
262 exit(101);
263 }
264 EVP_MD_CTX_cleanup(&ctx);
265
266 if(mdn != cn)
267 {
268 fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn);
269 exit(102);
270 }
271
272 if(memcmp(md,ciphertext,cn))
273 {
274 fprintf(stderr,"Digest mismatch\n");
275 hexdump(stderr,"Got",md,cn);
276 hexdump(stderr,"Expected",ciphertext,cn);
277 exit(103);
278 }
279
280 printf("\n");
281
282 return 1;
283 }
284
285int main(int argc,char **argv)
286 {
287 const char *szTestFile;
288 FILE *f;
289
290 if(argc != 2)
291 {
292 fprintf(stderr,"%s <test file>\n",argv[0]);
293 exit(1);
294 }
295 CRYPTO_malloc_debug_init();
296 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
297 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
298
299 szTestFile=argv[1];
300
301 f=fopen(szTestFile,"r");
302 if(!f)
303 {
304 perror(szTestFile);
305 exit(2);
306 }
307
308 /* Load up the software EVP_CIPHER and EVP_MD definitions */
309 OpenSSL_add_all_ciphers();
310 OpenSSL_add_all_digests();
311 /* Load all compiled-in ENGINEs */
312 ENGINE_load_builtin_engines();
313#if 0
314 OPENSSL_config();
315#endif
316 /* Register all available ENGINE implementations of ciphers and digests.
317 * This could perhaps be changed to "ENGINE_register_all_complete()"? */
318 ENGINE_register_all_ciphers();
319 ENGINE_register_all_digests();
320 /* If we add command-line options, this statement should be switchable.
321 * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if
322 * they weren't already initialised. */
323 /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */
324
325 for( ; ; )
326 {
327 char line[4096];
328 char *p;
329 char *cipher;
330 unsigned char *iv,*key,*plaintext,*ciphertext;
331 int kn,in,pn,cn;
332
333 if(!fgets((char *)line,sizeof line,f))
334 break;
335 if(line[0] == '#' || line[0] == '\n')
336 continue;
337 p=line;
338 cipher=sstrsep(&p,":");
339 key=ustrsep(&p,":");
340 iv=ustrsep(&p,":");
341 plaintext=ustrsep(&p,":");
342 ciphertext=ustrsep(&p,"\n");
343
344 kn=convert(key);
345 in=convert(iv);
346 pn=convert(plaintext);
347 cn=convert(ciphertext);
348
349 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn)
350 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
351 {
352 fprintf(stderr,"Can't find %s\n",cipher);
353 exit(3);
354 }
355 }
356
357 ENGINE_cleanup();
358 EVP_cleanup();
359 CRYPTO_cleanup_all_ex_data();
360 ERR_remove_state(0);
361 ERR_free_strings();
362 CRYPTO_mem_leaks_fp(stderr);
363
364 return 0;
365 }
diff --git a/src/lib/libssl/src/crypto/evp/evptests.txt b/src/lib/libssl/src/crypto/evp/evptests.txt
new file mode 100644
index 0000000000..6c1529db37
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evptests.txt
@@ -0,0 +1,82 @@
1#cipher:key:iv:input:output
2#digest:::input:output
3
4# SHA(1) tests (from shatest.c)
5SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d
6
7# MD5 tests (from md5test.c)
8MD5::::d41d8cd98f00b204e9800998ecf8427e
9MD5:::61:0cc175b9c0f1b6a831c399e269772661
10MD5:::616263:900150983cd24fb0d6963f7d28e17f72
11MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0
12MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b
13MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f
14MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a
15
16# AES 128 ECB tests (from FIPS-197 test vectors, encrypt)
17
18AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A
19
20# AES 192 ECB tests (from FIPS-197 test vectors, encrypt)
21
22AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191
23
24# AES 256 ECB tests (from FIPS-197 test vectors, encrypt)
25
26AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089
27
28# AES 128 ECB tests (from NIST test vectors, encrypt)
29
30#AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F
31
32# AES 128 ECB tests (from NIST test vectors, decrypt)
33
34#AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000
35
36# AES 192 ECB tests (from NIST test vectors, decrypt)
37
38#AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000
39
40# AES 256 ECB tests (from NIST test vectors, decrypt)
41
42#AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000
43
44# AES 128 CBC tests (from NIST test vectors, encrypt)
45
46#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D
47
48# AES 192 CBC tests (from NIST test vectors, encrypt)
49
50#AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104
51
52# AES 256 CBC tests (from NIST test vectors, encrypt)
53
54#AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0
55
56# AES 128 CBC tests (from NIST test vectors, decrypt)
57
58#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000
59
60# DES ECB tests (from destest)
61
62DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7
63DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58
64DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B
65DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533
66DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D
67DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD
68DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4
69
70# DESX-CBC tests (from destest)
71DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4
72
73# DES EDE3 CBC tests (from destest)
74DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
75
76# RC4 tests (from rc4test)
77RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596
78RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879
79RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a
80RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858
81RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf
82RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61
diff --git a/src/lib/libssl/src/crypto/evp/m_md4.c b/src/lib/libssl/src/crypto/evp/m_md4.c
new file mode 100644
index 0000000000..6a24ceb86d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_md4.c
@@ -0,0 +1,83 @@
1/* crypto/evp/m_md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_MD4
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD md4_md=
67 {
68 NID_md4,
69 0,
70 MD4_DIGEST_LENGTH,
71 MD4_Init,
72 MD4_Update,
73 MD4_Final,
74 EVP_PKEY_RSA_method,
75 MD4_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(MD4_CTX),
77 };
78
79EVP_MD *EVP_md4(void)
80 {
81 return(&md4_md);
82 }
83#endif
diff --git a/src/lib/libssl/src/crypto/evp/openbsd_hw.c b/src/lib/libssl/src/crypto/evp/openbsd_hw.c
new file mode 100644
index 0000000000..3831a5731e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/openbsd_hw.c
@@ -0,0 +1,446 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <openssl/evp.h>
51#include <openssl/objects.h>
52#include <openssl/rsa.h>
53#include "evp_locl.h"
54
55/* This stuff should now all be supported through
56 * crypto/engine/hw_openbsd_dev_crypto.c unless I botched it up */
57static void *dummy=&dummy;
58
59#if 0
60
61/* check flag after OpenSSL headers to ensure make depend works */
62#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
63
64#include <fcntl.h>
65#include <stdio.h>
66#include <errno.h>
67#include <sys/ioctl.h>
68#include <crypto/cryptodev.h>
69#include <unistd.h>
70#include <assert.h>
71
72/* longest key supported in hardware */
73#define MAX_HW_KEY 24
74#define MAX_HW_IV 8
75
76#define MD5_DIGEST_LENGTH 16
77#define MD5_CBLOCK 64
78
79static int fd;
80static int dev_failed;
81
82typedef struct session_op session_op;
83
84#define CDATA(ctx) EVP_C_DATA(session_op,ctx)
85
86static void err(const char *str)
87 {
88 fprintf(stderr,"%s: errno %d\n",str,errno);
89 }
90
91static int dev_crypto_init(session_op *ses)
92 {
93 if(dev_failed)
94 return 0;
95 if(!fd)
96 {
97 int cryptodev_fd;
98
99 if ((cryptodev_fd=open("/dev/crypto",O_RDWR,0)) < 0)
100 {
101 err("/dev/crypto");
102 dev_failed=1;
103 return 0;
104 }
105 if (ioctl(cryptodev_fd,CRIOGET,&fd) == -1)
106 {
107 err("CRIOGET failed");
108 close(cryptodev_fd);
109 dev_failed=1;
110 return 0;
111 }
112 close(cryptodev_fd);
113 }
114 assert(ses);
115 memset(ses,'\0',sizeof *ses);
116
117 return 1;
118 }
119
120static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
121 {
122 if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
123 err("CIOCFSESSION failed");
124
125 OPENSSL_free(CDATA(ctx)->key);
126
127 return 1;
128 }
129
130static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
131 const unsigned char *key,int klen)
132 {
133 if(!dev_crypto_init(CDATA(ctx)))
134 return 0;
135
136 CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
137
138 assert(ctx->cipher->iv_len <= MAX_HW_IV);
139
140 memcpy(CDATA(ctx)->key,key,klen);
141
142 CDATA(ctx)->cipher=cipher;
143 CDATA(ctx)->keylen=klen;
144
145 if (ioctl(fd,CIOCGSESSION,CDATA(ctx)) == -1)
146 {
147 err("CIOCGSESSION failed");
148 return 0;
149 }
150 return 1;
151 }
152
153static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
154 const unsigned char *in,unsigned int inl)
155 {
156 struct crypt_op cryp;
157 unsigned char lb[MAX_HW_IV];
158
159 if(!inl)
160 return 1;
161
162 assert(CDATA(ctx));
163 assert(!dev_failed);
164
165 memset(&cryp,'\0',sizeof cryp);
166 cryp.ses=CDATA(ctx)->ses;
167 cryp.op=ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
168 cryp.flags=0;
169 cryp.len=inl;
170 assert((inl&(ctx->cipher->block_size-1)) == 0);
171 cryp.src=(caddr_t)in;
172 cryp.dst=(caddr_t)out;
173 cryp.mac=0;
174 if(ctx->cipher->iv_len)
175 cryp.iv=(caddr_t)ctx->iv;
176
177 if(!ctx->encrypt)
178 memcpy(lb,&in[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
179
180 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
181 {
182 if(errno == EINVAL) /* buffers are misaligned */
183 {
184 unsigned int cinl=0;
185 char *cin=NULL;
186 char *cout=NULL;
187
188 /* NB: this can only make cinl != inl with stream ciphers */
189 cinl=(inl+3)/4*4;
190
191 if(((unsigned long)in&3) || cinl != inl)
192 {
193 cin=OPENSSL_malloc(cinl);
194 memcpy(cin,in,inl);
195 cryp.src=cin;
196 }
197
198 if(((unsigned long)out&3) || cinl != inl)
199 {
200 cout=OPENSSL_malloc(cinl);
201 cryp.dst=cout;
202 }
203
204 cryp.len=cinl;
205
206 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
207 {
208 err("CIOCCRYPT(2) failed");
209 printf("src=%p dst=%p\n",cryp.src,cryp.dst);
210 abort();
211 return 0;
212 }
213
214 if(cout)
215 {
216 memcpy(out,cout,inl);
217 OPENSSL_free(cout);
218 }
219 if(cin)
220 OPENSSL_free(cin);
221 }
222 else
223 {
224 err("CIOCCRYPT failed");
225 abort();
226 return 0;
227 }
228 }
229
230 if(ctx->encrypt)
231 memcpy(ctx->iv,&out[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
232 else
233 memcpy(ctx->iv,lb,ctx->cipher->iv_len);
234
235 return 1;
236 }
237
238static int dev_crypto_des_ede3_init_key(EVP_CIPHER_CTX *ctx,
239 const unsigned char *key,
240 const unsigned char *iv, int enc)
241 { return dev_crypto_init_key(ctx,CRYPTO_3DES_CBC,key,24); }
242
243#define dev_crypto_des_ede3_cbc_cipher dev_crypto_cipher
244
245BLOCK_CIPHER_def_cbc(dev_crypto_des_ede3, session_op, NID_des_ede3, 8, 24, 8,
246 0, dev_crypto_des_ede3_init_key,
247 dev_crypto_cleanup,
248 EVP_CIPHER_set_asn1_iv,
249 EVP_CIPHER_get_asn1_iv,
250 NULL)
251
252static int dev_crypto_rc4_init_key(EVP_CIPHER_CTX *ctx,
253 const unsigned char *key,
254 const unsigned char *iv, int enc)
255 { return dev_crypto_init_key(ctx,CRYPTO_ARC4,key,16); }
256
257static const EVP_CIPHER r4_cipher=
258 {
259 NID_rc4,
260 1,16,0, /* FIXME: key should be up to 256 bytes */
261 EVP_CIPH_VARIABLE_LENGTH,
262 dev_crypto_rc4_init_key,
263 dev_crypto_cipher,
264 dev_crypto_cleanup,
265 sizeof(session_op),
266 NULL,
267 NULL,
268 NULL
269 };
270
271const EVP_CIPHER *EVP_dev_crypto_rc4(void)
272 { return &r4_cipher; }
273
274typedef struct
275 {
276 session_op sess;
277 char *data;
278 int len;
279 unsigned char md[EVP_MAX_MD_SIZE];
280 } MD_DATA;
281
282static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
283 {
284 if(!dev_crypto_init(&md_data->sess))
285 return 0;
286
287 md_data->len=0;
288 md_data->data=NULL;
289
290 md_data->sess.mac=mac;
291
292 if (ioctl(fd,CIOCGSESSION,&md_data->sess) == -1)
293 {
294 err("CIOCGSESSION failed");
295 return 0;
296 }
297 return 1;
298 }
299
300static int dev_crypto_cleanup_digest(MD_DATA *md_data)
301 {
302 if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
303 {
304 err("CIOCFSESSION failed");
305 return 0;
306 }
307
308 return 1;
309 }
310
311/* FIXME: if device can do chained MACs, then don't accumulate */
312/* FIXME: move accumulation to the framework */
313static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
314 { return dev_crypto_init_digest(ctx->md_data,CRYPTO_MD5); }
315
316static int do_digest(int ses,unsigned char *md,const void *data,int len)
317 {
318 struct crypt_op cryp;
319 static unsigned char md5zero[16]=
320 {
321 0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,
322 0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e
323 };
324
325 /* some cards can't do zero length */
326 if(!len)
327 {
328 memcpy(md,md5zero,16);
329 return 1;
330 }
331
332 memset(&cryp,'\0',sizeof cryp);
333 cryp.ses=ses;
334 cryp.op=COP_ENCRYPT;/* required to do the MAC rather than check it */
335 cryp.len=len;
336 cryp.src=(caddr_t)data;
337 cryp.dst=(caddr_t)data; // FIXME!!!
338 cryp.mac=(caddr_t)md;
339
340 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
341 {
342 if(errno == EINVAL) /* buffer is misaligned */
343 {
344 char *dcopy;
345
346 dcopy=OPENSSL_malloc(len);
347 memcpy(dcopy,data,len);
348 cryp.src=dcopy;
349 cryp.dst=cryp.src; // FIXME!!!
350
351 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
352 {
353 err("CIOCCRYPT(MAC2) failed");
354 abort();
355 return 0;
356 }
357 OPENSSL_free(dcopy);
358 }
359 else
360 {
361 err("CIOCCRYPT(MAC) failed");
362 abort();
363 return 0;
364 }
365 }
366 // printf("done\n");
367
368 return 1;
369 }
370
371static int dev_crypto_md5_update(EVP_MD_CTX *ctx,const void *data,
372 unsigned long len)
373 {
374 MD_DATA *md_data=ctx->md_data;
375
376 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
377 return do_digest(md_data->sess.ses,md_data->md,data,len);
378
379 md_data->data=OPENSSL_realloc(md_data->data,md_data->len+len);
380 memcpy(md_data->data+md_data->len,data,len);
381 md_data->len+=len;
382
383 return 1;
384 }
385
386static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md)
387 {
388 int ret;
389 MD_DATA *md_data=ctx->md_data;
390
391 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
392 {
393 memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
394 ret=1;
395 }
396 else
397 {
398 ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
399 OPENSSL_free(md_data->data);
400 md_data->data=NULL;
401 md_data->len=0;
402 }
403
404 return ret;
405 }
406
407static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
408 {
409 const MD_DATA *from_md=from->md_data;
410 MD_DATA *to_md=to->md_data;
411
412 // How do we copy sessions?
413 assert(from->digest->flags&EVP_MD_FLAG_ONESHOT);
414
415 to_md->data=OPENSSL_malloc(from_md->len);
416 memcpy(to_md->data,from_md->data,from_md->len);
417
418 return 1;
419 }
420
421static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
422 {
423 return dev_crypto_cleanup_digest(ctx->md_data);
424 }
425
426static const EVP_MD md5_md=
427 {
428 NID_md5,
429 NID_md5WithRSAEncryption,
430 MD5_DIGEST_LENGTH,
431 EVP_MD_FLAG_ONESHOT, // XXX: set according to device info...
432 dev_crypto_md5_init,
433 dev_crypto_md5_update,
434 dev_crypto_md5_final,
435 dev_crypto_md5_copy,
436 dev_crypto_md5_cleanup,
437 EVP_PKEY_RSA_method,
438 MD5_CBLOCK,
439 sizeof(MD_DATA),
440 };
441
442const EVP_MD *EVP_dev_crypto_md5(void)
443 { return &md5_md; }
444
445#endif
446#endif
diff --git a/src/lib/libssl/src/crypto/evp/p5_crpt.c b/src/lib/libssl/src/crypto/evp/p5_crpt.c
new file mode 100644
index 0000000000..e3dae52d4d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p5_crpt.c
@@ -0,0 +1,146 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include "cryptlib.h"
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef NO_DES
71# ifndef NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef NO_RC2
85# ifndef NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 EVP_DigestInit (&ctx, md);
129 EVP_DigestUpdate (&ctx, pass, passlen);
130 EVP_DigestUpdate (&ctx, salt, saltlen);
131 PBEPARAM_free(pbe);
132 EVP_DigestFinal (&ctx, md_tmp, NULL);
133 for (i = 1; i < iter; i++) {
134 EVP_DigestInit(&ctx, md);
135 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
136 EVP_DigestFinal (&ctx, md_tmp, NULL);
137 }
138 memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher));
139 memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
140 EVP_CIPHER_iv_length(cipher));
141 EVP_CipherInit(cctx, cipher, key, iv, en_de);
142 memset(md_tmp, 0, EVP_MAX_MD_SIZE);
143 memset(key, 0, EVP_MAX_KEY_LENGTH);
144 memset(iv, 0, EVP_MAX_IV_LENGTH);
145 return 1;
146}
diff --git a/src/lib/libssl/src/crypto/evp/p5_crpt2.c b/src/lib/libssl/src/crypto/evp/p5_crpt2.c
new file mode 100644
index 0000000000..27a2c518be
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p5_crpt2.c
@@ -0,0 +1,247 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(NO_HMAC) && !defined(NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include "cryptlib.h"
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87 p = out;
88 tkeylen = keylen;
89 if(passlen == -1) passlen = strlen(pass);
90 while(tkeylen) {
91 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
92 else cplen = tkeylen;
93 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
94 * but just in case...
95 */
96 itmp[0] = (unsigned char)((i >> 24) & 0xff);
97 itmp[1] = (unsigned char)((i >> 16) & 0xff);
98 itmp[2] = (unsigned char)((i >> 8) & 0xff);
99 itmp[3] = (unsigned char)(i & 0xff);
100 HMAC_Init(&hctx, pass, passlen, EVP_sha1());
101 HMAC_Update(&hctx, salt, saltlen);
102 HMAC_Update(&hctx, itmp, 4);
103 HMAC_Final(&hctx, digtmp, NULL);
104 memcpy(p, digtmp, cplen);
105 for(j = 1; j < iter; j++) {
106 HMAC(EVP_sha1(), pass, passlen,
107 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
108 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
109 }
110 tkeylen-= cplen;
111 i++;
112 p+= cplen;
113 }
114 HMAC_cleanup(&hctx);
115#ifdef DEBUG_PKCS5V2
116 fprintf(stderr, "Password:\n");
117 h__dump (pass, passlen);
118 fprintf(stderr, "Salt:\n");
119 h__dump (salt, saltlen);
120 fprintf(stderr, "Iteration count %d\n", iter);
121 fprintf(stderr, "Key:\n");
122 h__dump (out, keylen);
123#endif
124 return 1;
125}
126
127#ifdef DO_TEST
128main()
129{
130 unsigned char out[4];
131 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
132 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
133 fprintf(stderr, "Out %02X %02X %02X %02X\n",
134 out[0], out[1], out[2], out[3]);
135}
136
137#endif
138
139/* Now the key derivation function itself. This is a bit evil because
140 * it has to check the ASN1 parameters are valid: and there are quite a
141 * few of them...
142 */
143
144int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
145 ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md,
146 int en_de)
147{
148 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
149 int saltlen, keylen, iter, plen;
150 PBE2PARAM *pbe2 = NULL;
151 const EVP_CIPHER *cipher;
152 PBKDF2PARAM *kdf = NULL;
153
154 pbuf = param->value.sequence->data;
155 plen = param->value.sequence->length;
156 if(!param || (param->type != V_ASN1_SEQUENCE) ||
157 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
158 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
159 return 0;
160 }
161
162 /* See if we recognise the key derivation function */
163
164 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
165 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
166 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
167 goto err;
168 }
169
170 /* lets see if we recognise the encryption algorithm.
171 */
172
173 cipher = EVP_get_cipherbyname(
174 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
175
176 if(!cipher) {
177 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
178 EVP_R_UNSUPPORTED_CIPHER);
179 goto err;
180 }
181
182 /* Fixup cipher based on AlgorithmIdentifier */
183 EVP_CipherInit(ctx, cipher, NULL, NULL, en_de);
184 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
185 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
186 EVP_R_CIPHER_PARAMETER_ERROR);
187 goto err;
188 }
189 keylen = EVP_CIPHER_CTX_key_length(ctx);
190
191 /* Now decode key derivation function */
192
193 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
194 plen = pbe2->keyfunc->parameter->value.sequence->length;
195 if(!pbe2->keyfunc->parameter ||
196 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
197 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
198 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
199 goto err;
200 }
201
202 PBE2PARAM_free(pbe2);
203 pbe2 = NULL;
204
205 /* Now check the parameters of the kdf */
206
207 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
208 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
209 EVP_R_UNSUPPORTED_KEYLENGTH);
210 goto err;
211 }
212
213 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
214 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
215 goto err;
216 }
217
218 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
219 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
220 EVP_R_UNSUPPORTED_SALT_TYPE);
221 goto err;
222 }
223
224 /* it seems that its all OK */
225 salt = kdf->salt->value.octet_string->data;
226 saltlen = kdf->salt->value.octet_string->length;
227 iter = ASN1_INTEGER_get(kdf->iter);
228 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
229 EVP_CipherInit(ctx, NULL, key, NULL, en_de);
230 memset(key, 0, keylen);
231 PBKDF2PARAM_free(kdf);
232 return 1;
233
234 err:
235 PBE2PARAM_free(pbe2);
236 PBKDF2PARAM_free(kdf);
237 return 0;
238}
239
240#ifdef DEBUG_PKCS5V2
241static void h__dump (const unsigned char *p, int len)
242{
243 for (; len --; p++) fprintf(stderr, "%02X ", *p);
244 fprintf(stderr, "\n");
245}
246#endif
247#endif
diff --git a/src/lib/libssl/src/crypto/idea/idea.h b/src/lib/libssl/src/crypto/idea/idea.h
new file mode 100644
index 0000000000..ae32f5692e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/idea/idea.h
@@ -0,0 +1,99 @@
1/* crypto/idea/idea.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_IDEA_H
60#define HEADER_IDEA_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_IDEA
67#error IDEA is disabled.
68#endif
69
70#define IDEA_ENCRYPT 1
71#define IDEA_DECRYPT 0
72
73#include <openssl/opensslconf.h> /* IDEA_INT */
74#define IDEA_BLOCK 8
75#define IDEA_KEY_LENGTH 16
76
77typedef struct idea_key_st
78 {
79 IDEA_INT data[9][6];
80 } IDEA_KEY_SCHEDULE;
81
82const char *idea_options(void);
83void idea_ecb_encrypt(unsigned char *in, unsigned char *out,
84 IDEA_KEY_SCHEDULE *ks);
85void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks);
86void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
87void idea_cbc_encrypt(unsigned char *in, unsigned char *out,
88 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
89void idea_cfb64_encrypt(unsigned char *in, unsigned char *out,
90 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
91 int *num,int enc);
92void idea_ofb64_encrypt(unsigned char *in, unsigned char *out,
93 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
94void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libssl/src/crypto/install.com b/src/lib/libssl/src/crypto/install.com
new file mode 100644
index 0000000000..b75d1b44b2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/install.com
@@ -0,0 +1,128 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
23$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
24$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
25$
26$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
27 CREATE/DIR/LOG WRK_SSLROOT:[000000]
28$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN -
29 CREATE/DIR/LOG WRK_SSLVLIB:
30$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLALIB:
32$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLINCLUDE:
34$
35$ SDIRS := ,MD2,MD5,SHA,MDC2,HMAC,RIPEMD,-
36 DES,RC2,RC4,RC5,IDEA,BF,CAST,-
37 BN,RSA,DSA,DH,-
38 BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,-
39 EVP,ASN1,PEM,X509,X509V3,-
40 CONF,TXT_DB,PKCS7,PKCS12,COMP
41$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h
42$ EXHEADER_MD2 := md2.h
43$ EXHEADER_MD5 := md5.h
44$ EXHEADER_SHA := sha.h
45$ EXHEADER_MDC2 := mdc2.h
46$ EXHEADER_HMAC := hmac.h
47$ EXHEADER_RIPEMD := ripemd.h
48$ EXHEADER_DES := des.h
49$ EXHEADER_RC2 := rc2.h
50$ EXHEADER_RC4 := rc4.h
51$ EXHEADER_RC5 := rc5.h
52$ EXHEADER_IDEA := idea.h
53$ EXHEADER_BF := blowfish.h
54$ EXHEADER_CAST := cast.h
55$ EXHEADER_BN := bn.h
56$ EXHEADER_RSA := rsa.h
57$ EXHEADER_DSA := dsa.h
58$ EXHEADER_DH := dh.h
59$ EXHEADER_BUFFER := buffer.h
60$ EXHEADER_BIO := bio.h
61$ EXHEADER_STACK := stack.h,safestack.h
62$ EXHEADER_LHASH := lhash.h
63$ EXHEADER_RAND := rand.h
64$ EXHEADER_ERR := err.h
65$ EXHEADER_OBJECTS := objects.h
66$ EXHEADER_EVP := evp.h
67$ EXHEADER_ASN1 := asn1.h,asn1_mac.h
68$ EXHEADER_PEM := pem.h,pem2.h
69$ EXHEADER_X509 := x509.h,x509_vfy.h
70$ EXHEADER_X509V3 := x509v3.h
71$ EXHEADER_CONF := conf.h
72$ EXHEADER_TXT_DB := txt_db.h
73$ EXHEADER_PKCS7 := pkcs7.h
74$ EXHEADER_PKCS12 := pkcs12.h
75$ EXHEADER_COMP := comp.h
76$ LIBS := LIBCRYPTO
77$
78$ VEXE_DIR := [-.VAX.EXE.CRYPTO]
79$ AEXE_DIR := [-.AXP.EXE.CRYPTO]
80$
81$ I = 0
82$ LOOP_SDIRS:
83$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
84$ I = I + 1
85$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
86$ tmp = EXHEADER_'D'
87$ IF D .EQS. ""
88$ THEN
89$ COPY 'tmp' WRK_SSLINCLUDE: /LOG
90$ ELSE
91$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
92$ ENDIF
93$ GOTO LOOP_SDIRS
94$ LOOP_SDIRS_END:
95$
96$ I = 0
97$ LOOP_LIB:
98$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
99$ I = I + 1
100$ IF E .EQS. "," THEN GOTO LOOP_LIB_END
101$ SET NOON
102$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. ""
103$ THEN
104$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log
105$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB
106$ ENDIF
107$ ! Preparing for the time when we have shareable images
108$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
109$ THEN
110$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log
111$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE
112$ ENDIF
113$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. ""
114$ THEN
115$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log
116$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB
117$ ENDIF
118$ ! Preparing for the time when we have shareable images
119$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
120$ THEN
121$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log
122$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE
123$ ENDIF
124$ SET ON
125$ GOTO LOOP_LIB
126$ LOOP_LIB_END:
127$
128$ EXIT
diff --git a/src/lib/libssl/src/crypto/krb5/krb5_asn.c b/src/lib/libssl/src/crypto/krb5/krb5_asn.c
new file mode 100644
index 0000000000..1fb741d2a0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/krb5/krb5_asn.c
@@ -0,0 +1,167 @@
1/* krb5_asn.c */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/krb5_asn.h>
61
62
63ASN1_SEQUENCE(KRB5_ENCDATA) = {
64 ASN1_EXP(KRB5_ENCDATA, etype, ASN1_INTEGER, 0),
65 ASN1_EXP_OPT(KRB5_ENCDATA, kvno, ASN1_INTEGER, 1),
66 ASN1_EXP(KRB5_ENCDATA, cipher, ASN1_OCTET_STRING,2)
67} ASN1_SEQUENCE_END(KRB5_ENCDATA)
68
69IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCDATA)
70
71
72ASN1_SEQUENCE(KRB5_PRINCNAME) = {
73 ASN1_EXP(KRB5_PRINCNAME, nametype, ASN1_INTEGER, 0),
74 ASN1_EXP_SEQUENCE_OF(KRB5_PRINCNAME, namestring, ASN1_GENERALSTRING, 1)
75} ASN1_SEQUENCE_END(KRB5_PRINCNAME)
76
77IMPLEMENT_ASN1_FUNCTIONS(KRB5_PRINCNAME)
78
79
80/* [APPLICATION 1] = 0x61 */
81ASN1_SEQUENCE(KRB5_TKTBODY) = {
82 ASN1_EXP(KRB5_TKTBODY, tktvno, ASN1_INTEGER, 0),
83 ASN1_EXP(KRB5_TKTBODY, realm, ASN1_GENERALSTRING, 1),
84 ASN1_EXP(KRB5_TKTBODY, sname, KRB5_PRINCNAME, 2),
85 ASN1_EXP(KRB5_TKTBODY, encdata, KRB5_ENCDATA, 3)
86} ASN1_SEQUENCE_END(KRB5_TKTBODY)
87
88IMPLEMENT_ASN1_FUNCTIONS(KRB5_TKTBODY)
89
90
91ASN1_ITEM_TEMPLATE(KRB5_TICKET) =
92 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1,
93 KRB5_TICKET, KRB5_TKTBODY)
94ASN1_ITEM_TEMPLATE_END(KRB5_TICKET)
95
96IMPLEMENT_ASN1_FUNCTIONS(KRB5_TICKET)
97
98
99/* [APPLICATION 14] = 0x6e */
100ASN1_SEQUENCE(KRB5_APREQBODY) = {
101 ASN1_EXP(KRB5_APREQBODY, pvno, ASN1_INTEGER, 0),
102 ASN1_EXP(KRB5_APREQBODY, msgtype, ASN1_INTEGER, 1),
103 ASN1_EXP(KRB5_APREQBODY, apoptions, ASN1_BIT_STRING, 2),
104 ASN1_EXP(KRB5_APREQBODY, ticket, KRB5_TICKET, 3),
105 ASN1_EXP(KRB5_APREQBODY, authenticator, KRB5_ENCDATA, 4),
106} ASN1_SEQUENCE_END(KRB5_APREQBODY)
107
108IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQBODY)
109
110ASN1_ITEM_TEMPLATE(KRB5_APREQ) =
111 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 14,
112 KRB5_APREQ, KRB5_APREQBODY)
113ASN1_ITEM_TEMPLATE_END(KRB5_APREQ)
114
115IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQ)
116
117
118/* Authenticator stuff */
119
120ASN1_SEQUENCE(KRB5_CHECKSUM) = {
121 ASN1_EXP(KRB5_CHECKSUM, ctype, ASN1_INTEGER, 0),
122 ASN1_EXP(KRB5_CHECKSUM, checksum, ASN1_OCTET_STRING,1)
123} ASN1_SEQUENCE_END(KRB5_CHECKSUM)
124
125IMPLEMENT_ASN1_FUNCTIONS(KRB5_CHECKSUM)
126
127
128ASN1_SEQUENCE(KRB5_ENCKEY) = {
129 ASN1_EXP(KRB5_ENCKEY, ktype, ASN1_INTEGER, 0),
130 ASN1_EXP(KRB5_ENCKEY, keyvalue, ASN1_OCTET_STRING,1)
131} ASN1_SEQUENCE_END(KRB5_ENCKEY)
132
133IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCKEY)
134
135
136/* SEQ OF SEQ; see ASN1_EXP_SEQUENCE_OF_OPT() below */
137ASN1_SEQUENCE(KRB5_AUTHDATA) = {
138 ASN1_EXP(KRB5_AUTHDATA, adtype, ASN1_INTEGER, 0),
139 ASN1_EXP(KRB5_AUTHDATA, addata, ASN1_OCTET_STRING,1)
140} ASN1_SEQUENCE_END(KRB5_AUTHDATA)
141
142IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHDATA)
143
144
145/* [APPLICATION 2] = 0x62 */
146ASN1_SEQUENCE(KRB5_AUTHENTBODY) = {
147 ASN1_EXP(KRB5_AUTHENTBODY, avno, ASN1_INTEGER, 0),
148 ASN1_EXP(KRB5_AUTHENTBODY, crealm, ASN1_GENERALSTRING, 1),
149 ASN1_EXP(KRB5_AUTHENTBODY, cname, KRB5_PRINCNAME, 2),
150 ASN1_EXP_OPT(KRB5_AUTHENTBODY, cksum, KRB5_CHECKSUM, 3),
151 ASN1_EXP(KRB5_AUTHENTBODY, cusec, ASN1_INTEGER, 4),
152 ASN1_EXP(KRB5_AUTHENTBODY, ctime, ASN1_GENERALIZEDTIME, 5),
153 ASN1_EXP_OPT(KRB5_AUTHENTBODY, subkey, KRB5_ENCKEY, 6),
154 ASN1_EXP_OPT(KRB5_AUTHENTBODY, seqnum, ASN1_INTEGER, 7),
155 ASN1_EXP_SEQUENCE_OF_OPT
156 (KRB5_AUTHENTBODY, authorization, KRB5_AUTHDATA, 8),
157} ASN1_SEQUENCE_END(KRB5_AUTHENTBODY)
158
159IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
160
161ASN1_ITEM_TEMPLATE(KRB5_AUTHENT) =
162 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 2,
163 KRB5_AUTHENT, KRB5_AUTHENTBODY)
164ASN1_ITEM_TEMPLATE_END(KRB5_AUTHENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENT)
167
diff --git a/src/lib/libssl/src/crypto/krb5/krb5_asn.h b/src/lib/libssl/src/crypto/krb5/krb5_asn.h
new file mode 100644
index 0000000000..3329477b07
--- /dev/null
+++ b/src/lib/libssl/src/crypto/krb5/krb5_asn.h
@@ -0,0 +1,256 @@
1/* krb5_asn.h */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5
6/* ====================================================================
7 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_KRB5_ASN_H
61#define HEADER_KRB5_ASN_H
62
63/*
64#include <krb5.h>
65*/
66#include <openssl/safestack.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72
73/* ASN.1 from Kerberos RFC 1510
74*/
75
76/* EncryptedData ::= SEQUENCE {
77** etype[0] INTEGER, -- EncryptionType
78** kvno[1] INTEGER OPTIONAL,
79** cipher[2] OCTET STRING -- ciphertext
80** }
81*/
82typedef struct krb5_encdata_st
83 {
84 ASN1_INTEGER *etype;
85 ASN1_INTEGER *kvno;
86 ASN1_OCTET_STRING *cipher;
87 } KRB5_ENCDATA;
88
89DECLARE_STACK_OF(KRB5_ENCDATA)
90
91/* PrincipalName ::= SEQUENCE {
92** name-type[0] INTEGER,
93** name-string[1] SEQUENCE OF GeneralString
94** }
95*/
96typedef struct krb5_princname_st
97 {
98 ASN1_INTEGER *nametype;
99 STACK_OF(ASN1_GENERALSTRING) *namestring;
100 } KRB5_PRINCNAME;
101
102DECLARE_STACK_OF(KRB5_PRINCNAME)
103
104
105/* Ticket ::= [APPLICATION 1] SEQUENCE {
106** tkt-vno[0] INTEGER,
107** realm[1] Realm,
108** sname[2] PrincipalName,
109** enc-part[3] EncryptedData
110** }
111*/
112typedef struct krb5_tktbody_st
113 {
114 ASN1_INTEGER *tktvno;
115 ASN1_GENERALSTRING *realm;
116 KRB5_PRINCNAME *sname;
117 KRB5_ENCDATA *encdata;
118 } KRB5_TKTBODY;
119
120typedef STACK_OF(KRB5_TKTBODY) KRB5_TICKET;
121DECLARE_STACK_OF(KRB5_TKTBODY)
122
123
124/* AP-REQ ::= [APPLICATION 14] SEQUENCE {
125** pvno[0] INTEGER,
126** msg-type[1] INTEGER,
127** ap-options[2] APOptions,
128** ticket[3] Ticket,
129** authenticator[4] EncryptedData
130** }
131**
132** APOptions ::= BIT STRING {
133** reserved(0), use-session-key(1), mutual-required(2) }
134*/
135typedef struct krb5_ap_req_st
136 {
137 ASN1_INTEGER *pvno;
138 ASN1_INTEGER *msgtype;
139 ASN1_BIT_STRING *apoptions;
140 KRB5_TICKET *ticket;
141 KRB5_ENCDATA *authenticator;
142 } KRB5_APREQBODY;
143
144typedef STACK_OF(KRB5_APREQBODY) KRB5_APREQ;
145DECLARE_STACK_OF(KRB5_APREQBODY)
146
147
148/* Authenticator Stuff */
149
150
151/* Checksum ::= SEQUENCE {
152** cksumtype[0] INTEGER,
153** checksum[1] OCTET STRING
154** }
155*/
156typedef struct krb5_checksum_st
157 {
158 ASN1_INTEGER *ctype;
159 ASN1_OCTET_STRING *checksum;
160 } KRB5_CHECKSUM;
161
162DECLARE_STACK_OF(KRB5_CHECKSUM)
163
164
165/* EncryptionKey ::= SEQUENCE {
166** keytype[0] INTEGER,
167** keyvalue[1] OCTET STRING
168** }
169*/
170typedef struct krb5_encryptionkey_st
171 {
172 ASN1_INTEGER *ktype;
173 ASN1_OCTET_STRING *keyvalue;
174 } KRB5_ENCKEY;
175
176DECLARE_STACK_OF(KRB5_ENCKEY)
177
178
179/* AuthorizationData ::= SEQUENCE OF SEQUENCE {
180** ad-type[0] INTEGER,
181** ad-data[1] OCTET STRING
182** }
183*/
184typedef struct krb5_authorization_st
185 {
186 ASN1_INTEGER *adtype;
187 ASN1_OCTET_STRING *addata;
188 } KRB5_AUTHDATA;
189
190DECLARE_STACK_OF(KRB5_AUTHDATA)
191
192
193/* -- Unencrypted authenticator
194** Authenticator ::= [APPLICATION 2] SEQUENCE {
195** authenticator-vno[0] INTEGER,
196** crealm[1] Realm,
197** cname[2] PrincipalName,
198** cksum[3] Checksum OPTIONAL,
199** cusec[4] INTEGER,
200** ctime[5] KerberosTime,
201** subkey[6] EncryptionKey OPTIONAL,
202** seq-number[7] INTEGER OPTIONAL,
203** authorization-data[8] AuthorizationData OPTIONAL
204** }
205*/
206typedef struct krb5_authenticator_st
207 {
208 ASN1_INTEGER *avno;
209 ASN1_GENERALSTRING *crealm;
210 KRB5_PRINCNAME *cname;
211 KRB5_CHECKSUM *cksum;
212 ASN1_INTEGER *cusec;
213 ASN1_GENERALIZEDTIME *ctime;
214 KRB5_ENCKEY *subkey;
215 ASN1_INTEGER *seqnum;
216 KRB5_AUTHDATA *authorization;
217 } KRB5_AUTHENTBODY;
218
219typedef STACK_OF(KRB5_AUTHENTBODY) KRB5_AUTHENT;
220DECLARE_STACK_OF(KRB5_AUTHENTBODY)
221
222
223/* DECLARE_ASN1_FUNCTIONS(type) = DECLARE_ASN1_FUNCTIONS_name(type, type) =
224** type *name##_new(void);
225** void name##_free(type *a);
226** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) =
227** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) =
228** type *d2i_##name(type **a, unsigned char **in, long len);
229** int i2d_##name(type *a, unsigned char **out);
230** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it
231*/
232
233DECLARE_ASN1_FUNCTIONS(KRB5_ENCDATA)
234DECLARE_ASN1_FUNCTIONS(KRB5_PRINCNAME)
235DECLARE_ASN1_FUNCTIONS(KRB5_TKTBODY)
236DECLARE_ASN1_FUNCTIONS(KRB5_APREQBODY)
237DECLARE_ASN1_FUNCTIONS(KRB5_TICKET)
238DECLARE_ASN1_FUNCTIONS(KRB5_APREQ)
239
240DECLARE_ASN1_FUNCTIONS(KRB5_CHECKSUM)
241DECLARE_ASN1_FUNCTIONS(KRB5_ENCKEY)
242DECLARE_ASN1_FUNCTIONS(KRB5_AUTHDATA)
243DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
244DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENT)
245
246
247/* BEGIN ERROR CODES */
248/* The following lines are auto generated by the script mkerr.pl. Any changes
249 * made after this point may be overwritten when the script is next run.
250 */
251
252#ifdef __cplusplus
253}
254#endif
255#endif
256
diff --git a/src/lib/libssl/src/crypto/md2/md2.h b/src/lib/libssl/src/crypto/md2/md2.h
new file mode 100644
index 0000000000..0d3592506c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md2/md2.h
@@ -0,0 +1,91 @@
1/* crypto/md/md2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD2_H
60#define HEADER_MD2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_MD2
67#error MD2 is disabled.
68#endif
69
70#define MD2_DIGEST_LENGTH 16
71#define MD2_BLOCK 16
72#include <openssl/opensslconf.h> /* MD2_INT */
73
74typedef struct MD2state_st
75 {
76 int num;
77 unsigned char data[MD2_BLOCK];
78 MD2_INT cksm[MD2_BLOCK];
79 MD2_INT state[MD2_BLOCK];
80 } MD2_CTX;
81
82const char *MD2_options(void);
83void MD2_Init(MD2_CTX *c);
84void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len);
85void MD2_Final(unsigned char *md, MD2_CTX *c);
86unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md);
87#ifdef __cplusplus
88}
89#endif
90
91#endif
diff --git a/src/lib/libssl/src/crypto/md32_common.h b/src/lib/libssl/src/crypto/md32_common.h
new file mode 100644
index 0000000000..2b91f9eef2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md32_common.h
@@ -0,0 +1,594 @@
1/* crypto/md32_common.h */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 * This is a generic 32 bit "collector" for message digest algorithms.
58 * Whenever needed it collects input character stream into chunks of
59 * 32 bit values and invokes a block function that performs actual hash
60 * calculations.
61 *
62 * Porting guide.
63 *
64 * Obligatory macros:
65 *
66 * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
67 * this macro defines byte order of input stream.
68 * HASH_CBLOCK
69 * size of a unit chunk HASH_BLOCK operates on.
70 * HASH_LONG
71 * has to be at lest 32 bit wide, if it's wider, then
72 * HASH_LONG_LOG2 *has to* be defined along
73 * HASH_CTX
74 * context structure that at least contains following
75 * members:
76 * typedef struct {
77 * ...
78 * HASH_LONG Nl,Nh;
79 * HASH_LONG data[HASH_LBLOCK];
80 * int num;
81 * ...
82 * } HASH_CTX;
83 * HASH_UPDATE
84 * name of "Update" function, implemented here.
85 * HASH_TRANSFORM
86 * name of "Transform" function, implemented here.
87 * HASH_FINAL
88 * name of "Final" function, implemented here.
89 * HASH_BLOCK_HOST_ORDER
90 * name of "block" function treating *aligned* input message
91 * in host byte order, implemented externally.
92 * HASH_BLOCK_DATA_ORDER
93 * name of "block" function treating *unaligned* input message
94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same
96 * "endianess").
97 *
98 * Optional macros:
99 *
100 * B_ENDIAN or L_ENDIAN
101 * defines host byte-order.
102 * HASH_LONG_LOG2
103 * defaults to 2 if not states otherwise.
104 * HASH_LBLOCK
105 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
106 * HASH_BLOCK_DATA_ORDER_ALIGNED
107 * alternative "block" function capable of treating
108 * aligned input message in original (data) order,
109 * implemented externally.
110 *
111 * MD5 example:
112 *
113 * #define DATA_ORDER_IS_LITTLE_ENDIAN
114 *
115 * #define HASH_LONG MD5_LONG
116 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
117 * #define HASH_CTX MD5_CTX
118 * #define HASH_CBLOCK MD5_CBLOCK
119 * #define HASH_LBLOCK MD5_LBLOCK
120 * #define HASH_UPDATE MD5_Update
121 * #define HASH_TRANSFORM MD5_Transform
122 * #define HASH_FINAL MD5_Final
123 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
124 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
125 *
126 * <appro@fy.chalmers.se>
127 */
128
129#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
130#error "DATA_ORDER must be defined!"
131#endif
132
133#ifndef HASH_CBLOCK
134#error "HASH_CBLOCK must be defined!"
135#endif
136#ifndef HASH_LONG
137#error "HASH_LONG must be defined!"
138#endif
139#ifndef HASH_CTX
140#error "HASH_CTX must be defined!"
141#endif
142
143#ifndef HASH_UPDATE
144#error "HASH_UPDATE must be defined!"
145#endif
146#ifndef HASH_TRANSFORM
147#error "HASH_TRANSFORM must be defined!"
148#endif
149#ifndef HASH_FINAL
150#error "HASH_FINAL must be defined!"
151#endif
152
153#ifndef HASH_BLOCK_HOST_ORDER
154#error "HASH_BLOCK_HOST_ORDER must be defined!"
155#endif
156
157#if 0
158/*
159 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
160 * isn't defined.
161 */
162#ifndef HASH_BLOCK_DATA_ORDER
163#error "HASH_BLOCK_DATA_ORDER must be defined!"
164#endif
165#endif
166
167#ifndef HASH_LBLOCK
168#define HASH_LBLOCK (HASH_CBLOCK/4)
169#endif
170
171#ifndef HASH_LONG_LOG2
172#define HASH_LONG_LOG2 2
173#endif
174
175/*
176 * Engage compiler specific rotate intrinsic function if available.
177 */
178#undef ROTATE
179#ifndef PEDANTIC
180# if defined(_MSC_VER)
181# define ROTATE(a,n) _lrotl(a,n)
182# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
183 /*
184 * Some GNU C inline assembler templates. Note that these are
185 * rotates by *constant* number of bits! But that's exactly
186 * what we need here...
187 *
188 * <appro@fy.chalmers.se>
189 */
190# if defined(__i386)
191# define ROTATE(a,n) ({ register unsigned int ret; \
192 asm volatile ( \
193 "roll %1,%0" \
194 : "=r"(ret) \
195 : "I"(n), "0"(a) \
196 : "cc"); \
197 ret; \
198 })
199# elif defined(__powerpc)
200# define ROTATE(a,n) ({ register unsigned int ret; \
201 asm volatile ( \
202 "rlwinm %0,%1,%2,0,31" \
203 : "=r"(ret) \
204 : "r"(a), "I"(n)); \
205 ret; \
206 })
207# endif
208# endif
209
210/*
211 * Engage compiler specific "fetch in reverse byte order"
212 * intrinsic function if available.
213 */
214# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
215 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
216# if defined(__i386) && !defined(I386_ONLY)
217# define BE_FETCH32(a) ({ register unsigned int l=(a);\
218 asm volatile ( \
219 "bswapl %0" \
220 : "=r"(l) : "0"(l)); \
221 l; \
222 })
223# elif defined(__powerpc)
224# define LE_FETCH32(a) ({ register unsigned int l; \
225 asm volatile ( \
226 "lwbrx %0,0,%1" \
227 : "=r"(l) \
228 : "r"(a)); \
229 l; \
230 })
231
232# elif defined(__sparc) && defined(ULTRASPARC)
233# define LE_FETCH32(a) ({ register unsigned int l; \
234 asm volatile ( \
235 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
236 : "=r"(l) \
237 : "r"(a)); \
238 l; \
239 })
240# endif
241# endif
242#endif /* PEDANTIC */
243
244#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
245/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
246#ifdef ROTATE
247/* 5 instructions with rotate instruction, else 9 */
248#define REVERSE_FETCH32(a,l) ( \
249 l=*(const HASH_LONG *)(a), \
250 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
251 )
252#else
253/* 6 instructions with rotate instruction, else 8 */
254#define REVERSE_FETCH32(a,l) ( \
255 l=*(const HASH_LONG *)(a), \
256 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
257 ROTATE(l,16) \
258 )
259/*
260 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
261 * It's rewritten as above for two reasons:
262 * - RISCs aren't good at long constants and have to explicitely
263 * compose 'em with several (well, usually 2) instructions in a
264 * register before performing the actual operation and (as you
265 * already realized:-) having same constant should inspire the
266 * compiler to permanently allocate the only register for it;
267 * - most modern CPUs have two ALUs, but usually only one has
268 * circuitry for shifts:-( this minor tweak inspires compiler
269 * to schedule shift instructions in a better way...
270 *
271 * <appro@fy.chalmers.se>
272 */
273#endif
274#endif
275
276#ifndef ROTATE
277#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
278#endif
279
280/*
281 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
282 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
283 * and host are of the same "endianess". It's possible to mask
284 * this with blank #define HASH_BLOCK_DATA_ORDER though...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#if defined(B_ENDIAN)
289# if defined(DATA_ORDER_IS_BIG_ENDIAN)
290# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
291# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
292# endif
293# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
294# ifndef HOST_FETCH32
295# ifdef LE_FETCH32
296# define HOST_FETCH32(p,l) LE_FETCH32(p)
297# elif defined(REVERSE_FETCH32)
298# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
299# endif
300# endif
301# endif
302#elif defined(L_ENDIAN)
303# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
304# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
305# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
306# endif
307# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
308# ifndef HOST_FETCH32
309# ifdef BE_FETCH32
310# define HOST_FETCH32(p,l) BE_FETCH32(p)
311# elif defined(REVERSE_FETCH32)
312# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
313# endif
314# endif
315# endif
316#endif
317
318#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
319#ifndef HASH_BLOCK_DATA_ORDER
320#error "HASH_BLOCK_DATA_ORDER must be defined!"
321#endif
322#endif
323
324#if defined(DATA_ORDER_IS_BIG_ENDIAN)
325
326#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
327 l|=(((unsigned long)(*((c)++)))<<16), \
328 l|=(((unsigned long)(*((c)++)))<< 8), \
329 l|=(((unsigned long)(*((c)++))) ), \
330 l)
331#define HOST_p_c2l(c,l,n) { \
332 switch (n) { \
333 case 0: l =((unsigned long)(*((c)++)))<<24; \
334 case 1: l|=((unsigned long)(*((c)++)))<<16; \
335 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
336 case 3: l|=((unsigned long)(*((c)++))); \
337 } }
338#define HOST_p_c2l_p(c,l,sc,len) { \
339 switch (sc) { \
340 case 0: l =((unsigned long)(*((c)++)))<<24; \
341 if (--len == 0) break; \
342 case 1: l|=((unsigned long)(*((c)++)))<<16; \
343 if (--len == 0) break; \
344 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
345 } }
346/* NOTE the pointer is not incremented at the end of this */
347#define HOST_c2l_p(c,l,n) { \
348 l=0; (c)+=n; \
349 switch (n) { \
350 case 3: l =((unsigned long)(*(--(c))))<< 8; \
351 case 2: l|=((unsigned long)(*(--(c))))<<16; \
352 case 1: l|=((unsigned long)(*(--(c))))<<24; \
353 } }
354#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
355 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
356 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
357 *((c)++)=(unsigned char)(((l) )&0xff), \
358 l)
359
360#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
361
362#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
363 l|=(((unsigned long)(*((c)++)))<< 8), \
364 l|=(((unsigned long)(*((c)++)))<<16), \
365 l|=(((unsigned long)(*((c)++)))<<24), \
366 l)
367#define HOST_p_c2l(c,l,n) { \
368 switch (n) { \
369 case 0: l =((unsigned long)(*((c)++))); \
370 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
371 case 2: l|=((unsigned long)(*((c)++)))<<16; \
372 case 3: l|=((unsigned long)(*((c)++)))<<24; \
373 } }
374#define HOST_p_c2l_p(c,l,sc,len) { \
375 switch (sc) { \
376 case 0: l =((unsigned long)(*((c)++))); \
377 if (--len == 0) break; \
378 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
379 if (--len == 0) break; \
380 case 2: l|=((unsigned long)(*((c)++)))<<16; \
381 } }
382/* NOTE the pointer is not incremented at the end of this */
383#define HOST_c2l_p(c,l,n) { \
384 l=0; (c)+=n; \
385 switch (n) { \
386 case 3: l =((unsigned long)(*(--(c))))<<16; \
387 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
388 case 1: l|=((unsigned long)(*(--(c)))); \
389 } }
390#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
391 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
392 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
393 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
394 l)
395
396#endif
397
398/*
399 * Time for some action:-)
400 */
401
402void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len)
403 {
404 register HASH_LONG * p;
405 register unsigned long l;
406 int sw,sc,ew,ec;
407
408 if (len==0) return;
409
410 l=(c->Nl+(len<<3))&0xffffffffL;
411 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
412 * Wei Dai <weidai@eskimo.com> for pointing it out. */
413 if (l < c->Nl) /* overflow */
414 c->Nh++;
415 c->Nh+=(len>>29);
416 c->Nl=l;
417
418 if (c->num != 0)
419 {
420 p=c->data;
421 sw=c->num>>2;
422 sc=c->num&0x03;
423
424 if ((c->num+len) >= HASH_CBLOCK)
425 {
426 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
427 for (; sw<HASH_LBLOCK; sw++)
428 {
429 HOST_c2l(data,l); p[sw]=l;
430 }
431 HASH_BLOCK_HOST_ORDER (c,p,1);
432 len-=(HASH_CBLOCK-c->num);
433 c->num=0;
434 /* drop through and do the rest */
435 }
436 else
437 {
438 c->num+=len;
439 if ((sc+len) < 4) /* ugly, add char's to a word */
440 {
441 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
442 }
443 else
444 {
445 ew=(c->num>>2);
446 ec=(c->num&0x03);
447 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
448 for (; sw < ew; sw++)
449 {
450 HOST_c2l(data,l); p[sw]=l;
451 }
452 if (ec)
453 {
454 HOST_c2l_p(data,l,ec); p[sw]=l;
455 }
456 }
457 return;
458 }
459 }
460
461 sw=len/HASH_CBLOCK;
462 if (sw > 0)
463 {
464#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
465 /*
466 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
467 * only if sizeof(HASH_LONG)==4.
468 */
469 if ((((unsigned long)data)%4) == 0)
470 {
471 /* data is properly aligned so that we can cast it: */
472 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
473 sw*=HASH_CBLOCK;
474 data+=sw;
475 len-=sw;
476 }
477 else
478#if !defined(HASH_BLOCK_DATA_ORDER)
479 while (sw--)
480 {
481 memcpy (p=c->data,data,HASH_CBLOCK);
482 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
483 data+=HASH_CBLOCK;
484 len-=HASH_CBLOCK;
485 }
486#endif
487#endif
488#if defined(HASH_BLOCK_DATA_ORDER)
489 {
490 HASH_BLOCK_DATA_ORDER(c,data,sw);
491 sw*=HASH_CBLOCK;
492 data+=sw;
493 len-=sw;
494 }
495#endif
496 }
497
498 if (len!=0)
499 {
500 p = c->data;
501 c->num = len;
502 ew=len>>2; /* words to copy */
503 ec=len&0x03;
504 for (; ew; ew--,p++)
505 {
506 HOST_c2l(data,l); *p=l;
507 }
508 HOST_c2l_p(data,l,ec);
509 *p=l;
510 }
511 }
512
513
514void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
515 {
516#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
517 if ((((unsigned long)data)%4) == 0)
518 /* data is properly aligned so that we can cast it: */
519 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
520 else
521#if !defined(HASH_BLOCK_DATA_ORDER)
522 {
523 memcpy (c->data,data,HASH_CBLOCK);
524 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
525 }
526#endif
527#endif
528#if defined(HASH_BLOCK_DATA_ORDER)
529 HASH_BLOCK_DATA_ORDER (c,data,1);
530#endif
531 }
532
533
534void HASH_FINAL (unsigned char *md, HASH_CTX *c)
535 {
536 register HASH_LONG *p;
537 register unsigned long l;
538 register int i,j;
539 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
540 const unsigned char *cp=end;
541
542 /* c->num should definitly have room for at least one more byte. */
543 p=c->data;
544 i=c->num>>2;
545 j=c->num&0x03;
546
547#if 0
548 /* purify often complains about the following line as an
549 * Uninitialized Memory Read. While this can be true, the
550 * following p_c2l macro will reset l when that case is true.
551 * This is because j&0x03 contains the number of 'valid' bytes
552 * already in p[i]. If and only if j&0x03 == 0, the UMR will
553 * occur but this is also the only time p_c2l will do
554 * l= *(cp++) instead of l|= *(cp++)
555 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
556 * 'potential bug' */
557#ifdef PURIFY
558 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
559#endif
560 l=p[i];
561#else
562 l = (j==0) ? 0 : p[i];
563#endif
564 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
565
566 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
567 {
568 if (i<HASH_LBLOCK) p[i]=0;
569 HASH_BLOCK_HOST_ORDER (c,p,1);
570 i=0;
571 }
572 for (; i<(HASH_LBLOCK-2); i++)
573 p[i]=0;
574
575#if defined(DATA_ORDER_IS_BIG_ENDIAN)
576 p[HASH_LBLOCK-2]=c->Nh;
577 p[HASH_LBLOCK-1]=c->Nl;
578#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
579 p[HASH_LBLOCK-2]=c->Nl;
580 p[HASH_LBLOCK-1]=c->Nh;
581#endif
582 HASH_BLOCK_HOST_ORDER (c,p,1);
583
584 l=c->A; HOST_l2c(l,md);
585 l=c->B; HOST_l2c(l,md);
586 l=c->C; HOST_l2c(l,md);
587 l=c->D; HOST_l2c(l,md);
588
589 c->num=0;
590 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
591 * but I'm not worried :-)
592 memset((void *)c,0,sizeof(HASH_CTX));
593 */
594 }
diff --git a/src/lib/libssl/src/crypto/md4/md4.c b/src/lib/libssl/src/crypto/md4/md4.c
new file mode 100644
index 0000000000..e4b0aac011
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4.c
@@ -0,0 +1,127 @@
1/* crypto/md4/md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/md4.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("MD4(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 MD4_CTX c;
102 unsigned char md[MD4_DIGEST_LENGTH];
103 int fd;
104 int i;
105 static unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 MD4_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,BUFSIZE);
112 if (i <= 0) break;
113 MD4_Update(&c,buf,(unsigned long)i);
114 }
115 MD4_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<MD4_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libssl/src/crypto/md4/md4.h b/src/lib/libssl/src/crypto/md4/md4.h
new file mode 100644
index 0000000000..c794e186db
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4.h
@@ -0,0 +1,114 @@
1/* crypto/md4/md4.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD4_H
60#define HEADER_MD4_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_MD4
67#error MD4 is disabled.
68#endif
69
70/*
71 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !
73 * ! MD4_LONG_LOG2 has to be defined along. !
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 */
76
77#if defined(WIN16) || defined(__LP32__)
78#define MD4_LONG unsigned long
79#elif defined(_CRAY) || defined(__ILP64__)
80#define MD4_LONG unsigned long
81#define MD4_LONG_LOG2 3
82/*
83 * _CRAY note. I could declare short, but I have no idea what impact
84 * does it have on performance on none-T3E machines. I could declare
85 * int, but at least on C90 sizeof(int) can be chosen at compile time.
86 * So I've chosen long...
87 * <appro@fy.chalmers.se>
88 */
89#else
90#define MD4_LONG unsigned int
91#endif
92
93#define MD4_CBLOCK 64
94#define MD4_LBLOCK (MD4_CBLOCK/4)
95#define MD4_DIGEST_LENGTH 16
96
97typedef struct MD4state_st
98 {
99 MD4_LONG A,B,C,D;
100 MD4_LONG Nl,Nh;
101 MD4_LONG data[MD4_LBLOCK];
102 int num;
103 } MD4_CTX;
104
105void MD4_Init(MD4_CTX *c);
106void MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
107void MD4_Final(unsigned char *md, MD4_CTX *c);
108unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
109void MD4_Transform(MD4_CTX *c, const unsigned char *b);
110#ifdef __cplusplus
111}
112#endif
113
114#endif
diff --git a/src/lib/libssl/src/crypto/md4/md4_dgst.c b/src/lib/libssl/src/crypto/md4/md4_dgst.c
new file mode 100644
index 0000000000..81488ae2e2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4_dgst.c
@@ -0,0 +1,285 @@
1/* crypto/md4/md4_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md4_locl.h"
61#include <openssl/opensslv.h>
62
63const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73void MD4_Init(MD4_CTX *c)
74 {
75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B;
77 c->C=INIT_DATA_C;
78 c->D=INIT_DATA_D;
79 c->Nl=0;
80 c->Nh=0;
81 c->num=0;
82 }
83
84#ifndef md4_block_host_order
85void md4_block_host_order (MD4_CTX *c, const void *data, int num)
86 {
87 const MD4_LONG *X=data;
88 register unsigned long A,B,C,D;
89 /*
90 * In case you wonder why A-D are declared as long and not
91 * as MD4_LONG. Doing so results in slight performance
92 * boost on LP64 architectures. The catch is we don't
93 * really care if 32 MSBs of a 64-bit register get polluted
94 * with eventual overflows as we *save* only 32 LSBs in
95 * *either* case. Now declaring 'em long excuses the compiler
96 * from keeping 32 MSBs zeroed resulting in 13% performance
97 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
98 * Well, to be honest it should say that this *prevents*
99 * performance degradation.
100 *
101 * <appro@fy.chalmers.se>
102 */
103
104 A=c->A;
105 B=c->B;
106 C=c->C;
107 D=c->D;
108
109 for (;num--;X+=HASH_LBLOCK)
110 {
111 /* Round 0 */
112 R0(A,B,C,D,X[ 0], 3,0);
113 R0(D,A,B,C,X[ 1], 7,0);
114 R0(C,D,A,B,X[ 2],11,0);
115 R0(B,C,D,A,X[ 3],19,0);
116 R0(A,B,C,D,X[ 4], 3,0);
117 R0(D,A,B,C,X[ 5], 7,0);
118 R0(C,D,A,B,X[ 6],11,0);
119 R0(B,C,D,A,X[ 7],19,0);
120 R0(A,B,C,D,X[ 8], 3,0);
121 R0(D,A,B,C,X[ 9], 7,0);
122 R0(C,D,A,B,X[10],11,0);
123 R0(B,C,D,A,X[11],19,0);
124 R0(A,B,C,D,X[12], 3,0);
125 R0(D,A,B,C,X[13], 7,0);
126 R0(C,D,A,B,X[14],11,0);
127 R0(B,C,D,A,X[15],19,0);
128 /* Round 1 */
129 R1(A,B,C,D,X[ 0], 3,0x5A827999L);
130 R1(D,A,B,C,X[ 4], 5,0x5A827999L);
131 R1(C,D,A,B,X[ 8], 9,0x5A827999L);
132 R1(B,C,D,A,X[12],13,0x5A827999L);
133 R1(A,B,C,D,X[ 1], 3,0x5A827999L);
134 R1(D,A,B,C,X[ 5], 5,0x5A827999L);
135 R1(C,D,A,B,X[ 9], 9,0x5A827999L);
136 R1(B,C,D,A,X[13],13,0x5A827999L);
137 R1(A,B,C,D,X[ 2], 3,0x5A827999L);
138 R1(D,A,B,C,X[ 6], 5,0x5A827999L);
139 R1(C,D,A,B,X[10], 9,0x5A827999L);
140 R1(B,C,D,A,X[14],13,0x5A827999L);
141 R1(A,B,C,D,X[ 3], 3,0x5A827999L);
142 R1(D,A,B,C,X[ 7], 5,0x5A827999L);
143 R1(C,D,A,B,X[11], 9,0x5A827999L);
144 R1(B,C,D,A,X[15],13,0x5A827999L);
145 /* Round 2 */
146 R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
147 R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
148 R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
149 R2(B,C,D,A,X[12],15,0x6ED9EBA1);
150 R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
151 R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
152 R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
153 R2(B,C,D,A,X[14],15,0x6ED9EBA1);
154 R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
155 R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
156 R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
157 R2(B,C,D,A,X[13],15,0x6ED9EBA1);
158 R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
159 R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
160 R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
161 R2(B,C,D,A,X[15],15,0x6ED9EBA1);
162
163 A = c->A += A;
164 B = c->B += B;
165 C = c->C += C;
166 D = c->D += D;
167 }
168 }
169#endif
170
171#ifndef md4_block_data_order
172#ifdef X
173#undef X
174#endif
175void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
176 {
177 const unsigned char *data=data_;
178 register unsigned long A,B,C,D,l;
179 /*
180 * In case you wonder why A-D are declared as long and not
181 * as MD4_LONG. Doing so results in slight performance
182 * boost on LP64 architectures. The catch is we don't
183 * really care if 32 MSBs of a 64-bit register get polluted
184 * with eventual overflows as we *save* only 32 LSBs in
185 * *either* case. Now declaring 'em long excuses the compiler
186 * from keeping 32 MSBs zeroed resulting in 13% performance
187 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
188 * Well, to be honest it should say that this *prevents*
189 * performance degradation.
190 *
191 * <appro@fy.chalmers.se>
192 */
193#ifndef MD32_XARRAY
194 /* See comment in crypto/sha/sha_locl.h for details. */
195 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
196 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
197# define X(i) XX##i
198#else
199 MD4_LONG XX[MD4_LBLOCK];
200# define X(i) XX[i]
201#endif
202
203 A=c->A;
204 B=c->B;
205 C=c->C;
206 D=c->D;
207
208 for (;num--;)
209 {
210 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
211 /* Round 0 */
212 R0(A,B,C,D,X( 0), 3,0); HOST_c2l(data,l); X( 2)=l;
213 R0(D,A,B,C,X( 1), 7,0); HOST_c2l(data,l); X( 3)=l;
214 R0(C,D,A,B,X( 2),11,0); HOST_c2l(data,l); X( 4)=l;
215 R0(B,C,D,A,X( 3),19,0); HOST_c2l(data,l); X( 5)=l;
216 R0(A,B,C,D,X( 4), 3,0); HOST_c2l(data,l); X( 6)=l;
217 R0(D,A,B,C,X( 5), 7,0); HOST_c2l(data,l); X( 7)=l;
218 R0(C,D,A,B,X( 6),11,0); HOST_c2l(data,l); X( 8)=l;
219 R0(B,C,D,A,X( 7),19,0); HOST_c2l(data,l); X( 9)=l;
220 R0(A,B,C,D,X( 8), 3,0); HOST_c2l(data,l); X(10)=l;
221 R0(D,A,B,C,X( 9), 7,0); HOST_c2l(data,l); X(11)=l;
222 R0(C,D,A,B,X(10),11,0); HOST_c2l(data,l); X(12)=l;
223 R0(B,C,D,A,X(11),19,0); HOST_c2l(data,l); X(13)=l;
224 R0(A,B,C,D,X(12), 3,0); HOST_c2l(data,l); X(14)=l;
225 R0(D,A,B,C,X(13), 7,0); HOST_c2l(data,l); X(15)=l;
226 R0(C,D,A,B,X(14),11,0);
227 R0(B,C,D,A,X(15),19,0);
228 /* Round 1 */
229 R1(A,B,C,D,X( 0), 3,0x5A827999L);
230 R1(D,A,B,C,X( 4), 5,0x5A827999L);
231 R1(C,D,A,B,X( 8), 9,0x5A827999L);
232 R1(B,C,D,A,X(12),13,0x5A827999L);
233 R1(A,B,C,D,X( 1), 3,0x5A827999L);
234 R1(D,A,B,C,X( 5), 5,0x5A827999L);
235 R1(C,D,A,B,X( 9), 9,0x5A827999L);
236 R1(B,C,D,A,X(13),13,0x5A827999L);
237 R1(A,B,C,D,X( 2), 3,0x5A827999L);
238 R1(D,A,B,C,X( 6), 5,0x5A827999L);
239 R1(C,D,A,B,X(10), 9,0x5A827999L);
240 R1(B,C,D,A,X(14),13,0x5A827999L);
241 R1(A,B,C,D,X( 3), 3,0x5A827999L);
242 R1(D,A,B,C,X( 7), 5,0x5A827999L);
243 R1(C,D,A,B,X(11), 9,0x5A827999L);
244 R1(B,C,D,A,X(15),13,0x5A827999L);
245 /* Round 2 */
246 R2(A,B,C,D,X( 0), 3,0x6ED9EBA1L);
247 R2(D,A,B,C,X( 8), 9,0x6ED9EBA1L);
248 R2(C,D,A,B,X( 4),11,0x6ED9EBA1L);
249 R2(B,C,D,A,X(12),15,0x6ED9EBA1L);
250 R2(A,B,C,D,X( 2), 3,0x6ED9EBA1L);
251 R2(D,A,B,C,X(10), 9,0x6ED9EBA1L);
252 R2(C,D,A,B,X( 6),11,0x6ED9EBA1L);
253 R2(B,C,D,A,X(14),15,0x6ED9EBA1L);
254 R2(A,B,C,D,X( 1), 3,0x6ED9EBA1L);
255 R2(D,A,B,C,X( 9), 9,0x6ED9EBA1L);
256 R2(C,D,A,B,X( 5),11,0x6ED9EBA1L);
257 R2(B,C,D,A,X(13),15,0x6ED9EBA1L);
258 R2(A,B,C,D,X( 3), 3,0x6ED9EBA1L);
259 R2(D,A,B,C,X(11), 9,0x6ED9EBA1L);
260 R2(C,D,A,B,X( 7),11,0x6ED9EBA1L);
261 R2(B,C,D,A,X(15),15,0x6ED9EBA1L);
262
263 A = c->A += A;
264 B = c->B += B;
265 C = c->C += C;
266 D = c->D += D;
267 }
268 }
269#endif
270
271#ifdef undef
272int printit(unsigned long *l)
273 {
274 int i,ii;
275
276 for (i=0; i<2; i++)
277 {
278 for (ii=0; ii<8; ii++)
279 {
280 fprintf(stderr,"%08lx ",l[i*8+ii]);
281 }
282 fprintf(stderr,"\n");
283 }
284 }
285#endif
diff --git a/src/lib/libssl/src/crypto/md4/md4_locl.h b/src/lib/libssl/src/crypto/md4/md4_locl.h
new file mode 100644
index 0000000000..0a2b39018d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4_locl.h
@@ -0,0 +1,154 @@
1/* crypto/md4/md4_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/opensslconf.h>
62#include <openssl/md4.h>
63
64#ifndef MD4_LONG_LOG2
65#define MD4_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68void md4_block_host_order (MD4_CTX *c, const void *p,int num);
69void md4_block_data_order (MD4_CTX *c, const void *p,int num);
70
71#if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
72/*
73 * *_block_host_order is expected to handle aligned data while
74 * *_block_data_order - unaligned. As algorithm and host (x86)
75 * are in this case of the same "endianness" these two are
76 * otherwise indistinguishable. But normally you don't want to
77 * call the same function because unaligned access in places
78 * where alignment is expected is usually a "Bad Thing". Indeed,
79 * on RISCs you get punished with BUS ERROR signal or *severe*
80 * performance degradation. Intel CPUs are in turn perfectly
81 * capable of loading unaligned data without such drastic side
82 * effect. Yes, they say it's slower than aligned load, but no
83 * exception is generated and therefore performance degradation
84 * is *incomparable* with RISCs. What we should weight here is
85 * costs of unaligned access against costs of aligning data.
86 * According to my measurements allowing unaligned access results
87 * in ~9% performance improvement on Pentium II operating at
88 * 266MHz. I won't be surprised if the difference will be higher
89 * on faster systems:-)
90 *
91 * <appro@fy.chalmers.se>
92 */
93#define md4_block_data_order md4_block_host_order
94#endif
95
96#define DATA_ORDER_IS_LITTLE_ENDIAN
97
98#define HASH_LONG MD4_LONG
99#define HASH_LONG_LOG2 MD4_LONG_LOG2
100#define HASH_CTX MD4_CTX
101#define HASH_CBLOCK MD4_CBLOCK
102#define HASH_LBLOCK MD4_LBLOCK
103#define HASH_UPDATE MD4_Update
104#define HASH_TRANSFORM MD4_Transform
105#define HASH_FINAL MD4_Final
106#define HASH_MAKE_STRING(c,s) do { \
107 unsigned long ll; \
108 ll=(c)->A; HOST_l2c(ll,(s)); \
109 ll=(c)->B; HOST_l2c(ll,(s)); \
110 ll=(c)->C; HOST_l2c(ll,(s)); \
111 ll=(c)->D; HOST_l2c(ll,(s)); \
112 } while (0)
113#define HASH_BLOCK_HOST_ORDER md4_block_host_order
114#if !defined(L_ENDIAN) || defined(md4_block_data_order)
115#define HASH_BLOCK_DATA_ORDER md4_block_data_order
116/*
117 * Little-endians (Intel and Alpha) feel better without this.
118 * It looks like memcpy does better job than generic
119 * md4_block_data_order on copying-n-aligning input data.
120 * But frankly speaking I didn't expect such result on Alpha.
121 * On the other hand I've got this with egcs-1.0.2 and if
122 * program is compiled with another (better?) compiler it
123 * might turn out other way around.
124 *
125 * <appro@fy.chalmers.se>
126 */
127#endif
128
129#include "md32_common.h"
130
131/*
132#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
133#define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z))))
134*/
135
136/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
137 * simplified to the code below. Wei attributes these optimizations
138 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
139 */
140#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
141#define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
142#define H(b,c,d) ((b) ^ (c) ^ (d))
143
144#define R0(a,b,c,d,k,s,t) { \
145 a+=((k)+(t)+F((b),(c),(d))); \
146 a=ROTATE(a,s); };
147
148#define R1(a,b,c,d,k,s,t) { \
149 a+=((k)+(t)+G((b),(c),(d))); \
150 a=ROTATE(a,s); };\
151
152#define R2(a,b,c,d,k,s,t) { \
153 a+=((k)+(t)+H((b),(c),(d))); \
154 a=ROTATE(a,s); };
diff --git a/src/lib/libssl/src/crypto/md4/md4_one.c b/src/lib/libssl/src/crypto/md4/md4_one.c
new file mode 100644
index 0000000000..87a995d38d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4_one.c
@@ -0,0 +1,95 @@
1/* crypto/md4/md4_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/md4.h>
62
63#ifdef CHARSET_EBCDIC
64#include <openssl/ebcdic.h>
65#endif
66
67unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md)
68 {
69 MD4_CTX c;
70 static unsigned char m[MD4_DIGEST_LENGTH];
71
72 if (md == NULL) md=m;
73 MD4_Init(&c);
74#ifndef CHARSET_EBCDIC
75 MD4_Update(&c,d,n);
76#else
77 {
78 char temp[1024];
79 unsigned long chunk;
80
81 while (n > 0)
82 {
83 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
84 ebcdic2ascii(temp, d, chunk);
85 MD4_Update(&c,temp,chunk);
86 n -= chunk;
87 d += chunk;
88 }
89 }
90#endif
91 MD4_Final(md,&c);
92 memset(&c,0,sizeof(c)); /* security consideration */
93 return(md);
94 }
95
diff --git a/src/lib/libssl/src/crypto/md4/md4s.cpp b/src/lib/libssl/src/crypto/md4/md4s.cpp
new file mode 100644
index 0000000000..c0ec97fc9f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4s.cpp
@@ -0,0 +1,78 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/md4.h>
36
37extern "C" {
38void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD4_CTX ctx;
45 unsigned long s1,s2,e1,e2;
46 unsigned char k[16];
47 unsigned long data[2];
48 unsigned char iv[8];
49 int i,num=0,numm;
50 int j=0;
51
52 if (argc >= 2)
53 num=atoi(argv[1]);
54
55 if (num == 0) num=16;
56 if (num > 250) num=16;
57 numm=num+2;
58 num*=64;
59 numm*=64;
60
61 for (j=0; j<6; j++)
62 {
63 for (i=0; i<10; i++) /**/
64 {
65 md4_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md4_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md4_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md4_block_x86(&ctx,buffer,num);
73 }
74 printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 }
77 }
78
diff --git a/src/lib/libssl/src/crypto/md4/md4test.c b/src/lib/libssl/src/crypto/md4/md4test.c
new file mode 100644
index 0000000000..97e6e21efd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md4/md4test.c
@@ -0,0 +1,131 @@
1/* crypto/md4/md4test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#ifdef NO_MD4
64int main(int argc, char *argv[])
65{
66 printf("No MD4 support\n");
67 return(0);
68}
69#else
70#include <openssl/md4.h>
71
72static char *test[]={
73 "",
74 "a",
75 "abc",
76 "message digest",
77 "abcdefghijklmnopqrstuvwxyz",
78 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
79 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
80 NULL,
81 };
82
83static char *ret[]={
84"31d6cfe0d16ae931b73c59d7e0c089c0",
85"bde52cb31de33e46245e05fbdbd6fb24",
86"a448017aaf21d8525fc10ae87aa6729d",
87"d9130a8164549fe818874806e1c7014b",
88"d79e1c308aa5bbcdeea8ed63df412da9",
89"043f8582f241db351ce627e153e7f0e4",
90"e33b4ddc9c38f2199c3e7b164fcc0536",
91};
92
93static char *pt(unsigned char *md);
94int main(int argc, char *argv[])
95 {
96 int i,err=0;
97 unsigned char **P,**R;
98 char *p;
99
100 P=(unsigned char **)test;
101 R=(unsigned char **)ret;
102 i=1;
103 while (*P != NULL)
104 {
105 p=pt(MD4(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
106 if (strcmp(p,(char *)*R) != 0)
107 {
108 printf("error calculating MD4 on '%s'\n",*P);
109 printf("got %s instead of %s\n",p,*R);
110 err++;
111 }
112 else
113 printf("test %d ok\n",i);
114 i++;
115 R++;
116 P++;
117 }
118 exit(err);
119 return(0);
120 }
121
122static char *pt(unsigned char *md)
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD4_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
131#endif
diff --git a/src/lib/libssl/src/crypto/md5/asm/md5-sparcv9.S b/src/lib/libssl/src/crypto/md5/asm/md5-sparcv9.S
new file mode 100644
index 0000000000..ca4257f134
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/asm/md5-sparcv9.S
@@ -0,0 +1,1029 @@
1.ident "md5-sparcv9.S, Version 1.0"
2.ident "SPARC V9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3.file "md5-sparcv9.S"
4
5/*
6 * ====================================================================
7 * Copyright (c) 1999 Andy Polyakov <appro@fy.chalmers.se>.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted as long as above copyright notices are retained. Warranty
11 * of any kind is (of course:-) disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contribution to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is an
18 * assembler implementation of MD5 block hash function. I've hand-coded
19 * this for the sole reason to reach UltraSPARC-specific "load in
20 * little-endian byte order" instruction. This gives up to 15%
21 * performance improvement for cases when input message is aligned at
22 * 32 bits boundary. The module was tested under both 32 *and* 64 bit
23 * kernels. For updates see http://fy.chalmers.se/~appro/hpe/.
24 *
25 * To compile with SC4.x/SC5.x:
26 *
27 * cc -xarch=v[9|8plus] -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
28 * -c md5-sparcv9.S
29 *
30 * and with gcc:
31 *
32 * gcc -mcpu=ultrasparc -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
33 * -c md5-sparcv9.S
34 *
35 * or if above fails (it does if you have gas):
36 *
37 * gcc -E -DULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \
38 * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o
39 */
40
41#define A %o0
42#define B %o1
43#define C %o2
44#define D %o3
45#define T1 %o4
46#define T2 %o5
47
48#define R0 %l0
49#define R1 %l1
50#define R2 %l2
51#define R3 %l3
52#define R4 %l4
53#define R5 %l5
54#define R6 %l6
55#define R7 %l7
56#define R8 %i3
57#define R9 %i4
58#define R10 %i5
59#define R11 %g1
60#define R12 %g2
61#define R13 %g3
62#define RX %g4
63
64#define Aptr %i0+0
65#define Bptr %i0+4
66#define Cptr %i0+8
67#define Dptr %i0+12
68
69#define Aval R5 /* those not used at the end of the last round */
70#define Bval R6
71#define Cval R7
72#define Dval R8
73
74#if defined(MD5_BLOCK_DATA_ORDER)
75# if defined(ULTRASPARC)
76# define LOAD lda
77# define X(i) [%i1+i*4]%asi
78# define md5_block md5_block_asm_data_order_aligned
79# define ASI_PRIMARY_LITTLE 0x88
80# else
81# error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!"
82# endif
83#else
84# define LOAD ld
85# define X(i) [%i1+i*4]
86# define md5_block md5_block_asm_host_order
87#endif
88
89.section ".text",#alloc,#execinstr
90
91#if defined(__SUNPRO_C) && defined(__sparcv9)
92 /* They've said -xarch=v9 at command line */
93 .register %g2,#scratch
94 .register %g3,#scratch
95# define FRAME -192
96#elif defined(__GNUC__) && defined(__arch64__)
97 /* They've said -m64 at command line */
98 .register %g2,#scratch
99 .register %g3,#scratch
100# define FRAME -192
101#else
102# define FRAME -96
103#endif
104
105.align 32
106
107.global md5_block
108md5_block:
109 save %sp,FRAME,%sp
110
111 ld [Dptr],D
112 ld [Cptr],C
113 ld [Bptr],B
114 ld [Aptr],A
115#ifdef ASI_PRIMARY_LITTLE
116 rd %asi,%o7 ! How dare I? Well, I just do:-)
117 wr %g0,ASI_PRIMARY_LITTLE,%asi
118#endif
119 LOAD X(0),R0
120
121.Lmd5_block_loop:
122
123!!!!!!!!Round 0
124
125 xor C,D,T1
126 sethi %hi(0xd76aa478),T2
127 and T1,B,T1
128 or T2,%lo(0xd76aa478),T2 !=
129 xor T1,D,T1
130 add T1,R0,T1
131 LOAD X(1),R1
132 add T1,T2,T1 !=
133 add A,T1,A
134 sll A,7,T2
135 srl A,32-7,A
136 or A,T2,A !=
137 xor B,C,T1
138 add A,B,A
139
140 sethi %hi(0xe8c7b756),T2
141 and T1,A,T1 !=
142 or T2,%lo(0xe8c7b756),T2
143 xor T1,C,T1
144 LOAD X(2),R2
145 add T1,R1,T1 !=
146 add T1,T2,T1
147 add D,T1,D
148 sll D,12,T2
149 srl D,32-12,D !=
150 or D,T2,D
151 xor A,B,T1
152 add D,A,D
153
154 sethi %hi(0x242070db),T2 !=
155 and T1,D,T1
156 or T2,%lo(0x242070db),T2
157 xor T1,B,T1
158 add T1,R2,T1 !=
159 LOAD X(3),R3
160 add T1,T2,T1
161 add C,T1,C
162 sll C,17,T2 !=
163 srl C,32-17,C
164 or C,T2,C
165 xor D,A,T1
166 add C,D,C !=
167
168 sethi %hi(0xc1bdceee),T2
169 and T1,C,T1
170 or T2,%lo(0xc1bdceee),T2
171 xor T1,A,T1 !=
172 add T1,R3,T1
173 LOAD X(4),R4
174 add T1,T2,T1
175 add B,T1,B !=
176 sll B,22,T2
177 srl B,32-22,B
178 or B,T2,B
179 xor C,D,T1 !=
180 add B,C,B
181
182 sethi %hi(0xf57c0faf),T2
183 and T1,B,T1
184 or T2,%lo(0xf57c0faf),T2 !=
185 xor T1,D,T1
186 add T1,R4,T1
187 LOAD X(5),R5
188 add T1,T2,T1 !=
189 add A,T1,A
190 sll A,7,T2
191 srl A,32-7,A
192 or A,T2,A !=
193 xor B,C,T1
194 add A,B,A
195
196 sethi %hi(0x4787c62a),T2
197 and T1,A,T1 !=
198 or T2,%lo(0x4787c62a),T2
199 xor T1,C,T1
200 LOAD X(6),R6
201 add T1,R5,T1 !=
202 add T1,T2,T1
203 add D,T1,D
204 sll D,12,T2
205 srl D,32-12,D !=
206 or D,T2,D
207 xor A,B,T1
208 add D,A,D
209
210 sethi %hi(0xa8304613),T2 !=
211 and T1,D,T1
212 or T2,%lo(0xa8304613),T2
213 xor T1,B,T1
214 add T1,R6,T1 !=
215 LOAD X(7),R7
216 add T1,T2,T1
217 add C,T1,C
218 sll C,17,T2 !=
219 srl C,32-17,C
220 or C,T2,C
221 xor D,A,T1
222 add C,D,C !=
223
224 sethi %hi(0xfd469501),T2
225 and T1,C,T1
226 or T2,%lo(0xfd469501),T2
227 xor T1,A,T1 !=
228 add T1,R7,T1
229 LOAD X(8),R8
230 add T1,T2,T1
231 add B,T1,B !=
232 sll B,22,T2
233 srl B,32-22,B
234 or B,T2,B
235 xor C,D,T1 !=
236 add B,C,B
237
238 sethi %hi(0x698098d8),T2
239 and T1,B,T1
240 or T2,%lo(0x698098d8),T2 !=
241 xor T1,D,T1
242 add T1,R8,T1
243 LOAD X(9),R9
244 add T1,T2,T1 !=
245 add A,T1,A
246 sll A,7,T2
247 srl A,32-7,A
248 or A,T2,A !=
249 xor B,C,T1
250 add A,B,A
251
252 sethi %hi(0x8b44f7af),T2
253 and T1,A,T1 !=
254 or T2,%lo(0x8b44f7af),T2
255 xor T1,C,T1
256 LOAD X(10),R10
257 add T1,R9,T1 !=
258 add T1,T2,T1
259 add D,T1,D
260 sll D,12,T2
261 srl D,32-12,D !=
262 or D,T2,D
263 xor A,B,T1
264 add D,A,D
265
266 sethi %hi(0xffff5bb1),T2 !=
267 and T1,D,T1
268 or T2,%lo(0xffff5bb1),T2
269 xor T1,B,T1
270 add T1,R10,T1 !=
271 LOAD X(11),R11
272 add T1,T2,T1
273 add C,T1,C
274 sll C,17,T2 !=
275 srl C,32-17,C
276 or C,T2,C
277 xor D,A,T1
278 add C,D,C !=
279
280 sethi %hi(0x895cd7be),T2
281 and T1,C,T1
282 or T2,%lo(0x895cd7be),T2
283 xor T1,A,T1 !=
284 add T1,R11,T1
285 LOAD X(12),R12
286 add T1,T2,T1
287 add B,T1,B !=
288 sll B,22,T2
289 srl B,32-22,B
290 or B,T2,B
291 xor C,D,T1 !=
292 add B,C,B
293
294 sethi %hi(0x6b901122),T2
295 and T1,B,T1
296 or T2,%lo(0x6b901122),T2 !=
297 xor T1,D,T1
298 add T1,R12,T1
299 LOAD X(13),R13
300 add T1,T2,T1 !=
301 add A,T1,A
302 sll A,7,T2
303 srl A,32-7,A
304 or A,T2,A !=
305 xor B,C,T1
306 add A,B,A
307
308 sethi %hi(0xfd987193),T2
309 and T1,A,T1 !=
310 or T2,%lo(0xfd987193),T2
311 xor T1,C,T1
312 LOAD X(14),RX
313 add T1,R13,T1 !=
314 add T1,T2,T1
315 add D,T1,D
316 sll D,12,T2
317 srl D,32-12,D !=
318 or D,T2,D
319 xor A,B,T1
320 add D,A,D
321
322 sethi %hi(0xa679438e),T2 !=
323 and T1,D,T1
324 or T2,%lo(0xa679438e),T2
325 xor T1,B,T1
326 add T1,RX,T1 !=
327 LOAD X(15),RX
328 add T1,T2,T1
329 add C,T1,C
330 sll C,17,T2 !=
331 srl C,32-17,C
332 or C,T2,C
333 xor D,A,T1
334 add C,D,C !=
335
336 sethi %hi(0x49b40821),T2
337 and T1,C,T1
338 or T2,%lo(0x49b40821),T2
339 xor T1,A,T1 !=
340 add T1,RX,T1
341 !pre-LOADed X(1),R1
342 add T1,T2,T1
343 add B,T1,B
344 sll B,22,T2 !=
345 srl B,32-22,B
346 or B,T2,B
347 add B,C,B
348
349!!!!!!!!Round 1
350
351 xor B,C,T1 !=
352 sethi %hi(0xf61e2562),T2
353 and T1,D,T1
354 or T2,%lo(0xf61e2562),T2
355 xor T1,C,T1 !=
356 add T1,R1,T1
357 !pre-LOADed X(6),R6
358 add T1,T2,T1
359 add A,T1,A
360 sll A,5,T2 !=
361 srl A,32-5,A
362 or A,T2,A
363 add A,B,A
364
365 xor A,B,T1 !=
366 sethi %hi(0xc040b340),T2
367 and T1,C,T1
368 or T2,%lo(0xc040b340),T2
369 xor T1,B,T1 !=
370 add T1,R6,T1
371 !pre-LOADed X(11),R11
372 add T1,T2,T1
373 add D,T1,D
374 sll D,9,T2 !=
375 srl D,32-9,D
376 or D,T2,D
377 add D,A,D
378
379 xor D,A,T1 !=
380 sethi %hi(0x265e5a51),T2
381 and T1,B,T1
382 or T2,%lo(0x265e5a51),T2
383 xor T1,A,T1 !=
384 add T1,R11,T1
385 !pre-LOADed X(0),R0
386 add T1,T2,T1
387 add C,T1,C
388 sll C,14,T2 !=
389 srl C,32-14,C
390 or C,T2,C
391 add C,D,C
392
393 xor C,D,T1 !=
394 sethi %hi(0xe9b6c7aa),T2
395 and T1,A,T1
396 or T2,%lo(0xe9b6c7aa),T2
397 xor T1,D,T1 !=
398 add T1,R0,T1
399 !pre-LOADed X(5),R5
400 add T1,T2,T1
401 add B,T1,B
402 sll B,20,T2 !=
403 srl B,32-20,B
404 or B,T2,B
405 add B,C,B
406
407 xor B,C,T1 !=
408 sethi %hi(0xd62f105d),T2
409 and T1,D,T1
410 or T2,%lo(0xd62f105d),T2
411 xor T1,C,T1 !=
412 add T1,R5,T1
413 !pre-LOADed X(10),R10
414 add T1,T2,T1
415 add A,T1,A
416 sll A,5,T2 !=
417 srl A,32-5,A
418 or A,T2,A
419 add A,B,A
420
421 xor A,B,T1 !=
422 sethi %hi(0x02441453),T2
423 and T1,C,T1
424 or T2,%lo(0x02441453),T2
425 xor T1,B,T1 !=
426 add T1,R10,T1
427 LOAD X(15),RX
428 add T1,T2,T1
429 add D,T1,D !=
430 sll D,9,T2
431 srl D,32-9,D
432 or D,T2,D
433 add D,A,D !=
434
435 xor D,A,T1
436 sethi %hi(0xd8a1e681),T2
437 and T1,B,T1
438 or T2,%lo(0xd8a1e681),T2 !=
439 xor T1,A,T1
440 add T1,RX,T1
441 !pre-LOADed X(4),R4
442 add T1,T2,T1
443 add C,T1,C !=
444 sll C,14,T2
445 srl C,32-14,C
446 or C,T2,C
447 add C,D,C !=
448
449 xor C,D,T1
450 sethi %hi(0xe7d3fbc8),T2
451 and T1,A,T1
452 or T2,%lo(0xe7d3fbc8),T2 !=
453 xor T1,D,T1
454 add T1,R4,T1
455 !pre-LOADed X(9),R9
456 add T1,T2,T1
457 add B,T1,B !=
458 sll B,20,T2
459 srl B,32-20,B
460 or B,T2,B
461 add B,C,B !=
462
463 xor B,C,T1
464 sethi %hi(0x21e1cde6),T2
465 and T1,D,T1
466 or T2,%lo(0x21e1cde6),T2 !=
467 xor T1,C,T1
468 add T1,R9,T1
469 LOAD X(14),RX
470 add T1,T2,T1 !=
471 add A,T1,A
472 sll A,5,T2
473 srl A,32-5,A
474 or A,T2,A !=
475 add A,B,A
476
477 xor A,B,T1
478 sethi %hi(0xc33707d6),T2
479 and T1,C,T1 !=
480 or T2,%lo(0xc33707d6),T2
481 xor T1,B,T1
482 add T1,RX,T1
483 !pre-LOADed X(3),R3
484 add T1,T2,T1 !=
485 add D,T1,D
486 sll D,9,T2
487 srl D,32-9,D
488 or D,T2,D !=
489 add D,A,D
490
491 xor D,A,T1
492 sethi %hi(0xf4d50d87),T2
493 and T1,B,T1 !=
494 or T2,%lo(0xf4d50d87),T2
495 xor T1,A,T1
496 add T1,R3,T1
497 !pre-LOADed X(8),R8
498 add T1,T2,T1 !=
499 add C,T1,C
500 sll C,14,T2
501 srl C,32-14,C
502 or C,T2,C !=
503 add C,D,C
504
505 xor C,D,T1
506 sethi %hi(0x455a14ed),T2
507 and T1,A,T1 !=
508 or T2,%lo(0x455a14ed),T2
509 xor T1,D,T1
510 add T1,R8,T1
511 !pre-LOADed X(13),R13
512 add T1,T2,T1 !=
513 add B,T1,B
514 sll B,20,T2
515 srl B,32-20,B
516 or B,T2,B !=
517 add B,C,B
518
519 xor B,C,T1
520 sethi %hi(0xa9e3e905),T2
521 and T1,D,T1 !=
522 or T2,%lo(0xa9e3e905),T2
523 xor T1,C,T1
524 add T1,R13,T1
525 !pre-LOADed X(2),R2
526 add T1,T2,T1 !=
527 add A,T1,A
528 sll A,5,T2
529 srl A,32-5,A
530 or A,T2,A !=
531 add A,B,A
532
533 xor A,B,T1
534 sethi %hi(0xfcefa3f8),T2
535 and T1,C,T1 !=
536 or T2,%lo(0xfcefa3f8),T2
537 xor T1,B,T1
538 add T1,R2,T1
539 !pre-LOADed X(7),R7
540 add T1,T2,T1 !=
541 add D,T1,D
542 sll D,9,T2
543 srl D,32-9,D
544 or D,T2,D !=
545 add D,A,D
546
547 xor D,A,T1
548 sethi %hi(0x676f02d9),T2
549 and T1,B,T1 !=
550 or T2,%lo(0x676f02d9),T2
551 xor T1,A,T1
552 add T1,R7,T1
553 !pre-LOADed X(12),R12
554 add T1,T2,T1 !=
555 add C,T1,C
556 sll C,14,T2
557 srl C,32-14,C
558 or C,T2,C !=
559 add C,D,C
560
561 xor C,D,T1
562 sethi %hi(0x8d2a4c8a),T2
563 and T1,A,T1 !=
564 or T2,%lo(0x8d2a4c8a),T2
565 xor T1,D,T1
566 add T1,R12,T1
567 !pre-LOADed X(5),R5
568 add T1,T2,T1 !=
569 add B,T1,B
570 sll B,20,T2
571 srl B,32-20,B
572 or B,T2,B !=
573 add B,C,B
574
575!!!!!!!!Round 2
576
577 xor B,C,T1
578 sethi %hi(0xfffa3942),T2
579 xor T1,D,T1 !=
580 or T2,%lo(0xfffa3942),T2
581 add T1,R5,T1
582 !pre-LOADed X(8),R8
583 add T1,T2,T1
584 add A,T1,A !=
585 sll A,4,T2
586 srl A,32-4,A
587 or A,T2,A
588 add A,B,A !=
589
590 xor A,B,T1
591 sethi %hi(0x8771f681),T2
592 xor T1,C,T1
593 or T2,%lo(0x8771f681),T2 !=
594 add T1,R8,T1
595 !pre-LOADed X(11),R11
596 add T1,T2,T1
597 add D,T1,D
598 sll D,11,T2 !=
599 srl D,32-11,D
600 or D,T2,D
601 add D,A,D
602
603 xor D,A,T1 !=
604 sethi %hi(0x6d9d6122),T2
605 xor T1,B,T1
606 or T2,%lo(0x6d9d6122),T2
607 add T1,R11,T1 !=
608 LOAD X(14),RX
609 add T1,T2,T1
610 add C,T1,C
611 sll C,16,T2 !=
612 srl C,32-16,C
613 or C,T2,C
614 add C,D,C
615
616 xor C,D,T1 !=
617 sethi %hi(0xfde5380c),T2
618 xor T1,A,T1
619 or T2,%lo(0xfde5380c),T2
620 add T1,RX,T1 !=
621 !pre-LOADed X(1),R1
622 add T1,T2,T1
623 add B,T1,B
624 sll B,23,T2
625 srl B,32-23,B !=
626 or B,T2,B
627 add B,C,B
628
629 xor B,C,T1
630 sethi %hi(0xa4beea44),T2 !=
631 xor T1,D,T1
632 or T2,%lo(0xa4beea44),T2
633 add T1,R1,T1
634 !pre-LOADed X(4),R4
635 add T1,T2,T1 !=
636 add A,T1,A
637 sll A,4,T2
638 srl A,32-4,A
639 or A,T2,A !=
640 add A,B,A
641
642 xor A,B,T1
643 sethi %hi(0x4bdecfa9),T2
644 xor T1,C,T1 !=
645 or T2,%lo(0x4bdecfa9),T2
646 add T1,R4,T1
647 !pre-LOADed X(7),R7
648 add T1,T2,T1
649 add D,T1,D !=
650 sll D,11,T2
651 srl D,32-11,D
652 or D,T2,D
653 add D,A,D !=
654
655 xor D,A,T1
656 sethi %hi(0xf6bb4b60),T2
657 xor T1,B,T1
658 or T2,%lo(0xf6bb4b60),T2 !=
659 add T1,R7,T1
660 !pre-LOADed X(10),R10
661 add T1,T2,T1
662 add C,T1,C
663 sll C,16,T2 !=
664 srl C,32-16,C
665 or C,T2,C
666 add C,D,C
667
668 xor C,D,T1 !=
669 sethi %hi(0xbebfbc70),T2
670 xor T1,A,T1
671 or T2,%lo(0xbebfbc70),T2
672 add T1,R10,T1 !=
673 !pre-LOADed X(13),R13
674 add T1,T2,T1
675 add B,T1,B
676 sll B,23,T2
677 srl B,32-23,B !=
678 or B,T2,B
679 add B,C,B
680
681 xor B,C,T1
682 sethi %hi(0x289b7ec6),T2 !=
683 xor T1,D,T1
684 or T2,%lo(0x289b7ec6),T2
685 add T1,R13,T1
686 !pre-LOADed X(0),R0
687 add T1,T2,T1 !=
688 add A,T1,A
689 sll A,4,T2
690 srl A,32-4,A
691 or A,T2,A !=
692 add A,B,A
693
694 xor A,B,T1
695 sethi %hi(0xeaa127fa),T2
696 xor T1,C,T1 !=
697 or T2,%lo(0xeaa127fa),T2
698 add T1,R0,T1
699 !pre-LOADed X(3),R3
700 add T1,T2,T1
701 add D,T1,D !=
702 sll D,11,T2
703 srl D,32-11,D
704 or D,T2,D
705 add D,A,D !=
706
707 xor D,A,T1
708 sethi %hi(0xd4ef3085),T2
709 xor T1,B,T1
710 or T2,%lo(0xd4ef3085),T2 !=
711 add T1,R3,T1
712 !pre-LOADed X(6),R6
713 add T1,T2,T1
714 add C,T1,C
715 sll C,16,T2 !=
716 srl C,32-16,C
717 or C,T2,C
718 add C,D,C
719
720 xor C,D,T1 !=
721 sethi %hi(0x04881d05),T2
722 xor T1,A,T1
723 or T2,%lo(0x04881d05),T2
724 add T1,R6,T1 !=
725 !pre-LOADed X(9),R9
726 add T1,T2,T1
727 add B,T1,B
728 sll B,23,T2
729 srl B,32-23,B !=
730 or B,T2,B
731 add B,C,B
732
733 xor B,C,T1
734 sethi %hi(0xd9d4d039),T2 !=
735 xor T1,D,T1
736 or T2,%lo(0xd9d4d039),T2
737 add T1,R9,T1
738 !pre-LOADed X(12),R12
739 add T1,T2,T1 !=
740 add A,T1,A
741 sll A,4,T2
742 srl A,32-4,A
743 or A,T2,A !=
744 add A,B,A
745
746 xor A,B,T1
747 sethi %hi(0xe6db99e5),T2
748 xor T1,C,T1 !=
749 or T2,%lo(0xe6db99e5),T2
750 add T1,R12,T1
751 LOAD X(15),RX
752 add T1,T2,T1 !=
753 add D,T1,D
754 sll D,11,T2
755 srl D,32-11,D
756 or D,T2,D !=
757 add D,A,D
758
759 xor D,A,T1
760 sethi %hi(0x1fa27cf8),T2
761 xor T1,B,T1 !=
762 or T2,%lo(0x1fa27cf8),T2
763 add T1,RX,T1
764 !pre-LOADed X(2),R2
765 add T1,T2,T1
766 add C,T1,C !=
767 sll C,16,T2
768 srl C,32-16,C
769 or C,T2,C
770 add C,D,C !=
771
772 xor C,D,T1
773 sethi %hi(0xc4ac5665),T2
774 xor T1,A,T1
775 or T2,%lo(0xc4ac5665),T2 !=
776 add T1,R2,T1
777 !pre-LOADed X(0),R0
778 add T1,T2,T1
779 add B,T1,B
780 sll B,23,T2 !=
781 srl B,32-23,B
782 or B,T2,B
783 add B,C,B
784
785!!!!!!!!Round 3
786
787 orn B,D,T1 !=
788 sethi %hi(0xf4292244),T2
789 xor T1,C,T1
790 or T2,%lo(0xf4292244),T2
791 add T1,R0,T1 !=
792 !pre-LOADed X(7),R7
793 add T1,T2,T1
794 add A,T1,A
795 sll A,6,T2
796 srl A,32-6,A !=
797 or A,T2,A
798 add A,B,A
799
800 orn A,C,T1
801 sethi %hi(0x432aff97),T2 !=
802 xor T1,B,T1
803 or T2,%lo(0x432aff97),T2
804 LOAD X(14),RX
805 add T1,R7,T1 !=
806 add T1,T2,T1
807 add D,T1,D
808 sll D,10,T2
809 srl D,32-10,D !=
810 or D,T2,D
811 add D,A,D
812
813 orn D,B,T1
814 sethi %hi(0xab9423a7),T2 !=
815 xor T1,A,T1
816 or T2,%lo(0xab9423a7),T2
817 add T1,RX,T1
818 !pre-LOADed X(5),R5
819 add T1,T2,T1 !=
820 add C,T1,C
821 sll C,15,T2
822 srl C,32-15,C
823 or C,T2,C !=
824 add C,D,C
825
826 orn C,A,T1
827 sethi %hi(0xfc93a039),T2
828 xor T1,D,T1 !=
829 or T2,%lo(0xfc93a039),T2
830 add T1,R5,T1
831 !pre-LOADed X(12),R12
832 add T1,T2,T1
833 add B,T1,B !=
834 sll B,21,T2
835 srl B,32-21,B
836 or B,T2,B
837 add B,C,B !=
838
839 orn B,D,T1
840 sethi %hi(0x655b59c3),T2
841 xor T1,C,T1
842 or T2,%lo(0x655b59c3),T2 !=
843 add T1,R12,T1
844 !pre-LOADed X(3),R3
845 add T1,T2,T1
846 add A,T1,A
847 sll A,6,T2 !=
848 srl A,32-6,A
849 or A,T2,A
850 add A,B,A
851
852 orn A,C,T1 !=
853 sethi %hi(0x8f0ccc92),T2
854 xor T1,B,T1
855 or T2,%lo(0x8f0ccc92),T2
856 add T1,R3,T1 !=
857 !pre-LOADed X(10),R10
858 add T1,T2,T1
859 add D,T1,D
860 sll D,10,T2
861 srl D,32-10,D !=
862 or D,T2,D
863 add D,A,D
864
865 orn D,B,T1
866 sethi %hi(0xffeff47d),T2 !=
867 xor T1,A,T1
868 or T2,%lo(0xffeff47d),T2
869 add T1,R10,T1
870 !pre-LOADed X(1),R1
871 add T1,T2,T1 !=
872 add C,T1,C
873 sll C,15,T2
874 srl C,32-15,C
875 or C,T2,C !=
876 add C,D,C
877
878 orn C,A,T1
879 sethi %hi(0x85845dd1),T2
880 xor T1,D,T1 !=
881 or T2,%lo(0x85845dd1),T2
882 add T1,R1,T1
883 !pre-LOADed X(8),R8
884 add T1,T2,T1
885 add B,T1,B !=
886 sll B,21,T2
887 srl B,32-21,B
888 or B,T2,B
889 add B,C,B !=
890
891 orn B,D,T1
892 sethi %hi(0x6fa87e4f),T2
893 xor T1,C,T1
894 or T2,%lo(0x6fa87e4f),T2 !=
895 add T1,R8,T1
896 LOAD X(15),RX
897 add T1,T2,T1
898 add A,T1,A !=
899 sll A,6,T2
900 srl A,32-6,A
901 or A,T2,A
902 add A,B,A !=
903
904 orn A,C,T1
905 sethi %hi(0xfe2ce6e0),T2
906 xor T1,B,T1
907 or T2,%lo(0xfe2ce6e0),T2 !=
908 add T1,RX,T1
909 !pre-LOADed X(6),R6
910 add T1,T2,T1
911 add D,T1,D
912 sll D,10,T2 !=
913 srl D,32-10,D
914 or D,T2,D
915 add D,A,D
916
917 orn D,B,T1 !=
918 sethi %hi(0xa3014314),T2
919 xor T1,A,T1
920 or T2,%lo(0xa3014314),T2
921 add T1,R6,T1 !=
922 !pre-LOADed X(13),R13
923 add T1,T2,T1
924 add C,T1,C
925 sll C,15,T2
926 srl C,32-15,C !=
927 or C,T2,C
928 add C,D,C
929
930 orn C,A,T1
931 sethi %hi(0x4e0811a1),T2 !=
932 xor T1,D,T1
933 or T2,%lo(0x4e0811a1),T2
934 !pre-LOADed X(4),R4
935 ld [Aptr],Aval
936 add T1,R13,T1 !=
937 add T1,T2,T1
938 add B,T1,B
939 sll B,21,T2
940 srl B,32-21,B !=
941 or B,T2,B
942 add B,C,B
943
944 orn B,D,T1
945 sethi %hi(0xf7537e82),T2 !=
946 xor T1,C,T1
947 or T2,%lo(0xf7537e82),T2
948 !pre-LOADed X(11),R11
949 ld [Dptr],Dval
950 add T1,R4,T1 !=
951 add T1,T2,T1
952 add A,T1,A
953 sll A,6,T2
954 srl A,32-6,A !=
955 or A,T2,A
956 add A,B,A
957
958 orn A,C,T1
959 sethi %hi(0xbd3af235),T2 !=
960 xor T1,B,T1
961 or T2,%lo(0xbd3af235),T2
962 !pre-LOADed X(2),R2
963 ld [Cptr],Cval
964 add T1,R11,T1 !=
965 add T1,T2,T1
966 add D,T1,D
967 sll D,10,T2
968 srl D,32-10,D !=
969 or D,T2,D
970 add D,A,D
971
972 orn D,B,T1
973 sethi %hi(0x2ad7d2bb),T2 !=
974 xor T1,A,T1
975 or T2,%lo(0x2ad7d2bb),T2
976 !pre-LOADed X(9),R9
977 ld [Bptr],Bval
978 add T1,R2,T1 !=
979 add Aval,A,Aval
980 add T1,T2,T1
981 st Aval,[Aptr]
982 add C,T1,C !=
983 sll C,15,T2
984 add Dval,D,Dval
985 srl C,32-15,C
986 or C,T2,C !=
987 st Dval,[Dptr]
988 add C,D,C
989
990 orn C,A,T1
991 sethi %hi(0xeb86d391),T2 !=
992 xor T1,D,T1
993 or T2,%lo(0xeb86d391),T2
994 add T1,R9,T1
995 !pre-LOADed X(0),R0
996 mov Aval,A !=
997 add T1,T2,T1
998 mov Dval,D
999 add B,T1,B
1000 sll B,21,T2 !=
1001 add Cval,C,Cval
1002 srl B,32-21,B
1003 st Cval,[Cptr]
1004 or B,T2,B !=
1005 add B,C,B
1006
1007 deccc %i2
1008 mov Cval,C
1009 add B,Bval,B !=
1010 inc 64,%i1
1011 nop
1012 st B,[Bptr]
1013 nop !=
1014
1015#ifdef ULTRASPARC
1016 bg,a,pt %icc,.Lmd5_block_loop
1017#else
1018 bg,a .Lmd5_block_loop
1019#endif
1020 LOAD X(0),R0
1021
1022#ifdef ASI_PRIMARY_LITTLE
1023 wr %g0,%o7,%asi
1024#endif
1025 ret
1026 restore %g0,0,%o0
1027
1028.type md5_block,#function
1029.size md5_block,(.-md5_block)
diff --git a/src/lib/libssl/src/crypto/mem_dbg.c b/src/lib/libssl/src/crypto/mem_dbg.c
new file mode 100644
index 0000000000..14770c0733
--- /dev/null
+++ b/src/lib/libssl/src/crypto/mem_dbg.c
@@ -0,0 +1,703 @@
1/* crypto/mem_dbg.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <time.h>
62#include <openssl/crypto.h>
63#include <openssl/buffer.h>
64#include <openssl/bio.h>
65#include <openssl/lhash.h>
66#include "cryptlib.h"
67
68static int mh_mode=CRYPTO_MEM_CHECK_OFF;
69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE
70 * when the application asks for it (usually after library initialisation
71 * for which no book-keeping is desired).
72 *
73 * State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
74 * thinks that certain allocations should not be checked (e.g. the data
75 * structures used for memory checking). It is not suitable as an initial
76 * state: the library will unexpectedly enable memory checking when it
77 * executes one of those sections that want to disable checking
78 * temporarily.
79 *
80 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
81 */
82
83static unsigned long order = 0; /* number of memory requests */
84static LHASH *mh=NULL; /* hash-table of memory requests (address as key) */
85
86
87typedef struct app_mem_info_st
88/* For application-defined information (static C-string `info')
89 * to be displayed in memory leak list.
90 * Each thread has its own stack. For applications, there is
91 * CRYPTO_push_info("...") to push an entry,
92 * CRYPTO_pop_info() to pop an entry,
93 * CRYPTO_remove_all_info() to pop all entries.
94 */
95 {
96 unsigned long thread;
97 const char *file;
98 int line;
99 const char *info;
100 struct app_mem_info_st *next; /* tail of thread's stack */
101 int references;
102 } APP_INFO;
103
104static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
105 * that are at the top of their thread's stack
106 * (with `thread' as key) */
107
108typedef struct mem_st
109/* memory-block description */
110 {
111 char *addr;
112 int num;
113 const char *file;
114 int line;
115 unsigned long thread;
116 unsigned long order;
117 time_t time;
118 APP_INFO *app_info;
119 } MEM;
120
121static long options = /* extra information to be recorded */
122#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
123 V_CRYPTO_MDEBUG_TIME |
124#endif
125#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
126 V_CRYPTO_MDEBUG_THREAD |
127#endif
128 0;
129
130
131static unsigned long disabling_thread = 0;
132
133int CRYPTO_mem_ctrl(int mode)
134 {
135 int ret=mh_mode;
136
137 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
138 switch (mode)
139 {
140 /* for applications: */
141 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
142 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
143 disabling_thread = 0;
144 break;
145 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
146 mh_mode = 0;
147 disabling_thread = 0;
148 break;
149
150 /* switch off temporarily (for library-internal use): */
151 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
152 if (mh_mode & CRYPTO_MEM_CHECK_ON)
153 {
154 mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
155 if (disabling_thread != CRYPTO_thread_id()) /* otherwise we already have the MALLOC2 lock */
156 {
157 /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
158 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
159 * somebody else holds CRYPTO_LOCK_MALLOC2 (and cannot release
160 * it because we block entry to this function).
161 * Give them a chance, first, and then claim the locks in
162 * appropriate order (long-time lock first).
163 */
164 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
165 /* Note that after we have waited for CRYPTO_LOCK_MALLOC2
166 * and CRYPTO_LOCK_MALLOC, we'll still be in the right
167 * "case" and "if" branch because MemCheck_start and
168 * MemCheck_stop may never be used while there are multiple
169 * OpenSSL threads. */
170 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
171 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
172 disabling_thread=CRYPTO_thread_id();
173 }
174 }
175 break;
176 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
177 if (mh_mode & CRYPTO_MEM_CHECK_ON)
178 {
179 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
180 if (disabling_thread != 0)
181 {
182 disabling_thread=0;
183 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
184 }
185 }
186 break;
187
188 default:
189 break;
190 }
191 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
192 return(ret);
193 }
194
195int CRYPTO_is_mem_check_on(void)
196 {
197 int ret = 0;
198
199 if (mh_mode & CRYPTO_MEM_CHECK_ON)
200 {
201 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
202
203 ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
204 && disabling_thread != CRYPTO_thread_id();
205
206 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
207 }
208 return(ret);
209 }
210
211
212void CRYPTO_dbg_set_options(long bits)
213 {
214 options = bits;
215 }
216
217long CRYPTO_dbg_get_options(void)
218 {
219 return options;
220 }
221
222static int mem_cmp(MEM *a, MEM *b)
223 {
224 return(a->addr - b->addr);
225 }
226
227static unsigned long mem_hash(MEM *a)
228 {
229 unsigned long ret;
230
231 ret=(unsigned long)a->addr;
232
233 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
234 return(ret);
235 }
236
237static int app_info_cmp(APP_INFO *a, APP_INFO *b)
238 {
239 return(a->thread != b->thread);
240 }
241
242static unsigned long app_info_hash(APP_INFO *a)
243 {
244 unsigned long ret;
245
246 ret=(unsigned long)a->thread;
247
248 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
249 return(ret);
250 }
251
252static APP_INFO *pop_info()
253 {
254 APP_INFO tmp;
255 APP_INFO *ret = NULL;
256
257 if (amih != NULL)
258 {
259 tmp.thread=CRYPTO_thread_id();
260 if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
261 {
262 APP_INFO *next=ret->next;
263
264 if (next != NULL)
265 {
266 next->references++;
267 lh_insert(amih,(char *)next);
268 }
269#ifdef LEVITTE_DEBUG
270 if (ret->thread != tmp.thread)
271 {
272 fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
273 ret->thread, tmp.thread);
274 abort();
275 }
276#endif
277 if (--(ret->references) <= 0)
278 {
279 ret->next = NULL;
280 if (next != NULL)
281 next->references--;
282 Free(ret);
283 }
284 }
285 }
286 return(ret);
287 }
288
289int CRYPTO_push_info_(const char *info, const char *file, int line)
290 {
291 APP_INFO *ami, *amim;
292 int ret=0;
293
294 if (is_MemCheck_on())
295 {
296 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
297
298 if ((ami = (APP_INFO *)Malloc(sizeof(APP_INFO))) == NULL)
299 {
300 ret=0;
301 goto err;
302 }
303 if (amih == NULL)
304 {
305 if ((amih=lh_new(app_info_hash,app_info_cmp)) == NULL)
306 {
307 Free(ami);
308 ret=0;
309 goto err;
310 }
311 }
312
313 ami->thread=CRYPTO_thread_id();
314 ami->file=file;
315 ami->line=line;
316 ami->info=info;
317 ami->references=1;
318 ami->next=NULL;
319
320 if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
321 {
322#ifdef LEVITTE_DEBUG
323 if (ami->thread != amim->thread)
324 {
325 fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
326 amim->thread, ami->thread);
327 abort();
328 }
329#endif
330 ami->next=amim;
331 }
332 err:
333 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
334 }
335
336 return(ret);
337 }
338
339int CRYPTO_pop_info(void)
340 {
341 int ret=0;
342
343 if (is_MemCheck_on()) /* _must_ be true, or something went severely wrong */
344 {
345 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
346
347 ret=(pop_info() != NULL);
348
349 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
350 }
351 return(ret);
352 }
353
354int CRYPTO_remove_all_info(void)
355 {
356 int ret=0;
357
358 if (is_MemCheck_on()) /* _must_ be true */
359 {
360 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
361
362 while(pop_info() != NULL)
363 ret++;
364
365 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
366 }
367 return(ret);
368 }
369
370
371static unsigned long break_order_num=0;
372void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
373 int before_p)
374 {
375 MEM *m,*mm;
376 APP_INFO tmp,*amim;
377
378 switch(before_p & 127)
379 {
380 case 0:
381 break;
382 case 1:
383 if (addr == NULL)
384 break;
385
386 if (is_MemCheck_on())
387 {
388 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
389 if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL)
390 {
391 Free(addr);
392 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
393 return;
394 }
395 if (mh == NULL)
396 {
397 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
398 {
399 Free(addr);
400 Free(m);
401 addr=NULL;
402 goto err;
403 }
404 }
405
406 m->addr=addr;
407 m->file=file;
408 m->line=line;
409 m->num=num;
410 if (options & V_CRYPTO_MDEBUG_THREAD)
411 m->thread=CRYPTO_thread_id();
412 else
413 m->thread=0;
414
415 if (order == break_order_num)
416 {
417 /* BREAK HERE */
418 m->order=order;
419 }
420 m->order=order++;
421#ifdef LEVITTE_DEBUG
422 fprintf(stderr, "LEVITTE_DEBUG: [%5d] %c 0x%p (%d)\n",
423 m->order,
424 (before_p & 128) ? '*' : '+',
425 m->addr, m->num);
426#endif
427 if (options & V_CRYPTO_MDEBUG_TIME)
428 m->time=time(NULL);
429 else
430 m->time=0;
431
432 tmp.thread=CRYPTO_thread_id();
433 m->app_info=NULL;
434 if (amih != NULL
435 && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
436 {
437 m->app_info = amim;
438 amim->references++;
439 }
440
441 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
442 {
443 /* Not good, but don't sweat it */
444 if (mm->app_info != NULL)
445 {
446 mm->app_info->references--;
447 }
448 Free(mm);
449 }
450 err:
451 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
452 }
453 break;
454 }
455 return;
456 }
457
458void CRYPTO_dbg_free(void *addr, int before_p)
459 {
460 MEM m,*mp;
461
462 switch(before_p)
463 {
464 case 0:
465 if (addr == NULL)
466 break;
467
468 if (is_MemCheck_on() && (mh != NULL))
469 {
470 MemCheck_off();
471
472 m.addr=addr;
473 mp=(MEM *)lh_delete(mh,(char *)&m);
474 if (mp != NULL)
475 {
476#ifdef LEVITTE_DEBUG
477 fprintf(stderr, "LEVITTE_DEBUG: [%5d] - 0x%p (%d)\n",
478 mp->order, mp->addr, mp->num);
479#endif
480 if (mp->app_info != NULL)
481 {
482 mp->app_info->references--;
483 }
484 Free(mp);
485 }
486
487 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
488 }
489 break;
490 case 1:
491 break;
492 }
493 }
494
495void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
496 const char *file, int line, int before_p)
497 {
498 MEM m,*mp;
499
500#ifdef LEVITTE_DEBUG
501 fprintf(stderr, "LEVITTE_DEBUG: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
502 addr1, addr2, num, file, line, before_p);
503#endif
504
505 switch(before_p)
506 {
507 case 0:
508 break;
509 case 1:
510 if (addr2 == NULL)
511 break;
512
513 if (addr1 == NULL)
514 {
515 CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
516 break;
517 }
518
519 if (is_MemCheck_on())
520 {
521 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
522
523 m.addr=addr1;
524 mp=(MEM *)lh_delete(mh,(char *)&m);
525 if (mp != NULL)
526 {
527#ifdef LEVITTE_DEBUG
528 fprintf(stderr, "LEVITTE_DEBUG: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
529 mp->order,
530 mp->addr, mp->num,
531 addr2, num);
532#endif
533 mp->addr=addr2;
534 mp->num=num;
535 lh_insert(mh,(char *)mp);
536 }
537
538 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
539 }
540 break;
541 }
542 return;
543 }
544
545
546typedef struct mem_leak_st
547 {
548 BIO *bio;
549 int chunks;
550 long bytes;
551 } MEM_LEAK;
552
553static void print_leak(MEM *m, MEM_LEAK *l)
554 {
555 char buf[1024];
556 char *bufp = buf;
557 APP_INFO *amip;
558 int ami_cnt;
559 struct tm *lcl = NULL;
560 unsigned long ti;
561
562 if(m->addr == (char *)l->bio)
563 return;
564
565 if (options & V_CRYPTO_MDEBUG_TIME)
566 {
567 lcl = localtime(&m->time);
568
569 sprintf(bufp, "[%02d:%02d:%02d] ",
570 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
571 bufp += strlen(bufp);
572 }
573
574 sprintf(bufp, "%5lu file=%s, line=%d, ",
575 m->order,m->file,m->line);
576 bufp += strlen(bufp);
577
578 if (options & V_CRYPTO_MDEBUG_THREAD)
579 {
580 sprintf(bufp, "thread=%lu, ", m->thread);
581 bufp += strlen(bufp);
582 }
583
584 sprintf(bufp, "number=%d, address=%08lX\n",
585 m->num,(unsigned long)m->addr);
586 bufp += strlen(bufp);
587
588 BIO_puts(l->bio,buf);
589
590 l->chunks++;
591 l->bytes+=m->num;
592
593 amip=m->app_info;
594 ami_cnt=0;
595 if (!amip)
596 return;
597 ti=amip->thread;
598
599 do
600 {
601 int buf_len;
602 int info_len;
603
604 ami_cnt++;
605 memset(buf,'>',ami_cnt);
606 sprintf(buf + ami_cnt,
607 " thread=%lu, file=%s, line=%d, info=\"",
608 amip->thread, amip->file, amip->line);
609 buf_len=strlen(buf);
610 info_len=strlen(amip->info);
611 if (128 - buf_len - 3 < info_len)
612 {
613 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
614 buf_len = 128 - 3;
615 }
616 else
617 {
618 strcpy(buf + buf_len, amip->info);
619 buf_len = strlen(buf);
620 }
621 sprintf(buf + buf_len, "\"\n");
622
623 BIO_puts(l->bio,buf);
624
625 amip = amip->next;
626 }
627 while(amip && amip->thread == ti);
628
629#ifdef LEVITTE_DEBUG
630 if (amip)
631 {
632 fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
633 abort();
634 }
635#endif
636 }
637
638void CRYPTO_mem_leaks(BIO *b)
639 {
640 MEM_LEAK ml;
641 char buf[80];
642
643 if (mh == NULL) return;
644 ml.bio=b;
645 ml.bytes=0;
646 ml.chunks=0;
647 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
648 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
649 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
650 if (ml.chunks != 0)
651 {
652 sprintf(buf,"%ld bytes leaked in %d chunks\n",
653 ml.bytes,ml.chunks);
654 BIO_puts(b,buf);
655 }
656
657#if 0
658 lh_stats_bio(mh,b);
659 lh_node_stats_bio(mh,b);
660 lh_node_usage_stats_bio(mh,b);
661#endif
662 }
663
664union void_fn_to_char_u
665 {
666 char *char_p;
667 void (*fn_p)();
668 };
669
670static void cb_leak(MEM *m, char *cb)
671 {
672 union void_fn_to_char_u mem_callback;
673
674 mem_callback.char_p=cb;
675 mem_callback.fn_p(m->order,m->file,m->line,m->num,m->addr);
676 }
677
678void CRYPTO_mem_leaks_cb(void (*cb)())
679 {
680 union void_fn_to_char_u mem_cb;
681
682 if (mh == NULL) return;
683 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
684 mem_cb.fn_p=cb;
685 lh_doall_arg(mh,(void (*)())cb_leak,mem_cb.char_p);
686 mem_cb.char_p=NULL;
687 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
688 }
689
690#ifndef NO_FP_API
691void CRYPTO_mem_leaks_fp(FILE *fp)
692 {
693 BIO *b;
694
695 if (mh == NULL) return;
696 if ((b=BIO_new(BIO_s_file())) == NULL)
697 return;
698 BIO_set_fp(b,fp,BIO_NOCLOSE);
699 CRYPTO_mem_leaks(b);
700 BIO_free(b);
701 }
702#endif
703
diff --git a/src/lib/libssl/src/crypto/o_time.c b/src/lib/libssl/src/crypto/o_time.c
new file mode 100644
index 0000000000..1bc0297b36
--- /dev/null
+++ b/src/lib/libssl/src/crypto/o_time.c
@@ -0,0 +1,203 @@
1/* crypto/o_time.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/e_os2.h>
60#include <string.h>
61#include "o_time.h"
62
63#ifdef OPENSSL_SYS_VMS
64# include <libdtdef.h>
65# include <lib$routines.h>
66# include <lnmdef.h>
67# include <starlet.h>
68# include <descrip.h>
69# include <stdlib.h>
70#endif
71
72struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
73 {
74 struct tm *ts = NULL;
75
76#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)
77 /* should return &data, but doesn't on some systems,
78 so we don't even look at the return value */
79 gmtime_r(timer,result);
80 ts = result;
81#elif !defined(OPENSSL_SYS_VMS)
82 ts = gmtime(timer);
83 memcpy(result, ts, sizeof(struct tm));
84 ts = result;
85#endif
86#ifdef OPENSSL_SYS_VMS
87 if (ts == NULL)
88 {
89 static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
90 static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
91 char logvalue[256];
92 unsigned int reslen = 0;
93 struct {
94 short buflen;
95 short code;
96 void *bufaddr;
97 unsigned int *reslen;
98 } itemlist[] = {
99 { 0, LNM$_STRING, 0, 0 },
100 { 0, 0, 0, 0 },
101 };
102 int status;
103 time_t t;
104
105 /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
106 itemlist[0].buflen = sizeof(logvalue);
107 itemlist[0].bufaddr = logvalue;
108 itemlist[0].reslen = &reslen;
109 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
110 if (!(status & 1))
111 return NULL;
112 logvalue[reslen] = '\0';
113
114 /* Get the numerical value of the equivalence string */
115 status = atoi(logvalue);
116
117 /* and use it to move time to GMT */
118 t = *timer - status;
119
120 /* then convert the result to the time structure */
121#ifndef OPENSSL_THREADS
122 ts=(struct tm *)localtime(&t);
123#else
124 /* Since there was no gmtime_r() to do this stuff for us,
125 we have to do it the hard way. */
126 {
127 /* The VMS epoch is the astronomical Smithsonian date,
128 if I remember correctly, which is November 17, 1858.
129 Furthermore, time is measure in thenths of microseconds
130 and stored in quadwords (64 bit integers). unix_epoch
131 below is January 1st 1970 expressed as a VMS time. The
132 following code was used to get this number:
133
134 #include <stdio.h>
135 #include <stdlib.h>
136 #include <lib$routines.h>
137 #include <starlet.h>
138
139 main()
140 {
141 unsigned long systime[2];
142 unsigned short epoch_values[7] =
143 { 1970, 1, 1, 0, 0, 0, 0 };
144
145 lib$cvt_vectim(epoch_values, systime);
146
147 printf("%u %u", systime[0], systime[1]);
148 }
149 */
150 unsigned long unix_epoch[2] = { 1273708544, 8164711 };
151 unsigned long deltatime[2];
152 unsigned long systime[2];
153 struct vms_vectime
154 {
155 short year, month, day, hour, minute, second,
156 centi_second;
157 } time_values;
158 long operation;
159
160 /* Turn the number of seconds since January 1st 1970 to
161 an internal delta time.
162 Note that lib$cvt_to_internal_time() will assume
163 that t is signed, and will therefore break on 32-bit
164 systems some time in 2038.
165 */
166 operation = LIB$K_DELTA_SECONDS;
167 status = lib$cvt_to_internal_time(&operation,
168 &t, deltatime);
169
170 /* Add the delta time with the Unix epoch and we have
171 the current UTC time in internal format */
172 status = lib$add_times(unix_epoch, deltatime, systime);
173
174 /* Turn the internal time into a time vector */
175 status = sys$numtim(&time_values, systime);
176
177 /* Fill in the struct tm with the result */
178 result->tm_sec = time_values.second;
179 result->tm_min = time_values.minute;
180 result->tm_hour = time_values.hour;
181 result->tm_mday = time_values.day;
182 result->tm_mon = time_values.month - 1;
183 result->tm_year = time_values.year - 1900;
184
185 operation = LIB$K_DAY_OF_WEEK;
186 status = lib$cvt_from_internal_time(&operation,
187 &result->tm_wday, systime);
188 result->tm_wday %= 7;
189
190 operation = LIB$K_DAY_OF_YEAR;
191 status = lib$cvt_from_internal_time(&operation,
192 &result->tm_yday, systime);
193 result->tm_yday--;
194
195 result->tm_isdst = 0; /* There's no way to know... */
196
197 ts = result;
198#endif
199 }
200 }
201#endif
202 return ts;
203 }
diff --git a/src/lib/libssl/src/crypto/o_time.h b/src/lib/libssl/src/crypto/o_time.h
new file mode 100644
index 0000000000..e66044626d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/o_time.h
@@ -0,0 +1,66 @@
1/* crypto/o_time.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_O_TIME_H
60#define HEADER_O_TIME_H
61
62#include <time.h>
63
64struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
65
66#endif
diff --git a/src/lib/libssl/src/crypto/objects/o_names.c b/src/lib/libssl/src/crypto/objects/o_names.c
new file mode 100644
index 0000000000..4da5e45b9c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/o_names.c
@@ -0,0 +1,243 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <openssl/lhash.h>
6#include <openssl/objects.h>
7
8/* I use the ex_data stuff to manage the identifiers for the obj_name_types
9 * that applications may define. I only really use the free function field.
10 */
11static LHASH *names_lh=NULL;
12static int names_type_num=OBJ_NAME_TYPE_NUM;
13static STACK *names_cmp=NULL;
14static STACK *names_hash=NULL;
15static STACK *names_free=NULL;
16
17static unsigned long obj_name_hash(OBJ_NAME *a);
18static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b);
19
20int OBJ_NAME_init(void)
21 {
22 if (names_lh != NULL) return(1);
23 MemCheck_off();
24 names_lh=lh_new(obj_name_hash,obj_name_cmp);
25 MemCheck_on();
26 return(names_lh != NULL);
27 }
28
29int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(),
30 void (*free_func)())
31 {
32 int ret;
33 int i;
34
35 if (names_free == NULL)
36 {
37 MemCheck_off();
38 names_hash=sk_new_null();
39 names_cmp=sk_new_null();
40 names_free=sk_new_null();
41 MemCheck_on();
42 }
43 if ((names_free == NULL) || (names_hash == NULL) || (names_cmp == NULL))
44 {
45 /* ERROR */
46 return(0);
47 }
48 ret=names_type_num;
49 names_type_num++;
50 for (i=sk_num(names_free); i<names_type_num; i++)
51 {
52 MemCheck_off();
53 sk_push(names_hash,(char *)strcmp);
54 sk_push(names_cmp,(char *)lh_strhash);
55 sk_push(names_free,NULL);
56 MemCheck_on();
57 }
58 if (hash_func != NULL)
59 sk_set(names_hash,ret,(char *)hash_func);
60 if (cmp_func != NULL)
61 sk_set(names_cmp,ret,(char *)cmp_func);
62 if (free_func != NULL)
63 sk_set(names_free,ret,(char *)free_func);
64 return(ret);
65 }
66
67static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
68 {
69 int ret;
70 int (*cmp)();
71
72 ret=a->type-b->type;
73 if (ret == 0)
74 {
75 if ((names_cmp != NULL) && (sk_num(names_cmp) > a->type))
76 {
77 cmp=(int (*)())sk_value(names_cmp,a->type);
78 ret=cmp(a->name,b->name);
79 }
80 else
81 ret=strcmp(a->name,b->name);
82 }
83 return(ret);
84 }
85
86static unsigned long obj_name_hash(OBJ_NAME *a)
87 {
88 unsigned long ret;
89 unsigned long (*hash)();
90
91 if ((names_hash != NULL) && (sk_num(names_hash) > a->type))
92 {
93 hash=(unsigned long (*)())sk_value(names_hash,a->type);
94 ret=hash(a->name);
95 }
96 else
97 {
98 ret=lh_strhash(a->name);
99 }
100 ret^=a->type;
101 return(ret);
102 }
103
104const char *OBJ_NAME_get(const char *name, int type)
105 {
106 OBJ_NAME on,*ret;
107 int num=0,alias;
108
109 if (name == NULL) return(NULL);
110 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
111
112 alias=type&OBJ_NAME_ALIAS;
113 type&= ~OBJ_NAME_ALIAS;
114
115 on.name=name;
116 on.type=type;
117
118 for (;;)
119 {
120 ret=(OBJ_NAME *)lh_retrieve(names_lh,(char *)&on);
121 if (ret == NULL) return(NULL);
122 if ((ret->alias) && !alias)
123 {
124 if (++num > 10) return(NULL);
125 on.name=ret->data;
126 }
127 else
128 {
129 return(ret->data);
130 }
131 }
132 }
133
134int OBJ_NAME_add(const char *name, int type, const char *data)
135 {
136 void (*f)();
137 OBJ_NAME *onp,*ret;
138 int alias;
139
140 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
141
142 alias=type&OBJ_NAME_ALIAS;
143 type&= ~OBJ_NAME_ALIAS;
144
145 onp=(OBJ_NAME *)Malloc(sizeof(OBJ_NAME));
146 if (onp == NULL)
147 {
148 /* ERROR */
149 return(0);
150 }
151
152 onp->name=name;
153 onp->alias=alias;
154 onp->type=type;
155 onp->data=data;
156
157 ret=(OBJ_NAME *)lh_insert(names_lh,(char *)onp);
158 if (ret != NULL)
159 {
160 /* free things */
161 if ((names_free != NULL) && (sk_num(names_free) > ret->type))
162 {
163 f=(void (*)())sk_value(names_free,ret->type);
164 f(ret->name,ret->type,ret->data);
165 }
166 Free((char *)ret);
167 }
168 else
169 {
170 if (lh_error(names_lh))
171 {
172 /* ERROR */
173 return(0);
174 }
175 }
176 return(1);
177 }
178
179int OBJ_NAME_remove(const char *name, int type)
180 {
181 OBJ_NAME on,*ret;
182 void (*f)();
183
184 if (names_lh == NULL) return(0);
185
186 type&= ~OBJ_NAME_ALIAS;
187 on.name=name;
188 on.type=type;
189 ret=(OBJ_NAME *)lh_delete(names_lh,(char *)&on);
190 if (ret != NULL)
191 {
192 /* free things */
193 if ((names_free != NULL) && (sk_num(names_free) > type))
194 {
195 f=(void (*)())sk_value(names_free,type);
196 f(ret->name,ret->type,ret->data);
197 }
198 Free((char *)ret);
199 return(1);
200 }
201 else
202 return(0);
203 }
204
205static int free_type;
206
207static void names_lh_free(OBJ_NAME *onp, int type)
208{
209 if(onp == NULL)
210 return;
211
212 if ((free_type < 0) || (free_type == onp->type))
213 {
214 OBJ_NAME_remove(onp->name,onp->type);
215 }
216 }
217
218void OBJ_NAME_cleanup(int type)
219 {
220 unsigned long down_load;
221
222 if (names_lh == NULL) return;
223
224 free_type=type;
225 down_load=names_lh->down_load;
226 names_lh->down_load=0;
227
228 lh_doall(names_lh,names_lh_free);
229 if (type < 0)
230 {
231 lh_free(names_lh);
232 sk_free(names_hash);
233 sk_free(names_cmp);
234 sk_free(names_free);
235 names_lh=NULL;
236 names_hash=NULL;
237 names_cmp=NULL;
238 names_free=NULL;
239 }
240 else
241 names_lh->down_load=down_load;
242 }
243
diff --git a/src/lib/libssl/src/crypto/objects/obj_mac.h b/src/lib/libssl/src/crypto/objects/obj_mac.h
new file mode 100644
index 0000000000..401b1e5a1b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_mac.h
@@ -0,0 +1,1798 @@
1/* lib/obj/obj_mac.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
60 * following command:
61 * perl objects.pl objects.txt obj_mac.num obj_mac.h
62 */
63
64#define SN_undef "UNDEF"
65#define LN_undef "undefined"
66#define NID_undef 0
67#define OBJ_undef 0L
68
69#define SN_iso "ISO"
70#define LN_iso "iso"
71#define NID_iso 181
72#define OBJ_iso 1L
73
74#define SN_member_body "member-body"
75#define LN_member_body "ISO Member Body"
76#define NID_member_body 182
77#define OBJ_member_body OBJ_iso,2L
78
79#define SN_ISO_US "ISO-US"
80#define LN_ISO_US "ISO US Member Body"
81#define NID_ISO_US 183
82#define OBJ_ISO_US OBJ_member_body,840L
83
84#define SN_X9_57 "X9-57"
85#define LN_X9_57 "X9.57"
86#define NID_X9_57 184
87#define OBJ_X9_57 OBJ_ISO_US,10040L
88
89#define SN_X9cm "X9cm"
90#define LN_X9cm "X9.57 CM ?"
91#define NID_X9cm 185
92#define OBJ_X9cm OBJ_X9_57,4L
93
94#define SN_dsa "DSA"
95#define LN_dsa "dsaEncryption"
96#define NID_dsa 116
97#define OBJ_dsa OBJ_X9cm,1L
98
99#define SN_dsaWithSHA1 "DSA-SHA1"
100#define LN_dsaWithSHA1 "dsaWithSHA1"
101#define NID_dsaWithSHA1 113
102#define OBJ_dsaWithSHA1 OBJ_X9cm,3L
103
104#define SN_cast5_cbc "CAST5-CBC"
105#define LN_cast5_cbc "cast5-cbc"
106#define NID_cast5_cbc 108
107#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L
108
109#define SN_cast5_ecb "CAST5-ECB"
110#define LN_cast5_ecb "cast5-ecb"
111#define NID_cast5_ecb 109
112
113#define SN_cast5_cfb64 "CAST5-CFB"
114#define LN_cast5_cfb64 "cast5-cfb"
115#define NID_cast5_cfb64 110
116
117#define SN_cast5_ofb64 "CAST5-OFB"
118#define LN_cast5_ofb64 "cast5-ofb"
119#define NID_cast5_ofb64 111
120
121#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
122#define NID_pbeWithMD5AndCast5_CBC 112
123#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L
124
125#define SN_rsadsi "rsadsi"
126#define LN_rsadsi "RSA Data Security, Inc."
127#define NID_rsadsi 1
128#define OBJ_rsadsi OBJ_ISO_US,113549L
129
130#define SN_pkcs "pkcs"
131#define LN_pkcs "RSA Data Security, Inc. PKCS"
132#define NID_pkcs 2
133#define OBJ_pkcs OBJ_rsadsi,1L
134
135#define SN_pkcs1 "pkcs1"
136#define NID_pkcs1 186
137#define OBJ_pkcs1 OBJ_pkcs,1L
138
139#define LN_rsaEncryption "rsaEncryption"
140#define NID_rsaEncryption 6
141#define OBJ_rsaEncryption OBJ_pkcs1,1L
142
143#define SN_md2WithRSAEncryption "RSA-MD2"
144#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
145#define NID_md2WithRSAEncryption 7
146#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L
147
148#define SN_md5WithRSAEncryption "RSA-MD5"
149#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
150#define NID_md5WithRSAEncryption 8
151#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L
152
153#define SN_sha1WithRSAEncryption "RSA-SHA1"
154#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
155#define NID_sha1WithRSAEncryption 65
156#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L
157
158#define SN_pkcs3 "pkcs3"
159#define NID_pkcs3 27
160#define OBJ_pkcs3 OBJ_pkcs,3L
161
162#define LN_dhKeyAgreement "dhKeyAgreement"
163#define NID_dhKeyAgreement 28
164#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
165
166#define SN_pkcs5 "pkcs5"
167#define NID_pkcs5 187
168#define OBJ_pkcs5 OBJ_pkcs,5L
169
170#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
171#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
172#define NID_pbeWithMD2AndDES_CBC 9
173#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L
174
175#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
176#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
177#define NID_pbeWithMD5AndDES_CBC 10
178#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L
179
180#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
181#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
182#define NID_pbeWithMD2AndRC2_CBC 168
183#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L
184
185#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
186#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
187#define NID_pbeWithMD5AndRC2_CBC 169
188#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L
189
190#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
191#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
192#define NID_pbeWithSHA1AndDES_CBC 170
193#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L
194
195#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
196#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
197#define NID_pbeWithSHA1AndRC2_CBC 68
198#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L
199
200#define LN_id_pbkdf2 "PBKDF2"
201#define NID_id_pbkdf2 69
202#define OBJ_id_pbkdf2 OBJ_pkcs5,12L
203
204#define LN_pbes2 "PBES2"
205#define NID_pbes2 161
206#define OBJ_pbes2 OBJ_pkcs5,13L
207
208#define LN_pbmac1 "PBMAC1"
209#define NID_pbmac1 162
210#define OBJ_pbmac1 OBJ_pkcs5,14L
211
212#define SN_pkcs7 "pkcs7"
213#define NID_pkcs7 20
214#define OBJ_pkcs7 OBJ_pkcs,7L
215
216#define LN_pkcs7_data "pkcs7-data"
217#define NID_pkcs7_data 21
218#define OBJ_pkcs7_data OBJ_pkcs7,1L
219
220#define LN_pkcs7_signed "pkcs7-signedData"
221#define NID_pkcs7_signed 22
222#define OBJ_pkcs7_signed OBJ_pkcs7,2L
223
224#define LN_pkcs7_enveloped "pkcs7-envelopedData"
225#define NID_pkcs7_enveloped 23
226#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
227
228#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
229#define NID_pkcs7_signedAndEnveloped 24
230#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
231
232#define LN_pkcs7_digest "pkcs7-digestData"
233#define NID_pkcs7_digest 25
234#define OBJ_pkcs7_digest OBJ_pkcs7,5L
235
236#define LN_pkcs7_encrypted "pkcs7-encryptedData"
237#define NID_pkcs7_encrypted 26
238#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
239
240#define SN_pkcs9 "pkcs9"
241#define NID_pkcs9 47
242#define OBJ_pkcs9 OBJ_pkcs,9L
243
244#define SN_pkcs9_emailAddress "Email"
245#define LN_pkcs9_emailAddress "emailAddress"
246#define NID_pkcs9_emailAddress 48
247#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
248
249#define LN_pkcs9_unstructuredName "unstructuredName"
250#define NID_pkcs9_unstructuredName 49
251#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
252
253#define LN_pkcs9_contentType "contentType"
254#define NID_pkcs9_contentType 50
255#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
256
257#define LN_pkcs9_messageDigest "messageDigest"
258#define NID_pkcs9_messageDigest 51
259#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
260
261#define LN_pkcs9_signingTime "signingTime"
262#define NID_pkcs9_signingTime 52
263#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
264
265#define LN_pkcs9_countersignature "countersignature"
266#define NID_pkcs9_countersignature 53
267#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
268
269#define LN_pkcs9_challengePassword "challengePassword"
270#define NID_pkcs9_challengePassword 54
271#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
272
273#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
274#define NID_pkcs9_unstructuredAddress 55
275#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
276
277#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
278#define NID_pkcs9_extCertAttributes 56
279#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
280
281#define SN_ext_req "extReq"
282#define LN_ext_req "Extension Request"
283#define NID_ext_req 172
284#define OBJ_ext_req OBJ_pkcs9,14L
285
286#define SN_SMIMECapabilities "SMIME-CAPS"
287#define LN_SMIMECapabilities "S/MIME Capabilities"
288#define NID_SMIMECapabilities 167
289#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
290
291#define SN_SMIME "SMIME"
292#define LN_SMIME "S/MIME"
293#define NID_SMIME 188
294#define OBJ_SMIME OBJ_pkcs9,16L
295
296#define SN_id_smime_mod "id-smime-mod"
297#define NID_id_smime_mod 189
298#define OBJ_id_smime_mod OBJ_SMIME,0L
299
300#define SN_id_smime_ct "id-smime-ct"
301#define NID_id_smime_ct 190
302#define OBJ_id_smime_ct OBJ_SMIME,1L
303
304#define SN_id_smime_aa "id-smime-aa"
305#define NID_id_smime_aa 191
306#define OBJ_id_smime_aa OBJ_SMIME,2L
307
308#define SN_id_smime_alg "id-smime-alg"
309#define NID_id_smime_alg 192
310#define OBJ_id_smime_alg OBJ_SMIME,3L
311
312#define SN_id_smime_cd "id-smime-cd"
313#define NID_id_smime_cd 193
314#define OBJ_id_smime_cd OBJ_SMIME,4L
315
316#define SN_id_smime_spq "id-smime-spq"
317#define NID_id_smime_spq 194
318#define OBJ_id_smime_spq OBJ_SMIME,5L
319
320#define SN_id_smime_cti "id-smime-cti"
321#define NID_id_smime_cti 195
322#define OBJ_id_smime_cti OBJ_SMIME,6L
323
324#define SN_id_smime_mod_cms "id-smime-mod-cms"
325#define NID_id_smime_mod_cms 196
326#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L
327
328#define SN_id_smime_mod_ess "id-smime-mod-ess"
329#define NID_id_smime_mod_ess 197
330#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L
331
332#define SN_id_smime_mod_oid "id-smime-mod-oid"
333#define NID_id_smime_mod_oid 198
334#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L
335
336#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3"
337#define NID_id_smime_mod_msg_v3 199
338#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L
339
340#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88"
341#define NID_id_smime_mod_ets_eSignature_88 200
342#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L
343
344#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97"
345#define NID_id_smime_mod_ets_eSignature_97 201
346#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L
347
348#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88"
349#define NID_id_smime_mod_ets_eSigPolicy_88 202
350#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L
351
352#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97"
353#define NID_id_smime_mod_ets_eSigPolicy_97 203
354#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L
355
356#define SN_id_smime_ct_receipt "id-smime-ct-receipt"
357#define NID_id_smime_ct_receipt 204
358#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L
359
360#define SN_id_smime_ct_authData "id-smime-ct-authData"
361#define NID_id_smime_ct_authData 205
362#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L
363
364#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert"
365#define NID_id_smime_ct_publishCert 206
366#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L
367
368#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo"
369#define NID_id_smime_ct_TSTInfo 207
370#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L
371
372#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo"
373#define NID_id_smime_ct_TDTInfo 208
374#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L
375
376#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo"
377#define NID_id_smime_ct_contentInfo 209
378#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L
379
380#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData"
381#define NID_id_smime_ct_DVCSRequestData 210
382#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L
383
384#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData"
385#define NID_id_smime_ct_DVCSResponseData 211
386#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L
387
388#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest"
389#define NID_id_smime_aa_receiptRequest 212
390#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L
391
392#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel"
393#define NID_id_smime_aa_securityLabel 213
394#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L
395
396#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory"
397#define NID_id_smime_aa_mlExpandHistory 214
398#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L
399
400#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint"
401#define NID_id_smime_aa_contentHint 215
402#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L
403
404#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest"
405#define NID_id_smime_aa_msgSigDigest 216
406#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L
407
408#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType"
409#define NID_id_smime_aa_encapContentType 217
410#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L
411
412#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier"
413#define NID_id_smime_aa_contentIdentifier 218
414#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L
415
416#define SN_id_smime_aa_macValue "id-smime-aa-macValue"
417#define NID_id_smime_aa_macValue 219
418#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L
419
420#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels"
421#define NID_id_smime_aa_equivalentLabels 220
422#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L
423
424#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference"
425#define NID_id_smime_aa_contentReference 221
426#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L
427
428#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref"
429#define NID_id_smime_aa_encrypKeyPref 222
430#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L
431
432#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate"
433#define NID_id_smime_aa_signingCertificate 223
434#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L
435
436#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts"
437#define NID_id_smime_aa_smimeEncryptCerts 224
438#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L
439
440#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken"
441#define NID_id_smime_aa_timeStampToken 225
442#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L
443
444#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId"
445#define NID_id_smime_aa_ets_sigPolicyId 226
446#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L
447
448#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType"
449#define NID_id_smime_aa_ets_commitmentType 227
450#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L
451
452#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation"
453#define NID_id_smime_aa_ets_signerLocation 228
454#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L
455
456#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr"
457#define NID_id_smime_aa_ets_signerAttr 229
458#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L
459
460#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert"
461#define NID_id_smime_aa_ets_otherSigCert 230
462#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L
463
464#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp"
465#define NID_id_smime_aa_ets_contentTimestamp 231
466#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L
467
468#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs"
469#define NID_id_smime_aa_ets_CertificateRefs 232
470#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L
471
472#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs"
473#define NID_id_smime_aa_ets_RevocationRefs 233
474#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L
475
476#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues"
477#define NID_id_smime_aa_ets_certValues 234
478#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L
479
480#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues"
481#define NID_id_smime_aa_ets_revocationValues 235
482#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L
483
484#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp"
485#define NID_id_smime_aa_ets_escTimeStamp 236
486#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L
487
488#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp"
489#define NID_id_smime_aa_ets_certCRLTimestamp 237
490#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L
491
492#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp"
493#define NID_id_smime_aa_ets_archiveTimeStamp 238
494#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L
495
496#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType"
497#define NID_id_smime_aa_signatureType 239
498#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L
499
500#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc"
501#define NID_id_smime_aa_dvcs_dvc 240
502#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L
503
504#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES"
505#define NID_id_smime_alg_ESDHwith3DES 241
506#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L
507
508#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2"
509#define NID_id_smime_alg_ESDHwithRC2 242
510#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L
511
512#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap"
513#define NID_id_smime_alg_3DESwrap 243
514#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L
515
516#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap"
517#define NID_id_smime_alg_RC2wrap 244
518#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L
519
520#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH"
521#define NID_id_smime_alg_ESDH 245
522#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L
523
524#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap"
525#define NID_id_smime_alg_CMS3DESwrap 246
526#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L
527
528#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap"
529#define NID_id_smime_alg_CMSRC2wrap 247
530#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L
531
532#define SN_id_smime_cd_ldap "id-smime-cd-ldap"
533#define NID_id_smime_cd_ldap 248
534#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L
535
536#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri"
537#define NID_id_smime_spq_ets_sqt_uri 249
538#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L
539
540#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice"
541#define NID_id_smime_spq_ets_sqt_unotice 250
542#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L
543
544#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin"
545#define NID_id_smime_cti_ets_proofOfOrigin 251
546#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L
547
548#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt"
549#define NID_id_smime_cti_ets_proofOfReceipt 252
550#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L
551
552#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery"
553#define NID_id_smime_cti_ets_proofOfDelivery 253
554#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L
555
556#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender"
557#define NID_id_smime_cti_ets_proofOfSender 254
558#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L
559
560#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval"
561#define NID_id_smime_cti_ets_proofOfApproval 255
562#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L
563
564#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation"
565#define NID_id_smime_cti_ets_proofOfCreation 256
566#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L
567
568#define LN_friendlyName "friendlyName"
569#define NID_friendlyName 156
570#define OBJ_friendlyName OBJ_pkcs9,20L
571
572#define LN_localKeyID "localKeyID"
573#define NID_localKeyID 157
574#define OBJ_localKeyID OBJ_pkcs9,21L
575
576#define OBJ_certTypes OBJ_pkcs9,22L
577
578#define LN_x509Certificate "x509Certificate"
579#define NID_x509Certificate 158
580#define OBJ_x509Certificate OBJ_certTypes,1L
581
582#define LN_sdsiCertificate "sdsiCertificate"
583#define NID_sdsiCertificate 159
584#define OBJ_sdsiCertificate OBJ_certTypes,2L
585
586#define OBJ_crlTypes OBJ_pkcs9,23L
587
588#define LN_x509Crl "x509Crl"
589#define NID_x509Crl 160
590#define OBJ_x509Crl OBJ_crlTypes,1L
591
592#define OBJ_pkcs12 OBJ_pkcs,12L
593
594#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L
595
596#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
597#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
598#define NID_pbe_WithSHA1And128BitRC4 144
599#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L
600
601#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
602#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
603#define NID_pbe_WithSHA1And40BitRC4 145
604#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L
605
606#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
607#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
608#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
609#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L
610
611#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
612#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
613#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
614#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L
615
616#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
617#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
618#define NID_pbe_WithSHA1And128BitRC2_CBC 148
619#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L
620
621#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
622#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
623#define NID_pbe_WithSHA1And40BitRC2_CBC 149
624#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L
625
626#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L
627
628#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L
629
630#define LN_keyBag "keyBag"
631#define NID_keyBag 150
632#define OBJ_keyBag OBJ_pkcs12_BagIds,1L
633
634#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
635#define NID_pkcs8ShroudedKeyBag 151
636#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L
637
638#define LN_certBag "certBag"
639#define NID_certBag 152
640#define OBJ_certBag OBJ_pkcs12_BagIds,3L
641
642#define LN_crlBag "crlBag"
643#define NID_crlBag 153
644#define OBJ_crlBag OBJ_pkcs12_BagIds,4L
645
646#define LN_secretBag "secretBag"
647#define NID_secretBag 154
648#define OBJ_secretBag OBJ_pkcs12_BagIds,5L
649
650#define LN_safeContentsBag "safeContentsBag"
651#define NID_safeContentsBag 155
652#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L
653
654#define SN_md2 "MD2"
655#define LN_md2 "md2"
656#define NID_md2 3
657#define OBJ_md2 OBJ_rsadsi,2L,2L
658
659#define SN_md4 "MD4"
660#define LN_md4 "md4"
661#define NID_md4 257
662#define OBJ_md4 OBJ_rsadsi,2L,4L
663
664#define SN_md5 "MD5"
665#define LN_md5 "md5"
666#define NID_md5 4
667#define OBJ_md5 OBJ_rsadsi,2L,5L
668
669#define SN_md5_sha1 "MD5-SHA1"
670#define LN_md5_sha1 "md5-sha1"
671#define NID_md5_sha1 114
672
673#define LN_hmacWithSHA1 "hmacWithSHA1"
674#define NID_hmacWithSHA1 163
675#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
676
677#define SN_rc2_cbc "RC2-CBC"
678#define LN_rc2_cbc "rc2-cbc"
679#define NID_rc2_cbc 37
680#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
681
682#define SN_rc2_ecb "RC2-ECB"
683#define LN_rc2_ecb "rc2-ecb"
684#define NID_rc2_ecb 38
685
686#define SN_rc2_cfb64 "RC2-CFB"
687#define LN_rc2_cfb64 "rc2-cfb"
688#define NID_rc2_cfb64 39
689
690#define SN_rc2_ofb64 "RC2-OFB"
691#define LN_rc2_ofb64 "rc2-ofb"
692#define NID_rc2_ofb64 40
693
694#define SN_rc2_40_cbc "RC2-40-CBC"
695#define LN_rc2_40_cbc "rc2-40-cbc"
696#define NID_rc2_40_cbc 98
697
698#define SN_rc2_64_cbc "RC2-64-CBC"
699#define LN_rc2_64_cbc "rc2-64-cbc"
700#define NID_rc2_64_cbc 166
701
702#define SN_rc4 "RC4"
703#define LN_rc4 "rc4"
704#define NID_rc4 5
705#define OBJ_rc4 OBJ_rsadsi,3L,4L
706
707#define SN_rc4_40 "RC4-40"
708#define LN_rc4_40 "rc4-40"
709#define NID_rc4_40 97
710
711#define SN_des_ede3_cbc "DES-EDE3-CBC"
712#define LN_des_ede3_cbc "des-ede3-cbc"
713#define NID_des_ede3_cbc 44
714#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
715
716#define SN_rc5_cbc "RC5-CBC"
717#define LN_rc5_cbc "rc5-cbc"
718#define NID_rc5_cbc 120
719#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
720
721#define SN_rc5_ecb "RC5-ECB"
722#define LN_rc5_ecb "rc5-ecb"
723#define NID_rc5_ecb 121
724
725#define SN_rc5_cfb64 "RC5-CFB"
726#define LN_rc5_cfb64 "rc5-cfb"
727#define NID_rc5_cfb64 122
728
729#define SN_rc5_ofb64 "RC5-OFB"
730#define LN_rc5_ofb64 "rc5-ofb"
731#define NID_rc5_ofb64 123
732
733#define SN_ms_ext_req "msExtReq"
734#define LN_ms_ext_req "Microsoft Extension Request"
735#define NID_ms_ext_req 171
736#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
737
738#define SN_ms_code_ind "msCodeInd"
739#define LN_ms_code_ind "Microsoft Individual Code Signing"
740#define NID_ms_code_ind 134
741#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
742
743#define SN_ms_code_com "msCodeCom"
744#define LN_ms_code_com "Microsoft Commercial Code Signing"
745#define NID_ms_code_com 135
746#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
747
748#define SN_ms_ctl_sign "msCTLSign"
749#define LN_ms_ctl_sign "Microsoft Trust List Signing"
750#define NID_ms_ctl_sign 136
751#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
752
753#define SN_ms_sgc "msSGC"
754#define LN_ms_sgc "Microsoft Server Gated Crypto"
755#define NID_ms_sgc 137
756#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
757
758#define SN_ms_efs "msEFS"
759#define LN_ms_efs "Microsoft Encrypted File System"
760#define NID_ms_efs 138
761#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
762
763#define SN_idea_cbc "IDEA-CBC"
764#define LN_idea_cbc "idea-cbc"
765#define NID_idea_cbc 34
766#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
767
768#define SN_idea_ecb "IDEA-ECB"
769#define LN_idea_ecb "idea-ecb"
770#define NID_idea_ecb 36
771
772#define SN_idea_cfb64 "IDEA-CFB"
773#define LN_idea_cfb64 "idea-cfb"
774#define NID_idea_cfb64 35
775
776#define SN_idea_ofb64 "IDEA-OFB"
777#define LN_idea_ofb64 "idea-ofb"
778#define NID_idea_ofb64 46
779
780#define SN_bf_cbc "BF-CBC"
781#define LN_bf_cbc "bf-cbc"
782#define NID_bf_cbc 91
783#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
784
785#define SN_bf_ecb "BF-ECB"
786#define LN_bf_ecb "bf-ecb"
787#define NID_bf_ecb 92
788
789#define SN_bf_cfb64 "BF-CFB"
790#define LN_bf_cfb64 "bf-cfb"
791#define NID_bf_cfb64 93
792
793#define SN_bf_ofb64 "BF-OFB"
794#define LN_bf_ofb64 "bf-ofb"
795#define NID_bf_ofb64 94
796
797#define SN_id_pkix "PKIX"
798#define NID_id_pkix 127
799#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
800
801#define SN_id_pkix_mod "id-pkix-mod"
802#define NID_id_pkix_mod 258
803#define OBJ_id_pkix_mod OBJ_id_pkix,0L
804
805#define SN_id_pe "id-pe"
806#define NID_id_pe 175
807#define OBJ_id_pe OBJ_id_pkix,1L
808
809#define SN_id_qt "id-qt"
810#define NID_id_qt 259
811#define OBJ_id_qt OBJ_id_pkix,2L
812
813#define SN_id_kp "id-kp"
814#define NID_id_kp 128
815#define OBJ_id_kp OBJ_id_pkix,3L
816
817#define SN_id_it "id-it"
818#define NID_id_it 260
819#define OBJ_id_it OBJ_id_pkix,4L
820
821#define SN_id_pkip "id-pkip"
822#define NID_id_pkip 261
823#define OBJ_id_pkip OBJ_id_pkix,5L
824
825#define SN_id_alg "id-alg"
826#define NID_id_alg 262
827#define OBJ_id_alg OBJ_id_pkix,6L
828
829#define SN_id_cmc "id-cmc"
830#define NID_id_cmc 263
831#define OBJ_id_cmc OBJ_id_pkix,7L
832
833#define SN_id_on "id-on"
834#define NID_id_on 264
835#define OBJ_id_on OBJ_id_pkix,8L
836
837#define SN_id_pda "id-pda"
838#define NID_id_pda 265
839#define OBJ_id_pda OBJ_id_pkix,9L
840
841#define SN_id_aca "id-aca"
842#define NID_id_aca 266
843#define OBJ_id_aca OBJ_id_pkix,10L
844
845#define SN_id_qcs "id-qcs"
846#define NID_id_qcs 267
847#define OBJ_id_qcs OBJ_id_pkix,11L
848
849#define SN_id_cct "id-cct"
850#define NID_id_cct 268
851#define OBJ_id_cct OBJ_id_pkix,12L
852
853#define SN_id_ad "id-ad"
854#define NID_id_ad 176
855#define OBJ_id_ad OBJ_id_pkix,48L
856
857#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88"
858#define NID_id_pkix1_explicit_88 269
859#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L
860
861#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88"
862#define NID_id_pkix1_implicit_88 270
863#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L
864
865#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93"
866#define NID_id_pkix1_explicit_93 271
867#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L
868
869#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93"
870#define NID_id_pkix1_implicit_93 272
871#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L
872
873#define SN_id_mod_crmf "id-mod-crmf"
874#define NID_id_mod_crmf 273
875#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L
876
877#define SN_id_mod_cmc "id-mod-cmc"
878#define NID_id_mod_cmc 274
879#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L
880
881#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88"
882#define NID_id_mod_kea_profile_88 275
883#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L
884
885#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93"
886#define NID_id_mod_kea_profile_93 276
887#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L
888
889#define SN_id_mod_cmp "id-mod-cmp"
890#define NID_id_mod_cmp 277
891#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L
892
893#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88"
894#define NID_id_mod_qualified_cert_88 278
895#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L
896
897#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93"
898#define NID_id_mod_qualified_cert_93 279
899#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L
900
901#define SN_id_mod_attribute_cert "id-mod-attribute-cert"
902#define NID_id_mod_attribute_cert 280
903#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L
904
905#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol"
906#define NID_id_mod_timestamp_protocol 281
907#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L
908
909#define SN_id_mod_ocsp "id-mod-ocsp"
910#define NID_id_mod_ocsp 282
911#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L
912
913#define SN_id_mod_dvcs "id-mod-dvcs"
914#define NID_id_mod_dvcs 283
915#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L
916
917#define SN_id_mod_cmp2000 "id-mod-cmp2000"
918#define NID_id_mod_cmp2000 284
919#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L
920
921#define SN_info_access "authorityInfoAccess"
922#define LN_info_access "Authority Information Access"
923#define NID_info_access 177
924#define OBJ_info_access OBJ_id_pe,1L
925
926#define SN_biometricInfo "biometricInfo"
927#define LN_biometricInfo "Biometric Info"
928#define NID_biometricInfo 285
929#define OBJ_biometricInfo OBJ_id_pe,2L
930
931#define SN_qcStatements "qcStatements"
932#define NID_qcStatements 286
933#define OBJ_qcStatements OBJ_id_pe,3L
934
935#define SN_ac_auditEntity "ac-auditEntity"
936#define NID_ac_auditEntity 287
937#define OBJ_ac_auditEntity OBJ_id_pe,4L
938
939#define SN_ac_targeting "ac-targeting"
940#define NID_ac_targeting 288
941#define OBJ_ac_targeting OBJ_id_pe,5L
942
943#define SN_aaControls "aaControls"
944#define NID_aaControls 289
945#define OBJ_aaControls OBJ_id_pe,6L
946
947#define SN_sbqp_ipAddrBlock "sbqp-ipAddrBlock"
948#define NID_sbqp_ipAddrBlock 290
949#define OBJ_sbqp_ipAddrBlock OBJ_id_pe,7L
950
951#define SN_sbqp_autonomousSysNum "sbqp-autonomousSysNum"
952#define NID_sbqp_autonomousSysNum 291
953#define OBJ_sbqp_autonomousSysNum OBJ_id_pe,8L
954
955#define SN_sbqp_routerIdentifier "sbqp-routerIdentifier"
956#define NID_sbqp_routerIdentifier 292
957#define OBJ_sbqp_routerIdentifier OBJ_id_pe,9L
958
959#define SN_id_qt_cps "id-qt-cps"
960#define LN_id_qt_cps "Policy Qualifier CPS"
961#define NID_id_qt_cps 164
962#define OBJ_id_qt_cps OBJ_id_qt,1L
963
964#define SN_id_qt_unotice "id-qt-unotice"
965#define LN_id_qt_unotice "Policy Qualifier User Notice"
966#define NID_id_qt_unotice 165
967#define OBJ_id_qt_unotice OBJ_id_qt,2L
968
969#define SN_textNotice "textNotice"
970#define NID_textNotice 293
971#define OBJ_textNotice OBJ_id_qt,3L
972
973#define SN_server_auth "serverAuth"
974#define LN_server_auth "TLS Web Server Authentication"
975#define NID_server_auth 129
976#define OBJ_server_auth OBJ_id_kp,1L
977
978#define SN_client_auth "clientAuth"
979#define LN_client_auth "TLS Web Client Authentication"
980#define NID_client_auth 130
981#define OBJ_client_auth OBJ_id_kp,2L
982
983#define SN_code_sign "codeSigning"
984#define LN_code_sign "Code Signing"
985#define NID_code_sign 131
986#define OBJ_code_sign OBJ_id_kp,3L
987
988#define SN_email_protect "emailProtection"
989#define LN_email_protect "E-mail Protection"
990#define NID_email_protect 132
991#define OBJ_email_protect OBJ_id_kp,4L
992
993#define SN_ipsecEndSystem "ipsecEndSystem"
994#define LN_ipsecEndSystem "IPSec End System"
995#define NID_ipsecEndSystem 294
996#define OBJ_ipsecEndSystem OBJ_id_kp,5L
997
998#define SN_ipsecTunnel "ipsecTunnel"
999#define LN_ipsecTunnel "IPSec Tunnel"
1000#define NID_ipsecTunnel 295
1001#define OBJ_ipsecTunnel OBJ_id_kp,6L
1002
1003#define SN_ipsecUser "ipsecUser"
1004#define LN_ipsecUser "IPSec User"
1005#define NID_ipsecUser 296
1006#define OBJ_ipsecUser OBJ_id_kp,7L
1007
1008#define SN_time_stamp "timeStamping"
1009#define LN_time_stamp "Time Stamping"
1010#define NID_time_stamp 133
1011#define OBJ_time_stamp OBJ_id_kp,8L
1012
1013#define SN_OCSP_sign "OCSPSigning"
1014#define LN_OCSP_sign "OCSP Signing"
1015#define NID_OCSP_sign 180
1016#define OBJ_OCSP_sign OBJ_id_kp,9L
1017
1018#define SN_dvcs "DVCS"
1019#define LN_dvcs "dvcs"
1020#define NID_dvcs 297
1021#define OBJ_dvcs OBJ_id_kp,10L
1022
1023#define SN_id_it_caProtEncCert "id-it-caProtEncCert"
1024#define NID_id_it_caProtEncCert 298
1025#define OBJ_id_it_caProtEncCert OBJ_id_it,1L
1026
1027#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes"
1028#define NID_id_it_signKeyPairTypes 299
1029#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L
1030
1031#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes"
1032#define NID_id_it_encKeyPairTypes 300
1033#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L
1034
1035#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg"
1036#define NID_id_it_preferredSymmAlg 301
1037#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L
1038
1039#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo"
1040#define NID_id_it_caKeyUpdateInfo 302
1041#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L
1042
1043#define SN_id_it_currentCRL "id-it-currentCRL"
1044#define NID_id_it_currentCRL 303
1045#define OBJ_id_it_currentCRL OBJ_id_it,6L
1046
1047#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs"
1048#define NID_id_it_unsupportedOIDs 304
1049#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L
1050
1051#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest"
1052#define NID_id_it_subscriptionRequest 305
1053#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L
1054
1055#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse"
1056#define NID_id_it_subscriptionResponse 306
1057#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L
1058
1059#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq"
1060#define NID_id_it_keyPairParamReq 307
1061#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L
1062
1063#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep"
1064#define NID_id_it_keyPairParamRep 308
1065#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L
1066
1067#define SN_id_it_revPassphrase "id-it-revPassphrase"
1068#define NID_id_it_revPassphrase 309
1069#define OBJ_id_it_revPassphrase OBJ_id_it,12L
1070
1071#define SN_id_it_implicitConfirm "id-it-implicitConfirm"
1072#define NID_id_it_implicitConfirm 310
1073#define OBJ_id_it_implicitConfirm OBJ_id_it,13L
1074
1075#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime"
1076#define NID_id_it_confirmWaitTime 311
1077#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L
1078
1079#define SN_id_it_origPKIMessage "id-it-origPKIMessage"
1080#define NID_id_it_origPKIMessage 312
1081#define OBJ_id_it_origPKIMessage OBJ_id_it,15L
1082
1083#define SN_id_regCtrl "id-regCtrl"
1084#define NID_id_regCtrl 313
1085#define OBJ_id_regCtrl OBJ_id_pkip,1L
1086
1087#define SN_id_regInfo "id-regInfo"
1088#define NID_id_regInfo 314
1089#define OBJ_id_regInfo OBJ_id_pkip,2L
1090
1091#define SN_id_regCtrl_regToken "id-regCtrl-regToken"
1092#define NID_id_regCtrl_regToken 315
1093#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L
1094
1095#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator"
1096#define NID_id_regCtrl_authenticator 316
1097#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L
1098
1099#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo"
1100#define NID_id_regCtrl_pkiPublicationInfo 317
1101#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L
1102
1103#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions"
1104#define NID_id_regCtrl_pkiArchiveOptions 318
1105#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L
1106
1107#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID"
1108#define NID_id_regCtrl_oldCertID 319
1109#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L
1110
1111#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey"
1112#define NID_id_regCtrl_protocolEncrKey 320
1113#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L
1114
1115#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs"
1116#define NID_id_regInfo_utf8Pairs 321
1117#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L
1118
1119#define SN_id_regInfo_certReq "id-regInfo-certReq"
1120#define NID_id_regInfo_certReq 322
1121#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L
1122
1123#define SN_id_alg_des40 "id-alg-des40"
1124#define NID_id_alg_des40 323
1125#define OBJ_id_alg_des40 OBJ_id_alg,1L
1126
1127#define SN_id_alg_noSignature "id-alg-noSignature"
1128#define NID_id_alg_noSignature 324
1129#define OBJ_id_alg_noSignature OBJ_id_alg,2L
1130
1131#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1"
1132#define NID_id_alg_dh_sig_hmac_sha1 325
1133#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L
1134
1135#define SN_id_alg_dh_pop "id-alg-dh-pop"
1136#define NID_id_alg_dh_pop 326
1137#define OBJ_id_alg_dh_pop OBJ_id_alg,4L
1138
1139#define SN_id_cmc_statusInfo "id-cmc-statusInfo"
1140#define NID_id_cmc_statusInfo 327
1141#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L
1142
1143#define SN_id_cmc_identification "id-cmc-identification"
1144#define NID_id_cmc_identification 328
1145#define OBJ_id_cmc_identification OBJ_id_cmc,2L
1146
1147#define SN_id_cmc_identityProof "id-cmc-identityProof"
1148#define NID_id_cmc_identityProof 329
1149#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L
1150
1151#define SN_id_cmc_dataReturn "id-cmc-dataReturn"
1152#define NID_id_cmc_dataReturn 330
1153#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L
1154
1155#define SN_id_cmc_transactionId "id-cmc-transactionId"
1156#define NID_id_cmc_transactionId 331
1157#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L
1158
1159#define SN_id_cmc_senderNonce "id-cmc-senderNonce"
1160#define NID_id_cmc_senderNonce 332
1161#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L
1162
1163#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce"
1164#define NID_id_cmc_recipientNonce 333
1165#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L
1166
1167#define SN_id_cmc_addExtensions "id-cmc-addExtensions"
1168#define NID_id_cmc_addExtensions 334
1169#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L
1170
1171#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP"
1172#define NID_id_cmc_encryptedPOP 335
1173#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L
1174
1175#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP"
1176#define NID_id_cmc_decryptedPOP 336
1177#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L
1178
1179#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness"
1180#define NID_id_cmc_lraPOPWitness 337
1181#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L
1182
1183#define SN_id_cmc_getCert "id-cmc-getCert"
1184#define NID_id_cmc_getCert 338
1185#define OBJ_id_cmc_getCert OBJ_id_cmc,15L
1186
1187#define SN_id_cmc_getCRL "id-cmc-getCRL"
1188#define NID_id_cmc_getCRL 339
1189#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L
1190
1191#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest"
1192#define NID_id_cmc_revokeRequest 340
1193#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L
1194
1195#define SN_id_cmc_regInfo "id-cmc-regInfo"
1196#define NID_id_cmc_regInfo 341
1197#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L
1198
1199#define SN_id_cmc_responseInfo "id-cmc-responseInfo"
1200#define NID_id_cmc_responseInfo 342
1201#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L
1202
1203#define SN_id_cmc_queryPending "id-cmc-queryPending"
1204#define NID_id_cmc_queryPending 343
1205#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L
1206
1207#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom"
1208#define NID_id_cmc_popLinkRandom 344
1209#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L
1210
1211#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness"
1212#define NID_id_cmc_popLinkWitness 345
1213#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L
1214
1215#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance"
1216#define NID_id_cmc_confirmCertAcceptance 346
1217#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L
1218
1219#define SN_id_on_personalData "id-on-personalData"
1220#define NID_id_on_personalData 347
1221#define OBJ_id_on_personalData OBJ_id_on,1L
1222
1223#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth"
1224#define NID_id_pda_dateOfBirth 348
1225#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L
1226
1227#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth"
1228#define NID_id_pda_placeOfBirth 349
1229#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L
1230
1231#define SN_id_pda_pseudonym "id-pda-pseudonym"
1232#define NID_id_pda_pseudonym 350
1233#define OBJ_id_pda_pseudonym OBJ_id_pda,3L
1234
1235#define SN_id_pda_gender "id-pda-gender"
1236#define NID_id_pda_gender 351
1237#define OBJ_id_pda_gender OBJ_id_pda,4L
1238
1239#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship"
1240#define NID_id_pda_countryOfCitizenship 352
1241#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,5L
1242
1243#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence"
1244#define NID_id_pda_countryOfResidence 353
1245#define OBJ_id_pda_countryOfResidence OBJ_id_pda,6L
1246
1247#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo"
1248#define NID_id_aca_authenticationInfo 354
1249#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L
1250
1251#define SN_id_aca_accessIdentity "id-aca-accessIdentity"
1252#define NID_id_aca_accessIdentity 355
1253#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L
1254
1255#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity"
1256#define NID_id_aca_chargingIdentity 356
1257#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L
1258
1259#define SN_id_aca_group "id-aca-group"
1260#define NID_id_aca_group 357
1261#define OBJ_id_aca_group OBJ_id_aca,4L
1262
1263#define SN_id_aca_role "id-aca-role"
1264#define NID_id_aca_role 358
1265#define OBJ_id_aca_role OBJ_id_aca,5L
1266
1267#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1"
1268#define NID_id_qcs_pkixQCSyntax_v1 359
1269#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L
1270
1271#define SN_id_cct_crs "id-cct-crs"
1272#define NID_id_cct_crs 360
1273#define OBJ_id_cct_crs OBJ_id_cct,1L
1274
1275#define SN_id_cct_PKIData "id-cct-PKIData"
1276#define NID_id_cct_PKIData 361
1277#define OBJ_id_cct_PKIData OBJ_id_cct,2L
1278
1279#define SN_id_cct_PKIResponse "id-cct-PKIResponse"
1280#define NID_id_cct_PKIResponse 362
1281#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L
1282
1283#define SN_ad_OCSP "OCSP"
1284#define LN_ad_OCSP "OCSP"
1285#define NID_ad_OCSP 178
1286#define OBJ_ad_OCSP OBJ_id_ad,1L
1287
1288#define SN_ad_ca_issuers "caIssuers"
1289#define LN_ad_ca_issuers "CA Issuers"
1290#define NID_ad_ca_issuers 179
1291#define OBJ_ad_ca_issuers OBJ_id_ad,2L
1292
1293#define SN_ad_timeStamping "ad_timestamping"
1294#define LN_ad_timeStamping "AD Time Stamping"
1295#define NID_ad_timeStamping 363
1296#define OBJ_ad_timeStamping OBJ_id_ad,3L
1297
1298#define SN_ad_dvcs "AD_DVCS"
1299#define LN_ad_dvcs "ad dvcs"
1300#define NID_ad_dvcs 364
1301#define OBJ_ad_dvcs OBJ_id_ad,4L
1302
1303#define OBJ_id_pkix_OCSP OBJ_ad_OCSP
1304
1305#define SN_id_pkix_OCSP_basic "basicOCSPResponse"
1306#define LN_id_pkix_OCSP_basic "Basic OCSP Response"
1307#define NID_id_pkix_OCSP_basic 365
1308#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L
1309
1310#define SN_id_pkix_OCSP_Nonce "Nonce"
1311#define LN_id_pkix_OCSP_Nonce "OCSP Nonce"
1312#define NID_id_pkix_OCSP_Nonce 366
1313#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L
1314
1315#define SN_id_pkix_OCSP_CrlID "CrlID"
1316#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID"
1317#define NID_id_pkix_OCSP_CrlID 367
1318#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L
1319
1320#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses"
1321#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses"
1322#define NID_id_pkix_OCSP_acceptableResponses 368
1323#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L
1324
1325#define SN_id_pkix_OCSP_noCheck "noCheck"
1326#define NID_id_pkix_OCSP_noCheck 369
1327#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L
1328
1329#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff"
1330#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff"
1331#define NID_id_pkix_OCSP_archiveCutoff 370
1332#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L
1333
1334#define SN_id_pkix_OCSP_serviceLocator "serviceLocator"
1335#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator"
1336#define NID_id_pkix_OCSP_serviceLocator 371
1337#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L
1338
1339#define SN_id_pkix_OCSP_extendedStatus "extendedStatus"
1340#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status"
1341#define NID_id_pkix_OCSP_extendedStatus 372
1342#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L
1343
1344#define SN_id_pkix_OCSP_valid "valid"
1345#define NID_id_pkix_OCSP_valid 373
1346#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L
1347
1348#define SN_id_pkix_OCSP_path "path"
1349#define NID_id_pkix_OCSP_path 374
1350#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L
1351
1352#define SN_id_pkix_OCSP_trustRoot "trustRoot"
1353#define LN_id_pkix_OCSP_trustRoot "Trust Root"
1354#define NID_id_pkix_OCSP_trustRoot 375
1355#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L
1356
1357#define SN_algorithm "algorithm"
1358#define LN_algorithm "algorithm"
1359#define NID_algorithm 376
1360#define OBJ_algorithm 1L,3L,14L,3L,2L
1361
1362#define SN_md5WithRSA "RSA-NP-MD5"
1363#define LN_md5WithRSA "md5WithRSA"
1364#define NID_md5WithRSA 104
1365#define OBJ_md5WithRSA OBJ_algorithm,3L
1366
1367#define SN_des_ecb "DES-ECB"
1368#define LN_des_ecb "des-ecb"
1369#define NID_des_ecb 29
1370#define OBJ_des_ecb OBJ_algorithm,6L
1371
1372#define SN_des_cbc "DES-CBC"
1373#define LN_des_cbc "des-cbc"
1374#define NID_des_cbc 31
1375#define OBJ_des_cbc OBJ_algorithm,7L
1376
1377#define SN_des_ofb64 "DES-OFB"
1378#define LN_des_ofb64 "des-ofb"
1379#define NID_des_ofb64 45
1380#define OBJ_des_ofb64 OBJ_algorithm,8L
1381
1382#define SN_des_cfb64 "DES-CFB"
1383#define LN_des_cfb64 "des-cfb"
1384#define NID_des_cfb64 30
1385#define OBJ_des_cfb64 OBJ_algorithm,9L
1386
1387#define SN_rsaSignature "rsaSignature"
1388#define NID_rsaSignature 377
1389#define OBJ_rsaSignature OBJ_algorithm,11L
1390
1391#define SN_dsa_2 "DSA-old"
1392#define LN_dsa_2 "dsaEncryption-old"
1393#define NID_dsa_2 67
1394#define OBJ_dsa_2 OBJ_algorithm,12L
1395
1396#define SN_dsaWithSHA "DSA-SHA"
1397#define LN_dsaWithSHA "dsaWithSHA"
1398#define NID_dsaWithSHA 66
1399#define OBJ_dsaWithSHA OBJ_algorithm,13L
1400
1401#define SN_shaWithRSAEncryption "RSA-SHA"
1402#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
1403#define NID_shaWithRSAEncryption 42
1404#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
1405
1406#define SN_des_ede "DES-EDE"
1407#define LN_des_ede "des-ede"
1408#define NID_des_ede 32
1409#define OBJ_des_ede OBJ_algorithm,17L
1410
1411#define SN_des_ede3 "DES-EDE3"
1412#define LN_des_ede3 "des-ede3"
1413#define NID_des_ede3 33
1414
1415#define SN_des_ede_cbc "DES-EDE-CBC"
1416#define LN_des_ede_cbc "des-ede-cbc"
1417#define NID_des_ede_cbc 43
1418
1419#define SN_des_ede_cfb64 "DES-EDE-CFB"
1420#define LN_des_ede_cfb64 "des-ede-cfb"
1421#define NID_des_ede_cfb64 60
1422
1423#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
1424#define LN_des_ede3_cfb64 "des-ede3-cfb"
1425#define NID_des_ede3_cfb64 61
1426
1427#define SN_des_ede_ofb64 "DES-EDE-OFB"
1428#define LN_des_ede_ofb64 "des-ede-ofb"
1429#define NID_des_ede_ofb64 62
1430
1431#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
1432#define LN_des_ede3_ofb64 "des-ede3-ofb"
1433#define NID_des_ede3_ofb64 63
1434
1435#define SN_desx_cbc "DESX-CBC"
1436#define LN_desx_cbc "desx-cbc"
1437#define NID_desx_cbc 80
1438
1439#define SN_sha "SHA"
1440#define LN_sha "sha"
1441#define NID_sha 41
1442#define OBJ_sha OBJ_algorithm,18L
1443
1444#define SN_sha1 "SHA1"
1445#define LN_sha1 "sha1"
1446#define NID_sha1 64
1447#define OBJ_sha1 OBJ_algorithm,26L
1448
1449#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
1450#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
1451#define NID_dsaWithSHA1_2 70
1452#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
1453
1454#define SN_sha1WithRSA "RSA-SHA1-2"
1455#define LN_sha1WithRSA "sha1WithRSA"
1456#define NID_sha1WithRSA 115
1457#define OBJ_sha1WithRSA OBJ_algorithm,29L
1458
1459#define SN_ripemd160 "RIPEMD160"
1460#define LN_ripemd160 "ripemd160"
1461#define NID_ripemd160 117
1462#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
1463
1464#define SN_ripemd160WithRSA "RSA-RIPEMD160"
1465#define LN_ripemd160WithRSA "ripemd160WithRSA"
1466#define NID_ripemd160WithRSA 119
1467#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
1468
1469#define SN_sxnet "SXNetID"
1470#define LN_sxnet "Strong Extranet ID"
1471#define NID_sxnet 143
1472#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
1473
1474#define SN_X500 "X500"
1475#define LN_X500 "directory services (X.500)"
1476#define NID_X500 11
1477#define OBJ_X500 2L,5L
1478
1479#define SN_X509 "X509"
1480#define NID_X509 12
1481#define OBJ_X509 OBJ_X500,4L
1482
1483#define SN_commonName "CN"
1484#define LN_commonName "commonName"
1485#define NID_commonName 13
1486#define OBJ_commonName OBJ_X509,3L
1487
1488#define SN_surname "S"
1489#define LN_surname "surname"
1490#define NID_surname 100
1491#define OBJ_surname OBJ_X509,4L
1492
1493#define SN_serialNumber "SN"
1494#define LN_serialNumber "serialNumber"
1495#define NID_serialNumber 105
1496#define OBJ_serialNumber OBJ_X509,5L
1497
1498#define SN_countryName "C"
1499#define LN_countryName "countryName"
1500#define NID_countryName 14
1501#define OBJ_countryName OBJ_X509,6L
1502
1503#define SN_localityName "L"
1504#define LN_localityName "localityName"
1505#define NID_localityName 15
1506#define OBJ_localityName OBJ_X509,7L
1507
1508#define SN_stateOrProvinceName "ST"
1509#define LN_stateOrProvinceName "stateOrProvinceName"
1510#define NID_stateOrProvinceName 16
1511#define OBJ_stateOrProvinceName OBJ_X509,8L
1512
1513#define SN_organizationName "O"
1514#define LN_organizationName "organizationName"
1515#define NID_organizationName 17
1516#define OBJ_organizationName OBJ_X509,10L
1517
1518#define SN_organizationalUnitName "OU"
1519#define LN_organizationalUnitName "organizationalUnitName"
1520#define NID_organizationalUnitName 18
1521#define OBJ_organizationalUnitName OBJ_X509,11L
1522
1523#define SN_title "T"
1524#define LN_title "title"
1525#define NID_title 106
1526#define OBJ_title OBJ_X509,12L
1527
1528#define SN_description "D"
1529#define LN_description "description"
1530#define NID_description 107
1531#define OBJ_description OBJ_X509,13L
1532
1533#define SN_name "name"
1534#define LN_name "name"
1535#define NID_name 173
1536#define OBJ_name OBJ_X509,41L
1537
1538#define SN_givenName "G"
1539#define LN_givenName "givenName"
1540#define NID_givenName 99
1541#define OBJ_givenName OBJ_X509,42L
1542
1543#define SN_initials "I"
1544#define LN_initials "initials"
1545#define NID_initials 101
1546#define OBJ_initials OBJ_X509,43L
1547
1548#define SN_uniqueIdentifier "UID"
1549#define LN_uniqueIdentifier "uniqueIdentifier"
1550#define NID_uniqueIdentifier 102
1551#define OBJ_uniqueIdentifier OBJ_X509,45L
1552
1553#define SN_dnQualifier "dnQualifier"
1554#define LN_dnQualifier "dnQualifier"
1555#define NID_dnQualifier 174
1556#define OBJ_dnQualifier OBJ_X509,46L
1557
1558#define SN_X500algorithms "X500algorithms"
1559#define LN_X500algorithms "directory services - algorithms"
1560#define NID_X500algorithms 378
1561#define OBJ_X500algorithms OBJ_X500,8L
1562
1563#define SN_rsa "RSA"
1564#define LN_rsa "rsa"
1565#define NID_rsa 19
1566#define OBJ_rsa OBJ_X500algorithms,1L,1L
1567
1568#define SN_mdc2WithRSA "RSA-MDC2"
1569#define LN_mdc2WithRSA "mdc2WithRSA"
1570#define NID_mdc2WithRSA 96
1571#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L
1572
1573#define SN_mdc2 "MDC2"
1574#define LN_mdc2 "mdc2"
1575#define NID_mdc2 95
1576#define OBJ_mdc2 OBJ_X500algorithms,3L,101L
1577
1578#define SN_id_ce "id-ce"
1579#define NID_id_ce 81
1580#define OBJ_id_ce OBJ_X500,29L
1581
1582#define SN_subject_key_identifier "subjectKeyIdentifier"
1583#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
1584#define NID_subject_key_identifier 82
1585#define OBJ_subject_key_identifier OBJ_id_ce,14L
1586
1587#define SN_key_usage "keyUsage"
1588#define LN_key_usage "X509v3 Key Usage"
1589#define NID_key_usage 83
1590#define OBJ_key_usage OBJ_id_ce,15L
1591
1592#define SN_private_key_usage_period "privateKeyUsagePeriod"
1593#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
1594#define NID_private_key_usage_period 84
1595#define OBJ_private_key_usage_period OBJ_id_ce,16L
1596
1597#define SN_subject_alt_name "subjectAltName"
1598#define LN_subject_alt_name "X509v3 Subject Alternative Name"
1599#define NID_subject_alt_name 85
1600#define OBJ_subject_alt_name OBJ_id_ce,17L
1601
1602#define SN_issuer_alt_name "issuerAltName"
1603#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
1604#define NID_issuer_alt_name 86
1605#define OBJ_issuer_alt_name OBJ_id_ce,18L
1606
1607#define SN_basic_constraints "basicConstraints"
1608#define LN_basic_constraints "X509v3 Basic Constraints"
1609#define NID_basic_constraints 87
1610#define OBJ_basic_constraints OBJ_id_ce,19L
1611
1612#define SN_crl_number "crlNumber"
1613#define LN_crl_number "X509v3 CRL Number"
1614#define NID_crl_number 88
1615#define OBJ_crl_number OBJ_id_ce,20L
1616
1617#define SN_crl_reason "CRLReason"
1618#define LN_crl_reason "X509v3 CRL Reason Code"
1619#define NID_crl_reason 141
1620#define OBJ_crl_reason OBJ_id_ce,21L
1621
1622#define SN_invalidity_date "invalidityDate"
1623#define LN_invalidity_date "Invalidity Date"
1624#define NID_invalidity_date 142
1625#define OBJ_invalidity_date OBJ_id_ce,24L
1626
1627#define SN_delta_crl "deltaCRL"
1628#define LN_delta_crl "X509v3 Delta CRL Indicator"
1629#define NID_delta_crl 140
1630#define OBJ_delta_crl OBJ_id_ce,27L
1631
1632#define SN_crl_distribution_points "crlDistributionPoints"
1633#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
1634#define NID_crl_distribution_points 103
1635#define OBJ_crl_distribution_points OBJ_id_ce,31L
1636
1637#define SN_certificate_policies "certificatePolicies"
1638#define LN_certificate_policies "X509v3 Certificate Policies"
1639#define NID_certificate_policies 89
1640#define OBJ_certificate_policies OBJ_id_ce,32L
1641
1642#define SN_authority_key_identifier "authorityKeyIdentifier"
1643#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
1644#define NID_authority_key_identifier 90
1645#define OBJ_authority_key_identifier OBJ_id_ce,35L
1646
1647#define SN_ext_key_usage "extendedKeyUsage"
1648#define LN_ext_key_usage "X509v3 Extended Key Usage"
1649#define NID_ext_key_usage 126
1650#define OBJ_ext_key_usage OBJ_id_ce,37L
1651
1652#define SN_netscape "Netscape"
1653#define LN_netscape "Netscape Communications Corp."
1654#define NID_netscape 57
1655#define OBJ_netscape 2L,16L,840L,1L,113730L
1656
1657#define SN_netscape_cert_extension "nsCertExt"
1658#define LN_netscape_cert_extension "Netscape Certificate Extension"
1659#define NID_netscape_cert_extension 58
1660#define OBJ_netscape_cert_extension OBJ_netscape,1L
1661
1662#define SN_netscape_data_type "nsDataType"
1663#define LN_netscape_data_type "Netscape Data Type"
1664#define NID_netscape_data_type 59
1665#define OBJ_netscape_data_type OBJ_netscape,2L
1666
1667#define SN_netscape_cert_type "nsCertType"
1668#define LN_netscape_cert_type "Netscape Cert Type"
1669#define NID_netscape_cert_type 71
1670#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
1671
1672#define SN_netscape_base_url "nsBaseUrl"
1673#define LN_netscape_base_url "Netscape Base Url"
1674#define NID_netscape_base_url 72
1675#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
1676
1677#define SN_netscape_revocation_url "nsRevocationUrl"
1678#define LN_netscape_revocation_url "Netscape Revocation Url"
1679#define NID_netscape_revocation_url 73
1680#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
1681
1682#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
1683#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
1684#define NID_netscape_ca_revocation_url 74
1685#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
1686
1687#define SN_netscape_renewal_url "nsRenewalUrl"
1688#define LN_netscape_renewal_url "Netscape Renewal Url"
1689#define NID_netscape_renewal_url 75
1690#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
1691
1692#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
1693#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
1694#define NID_netscape_ca_policy_url 76
1695#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
1696
1697#define SN_netscape_ssl_server_name "nsSslServerName"
1698#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
1699#define NID_netscape_ssl_server_name 77
1700#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
1701
1702#define SN_netscape_comment "nsComment"
1703#define LN_netscape_comment "Netscape Comment"
1704#define NID_netscape_comment 78
1705#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
1706
1707#define SN_netscape_cert_sequence "nsCertSequence"
1708#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
1709#define NID_netscape_cert_sequence 79
1710#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
1711
1712#define SN_ns_sgc "nsSGC"
1713#define LN_ns_sgc "Netscape Server Gated Crypto"
1714#define NID_ns_sgc 139
1715#define OBJ_ns_sgc OBJ_netscape,4L,1L
1716
1717#define SN_org "ORG"
1718#define LN_org "org"
1719#define NID_org 379
1720#define OBJ_org OBJ_iso,3L
1721
1722#define SN_dod "DOD"
1723#define LN_dod "dod"
1724#define NID_dod 380
1725#define OBJ_dod OBJ_org,6L
1726
1727#define SN_iana "IANA"
1728#define LN_iana "iana"
1729#define NID_iana 381
1730#define OBJ_iana OBJ_dod,1L
1731
1732#define OBJ_internet OBJ_iana
1733
1734#define SN_Directory "directory"
1735#define LN_Directory "Directory"
1736#define NID_Directory 382
1737#define OBJ_Directory OBJ_internet,1L
1738
1739#define SN_Management "mgmt"
1740#define LN_Management "Management"
1741#define NID_Management 383
1742#define OBJ_Management OBJ_internet,2L
1743
1744#define SN_Experimental "experimental"
1745#define LN_Experimental "Experimental"
1746#define NID_Experimental 384
1747#define OBJ_Experimental OBJ_internet,3L
1748
1749#define SN_Private "private"
1750#define LN_Private "Private"
1751#define NID_Private 385
1752#define OBJ_Private OBJ_internet,4L
1753
1754#define SN_Security "security"
1755#define LN_Security "Security"
1756#define NID_Security 386
1757#define OBJ_Security OBJ_internet,5L
1758
1759#define SN_SNMPv2 "snmpv2"
1760#define LN_SNMPv2 "SNMPv2"
1761#define NID_SNMPv2 387
1762#define OBJ_SNMPv2 OBJ_internet,6L
1763
1764#define SN_Mail "mail"
1765#define LN_Mail "Mail"
1766#define NID_Mail 388
1767#define OBJ_Mail OBJ_internet,7L
1768
1769#define SN_Enterprises "enterprises"
1770#define LN_Enterprises "Enterprises"
1771#define NID_Enterprises 389
1772#define OBJ_Enterprises OBJ_private,1L
1773
1774#define SN_dcObject "dcobject"
1775#define LN_dcObject "dcObject"
1776#define NID_dcObject 390
1777#define OBJ_dcObject OBJ_enterprises,1466L,344L
1778
1779#define SN_domainComponent "DC"
1780#define LN_domainComponent "domainComponent"
1781#define NID_domainComponent 391
1782#define OBJ_domainComponent 0L,9L,2342L,19200300L,100L,1L,25L
1783
1784#define SN_Domain "domain"
1785#define LN_Domain "Domain"
1786#define NID_Domain 392
1787#define OBJ_Domain 0L,9L,2342L,19200300L,100L,4L,13L
1788
1789#define SN_rle_compression "RLE"
1790#define LN_rle_compression "run length compression"
1791#define NID_rle_compression 124
1792#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
1793
1794#define SN_zlib_compression "ZLIB"
1795#define LN_zlib_compression "zlib compression"
1796#define NID_zlib_compression 125
1797#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
1798
diff --git a/src/lib/libssl/src/crypto/objects/obj_mac.num b/src/lib/libssl/src/crypto/objects/obj_mac.num
new file mode 100644
index 0000000000..d73a51370f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_mac.num
@@ -0,0 +1,392 @@
1undef 0
2rsadsi 1
3pkcs 2
4md2 3
5md5 4
6rc4 5
7rsaEncryption 6
8md2WithRSAEncryption 7
9md5WithRSAEncryption 8
10pbeWithMD2AndDES_CBC 9
11pbeWithMD5AndDES_CBC 10
12X500 11
13X509 12
14commonName 13
15countryName 14
16localityName 15
17stateOrProvinceName 16
18organizationName 17
19organizationalUnitName 18
20rsa 19
21pkcs7 20
22pkcs7_data 21
23pkcs7_signed 22
24pkcs7_enveloped 23
25pkcs7_signedAndEnveloped 24
26pkcs7_digest 25
27pkcs7_encrypted 26
28pkcs3 27
29dhKeyAgreement 28
30des_ecb 29
31des_cfb64 30
32des_cbc 31
33des_ede 32
34des_ede3 33
35idea_cbc 34
36idea_cfb64 35
37idea_ecb 36
38rc2_cbc 37
39rc2_ecb 38
40rc2_cfb64 39
41rc2_ofb64 40
42sha 41
43shaWithRSAEncryption 42
44des_ede_cbc 43
45des_ede3_cbc 44
46des_ofb64 45
47idea_ofb64 46
48pkcs9 47
49pkcs9_emailAddress 48
50pkcs9_unstructuredName 49
51pkcs9_contentType 50
52pkcs9_messageDigest 51
53pkcs9_signingTime 52
54pkcs9_countersignature 53
55pkcs9_challengePassword 54
56pkcs9_unstructuredAddress 55
57pkcs9_extCertAttributes 56
58netscape 57
59netscape_cert_extension 58
60netscape_data_type 59
61des_ede_cfb64 60
62des_ede3_cfb64 61
63des_ede_ofb64 62
64des_ede3_ofb64 63
65sha1 64
66sha1WithRSAEncryption 65
67dsaWithSHA 66
68dsa_2 67
69pbeWithSHA1AndRC2_CBC 68
70id_pbkdf2 69
71dsaWithSHA1_2 70
72netscape_cert_type 71
73netscape_base_url 72
74netscape_revocation_url 73
75netscape_ca_revocation_url 74
76netscape_renewal_url 75
77netscape_ca_policy_url 76
78netscape_ssl_server_name 77
79netscape_comment 78
80netscape_cert_sequence 79
81desx_cbc 80
82id_ce 81
83subject_key_identifier 82
84key_usage 83
85private_key_usage_period 84
86subject_alt_name 85
87issuer_alt_name 86
88basic_constraints 87
89crl_number 88
90certificate_policies 89
91authority_key_identifier 90
92bf_cbc 91
93bf_ecb 92
94bf_cfb64 93
95bf_ofb64 94
96mdc2 95
97mdc2WithRSA 96
98rc4_40 97
99rc2_40_cbc 98
100givenName 99
101surname 100
102initials 101
103uniqueIdentifier 102
104crl_distribution_points 103
105md5WithRSA 104
106serialNumber 105
107title 106
108description 107
109cast5_cbc 108
110cast5_ecb 109
111cast5_cfb64 110
112cast5_ofb64 111
113pbeWithMD5AndCast5_CBC 112
114dsaWithSHA1 113
115md5_sha1 114
116sha1WithRSA 115
117dsa 116
118ripemd160 117
119ripemd160WithRSA 119
120rc5_cbc 120
121rc5_ecb 121
122rc5_cfb64 122
123rc5_ofb64 123
124rle_compression 124
125zlib_compression 125
126ext_key_usage 126
127id_pkix 127
128id_kp 128
129server_auth 129
130client_auth 130
131code_sign 131
132email_protect 132
133time_stamp 133
134ms_code_ind 134
135ms_code_com 135
136ms_ctl_sign 136
137ms_sgc 137
138ms_efs 138
139ns_sgc 139
140delta_crl 140
141crl_reason 141
142invalidity_date 142
143sxnet 143
144pbe_WithSHA1And128BitRC4 144
145pbe_WithSHA1And40BitRC4 145
146pbe_WithSHA1And3_Key_TripleDES_CBC 146
147pbe_WithSHA1And2_Key_TripleDES_CBC 147
148pbe_WithSHA1And128BitRC2_CBC 148
149pbe_WithSHA1And40BitRC2_CBC 149
150keyBag 150
151pkcs8ShroudedKeyBag 151
152certBag 152
153crlBag 153
154secretBag 154
155safeContentsBag 155
156friendlyName 156
157localKeyID 157
158x509Certificate 158
159sdsiCertificate 159
160x509Crl 160
161pbes2 161
162pbmac1 162
163hmacWithSHA1 163
164id_qt_cps 164
165id_qt_unotice 165
166rc2_64_cbc 166
167SMIMECapabilities 167
168pbeWithMD2AndRC2_CBC 168
169pbeWithMD5AndRC2_CBC 169
170pbeWithSHA1AndDES_CBC 170
171ms_ext_req 171
172ext_req 172
173name 173
174dnQualifier 174
175id_pe 175
176id_ad 176
177info_access 177
178ad_OCSP 178
179ad_ca_issuers 179
180OCSP_sign 180
181iso 181
182member_body 182
183ISO_US 183
184X9_57 184
185X9cm 185
186pkcs1 186
187pkcs5 187
188SMIME 188
189id_smime_mod 189
190id_smime_ct 190
191id_smime_aa 191
192id_smime_alg 192
193id_smime_cd 193
194id_smime_spq 194
195id_smime_cti 195
196id_smime_mod_cms 196
197id_smime_mod_ess 197
198id_smime_mod_oid 198
199id_smime_mod_msg_v3 199
200id_smime_mod_ets_eSignature_88 200
201id_smime_mod_ets_eSignature_97 201
202id_smime_mod_ets_eSigPolicy_88 202
203id_smime_mod_ets_eSigPolicy_97 203
204id_smime_ct_receipt 204
205id_smime_ct_authData 205
206id_smime_ct_publishCert 206
207id_smime_ct_TSTInfo 207
208id_smime_ct_TDTInfo 208
209id_smime_ct_contentInfo 209
210id_smime_ct_DVCSRequestData 210
211id_smime_ct_DVCSResponseData 211
212id_smime_aa_receiptRequest 212
213id_smime_aa_securityLabel 213
214id_smime_aa_mlExpandHistory 214
215id_smime_aa_contentHint 215
216id_smime_aa_msgSigDigest 216
217id_smime_aa_encapContentType 217
218id_smime_aa_contentIdentifier 218
219id_smime_aa_macValue 219
220id_smime_aa_equivalentLabels 220
221id_smime_aa_contentReference 221
222id_smime_aa_encrypKeyPref 222
223id_smime_aa_signingCertificate 223
224id_smime_aa_smimeEncryptCerts 224
225id_smime_aa_timeStampToken 225
226id_smime_aa_ets_sigPolicyId 226
227id_smime_aa_ets_commitmentType 227
228id_smime_aa_ets_signerLocation 228
229id_smime_aa_ets_signerAttr 229
230id_smime_aa_ets_otherSigCert 230
231id_smime_aa_ets_contentTimestamp 231
232id_smime_aa_ets_CertificateRefs 232
233id_smime_aa_ets_RevocationRefs 233
234id_smime_aa_ets_certValues 234
235id_smime_aa_ets_revocationValues 235
236id_smime_aa_ets_escTimeStamp 236
237id_smime_aa_ets_certCRLTimestamp 237
238id_smime_aa_ets_archiveTimeStamp 238
239id_smime_aa_signatureType 239
240id_smime_aa_dvcs_dvc 240
241id_smime_alg_ESDHwith3DES 241
242id_smime_alg_ESDHwithRC2 242
243id_smime_alg_3DESwrap 243
244id_smime_alg_RC2wrap 244
245id_smime_alg_ESDH 245
246id_smime_alg_CMS3DESwrap 246
247id_smime_alg_CMSRC2wrap 247
248id_smime_cd_ldap 248
249id_smime_spq_ets_sqt_uri 249
250id_smime_spq_ets_sqt_unotice 250
251id_smime_cti_ets_proofOfOrigin 251
252id_smime_cti_ets_proofOfReceipt 252
253id_smime_cti_ets_proofOfDelivery 253
254id_smime_cti_ets_proofOfSender 254
255id_smime_cti_ets_proofOfApproval 255
256id_smime_cti_ets_proofOfCreation 256
257md4 257
258id_pkix_mod 258
259id_qt 259
260id_it 260
261id_pkip 261
262id_alg 262
263id_cmc 263
264id_on 264
265id_pda 265
266id_aca 266
267id_qcs 267
268id_cct 268
269id_pkix1_explicit_88 269
270id_pkix1_implicit_88 270
271id_pkix1_explicit_93 271
272id_pkix1_implicit_93 272
273id_mod_crmf 273
274id_mod_cmc 274
275id_mod_kea_profile_88 275
276id_mod_kea_profile_93 276
277id_mod_cmp 277
278id_mod_qualified_cert_88 278
279id_mod_qualified_cert_93 279
280id_mod_attribute_cert 280
281id_mod_timestamp_protocol 281
282id_mod_ocsp 282
283id_mod_dvcs 283
284id_mod_cmp2000 284
285biometricInfo 285
286qcStatements 286
287ac_auditEntity 287
288ac_targeting 288
289aaControls 289
290sbqp_ipAddrBlock 290
291sbqp_autonomousSysNum 291
292sbqp_routerIdentifier 292
293textNotice 293
294ipsecEndSystem 294
295ipsecTunnel 295
296ipsecUser 296
297dvcs 297
298id_it_caProtEncCert 298
299id_it_signKeyPairTypes 299
300id_it_encKeyPairTypes 300
301id_it_preferredSymmAlg 301
302id_it_caKeyUpdateInfo 302
303id_it_currentCRL 303
304id_it_unsupportedOIDs 304
305id_it_subscriptionRequest 305
306id_it_subscriptionResponse 306
307id_it_keyPairParamReq 307
308id_it_keyPairParamRep 308
309id_it_revPassphrase 309
310id_it_implicitConfirm 310
311id_it_confirmWaitTime 311
312id_it_origPKIMessage 312
313id_regCtrl 313
314id_regInfo 314
315id_regCtrl_regToken 315
316id_regCtrl_authenticator 316
317id_regCtrl_pkiPublicationInfo 317
318id_regCtrl_pkiArchiveOptions 318
319id_regCtrl_oldCertID 319
320id_regCtrl_protocolEncrKey 320
321id_regInfo_utf8Pairs 321
322id_regInfo_certReq 322
323id_alg_des40 323
324id_alg_noSignature 324
325id_alg_dh_sig_hmac_sha1 325
326id_alg_dh_pop 326
327id_cmc_statusInfo 327
328id_cmc_identification 328
329id_cmc_identityProof 329
330id_cmc_dataReturn 330
331id_cmc_transactionId 331
332id_cmc_senderNonce 332
333id_cmc_recipientNonce 333
334id_cmc_addExtensions 334
335id_cmc_encryptedPOP 335
336id_cmc_decryptedPOP 336
337id_cmc_lraPOPWitness 337
338id_cmc_getCert 338
339id_cmc_getCRL 339
340id_cmc_revokeRequest 340
341id_cmc_regInfo 341
342id_cmc_responseInfo 342
343id_cmc_queryPending 343
344id_cmc_popLinkRandom 344
345id_cmc_popLinkWitness 345
346id_cmc_confirmCertAcceptance 346
347id_on_personalData 347
348id_pda_dateOfBirth 348
349id_pda_placeOfBirth 349
350id_pda_pseudonym 350
351id_pda_gender 351
352id_pda_countryOfCitizenship 352
353id_pda_countryOfResidence 353
354id_aca_authenticationInfo 354
355id_aca_accessIdentity 355
356id_aca_chargingIdentity 356
357id_aca_group 357
358id_aca_role 358
359id_qcs_pkixQCSyntax_v1 359
360id_cct_crs 360
361id_cct_PKIData 361
362id_cct_PKIResponse 362
363ad_timeStamping 363
364ad_dvcs 364
365id_pkix_OCSP_basic 365
366id_pkix_OCSP_Nonce 366
367id_pkix_OCSP_CrlID 367
368id_pkix_OCSP_acceptableResponses 368
369id_pkix_OCSP_noCheck 369
370id_pkix_OCSP_archiveCutoff 370
371id_pkix_OCSP_serviceLocator 371
372id_pkix_OCSP_extendedStatus 372
373id_pkix_OCSP_valid 373
374id_pkix_OCSP_path 374
375id_pkix_OCSP_trustRoot 375
376algorithm 376
377rsaSignature 377
378X500algorithms 378
379org 379
380dod 380
381iana 381
382Directory 382
383Management 383
384Experimental 384
385Private 385
386Security 386
387SNMPv2 387
388Mail 388
389Enterprises 389
390dcObject 390
391domainComponent 391
392Domain 392
diff --git a/src/lib/libssl/src/crypto/objects/objects.README b/src/lib/libssl/src/crypto/objects/objects.README
new file mode 100644
index 0000000000..4d745508d8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/objects.README
@@ -0,0 +1,44 @@
1objects.txt syntax
2------------------
3
4To cover all the naming hacks that were previously in objects.h needed some
5kind of hacks in objects.txt.
6
7The basic syntax for adding an object is as follows:
8
9 1 2 3 4 : shortName : Long Name
10
11 If the long name doesn't contain spaces, or no short name
12 exists, the long name is used as basis for the base name
13 in C. Otherwise, the short name is used.
14
15 The base name (let's call it 'base') will then be used to
16 create the C macros SN_base, LN_base, NID_base and OBJ_base.
17
18 Note that if the base name contains spaces, dashes or periods,
19 those will be converte to underscore.
20
21Then there are some extra commands:
22
23 !Alias foo 1 2 3 4
24
25 This juts makes a name foo for an OID. The C macro
26 OBJ_foo will be created as a result.
27
28 !Cname foo
29
30 This makes sure that the name foo will be used as base name
31 in C.
32
33 !module foo
34 1 2 3 4 : shortName : Long Name
35 !global
36
37 The !module command was meant to define a kind of modularity.
38 What it does is to make sure the module name is prepended
39 to the base name. !global turns this off. This construction
40 is not recursive.
41
42Lines starting with # are treated as comments, as well as any line starting
43with ! and not matching the commands above.
44
diff --git a/src/lib/libssl/src/crypto/objects/objects.pl b/src/lib/libssl/src/crypto/objects/objects.pl
new file mode 100644
index 0000000000..c956bbb841
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/objects.pl
@@ -0,0 +1,224 @@
1#!/usr/local/bin/perl
2
3open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
4$max_nid=0;
5$o=0;
6while(<NUMIN>)
7 {
8 chop;
9 $o++;
10 s/#.*$//;
11 next if /^\s*$/;
12 ($Cname,$mynum) = split;
13 if (defined($nidn{$mynum}))
14 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
15 $nid{$Cname} = $mynum;
16 $nidn{$mynum} = $Cname;
17 $order{$mynum} = $o;
18 $max_nid = $mynum if $mynum > $max_nid;
19 }
20close NUMIN;
21
22open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
23$Cname="";
24$o=0;
25while (<IN>)
26 {
27 chop;
28 $o++;
29 if (/^!module\s+(.*)$/)
30 {
31 $module = $1."-";
32 $module =~ s/\./_/g;
33 $module =~ s/-/_/g;
34 }
35 if (/^!global$/)
36 { $module = ""; }
37 if (/^!Cname\s+(.*)$/)
38 { $Cname = $1; }
39 if (/^!Alias\s+(.+?)\s+(.*)$/)
40 {
41 $Cname = $module.$1;
42 $myoid = $2;
43 $myoid = &process_oid($myoid);
44 $Cname =~ s/-/_/g;
45 $ordern{$o} = $Cname;
46 $order{$Cname} = $o;
47 $obj{$Cname} = $myoid;
48 $_ = "";
49 $Cname = "";
50 }
51 s/!.*$//;
52 s/#.*$//;
53 next if /^\s*$/;
54 ($myoid,$mysn,$myln) = split ':';
55 $mysn =~ s/^\s*//;
56 $mysn =~ s/\s*$//;
57 $myln =~ s/^\s*//;
58 $myln =~ s/\s*$//;
59 $myoid =~ s/^\s*//;
60 $myoid =~ s/\s*$//;
61 if ($myoid ne "")
62 {
63 $myoid = &process_oid($myoid);
64 }
65
66 if ($Cname eq "" && !($myln =~ / /))
67 {
68 $Cname = $myln;
69 $Cname =~ s/\./_/g;
70 $Cname =~ s/-/_/g;
71 if ($Cname ne "" && defined($ln{$module.$Cname}))
72 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
73 }
74 if ($Cname eq "")
75 {
76 $Cname = $mysn;
77 $Cname =~ s/-/_/g;
78 if ($Cname ne "" && defined($sn{$module.$Cname}))
79 { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
80 }
81 if ($Cname eq "")
82 {
83 $Cname = $myln;
84 $Cname =~ s/-/_/g;
85 $Cname =~ s/\./_/g;
86 $Cname =~ s/ /_/g;
87 if ($Cname ne "" && defined($ln{$module.$Cname}))
88 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
89 }
90 $Cname =~ s/\./_/g;
91 $Cname =~ s/-/_/g;
92 $Cname = $module.$Cname;
93 $ordern{$o} = $Cname;
94 $order{$Cname} = $o;
95 $sn{$Cname} = $mysn;
96 $ln{$Cname} = $myln;
97 $obj{$Cname} = $myoid;
98 if (!defined($nid{$Cname}))
99 {
100 $max_nid++;
101 $nid{$Cname} = $max_nid;
102 $nidn{$max_nid} = $Cname;
103 }
104 $Cname="";
105 }
106close IN;
107
108open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
109foreach (sort { $a <=> $b } keys %nidn)
110 {
111 print NUMOUT $nidn{$_},"\t\t",$_,"\n";
112 }
113close NUMOUT;
114
115open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
116print OUT <<'EOF';
117/* lib/obj/obj_mac.h */
118/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
119 * All rights reserved.
120 *
121 * This package is an SSL implementation written
122 * by Eric Young (eay@cryptsoft.com).
123 * The implementation was written so as to conform with Netscapes SSL.
124 *
125 * This library is free for commercial and non-commercial use as long as
126 * the following conditions are aheared to. The following conditions
127 * apply to all code found in this distribution, be it the RC4, RSA,
128 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
129 * included with this distribution is covered by the same copyright terms
130 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
131 *
132 * Copyright remains Eric Young's, and as such any Copyright notices in
133 * the code are not to be removed.
134 * If this package is used in a product, Eric Young should be given attribution
135 * as the author of the parts of the library used.
136 * This can be in the form of a textual message at program startup or
137 * in documentation (online or textual) provided with the package.
138 *
139 * Redistribution and use in source and binary forms, with or without
140 * modification, are permitted provided that the following conditions
141 * are met:
142 * 1. Redistributions of source code must retain the copyright
143 * notice, this list of conditions and the following disclaimer.
144 * 2. Redistributions in binary form must reproduce the above copyright
145 * notice, this list of conditions and the following disclaimer in the
146 * documentation and/or other materials provided with the distribution.
147 * 3. All advertising materials mentioning features or use of this software
148 * must display the following acknowledgement:
149 * "This product includes cryptographic software written by
150 * Eric Young (eay@cryptsoft.com)"
151 * The word 'cryptographic' can be left out if the rouines from the library
152 * being used are not cryptographic related :-).
153 * 4. If you include any Windows specific code (or a derivative thereof) from
154 * the apps directory (application code) you must include an acknowledgement:
155 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
156 *
157 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
158 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
159 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
160 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
161 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
162 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
163 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
164 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
165 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
166 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
167 * SUCH DAMAGE.
168 *
169 * The licence and distribution terms for any publically available version or
170 * derivative of this code cannot be changed. i.e. this code cannot simply be
171 * copied and put under another distribution licence
172 * [including the GNU Public Licence.]
173 */
174
175/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
176 * following command:
177 * perl objects.pl objects.txt obj_mac.num obj_mac.h
178 */
179
180#define SN_undef "UNDEF"
181#define LN_undef "undefined"
182#define NID_undef 0
183#define OBJ_undef 0L
184
185EOF
186
187foreach (sort { $a <=> $b } keys %ordern)
188 {
189 $Cname=$ordern{$_};
190 print OUT "#define SN_",$Cname,"\t\t\"",$sn{$Cname},"\"\n" if $sn{$Cname} ne "";
191 print OUT "#define LN_",$Cname,"\t\t\"",$ln{$Cname},"\"\n" if $ln{$Cname} ne "";
192 print OUT "#define NID_",$Cname,"\t\t",$nid{$Cname},"\n" if $nid{$Cname} ne "";
193 print OUT "#define OBJ_",$Cname,"\t\t",$obj{$Cname},"\n" if $obj{$Cname} ne "";
194 print OUT "\n";
195 }
196
197close OUT;
198
199sub process_oid
200 {
201 local($oid)=@_;
202 local(@a,$oid_pref);
203
204 @a = split(/\s+/,$myoid);
205 $pref_oid = "";
206 $pref_sep = "";
207 if (!($a[0] =~ /^[0-9]+$/))
208 {
209 $a[0] =~ s/-/_/g;
210 $pref_oid = "OBJ_" . $a[0];
211 $pref_sep = ",";
212 shift @a;
213 }
214 $oids = join('L,',@a) . "L";
215 if ($oids ne "L")
216 {
217 $oids = $pref_oid . $pref_sep . $oids;
218 }
219 else
220 {
221 $oids = $pref_oid;
222 }
223 return($oids);
224 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp.h b/src/lib/libssl/src/crypto/ocsp/ocsp.h
new file mode 100644
index 0000000000..fab3c03182
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp.h
@@ -0,0 +1,619 @@
1/* ocsp.h */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#ifndef HEADER_OCSP_H
65#define HEADER_OCSP_H
66
67#include <openssl/x509.h>
68#include <openssl/x509v3.h>
69#include <openssl/safestack.h>
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75/* Various flags and values */
76
77#define OCSP_DEFAULT_NONCE_LENGTH 16
78
79#define OCSP_NOCERTS 0x1
80#define OCSP_NOINTERN 0x2
81#define OCSP_NOSIGS 0x4
82#define OCSP_NOCHAIN 0x8
83#define OCSP_NOVERIFY 0x10
84#define OCSP_NOEXPLICIT 0x20
85#define OCSP_NOCASIGN 0x40
86#define OCSP_NODELEGATED 0x80
87#define OCSP_NOCHECKS 0x100
88#define OCSP_TRUSTOTHER 0x200
89#define OCSP_RESPID_KEY 0x400
90#define OCSP_NOTIME 0x800
91
92/* CertID ::= SEQUENCE {
93 * hashAlgorithm AlgorithmIdentifier,
94 * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
95 * issuerKeyHash OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields)
96 * serialNumber CertificateSerialNumber }
97 */
98typedef struct ocsp_cert_id_st
99 {
100 X509_ALGOR *hashAlgorithm;
101 ASN1_OCTET_STRING *issuerNameHash;
102 ASN1_OCTET_STRING *issuerKeyHash;
103 ASN1_INTEGER *serialNumber;
104 } OCSP_CERTID;
105
106DECLARE_STACK_OF(OCSP_CERTID)
107
108/* Request ::= SEQUENCE {
109 * reqCert CertID,
110 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
111 */
112typedef struct ocsp_one_request_st
113 {
114 OCSP_CERTID *reqCert;
115 STACK_OF(X509_EXTENSION) *singleRequestExtensions;
116 } OCSP_ONEREQ;
117
118DECLARE_STACK_OF(OCSP_ONEREQ)
119DECLARE_ASN1_SET_OF(OCSP_ONEREQ)
120
121
122/* TBSRequest ::= SEQUENCE {
123 * version [0] EXPLICIT Version DEFAULT v1,
124 * requestorName [1] EXPLICIT GeneralName OPTIONAL,
125 * requestList SEQUENCE OF Request,
126 * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
127 */
128typedef struct ocsp_req_info_st
129 {
130 ASN1_INTEGER *version;
131 GENERAL_NAME *requestorName;
132 STACK_OF(OCSP_ONEREQ) *requestList;
133 STACK_OF(X509_EXTENSION) *requestExtensions;
134 } OCSP_REQINFO;
135
136/* Signature ::= SEQUENCE {
137 * signatureAlgorithm AlgorithmIdentifier,
138 * signature BIT STRING,
139 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
140 */
141typedef struct ocsp_signature_st
142 {
143 X509_ALGOR *signatureAlgorithm;
144 ASN1_BIT_STRING *signature;
145 STACK_OF(X509) *certs;
146 } OCSP_SIGNATURE;
147
148/* OCSPRequest ::= SEQUENCE {
149 * tbsRequest TBSRequest,
150 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
151 */
152typedef struct ocsp_request_st
153 {
154 OCSP_REQINFO *tbsRequest;
155 OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */
156 } OCSP_REQUEST;
157
158/* OCSPResponseStatus ::= ENUMERATED {
159 * successful (0), --Response has valid confirmations
160 * malformedRequest (1), --Illegal confirmation request
161 * internalError (2), --Internal error in issuer
162 * tryLater (3), --Try again later
163 * --(4) is not used
164 * sigRequired (5), --Must sign the request
165 * unauthorized (6) --Request unauthorized
166 * }
167 */
168#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0
169#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1
170#define OCSP_RESPONSE_STATUS_INTERNALERROR 2
171#define OCSP_RESPONSE_STATUS_TRYLATER 3
172#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5
173#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
174
175/* ResponseBytes ::= SEQUENCE {
176 * responseType OBJECT IDENTIFIER,
177 * response OCTET STRING }
178 */
179typedef struct ocsp_resp_bytes_st
180 {
181 ASN1_OBJECT *responseType;
182 ASN1_OCTET_STRING *response;
183 } OCSP_RESPBYTES;
184
185/* OCSPResponse ::= SEQUENCE {
186 * responseStatus OCSPResponseStatus,
187 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
188 */
189typedef struct ocsp_response_st
190 {
191 ASN1_ENUMERATED *responseStatus;
192 OCSP_RESPBYTES *responseBytes;
193 } OCSP_RESPONSE;
194
195/* ResponderID ::= CHOICE {
196 * byName [1] Name,
197 * byKey [2] KeyHash }
198 */
199#define V_OCSP_RESPID_NAME 0
200#define V_OCSP_RESPID_KEY 1
201typedef struct ocsp_responder_id_st
202 {
203 int type;
204 union {
205 X509_NAME* byName;
206 ASN1_OCTET_STRING *byKey;
207 } value;
208 } OCSP_RESPID;
209/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key
210 * --(excluding the tag and length fields)
211 */
212
213/* RevokedInfo ::= SEQUENCE {
214 * revocationTime GeneralizedTime,
215 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
216 */
217typedef struct ocsp_revoked_info_st
218 {
219 ASN1_GENERALIZEDTIME *revocationTime;
220 ASN1_ENUMERATED *revocationReason;
221 } OCSP_REVOKEDINFO;
222
223/* CertStatus ::= CHOICE {
224 * good [0] IMPLICIT NULL,
225 * revoked [1] IMPLICIT RevokedInfo,
226 * unknown [2] IMPLICIT UnknownInfo }
227 */
228#define V_OCSP_CERTSTATUS_GOOD 0
229#define V_OCSP_CERTSTATUS_REVOKED 1
230#define V_OCSP_CERTSTATUS_UNKNOWN 2
231typedef struct ocsp_cert_status_st
232 {
233 int type;
234 union {
235 ASN1_NULL *good;
236 OCSP_REVOKEDINFO *revoked;
237 ASN1_NULL *unknown;
238 } value;
239 } OCSP_CERTSTATUS;
240
241/* SingleResponse ::= SEQUENCE {
242 * certID CertID,
243 * certStatus CertStatus,
244 * thisUpdate GeneralizedTime,
245 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
246 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
247 */
248typedef struct ocsp_single_response_st
249 {
250 OCSP_CERTID *certId;
251 OCSP_CERTSTATUS *certStatus;
252 ASN1_GENERALIZEDTIME *thisUpdate;
253 ASN1_GENERALIZEDTIME *nextUpdate;
254 STACK_OF(X509_EXTENSION) *singleExtensions;
255 } OCSP_SINGLERESP;
256
257DECLARE_STACK_OF(OCSP_SINGLERESP)
258DECLARE_ASN1_SET_OF(OCSP_SINGLERESP)
259
260/* ResponseData ::= SEQUENCE {
261 * version [0] EXPLICIT Version DEFAULT v1,
262 * responderID ResponderID,
263 * producedAt GeneralizedTime,
264 * responses SEQUENCE OF SingleResponse,
265 * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
266 */
267typedef struct ocsp_response_data_st
268 {
269 ASN1_INTEGER *version;
270 OCSP_RESPID *responderId;
271 ASN1_GENERALIZEDTIME *producedAt;
272 STACK_OF(OCSP_SINGLERESP) *responses;
273 STACK_OF(X509_EXTENSION) *responseExtensions;
274 } OCSP_RESPDATA;
275
276/* BasicOCSPResponse ::= SEQUENCE {
277 * tbsResponseData ResponseData,
278 * signatureAlgorithm AlgorithmIdentifier,
279 * signature BIT STRING,
280 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
281 */
282 /* Note 1:
283 The value for "signature" is specified in the OCSP rfc2560 as follows:
284 "The value for the signature SHALL be computed on the hash of the DER
285 encoding ResponseData." This means that you must hash the DER-encoded
286 tbsResponseData, and then run it through a crypto-signing function, which
287 will (at least w/RSA) do a hash-'n'-private-encrypt operation. This seems
288 a bit odd, but that's the spec. Also note that the data structures do not
289 leave anywhere to independently specify the algorithm used for the initial
290 hash. So, we look at the signature-specification algorithm, and try to do
291 something intelligent. -- Kathy Weinhold, CertCo */
292 /* Note 2:
293 It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open
294 for interpretation. I've done tests against another responder, and found
295 that it doesn't do the double hashing that the RFC seems to say one
296 should. Therefore, all relevant functions take a flag saying which
297 variant should be used. -- Richard Levitte, OpenSSL team and CeloCom */
298typedef struct ocsp_basic_response_st
299 {
300 OCSP_RESPDATA *tbsResponseData;
301 X509_ALGOR *signatureAlgorithm;
302 ASN1_BIT_STRING *signature;
303 STACK_OF(X509) *certs;
304 } OCSP_BASICRESP;
305
306/*
307 * CRLReason ::= ENUMERATED {
308 * unspecified (0),
309 * keyCompromise (1),
310 * cACompromise (2),
311 * affiliationChanged (3),
312 * superseded (4),
313 * cessationOfOperation (5),
314 * certificateHold (6),
315 * removeFromCRL (8) }
316 */
317#define OCSP_REVOKED_STATUS_NOSTATUS -1
318#define OCSP_REVOKED_STATUS_UNSPECIFIED 0
319#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1
320#define OCSP_REVOKED_STATUS_CACOMPROMISE 2
321#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3
322#define OCSP_REVOKED_STATUS_SUPERSEDED 4
323#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5
324#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6
325#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8
326
327/* CrlID ::= SEQUENCE {
328 * crlUrl [0] EXPLICIT IA5String OPTIONAL,
329 * crlNum [1] EXPLICIT INTEGER OPTIONAL,
330 * crlTime [2] EXPLICIT GeneralizedTime OPTIONAL }
331 */
332typedef struct ocsp_crl_id_st
333 {
334 ASN1_IA5STRING *crlUrl;
335 ASN1_INTEGER *crlNum;
336 ASN1_GENERALIZEDTIME *crlTime;
337 } OCSP_CRLID;
338
339/* ServiceLocator ::= SEQUENCE {
340 * issuer Name,
341 * locator AuthorityInfoAccessSyntax OPTIONAL }
342 */
343typedef struct ocsp_service_locator_st
344 {
345 X509_NAME* issuer;
346 STACK_OF(ACCESS_DESCRIPTION) *locator;
347 } OCSP_SERVICELOC;
348
349#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
350#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
351
352#define d2i_OCSP_REQUEST_bio(bp,p) (OCSP_REQUEST*)ASN1_d2i_bio((char*(*)()) \
353 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_REQUEST, (bp),\
354 (unsigned char **)(p))
355
356#define d2i_OCSP_RESPONSE_bio(bp,p) (OCSP_RESPONSE*)ASN1_d2i_bio((char*(*)())\
357 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_RESPONSE, (bp),\
358 (unsigned char **)(p))
359
360#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
361 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL)
362
363#define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\
364 (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL)
365
366#define PEM_write_bio_OCSP_REQUEST(bp,o) \
367 PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\
368 bp,(char *)o, NULL,NULL,0,NULL,NULL)
369
370#define PEM_write_bio_OCSP_RESPONSE(bp,o) \
371 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
372 bp,(char *)o, NULL,NULL,0,NULL,NULL)
373
374#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_RESPONSE,bp,\
375 (unsigned char *)o)
376
377#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_REQUEST,bp,\
378 (unsigned char *)o)
379
380#define OCSP_REQUEST_sign(o,pkey,md) \
381 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\
382 o->optionalSignature->signatureAlgorithm,NULL,\
383 o->optionalSignature->signature,o->tbsRequest,pkey,md)
384
385#define OCSP_BASICRESP_sign(o,pkey,md,d) \
386 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),o->signatureAlgorithm,NULL,\
387 o->signature,o->tbsResponseData,pkey,md)
388
389#define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\
390 a->optionalSignature->signatureAlgorithm,\
391 a->optionalSignature->signature,a->tbsRequest,r)
392
393#define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\
394 a->signatureAlgorithm,a->signature,a->tbsResponseData,r)
395
396#define ASN1_BIT_STRING_digest(data,type,md,len) \
397 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
398
399#define OCSP_CERTID_dup(cid) (OCSP_CERTID*)ASN1_dup((int(*)())i2d_OCSP_CERTID,\
400 (char *(*)())d2i_OCSP_CERTID,(char *)(cid))
401
402#define OCSP_CERTSTATUS_dup(cs)\
403 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
404 (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
405
406OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);
407
408OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);
409
410OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
411 X509_NAME *issuerName,
412 ASN1_BIT_STRING* issuerKey,
413 ASN1_INTEGER *serialNumber);
414
415OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);
416
417int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);
418int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);
419int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);
420int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);
421
422int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm);
423int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);
424
425int OCSP_request_sign(OCSP_REQUEST *req,
426 X509 *signer,
427 EVP_PKEY *key,
428 const EVP_MD *dgst,
429 STACK_OF(X509) *certs,
430 unsigned long flags);
431
432int OCSP_response_status(OCSP_RESPONSE *resp);
433OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);
434
435int OCSP_resp_count(OCSP_BASICRESP *bs);
436OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
437int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
438int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
439 ASN1_GENERALIZEDTIME **revtime,
440 ASN1_GENERALIZEDTIME **thisupd,
441 ASN1_GENERALIZEDTIME **nextupd);
442int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
443 int *reason,
444 ASN1_GENERALIZEDTIME **revtime,
445 ASN1_GENERALIZEDTIME **thisupd,
446 ASN1_GENERALIZEDTIME **nextupd);
447int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
448 ASN1_GENERALIZEDTIME *nextupd,
449 long sec, long maxsec);
450
451int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags);
452
453int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl);
454
455int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
456int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
457
458int OCSP_request_onereq_count(OCSP_REQUEST *req);
459OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);
460OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);
461int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
462 ASN1_OCTET_STRING **pikeyHash,
463 ASN1_INTEGER **pserial, OCSP_CERTID *cid);
464int OCSP_request_is_signed(OCSP_REQUEST *req);
465OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
466OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
467 OCSP_CERTID *cid,
468 int status, int reason,
469 ASN1_TIME *revtime,
470 ASN1_TIME *thisupd, ASN1_TIME *nextupd);
471int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
472int OCSP_basic_sign(OCSP_BASICRESP *brsp,
473 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
474 STACK_OF(X509) *certs, unsigned long flags);
475
476ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
477 char *data, STACK_OF(ASN1_OBJECT) *sk);
478
479X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);
480
481X509_EXTENSION *OCSP_accept_responses_new(char **oids);
482
483X509_EXTENSION *OCSP_archive_cutoff_new(char* tim);
484
485X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls);
486
487int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);
488int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);
489int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos);
490int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);
491X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);
492X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);
493void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx);
494int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
495 unsigned long flags);
496int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);
497
498int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);
499int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);
500int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos);
501int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);
502X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);
503X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);
504void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);
505int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
506 unsigned long flags);
507int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);
508
509int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);
510int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);
511int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos);
512int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos);
513X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);
514X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);
515void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx);
516int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
517 unsigned long flags);
518int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);
519
520int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);
521int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);
522int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos);
523int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos);
524X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);
525X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);
526void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx);
527int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
528 unsigned long flags);
529int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);
530
531DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)
532DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
533DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
534DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)
535DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)
536DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
537DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)
538DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)
539DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)
540DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)
541DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)
542DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)
543DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
544DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
545DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
546
547char *OCSP_response_status_str(long s);
548char *OCSP_cert_status_str(long s);
549char *OCSP_crl_reason_str(long s);
550
551int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags);
552int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags);
553
554int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
555 X509_STORE *st, unsigned long flags);
556
557/* BEGIN ERROR CODES */
558/* The following lines are auto generated by the script mkerr.pl. Any changes
559 * made after this point may be overwritten when the script is next run.
560 */
561void ERR_load_OCSP_strings(void);
562
563/* Error codes for the OCSP functions. */
564
565/* Function codes. */
566#define OCSP_F_ASN1_STRING_ENCODE 100
567#define OCSP_F_CERT_ID_NEW 101
568#define OCSP_F_D2I_OCSP_NONCE 102
569#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103
570#define OCSP_F_OCSP_BASIC_SIGN 104
571#define OCSP_F_OCSP_BASIC_VERIFY 105
572#define OCSP_F_OCSP_CHECK_DELEGATED 106
573#define OCSP_F_OCSP_CHECK_IDS 107
574#define OCSP_F_OCSP_CHECK_ISSUER 108
575#define OCSP_F_OCSP_CHECK_VALIDITY 115
576#define OCSP_F_OCSP_MATCH_ISSUERID 109
577#define OCSP_F_OCSP_PARSE_URL 114
578#define OCSP_F_OCSP_REQUEST_SIGN 110
579#define OCSP_F_OCSP_REQUEST_VERIFY 116
580#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111
581#define OCSP_F_OCSP_SENDREQ_BIO 112
582#define OCSP_F_REQUEST_VERIFY 113
583
584/* Reason codes. */
585#define OCSP_R_BAD_DATA 100
586#define OCSP_R_CERTIFICATE_VERIFY_ERROR 101
587#define OCSP_R_DIGEST_ERR 102
588#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122
589#define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123
590#define OCSP_R_ERROR_PARSING_URL 121
591#define OCSP_R_MISSING_OCSPSIGNING_USAGE 103
592#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124
593#define OCSP_R_NOT_BASIC_RESPONSE 104
594#define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105
595#define OCSP_R_NO_CONTENT 106
596#define OCSP_R_NO_PUBLIC_KEY 107
597#define OCSP_R_NO_RESPONSE_DATA 108
598#define OCSP_R_NO_REVOKED_TIME 109
599#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110
600#define OCSP_R_REQUEST_NOT_SIGNED 128
601#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111
602#define OCSP_R_ROOT_CA_NOT_TRUSTED 112
603#define OCSP_R_SERVER_READ_ERROR 113
604#define OCSP_R_SERVER_RESPONSE_ERROR 114
605#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115
606#define OCSP_R_SERVER_WRITE_ERROR 116
607#define OCSP_R_SIGNATURE_FAILURE 117
608#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118
609#define OCSP_R_STATUS_EXPIRED 125
610#define OCSP_R_STATUS_NOT_YET_VALID 126
611#define OCSP_R_STATUS_TOO_OLD 127
612#define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119
613#define OCSP_R_UNKNOWN_NID 120
614#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129
615
616#ifdef __cplusplus
617}
618#endif
619#endif
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_asn.c b/src/lib/libssl/src/crypto/ocsp/ocsp_asn.c
new file mode 100644
index 0000000000..8c148cda6a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_asn.c
@@ -0,0 +1,182 @@
1/* ocsp_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/ocsp.h>
61
62ASN1_SEQUENCE(OCSP_SIGNATURE) = {
63 ASN1_SIMPLE(OCSP_SIGNATURE, signatureAlgorithm, X509_ALGOR),
64 ASN1_SIMPLE(OCSP_SIGNATURE, signature, ASN1_BIT_STRING),
65 ASN1_EXP_SEQUENCE_OF(OCSP_SIGNATURE, certs, X509, 0)
66} ASN1_SEQUENCE_END(OCSP_SIGNATURE)
67
68IMPLEMENT_ASN1_FUNCTIONS(OCSP_SIGNATURE)
69
70ASN1_SEQUENCE(OCSP_CERTID) = {
71 ASN1_SIMPLE(OCSP_CERTID, hashAlgorithm, X509_ALGOR),
72 ASN1_SIMPLE(OCSP_CERTID, issuerNameHash, ASN1_OCTET_STRING),
73 ASN1_SIMPLE(OCSP_CERTID, issuerKeyHash, ASN1_OCTET_STRING),
74 ASN1_SIMPLE(OCSP_CERTID, serialNumber, ASN1_INTEGER)
75} ASN1_SEQUENCE_END(OCSP_CERTID)
76
77IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTID)
78
79ASN1_SEQUENCE(OCSP_ONEREQ) = {
80 ASN1_SIMPLE(OCSP_ONEREQ, reqCert, OCSP_CERTID),
81 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_ONEREQ, singleRequestExtensions, X509_EXTENSION, 0)
82} ASN1_SEQUENCE_END(OCSP_ONEREQ)
83
84IMPLEMENT_ASN1_FUNCTIONS(OCSP_ONEREQ)
85
86ASN1_SEQUENCE(OCSP_REQINFO) = {
87 ASN1_EXP_OPT(OCSP_REQINFO, version, ASN1_INTEGER, 0),
88 ASN1_EXP_OPT(OCSP_REQINFO, requestorName, GENERAL_NAME, 1),
89 ASN1_SEQUENCE_OF(OCSP_REQINFO, requestList, OCSP_ONEREQ),
90 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_REQINFO, requestExtensions, X509_EXTENSION, 2)
91} ASN1_SEQUENCE_END(OCSP_REQINFO)
92
93IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQINFO)
94
95ASN1_SEQUENCE(OCSP_REQUEST) = {
96 ASN1_SIMPLE(OCSP_REQUEST, tbsRequest, OCSP_REQINFO),
97 ASN1_EXP_OPT(OCSP_REQUEST, optionalSignature, OCSP_SIGNATURE, 0)
98} ASN1_SEQUENCE_END(OCSP_REQUEST)
99
100IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQUEST)
101
102/* OCSP_RESPONSE templates */
103
104ASN1_SEQUENCE(OCSP_RESPBYTES) = {
105 ASN1_SIMPLE(OCSP_RESPBYTES, responseType, ASN1_OBJECT),
106 ASN1_SIMPLE(OCSP_RESPBYTES, response, ASN1_OCTET_STRING)
107} ASN1_SEQUENCE_END(OCSP_RESPBYTES)
108
109IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPBYTES)
110
111ASN1_SEQUENCE(OCSP_RESPONSE) = {
112 ASN1_SIMPLE(OCSP_RESPONSE, responseStatus, ASN1_ENUMERATED),
113 ASN1_EXP_OPT(OCSP_RESPONSE, responseBytes, OCSP_RESPBYTES, 0)
114} ASN1_SEQUENCE_END(OCSP_RESPONSE)
115
116IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPONSE)
117
118ASN1_CHOICE(OCSP_RESPID) = {
119 ASN1_EXP(OCSP_RESPID, value.byName, X509_NAME, 1),
120 ASN1_IMP(OCSP_RESPID, value.byKey, ASN1_OCTET_STRING, 2)
121} ASN1_CHOICE_END(OCSP_RESPID)
122
123IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPID)
124
125ASN1_SEQUENCE(OCSP_REVOKEDINFO) = {
126 ASN1_SIMPLE(OCSP_REVOKEDINFO, revocationTime, ASN1_GENERALIZEDTIME),
127 ASN1_EXP_OPT(OCSP_REVOKEDINFO, revocationReason, ASN1_ENUMERATED, 0)
128} ASN1_SEQUENCE_END(OCSP_REVOKEDINFO)
129
130IMPLEMENT_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
131
132ASN1_CHOICE(OCSP_CERTSTATUS) = {
133 ASN1_IMP(OCSP_CERTSTATUS, value.good, ASN1_NULL, 0),
134 ASN1_IMP(OCSP_CERTSTATUS, value.revoked, OCSP_REVOKEDINFO, 1),
135 ASN1_IMP(OCSP_CERTSTATUS, value.unknown, ASN1_NULL, 2)
136} ASN1_CHOICE_END(OCSP_CERTSTATUS)
137
138IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
139
140ASN1_SEQUENCE(OCSP_SINGLERESP) = {
141 ASN1_SIMPLE(OCSP_SINGLERESP, certId, OCSP_CERTID),
142 ASN1_SIMPLE(OCSP_SINGLERESP, certStatus, OCSP_CERTSTATUS),
143 ASN1_SIMPLE(OCSP_SINGLERESP, thisUpdate, ASN1_GENERALIZEDTIME),
144 ASN1_EXP_OPT(OCSP_SINGLERESP, nextUpdate, ASN1_GENERALIZEDTIME, 0),
145 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_SINGLERESP, singleExtensions, X509_EXTENSION, 1)
146} ASN1_SEQUENCE_END(OCSP_SINGLERESP)
147
148IMPLEMENT_ASN1_FUNCTIONS(OCSP_SINGLERESP)
149
150ASN1_SEQUENCE(OCSP_RESPDATA) = {
151 ASN1_EXP_OPT(OCSP_RESPDATA, version, ASN1_INTEGER, 0),
152 ASN1_SIMPLE(OCSP_RESPDATA, responderId, OCSP_RESPID),
153 ASN1_SIMPLE(OCSP_RESPDATA, producedAt, ASN1_GENERALIZEDTIME),
154 ASN1_SEQUENCE_OF(OCSP_RESPDATA, responses, OCSP_SINGLERESP),
155 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_RESPDATA, responseExtensions, X509_EXTENSION, 1)
156} ASN1_SEQUENCE_END(OCSP_RESPDATA)
157
158IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPDATA)
159
160ASN1_SEQUENCE(OCSP_BASICRESP) = {
161 ASN1_SIMPLE(OCSP_BASICRESP, tbsResponseData, OCSP_RESPDATA),
162 ASN1_SIMPLE(OCSP_BASICRESP, signatureAlgorithm, X509_ALGOR),
163 ASN1_SIMPLE(OCSP_BASICRESP, signature, ASN1_BIT_STRING),
164 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_BASICRESP, certs, X509, 0)
165} ASN1_SEQUENCE_END(OCSP_BASICRESP)
166
167IMPLEMENT_ASN1_FUNCTIONS(OCSP_BASICRESP)
168
169ASN1_SEQUENCE(OCSP_CRLID) = {
170 ASN1_EXP_OPT(OCSP_CRLID, crlUrl, ASN1_IA5STRING, 0),
171 ASN1_EXP_OPT(OCSP_CRLID, crlNum, ASN1_INTEGER, 1),
172 ASN1_EXP_OPT(OCSP_CRLID, crlTime, ASN1_GENERALIZEDTIME, 2)
173} ASN1_SEQUENCE_END(OCSP_CRLID)
174
175IMPLEMENT_ASN1_FUNCTIONS(OCSP_CRLID)
176
177ASN1_SEQUENCE(OCSP_SERVICELOC) = {
178 ASN1_SIMPLE(OCSP_SERVICELOC, issuer, X509_NAME),
179 ASN1_SEQUENCE_OF_OPT(OCSP_SERVICELOC, locator, ACCESS_DESCRIPTION)
180} ASN1_SEQUENCE_END(OCSP_SERVICELOC)
181
182IMPLEMENT_ASN1_FUNCTIONS(OCSP_SERVICELOC)
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_cl.c b/src/lib/libssl/src/crypto/ocsp/ocsp_cl.c
new file mode 100644
index 0000000000..9b3e6dd8ca
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_cl.c
@@ -0,0 +1,370 @@
1/* ocsp_cl.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include <cryptlib.h>
67#include <openssl/objects.h>
68#include <openssl/rand.h>
69#include <openssl/x509.h>
70#include <openssl/pem.h>
71#include <openssl/x509v3.h>
72#include <openssl/ocsp.h>
73
74/* Utility functions related to sending OCSP requests and extracting
75 * relevant information from the response.
76 */
77
78/* Add an OCSP_CERTID to an OCSP request. Return new OCSP_ONEREQ
79 * pointer: useful if we want to add extensions.
80 */
81
82OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
83 {
84 OCSP_ONEREQ *one = NULL;
85
86 if (!(one = OCSP_ONEREQ_new())) goto err;
87 if (one->reqCert) OCSP_CERTID_free(one->reqCert);
88 one->reqCert = cid;
89 if (req &&
90 !sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one))
91 goto err;
92 return one;
93err:
94 OCSP_ONEREQ_free(one);
95 return NULL;
96 }
97
98/* Set requestorName from an X509_NAME structure */
99
100int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
101 {
102 GENERAL_NAME *gen;
103 gen = GENERAL_NAME_new();
104 if (!X509_NAME_set(&gen->d.directoryName, nm))
105 {
106 GENERAL_NAME_free(gen);
107 return 0;
108 }
109 gen->type = GEN_DIRNAME;
110 if (req->tbsRequest->requestorName)
111 GENERAL_NAME_free(req->tbsRequest->requestorName);
112 req->tbsRequest->requestorName = gen;
113 return 1;
114 }
115
116
117/* Add a certificate to an OCSP request */
118
119int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
120 {
121 OCSP_SIGNATURE *sig;
122 if (!req->optionalSignature)
123 req->optionalSignature = OCSP_SIGNATURE_new();
124 sig = req->optionalSignature;
125 if (!sig) return 0;
126 if (!cert) return 1;
127 if (!sig->certs && !(sig->certs = sk_X509_new_null()))
128 return 0;
129
130 if(!sk_X509_push(sig->certs, cert)) return 0;
131 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
132 return 1;
133 }
134
135/* Sign an OCSP request set the requestorName to the subjec
136 * name of an optional signers certificate and include one
137 * or more optional certificates in the request. Behaves
138 * like PKCS7_sign().
139 */
140
141int OCSP_request_sign(OCSP_REQUEST *req,
142 X509 *signer,
143 EVP_PKEY *key,
144 const EVP_MD *dgst,
145 STACK_OF(X509) *certs,
146 unsigned long flags)
147 {
148 int i;
149 OCSP_SIGNATURE *sig;
150 X509 *x;
151
152 if (!OCSP_request_set1_name(req, X509_get_subject_name(signer)))
153 goto err;
154
155 if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
156 if (!dgst) dgst = EVP_sha1();
157 if (key)
158 {
159 if (!X509_check_private_key(signer, key))
160 {
161 OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
162 goto err;
163 }
164 if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
165 }
166
167 if (!(flags & OCSP_NOCERTS))
168 {
169 if(!OCSP_request_add1_cert(req, signer)) goto err;
170 for (i = 0; i < sk_X509_num(certs); i++)
171 {
172 x = sk_X509_value(certs, i);
173 if (!OCSP_request_add1_cert(req, x)) goto err;
174 }
175 }
176
177 return 1;
178err:
179 OCSP_SIGNATURE_free(req->optionalSignature);
180 req->optionalSignature = NULL;
181 return 0;
182 }
183
184/* Get response status */
185
186int OCSP_response_status(OCSP_RESPONSE *resp)
187 {
188 return ASN1_ENUMERATED_get(resp->responseStatus);
189 }
190
191/* Extract basic response from OCSP_RESPONSE or NULL if
192 * no basic response present.
193 */
194
195
196OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp)
197 {
198 OCSP_RESPBYTES *rb;
199 rb = resp->responseBytes;
200 if (!rb)
201 {
202 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NO_RESPONSE_DATA);
203 return NULL;
204 }
205 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
206 {
207 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NOT_BASIC_RESPONSE);
208 return NULL;
209 }
210
211 return ASN1_item_unpack(rb->response, ASN1_ITEM_rptr(OCSP_BASICRESP));
212 }
213
214/* Return number of OCSP_SINGLERESP reponses present in
215 * a basic response.
216 */
217
218int OCSP_resp_count(OCSP_BASICRESP *bs)
219 {
220 if (!bs) return -1;
221 return sk_OCSP_SINGLERESP_num(bs->tbsResponseData->responses);
222 }
223
224/* Extract an OCSP_SINGLERESP response with a given index */
225
226OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx)
227 {
228 if (!bs) return NULL;
229 return sk_OCSP_SINGLERESP_value(bs->tbsResponseData->responses, idx);
230 }
231
232/* Look single response matching a given certificate ID */
233
234int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last)
235 {
236 int i;
237 STACK_OF(OCSP_SINGLERESP) *sresp;
238 OCSP_SINGLERESP *single;
239 if (!bs) return -1;
240 if (last < 0) last = 0;
241 else last++;
242 sresp = bs->tbsResponseData->responses;
243 for (i = last; i < sk_OCSP_SINGLERESP_num(sresp); i++)
244 {
245 single = sk_OCSP_SINGLERESP_value(sresp, i);
246 if (!OCSP_id_cmp(id, single->certId)) return i;
247 }
248 return -1;
249 }
250
251/* Extract status information from an OCSP_SINGLERESP structure.
252 * Note: the revtime and reason values are only set if the
253 * certificate status is revoked. Returns numerical value of
254 * status.
255 */
256
257int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
258 ASN1_GENERALIZEDTIME **revtime,
259 ASN1_GENERALIZEDTIME **thisupd,
260 ASN1_GENERALIZEDTIME **nextupd)
261 {
262 int ret;
263 OCSP_CERTSTATUS *cst;
264 if(!single) return -1;
265 cst = single->certStatus;
266 ret = cst->type;
267 if (ret == V_OCSP_CERTSTATUS_REVOKED)
268 {
269 OCSP_REVOKEDINFO *rev = cst->value.revoked;
270 if (revtime) *revtime = rev->revocationTime;
271 if (reason)
272 {
273 if(rev->revocationReason)
274 *reason = ASN1_ENUMERATED_get(rev->revocationReason);
275 else *reason = -1;
276 }
277 }
278 if(thisupd) *thisupd = single->thisUpdate;
279 if(nextupd) *nextupd = single->nextUpdate;
280 return ret;
281 }
282
283/* This function combines the previous ones: look up a certificate ID and
284 * if found extract status information. Return 0 is successful.
285 */
286
287int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
288 int *reason,
289 ASN1_GENERALIZEDTIME **revtime,
290 ASN1_GENERALIZEDTIME **thisupd,
291 ASN1_GENERALIZEDTIME **nextupd)
292 {
293 int i;
294 OCSP_SINGLERESP *single;
295 i = OCSP_resp_find(bs, id, -1);
296 /* Maybe check for multiple responses and give an error? */
297 if(i < 0) return 0;
298 single = OCSP_resp_get0(bs, i);
299 i = OCSP_single_get0_status(single, reason, revtime, thisupd, nextupd);
300 if(status) *status = i;
301 return 1;
302 }
303
304/* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
305 * take a few seconds to process and/or the time wont be totally accurate. Therefore to avoid
306 * rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
307 * Also to avoid accepting very old responses without a nextUpdate field an optional maxage
308 * parameter specifies the maximum age the thisUpdate field can be.
309 */
310
311int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
312 {
313 int ret = 1;
314 time_t t_now, t_tmp;
315 time(&t_now);
316 /* Check thisUpdate is valid and not more than nsec in the future */
317 if (!ASN1_GENERALIZEDTIME_check(thisupd))
318 {
319 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
320 ret = 0;
321 }
322 else
323 {
324 t_tmp = t_now + nsec;
325 if (X509_cmp_time(thisupd, &t_tmp) > 0)
326 {
327 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
328 ret = 0;
329 }
330
331 /* If maxsec specified check thisUpdate is not more than maxsec in the past */
332 if (maxsec >= 0)
333 {
334 t_tmp = t_now - maxsec;
335 if (X509_cmp_time(thisupd, &t_tmp) < 0)
336 {
337 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
338 ret = 0;
339 }
340 }
341 }
342
343
344 if (!nextupd) return ret;
345
346 /* Check nextUpdate is valid and not more than nsec in the past */
347 if (!ASN1_GENERALIZEDTIME_check(nextupd))
348 {
349 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
350 ret = 0;
351 }
352 else
353 {
354 t_tmp = t_now - nsec;
355 if (X509_cmp_time(nextupd, &t_tmp) < 0)
356 {
357 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
358 ret = 0;
359 }
360 }
361
362 /* Also don't allow nextUpdate to precede thisUpdate */
363 if (ASN1_STRING_cmp(nextupd, thisupd) < 0)
364 {
365 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
366 ret = 0;
367 }
368
369 return ret;
370 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_err.c b/src/lib/libssl/src/crypto/ocsp/ocsp_err.c
new file mode 100644
index 0000000000..4c4d8306f8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_err.c
@@ -0,0 +1,139 @@
1/* crypto/ocsp/ocsp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ocsp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA OCSP_str_functs[]=
68 {
69{ERR_PACK(0,OCSP_F_ASN1_STRING_ENCODE,0), "ASN1_STRING_encode"},
70{ERR_PACK(0,OCSP_F_CERT_ID_NEW,0), "CERT_ID_NEW"},
71{ERR_PACK(0,OCSP_F_D2I_OCSP_NONCE,0), "D2I_OCSP_NONCE"},
72{ERR_PACK(0,OCSP_F_OCSP_BASIC_ADD1_STATUS,0), "OCSP_basic_add1_status"},
73{ERR_PACK(0,OCSP_F_OCSP_BASIC_SIGN,0), "OCSP_basic_sign"},
74{ERR_PACK(0,OCSP_F_OCSP_BASIC_VERIFY,0), "OCSP_basic_verify"},
75{ERR_PACK(0,OCSP_F_OCSP_CHECK_DELEGATED,0), "OCSP_CHECK_DELEGATED"},
76{ERR_PACK(0,OCSP_F_OCSP_CHECK_IDS,0), "OCSP_CHECK_IDS"},
77{ERR_PACK(0,OCSP_F_OCSP_CHECK_ISSUER,0), "OCSP_CHECK_ISSUER"},
78{ERR_PACK(0,OCSP_F_OCSP_CHECK_VALIDITY,0), "OCSP_check_validity"},
79{ERR_PACK(0,OCSP_F_OCSP_MATCH_ISSUERID,0), "OCSP_MATCH_ISSUERID"},
80{ERR_PACK(0,OCSP_F_OCSP_PARSE_URL,0), "OCSP_parse_url"},
81{ERR_PACK(0,OCSP_F_OCSP_REQUEST_SIGN,0), "OCSP_request_sign"},
82{ERR_PACK(0,OCSP_F_OCSP_REQUEST_VERIFY,0), "OCSP_request_verify"},
83{ERR_PACK(0,OCSP_F_OCSP_RESPONSE_GET1_BASIC,0), "OCSP_response_get1_basic"},
84{ERR_PACK(0,OCSP_F_OCSP_SENDREQ_BIO,0), "OCSP_sendreq_bio"},
85{ERR_PACK(0,OCSP_F_REQUEST_VERIFY,0), "REQUEST_VERIFY"},
86{0,NULL}
87 };
88
89static ERR_STRING_DATA OCSP_str_reasons[]=
90 {
91{OCSP_R_BAD_DATA ,"bad data"},
92{OCSP_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"},
93{OCSP_R_DIGEST_ERR ,"digest err"},
94{OCSP_R_ERROR_IN_NEXTUPDATE_FIELD ,"error in nextupdate field"},
95{OCSP_R_ERROR_IN_THISUPDATE_FIELD ,"error in thisupdate field"},
96{OCSP_R_ERROR_PARSING_URL ,"error parsing url"},
97{OCSP_R_MISSING_OCSPSIGNING_USAGE ,"missing ocspsigning usage"},
98{OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE ,"nextupdate before thisupdate"},
99{OCSP_R_NOT_BASIC_RESPONSE ,"not basic response"},
100{OCSP_R_NO_CERTIFICATES_IN_CHAIN ,"no certificates in chain"},
101{OCSP_R_NO_CONTENT ,"no content"},
102{OCSP_R_NO_PUBLIC_KEY ,"no public key"},
103{OCSP_R_NO_RESPONSE_DATA ,"no response data"},
104{OCSP_R_NO_REVOKED_TIME ,"no revoked time"},
105{OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"},
106{OCSP_R_REQUEST_NOT_SIGNED ,"request not signed"},
107{OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA,"response contains no revocation data"},
108{OCSP_R_ROOT_CA_NOT_TRUSTED ,"root ca not trusted"},
109{OCSP_R_SERVER_READ_ERROR ,"server read error"},
110{OCSP_R_SERVER_RESPONSE_ERROR ,"server response error"},
111{OCSP_R_SERVER_RESPONSE_PARSE_ERROR ,"server response parse error"},
112{OCSP_R_SERVER_WRITE_ERROR ,"server write error"},
113{OCSP_R_SIGNATURE_FAILURE ,"signature failure"},
114{OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"},
115{OCSP_R_STATUS_EXPIRED ,"status expired"},
116{OCSP_R_STATUS_NOT_YET_VALID ,"status not yet valid"},
117{OCSP_R_STATUS_TOO_OLD ,"status too old"},
118{OCSP_R_UNKNOWN_MESSAGE_DIGEST ,"unknown message digest"},
119{OCSP_R_UNKNOWN_NID ,"unknown nid"},
120{OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE ,"unsupported requestorname type"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_OCSP_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
134 ERR_load_strings(ERR_LIB_OCSP,OCSP_str_functs);
135 ERR_load_strings(ERR_LIB_OCSP,OCSP_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c b/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c
new file mode 100644
index 0000000000..d6c8899f58
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c
@@ -0,0 +1,528 @@
1/* ocsp_ext.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/ocsp.h>
69#include <openssl/rand.h>
70#include <openssl/x509v3.h>
71
72/* Standard wrapper functions for extensions */
73
74/* OCSP request extensions */
75
76int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
77 {
78 return(X509v3_get_ext_count(x->tbsRequest->requestExtensions));
79 }
80
81int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
82 {
83 return(X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions,nid,lastpos));
84 }
85
86int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos)
87 {
88 return(X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions,obj,lastpos));
89 }
90
91int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
92 {
93 return(X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,crit,lastpos));
94 }
95
96X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
97 {
98 return(X509v3_get_ext(x->tbsRequest->requestExtensions,loc));
99 }
100
101X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
102 {
103 return(X509v3_delete_ext(x->tbsRequest->requestExtensions,loc));
104 }
105
106void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
107 {
108 return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx);
109 }
110
111int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
112 unsigned long flags)
113 {
114 return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value, crit, flags);
115 }
116
117int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
118 {
119 return(X509v3_add_ext(&(x->tbsRequest->requestExtensions),ex,loc) != NULL);
120 }
121
122/* Single extensions */
123
124int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
125 {
126 return(X509v3_get_ext_count(x->singleRequestExtensions));
127 }
128
129int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
130 {
131 return(X509v3_get_ext_by_NID(x->singleRequestExtensions,nid,lastpos));
132 }
133
134int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos)
135 {
136 return(X509v3_get_ext_by_OBJ(x->singleRequestExtensions,obj,lastpos));
137 }
138
139int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
140 {
141 return(X509v3_get_ext_by_critical(x->singleRequestExtensions,crit,lastpos));
142 }
143
144X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
145 {
146 return(X509v3_get_ext(x->singleRequestExtensions,loc));
147 }
148
149X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
150 {
151 return(X509v3_delete_ext(x->singleRequestExtensions,loc));
152 }
153
154void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
155 {
156 return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
157 }
158
159int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
160 unsigned long flags)
161 {
162 return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, flags);
163 }
164
165int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
166 {
167 return(X509v3_add_ext(&(x->singleRequestExtensions),ex,loc) != NULL);
168 }
169
170/* OCSP Basic response */
171
172int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
173 {
174 return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions));
175 }
176
177int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
178 {
179 return(X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,nid,lastpos));
180 }
181
182int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos)
183 {
184 return(X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,obj,lastpos));
185 }
186
187int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos)
188 {
189 return(X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,crit,lastpos));
190 }
191
192X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
193 {
194 return(X509v3_get_ext(x->tbsResponseData->responseExtensions,loc));
195 }
196
197X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
198 {
199 return(X509v3_delete_ext(x->tbsResponseData->responseExtensions,loc));
200 }
201
202void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx)
203 {
204 return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid, crit, idx);
205 }
206
207int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
208 unsigned long flags)
209 {
210 return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid, value, crit, flags);
211 }
212
213int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
214 {
215 return(X509v3_add_ext(&(x->tbsResponseData->responseExtensions),ex,loc) != NULL);
216 }
217
218/* OCSP single response extensions */
219
220int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
221 {
222 return(X509v3_get_ext_count(x->singleExtensions));
223 }
224
225int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
226 {
227 return(X509v3_get_ext_by_NID(x->singleExtensions,nid,lastpos));
228 }
229
230int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos)
231 {
232 return(X509v3_get_ext_by_OBJ(x->singleExtensions,obj,lastpos));
233 }
234
235int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos)
236 {
237 return(X509v3_get_ext_by_critical(x->singleExtensions,crit,lastpos));
238 }
239
240X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
241 {
242 return(X509v3_get_ext(x->singleExtensions,loc));
243 }
244
245X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
246 {
247 return(X509v3_delete_ext(x->singleExtensions,loc));
248 }
249
250void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx)
251 {
252 return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
253 }
254
255int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
256 unsigned long flags)
257 {
258 return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
259 }
260
261int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
262 {
263 return(X509v3_add_ext(&(x->singleExtensions),ex,loc) != NULL);
264 }
265
266/* also CRL Entry Extensions */
267
268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
269 char *data, STACK_OF(ASN1_OBJECT) *sk)
270 {
271 int i;
272 unsigned char *p, *b = NULL;
273
274 if (data)
275 {
276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
278 goto err;
279 if (i2d(data, &p) <= 0) goto err;
280 }
281 else if (sk)
282 {
283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,i2d,V_ASN1_SEQUENCE,
284 V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err;
285 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
286 goto err;
287 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,i2d,V_ASN1_SEQUENCE,
288 V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err;
289 }
290 else
291 {
292 OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA);
293 goto err;
294 }
295 if (!s && !(s = ASN1_STRING_new())) goto err;
296 if (!(ASN1_STRING_set(s, b, i))) goto err;
297 OPENSSL_free(b);
298 return s;
299err:
300 if (b) OPENSSL_free(b);
301 return NULL;
302 }
303
304/* Nonce handling functions */
305
306/* Add a nonce to an extension stack. A nonce can be specificed or if NULL
307 * a random nonce will be generated.
308 */
309
310static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len)
311 {
312 unsigned char *tmpval;
313 ASN1_OCTET_STRING os;
314 int ret = 0;
315 if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH;
316 if (val) tmpval = val;
317 else
318 {
319 if (!(tmpval = OPENSSL_malloc(len))) goto err;
320 RAND_pseudo_bytes(tmpval, len);
321 }
322 os.data = tmpval;
323 os.length = len;
324 if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
325 &os, 0, X509V3_ADD_REPLACE))
326 goto err;
327 ret = 1;
328 err:
329 if(!val) OPENSSL_free(tmpval);
330 return ret;
331 }
332
333
334/* Add nonce to an OCSP request */
335
336int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
337 {
338 return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len);
339 }
340
341/* Same as above but for a response */
342
343int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
344 {
345 return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val, len);
346 }
347
348/* Check nonce validity in a request and response.
349 * Return value reflects result:
350 * 1: nonces present and equal.
351 * 2: nonces both absent.
352 * 3: nonce present in response only.
353 * 0: nonces both present and not equal.
354 * -1: nonce in request only.
355 *
356 * For most responders clients can check return > 0.
357 * If responder doesn't handle nonces return != 0 may be
358 * necessary. return == 0 is always an error.
359 */
360
361int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
362 {
363 /*
364 * Since we are only interested in the presence or absence of
365 * the nonce and comparing its value there is no need to use
366 * the X509V3 routines: this way we can avoid them allocating an
367 * ASN1_OCTET_STRING structure for the value which would be
368 * freed immediately anyway.
369 */
370
371 int req_idx, resp_idx;
372 X509_EXTENSION *req_ext, *resp_ext;
373 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
374 resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
375 /* Check both absent */
376 if((req_idx < 0) && (resp_idx < 0))
377 return 2;
378 /* Check in request only */
379 if((req_idx >= 0) && (resp_idx < 0))
380 return -1;
381 /* Check in response but not request */
382 if((req_idx < 0) && (resp_idx >= 0))
383 return 3;
384 /* Otherwise nonce in request and response so retrieve the extensions */
385 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
386 resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
387 if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
388 return 0;
389 return 1;
390 }
391
392/* Copy the nonce value (if any) from an OCSP request to
393 * a response.
394 */
395
396int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
397 {
398 X509_EXTENSION *req_ext;
399 int req_idx;
400 /* Check for nonce in request */
401 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
402 /* If no nonce that's OK */
403 if (req_idx < 0) return 2;
404 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
405 return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
406 }
407
408X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
409 {
410 X509_EXTENSION *x = NULL;
411 OCSP_CRLID *cid = NULL;
412
413 if (!(cid = OCSP_CRLID_new())) goto err;
414 if (url)
415 {
416 if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err;
417 if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err;
418 }
419 if (n)
420 {
421 if (!(cid->crlNum = ASN1_INTEGER_new())) goto err;
422 if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err;
423 }
424 if (tim)
425 {
426 if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err;
427 if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim)))
428 goto err;
429 }
430 if (!(x = X509_EXTENSION_new())) goto err;
431 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
432 if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL)))
433 goto err;
434 OCSP_CRLID_free(cid);
435 return x;
436err:
437 if (x) X509_EXTENSION_free(x);
438 if (cid) OCSP_CRLID_free(cid);
439 return NULL;
440 }
441
442/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
443X509_EXTENSION *OCSP_accept_responses_new(char **oids)
444 {
445 int nid;
446 STACK_OF(ASN1_OBJECT) *sk = NULL;
447 ASN1_OBJECT *o = NULL;
448 X509_EXTENSION *x = NULL;
449
450 if (!(sk = sk_ASN1_OBJECT_new_null())) goto err;
451 while (oids && *oids)
452 {
453 if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid)))
454 sk_ASN1_OBJECT_push(sk, o);
455 oids++;
456 }
457 if (!(x = X509_EXTENSION_new())) goto err;
458 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
459 goto err;
460 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk)))
461 goto err;
462 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
463 return x;
464err:
465 if (x) X509_EXTENSION_free(x);
466 if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
467 return NULL;
468 }
469
470/* ArchiveCutoff ::= GeneralizedTime */
471X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
472 {
473 X509_EXTENSION *x=NULL;
474 ASN1_GENERALIZEDTIME *gt = NULL;
475
476 if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err;
477 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
478 if (!(x = X509_EXTENSION_new())) goto err;
479 if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
480 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME,
481 (char*)gt,NULL))) goto err;
482 ASN1_GENERALIZEDTIME_free(gt);
483 return x;
484err:
485 if (gt) ASN1_GENERALIZEDTIME_free(gt);
486 if (x) X509_EXTENSION_free(x);
487 return NULL;
488 }
489
490/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
491 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This
492 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
493 */
494X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
495 {
496 X509_EXTENSION *x = NULL;
497 ASN1_IA5STRING *ia5 = NULL;
498 OCSP_SERVICELOC *sloc = NULL;
499 ACCESS_DESCRIPTION *ad = NULL;
500
501 if (!(sloc = OCSP_SERVICELOC_new())) goto err;
502 if (!(sloc->issuer = X509_NAME_dup(issuer))) goto err;
503 if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null())) goto err;
504 while (urls && *urls)
505 {
506 if (!(ad = ACCESS_DESCRIPTION_new())) goto err;
507 if (!(ad->method=OBJ_nid2obj(NID_ad_OCSP))) goto err;
508 if (!(ad->location = GENERAL_NAME_new())) goto err;
509 if (!(ia5 = ASN1_IA5STRING_new())) goto err;
510 if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1)) goto err;
511 ad->location->type = GEN_URI;
512 ad->location->d.ia5 = ia5;
513 if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err;
514 urls++;
515 }
516 if (!(x = X509_EXTENSION_new())) goto err;
517 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator)))
518 goto err;
519 if (!(ASN1_STRING_encode(x->value, i2d_OCSP_SERVICELOC,
520 (char*)sloc, NULL))) goto err;
521 OCSP_SERVICELOC_free(sloc);
522 return x;
523err:
524 if (x) X509_EXTENSION_free(x);
525 if (sloc) OCSP_SERVICELOC_free(sloc);
526 return NULL;
527 }
528
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_ht.c b/src/lib/libssl/src/crypto/ocsp/ocsp_ht.c
new file mode 100644
index 0000000000..b78cd37092
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_ht.c
@@ -0,0 +1,164 @@
1/* ocsp_ht.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/asn1.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <ctype.h>
63#include <string.h>
64#include <openssl/ocsp.h>
65#include <openssl/err.h>
66#include <openssl/buffer.h>
67
68/* Quick and dirty HTTP OCSP request handler.
69 * Could make this a bit cleverer by adding
70 * support for non blocking BIOs and a few
71 * other refinements.
72 */
73
74OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
75{
76 BIO *mem = NULL;
77 char tmpbuf[1024];
78 OCSP_RESPONSE *resp = NULL;
79 char *p, *q, *r;
80 int len, retcode;
81 static char req_txt[] =
82"POST %s HTTP/1.0\r\n\
83Content-Type: application/ocsp-request\r\n\
84Content-Length: %d\r\n\r\n";
85
86 len = i2d_OCSP_REQUEST(req, NULL);
87 if(BIO_printf(b, req_txt, path, len) < 0) {
88 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
89 goto err;
90 }
91 if(i2d_OCSP_REQUEST_bio(b, req) <= 0) {
92 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
93 goto err;
94 }
95 if(!(mem = BIO_new(BIO_s_mem()))) goto err;
96 /* Copy response to a memory BIO: socket bios can't do gets! */
97 while ((len = BIO_read(b, tmpbuf, 1024))) {
98 if(len < 0) {
99 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR);
100 goto err;
101 }
102 BIO_write(mem, tmpbuf, len);
103 }
104 if(BIO_gets(mem, tmpbuf, 512) <= 0) {
105 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
106 goto err;
107 }
108 /* Parse the HTTP response. This will look like this:
109 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
110 * informational message.
111 */
112
113 /* Skip to first white space (passed protocol info) */
114 for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue;
115 if(!*p) {
116 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
117 goto err;
118 }
119 /* Skip past white space to start of response code */
120 while(*p && isspace((unsigned char)*p)) p++;
121 if(!*p) {
122 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
123 goto err;
124 }
125 /* Find end of response code: first whitespace after start of code */
126 for(q = p; *q && !isspace((unsigned char)*q); q++) continue;
127 if(!*q) {
128 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
129 goto err;
130 }
131 /* Set end of response code and start of message */
132 *q++ = 0;
133 /* Attempt to parse numeric code */
134 retcode = strtoul(p, &r, 10);
135 if(*r) goto err;
136 /* Skip over any leading white space in message */
137 while(*q && isspace((unsigned char)*q)) q++;
138 if(!*q) goto err;
139 /* Finally zap any trailing white space in message (include CRLF) */
140 /* We know q has a non white space character so this is OK */
141 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0;
142 if(retcode != 200) {
143 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR);
144 ERR_add_error_data(4, "Code=", p, ",Reason=", q);
145 goto err;
146 }
147 /* Find blank line marking beginning of content */
148 while(BIO_gets(mem, tmpbuf, 512) > 0)
149 {
150 for(p = tmpbuf; *p && isspace((unsigned char)*p); p++) continue;
151 if(!*p) break;
152 }
153 if(*p) {
154 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT);
155 goto err;
156 }
157 if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
158 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR);
159 goto err;
160 }
161 err:
162 BIO_free(mem);
163 return resp;
164}
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_lib.c b/src/lib/libssl/src/crypto/ocsp/ocsp_lib.c
new file mode 100644
index 0000000000..3875af165c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_lib.c
@@ -0,0 +1,261 @@
1/* ocsp_lib.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/rand.h>
68#include <openssl/x509.h>
69#include <openssl/pem.h>
70#include <openssl/x509v3.h>
71#include <openssl/ocsp.h>
72
73/* Convert a certificate and its issuer to an OCSP_CERTID */
74
75OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer)
76{
77 X509_NAME *iname;
78 ASN1_INTEGER *serial;
79 ASN1_BIT_STRING *ikey;
80#ifndef OPENSSL_NO_SHA1
81 if(!dgst) dgst = EVP_sha1();
82#endif
83 if (subject)
84 {
85 iname = X509_get_issuer_name(subject);
86 serial = X509_get_serialNumber(subject);
87 }
88 else
89 {
90 iname = X509_get_subject_name(issuer);
91 serial = NULL;
92 }
93 ikey = X509_get0_pubkey_bitstr(issuer);
94 return OCSP_cert_id_new(dgst, iname, ikey, serial);
95}
96
97
98OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
99 X509_NAME *issuerName,
100 ASN1_BIT_STRING* issuerKey,
101 ASN1_INTEGER *serialNumber)
102 {
103 int nid;
104 unsigned int i;
105 X509_ALGOR *alg;
106 OCSP_CERTID *cid = NULL;
107 unsigned char md[EVP_MAX_MD_SIZE];
108
109 if (!(cid = OCSP_CERTID_new())) goto err;
110
111 alg = cid->hashAlgorithm;
112 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm);
113 if ((nid = EVP_MD_type(dgst)) == NID_undef)
114 {
115 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_UNKNOWN_NID);
116 goto err;
117 }
118 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err;
119 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
120 alg->parameter->type=V_ASN1_NULL;
121
122 if (!X509_NAME_digest(issuerName, dgst, md, &i)) goto digerr;
123 if (!(ASN1_OCTET_STRING_set(cid->issuerNameHash, md, i))) goto err;
124
125 /* Calculate the issuerKey hash, excluding tag and length */
126 EVP_Digest(issuerKey->data, issuerKey->length, md, &i, dgst, NULL);
127
128 if (!(ASN1_OCTET_STRING_set(cid->issuerKeyHash, md, i))) goto err;
129
130 if (serialNumber)
131 {
132 ASN1_INTEGER_free(cid->serialNumber);
133 if (!(cid->serialNumber = ASN1_INTEGER_dup(serialNumber))) goto err;
134 }
135 return cid;
136digerr:
137 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_DIGEST_ERR);
138err:
139 if (cid) OCSP_CERTID_free(cid);
140 return NULL;
141 }
142
143int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
144 {
145 int ret;
146 ret = OBJ_cmp(a->hashAlgorithm->algorithm, b->hashAlgorithm->algorithm);
147 if (ret) return ret;
148 ret = ASN1_OCTET_STRING_cmp(a->issuerNameHash, b->issuerNameHash);
149 if (ret) return ret;
150 return ASN1_OCTET_STRING_cmp(a->issuerKeyHash, b->issuerKeyHash);
151 }
152
153int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
154 {
155 int ret;
156 ret = OCSP_id_issuer_cmp(a, b);
157 if (ret) return ret;
158 return ASN1_INTEGER_cmp(a->serialNumber, b->serialNumber);
159 }
160
161
162/* Parse a URL and split it up into host, port and path components and whether
163 * it is SSL.
164 */
165
166int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
167 {
168 char *p, *buf;
169
170 char *host, *port;
171
172 /* dup the buffer since we are going to mess with it */
173 buf = BUF_strdup(url);
174 if (!buf) goto mem_err;
175
176 *phost = NULL;
177 *pport = NULL;
178 *ppath = NULL;
179
180 /* Check for initial colon */
181 p = strchr(buf, ':');
182
183 if (!p) goto parse_err;
184
185 *(p++) = '\0';
186
187 if (!strcmp(buf, "http"))
188 {
189 *pssl = 0;
190 port = "80";
191 }
192 else if (!strcmp(buf, "https"))
193 {
194 *pssl = 1;
195 port = "443";
196 }
197 else
198 goto parse_err;
199
200 /* Check for double slash */
201 if ((p[0] != '/') || (p[1] != '/'))
202 goto parse_err;
203
204 p += 2;
205
206 host = p;
207
208 /* Check for trailing part of path */
209
210 p = strchr(p, '/');
211
212 if (!p)
213 *ppath = BUF_strdup("/");
214 else
215 {
216 *ppath = BUF_strdup(p);
217 /* Set start of path to 0 so hostname is valid */
218 *p = '\0';
219 }
220
221 if (!*ppath) goto mem_err;
222
223 /* Look for optional ':' for port number */
224 if ((p = strchr(host, ':')))
225 {
226 *p = 0;
227 port = p + 1;
228 }
229 else
230 {
231 /* Not found: set default port */
232 if (*pssl) port = "443";
233 else port = "80";
234 }
235
236 *pport = BUF_strdup(port);
237 if (!*pport) goto mem_err;
238
239 *phost = BUF_strdup(host);
240
241 if (!*phost) goto mem_err;
242
243 OPENSSL_free(buf);
244
245 return 1;
246
247 mem_err:
248 OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE);
249 goto err;
250
251 parse_err:
252 OCSPerr(OCSP_F_OCSP_PARSE_URL, OCSP_R_ERROR_PARSING_URL);
253
254
255 err:
256 if (*ppath) OPENSSL_free(*ppath);
257 if (*pport) OPENSSL_free(*pport);
258 if (*phost) OPENSSL_free(*phost);
259 return 0;
260
261 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_prn.c b/src/lib/libssl/src/crypto/ocsp/ocsp_prn.c
new file mode 100644
index 0000000000..4b7bc28769
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_prn.c
@@ -0,0 +1,291 @@
1/* ocsp_prn.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was originally part of ocsp.c and was transfered to Richard
7 Levitte from CertCo by Kathy Weinhold in mid-spring 2000 to be included
8 in OpenSSL or released as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <openssl/bio.h>
65#include <openssl/err.h>
66#include <openssl/ocsp.h>
67#include <openssl/pem.h>
68
69static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
70 {
71 BIO_printf(bp, "%*sCertificate ID:\n", indent, "");
72 indent += 2;
73 BIO_printf(bp, "%*sHash Algorithm: ", indent, "");
74 i2a_ASN1_OBJECT(bp, a->hashAlgorithm->algorithm);
75 BIO_printf(bp, "\n%*sIssuer Name Hash: ", indent, "");
76 i2a_ASN1_STRING(bp, a->issuerNameHash, V_ASN1_OCTET_STRING);
77 BIO_printf(bp, "\n%*sIssuer Key Hash: ", indent, "");
78 i2a_ASN1_STRING(bp, a->issuerKeyHash, V_ASN1_OCTET_STRING);
79 BIO_printf(bp, "\n%*sSerial Number: ", indent, "");
80 i2a_ASN1_INTEGER(bp, a->serialNumber);
81 BIO_printf(bp, "\n");
82 return 1;
83 }
84
85typedef struct
86 {
87 long t;
88 char *m;
89 } OCSP_TBLSTR;
90
91static char *table2string(long s, OCSP_TBLSTR *ts, int len)
92{
93 OCSP_TBLSTR *p;
94 for (p=ts; p < ts + len; p++)
95 if (p->t == s)
96 return p->m;
97 return "(UNKNOWN)";
98}
99
100char *OCSP_response_status_str(long s)
101 {
102 static OCSP_TBLSTR rstat_tbl[] = {
103 { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" },
104 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
105 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
106 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" },
107 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" },
108 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } };
109 return table2string(s, rstat_tbl, 6);
110 }
111
112char *OCSP_cert_status_str(long s)
113 {
114 static OCSP_TBLSTR cstat_tbl[] = {
115 { V_OCSP_CERTSTATUS_GOOD, "good" },
116 { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
117 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } };
118 return table2string(s, cstat_tbl, 3);
119 }
120
121char *OCSP_crl_reason_str(long s)
122 {
123 OCSP_TBLSTR reason_tbl[] = {
124 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
125 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
126 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
127 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
128 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
129 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },
130 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
131 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } };
132 return table2string(s, reason_tbl, 8);
133 }
134
135int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
136 {
137 int i;
138 long l;
139 OCSP_CERTID* cid = NULL;
140 OCSP_ONEREQ *one = NULL;
141 OCSP_REQINFO *inf = o->tbsRequest;
142 OCSP_SIGNATURE *sig = o->optionalSignature;
143
144 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
145 l=ASN1_INTEGER_get(inf->version);
146 if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0) goto err;
147 if (inf->requestorName != NULL)
148 {
149 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
150 goto err;
151 GENERAL_NAME_print(bp, inf->requestorName);
152 }
153 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err;
154 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
155 {
156 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
157 cid = one->reqCert;
158 ocsp_certid_print(bp, cid, 8);
159 if (!X509V3_extensions_print(bp,
160 "Request Single Extensions",
161 one->singleRequestExtensions, flags, 8))
162 goto err;
163 }
164 if (!X509V3_extensions_print(bp, "Request Extensions",
165 inf->requestExtensions, flags, 4))
166 goto err;
167 if (sig)
168 {
169 X509_signature_print(bp, sig->signatureAlgorithm, sig->signature);
170 for (i=0; i<sk_X509_num(sig->certs); i++)
171 {
172 X509_print(bp, sk_X509_value(sig->certs,i));
173 PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i));
174 }
175 }
176 return 1;
177err:
178 return 0;
179 }
180
181int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
182 {
183 int i, ret = 0;
184 long l;
185 unsigned char *p;
186 OCSP_CERTID *cid = NULL;
187 OCSP_BASICRESP *br = NULL;
188 OCSP_RESPID *rid = NULL;
189 OCSP_RESPDATA *rd = NULL;
190 OCSP_CERTSTATUS *cst = NULL;
191 OCSP_REVOKEDINFO *rev = NULL;
192 OCSP_SINGLERESP *single = NULL;
193 OCSP_RESPBYTES *rb = o->responseBytes;
194
195 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err;
196 l=ASN1_ENUMERATED_get(o->responseStatus);
197 if (BIO_printf(bp," OCSP Response Status: %s (0x%x)\n",
198 OCSP_response_status_str(l), l) <= 0) goto err;
199 if (rb == NULL) return 1;
200 if (BIO_puts(bp," Response Type: ") <= 0)
201 goto err;
202 if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0)
203 goto err;
204 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
205 {
206 BIO_puts(bp," (unknown response type)\n");
207 return 1;
208 }
209
210 p = ASN1_STRING_data(rb->response);
211 i = ASN1_STRING_length(rb->response);
212 if (!(br = OCSP_response_get1_basic(o))) goto err;
213 rd = br->tbsResponseData;
214 l=ASN1_INTEGER_get(rd->version);
215 if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n",
216 l+1,l) <= 0) goto err;
217 if (BIO_puts(bp," Responder Id: ") <= 0) goto err;
218
219 rid = rd->responderId;
220 switch (rid->type)
221 {
222 case V_OCSP_RESPID_NAME:
223 X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE);
224 break;
225 case V_OCSP_RESPID_KEY:
226 i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING);
227 break;
228 }
229
230 if (BIO_printf(bp,"\n Produced At: ")<=0) goto err;
231 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err;
232 if (BIO_printf(bp,"\n Responses:\n") <= 0) goto err;
233 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++)
234 {
235 if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue;
236 single = sk_OCSP_SINGLERESP_value(rd->responses, i);
237 cid = single->certId;
238 if(ocsp_certid_print(bp, cid, 4) <= 0) goto err;
239 cst = single->certStatus;
240 if (BIO_printf(bp," Cert Status: %s",
241 OCSP_cert_status_str(cst->type)) <= 0)
242 goto err;
243 if (cst->type == V_OCSP_CERTSTATUS_REVOKED)
244 {
245 rev = cst->value.revoked;
246 if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
247 goto err;
248 if (!ASN1_GENERALIZEDTIME_print(bp,
249 rev->revocationTime))
250 goto err;
251 if (rev->revocationReason)
252 {
253 l=ASN1_ENUMERATED_get(rev->revocationReason);
254 if (BIO_printf(bp,
255 "\n Revocation Reason: %s (0x%x)",
256 OCSP_crl_reason_str(l), l) <= 0)
257 goto err;
258 }
259 }
260 if (BIO_printf(bp,"\n This Update: ") <= 0) goto err;
261 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
262 goto err;
263 if (single->nextUpdate)
264 {
265 if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err;
266 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate))
267 goto err;
268 }
269 if (!BIO_write(bp,"\n",1)) goto err;
270 if (!X509V3_extensions_print(bp,
271 "Response Single Extensions",
272 single->singleExtensions, flags, 8))
273 goto err;
274 if (!BIO_write(bp,"\n",1)) goto err;
275 }
276 if (!X509V3_extensions_print(bp, "Response Extensions",
277 rd->responseExtensions, flags, 4))
278 if(X509_signature_print(bp, br->signatureAlgorithm, br->signature) <= 0)
279 goto err;
280
281 for (i=0; i<sk_X509_num(br->certs); i++)
282 {
283 X509_print(bp, sk_X509_value(br->certs,i));
284 PEM_write_bio_X509(bp,sk_X509_value(br->certs,i));
285 }
286
287 ret = 1;
288err:
289 OCSP_BASICRESP_free(br);
290 return ret;
291 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_srv.c b/src/lib/libssl/src/crypto/ocsp/ocsp_srv.c
new file mode 100644
index 0000000000..fffa134e75
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_srv.c
@@ -0,0 +1,264 @@
1/* ocsp_srv.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <cryptlib.h>
61#include <openssl/objects.h>
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64#include <openssl/pem.h>
65#include <openssl/x509v3.h>
66#include <openssl/ocsp.h>
67
68/* Utility functions related to sending OCSP responses and extracting
69 * relevant information from the request.
70 */
71
72int OCSP_request_onereq_count(OCSP_REQUEST *req)
73 {
74 return sk_OCSP_ONEREQ_num(req->tbsRequest->requestList);
75 }
76
77OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i)
78 {
79 return sk_OCSP_ONEREQ_value(req->tbsRequest->requestList, i);
80 }
81
82OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one)
83 {
84 return one->reqCert;
85 }
86
87int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
88 ASN1_OCTET_STRING **pikeyHash,
89 ASN1_INTEGER **pserial, OCSP_CERTID *cid)
90 {
91 if (!cid) return 0;
92 if (pmd) *pmd = cid->hashAlgorithm->algorithm;
93 if(piNameHash) *piNameHash = cid->issuerNameHash;
94 if (pikeyHash) *pikeyHash = cid->issuerKeyHash;
95 if (pserial) *pserial = cid->serialNumber;
96 return 1;
97 }
98
99int OCSP_request_is_signed(OCSP_REQUEST *req)
100 {
101 if(req->optionalSignature) return 1;
102 return 0;
103 }
104
105/* Create an OCSP response and encode an optional basic response */
106OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs)
107 {
108 OCSP_RESPONSE *rsp = NULL;
109
110 if (!(rsp = OCSP_RESPONSE_new())) goto err;
111 if (!(ASN1_ENUMERATED_set(rsp->responseStatus, status))) goto err;
112 if (!bs) return rsp;
113 if (!(rsp->responseBytes = OCSP_RESPBYTES_new())) goto err;
114 rsp->responseBytes->responseType = OBJ_nid2obj(NID_id_pkix_OCSP_basic);
115 if (!ASN1_item_pack(bs, ASN1_ITEM_rptr(OCSP_BASICRESP), &rsp->responseBytes->response))
116 goto err;
117 return rsp;
118err:
119 if (rsp) OCSP_RESPONSE_free(rsp);
120 return NULL;
121 }
122
123
124OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
125 OCSP_CERTID *cid,
126 int status, int reason,
127 ASN1_TIME *revtime,
128 ASN1_TIME *thisupd, ASN1_TIME *nextupd)
129 {
130 OCSP_SINGLERESP *single = NULL;
131 OCSP_CERTSTATUS *cs;
132 OCSP_REVOKEDINFO *ri;
133
134 if(!rsp->tbsResponseData->responses &&
135 !(rsp->tbsResponseData->responses = sk_OCSP_SINGLERESP_new_null()))
136 goto err;
137
138 if (!(single = OCSP_SINGLERESP_new()))
139 goto err;
140
141
142
143 if (!ASN1_TIME_to_generalizedtime(thisupd, &single->thisUpdate))
144 goto err;
145 if (nextupd &&
146 !ASN1_TIME_to_generalizedtime(nextupd, &single->nextUpdate))
147 goto err;
148
149 OCSP_CERTID_free(single->certId);
150
151 if(!(single->certId = OCSP_CERTID_dup(cid)))
152 goto err;
153
154 cs = single->certStatus;
155 switch(cs->type = status)
156 {
157 case V_OCSP_CERTSTATUS_REVOKED:
158 if (!revtime)
159 {
160 OCSPerr(OCSP_F_OCSP_BASIC_ADD1_STATUS,OCSP_R_NO_REVOKED_TIME);
161 goto err;
162 }
163 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
164 if (!ASN1_TIME_to_generalizedtime(revtime, &ri->revocationTime))
165 goto err;
166 if (reason != OCSP_REVOKED_STATUS_NOSTATUS)
167 {
168 if (!(ri->revocationReason = ASN1_ENUMERATED_new()))
169 goto err;
170 if (!(ASN1_ENUMERATED_set(ri->revocationReason,
171 reason)))
172 goto err;
173 }
174 break;
175
176 case V_OCSP_CERTSTATUS_GOOD:
177 cs->value.good = ASN1_NULL_new();
178 break;
179
180 case V_OCSP_CERTSTATUS_UNKNOWN:
181 cs->value.unknown = ASN1_NULL_new();
182 break;
183
184 default:
185 goto err;
186
187 }
188 if (!(sk_OCSP_SINGLERESP_push(rsp->tbsResponseData->responses, single)))
189 goto err;
190 return single;
191err:
192 OCSP_SINGLERESP_free(single);
193 return NULL;
194 }
195
196/* Add a certificate to an OCSP request */
197
198int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert)
199 {
200 if (!resp->certs && !(resp->certs = sk_X509_new_null()))
201 return 0;
202
203 if(!sk_X509_push(resp->certs, cert)) return 0;
204 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
205 return 1;
206 }
207
208int OCSP_basic_sign(OCSP_BASICRESP *brsp,
209 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
210 STACK_OF(X509) *certs, unsigned long flags)
211 {
212 int i;
213 OCSP_RESPID *rid;
214
215 if (!X509_check_private_key(signer, key))
216 {
217 OCSPerr(OCSP_F_OCSP_BASIC_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
218 goto err;
219 }
220
221 if(!(flags & OCSP_NOCERTS))
222 {
223 if(!OCSP_basic_add1_cert(brsp, signer))
224 goto err;
225 for (i = 0; i < sk_X509_num(certs); i++)
226 {
227 X509 *tmpcert = sk_X509_value(certs, i);
228 if(!OCSP_basic_add1_cert(brsp, tmpcert))
229 goto err;
230 }
231 }
232
233 rid = brsp->tbsResponseData->responderId;
234 if (flags & OCSP_RESPID_KEY)
235 {
236 unsigned char md[SHA_DIGEST_LENGTH];
237 X509_pubkey_digest(signer, EVP_sha1(), md, NULL);
238 if (!(rid->value.byKey = ASN1_OCTET_STRING_new()))
239 goto err;
240 if (!(ASN1_OCTET_STRING_set(rid->value.byKey, md, SHA_DIGEST_LENGTH)))
241 goto err;
242 rid->type = V_OCSP_RESPID_KEY;
243 }
244 else
245 {
246 if (!X509_NAME_set(&rid->value.byName,
247 X509_get_subject_name(signer)))
248 goto err;
249 rid->type = V_OCSP_RESPID_NAME;
250 }
251
252 if (!(flags & OCSP_NOTIME) &&
253 !X509_gmtime_adj(brsp->tbsResponseData->producedAt, 0))
254 goto err;
255
256 /* Right now, I think that not doing double hashing is the right
257 thing. -- Richard Levitte */
258
259 if (!OCSP_BASICRESP_sign(brsp, key, dgst, 0)) goto err;
260
261 return 1;
262err:
263 return 0;
264 }
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_vfy.c b/src/lib/libssl/src/crypto/ocsp/ocsp_vfy.c
new file mode 100644
index 0000000000..1f5fda7ca3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ocsp/ocsp_vfy.c
@@ -0,0 +1,444 @@
1/* ocsp_vfy.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/ocsp.h>
60#include <openssl/err.h>
61#include <string.h>
62
63static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
64 X509_STORE *st, unsigned long flags);
65static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id);
66static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags);
67static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret);
68static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid, STACK_OF(OCSP_SINGLERESP) *sresp);
69static int ocsp_check_delegated(X509 *x, int flags);
70static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
71 X509_STORE *st, unsigned long flags);
72
73/* Verify a basic response message */
74
75int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
76 X509_STORE *st, unsigned long flags)
77 {
78 X509 *signer, *x;
79 STACK_OF(X509) *chain = NULL;
80 X509_STORE_CTX ctx;
81 int i, ret = 0;
82 ret = ocsp_find_signer(&signer, bs, certs, st, flags);
83 if (!ret)
84 {
85 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
86 goto end;
87 }
88 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
89 flags |= OCSP_NOVERIFY;
90 if (!(flags & OCSP_NOSIGS))
91 {
92 EVP_PKEY *skey;
93 skey = X509_get_pubkey(signer);
94 ret = OCSP_BASICRESP_verify(bs, skey, 0);
95 EVP_PKEY_free(skey);
96 if(ret <= 0)
97 {
98 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNATURE_FAILURE);
99 goto end;
100 }
101 }
102 if (!(flags & OCSP_NOVERIFY))
103 {
104 int init_res;
105 if(flags & OCSP_NOCHAIN)
106 init_res = X509_STORE_CTX_init(&ctx, st, signer, NULL);
107 else
108 init_res = X509_STORE_CTX_init(&ctx, st, signer, bs->certs);
109 if(!init_res)
110 {
111 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,ERR_R_X509_LIB);
112 goto end;
113 }
114
115 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
116 ret = X509_verify_cert(&ctx);
117 chain = X509_STORE_CTX_get1_chain(&ctx);
118 X509_STORE_CTX_cleanup(&ctx);
119 if (ret <= 0)
120 {
121 i = X509_STORE_CTX_get_error(&ctx);
122 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
123 ERR_add_error_data(2, "Verify error:",
124 X509_verify_cert_error_string(i));
125 goto end;
126 }
127 if(flags & OCSP_NOCHECKS)
128 {
129 ret = 1;
130 goto end;
131 }
132 /* At this point we have a valid certificate chain
133 * need to verify it against the OCSP issuer criteria.
134 */
135 ret = ocsp_check_issuer(bs, chain, flags);
136
137 /* If fatal error or valid match then finish */
138 if (ret != 0) goto end;
139
140 /* Easy case: explicitly trusted. Get root CA and
141 * check for explicit trust
142 */
143 if(flags & OCSP_NOEXPLICIT) goto end;
144
145 x = sk_X509_value(chain, sk_X509_num(chain) - 1);
146 if(X509_check_trust(x, NID_OCSP_sign, 0) != X509_TRUST_TRUSTED)
147 {
148 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_ROOT_CA_NOT_TRUSTED);
149 goto end;
150 }
151 ret = 1;
152 }
153
154
155
156 end:
157 if(chain) sk_X509_pop_free(chain, X509_free);
158 return ret;
159 }
160
161
162static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
163 X509_STORE *st, unsigned long flags)
164 {
165 X509 *signer;
166 OCSP_RESPID *rid = bs->tbsResponseData->responderId;
167 if ((signer = ocsp_find_signer_sk(certs, rid)))
168 {
169 *psigner = signer;
170 return 2;
171 }
172 if(!(flags & OCSP_NOINTERN) &&
173 (signer = ocsp_find_signer_sk(bs->certs, rid)))
174 {
175 *psigner = signer;
176 return 1;
177 }
178 /* Maybe lookup from store if by subject name */
179
180 *psigner = NULL;
181 return 0;
182 }
183
184
185static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id)
186 {
187 int i;
188 unsigned char tmphash[SHA_DIGEST_LENGTH], *keyhash;
189 X509 *x;
190
191 /* Easy if lookup by name */
192 if (id->type == V_OCSP_RESPID_NAME)
193 return X509_find_by_subject(certs, id->value.byName);
194
195 /* Lookup by key hash */
196
197 /* If key hash isn't SHA1 length then forget it */
198 if (id->value.byKey->length != SHA_DIGEST_LENGTH) return NULL;
199 keyhash = id->value.byKey->data;
200 /* Calculate hash of each key and compare */
201 for (i = 0; i < sk_X509_num(certs); i++)
202 {
203 x = sk_X509_value(certs, i);
204 X509_pubkey_digest(x, EVP_sha1(), tmphash, NULL);
205 if(!memcmp(keyhash, tmphash, SHA_DIGEST_LENGTH))
206 return x;
207 }
208 return NULL;
209 }
210
211
212static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags)
213 {
214 STACK_OF(OCSP_SINGLERESP) *sresp;
215 X509 *signer, *sca;
216 OCSP_CERTID *caid = NULL;
217 int i;
218 sresp = bs->tbsResponseData->responses;
219
220 if (sk_X509_num(chain) <= 0)
221 {
222 OCSPerr(OCSP_F_OCSP_CHECK_ISSUER, OCSP_R_NO_CERTIFICATES_IN_CHAIN);
223 return -1;
224 }
225
226 /* See if the issuer IDs match. */
227 i = ocsp_check_ids(sresp, &caid);
228
229 /* If ID mismatch or other error then return */
230 if (i <= 0) return i;
231
232 signer = sk_X509_value(chain, 0);
233 /* Check to see if OCSP responder CA matches request CA */
234 if (sk_X509_num(chain) > 1)
235 {
236 sca = sk_X509_value(chain, 1);
237 i = ocsp_match_issuerid(sca, caid, sresp);
238 if (i < 0) return i;
239 if (i)
240 {
241 /* We have a match, if extensions OK then success */
242 if (ocsp_check_delegated(signer, flags)) return 1;
243 return 0;
244 }
245 }
246
247 /* Otherwise check if OCSP request signed directly by request CA */
248 return ocsp_match_issuerid(signer, caid, sresp);
249 }
250
251
252/* Check the issuer certificate IDs for equality. If there is a mismatch with the same
253 * algorithm then there's no point trying to match any certificates against the issuer.
254 * If the issuer IDs all match then we just need to check equality against one of them.
255 */
256
257static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret)
258 {
259 OCSP_CERTID *tmpid, *cid;
260 int i, idcount;
261
262 idcount = sk_OCSP_SINGLERESP_num(sresp);
263 if (idcount <= 0)
264 {
265 OCSPerr(OCSP_F_OCSP_CHECK_IDS, OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
266 return -1;
267 }
268
269 cid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
270
271 *ret = NULL;
272
273 for (i = 1; i < idcount; i++)
274 {
275 tmpid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
276 /* Check to see if IDs match */
277 if (OCSP_id_issuer_cmp(cid, tmpid))
278 {
279 /* If algoritm mismatch let caller deal with it */
280 if (OBJ_cmp(tmpid->hashAlgorithm->algorithm,
281 cid->hashAlgorithm->algorithm))
282 return 2;
283 /* Else mismatch */
284 return 0;
285 }
286 }
287
288 /* All IDs match: only need to check one ID */
289 *ret = cid;
290 return 1;
291 }
292
293
294static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
295 STACK_OF(OCSP_SINGLERESP) *sresp)
296 {
297 /* If only one ID to match then do it */
298 if(cid)
299 {
300 const EVP_MD *dgst;
301 X509_NAME *iname;
302 int mdlen;
303 unsigned char md[EVP_MAX_MD_SIZE];
304 if (!(dgst = EVP_get_digestbyobj(cid->hashAlgorithm->algorithm)))
305 {
306 OCSPerr(OCSP_F_OCSP_MATCH_ISSUERID, OCSP_R_UNKNOWN_MESSAGE_DIGEST);
307 return -1;
308 }
309
310 mdlen = EVP_MD_size(dgst);
311 if ((cid->issuerNameHash->length != mdlen) ||
312 (cid->issuerKeyHash->length != mdlen))
313 return 0;
314 iname = X509_get_subject_name(cert);
315 if (!X509_NAME_digest(iname, dgst, md, NULL))
316 return -1;
317 if (memcmp(md, cid->issuerNameHash->data, mdlen))
318 return 0;
319 X509_pubkey_digest(cert, EVP_sha1(), md, NULL);
320 if (memcmp(md, cid->issuerKeyHash->data, mdlen))
321 return 0;
322
323 return 1;
324
325 }
326 else
327 {
328 /* We have to match the whole lot */
329 int i, ret;
330 OCSP_CERTID *tmpid;
331 for (i = 0; i < sk_OCSP_SINGLERESP_num(sresp); i++)
332 {
333 tmpid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
334 ret = ocsp_match_issuerid(cert, tmpid, NULL);
335 if (ret <= 0) return ret;
336 }
337 return 1;
338 }
339
340 }
341
342static int ocsp_check_delegated(X509 *x, int flags)
343 {
344 X509_check_purpose(x, -1, 0);
345 if ((x->ex_flags & EXFLAG_XKUSAGE) &&
346 (x->ex_xkusage & XKU_OCSP_SIGN))
347 return 1;
348 OCSPerr(OCSP_F_OCSP_CHECK_DELEGATED, OCSP_R_MISSING_OCSPSIGNING_USAGE);
349 return 0;
350 }
351
352/* Verify an OCSP request. This is fortunately much easier than OCSP
353 * response verify. Just find the signers certificate and verify it
354 * against a given trust value.
355 */
356
357int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags)
358 {
359 X509 *signer;
360 X509_NAME *nm;
361 GENERAL_NAME *gen;
362 int ret;
363 X509_STORE_CTX ctx;
364 if (!req->optionalSignature)
365 {
366 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_REQUEST_NOT_SIGNED);
367 return 0;
368 }
369 gen = req->tbsRequest->requestorName;
370 if (gen->type != GEN_DIRNAME)
371 {
372 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
373 return 0;
374 }
375 nm = gen->d.directoryName;
376 ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags);
377 if (ret <= 0)
378 {
379 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
380 return 0;
381 }
382 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
383 flags |= OCSP_NOVERIFY;
384 if (!(flags & OCSP_NOSIGS))
385 {
386 EVP_PKEY *skey;
387 skey = X509_get_pubkey(signer);
388 ret = OCSP_REQUEST_verify(req, skey);
389 EVP_PKEY_free(skey);
390 if(ret <= 0)
391 {
392 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNATURE_FAILURE);
393 return 0;
394 }
395 }
396 if (!(flags & OCSP_NOVERIFY))
397 {
398 int init_res;
399 if(flags & OCSP_NOCHAIN)
400 init_res = X509_STORE_CTX_init(&ctx, store, signer, NULL);
401 else
402 init_res = X509_STORE_CTX_init(&ctx, store, signer,
403 req->optionalSignature->certs);
404 if(!init_res)
405 {
406 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,ERR_R_X509_LIB);
407 return 0;
408 }
409
410 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
411 X509_STORE_CTX_set_trust(&ctx, X509_TRUST_OCSP_REQUEST);
412 ret = X509_verify_cert(&ctx);
413 X509_STORE_CTX_cleanup(&ctx);
414 if (ret <= 0)
415 {
416 ret = X509_STORE_CTX_get_error(&ctx);
417 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
418 ERR_add_error_data(2, "Verify error:",
419 X509_verify_cert_error_string(ret));
420 return 0;
421 }
422 }
423 return 1;
424 }
425
426static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
427 X509_STORE *st, unsigned long flags)
428 {
429 X509 *signer;
430 if(!(flags & OCSP_NOINTERN))
431 {
432 signer = X509_find_by_subject(req->optionalSignature->certs, nm);
433 *psigner = signer;
434 return 1;
435 }
436
437 signer = X509_find_by_subject(certs, nm);
438 if (signer)
439 {
440 *psigner = signer;
441 return 2;
442 }
443 return 0;
444 }
diff --git a/src/lib/libssl/src/crypto/opensslconf.h.in b/src/lib/libssl/src/crypto/opensslconf.h.in
new file mode 100644
index 0000000000..e4a8f8ad54
--- /dev/null
+++ b/src/lib/libssl/src/crypto/opensslconf.h.in
@@ -0,0 +1,142 @@
1/* crypto/opensslconf.h */
2/* WARNING: This file is autogenerated by Configure */
3
4/* Generate 80386 code? */
5#undef I386_ONLY
6
7#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
8#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
9#define OPENSSLDIR "/usr/local/ssl"
10#endif
11#endif
12
13#define OPENSSL_UNISTD <unistd.h>
14
15#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
16#define IDEA_INT unsigned int
17#endif
18
19#if defined(HEADER_MD2_H) && !defined(MD2_INT)
20#define MD2_INT unsigned int
21#endif
22
23#if defined(HEADER_RC2_H) && !defined(RC2_INT)
24/* I need to put in a mod for the alpha - eay */
25#define RC2_INT unsigned int
26#endif
27
28#if defined(HEADER_RC4_H) && !defined(RC4_INT)
29/* using int types make the structure larger but make the code faster
30 * on most boxes I have tested - up to %20 faster. */
31#define RC4_INT unsigned int
32#endif
33
34#if defined(HEADER_DES_H) && !defined(DES_LONG)
35/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
36 * %20 speed up (longs are 8 bytes, int's are 4). */
37#ifndef DES_LONG
38#define DES_LONG unsigned long
39#endif
40#endif
41
42#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
43#define CONFIG_HEADER_BN_H
44#undef BN_LLONG
45
46/* Should we define BN_DIV2W here? */
47
48/* Only one for the following should be defined */
49/* The prime number generation stuff may not work when
50 * EIGHT_BIT but I don't care since I've only used this mode
51 * for debuging the bignum libraries */
52#undef SIXTY_FOUR_BIT_LONG
53#undef SIXTY_FOUR_BIT
54#define THIRTY_TWO_BIT
55#undef SIXTEEN_BIT
56#undef EIGHT_BIT
57#endif
58
59#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
60#define CONFIG_HEADER_RC4_LOCL_H
61/* if this is defined data[i] is used instead of *data, this is a %20
62 * speedup on x86 */
63#undef RC4_INDEX
64#endif
65
66#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
67#define CONFIG_HEADER_BF_LOCL_H
68#undef BF_PTR
69#endif /* HEADER_BF_LOCL_H */
70
71#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
72#define CONFIG_HEADER_DES_LOCL_H
73#ifndef DES_DEFAULT_OPTIONS
74/* the following is tweaked from a config script, that is why it is a
75 * protected undef/define */
76#ifndef DES_PTR
77#undef DES_PTR
78#endif
79
80/* This helps C compiler generate the correct code for multiple functional
81 * units. It reduces register dependancies at the expense of 2 more
82 * registers */
83#ifndef DES_RISC1
84#undef DES_RISC1
85#endif
86
87#ifndef DES_RISC2
88#undef DES_RISC2
89#endif
90
91#if defined(DES_RISC1) && defined(DES_RISC2)
92YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
93#endif
94
95/* Unroll the inner loop, this sometimes helps, sometimes hinders.
96 * Very mucy CPU dependant */
97#ifndef DES_UNROLL
98#undef DES_UNROLL
99#endif
100
101/* These default values were supplied by
102 * Peter Gutman <pgut001@cs.auckland.ac.nz>
103 * They are only used if nothing else has been defined */
104#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
105/* Special defines which change the way the code is built depending on the
106 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
107 even newer MIPS CPU's, but at the moment one size fits all for
108 optimization options. Older Sparc's work better with only UNROLL, but
109 there's no way to tell at compile time what it is you're running on */
110
111#if defined( sun ) /* Newer Sparc's */
112# define DES_PTR
113# define DES_RISC1
114# define DES_UNROLL
115#elif defined( __ultrix ) /* Older MIPS */
116# define DES_PTR
117# define DES_RISC2
118# define DES_UNROLL
119#elif defined( __osf1__ ) /* Alpha */
120# define DES_PTR
121# define DES_RISC2
122#elif defined ( _AIX ) /* RS6000 */
123 /* Unknown */
124#elif defined( __hpux ) /* HP-PA */
125 /* Unknown */
126#elif defined( __aux ) /* 68K */
127 /* Unknown */
128#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
129# define DES_UNROLL
130#elif defined( __sgi ) /* Newer MIPS */
131# define DES_PTR
132# define DES_RISC2
133# define DES_UNROLL
134#elif defined( i386 ) /* x86 boxes, should be gcc */
135# define DES_PTR
136# define DES_RISC1
137# define DES_UNROLL
138#endif /* Systems-specific speed defines */
139#endif
140
141#endif /* DES_DEFAULT_OPTIONS */
142#endif /* HEADER_DES_LOCL_H */
diff --git a/src/lib/libssl/src/crypto/opensslv.h b/src/lib/libssl/src/crypto/opensslv.h
new file mode 100644
index 0000000000..b841347f05
--- /dev/null
+++ b/src/lib/libssl/src/crypto/opensslv.h
@@ -0,0 +1,21 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MMNNFFRBB: major minor fix final beta/patch
6 * For example:
7 * 0.9.3-dev 0x00903000
8 * 0.9.3beta1 0x00903001
9 * 0.9.3beta2-dev 0x00903002
10 * 0.9.3beta2 0x00903002
11 * 0.9.3 0x00903100
12 * 0.9.3a 0x00903101
13 * 0.9.4 0x00904100
14 * 1.2.3z 0x1020311a
15 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
16 */
17#define OPENSSL_VERSION_NUMBER 0x00904100L
18#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.4 09 Aug 1999"
19#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
20
21#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libssl/src/crypto/ossl_typ.h b/src/lib/libssl/src/crypto/ossl_typ.h
new file mode 100644
index 0000000000..6bd42aee4d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ossl_typ.h
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_OPENSSL_TYPES_H
56#define HEADER_OPENSSL_TYPES_H
57
58#ifdef NO_ASN1_TYPEDEFS
59#define ASN1_INTEGER ASN1_STRING
60#define ASN1_ENUMERATED ASN1_STRING
61#define ASN1_BIT_STRING ASN1_STRING
62#define ASN1_OCTET_STRING ASN1_STRING
63#define ASN1_PRINTABLESTRING ASN1_STRING
64#define ASN1_T61STRING ASN1_STRING
65#define ASN1_IA5STRING ASN1_STRING
66#define ASN1_UTCTIME ASN1_STRING
67#define ASN1_GENERALIZEDTIME ASN1_STRING
68#define ASN1_TIME ASN1_STRING
69#define ASN1_GENERALSTRING ASN1_STRING
70#define ASN1_UNIVERSALSTRING ASN1_STRING
71#define ASN1_BMPSTRING ASN1_STRING
72#define ASN1_VISIBLESTRING ASN1_STRING
73#define ASN1_UTF8STRING ASN1_STRING
74#define ASN1_BOOLEAN int
75#define ASN1_NULL int
76#else
77typedef struct asn1_string_st ASN1_INTEGER;
78typedef struct asn1_string_st ASN1_ENUMERATED;
79typedef struct asn1_string_st ASN1_BIT_STRING;
80typedef struct asn1_string_st ASN1_OCTET_STRING;
81typedef struct asn1_string_st ASN1_PRINTABLESTRING;
82typedef struct asn1_string_st ASN1_T61STRING;
83typedef struct asn1_string_st ASN1_IA5STRING;
84typedef struct asn1_string_st ASN1_GENERALSTRING;
85typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
86typedef struct asn1_string_st ASN1_BMPSTRING;
87typedef struct asn1_string_st ASN1_UTCTIME;
88typedef struct asn1_string_st ASN1_TIME;
89typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
90typedef struct asn1_string_st ASN1_VISIBLESTRING;
91typedef struct asn1_string_st ASN1_UTF8STRING;
92typedef int ASN1_BOOLEAN;
93typedef int ASN1_NULL;
94#endif
95
96#ifdef OPENSSL_SYS_WIN32
97#undef X509_NAME
98#undef PKCS7_ISSUER_AND_SERIAL
99#endif
100
101typedef struct evp_cipher_st EVP_CIPHER;
102typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
103typedef struct env_md_st EVP_MD;
104typedef struct env_md_ctx_st EVP_MD_CTX;
105typedef struct evp_pkey_st EVP_PKEY;
106
107typedef struct x509_st X509;
108typedef struct X509_algor_st X509_ALGOR;
109typedef struct X509_crl_st X509_CRL;
110typedef struct X509_name_st X509_NAME;
111typedef struct x509_store_st X509_STORE;
112typedef struct x509_store_ctx_st X509_STORE_CTX;
113
114typedef struct engine_st ENGINE;
115
116 /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
117#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */
118#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */
119
120#endif /* def HEADER_OPENSSL_TYPES_H */
diff --git a/src/lib/libssl/src/crypto/pem/pem2.h b/src/lib/libssl/src/crypto/pem/pem2.h
new file mode 100644
index 0000000000..4a016aacd2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem2.h
@@ -0,0 +1,60 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60void ERR_load_PEM_strings(void);
diff --git a/src/lib/libssl/src/crypto/pem/pem_oth.c b/src/lib/libssl/src/crypto/pem/pem_oth.c
new file mode 100644
index 0000000000..8d9064ea7c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_oth.c
@@ -0,0 +1,85 @@
1/* crypto/pem/pem_oth.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68/* Handle 'other' PEMs: not private keys */
69
70char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
71 pem_password_cb *cb, void *u)
72 {
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 char *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
78 return NULL;
79 p = data;
80 ret=d2i(x,&p,len);
81 if (ret == NULL)
82 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
83 OPENSSL_free(data);
84 return(ret);
85 }
diff --git a/src/lib/libssl/src/crypto/pem/pem_pk8.c b/src/lib/libssl/src/crypto/pem/pem_pk8.c
new file mode 100644
index 0000000000..f44182ffb5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_pk8.c
@@ -0,0 +1,243 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
70 int nid, const EVP_CIPHER *enc,
71 char *kstr, int klen,
72 pem_password_cb *cb, void *u);
73static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
74 int nid, const EVP_CIPHER *enc,
75 char *kstr, int klen,
76 pem_password_cb *cb, void *u);
77
78/* These functions write a private key in PKCS#8 format: it is a "drop in"
79 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
80 * is NULL then it uses the unencrypted private key form. The 'nid' versions
81 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
82 */
83
84int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u)
87{
88 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
89}
90
91int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
92 char *kstr, int klen,
93 pem_password_cb *cb, void *u)
94{
95 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
96}
97
98int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
99 char *kstr, int klen,
100 pem_password_cb *cb, void *u)
101{
102 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
103}
104
105int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
106 char *kstr, int klen,
107 pem_password_cb *cb, void *u)
108{
109 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
110}
111
112static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
113 char *kstr, int klen,
114 pem_password_cb *cb, void *u)
115{
116 X509_SIG *p8;
117 PKCS8_PRIV_KEY_INFO *p8inf;
118 char buf[PEM_BUFSIZE];
119 int ret;
120 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
121 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
123 return 0;
124 }
125 if(enc || (nid != -1)) {
126 if(!kstr) {
127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
128 else klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if(klen <= 0) {
130 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
131 PEM_R_READ_KEY);
132 PKCS8_PRIV_KEY_INFO_free(p8inf);
133 return 0;
134 }
135
136 kstr = buf;
137 }
138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
139 if(kstr == buf) memset(buf, 0, klen);
140 PKCS8_PRIV_KEY_INFO_free(p8inf);
141 if(isder) ret = i2d_PKCS8_bio(bp, p8);
142 else ret = PEM_write_bio_PKCS8(bp, p8);
143 X509_SIG_free(p8);
144 return ret;
145 } else {
146 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
147 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
148 PKCS8_PRIV_KEY_INFO_free(p8inf);
149 return ret;
150 }
151}
152
153EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
154{
155 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
156 X509_SIG *p8 = NULL;
157 int klen;
158 EVP_PKEY *ret;
159 char psbuf[PEM_BUFSIZE];
160 p8 = d2i_PKCS8_bio(bp, NULL);
161 if(!p8) return NULL;
162 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
163 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
164 if (klen <= 0) {
165 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
166 X509_SIG_free(p8);
167 return NULL;
168 }
169 p8inf = PKCS8_decrypt(p8, psbuf, klen);
170 X509_SIG_free(p8);
171 if(!p8inf) return NULL;
172 ret = EVP_PKCS82PKEY(p8inf);
173 PKCS8_PRIV_KEY_INFO_free(p8inf);
174 if(!ret) return NULL;
175 if(x) {
176 if(*x) EVP_PKEY_free(*x);
177 *x = ret;
178 }
179 return ret;
180}
181
182#ifndef OPENSSL_NO_FP_API
183
184int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
185 char *kstr, int klen,
186 pem_password_cb *cb, void *u)
187{
188 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
189}
190
191int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
192 char *kstr, int klen,
193 pem_password_cb *cb, void *u)
194{
195 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
196}
197
198int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
199 char *kstr, int klen,
200 pem_password_cb *cb, void *u)
201{
202 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
203}
204
205int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
206 char *kstr, int klen, pem_password_cb *cb, void *u)
207{
208 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
209}
210
211static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
212 char *kstr, int klen,
213 pem_password_cb *cb, void *u)
214{
215 BIO *bp;
216 int ret;
217 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
218 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
219 return(0);
220 }
221 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
222 BIO_free(bp);
223 return ret;
224}
225
226EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
227{
228 BIO *bp;
229 EVP_PKEY *ret;
230 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
231 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
232 return NULL;
233 }
234 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
235 BIO_free(bp);
236 return ret;
237}
238
239#endif
240
241IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
242IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
243 PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libssl/src/crypto/pem/pem_pkey.c b/src/lib/libssl/src/crypto/pem/pem_pkey.c
new file mode 100644
index 0000000000..270892d72b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_pkey.c
@@ -0,0 +1,139 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 {
72 char *nm=NULL;
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 EVP_PKEY *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
78 return NULL;
79 p = data;
80
81 if (strcmp(nm,PEM_STRING_RSA) == 0)
82 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
83 else if (strcmp(nm,PEM_STRING_DSA) == 0)
84 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
85 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
86 PKCS8_PRIV_KEY_INFO *p8inf;
87 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
88 ret = EVP_PKCS82PKEY(p8inf);
89 PKCS8_PRIV_KEY_INFO_free(p8inf);
90 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
91 PKCS8_PRIV_KEY_INFO *p8inf;
92 X509_SIG *p8;
93 int klen;
94 char psbuf[PEM_BUFSIZE];
95 p8 = d2i_X509_SIG(NULL, &p, len);
96 if(!p8) goto p8err;
97 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
98 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
99 if (klen <= 0) {
100 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
101 PEM_R_BAD_PASSWORD_READ);
102 goto err;
103 }
104 p8inf = PKCS8_decrypt(p8, psbuf, klen);
105 X509_SIG_free(p8);
106 if(!p8inf) goto p8err;
107 ret = EVP_PKCS82PKEY(p8inf);
108 if(x) {
109 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
110 *x = ret;
111 }
112 PKCS8_PRIV_KEY_INFO_free(p8inf);
113 }
114p8err:
115 if (ret == NULL)
116 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
117err:
118 OPENSSL_free(nm);
119 OPENSSL_free(data);
120 return(ret);
121 }
122
123#ifndef OPENSSL_NO_FP_API
124EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
125 {
126 BIO *b;
127 EVP_PKEY *ret;
128
129 if ((b=BIO_new(BIO_s_file())) == NULL)
130 {
131 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
132 return(0);
133 }
134 BIO_set_fp(b,fp,BIO_NOCLOSE);
135 ret=PEM_read_bio_PrivateKey(b,x,cb,u);
136 BIO_free(b);
137 return(ret);
138 }
139#endif
diff --git a/src/lib/libssl/src/crypto/pem/pem_x509.c b/src/lib/libssl/src/crypto/pem/pem_x509.c
new file mode 100644
index 0000000000..19f88d8d3a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_x509.c
@@ -0,0 +1,69 @@
1/* pem_x509.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69
diff --git a/src/lib/libssl/src/crypto/pem/pem_xaux.c b/src/lib/libssl/src/crypto/pem/pem_xaux.c
new file mode 100644
index 0000000000..2f579b5421
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_xaux.c
@@ -0,0 +1,68 @@
1/* pem_xaux.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
diff --git a/src/lib/libssl/src/crypto/perlasm/alpha.pl b/src/lib/libssl/src/crypto/perlasm/alpha.pl
new file mode 100644
index 0000000000..3dac571743
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/alpha.pl
@@ -0,0 +1,434 @@
1#!/usr/local/bin/perl
2
3package alpha;
4use Carp qw(croak cluck);
5
6$label="100";
7
8$n_debug=0;
9$smear_regs=1;
10$reg_alloc=1;
11
12$align="3";
13$com_start="#";
14
15sub main'asm_init_output { @out=(); }
16sub main'asm_get_output { return(@out); }
17sub main'get_labels { return(@labels); }
18sub main'external_label { push(@labels,@_); }
19
20# General registers
21
22%regs=( 'r0', '$0',
23 'r1', '$1',
24 'r2', '$2',
25 'r3', '$3',
26 'r4', '$4',
27 'r5', '$5',
28 'r6', '$6',
29 'r7', '$7',
30 'r8', '$8',
31 'r9', '$22',
32 'r10', '$23',
33 'r11', '$24',
34 'r12', '$25',
35 'r13', '$27',
36 'r14', '$28',
37 'r15', '$21', # argc == 5
38 'r16', '$20', # argc == 4
39 'r17', '$19', # argc == 3
40 'r18', '$18', # argc == 2
41 'r19', '$17', # argc == 1
42 'r20', '$16', # argc == 0
43 'r21', '$9', # save 0
44 'r22', '$10', # save 1
45 'r23', '$11', # save 2
46 'r24', '$12', # save 3
47 'r25', '$13', # save 4
48 'r26', '$14', # save 5
49
50 'a0', '$16',
51 'a1', '$17',
52 'a2', '$18',
53 'a3', '$19',
54 'a4', '$20',
55 'a5', '$21',
56
57 's0', '$9',
58 's1', '$10',
59 's2', '$11',
60 's3', '$12',
61 's4', '$13',
62 's5', '$14',
63 'zero', '$31',
64 'sp', '$30',
65 );
66
67$main'reg_s0="r21";
68$main'reg_s1="r22";
69$main'reg_s2="r23";
70$main'reg_s3="r24";
71$main'reg_s4="r25";
72$main'reg_s5="r26";
73
74@reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8',
75 '$22','$23','$24','$25','$20','$21','$27','$28');
76
77
78sub main'sub { &out3("subq",@_); }
79sub main'add { &out3("addq",@_); }
80sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); }
81sub main'or { &out3("bis",@_); }
82sub main'bis { &out3("bis",@_); }
83sub main'br { &out1("br",@_); }
84sub main'ld { &out2("ldq",@_); }
85sub main'st { &out2("stq",@_); }
86sub main'cmpult { &out3("cmpult",@_); }
87sub main'cmplt { &out3("cmplt",@_); }
88sub main'bgt { &out2("bgt",@_); }
89sub main'ble { &out2("ble",@_); }
90sub main'blt { &out2("blt",@_); }
91sub main'mul { &out3("mulq",@_); }
92sub main'muh { &out3("umulh",@_); }
93
94$main'QWS=8;
95
96sub main'asm_add
97 {
98 push(@out,@_);
99 }
100
101sub main'asm_finish
102 {
103 &main'file_end();
104 print &main'asm_get_output();
105 }
106
107sub main'asm_init
108 {
109 ($type,$fn)=@_;
110 $filename=$fn;
111
112 &main'asm_init_output();
113 &main'comment("Don't even think of reading this code");
114 &main'comment("It was automatically generated by $filename");
115 &main'comment("Which is a perl program used to generate the alpha assember.");
116 &main'comment("eric <eay\@cryptsoft.com>");
117 &main'comment("");
118
119 $filename =~ s/\.pl$//;
120 &main'file($filename);
121 }
122
123sub conv
124 {
125 local($r)=@_;
126 local($v);
127
128 return($regs{$r}) if defined($regs{$r});
129 return($r);
130 }
131
132sub main'QWPw
133 {
134 local($off,$reg)=@_;
135
136 return(&main'QWP($off*8,$reg));
137 }
138
139sub main'QWP
140 {
141 local($off,$reg)=@_;
142
143 $ret="$off(".&conv($reg).")";
144 return($ret);
145 }
146
147sub out3
148 {
149 local($name,$p1,$p2,$p3)=@_;
150
151 $p1=&conv($p1);
152 $p2=&conv($p2);
153 $p3=&conv($p3);
154 push(@out,"\t$name\t");
155 $l=length($p1)+1;
156 push(@out,$p1.",");
157 $ll=3-($l+9)/8;
158 $tmp1=sprintf("\t" x $ll);
159 push(@out,$tmp1);
160
161 $l=length($p2)+1;
162 push(@out,$p2.",");
163 $ll=3-($l+9)/8;
164 $tmp1=sprintf("\t" x $ll);
165 push(@out,$tmp1);
166
167 push(@out,&conv($p3)."\n");
168 }
169
170sub out2
171 {
172 local($name,$p1,$p2,$p3)=@_;
173
174 $p1=&conv($p1);
175 $p2=&conv($p2);
176 push(@out,"\t$name\t");
177 $l=length($p1)+1;
178 push(@out,$p1.",");
179 $ll=3-($l+9)/8;
180 $tmp1=sprintf("\t" x $ll);
181 push(@out,$tmp1);
182
183 push(@out,&conv($p2)."\n");
184 }
185
186sub out1
187 {
188 local($name,$p1)=@_;
189
190 $p1=&conv($p1);
191 push(@out,"\t$name\t".$p1."\n");
192 }
193
194sub out0
195 {
196 push(@out,"\t$_[0]\n");
197 }
198
199sub main'file
200 {
201 local($file)=@_;
202
203 local($tmp)=<<"EOF";
204 # DEC Alpha assember
205 # Generated from perl scripts contains in SSLeay
206 .file 1 "$file.s"
207 .set noat
208EOF
209 push(@out,$tmp);
210 }
211
212sub main'function_begin
213 {
214 local($func)=@_;
215
216print STDERR "$func\n";
217 local($tmp)=<<"EOF";
218 .text
219 .align $align
220 .globl $func
221 .ent $func
222${func}:
223${func}..ng:
224 .frame \$30,0,\$26,0
225 .prologue 0
226EOF
227 push(@out,$tmp);
228 $stack=0;
229 }
230
231sub main'function_end
232 {
233 local($func)=@_;
234
235 local($tmp)=<<"EOF";
236 ret \$31,(\$26),1
237 .end $func
238EOF
239 push(@out,$tmp);
240 $stack=0;
241 %label=();
242 }
243
244sub main'function_end_A
245 {
246 local($func)=@_;
247
248 local($tmp)=<<"EOF";
249 ret \$31,(\$26),1
250EOF
251 push(@out,$tmp);
252 }
253
254sub main'function_end_B
255 {
256 local($func)=@_;
257
258 $func=$under.$func;
259
260 push(@out,"\t.end $func\n");
261 $stack=0;
262 %label=();
263 }
264
265sub main'wparam
266 {
267 local($num)=@_;
268
269 if ($num < 6)
270 {
271 $num=20-$num;
272 return("r$num");
273 }
274 else
275 { return(&main'QWP($stack+$num*8,"sp")); }
276 }
277
278sub main'stack_push
279 {
280 local($num)=@_;
281 $stack+=$num*8;
282 &main'sub("sp",$num*8,"sp");
283 }
284
285sub main'stack_pop
286 {
287 local($num)=@_;
288 $stack-=$num*8;
289 &main'add("sp",$num*8,"sp");
290 }
291
292sub main'swtmp
293 {
294 return(&main'QWP(($_[0])*8,"sp"));
295 }
296
297# Should use swtmp, which is above sp. Linix can trash the stack above esp
298#sub main'wtmp
299# {
300# local($num)=@_;
301#
302# return(&main'QWP(-($num+1)*4,"esp","",0));
303# }
304
305sub main'comment
306 {
307 foreach (@_)
308 {
309 if (/^\s*$/)
310 { push(@out,"\n"); }
311 else
312 { push(@out,"\t$com_start $_ $com_end\n"); }
313 }
314 }
315
316sub main'label
317 {
318 if (!defined($label{$_[0]}))
319 {
320 $label{$_[0]}=$label;
321 $label++;
322 }
323 return('$'.$label{$_[0]});
324 }
325
326sub main'set_label
327 {
328 if (!defined($label{$_[0]}))
329 {
330 $label{$_[0]}=$label;
331 $label++;
332 }
333# push(@out,".align $align\n") if ($_[1] != 0);
334 push(@out,'$'."$label{$_[0]}:\n");
335 }
336
337sub main'file_end
338 {
339 }
340
341sub main'data_word
342 {
343 push(@out,"\t.long $_[0]\n");
344 }
345
346@pool_free=();
347@pool_taken=();
348$curr_num=0;
349$max=0;
350
351sub main'init_pool
352 {
353 local($args)=@_;
354 local($i);
355
356 @pool_free=();
357 for ($i=(14+(6-$args)); $i >= 0; $i--)
358 {
359 push(@pool_free,"r$i");
360 }
361 print STDERR "START :register pool:@pool_free\n";
362 $curr_num=$max=0;
363 }
364
365sub main'fin_pool
366 {
367 printf STDERR "END %2d:register pool:@pool_free\n",$max;
368 }
369
370sub main'GR
371 {
372 local($r)=@_;
373 local($i,@n,$_);
374
375 foreach (@pool_free)
376 {
377 if ($r ne $_)
378 { push(@n,$_); }
379 else
380 {
381 $curr_num++;
382 $max=$curr_num if ($curr_num > $max);
383 }
384 }
385 @pool_free=@n;
386print STDERR "GR:@pool_free\n" if $reg_alloc;
387 return(@_);
388 }
389
390sub main'NR
391 {
392 local($num)=@_;
393 local(@ret);
394
395 $num=1 if $num == 0;
396 ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free";
397 while ($num > 0)
398 {
399 push(@ret,pop @pool_free);
400 $curr_num++;
401 $max=$curr_num if ($curr_num > $max);
402 $num--
403 }
404 print STDERR "nr @ret\n" if $n_debug;
405print STDERR "NR:@pool_free\n" if $reg_alloc;
406 return(@ret);
407
408 }
409
410sub main'FR
411 {
412 local(@r)=@_;
413 local(@a,$v,$w);
414
415 print STDERR "fr @r\n" if $n_debug;
416# cluck "fr @r";
417 for $w (@pool_free)
418 {
419 foreach $v (@r)
420 {
421 croak "double register free of $v (@pool_free)" if $w eq $v;
422 }
423 }
424 foreach $v (@r)
425 {
426 croak "bad argument to FR" if ($v !~ /^r\d+$/);
427 if ($smear_regs)
428 { unshift(@pool_free,$v); }
429 else { push(@pool_free,$v); }
430 $curr_num--;
431 }
432print STDERR "FR:@pool_free\n" if $reg_alloc;
433 }
4341;
diff --git a/src/lib/libssl/src/crypto/perlasm/x86nasm.pl b/src/lib/libssl/src/crypto/perlasm/x86nasm.pl
new file mode 100644
index 0000000000..b4da364bbf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/x86nasm.pl
@@ -0,0 +1,342 @@
1#!/usr/local/bin/perl
2
3package x86nasm;
4
5$label="L000";
6
7%lb=( 'eax', 'al',
8 'ebx', 'bl',
9 'ecx', 'cl',
10 'edx', 'dl',
11 'ax', 'al',
12 'bx', 'bl',
13 'cx', 'cl',
14 'dx', 'dl',
15 );
16
17%hb=( 'eax', 'ah',
18 'ebx', 'bh',
19 'ecx', 'ch',
20 'edx', 'dh',
21 'ax', 'ah',
22 'bx', 'bh',
23 'cx', 'ch',
24 'dx', 'dh',
25 );
26
27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); }
30
31sub main'external_label
32{
33 push(@labels,@_);
34 foreach (@_) {
35 push(@out, "extern\t_$_\n");
36 }
37}
38
39sub main'LB
40 {
41 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
42 return($lb{$_[0]});
43 }
44
45sub main'HB
46 {
47 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
48 return($hb{$_[0]});
49 }
50
51sub main'BP
52 {
53 &get_mem("BYTE",@_);
54 }
55
56sub main'DWP
57 {
58 &get_mem("DWORD",@_);
59 }
60
61sub main'BC
62 {
63 return "BYTE @_";
64 }
65
66sub main'DWC
67 {
68 return "DWORD @_";
69 }
70
71sub main'stack_push
72 {
73 my($num)=@_;
74 $stack+=$num*4;
75 &main'sub("esp",$num*4);
76 }
77
78sub main'stack_pop
79 {
80 my($num)=@_;
81 $stack-=$num*4;
82 &main'add("esp",$num*4);
83 }
84
85sub get_mem
86 {
87 my($size,$addr,$reg1,$reg2,$idx)=@_;
88 my($t,$post);
89 my($ret)="[";
90 $addr =~ s/^\s+//;
91 if ($addr =~ /^(.+)\+(.+)$/)
92 {
93 $reg2=&conv($1);
94 $addr="_$2";
95 }
96 elsif ($addr =~ /^[_a-zA-Z]/)
97 {
98 $addr="_$addr";
99 }
100
101 $reg1="$regs{$reg1}" if defined($regs{$reg1});
102 $reg2="$regs{$reg2}" if defined($regs{$reg2});
103 if (($addr ne "") && ($addr ne 0))
104 {
105 if ($addr !~ /^-/)
106 { $ret.="${addr}+"; }
107 else { $post=$addr; }
108 }
109 if ($reg2 ne "")
110 {
111 $t="";
112 $t="*$idx" if ($idx != 0);
113 $reg1="+".$reg1 if ("$reg1$post" ne "");
114 $ret.="$reg2$t$reg1$post]";
115 }
116 else
117 {
118 $ret.="$reg1$post]"
119 }
120 return($ret);
121 }
122
123sub main'mov { &out2("mov",@_); }
124sub main'movb { &out2("mov",@_); }
125sub main'and { &out2("and",@_); }
126sub main'or { &out2("or",@_); }
127sub main'shl { &out2("shl",@_); }
128sub main'shr { &out2("shr",@_); }
129sub main'xor { &out2("xor",@_); }
130sub main'xorb { &out2("xor",@_); }
131sub main'add { &out2("add",@_); }
132sub main'adc { &out2("adc",@_); }
133sub main'sub { &out2("sub",@_); }
134sub main'rotl { &out2("rol",@_); }
135sub main'rotr { &out2("ror",@_); }
136sub main'exch { &out2("xchg",@_); }
137sub main'cmp { &out2("cmp",@_); }
138sub main'lea { &out2("lea",@_); }
139sub main'mul { &out1("mul",@_); }
140sub main'div { &out1("div",@_); }
141sub main'dec { &out1("dec",@_); }
142sub main'inc { &out1("inc",@_); }
143sub main'jmp { &out1("jmp",@_); }
144sub main'jmp_ptr { &out1p("jmp",@_); }
145
146# This is a bit of a kludge: declare all branches as NEAR.
147sub main'je { &out1("je NEAR",@_); }
148sub main'jle { &out1("jle NEAR",@_); }
149sub main'jz { &out1("jz NEAR",@_); }
150sub main'jge { &out1("jge NEAR",@_); }
151sub main'jl { &out1("jl NEAR",@_); }
152sub main'jb { &out1("jb NEAR",@_); }
153sub main'jc { &out1("jc NEAR",@_); }
154sub main'jnc { &out1("jnc NEAR",@_); }
155sub main'jnz { &out1("jnz NEAR",@_); }
156sub main'jne { &out1("jne NEAR",@_); }
157sub main'jno { &out1("jno NEAR",@_); }
158
159sub main'push { &out1("push",@_); $stack+=4; }
160sub main'pop { &out1("pop",@_); $stack-=4; }
161sub main'bswap { &out1("bswap",@_); &using486(); }
162sub main'not { &out1("not",@_); }
163sub main'call { &out1("call",'_'.$_[0]); }
164sub main'ret { &out0("ret"); }
165sub main'nop { &out0("nop"); }
166
167sub out2
168 {
169 my($name,$p1,$p2)=@_;
170 my($l,$t);
171
172 push(@out,"\t$name\t");
173 $t=&conv($p1).",";
174 $l=length($t);
175 push(@out,$t);
176 $l=4-($l+9)/8;
177 push(@out,"\t" x $l);
178 push(@out,&conv($p2));
179 push(@out,"\n");
180 }
181
182sub out0
183 {
184 my($name)=@_;
185
186 push(@out,"\t$name\n");
187 }
188
189sub out1
190 {
191 my($name,$p1)=@_;
192 my($l,$t);
193 push(@out,"\t$name\t".&conv($p1)."\n");
194 }
195
196sub conv
197 {
198 my($p)=@_;
199 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
200 return $p;
201 }
202
203sub using486
204 {
205 return if $using486;
206 $using486++;
207 grep(s/\.386/\.486/,@out);
208 }
209
210sub main'file
211 {
212 push(@out, "segment .text\n");
213 }
214
215sub main'function_begin
216 {
217 my($func,$extra)=@_;
218
219 push(@labels,$func);
220 my($tmp)=<<"EOF";
221global _$func
222_$func:
223 push ebp
224 push ebx
225 push esi
226 push edi
227EOF
228 push(@out,$tmp);
229 $stack=20;
230 }
231
232sub main'function_begin_B
233 {
234 my($func,$extra)=@_;
235 my($tmp)=<<"EOF";
236global _$func
237_$func:
238EOF
239 push(@out,$tmp);
240 $stack=4;
241 }
242
243sub main'function_end
244 {
245 my($func)=@_;
246
247 my($tmp)=<<"EOF";
248 pop edi
249 pop esi
250 pop ebx
251 pop ebp
252 ret
253EOF
254 push(@out,$tmp);
255 $stack=0;
256 %label=();
257 }
258
259sub main'function_end_B
260 {
261 $stack=0;
262 %label=();
263 }
264
265sub main'function_end_A
266 {
267 my($func)=@_;
268
269 my($tmp)=<<"EOF";
270 pop edi
271 pop esi
272 pop ebx
273 pop ebp
274 ret
275EOF
276 push(@out,$tmp);
277 }
278
279sub main'file_end
280 {
281 }
282
283sub main'wparam
284 {
285 my($num)=@_;
286
287 return(&main'DWP($stack+$num*4,"esp","",0));
288 }
289
290sub main'swtmp
291 {
292 return(&main'DWP($_[0]*4,"esp","",0));
293 }
294
295# Should use swtmp, which is above esp. Linix can trash the stack above esp
296#sub main'wtmp
297# {
298# my($num)=@_;
299#
300# return(&main'DWP(-(($num+1)*4),"esp","",0));
301# }
302
303sub main'comment
304 {
305 foreach (@_)
306 {
307 push(@out,"\t; $_\n");
308 }
309 }
310
311sub main'label
312 {
313 if (!defined($label{$_[0]}))
314 {
315 $label{$_[0]}="\$${label}${_[0]}";
316 $label++;
317 }
318 return($label{$_[0]});
319 }
320
321sub main'set_label
322 {
323 if (!defined($label{$_[0]}))
324 {
325 $label{$_[0]}="${label}${_[0]}";
326 $label++;
327 }
328 push(@out,"$label{$_[0]}:\n");
329 }
330
331sub main'data_word
332 {
333 push(@out,"\tDD\t$_[0]\n");
334 }
335
336sub out1p
337 {
338 my($name,$p1)=@_;
339 my($l,$t);
340
341 push(@out,"\t$name\t ".&conv($p1)."\n");
342 }
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_add.c b/src/lib/libssl/src/crypto/pkcs12/p12_add.c
new file mode 100644
index 0000000000..ae3d9de3b4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_add.c
@@ -0,0 +1,214 @@
1/* p12_add.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Pack an object into an OCTET STRING and turn into a safebag */
64
65PKCS12_SAFEBAG *PKCS12_pack_safebag (char *obj, int (*i2d)(), int nid1,
66 int nid2)
67{
68 PKCS12_BAGS *bag;
69 PKCS12_SAFEBAG *safebag;
70 if (!(bag = PKCS12_BAGS_new ())) {
71 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
72 return NULL;
73 }
74 bag->type = OBJ_nid2obj(nid1);
75 if (!ASN1_pack_string(obj, i2d, &bag->value.octet)) {
76 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
77 return NULL;
78 }
79 if (!(safebag = PKCS12_SAFEBAG_new ())) {
80 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
81 return NULL;
82 }
83 safebag->value.bag = bag;
84 safebag->type = OBJ_nid2obj(nid2);
85 return safebag;
86}
87
88/* Turn PKCS8 object into a keybag */
89
90PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG (PKCS8_PRIV_KEY_INFO *p8)
91{
92 PKCS12_SAFEBAG *bag;
93 if (!(bag = PKCS12_SAFEBAG_new())) {
94 PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 bag->type = OBJ_nid2obj(NID_keyBag);
98 bag->value.keybag = p8;
99 return bag;
100}
101
102/* Turn PKCS8 object into a shrouded keybag */
103
104PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG (int pbe_nid, const char *pass,
105 int passlen, unsigned char *salt, int saltlen, int iter,
106 PKCS8_PRIV_KEY_INFO *p8)
107{
108 PKCS12_SAFEBAG *bag;
109
110 /* Set up the safe bag */
111 if (!(bag = PKCS12_SAFEBAG_new ())) {
112 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115
116 bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag);
117 if (!(bag->value.shkeybag =
118 PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter,
119 p8))) {
120 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123
124 return bag;
125}
126
127/* Turn a stack of SAFEBAGS into a PKCS#7 data Contentinfo */
128PKCS7 *PKCS12_pack_p7data (STACK *sk)
129{
130 PKCS7 *p7;
131 if (!(p7 = PKCS7_new())) {
132 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
133 return NULL;
134 }
135 p7->type = OBJ_nid2obj(NID_pkcs7_data);
136 if (!(p7->d.data = ASN1_OCTET_STRING_new())) {
137 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
138 return NULL;
139 }
140
141 if (!ASN1_seq_pack(sk, i2d_PKCS12_SAFEBAG, &p7->d.data->data,
142 &p7->d.data->length)) {
143 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, PKCS12_R_CANT_PACK_STRUCTURE);
144 return NULL;
145 }
146 return p7;
147}
148
149/* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */
150
151PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen,
152 unsigned char *salt, int saltlen, int iter, STACK *bags)
153{
154 PKCS7 *p7;
155 X509_ALGOR *pbe;
156 if (!(p7 = PKCS7_new())) {
157 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
158 return NULL;
159 }
160 p7->type = OBJ_nid2obj(NID_pkcs7_encrypted);
161 if (!(p7->d.encrypted = PKCS7_ENCRYPT_new ())) {
162 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
163 return NULL;
164 }
165 ASN1_INTEGER_set (p7->d.encrypted->version, 0);
166 p7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data);
167 if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {
168 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
169 return NULL;
170 }
171 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
172 p7->d.encrypted->enc_data->algorithm = pbe;
173 ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
174 if (!(p7->d.encrypted->enc_data->enc_data =
175 PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen,
176 (char *)bags, 1))) {
177 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);
178 return NULL;
179 }
180
181 return p7;
182}
183
184X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
185 const char *pass, int passlen,
186 unsigned char *salt, int saltlen, int iter,
187 PKCS8_PRIV_KEY_INFO *p8inf)
188{
189 X509_SIG *p8;
190 X509_ALGOR *pbe;
191
192 if (!(p8 = X509_SIG_new())) {
193 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
194 return NULL;
195 }
196
197 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
198 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
199 if(!pbe) {
200 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
201 return NULL;
202 }
203 X509_ALGOR_free(p8->algor);
204 p8->algor = pbe;
205 ASN1_OCTET_STRING_free(p8->digest);
206 if (!(p8->digest =
207 PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen,
208 (char *)p8inf, 0))) {
209 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
210 return NULL;
211 }
212
213 return p8;
214}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_asn.c b/src/lib/libssl/src/crypto/pkcs12/p12_asn.c
new file mode 100644
index 0000000000..c327bdba03
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_asn.c
@@ -0,0 +1,125 @@
1/* p12_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs12.h>
63
64/* PKCS#12 ASN1 module */
65
66ASN1_SEQUENCE(PKCS12) = {
67 ASN1_SIMPLE(PKCS12, version, ASN1_INTEGER),
68 ASN1_SIMPLE(PKCS12, authsafes, PKCS7),
69 ASN1_OPT(PKCS12, mac, PKCS12_MAC_DATA)
70} ASN1_SEQUENCE_END(PKCS12)
71
72IMPLEMENT_ASN1_FUNCTIONS(PKCS12)
73
74ASN1_SEQUENCE(PKCS12_MAC_DATA) = {
75 ASN1_SIMPLE(PKCS12_MAC_DATA, dinfo, X509_SIG),
76 ASN1_SIMPLE(PKCS12_MAC_DATA, salt, ASN1_OCTET_STRING),
77 ASN1_OPT(PKCS12_MAC_DATA, iter, ASN1_INTEGER)
78} ASN1_SEQUENCE_END(PKCS12_MAC_DATA)
79
80IMPLEMENT_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
81
82ASN1_ADB_TEMPLATE(bag_default) = ASN1_EXP(PKCS12_BAGS, value.other, ASN1_ANY, 0);
83
84ASN1_ADB(PKCS12_BAGS) = {
85 ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)),
86 ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)),
87 ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)),
88} ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL);
89
90ASN1_SEQUENCE(PKCS12_BAGS) = {
91 ASN1_SIMPLE(PKCS12_BAGS, type, ASN1_OBJECT),
92 ASN1_ADB_OBJECT(PKCS12_BAGS),
93} ASN1_SEQUENCE_END(PKCS12_BAGS)
94
95IMPLEMENT_ASN1_FUNCTIONS(PKCS12_BAGS)
96
97ASN1_ADB_TEMPLATE(safebag_default) = ASN1_EXP(PKCS12_SAFEBAG, value.other, ASN1_ANY, 0);
98
99ASN1_ADB(PKCS12_SAFEBAG) = {
100 ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)),
101 ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, X509_SIG, 0)),
102 ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)),
103 ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
104 ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
105 ADB_ENTRY(NID_secretBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0))
106} ASN1_ADB_END(PKCS12_SAFEBAG, 0, type, 0, &safebag_default_tt, NULL);
107
108ASN1_SEQUENCE(PKCS12_SAFEBAG) = {
109 ASN1_SIMPLE(PKCS12_SAFEBAG, type, ASN1_OBJECT),
110 ASN1_ADB_OBJECT(PKCS12_SAFEBAG),
111 ASN1_SET_OF_OPT(PKCS12_SAFEBAG, attrib, X509_ATTRIBUTE)
112} ASN1_SEQUENCE_END(PKCS12_SAFEBAG)
113
114IMPLEMENT_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
115
116/* SEQUENCE OF SafeBag */
117ASN1_ITEM_TEMPLATE(PKCS12_SAFEBAGS) =
118 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_SAFEBAGS, PKCS12_SAFEBAG)
119ASN1_ITEM_TEMPLATE_END(PKCS12_SAFEBAGS)
120
121/* Authsafes: SEQUENCE OF PKCS7 */
122ASN1_ITEM_TEMPLATE(PKCS12_AUTHSAFES) =
123 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_AUTHSAFES, PKCS7)
124ASN1_ITEM_TEMPLATE_END(PKCS12_AUTHSAFES)
125
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_attr.c b/src/lib/libssl/src/crypto/pkcs12/p12_attr.c
new file mode 100644
index 0000000000..31c9782b77
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_attr.c
@@ -0,0 +1,238 @@
1/* p12_attr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Add a local keyid to a safebag */
64
65int PKCS12_add_localkeyid (PKCS12_SAFEBAG *bag, unsigned char *name,
66 int namelen)
67{
68 X509_ATTRIBUTE *attrib;
69 ASN1_BMPSTRING *oct;
70 ASN1_TYPE *keyid;
71 if (!(keyid = ASN1_TYPE_new ())) {
72 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
73 return 0;
74 }
75 keyid->type = V_ASN1_OCTET_STRING;
76 if (!(oct = ASN1_OCTET_STRING_new())) {
77 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 if (!ASN1_OCTET_STRING_set(oct, name, namelen)) {
81 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
82 return 0;
83 }
84 keyid->value.octet_string = oct;
85 if (!(attrib = X509_ATTRIBUTE_new ())) {
86 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
87 return 0;
88 }
89 attrib->object = OBJ_nid2obj(NID_localKeyID);
90 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
91 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
92 return 0;
93 }
94 sk_ASN1_TYPE_push (attrib->value.set,keyid);
95 attrib->set = 1;
96 if (!bag->attrib && !(bag->attrib = sk_X509_ATTRIBUTE_new (NULL))) {
97 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
98 return 0;
99 }
100 sk_X509_ATTRIBUTE_push (bag->attrib, attrib);
101 return 1;
102}
103
104/* Add key usage to PKCS#8 structure */
105
106int PKCS8_add_keyusage (PKCS8_PRIV_KEY_INFO *p8, int usage)
107{
108 X509_ATTRIBUTE *attrib;
109 ASN1_BIT_STRING *bstr;
110 ASN1_TYPE *keyid;
111 unsigned char us_val;
112 us_val = (unsigned char) usage;
113 if (!(keyid = ASN1_TYPE_new ())) {
114 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 keyid->type = V_ASN1_BIT_STRING;
118 if (!(bstr = ASN1_BIT_STRING_new())) {
119 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 if (!ASN1_BIT_STRING_set(bstr, &us_val, 1)) {
123 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
124 return 0;
125 }
126 keyid->value.bit_string = bstr;
127 if (!(attrib = X509_ATTRIBUTE_new ())) {
128 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131 attrib->object = OBJ_nid2obj(NID_key_usage);
132 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
133 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
134 return 0;
135 }
136 sk_ASN1_TYPE_push (attrib->value.set,keyid);
137 attrib->set = 1;
138 if (!p8->attributes
139 && !(p8->attributes = sk_X509_ATTRIBUTE_new (NULL))) {
140 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
141 return 0;
142 }
143 sk_X509_ATTRIBUTE_push (p8->attributes, attrib);
144 return 1;
145}
146
147/* Add a friendlyname to a safebag */
148
149int PKCS12_add_friendlyname_asc (PKCS12_SAFEBAG *bag, const char *name,
150 int namelen)
151{
152 unsigned char *uniname;
153 int ret, unilen;
154 if (!asc2uni(name, &uniname, &unilen)) {
155 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,
156 ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 ret = PKCS12_add_friendlyname_uni (bag, uniname, unilen);
160 Free(uniname);
161 return ret;
162}
163
164
165int PKCS12_add_friendlyname_uni (PKCS12_SAFEBAG *bag,
166 const unsigned char *name, int namelen)
167{
168 X509_ATTRIBUTE *attrib;
169 ASN1_BMPSTRING *bmp;
170 ASN1_TYPE *fname;
171 /* Zap ending double null if included */
172 if(!name[namelen - 1] && !name[namelen - 2]) namelen -= 2;
173 if (!(fname = ASN1_TYPE_new ())) {
174 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
175 ERR_R_MALLOC_FAILURE);
176 return 0;
177 }
178 fname->type = V_ASN1_BMPSTRING;
179 if (!(bmp = ASN1_BMPSTRING_new())) {
180 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
181 ERR_R_MALLOC_FAILURE);
182 return 0;
183 }
184 if (!(bmp->data = Malloc (namelen))) {
185 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
186 ERR_R_MALLOC_FAILURE);
187 return 0;
188 }
189 memcpy (bmp->data, name, namelen);
190 bmp->length = namelen;
191 fname->value.bmpstring = bmp;
192 if (!(attrib = X509_ATTRIBUTE_new ())) {
193 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
194 ERR_R_MALLOC_FAILURE);
195 return 0;
196 }
197 attrib->object = OBJ_nid2obj(NID_friendlyName);
198 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
199 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME,
200 ERR_R_MALLOC_FAILURE);
201 return 0;
202 }
203 sk_ASN1_TYPE_push (attrib->value.set,fname);
204 attrib->set = 1;
205 if (!bag->attrib && !(bag->attrib = sk_X509_ATTRIBUTE_new (NULL))) {
206 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
207 ERR_R_MALLOC_FAILURE);
208 return 0;
209 }
210 sk_X509_ATTRIBUTE_push (bag->attrib, attrib);
211 return PKCS12_OK;
212}
213
214ASN1_TYPE *PKCS12_get_attr_gen (STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid)
215{
216 X509_ATTRIBUTE *attrib;
217 int i;
218 if (!attrs) return NULL;
219 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) {
220 attrib = sk_X509_ATTRIBUTE_value (attrs, i);
221 if (OBJ_obj2nid (attrib->object) == attr_nid) {
222 if (sk_ASN1_TYPE_num (attrib->value.set))
223 return sk_ASN1_TYPE_value(attrib->value.set, 0);
224 else return NULL;
225 }
226 }
227 return NULL;
228}
229
230char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
231{
232 ASN1_TYPE *atype;
233 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL;
234 if (atype->type != V_ASN1_BMPSTRING) return NULL;
235 return uni2asc(atype->value.bmpstring->data,
236 atype->value.bmpstring->length);
237}
238
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c b/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c
new file mode 100644
index 0000000000..6de6f8128f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c
@@ -0,0 +1,122 @@
1/* p12_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* PKCS#12 specific PBE functions */
64
65void PKCS12_PBE_add(void)
66{
67#ifndef NO_RC4
68EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
69 PKCS12_PBE_keyivgen);
70EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
71 PKCS12_PBE_keyivgen);
72#endif
73EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
74 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
75EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
76 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
77#ifndef NO_RC2
78EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
79 EVP_sha1(), PKCS12_PBE_keyivgen);
80EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
81 EVP_sha1(), PKCS12_PBE_keyivgen);
82#endif
83}
84
85int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
86 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, int en_de)
87{
88 PBEPARAM *pbe;
89 int saltlen, iter;
90 unsigned char *salt, *pbuf;
91 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
92
93 /* Extract useful info from parameter */
94 pbuf = param->value.sequence->data;
95 if (!param || (param->type != V_ASN1_SEQUENCE) ||
96 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
97 EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
98 return 0;
99 }
100
101 if (!pbe->iter) iter = 1;
102 else iter = ASN1_INTEGER_get (pbe->iter);
103 salt = pbe->salt->data;
104 saltlen = pbe->salt->length;
105 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID,
106 iter, EVP_CIPHER_key_length(cipher), key, md)) {
107 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_KEY_GEN_ERROR);
108 PBEPARAM_free(pbe);
109 return 0;
110 }
111 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID,
112 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
113 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_IV_GEN_ERROR);
114 PBEPARAM_free(pbe);
115 return 0;
116 }
117 PBEPARAM_free(pbe);
118 EVP_CipherInit(ctx, cipher, key, iv, en_de);
119 memset(key, 0, EVP_MAX_KEY_LENGTH);
120 memset(iv, 0, EVP_MAX_IV_LENGTH);
121 return 1;
122}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_crt.c b/src/lib/libssl/src/crypto/pkcs12/p12_crt.c
new file mode 100644
index 0000000000..56d88b0759
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_crt.c
@@ -0,0 +1,159 @@
1/* p12_crt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
64 STACK *ca, int nid_key, int nid_cert, int iter, int mac_iter,
65 int keytype)
66{
67 PKCS12 *p12;
68 STACK *bags, *safes;
69 PKCS12_SAFEBAG *bag;
70 PKCS8_PRIV_KEY_INFO *p8;
71 PKCS7 *authsafe;
72 X509 *tcert;
73 int i;
74 unsigned char keyid[EVP_MAX_MD_SIZE];
75 unsigned int keyidlen;
76
77 /* Set defaults */
78 if(!nid_cert) nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
79 if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
80 if(!iter) iter = PKCS12_DEFAULT_ITER;
81 if(!mac_iter) mac_iter = 1;
82
83 if(!pkey || !cert) {
84 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
85 return NULL;
86 }
87
88 if(!(bags = sk_new (NULL))) {
89 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
90 return NULL;
91 }
92
93 /* Add user certificate */
94 if(!(bag = M_PKCS12_x5092certbag(cert))) return NULL;
95 if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL;
96 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
97 if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL;
98
99 if(!sk_push(bags, (char *)bag)) {
100 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103
104 /* Add all other certificates */
105 if(ca) {
106 for(i = 0; i < sk_num(ca); i++) {
107 tcert = (X509 *)sk_value(ca, i);
108 if(!(bag = M_PKCS12_x5092certbag(tcert))) return NULL;
109 if(!sk_push(bags, (char *)bag)) {
110 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
111 return NULL;
112 }
113 }
114 }
115
116 /* Turn certbags into encrypted authsafe */
117 authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0,
118 iter, bags);
119 sk_pop_free(bags, PKCS12_SAFEBAG_free);
120
121 if (!authsafe) return NULL;
122
123 if(!(safes = sk_new (NULL)) || !sk_push(safes, (char *)authsafe)) {
124 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
125 return NULL;
126 }
127
128 /* Make a shrouded key bag */
129 if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL;
130 if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL;
131 bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8);
132 if(!bag) return NULL;
133 PKCS8_PRIV_KEY_INFO_free(p8);
134 if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL;
135 if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL;
136 if(!(bags = sk_new(NULL)) || !sk_push (bags, (char *)bag)) {
137 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
138 return NULL;
139 }
140 /* Turn it into unencrypted safe bag */
141 if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL;
142 sk_pop_free(bags, PKCS12_SAFEBAG_free);
143 if(!sk_push(safes, (char *)authsafe)) {
144 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147
148 if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL;
149
150 if(!M_PKCS12_pack_authsafes (p12, safes)) return NULL;
151
152 sk_pop_free(safes, PKCS7_free);
153
154 if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL))
155 return NULL;
156
157 return p12;
158
159}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_decr.c b/src/lib/libssl/src/crypto/pkcs12/p12_decr.c
new file mode 100644
index 0000000000..d3d288e187
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_decr.c
@@ -0,0 +1,185 @@
1/* p12_decr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Define this to dump decrypted output to files called DERnnn */
64/*#define DEBUG_DECRYPT*/
65
66
67/* Encrypt/Decrypt a buffer based on password and algor, result in a
68 * Malloc'ed buffer
69 */
70
71unsigned char * PKCS12_pbe_crypt (X509_ALGOR *algor, const char *pass,
72 int passlen, unsigned char *in, int inlen, unsigned char **data,
73 int *datalen, int en_de)
74{
75 unsigned char *out;
76 int outlen, i;
77 EVP_CIPHER_CTX ctx;
78
79 /* Decrypt data */
80 if (!EVP_PBE_CipherInit (algor->algorithm, pass, passlen,
81 algor->parameter, &ctx, en_de)) {
82 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
83 return NULL;
84 }
85
86 if(!(out = Malloc (inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
87 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);
88 return NULL;
89 }
90
91 EVP_CipherUpdate (&ctx, out, &i, in, inlen);
92 outlen = i;
93 if(!EVP_CipherFinal (&ctx, out + i, &i)) {
94 Free (out);
95 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
96 return NULL;
97 }
98 outlen += i;
99 if (datalen) *datalen = outlen;
100 if (data) *data = out;
101 return out;
102
103}
104
105/* Decrypt an OCTET STRING and decode ASN1 structure
106 * if seq & 1 'obj' is a stack of structures to be encoded
107 * if seq & 2 zero buffer after use
108 * as a sequence.
109 */
110
111char * PKCS12_decrypt_d2i (X509_ALGOR *algor, char * (*d2i)(),
112 void (*free_func)(), const char *pass, int passlen,
113 ASN1_OCTET_STRING *oct, int seq)
114{
115 unsigned char *out, *p;
116 char *ret;
117 int outlen;
118
119 if (!PKCS12_pbe_crypt (algor, pass, passlen, oct->data, oct->length,
120 &out, &outlen, 0)) {
121 PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
122 return NULL;
123 }
124 p = out;
125#ifdef DEBUG_DECRYPT
126 {
127 FILE *op;
128
129 char fname[30];
130 static int fnm = 1;
131 sprintf(fname, "DER%d", fnm++);
132 op = fopen(fname, "wb");
133 fwrite (p, 1, outlen, op);
134 fclose(op);
135 }
136#endif
137 if (seq & 1) ret = (char *) d2i_ASN1_SET(NULL, &p, outlen, d2i,
138 free_func, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
139 else ret = d2i(NULL, &p, outlen);
140 if (seq & 2) memset(out, 0, outlen);
141 if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
142 Free (out);
143 return ret;
144}
145
146/* Encode ASN1 structure and encrypt, return OCTET STRING
147 * if 'seq' is non-zero 'obj' is a stack of structures to be encoded
148 * as a sequence
149 */
150
151ASN1_OCTET_STRING *PKCS12_i2d_encrypt (X509_ALGOR *algor, int (*i2d)(),
152 const char *pass, int passlen,
153 char *obj, int seq)
154{
155 ASN1_OCTET_STRING *oct;
156 unsigned char *in, *p;
157 int inlen;
158 if (!(oct = ASN1_OCTET_STRING_new ())) {
159 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
160 return NULL;
161 }
162 if (seq) inlen = i2d_ASN1_SET((STACK *)obj, NULL, i2d, V_ASN1_SEQUENCE,
163 V_ASN1_UNIVERSAL, IS_SEQUENCE);
164 else inlen = i2d (obj, NULL);
165 if (!inlen) {
166 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR);
167 return NULL;
168 }
169 if (!(in = Malloc (inlen))) {
170 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
171 return NULL;
172 }
173 p = in;
174 if (seq) i2d_ASN1_SET((STACK *)obj, &p, i2d, V_ASN1_SEQUENCE,
175 V_ASN1_UNIVERSAL, IS_SEQUENCE);
176 else i2d (obj, &p);
177 if (!PKCS12_pbe_crypt (algor, pass, passlen, in, inlen, &oct->data,
178 &oct->length, 1)) {
179 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
180 Free(in);
181 return NULL;
182 }
183 Free (in);
184 return oct;
185}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_init.c b/src/lib/libssl/src/crypto/pkcs12/p12_init.c
new file mode 100644
index 0000000000..dc6ab41db8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_init.c
@@ -0,0 +1,98 @@
1/* p12_init.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Initialise a PKCS12 structure to take data */
64
65PKCS12 *PKCS12_init (int mode)
66{
67 PKCS12 *pkcs12;
68 if (!(pkcs12 = PKCS12_new())) {
69 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
70 return NULL;
71 }
72 if (!(pkcs12->version = ASN1_INTEGER_new ())) {
73 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
74 return NULL;
75 }
76 ASN1_INTEGER_set (pkcs12->version, 3);
77 if (!(pkcs12->authsafes = PKCS7_new())) {
78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
79 return NULL;
80 }
81 pkcs12->authsafes->type = OBJ_nid2obj(mode);
82 switch (mode) {
83 case NID_pkcs7_data:
84 if (!(pkcs12->authsafes->d.data =
85 ASN1_OCTET_STRING_new())) {
86 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 break;
90 default:
91 PKCS12err(PKCS12_F_PKCS12_INIT,PKCS12_R_UNSUPPORTED_PKCS12_MODE);
92 PKCS12_free(pkcs12);
93 return NULL;
94 break;
95 }
96
97 return pkcs12;
98}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_key.c b/src/lib/libssl/src/crypto/pkcs12/p12_key.c
new file mode 100644
index 0000000000..25d8cdae57
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_key.c
@@ -0,0 +1,182 @@
1/* p12_key.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63
64/* Uncomment out this line to get debugging info about key generation */
65/*#define DEBUG_KEYGEN*/
66#ifdef DEBUG_KEYGEN
67#include <bio.h>
68extern BIO *bio_err;
69void h__dump (unsigned char *p, int len);
70#endif
71
72/* PKCS12 compatible key/IV generation */
73#ifndef min
74#define min(a,b) ((a) < (b) ? (a) : (b))
75#endif
76
77int PKCS12_key_gen_asc (const char *pass, int passlen, unsigned char *salt,
78 int saltlen, int id, int iter, int n, unsigned char *out,
79 const EVP_MD *md_type)
80{
81 int ret;
82 unsigned char *unipass;
83 int uniplen;
84 if (!asc2uni (pass, &unipass, &uniplen)) {
85 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
86 return 0;
87 }
88 ret = PKCS12_key_gen_uni (unipass, uniplen, salt, saltlen,
89 id, iter, n, out, md_type);
90 memset(unipass, 0, uniplen); /* Clear password from memory */
91 Free(unipass);
92 return ret;
93}
94
95int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt,
96 int saltlen, int id, int iter, int n, unsigned char *out,
97 const EVP_MD *md_type)
98{
99 unsigned char *B, *D, *I, *p, *Ai;
100 int Slen, Plen, Ilen;
101 int i, j, u, v;
102 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
103 EVP_MD_CTX ctx;
104#ifdef DEBUG_KEYGEN
105 unsigned char *tmpout = out;
106 int tmpn = n;
107 BIO_printf (bio_err, "KEYGEN DEBUG\n");
108 BIO_printf (bio_err, "ID %d, ITER %d\n", id, iter);
109 BIO_printf (bio_err, "Password (length %d):\n", passlen);
110 h__dump (pass, passlen);
111 BIO_printf (bio_err, "Salt (length %d):\n", saltlen);
112 h__dump (salt, saltlen);
113 BIO_printf (bio_err, "ID %d, ITER %d\n\n", id, iter);
114#endif
115 v = EVP_MD_block_size (md_type);
116 u = EVP_MD_size (md_type);
117 D = Malloc (v);
118 Ai = Malloc (u);
119 B = Malloc (v + 1);
120 Slen = v * ((saltlen+v-1)/v);
121 Plen = v * ((passlen+v-1)/v);
122 Ilen = Slen + Plen;
123 I = Malloc (Ilen);
124 Ij = BN_new();
125 Bpl1 = BN_new();
126 if (!D || !Ai || !B || !I || !Ij || !Bpl1) {
127 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
128 return 0;
129 }
130 for (i = 0; i < v; i++) D[i] = id;
131 p = I;
132 for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen];
133 for (i = 0; i < Plen; i++) *p++ = pass[i % passlen];
134 for (;;) {
135 EVP_DigestInit (&ctx, md_type);
136 EVP_DigestUpdate (&ctx, D, v);
137 EVP_DigestUpdate (&ctx, I, Ilen);
138 EVP_DigestFinal (&ctx, Ai, NULL);
139 for (j = 1; j < iter; j++) {
140 EVP_DigestInit (&ctx, md_type);
141 EVP_DigestUpdate (&ctx, Ai, u);
142 EVP_DigestFinal (&ctx, Ai, NULL);
143 }
144 memcpy (out, Ai, min (n, u));
145 if (u >= n) {
146 Free (Ai);
147 Free (B);
148 Free (D);
149 Free (I);
150 BN_free (Ij);
151 BN_free (Bpl1);
152#ifdef DEBUG_KEYGEN
153 BIO_printf (bio_err, "Output KEY (length %d)\n", tmpn);
154 h__dump (tmpout, tmpn);
155#endif
156 return 1;
157 }
158 n -= u;
159 out += u;
160 for (j = 0; j < v; j++) B[j] = Ai[j % u];
161 /* Work out B + 1 first then can use B as tmp space */
162 BN_bin2bn (B, v, Bpl1);
163 BN_add_word (Bpl1, 1);
164 for (j = 0; j < Ilen ; j+=v) {
165 BN_bin2bn (I + j, v, Ij);
166 BN_add (Ij, Ij, Bpl1);
167 BN_bn2bin (Ij, B);
168 /* If more than 2^(v*8) - 1 cut off MSB */
169 if (BN_num_bytes (Ij) > v) {
170 BN_bn2bin (Ij, B);
171 memcpy (I + j, B + 1, v);
172 } else BN_bn2bin (Ij, I + j);
173 }
174 }
175}
176#ifdef DEBUG_KEYGEN
177void h__dump (unsigned char *p, int len)
178{
179 for (; len --; p++) BIO_printf (bio_err, "%02X", *p);
180 BIO_printf (bio_err, "\n");
181}
182#endif
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_kiss.c b/src/lib/libssl/src/crypto/pkcs12/p12_kiss.c
new file mode 100644
index 0000000000..767e1303da
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_kiss.c
@@ -0,0 +1,238 @@
1/* p12_kiss.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Simplified PKCS#12 routines */
64
65static int parse_pk12( PKCS12 *p12, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca);
66static int parse_bags( STACK *bags, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca, ASN1_OCTET_STRING **keyid, char *keymatch);
67static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca, ASN1_OCTET_STRING **keyid, char *keymatch);
68/* Parse and decrypt a PKCS#12 structure returning user key, user cert
69 * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
70 * or it should point to a valid STACK structure. pkey and cert can be
71 * passed unitialised.
72 */
73
74int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
75 STACK **ca)
76{
77
78/* Check for NULL PKCS12 structure */
79
80if(!p12) {
81 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
82 return 0;
83}
84
85/* Allocate stack for ca certificates if needed */
86if ((ca != NULL) && (*ca == NULL)) {
87 if (!(*ca = sk_new(NULL))) {
88 PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91}
92
93if(pkey) *pkey = NULL;
94if(cert) *cert = NULL;
95
96/* Check the mac */
97
98if (!PKCS12_verify_mac (p12, pass, -1)) {
99 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
100 goto err;
101}
102
103if (!parse_pk12 (p12, pass, -1, pkey, cert, ca)) {
104 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
105 goto err;
106}
107
108return 1;
109
110err:
111
112if (pkey && *pkey) EVP_PKEY_free (*pkey);
113if (cert && *cert) X509_free (*cert);
114if (ca) sk_pop_free (*ca, X509_free);
115return 0;
116
117}
118
119/* Parse the outer PKCS#12 structure */
120
121static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
122 EVP_PKEY **pkey, X509 **cert, STACK **ca)
123{
124 STACK *asafes, *bags;
125 int i, bagnid;
126 PKCS7 *p7;
127 ASN1_OCTET_STRING *keyid = NULL;
128 char keymatch = 0;
129 if (!( asafes = M_PKCS12_unpack_authsafes (p12))) return 0;
130 for (i = 0; i < sk_num (asafes); i++) {
131 p7 = (PKCS7 *) sk_value (asafes, i);
132 bagnid = OBJ_obj2nid (p7->type);
133 if (bagnid == NID_pkcs7_data) {
134 bags = M_PKCS12_unpack_p7data (p7);
135 } else if (bagnid == NID_pkcs7_encrypted) {
136 bags = M_PKCS12_unpack_p7encdata (p7, pass, passlen);
137 } else continue;
138 if (!bags) {
139 sk_pop_free (asafes, PKCS7_free);
140 return 0;
141 }
142 if (!parse_bags (bags, pass, passlen, pkey, cert, ca,
143 &keyid, &keymatch)) {
144 sk_pop_free (bags, PKCS12_SAFEBAG_free);
145 sk_pop_free (asafes, PKCS7_free);
146 return 0;
147 }
148 sk_pop_free (bags, PKCS12_SAFEBAG_free);
149 }
150 sk_pop_free (asafes, PKCS7_free);
151 if (keyid) ASN1_OCTET_STRING_free (keyid);
152 return 1;
153}
154
155
156static int parse_bags (STACK *bags, const char *pass, int passlen,
157 EVP_PKEY **pkey, X509 **cert, STACK **ca,
158 ASN1_OCTET_STRING **keyid, char *keymatch)
159{
160 int i;
161 for (i = 0; i < sk_num (bags); i++) {
162 if (!parse_bag ((PKCS12_SAFEBAG *)sk_value (bags, i),
163 pass, passlen, pkey, cert, ca, keyid,
164 keymatch)) return 0;
165 }
166 return 1;
167}
168
169#define MATCH_KEY 0x1
170#define MATCH_CERT 0x2
171#define MATCH_ALL 0x3
172
173static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,
174 EVP_PKEY **pkey, X509 **cert, STACK **ca,
175 ASN1_OCTET_STRING **keyid,
176 char *keymatch)
177{
178 PKCS8_PRIV_KEY_INFO *p8;
179 X509 *x509;
180 ASN1_OCTET_STRING *lkey = NULL;
181 ASN1_TYPE *attrib;
182
183
184 if ((attrib = PKCS12_get_attr (bag, NID_localKeyID)))
185 lkey = attrib->value.octet_string;
186
187 /* Check for any local key id matching (if needed) */
188 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
189 if (*keyid) {
190 if (ASN1_OCTET_STRING_cmp (*keyid, lkey)) lkey = NULL;
191 } else {
192 if (!(*keyid = ASN1_OCTET_STRING_dup (lkey))) {
193 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
194 return 0;
195 }
196 }
197 }
198
199 switch (M_PKCS12_bag_type(bag))
200 {
201 case NID_keyBag:
202 if (!lkey || !pkey) return 1;
203 if (!(*pkey = EVP_PKCS82PKEY (bag->value.keybag))) return 0;
204 *keymatch |= MATCH_KEY;
205 break;
206
207 case NID_pkcs8ShroudedKeyBag:
208 if (!lkey || !pkey) return 1;
209 if (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen)))
210 return 0;
211 *pkey = EVP_PKCS82PKEY (p8);
212 PKCS8_PRIV_KEY_INFO_free (p8);
213 if (!(*pkey)) return 0;
214 *keymatch |= MATCH_KEY;
215 break;
216
217 case NID_certBag:
218 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
219 return 1;
220 if (!(x509 = M_PKCS12_certbag2x509(bag))) return 0;
221 if (lkey) {
222 *keymatch |= MATCH_CERT;
223 if (cert) *cert = x509;
224 } else if (ca) sk_push (*ca, (char *)x509);
225 break;
226
227 case NID_safeContentsBag:
228 return parse_bags(bag->value.safes, pass, passlen,
229 pkey, cert, ca, keyid, keymatch);
230 break;
231
232 default:
233 return 1;
234 break;
235 }
236 return 1;
237}
238
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c b/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c
new file mode 100644
index 0000000000..bac558d6b9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c
@@ -0,0 +1,170 @@
1/* p12_mutl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef NO_HMAC
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/hmac.h>
63#include <openssl/rand.h>
64#include <openssl/pkcs12.h>
65
66/* Generate a MAC */
67int PKCS12_gen_mac (PKCS12 *p12, const char *pass, int passlen,
68 unsigned char *mac, unsigned int *maclen)
69{
70 const EVP_MD *md_type;
71 HMAC_CTX hmac;
72 unsigned char key[PKCS12_MAC_KEY_LENGTH], *salt;
73 int saltlen, iter;
74 salt = p12->mac->salt->data;
75 saltlen = p12->mac->salt->length;
76 if (!p12->mac->iter) iter = 1;
77 else iter = ASN1_INTEGER_get (p12->mac->iter);
78 if(!(md_type =
79 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) {
80 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
81 return 0;
82 }
83 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
84 PKCS12_MAC_KEY_LENGTH, key, md_type)) {
85 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
86 return 0;
87 }
88 HMAC_Init (&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type);
89 HMAC_Update (&hmac, p12->authsafes->d.data->data,
90 p12->authsafes->d.data->length);
91 HMAC_Final (&hmac, mac, maclen);
92 return 1;
93}
94
95/* Verify the mac */
96int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen)
97{
98 unsigned char mac[EVP_MAX_MD_SIZE];
99 unsigned int maclen;
100 if(p12->mac == NULL) {
101 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
102 return 0;
103 }
104 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
105 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
106 return 0;
107 }
108 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
109 || memcmp (mac, p12->mac->dinfo->digest->data, maclen)) {
110 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_VERIFY_ERROR);
111 return 0;
112 }
113 return 1;
114}
115
116/* Set a mac */
117
118int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
119 unsigned char *salt, int saltlen, int iter, EVP_MD *md_type)
120{
121 unsigned char mac[EVP_MAX_MD_SIZE];
122 unsigned int maclen;
123
124 if (!md_type) md_type = EVP_sha1();
125 if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
126 PKCS12_ERROR) {
127 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
128 return 0;
129 }
130 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
131 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
132 return 0;
133 }
134 if (!(ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
135 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
136 return 0;
137 }
138 return 1;
139}
140
141/* Set up a mac structure */
142int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
143 EVP_MD *md_type)
144{
145 if (!(p12->mac = PKCS12_MAC_DATA_new ())) return PKCS12_ERROR;
146 if (iter > 1) {
147 if(!(p12->mac->iter = ASN1_INTEGER_new())) {
148 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
149 return 0;
150 }
151 ASN1_INTEGER_set (p12->mac->iter, iter);
152 }
153 if (!saltlen) saltlen = PKCS12_SALT_LEN;
154 p12->mac->salt->length = saltlen;
155 if (!(p12->mac->salt->data = Malloc (saltlen))) {
156 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 if (!salt) RAND_bytes (p12->mac->salt->data, saltlen);
160 else memcpy (p12->mac->salt->data, salt, saltlen);
161 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
162 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
163 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
164 return 0;
165 }
166 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
167
168 return 1;
169}
170#endif
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_npas.c b/src/lib/libssl/src/crypto/pkcs12/p12_npas.c
new file mode 100644
index 0000000000..ee71707e2c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_npas.c
@@ -0,0 +1,212 @@
1/* p12_npas.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/pkcs12.h>
65
66/* PKCS#12 password change routine */
67
68static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass);
69static int newpass_bags(STACK *bags, char *oldpass, char *newpass);
70static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass);
71static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
72
73/*
74 * Change the password on a PKCS#12 structure.
75 */
76
77int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
78{
79
80/* Check for NULL PKCS12 structure */
81
82if(!p12) {
83 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
84 return 0;
85}
86
87/* Check the mac */
88
89if (!PKCS12_verify_mac(p12, oldpass, -1)) {
90 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
91 return 0;
92}
93
94if (!newpass_p12(p12, oldpass, newpass)) {
95 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
96 return 0;
97}
98
99return 1;
100
101}
102
103/* Parse the outer PKCS#12 structure */
104
105static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
106{
107 STACK *asafes, *newsafes, *bags;
108 int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen;
109 PKCS7 *p7, *p7new;
110 ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
111 unsigned char mac[EVP_MAX_MD_SIZE];
112 unsigned int maclen;
113 if (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0;
114 if(!(newsafes = sk_new(NULL))) return 0;
115 for (i = 0; i < sk_num (asafes); i++) {
116 p7 = (PKCS7 *) sk_value(asafes, i);
117 bagnid = OBJ_obj2nid(p7->type);
118 if (bagnid == NID_pkcs7_data) {
119 bags = M_PKCS12_unpack_p7data(p7);
120 } else if (bagnid == NID_pkcs7_encrypted) {
121 bags = M_PKCS12_unpack_p7encdata(p7, oldpass, -1);
122 alg_get(p7->d.encrypted->enc_data->algorithm,
123 &pbe_nid, &pbe_iter, &pbe_saltlen);
124 } else continue;
125 if (!bags) {
126 sk_pop_free(asafes, PKCS7_free);
127 return 0;
128 }
129 if (!newpass_bags(bags, oldpass, newpass)) {
130 sk_pop_free(bags, PKCS12_SAFEBAG_free);
131 sk_pop_free(asafes, PKCS7_free);
132 return 0;
133 }
134 /* Repack bag in same form with new password */
135 if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
136 else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
137 pbe_saltlen, pbe_iter, bags);
138 sk_pop_free(bags, PKCS12_SAFEBAG_free);
139 if(!p7new) {
140 sk_pop_free(asafes, PKCS7_free);
141 return 0;
142 }
143 sk_push(newsafes, (char *)p7new);
144 }
145 sk_pop_free(asafes, PKCS7_free);
146
147 /* Repack safe: save old safe in case of error */
148
149 p12_data_tmp = p12->authsafes->d.data;
150 if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
151 if(!M_PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
152
153 if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
154 if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
155 if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
156 ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
157 p12->mac->dinfo->digest = macnew;
158 ASN1_OCTET_STRING_free(p12_data_tmp);
159
160 return 1;
161
162 saferr:
163 /* Restore old safe */
164 ASN1_OCTET_STRING_free(p12->authsafes->d.data);
165 ASN1_OCTET_STRING_free(macnew);
166 p12->authsafes->d.data = p12_data_tmp;
167 return 0;
168
169}
170
171
172static int newpass_bags(STACK *bags, char *oldpass, char *newpass)
173{
174 int i;
175 for (i = 0; i < sk_num(bags); i++) {
176 if (!newpass_bag((PKCS12_SAFEBAG *)sk_value(bags, i),
177 oldpass, newpass)) return 0;
178 }
179 return 1;
180}
181
182/* Change password of safebag: only needs handle shrouded keybags */
183
184static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
185{
186 PKCS8_PRIV_KEY_INFO *p8;
187 X509_SIG *p8new;
188 int p8_nid, p8_saltlen, p8_iter;
189
190 if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
191
192 if (!(p8 = M_PKCS12_decrypt_skey(bag, oldpass, -1))) return 0;
193 alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen);
194 if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
195 p8_iter, p8))) return 0;
196 X509_SIG_free(bag->value.shkeybag);
197 bag->value.shkeybag = p8new;
198 return 1;
199}
200
201static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
202{
203 PBEPARAM *pbe;
204 unsigned char *p;
205 p = alg->parameter->value.sequence->data;
206 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
207 *pnid = OBJ_obj2nid(alg->algorithm);
208 *piter = ASN1_INTEGER_get(pbe->iter);
209 *psaltlen = pbe->salt->length;
210 PBEPARAM_free(pbe);
211 return 0;
212}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_p8d.c b/src/lib/libssl/src/crypto/pkcs12/p12_p8d.c
new file mode 100644
index 0000000000..3c6f377933
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_p8d.c
@@ -0,0 +1,68 @@
1/* p12_p8d.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen)
64{
65 return PKCS12_item_decrypt_d2i(p8->algor, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass,
66 passlen, p8->digest, 1);
67}
68
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_p8e.c b/src/lib/libssl/src/crypto/pkcs12/p12_p8e.c
new file mode 100644
index 0000000000..3d47956652
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_p8e.c
@@ -0,0 +1,97 @@
1/* p12_p8e.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
64 const char *pass, int passlen,
65 unsigned char *salt, int saltlen, int iter,
66 PKCS8_PRIV_KEY_INFO *p8inf)
67{
68 X509_SIG *p8 = NULL;
69 X509_ALGOR *pbe;
70
71 if (!(p8 = X509_SIG_new())) {
72 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
73 goto err;
74 }
75
76 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
77 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
78 if(!pbe) {
79 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
80 goto err;
81 }
82 X509_ALGOR_free(p8->algor);
83 p8->algor = pbe;
84 M_ASN1_OCTET_STRING_free(p8->digest);
85 p8->digest = PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO),
86 pass, passlen, p8inf, 1);
87 if(!p8->digest) {
88 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
89 goto err;
90 }
91
92 return p8;
93
94 err:
95 X509_SIG_free(p8);
96 return NULL;
97}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_utl.c b/src/lib/libssl/src/crypto/pkcs12/p12_utl.c
new file mode 100644
index 0000000000..2adcbc95e1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_utl.c
@@ -0,0 +1,118 @@
1/* p12_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Cheap and nasty Unicode stuff */
64
65unsigned char *asc2uni (const char *asc, unsigned char **uni, int *unilen)
66{
67 int ulen, i;
68 unsigned char *unitmp;
69 ulen = strlen(asc)*2 + 2;
70 if (!(unitmp = Malloc (ulen))) return NULL;
71 for (i = 0; i < ulen; i+=2) {
72 unitmp[i] = 0;
73 unitmp[i + 1] = asc[i>>1];
74 }
75 if (unilen) *unilen = ulen;
76 if (uni) *uni = unitmp;
77 return unitmp;
78}
79
80char *uni2asc (unsigned char *uni, int unilen)
81{
82 int asclen, i;
83 char *asctmp;
84 asclen = unilen / 2;
85 /* If no terminating zero allow for one */
86 if (uni[unilen - 1]) asclen++;
87 uni++;
88 if (!(asctmp = Malloc (asclen))) return NULL;
89 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
90 asctmp[asclen - 1] = 0;
91 return asctmp;
92}
93
94int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12)
95{
96 return ASN1_i2d_bio((int(*)())i2d_PKCS12, bp, (unsigned char *)p12);
97}
98
99#ifndef NO_FP_API
100int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
101{
102 return ASN1_i2d_fp((int(*)())i2d_PKCS12, fp, (unsigned char *)p12);
103}
104#endif
105
106PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12)
107{
108 return (PKCS12 *)ASN1_d2i_bio((char *(*)())PKCS12_new,
109 (char *(*)())d2i_PKCS12, bp, (unsigned char **)p12);
110}
111#ifndef NO_FP_API
112PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
113{
114 return (PKCS12 *)ASN1_d2i_fp((char *(*)())PKCS12_new,
115 (char *(*)())d2i_PKCS12, fp, (unsigned char **)(p12));
116}
117#endif
118
diff --git a/src/lib/libssl/src/crypto/pkcs12/pk12err.c b/src/lib/libssl/src/crypto/pkcs12/pk12err.c
new file mode 100644
index 0000000000..38d7be7675
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/pk12err.c
@@ -0,0 +1,136 @@
1/* crypto/pkcs12/pk12err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/pkcs12.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA PKCS12_str_functs[]=
67 {
68{ERR_PACK(0,PKCS12_F_PARSE_BAGS,0), "PARSE_BAGS"},
69{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME,0), "PKCS12_ADD_FRIENDLYNAME"},
70{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,0), "PKCS12_add_friendlyname_asc"},
71{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,0), "PKCS12_add_friendlyname_uni"},
72{ERR_PACK(0,PKCS12_F_PKCS12_ADD_LOCALKEYID,0), "PKCS12_add_localkeyid"},
73{ERR_PACK(0,PKCS12_F_PKCS12_CREATE,0), "PKCS12_create"},
74{ERR_PACK(0,PKCS12_F_PKCS12_DECRYPT_D2I,0), "PKCS12_decrypt_d2i"},
75{ERR_PACK(0,PKCS12_F_PKCS12_GEN_MAC,0), "PKCS12_gen_mac"},
76{ERR_PACK(0,PKCS12_F_PKCS12_I2D_ENCRYPT,0), "PKCS12_i2d_encrypt"},
77{ERR_PACK(0,PKCS12_F_PKCS12_INIT,0), "PKCS12_init"},
78{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_ASC,0), "PKCS12_key_gen_asc"},
79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"},
80{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"},
81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"},
82{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"},
83{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"},
84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"},
85{ERR_PACK(0,PKCS12_F_PKCS12_PARSE,0), "PKCS12_parse"},
86{ERR_PACK(0,PKCS12_F_PKCS12_PBE_CRYPT,0), "PKCS12_pbe_crypt"},
87{ERR_PACK(0,PKCS12_F_PKCS12_PBE_KEYIVGEN,0), "PKCS12_PBE_keyivgen"},
88{ERR_PACK(0,PKCS12_F_PKCS12_SETUP_MAC,0), "PKCS12_setup_mac"},
89{ERR_PACK(0,PKCS12_F_PKCS12_SET_MAC,0), "PKCS12_set_mac"},
90{ERR_PACK(0,PKCS12_F_PKCS8_ADD_KEYUSAGE,0), "PKCS8_add_keyusage"},
91{ERR_PACK(0,PKCS12_F_PKCS8_ENCRYPT,0), "PKCS8_encrypt"},
92{ERR_PACK(0,PKCS12_F_VERIFY_MAC,0), "VERIFY_MAC"},
93{0,NULL}
94 };
95
96static ERR_STRING_DATA PKCS12_str_reasons[]=
97 {
98{PKCS12_R_CANT_PACK_STRUCTURE ,"cant pack structure"},
99{PKCS12_R_DECODE_ERROR ,"decode error"},
100{PKCS12_R_ENCODE_ERROR ,"encode error"},
101{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"},
102{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
103{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"},
104{PKCS12_R_IV_GEN_ERROR ,"iv gen error"},
105{PKCS12_R_KEY_GEN_ERROR ,"key gen error"},
106{PKCS12_R_MAC_ABSENT ,"mac absent"},
107{PKCS12_R_MAC_GENERATION_ERROR ,"mac generation error"},
108{PKCS12_R_MAC_SETUP_ERROR ,"mac setup error"},
109{PKCS12_R_MAC_STRING_SET_ERROR ,"mac string set error"},
110{PKCS12_R_MAC_VERIFY_ERROR ,"mac verify error"},
111{PKCS12_R_MAC_VERIFY_FAILURE ,"mac verify failure"},
112{PKCS12_R_PARSE_ERROR ,"parse error"},
113{PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR ,"pkcs12 algor cipherinit error"},
114{PKCS12_R_PKCS12_CIPHERFINAL_ERROR ,"pkcs12 cipherfinal error"},
115{PKCS12_R_PKCS12_PBE_CRYPT_ERROR ,"pkcs12 pbe crypt error"},
116{PKCS12_R_UNKNOWN_DIGEST_ALGORITHM ,"unknown digest algorithm"},
117{PKCS12_R_UNSUPPORTED_PKCS12_MODE ,"unsupported pkcs12 mode"},
118{0,NULL}
119 };
120
121#endif
122
123void ERR_load_PKCS12_strings(void)
124 {
125 static int init=1;
126
127 if (init)
128 {
129 init=0;
130#ifndef NO_ERR
131 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_functs);
132 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_reasons);
133#endif
134
135 }
136 }
diff --git a/src/lib/libssl/src/crypto/pkcs12/pkcs12.h b/src/lib/libssl/src/crypto/pkcs12/pkcs12.h
new file mode 100644
index 0000000000..4cfba5e6c6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs12/pkcs12.h
@@ -0,0 +1,337 @@
1/* pkcs12.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_PKCS12_H
60#define HEADER_PKCS12_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/bio.h>
67#include <openssl/x509.h>
68
69#define PKCS12_KEY_ID 1
70#define PKCS12_IV_ID 2
71#define PKCS12_MAC_ID 3
72
73/* Default iteration count */
74#ifndef PKCS12_DEFAULT_ITER
75#define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
76#endif
77
78#define PKCS12_MAC_KEY_LENGTH 20
79
80#define PKCS12_SALT_LEN 8
81
82/* Uncomment out next line for unicode password and names, otherwise ASCII */
83
84/*#define PBE_UNICODE*/
85
86#ifdef PBE_UNICODE
87#define PKCS12_key_gen PKCS12_key_gen_uni
88#define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni
89#else
90#define PKCS12_key_gen PKCS12_key_gen_asc
91#define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc
92#endif
93
94/* MS key usage constants */
95
96#define KEY_EX 0x10
97#define KEY_SIG 0x80
98
99typedef struct {
100X509_SIG *dinfo;
101ASN1_OCTET_STRING *salt;
102ASN1_INTEGER *iter; /* defaults to 1 */
103} PKCS12_MAC_DATA;
104
105typedef struct {
106ASN1_INTEGER *version;
107PKCS12_MAC_DATA *mac;
108PKCS7 *authsafes;
109} PKCS12;
110
111typedef struct {
112ASN1_OBJECT *type;
113union {
114 struct pkcs12_bag_st *bag; /* secret, crl and certbag */
115 struct pkcs8_priv_key_info_st *keybag; /* keybag */
116 X509_SIG *shkeybag; /* shrouded key bag */
117 STACK /* PKCS12_SAFEBAG */ *safes;
118 ASN1_TYPE *other;
119}value;
120STACK_OF(X509_ATTRIBUTE) *attrib;
121ASN1_TYPE *rest;
122} PKCS12_SAFEBAG;
123
124typedef struct pkcs12_bag_st {
125ASN1_OBJECT *type;
126union {
127 ASN1_OCTET_STRING *x509cert;
128 ASN1_OCTET_STRING *x509crl;
129 ASN1_OCTET_STRING *octet;
130 ASN1_IA5STRING *sdsicert;
131 ASN1_TYPE *other; /* Secret or other bag */
132}value;
133} PKCS12_BAGS;
134
135#define PKCS12_ERROR 0
136#define PKCS12_OK 1
137
138#define M_PKCS12_bag_type(bag) OBJ_obj2nid(bag->type)
139#define M_PKCS12_cert_bag_type(bag) OBJ_obj2nid(bag->value.bag->type)
140#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type
141
142#define M_PKCS12_x5092certbag(x509) \
143PKCS12_pack_safebag ((char *)(x509), i2d_X509, NID_x509Certificate, NID_certBag)
144
145#define M_PKCS12_x509crl2certbag(crl) \
146PKCS12_pack_safebag ((char *)(crl), i2d_X509CRL, NID_x509Crl, NID_crlBag)
147
148#define M_PKCS12_certbag2x509(bg) \
149(X509 *) ASN1_unpack_string ((bg)->value.bag->value.octet, \
150(char *(*)())d2i_X509)
151
152#define M_PKCS12_certbag2x509crl(bg) \
153(X509CRL *) ASN1_unpack_string ((bg)->value.bag->value.octet, \
154(char *(*)())d2i_X509CRL)
155
156/*#define M_PKCS12_pkcs82rsa(p8) \
157(RSA *) ASN1_unpack_string ((p8)->pkey, (char *(*)())d2i_RSAPrivateKey)*/
158
159#define M_PKCS12_unpack_p7data(p7) \
160ASN1_seq_unpack ((p7)->d.data->data, p7->d.data->length, \
161 (char *(*)())d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free)
162
163#define M_PKCS12_pack_authsafes(p12, safes) \
164ASN1_seq_pack((safes), (int (*)())i2d_PKCS7,\
165 &(p12)->authsafes->d.data->data, &(p12)->authsafes->d.data->length)
166
167#define M_PKCS12_unpack_authsafes(p12) \
168ASN1_seq_unpack((p12)->authsafes->d.data->data, \
169 (p12)->authsafes->d.data->length, (char *(*)())d2i_PKCS7, \
170 PKCS7_free)
171
172#define M_PKCS12_unpack_p7encdata(p7, pass, passlen) \
173(STACK *) PKCS12_decrypt_d2i ((p7)->d.encrypted->enc_data->algorithm,\
174 (char *(*)())d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free, \
175 (pass), (passlen), \
176 (p7)->d.encrypted->enc_data->enc_data, 3)
177
178#define M_PKCS12_decrypt_skey(bag, pass, passlen) \
179(PKCS8_PRIV_KEY_INFO *) PKCS12_decrypt_d2i ((bag)->value.shkeybag->algor, \
180(char *(*)())d2i_PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free, \
181 (pass), (passlen), \
182 (bag)->value.shkeybag->digest, 2)
183
184#define M_PKCS8_decrypt(p8, pass, passlen) \
185(PKCS8_PRIV_KEY_INFO *) PKCS12_decrypt_d2i ((p8)->algor, \
186(char *(*)())d2i_PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free,\
187 (pass), (passlen), (p8)->digest, 2)
188
189#define PKCS12_get_attr(bag, attr_nid) \
190 PKCS12_get_attr_gen(bag->attrib, attr_nid)
191
192#define PKCS8_get_attr(p8, attr_nid) \
193 PKCS12_get_attr_gen(p8->attributes, attr_nid)
194
195#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0)
196
197
198PKCS12_SAFEBAG *PKCS12_pack_safebag(char *obj, int (*i2d)(), int nid1, int nid2);
199PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8);
200X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
201 const char *pass, int passlen,
202 unsigned char *salt, int saltlen, int iter,
203 PKCS8_PRIV_KEY_INFO *p8);
204PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
205 int passlen, unsigned char *salt,
206 int saltlen, int iter,
207 PKCS8_PRIV_KEY_INFO *p8);
208PKCS7 *PKCS12_pack_p7data(STACK *sk);
209PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
210 unsigned char *salt, int saltlen, int iter,
211 STACK *bags);
212int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen);
213int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
214 int namelen);
215int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,
216 int namelen);
217int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
218ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid);
219char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
220unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
221 int passlen, unsigned char *in, int inlen,
222 unsigned char **data, int *datalen, int en_de);
223char *PKCS12_decrypt_d2i(X509_ALGOR *algor, char *(*d2i)(),
224 void (*free_func)(), const char *pass, int passlen,
225 ASN1_STRING *oct, int seq);
226ASN1_STRING *PKCS12_i2d_encrypt(X509_ALGOR *algor, int (*i2d)(),
227 const char *pass, int passlen, char *obj,
228 int seq);
229PKCS12 *PKCS12_init(int mode);
230int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
231 int saltlen, int id, int iter, int n,
232 unsigned char *out, const EVP_MD *md_type);
233int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type);
234int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
235 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md_type,
236 int en_de);
237int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
238 unsigned char *mac, unsigned int *maclen);
239int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
240int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
241 unsigned char *salt, int saltlen, int iter,
242 EVP_MD *md_type);
243int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
244 int saltlen, EVP_MD *md_type);
245unsigned char *asc2uni(const char *asc, unsigned char **uni, int *unilen);
246char *uni2asc(unsigned char *uni, int unilen);
247int i2d_PKCS12_BAGS(PKCS12_BAGS *a, unsigned char **pp);
248PKCS12_BAGS *PKCS12_BAGS_new(void);
249PKCS12_BAGS *d2i_PKCS12_BAGS(PKCS12_BAGS **a, unsigned char **pp, long length);
250void PKCS12_BAGS_free(PKCS12_BAGS *a);
251int i2d_PKCS12(PKCS12 *a, unsigned char **pp);
252PKCS12 *d2i_PKCS12(PKCS12 **a, unsigned char **pp, long length);
253PKCS12 *PKCS12_new(void);
254void PKCS12_free(PKCS12 *a);
255int i2d_PKCS12_MAC_DATA(PKCS12_MAC_DATA *a, unsigned char **pp);
256PKCS12_MAC_DATA *PKCS12_MAC_DATA_new(void);
257PKCS12_MAC_DATA *d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, unsigned char **pp,
258 long length);
259void PKCS12_MAC_DATA_free(PKCS12_MAC_DATA *a);
260int i2d_PKCS12_SAFEBAG(PKCS12_SAFEBAG *a, unsigned char **pp);
261PKCS12_SAFEBAG *PKCS12_SAFEBAG_new(void);
262PKCS12_SAFEBAG *d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **a, unsigned char **pp,
263 long length);
264void PKCS12_SAFEBAG_free(PKCS12_SAFEBAG *a);
265void ERR_load_PKCS12_strings(void);
266void PKCS12_PBE_add(void);
267int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
268 STACK **ca);
269PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
270 STACK *ca, int nid_key, int nid_cert, int iter,
271 int mac_iter, int keytype);
272int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
273int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
274PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
275PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
276
277/* BEGIN ERROR CODES */
278/* The following lines are auto generated by the script mkerr.pl. Any changes
279 * made after this point may be overwritten when the script is next run.
280 */
281
282/* Error codes for the PKCS12 functions. */
283
284/* Function codes. */
285#define PKCS12_F_PARSE_BAGS 103
286#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
287#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
288#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
289#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
290#define PKCS12_F_PKCS12_CREATE 105
291#define PKCS12_F_PKCS12_DECRYPT_D2I 106
292#define PKCS12_F_PKCS12_GEN_MAC 107
293#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
294#define PKCS12_F_PKCS12_INIT 109
295#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
296#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
297#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
298#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
299#define PKCS12_F_PKCS12_PACK_P7DATA 114
300#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
301#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
302#define PKCS12_F_PKCS12_PARSE 118
303#define PKCS12_F_PKCS12_PBE_CRYPT 119
304#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
305#define PKCS12_F_PKCS12_SETUP_MAC 122
306#define PKCS12_F_PKCS12_SET_MAC 123
307#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
308#define PKCS12_F_PKCS8_ENCRYPT 125
309#define PKCS12_F_VERIFY_MAC 126
310
311/* Reason codes. */
312#define PKCS12_R_CANT_PACK_STRUCTURE 100
313#define PKCS12_R_DECODE_ERROR 101
314#define PKCS12_R_ENCODE_ERROR 102
315#define PKCS12_R_ENCRYPT_ERROR 103
316#define PKCS12_R_INVALID_NULL_ARGUMENT 104
317#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
318#define PKCS12_R_IV_GEN_ERROR 106
319#define PKCS12_R_KEY_GEN_ERROR 107
320#define PKCS12_R_MAC_ABSENT 108
321#define PKCS12_R_MAC_GENERATION_ERROR 109
322#define PKCS12_R_MAC_SETUP_ERROR 110
323#define PKCS12_R_MAC_STRING_SET_ERROR 111
324#define PKCS12_R_MAC_VERIFY_ERROR 112
325#define PKCS12_R_MAC_VERIFY_FAILURE 113
326#define PKCS12_R_PARSE_ERROR 114
327#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
328#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
329#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
330#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
331#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
332
333#ifdef __cplusplus
334}
335#endif
336#endif
337
diff --git a/src/lib/libssl/src/crypto/pkcs7/bio_ber.c b/src/lib/libssl/src/crypto/pkcs7/bio_ber.c
new file mode 100644
index 0000000000..2f17723e98
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/bio_ber.c
@@ -0,0 +1,450 @@
1/* crypto/evp/bio_ber.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int ber_write(BIO *h,char *buf,int num);
66static int ber_read(BIO *h,char *buf,int size);
67/*static int ber_puts(BIO *h,char *str); */
68/*static int ber_gets(BIO *h,char *str,int size); */
69static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int ber_new(BIO *h);
71static int ber_free(BIO *data);
72#define BER_BUF_SIZE (32)
73
74/* This is used to hold the state of the BER objects being read. */
75typedef struct ber_struct
76 {
77 int tag;
78 int class;
79 long length;
80 int inf;
81 int num_left;
82 int depth;
83 } BER_CTX;
84
85typedef struct bio_ber_struct
86 {
87 int tag;
88 int class;
89 long length;
90 int inf;
91
92 /* most of the following are used when doing non-blocking IO */
93 /* reading */
94 long num_left; /* number of bytes still to read/write in block */
95 int depth; /* used with idefinite encoding. */
96 int finished; /* No more read data */
97
98 /* writting */
99 char *w_addr;
100 int w_offset;
101 int w_left;
102
103 int buf_len;
104 int buf_off;
105 unsigned char buf[BER_BUF_SIZE];
106 } BIO_BER_CTX;
107
108static BIO_METHOD methods_ber=
109 {
110 BIO_TYPE_CIPHER,"cipher",
111 ber_write,
112 ber_read,
113 NULL, /* ber_puts, */
114 NULL, /* ber_gets, */
115 ber_ctrl,
116 ber_new,
117 ber_free,
118 };
119
120BIO_METHOD *BIO_f_ber(void)
121 {
122 return(&methods_ber);
123 }
124
125static int ber_new(BIO *bi)
126 {
127 BIO_BER_CTX *ctx;
128
129 ctx=(BIO_BER_CTX *)Malloc(sizeof(BIO_BER_CTX));
130 if (ctx == NULL) return(0);
131
132 memset((char *)ctx,0,sizeof(BIO_BER_CTX));
133
134 bi->init=0;
135 bi->ptr=(char *)ctx;
136 bi->flags=0;
137 return(1);
138 }
139
140static int ber_free(BIO *a)
141 {
142 BIO_BER_CTX *b;
143
144 if (a == NULL) return(0);
145 b=(BIO_BER_CTX *)a->ptr;
146 memset(a->ptr,0,sizeof(BIO_BER_CTX));
147 Free(a->ptr);
148 a->ptr=NULL;
149 a->init=0;
150 a->flags=0;
151 return(1);
152 }
153
154int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx)
155 {
156 char buf[64];
157 int i,j,n;
158 int ret;
159 unsigned char *p;
160 unsigned long length
161 int tag;
162 int class;
163 long max;
164
165 BIO_clear_retry_flags(b);
166
167 /* Pack the buffer down if there is a hole at the front */
168 if (ctx->buf_off != 0)
169 {
170 p=ctx->buf;
171 j=ctx->buf_off;
172 n=ctx->buf_len-j;
173 for (i=0; i<n; i++)
174 {
175 p[0]=p[j];
176 p++;
177 }
178 ctx->buf_len-j;
179 ctx->buf_off=0;
180 }
181
182 /* If there is more room, read some more data */
183 i=BER_BUF_SIZE-ctx->buf_len;
184 if (i)
185 {
186 i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i);
187 if (i <= 0)
188 {
189 BIO_copy_next_retry(b);
190 return(i);
191 }
192 else
193 ctx->buf_len+=i;
194 }
195
196 max=ctx->buf_len;
197 p=ctx->buf;
198 ret=ASN1_get_object(&p,&length,&tag,&class,max);
199
200 if (ret & 0x80)
201 {
202 if ((ctx->buf_len < BER_BUF_SIZE) &&
203 (ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG))
204 {
205 ERR_get_error(); /* clear the error */
206 BIO_set_retry_read(b);
207 }
208 return(-1);
209 }
210
211 /* We have no error, we have a header, so make use of it */
212
213 if ((ctx->tag >= 0) && (ctx->tag != tag))
214 {
215 BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH);
216 sprintf(buf,"tag=%d, got %d",ctx->tag,tag);
217 ERR_add_error_data(1,buf);
218 return(-1);
219 }
220 if (ret & 0x01)
221 if (ret & V_ASN1_CONSTRUCTED)
222 }
223
224static int ber_read(BIO *b, char *out, int outl)
225 {
226 int ret=0,i,n;
227 BIO_BER_CTX *ctx;
228
229 BIO_clear_retry_flags(b);
230
231 if (out == NULL) return(0);
232 ctx=(BIO_BER_CTX *)b->ptr;
233
234 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
235
236 if (ctx->finished) return(0);
237
238again:
239 /* First see if we are half way through reading a block */
240 if (ctx->num_left > 0)
241 {
242 if (ctx->num_left < outl)
243 n=ctx->num_left;
244 else
245 n=outl;
246 i=BIO_read(b->next_bio,out,n);
247 if (i <= 0)
248 {
249 BIO_copy_next_retry(b);
250 return(i);
251 }
252 ctx->num_left-=i;
253 outl-=i;
254 ret+=i;
255 if (ctx->num_left <= 0)
256 {
257 ctx->depth--;
258 if (ctx->depth <= 0)
259 ctx->finished=1;
260 }
261 if (outl <= 0)
262 return(ret);
263 else
264 goto again;
265 }
266 else /* we need to read another BER header */
267 {
268 }
269 }
270
271static int ber_write(BIO *b, char *in, int inl)
272 {
273 int ret=0,n,i;
274 BIO_ENC_CTX *ctx;
275
276 ctx=(BIO_ENC_CTX *)b->ptr;
277 ret=inl;
278
279 BIO_clear_retry_flags(b);
280 n=ctx->buf_len-ctx->buf_off;
281 while (n > 0)
282 {
283 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
284 if (i <= 0)
285 {
286 BIO_copy_next_retry(b);
287 return(i);
288 }
289 ctx->buf_off+=i;
290 n-=i;
291 }
292 /* at this point all pending data has been written */
293
294 if ((in == NULL) || (inl <= 0)) return(0);
295
296 ctx->buf_off=0;
297 while (inl > 0)
298 {
299 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
300 EVP_CipherUpdate(&(ctx->cipher),
301 (unsigned char *)ctx->buf,&ctx->buf_len,
302 (unsigned char *)in,n);
303 inl-=n;
304 in+=n;
305
306 ctx->buf_off=0;
307 n=ctx->buf_len;
308 while (n > 0)
309 {
310 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
311 if (i <= 0)
312 {
313 BIO_copy_next_retry(b);
314 return(i);
315 }
316 n-=i;
317 ctx->buf_off+=i;
318 }
319 ctx->buf_len=0;
320 ctx->buf_off=0;
321 }
322 BIO_copy_next_retry(b);
323 return(ret);
324 }
325
326static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
327 {
328 BIO *dbio;
329 BIO_ENC_CTX *ctx,*dctx;
330 long ret=1;
331 int i;
332
333 ctx=(BIO_ENC_CTX *)b->ptr;
334
335 switch (cmd)
336 {
337 case BIO_CTRL_RESET:
338 ctx->ok=1;
339 ctx->finished=0;
340 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
341 ctx->cipher.berrypt);
342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
343 break;
344 case BIO_CTRL_EOF: /* More to read */
345 if (ctx->cont <= 0)
346 ret=1;
347 else
348 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
349 break;
350 case BIO_CTRL_WPENDING:
351 ret=ctx->buf_len-ctx->buf_off;
352 if (ret <= 0)
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 break;
355 case BIO_CTRL_PENDING: /* More to read in buffer */
356 ret=ctx->buf_len-ctx->buf_off;
357 if (ret <= 0)
358 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
359 break;
360 case BIO_CTRL_FLUSH:
361 /* do a final write */
362again:
363 while (ctx->buf_len != ctx->buf_off)
364 {
365 i=ber_write(b,NULL,0);
366 if (i < 0)
367 {
368 ret=i;
369 break;
370 }
371 }
372
373 if (!ctx->finished)
374 {
375 ctx->finished=1;
376 ctx->buf_off=0;
377 ret=EVP_CipherFinal(&(ctx->cipher),
378 (unsigned char *)ctx->buf,
379 &(ctx->buf_len));
380 ctx->ok=(int)ret;
381 if (ret <= 0) break;
382
383 /* push out the bytes */
384 goto again;
385 }
386
387 /* Finally flush the underlying BIO */
388 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
389 break;
390 case BIO_C_GET_CIPHER_STATUS:
391 ret=(long)ctx->ok;
392 break;
393 case BIO_C_DO_STATE_MACHINE:
394 BIO_clear_retry_flags(b);
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 BIO_copy_next_retry(b);
397 break;
398
399 case BIO_CTRL_DUP:
400 dbio=(BIO *)ptr;
401 dctx=(BIO_ENC_CTX *)dbio->ptr;
402 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
403 dbio->init=1;
404 break;
405 default:
406 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
407 break;
408 }
409 return(ret);
410 }
411
412/*
413void BIO_set_cipher_ctx(b,c)
414BIO *b;
415EVP_CIPHER_ctx *c;
416 {
417 if (b == NULL) return;
418
419 if ((b->callback != NULL) &&
420 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
421 return;
422
423 b->init=1;
424 ctx=(BIO_ENC_CTX *)b->ptr;
425 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
426
427 if (b->callback != NULL)
428 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
429 }
430*/
431
432void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
433 int e)
434 {
435 BIO_ENC_CTX *ctx;
436
437 if (b == NULL) return;
438
439 if ((b->callback != NULL) &&
440 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
441 return;
442
443 b->init=1;
444 ctx=(BIO_ENC_CTX *)b->ptr;
445 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
446
447 if (b->callback != NULL)
448 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
449 }
450
diff --git a/src/lib/libssl/src/crypto/pkcs7/dec.c b/src/lib/libssl/src/crypto/pkcs7/dec.c
new file mode 100644
index 0000000000..b3661f28d3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/dec.c
@@ -0,0 +1,246 @@
1/* crypto/pkcs7/verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <stdlib.h>
60#include <openssl/bio.h>
61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/asn1.h>
65
66int verify_callback(int ok, X509_STORE_CTX *ctx);
67
68BIO *bio_err=NULL;
69
70int main(argc,argv)
71int argc;
72char *argv[];
73 {
74 char *keyfile=NULL;
75 BIO *in;
76 EVP_PKEY *pkey;
77 X509 *x509;
78 PKCS7 *p7;
79 PKCS7_SIGNER_INFO *si;
80 X509_STORE_CTX cert_ctx;
81 X509_STORE *cert_store=NULL;
82 BIO *data,*detached=NULL,*p7bio=NULL;
83 char buf[1024*4];
84 unsigned char *pp;
85 int i,printit=0;
86 STACK_OF(PKCS7_SIGNER_INFO) *sk;
87
88 SSLeay_add_all_algorithms();
89 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
90
91 data=BIO_new(BIO_s_file());
92 pp=NULL;
93 while (argc > 1)
94 {
95 argc--;
96 argv++;
97 if (strcmp(argv[0],"-p") == 0)
98 {
99 printit=1;
100 }
101 else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) {
102 keyfile = argv[1];
103 argc-=1;
104 argv+=1;
105 } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
106 {
107 detached=BIO_new(BIO_s_file());
108 if (!BIO_read_filename(detached,argv[1]))
109 goto err;
110 argc-=1;
111 argv+=1;
112 }
113 else break;
114 }
115
116 if (!BIO_read_filename(data,argv[0])) goto err;
117
118 if(!keyfile) {
119 fprintf(stderr, "No private key file specified\n");
120 goto err;
121 }
122
123 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
124 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
125 BIO_reset(in);
126 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
127 BIO_free(in);
128
129 if (pp == NULL)
130 BIO_set_fp(data,stdin,BIO_NOCLOSE);
131
132
133 /* Load the PKCS7 object from a file */
134 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err;
135
136
137
138 /* This stuff is being setup for certificate verification.
139 * When using SSL, it could be replaced with a
140 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
141 cert_store=X509_STORE_new();
142 X509_STORE_set_default_paths(cert_store);
143 X509_STORE_load_locations(cert_store,NULL,"../../certs");
144 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
145
146 ERR_clear_error();
147
148 /* We need to process the data */
149 /* We cannot support detached encryption */
150 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
151
152 if (p7bio == NULL)
153 {
154 printf("problems decoding\n");
155 goto err;
156 }
157
158 /* We now have to 'read' from p7bio to calculate digests etc. */
159 for (;;)
160 {
161 i=BIO_read(p7bio,buf,sizeof(buf));
162 /* print it? */
163 if (i <= 0) break;
164 fwrite(buf,1, i, stdout);
165 }
166
167 /* We can now verify signatures */
168 sk=PKCS7_get_signer_info(p7);
169 if (sk == NULL)
170 {
171 fprintf(stderr, "there are no signatures on this data\n");
172 }
173 else
174 {
175 /* Ok, first we need to, for each subject entry,
176 * see if we can verify */
177 ERR_clear_error();
178 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
179 {
180 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
181 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
182 if (i <= 0)
183 goto err;
184 else
185 fprintf(stderr,"Signature verified\n");
186 }
187 }
188 X509_STORE_free(cert_store);
189
190 exit(0);
191err:
192 ERR_load_crypto_strings();
193 ERR_print_errors_fp(stderr);
194 exit(1);
195 }
196
197/* should be X509 * but we can just have them as char *. */
198int verify_callback(int ok, X509_STORE_CTX *ctx)
199 {
200 char buf[256];
201 X509 *err_cert;
202 int err,depth;
203
204 err_cert=X509_STORE_CTX_get_current_cert(ctx);
205 err= X509_STORE_CTX_get_error(ctx);
206 depth= X509_STORE_CTX_get_error_depth(ctx);
207
208 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
209 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
210 if (!ok)
211 {
212 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
213 X509_verify_cert_error_string(err));
214 if (depth < 6)
215 {
216 ok=1;
217 X509_STORE_CTX_set_error(ctx,X509_V_OK);
218 }
219 else
220 {
221 ok=0;
222 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
223 }
224 }
225 switch (ctx->error)
226 {
227 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
228 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
229 BIO_printf(bio_err,"issuer= %s\n",buf);
230 break;
231 case X509_V_ERR_CERT_NOT_YET_VALID:
232 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
233 BIO_printf(bio_err,"notBefore=");
234 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
235 BIO_printf(bio_err,"\n");
236 break;
237 case X509_V_ERR_CERT_HAS_EXPIRED:
238 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
239 BIO_printf(bio_err,"notAfter=");
240 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
241 BIO_printf(bio_err,"\n");
242 break;
243 }
244 BIO_printf(bio_err,"verify return:%d\n",ok);
245 return(ok);
246 }
diff --git a/src/lib/libssl/src/crypto/pkcs7/des.pem b/src/lib/libssl/src/crypto/pkcs7/des.pem
new file mode 100644
index 0000000000..62d1657e3e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/des.pem
@@ -0,0 +1,15 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15
diff --git a/src/lib/libssl/src/crypto/pkcs7/es1.pem b/src/lib/libssl/src/crypto/pkcs7/es1.pem
new file mode 100644
index 0000000000..47112a238f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/es1.pem
@@ -0,0 +1,66 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqGSIb3DQEBAQUABEDWak0y/5XZJhQJeCLo
6KECcHXkTEbjzYkYNHIinbiPmRK4QbNfs9z2mA3z/c2ykQ4eAqFR2jyNrUMN/+I5XEiv6MIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEAWg9+KgtCjc77Jdj1Ve4wGgHjVHbbSYEA1ZqKFDoi15vSr9hfpHmC4
11ycZzcRo16JkTfolefiHZzmyjVz94vSN6MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOA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IiHpmN+PaujXpv
56qZV2VhjkB2j09GEECOIdv8AVOJgKBAjlHgIqAD9jZQQIXHbs44+wogcEIGGqTACRJxrhMcMG
57X8drNjksIPt+snxTXUBIkTVpZWoABAh6unXPTyIr8QQgBF8xKoX27MWk7iTNmkSNZggZXa2a
58DWCGHSYLngbSOHIECD9XmO6VsvTgBAjfqB70CEW4WwQIVIBkbCocznUEEHB/zFXy/sR4OYHe
59UfbNPnIEEDWBB/NTCLMGE+o8BfyujcAECFik7GQnnF9VBBAhLXExQeWAofZNc6NtN7qZBCC1
60gVIS3ruTwKltmcrgx3heT3M8ZJhCfWa+6KzchnmKygQQ+1NL5sSzR4m/fdrqxHFyUAQYCT2x
61PamQr3wK3h0lyZER+4H0zPM86AhFBBC3CkmvL2vjflMfujnzPBVpBBge9rMbI5+0q9DLrTiT
625F3AIgXLpD8PQWAECHkHVo6RomV3BAgMbi8E271UeAQIqtS8wnI3XngECG3TWmOMb3/iBEha
63y+mvCS6I3n3JfL8e1B5P4qX9/czJRaERLuKpGNjLiL4A+zxN0LZ0UHd0qfmJjwOTxAx3iJAC
64lGXX4nB9ATYPUT5EU+o1Y4sECN01pP6vWNIdBDAsiE0Ts8/9ltJlqX2B3AoOM4qOt9EaCjXf
65lB+aEmrhtjUwuZ6GqS5Ke7P6XnakTk4ECCLIMatNdootAAAAAAAAAAAAAA==
66-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/example.c b/src/lib/libssl/src/crypto/pkcs7/example.c
new file mode 100644
index 0000000000..7354890084
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/example.c
@@ -0,0 +1,327 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <openssl/pkcs7.h>
4#include <openssl/asn1_mac.h>
5
6int add_signed_time(PKCS7_SIGNER_INFO *si)
7 {
8 ASN1_UTCTIME *sign_time;
9
10 /* The last parameter is the amount to add/subtract from the current
11 * time (in seconds) */
12 sign_time=X509_gmtime_adj(NULL,0);
13 PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
14 V_ASN1_UTCTIME,(char *)sign_time);
15 return(1);
16 }
17
18ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si)
19 {
20 ASN1_TYPE *so;
21
22 so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
23 if (so->type == V_ASN1_UTCTIME)
24 return so->value.utctime;
25 return NULL;
26 }
27
28static int signed_string_nid= -1;
29
30void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
31 {
32 ASN1_OCTET_STRING *os;
33
34 /* To a an object of OID 1.2.3.4.5, which is an octet string */
35 if (signed_string_nid == -1)
36 signed_string_nid=
37 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
38 os=ASN1_OCTET_STRING_new();
39 ASN1_OCTET_STRING_set(os,str,strlen(str));
40 /* When we add, we do not free */
41 PKCS7_add_signed_attribute(si,signed_string_nid,
42 V_ASN1_OCTET_STRING,(char *)os);
43 }
44
45int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
46 {
47 ASN1_TYPE *so;
48 ASN1_OCTET_STRING *os;
49 int i;
50
51 if (signed_string_nid == -1)
52 signed_string_nid=
53 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
54 /* To retrieve */
55 so=PKCS7_get_signed_attribute(si,signed_string_nid);
56 if (so != NULL)
57 {
58 if (so->type == V_ASN1_OCTET_STRING)
59 {
60 os=so->value.octet_string;
61 i=os->length;
62 if ((i+1) > len)
63 i=len-1;
64 memcpy(buf,os->data,i);
65 return(i);
66 }
67 }
68 return(0);
69 }
70
71static signed_seq2string_nid= -1;
72/* ########################################### */
73int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
74 {
75 /* To add an object of OID 1.9.999, which is a sequence containing
76 * 2 octet strings */
77 unsigned char *p;
78 ASN1_OCTET_STRING *os1,*os2;
79 ASN1_STRING *seq;
80 unsigned char *data;
81 int i,total;
82
83 if (signed_seq2string_nid == -1)
84 signed_seq2string_nid=
85 OBJ_create("1.9.9999","OID_example","Our example OID");
86
87 os1=ASN1_OCTET_STRING_new();
88 os2=ASN1_OCTET_STRING_new();
89 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
90 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
91 i =i2d_ASN1_OCTET_STRING(os1,NULL);
92 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
93 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
94
95 data=malloc(total);
96 p=data;
97 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
98 i2d_ASN1_OCTET_STRING(os1,&p);
99 i2d_ASN1_OCTET_STRING(os2,&p);
100
101 seq=ASN1_STRING_new();
102 ASN1_STRING_set(seq,data,total);
103 free(data);
104 ASN1_OCTET_STRING_free(os1);
105 ASN1_OCTET_STRING_free(os2);
106
107 PKCS7_add_signed_attribute(si,signed_seq2string_nid,
108 V_ASN1_SEQUENCE,(char *)seq);
109 return(1);
110 }
111
112/* For this case, I will malloc the return strings */
113int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
114 {
115 ASN1_TYPE *so;
116
117 if (signed_seq2string_nid == -1)
118 signed_seq2string_nid=
119 OBJ_create("1.9.9999","OID_example","Our example OID");
120 /* To retrieve */
121 so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
122 if (so && (so->type == V_ASN1_SEQUENCE))
123 {
124 ASN1_CTX c;
125 ASN1_STRING *s;
126 long length;
127 ASN1_OCTET_STRING *os1,*os2;
128
129 s=so->value.sequence;
130 c.p=ASN1_STRING_data(s);
131 c.max=c.p+ASN1_STRING_length(s);
132 if (!asn1_GetSequence(&c,&length)) goto err;
133 /* Length is the length of the seqence */
134
135 c.q=c.p;
136 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
137 goto err;
138 c.slen-=(c.p-c.q);
139
140 c.q=c.p;
141 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
142 goto err;
143 c.slen-=(c.p-c.q);
144
145 if (!asn1_Finish(&c)) goto err;
146 *str1=malloc(os1->length+1);
147 *str2=malloc(os2->length+1);
148 memcpy(*str1,os1->data,os1->length);
149 memcpy(*str2,os2->data,os2->length);
150 (*str1)[os1->length]='\0';
151 (*str2)[os2->length]='\0';
152 ASN1_OCTET_STRING_free(os1);
153 ASN1_OCTET_STRING_free(os2);
154 return(1);
155 }
156err:
157 return(0);
158 }
159
160
161/* #######################################
162 * THE OTHER WAY TO DO THINGS
163 * #######################################
164 */
165X509_ATTRIBUTE *create_time(void)
166 {
167 ASN1_UTCTIME *sign_time;
168 X509_ATTRIBUTE *ret;
169
170 /* The last parameter is the amount to add/subtract from the current
171 * time (in seconds) */
172 sign_time=X509_gmtime_adj(NULL,0);
173 ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
174 V_ASN1_UTCTIME,(char *)sign_time);
175 return(ret);
176 }
177
178ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk)
179 {
180 ASN1_TYPE *so;
181 PKCS7_SIGNER_INFO si;
182
183 si.auth_attr=sk;
184 so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
185 if (so->type == V_ASN1_UTCTIME)
186 return so->value.utctime;
187 return NULL;
188 }
189
190X509_ATTRIBUTE *create_string(char *str)
191 {
192 ASN1_OCTET_STRING *os;
193 X509_ATTRIBUTE *ret;
194
195 /* To a an object of OID 1.2.3.4.5, which is an octet string */
196 if (signed_string_nid == -1)
197 signed_string_nid=
198 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
199 os=ASN1_OCTET_STRING_new();
200 ASN1_OCTET_STRING_set(os,str,strlen(str));
201 /* When we add, we do not free */
202 ret=X509_ATTRIBUTE_create(signed_string_nid,
203 V_ASN1_OCTET_STRING,(char *)os);
204 return(ret);
205 }
206
207int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len)
208 {
209 ASN1_TYPE *so;
210 ASN1_OCTET_STRING *os;
211 int i;
212 PKCS7_SIGNER_INFO si;
213
214 si.auth_attr=sk;
215
216 if (signed_string_nid == -1)
217 signed_string_nid=
218 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
219 /* To retrieve */
220 so=PKCS7_get_signed_attribute(&si,signed_string_nid);
221 if (so != NULL)
222 {
223 if (so->type == V_ASN1_OCTET_STRING)
224 {
225 os=so->value.octet_string;
226 i=os->length;
227 if ((i+1) > len)
228 i=len-1;
229 memcpy(buf,os->data,i);
230 return(i);
231 }
232 }
233 return(0);
234 }
235
236X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
237 {
238 /* To add an object of OID 1.9.999, which is a sequence containing
239 * 2 octet strings */
240 unsigned char *p;
241 ASN1_OCTET_STRING *os1,*os2;
242 ASN1_STRING *seq;
243 X509_ATTRIBUTE *ret;
244 unsigned char *data;
245 int i,total;
246
247 if (signed_seq2string_nid == -1)
248 signed_seq2string_nid=
249 OBJ_create("1.9.9999","OID_example","Our example OID");
250
251 os1=ASN1_OCTET_STRING_new();
252 os2=ASN1_OCTET_STRING_new();
253 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
254 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
255 i =i2d_ASN1_OCTET_STRING(os1,NULL);
256 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
257 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
258
259 data=malloc(total);
260 p=data;
261 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
262 i2d_ASN1_OCTET_STRING(os1,&p);
263 i2d_ASN1_OCTET_STRING(os2,&p);
264
265 seq=ASN1_STRING_new();
266 ASN1_STRING_set(seq,data,total);
267 free(data);
268 ASN1_OCTET_STRING_free(os1);
269 ASN1_OCTET_STRING_free(os2);
270
271 ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
272 V_ASN1_SEQUENCE,(char *)seq);
273 return(ret);
274 }
275
276/* For this case, I will malloc the return strings */
277int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
278 {
279 ASN1_TYPE *so;
280 PKCS7_SIGNER_INFO si;
281
282 if (signed_seq2string_nid == -1)
283 signed_seq2string_nid=
284 OBJ_create("1.9.9999","OID_example","Our example OID");
285
286 si.auth_attr=sk;
287 /* To retrieve */
288 so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
289 if (so->type == V_ASN1_SEQUENCE)
290 {
291 ASN1_CTX c;
292 ASN1_STRING *s;
293 long length;
294 ASN1_OCTET_STRING *os1,*os2;
295
296 s=so->value.sequence;
297 c.p=ASN1_STRING_data(s);
298 c.max=c.p+ASN1_STRING_length(s);
299 if (!asn1_GetSequence(&c,&length)) goto err;
300 /* Length is the length of the seqence */
301
302 c.q=c.p;
303 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
304 goto err;
305 c.slen-=(c.p-c.q);
306
307 c.q=c.p;
308 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
309 goto err;
310 c.slen-=(c.p-c.q);
311
312 if (!asn1_Finish(&c)) goto err;
313 *str1=malloc(os1->length+1);
314 *str2=malloc(os2->length+1);
315 memcpy(*str1,os1->data,os1->length);
316 memcpy(*str2,os2->data,os2->length);
317 (*str1)[os1->length]='\0';
318 (*str2)[os2->length]='\0';
319 ASN1_OCTET_STRING_free(os1);
320 ASN1_OCTET_STRING_free(os2);
321 return(1);
322 }
323err:
324 return(0);
325 }
326
327
diff --git a/src/lib/libssl/src/crypto/pkcs7/example.h b/src/lib/libssl/src/crypto/pkcs7/example.h
new file mode 100644
index 0000000000..96167de188
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/example.h
@@ -0,0 +1,57 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55int add_signed_time(PKCS7_SIGNER_INFO *si);
56ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si);
57int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2);
diff --git a/src/lib/libssl/src/crypto/pkcs7/info.pem b/src/lib/libssl/src/crypto/pkcs7/info.pem
new file mode 100644
index 0000000000..989baf8709
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/info.pem
@@ -0,0 +1,57 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
49-----BEGIN RSA PRIVATE KEY-----
50MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
51mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
52fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
53zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
54p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
55bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
56IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
57-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/infokey.pem b/src/lib/libssl/src/crypto/pkcs7/infokey.pem
new file mode 100644
index 0000000000..1e2acc954d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/infokey.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
3mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
4fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
5zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
6p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
7bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
8IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_asn1.c b/src/lib/libssl/src/crypto/pkcs7/pk7_asn1.c
new file mode 100644
index 0000000000..46f0fc9375
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_asn1.c
@@ -0,0 +1,213 @@
1/* pk7_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs7.h>
63#include <openssl/x509.h>
64
65/* PKCS#7 ASN1 module */
66
67/* This is the ANY DEFINED BY table for the top level PKCS#7 structure */
68
69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0);
70
71ASN1_ADB(PKCS7) = {
72 ADB_ENTRY(NID_pkcs7_data, ASN1_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING, 0)),
73 ADB_ENTRY(NID_pkcs7_signed, ASN1_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)),
74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)),
75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)),
76 ADB_ENTRY(NID_pkcs7_digest, ASN1_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)),
77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
79
80ASN1_SEQUENCE(PKCS7) = {
81 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
82 ASN1_ADB_OBJECT(PKCS7)
83}ASN1_SEQUENCE_END(PKCS7)
84
85IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
86IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7)
87
88ASN1_SEQUENCE(PKCS7_SIGNED) = {
89 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER),
90 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR),
91 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7),
92 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0),
93 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1),
94 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO)
95} ASN1_SEQUENCE_END(PKCS7_SIGNED)
96
97IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
98
99/* Minor tweak to operation: free up EVP_PKEY */
100static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
101{
102 if(operation == ASN1_OP_FREE_POST) {
103 PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
104 EVP_PKEY_free(si->pkey);
105 }
106 return 1;
107}
108
109ASN1_SEQUENCE_cb(PKCS7_SIGNER_INFO, si_cb) = {
110 ASN1_SIMPLE(PKCS7_SIGNER_INFO, version, ASN1_INTEGER),
111 ASN1_SIMPLE(PKCS7_SIGNER_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
112 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_alg, X509_ALGOR),
113 /* NB this should be a SET OF but we use a SEQUENCE OF so the
114 * original order * is retained when the structure is reencoded.
115 * Since the attributes are implicitly tagged this will not affect
116 * the encoding.
117 */
118 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNER_INFO, auth_attr, X509_ATTRIBUTE, 0),
119 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_enc_alg, X509_ALGOR),
120 ASN1_SIMPLE(PKCS7_SIGNER_INFO, enc_digest, ASN1_OCTET_STRING),
121 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNER_INFO, unauth_attr, X509_ATTRIBUTE, 1)
122} ASN1_SEQUENCE_END_cb(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO)
123
124IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
125
126ASN1_SEQUENCE(PKCS7_ISSUER_AND_SERIAL) = {
127 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, issuer, X509_NAME),
128 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, serial, ASN1_INTEGER)
129} ASN1_SEQUENCE_END(PKCS7_ISSUER_AND_SERIAL)
130
131IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
132
133ASN1_SEQUENCE(PKCS7_ENVELOPE) = {
134 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER),
135 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
136 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT)
137} ASN1_SEQUENCE_END(PKCS7_ENVELOPE)
138
139IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
140
141/* Minor tweak to operation: free up X509 */
142static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
143{
144 if(operation == ASN1_OP_FREE_POST) {
145 PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
146 X509_free(ri->cert);
147 }
148 return 1;
149}
150
151ASN1_SEQUENCE_cb(PKCS7_RECIP_INFO, ri_cb) = {
152 ASN1_SIMPLE(PKCS7_RECIP_INFO, version, ASN1_INTEGER),
153 ASN1_SIMPLE(PKCS7_RECIP_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
154 ASN1_SIMPLE(PKCS7_RECIP_INFO, key_enc_algor, X509_ALGOR),
155 ASN1_SIMPLE(PKCS7_RECIP_INFO, enc_key, ASN1_OCTET_STRING)
156} ASN1_SEQUENCE_END_cb(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO)
157
158IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
159
160ASN1_SEQUENCE(PKCS7_ENC_CONTENT) = {
161 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
162 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
163 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0)
164} ASN1_SEQUENCE_END(PKCS7_ENC_CONTENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
167
168ASN1_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
169 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER),
170 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
171 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR),
172 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, enc_data, PKCS7_ENC_CONTENT),
173 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0),
174 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1),
175 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO)
176} ASN1_SEQUENCE_END(PKCS7_SIGN_ENVELOPE)
177
178IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
179
180ASN1_SEQUENCE(PKCS7_ENCRYPT) = {
181 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER),
182 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT)
183} ASN1_SEQUENCE_END(PKCS7_ENCRYPT)
184
185IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
186
187ASN1_SEQUENCE(PKCS7_DIGEST) = {
188 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER),
189 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR),
190 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7),
191 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING)
192} ASN1_SEQUENCE_END(PKCS7_DIGEST)
193
194IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST)
195
196/* Specials for authenticated attributes */
197
198/* When signing attributes we want to reorder them to match the sorted
199 * encoding.
200 */
201
202ASN1_ITEM_TEMPLATE(PKCS7_ATTR_SIGN) =
203 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_ORDER, 0, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
204ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_SIGN)
205
206/* When verifying attributes we need to use the received order. So
207 * we use SEQUENCE OF and tag it to SET OF
208 */
209
210ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
211 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
212 V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
213ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_attr.c b/src/lib/libssl/src/crypto/pkcs7/pk7_attr.c
new file mode 100644
index 0000000000..3b9c0fe3f2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_attr.c
@@ -0,0 +1,85 @@
1/* pk7_attr.c */
2/* S/MIME code.
3 * Copyright (C) 1997-8 Dr S N Henson (shenson@bigfoot.com)
4 * All Rights Reserved.
5 * Redistribution of this code without the authors permission is expressly
6 * prohibited.
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <openssl/bio.h>
12#include <openssl/asn1.h>
13#include <openssl/pem.h>
14#include <openssl/pkcs7.h>
15#include <openssl/err.h>
16
17int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap)
18{
19 ASN1_STRING *seq;
20 unsigned char *p, *pp;
21 int len;
22 len=i2d_ASN1_SET(cap,NULL,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
23 V_ASN1_UNIVERSAL, IS_SEQUENCE);
24 if(!(pp=(unsigned char *)Malloc(len))) {
25 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
26 return 0;
27 }
28 p=pp;
29 i2d_ASN1_SET(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
30 V_ASN1_UNIVERSAL, IS_SEQUENCE);
31 if(!(seq = ASN1_STRING_new())) {
32 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
33 return 0;
34 }
35 if(!ASN1_STRING_set (seq, pp, len)) {
36 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
37 return 0;
38 }
39 Free (pp);
40 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
41 V_ASN1_SEQUENCE, seq);
42}
43
44STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
45{
46 ASN1_TYPE *cap;
47 unsigned char *p;
48 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
49 if (!cap) return NULL;
50 p = cap->value.sequence->data;
51 return d2i_ASN1_SET (NULL, &p, cap->value.sequence->length,
52 (char *(*)())d2i_X509_ALGOR, X509_ALGOR_free, V_ASN1_SEQUENCE,
53 V_ASN1_UNIVERSAL);
54}
55
56/* Basic smime-capabilities OID and optional integer arg */
57int PKCS7_simple_smimecap(STACK *sk, int nid, int arg)
58{
59 X509_ALGOR *alg;
60 if(!(alg = X509_ALGOR_new())) {
61 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
62 return 0;
63 }
64 ASN1_OBJECT_free(alg->algorithm);
65 alg->algorithm = OBJ_nid2obj (nid);
66 if (arg > 0) {
67 ASN1_INTEGER *nbit;
68 if(!(alg->parameter = ASN1_TYPE_new())) {
69 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
70 return 0;
71 }
72 if(!(nbit = ASN1_INTEGER_new())) {
73 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!ASN1_INTEGER_set (nbit, arg)) {
77 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 alg->parameter->value.integer = nbit;
81 alg->parameter->type = V_ASN1_INTEGER;
82 }
83 sk_push (sk, (char *)alg);
84 return 1;
85}
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_mime.c b/src/lib/libssl/src/crypto/pkcs7/pk7_mime.c
new file mode 100644
index 0000000000..734643be28
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_mime.c
@@ -0,0 +1,673 @@
1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64
65/* MIME and related routines */
66
67/* MIME format structures
68 * Note that all are translated to lower case apart from
69 * parameter values. Quotes are stripped off
70 */
71
72typedef struct {
73char *name; /* Name of line e.g. "content-type" */
74char *value; /* Value of line e.g. "text/plain" */
75STACK /* MIME_PARAM */ *params; /* Zero or more parameters */
76} MIME_HEADER;
77
78typedef struct {
79char *param_name; /* Param name e.g. "micalg" */
80char *param_value; /* Param value e.g. "sha1" */
81} MIME_PARAM;
82
83
84static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
85static PKCS7 *B64_read_PKCS7(BIO *bio);
86static char * strip_ends(char *name);
87static char * strip_start(char *name);
88static char * strip_end(char *name);
89static MIME_HEADER *mime_hdr_new(char *name, char *value);
90static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
91static STACK *mime_parse_hdr(BIO *bio);
92static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b);
93static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b);
94static void mime_param_free(MIME_PARAM *param);
95static int mime_bound_check(char *line, int linelen, char *bound, int blen);
96static int multi_split(BIO *bio, char *bound, STACK **ret);
97static int iscrlf(char c);
98static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name);
99static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
100static void mime_hdr_free(MIME_HEADER *hdr);
101
102#define MAX_SMLEN 1024
103#define mime_debug(x) /* x */
104
105
106typedef void (*stkfree)();
107
108/* Base 64 read and write of PKCS#7 structure */
109
110static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
111{
112 BIO *b64;
113 if(!(b64 = BIO_new(BIO_f_base64()))) {
114 PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 bio = BIO_push(b64, bio);
118 i2d_PKCS7_bio(bio, p7);
119 BIO_flush(bio);
120 bio = BIO_pop(bio);
121 BIO_free(b64);
122 return 1;
123}
124
125static PKCS7 *B64_read_PKCS7(BIO *bio)
126{
127 BIO *b64;
128 PKCS7 *p7;
129 if(!(b64 = BIO_new(BIO_f_base64()))) {
130 PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE);
131 return 0;
132 }
133 bio = BIO_push(b64, bio);
134 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
135 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
136 BIO_flush(bio);
137 bio = BIO_pop(bio);
138 BIO_free(b64);
139 return p7;
140}
141
142/* SMIME sender */
143
144int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
145{
146 char linebuf[MAX_SMLEN];
147 char bound[33], c;
148 int i;
149 if((flags & PKCS7_DETACHED) && data) {
150 /* We want multipart/signed */
151 /* Generate a random boundary */
152 RAND_pseudo_bytes((unsigned char *)bound, 32);
153 for(i = 0; i < 32; i++) {
154 c = bound[i] & 0xf;
155 if(c < 10) c += '0';
156 else c += 'A' - 10;
157 bound[i] = c;
158 }
159 bound[32] = 0;
160 BIO_printf(bio, "MIME-Version: 1.0\n");
161 BIO_printf(bio, "Content-Type: multipart/signed ; ");
162 BIO_printf(bio, "protocol=\"application/x-pkcs7-signature\" ; ");
163 BIO_printf(bio, "micalg=sha1 ; boundary=\"----%s\"\n\n", bound);
164 BIO_printf(bio, "This is an S/MIME signed message\n\n");
165 /* Now write out the first part */
166 BIO_printf(bio, "------%s\r\n", bound);
167 if(flags & PKCS7_TEXT) BIO_printf(bio, "Content-Type: text/plain\n\n");
168 while((i = BIO_read(data, linebuf, MAX_SMLEN)) > 0)
169 BIO_write(bio, linebuf, i);
170 BIO_printf(bio, "\n------%s\n", bound);
171
172 /* Headers for signature */
173
174 BIO_printf(bio, "Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\n");
175 BIO_printf(bio, "Content-Transfer-Encoding: base64\n");
176 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7s\"\n\n");
177 B64_write_PKCS7(bio, p7);
178 BIO_printf(bio,"\n------%s--\n\n", bound);
179 return 1;
180 }
181 /* MIME headers */
182 BIO_printf(bio, "MIME-Version: 1.0\n");
183 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7m\"\n");
184 BIO_printf(bio, "Content-Type: application/x-pkcs7-mime; name=\"smime.p7m\"\n");
185 BIO_printf(bio, "Content-Transfer-Encoding: base64\n\n");
186 B64_write_PKCS7(bio, p7);
187 BIO_printf(bio, "\n");
188 return 1;
189}
190
191/* SMIME reader: handle multipart/signed and opaque signing.
192 * in multipart case the content is placed in a memory BIO
193 * pointed to by "bcont". In opaque this is set to NULL
194 */
195
196PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
197{
198 BIO *p7in;
199 STACK *headers = NULL;
200 STACK *parts = NULL;
201 MIME_HEADER *hdr;
202 MIME_PARAM *prm;
203 PKCS7 *p7;
204 int ret;
205
206 if(bcont) *bcont = NULL;
207
208 if (!(headers = mime_parse_hdr(bio))) {
209 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR);
210 return NULL;
211 }
212
213 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
214 sk_pop_free(headers, mime_hdr_free);
215 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
216 return NULL;
217 }
218
219 /* Handle multipart/signed */
220
221 if(!strcmp(hdr->value, "multipart/signed")) {
222 /* Split into two parts */
223 prm = mime_param_find(hdr, "boundary");
224 if(!prm || !prm->param_value) {
225 sk_pop_free(headers, mime_hdr_free);
226 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY);
227 return NULL;
228 }
229 ret = multi_split(bio, prm->param_value, &parts);
230 sk_pop_free(headers, mime_hdr_free);
231 if(!ret || (sk_num(parts) != 2) ) {
232 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE);
233 sk_pop_free(parts, (stkfree)BIO_free);
234 return NULL;
235 }
236
237 /* Parse the signature piece */
238 p7in = (BIO *)sk_value(parts, 1);
239
240 if (!(headers = mime_parse_hdr(p7in))) {
241 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
242 sk_pop_free(parts, (stkfree)BIO_free);
243 return NULL;
244 }
245
246 /* Get content type */
247
248 if(!(hdr = mime_hdr_find(headers, "content-type")) ||
249 !hdr->value) {
250 sk_pop_free(headers, mime_hdr_free);
251 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
252 return NULL;
253 }
254
255 if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
256 strcmp(hdr->value, "application/pkcs7-signature")) {
257 sk_pop_free(headers, mime_hdr_free);
258 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
259 ERR_add_error_data(2, "type: ", hdr->value);
260 sk_pop_free(parts, (stkfree)BIO_free);
261 return NULL;
262 }
263 sk_pop_free(headers, mime_hdr_free);
264 /* Read in PKCS#7 */
265 if(!(p7 = B64_read_PKCS7(p7in))) {
266 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
267 sk_pop_free(parts, (stkfree)BIO_free);
268 return NULL;
269 }
270
271 if(bcont) {
272 *bcont = (BIO *)sk_value(parts, 0);
273 BIO_free(p7in);
274 sk_free(parts);
275 } else sk_pop_free(parts, (stkfree)BIO_free);
276 return p7;
277 }
278
279 /* OK, if not multipart/signed try opaque signature */
280
281 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
282 strcmp (hdr->value, "application/pkcs7-mime")) {
283 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
284 ERR_add_error_data(2, "type: ", hdr->value);
285 sk_pop_free(headers, mime_hdr_free);
286 return NULL;
287 }
288
289 sk_pop_free(headers, mime_hdr_free);
290
291 if(!(p7 = B64_read_PKCS7(bio))) {
292 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
293 return NULL;
294 }
295 return p7;
296
297}
298
299/* Copy text from one BIO to another making the output CRLF at EOL */
300int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
301{
302 char eol;
303 int len;
304 char linebuf[MAX_SMLEN];
305 if(flags & PKCS7_BINARY) {
306 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
307 BIO_write(out, linebuf, len);
308 return 1;
309 }
310 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
311 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
312 eol = 0;
313 while(iscrlf(linebuf[len - 1])) {
314 len--;
315 eol = 1;
316 }
317 BIO_write(out, linebuf, len);
318 if(eol) BIO_write(out, "\r\n", 2);
319 }
320 return 1;
321}
322
323/* Strip off headers if they are text/plain */
324int SMIME_text(BIO *in, BIO *out)
325{
326 char iobuf[4096];
327 int len;
328 STACK *headers;
329 MIME_HEADER *hdr;
330 if (!(headers = mime_parse_hdr(in))) {
331 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
332 return 0;
333 }
334 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
335 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
336 sk_pop_free(headers, mime_hdr_free);
337 return 0;
338 }
339 if (strcmp (hdr->value, "text/plain")) {
340 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
341 ERR_add_error_data(2, "type: ", hdr->value);
342 sk_pop_free(headers, mime_hdr_free);
343 return 0;
344 }
345 sk_pop_free(headers, mime_hdr_free);
346 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
347 BIO_write(out, iobuf, len);
348 return 1;
349}
350
351/* Split a multipart/XXX message body into component parts: result is
352 * canonical parts in a STACK of bios
353 */
354
355static int multi_split(BIO *bio, char *bound, STACK **ret)
356{
357 char linebuf[MAX_SMLEN];
358 int len, blen;
359 BIO *bpart = NULL;
360 STACK *parts;
361 char state, part, first;
362 blen = strlen(bound);
363 part = 0;
364 state = 0;
365 first = 1;
366 parts = sk_new(NULL);
367 *ret = parts;
368 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
369 state = mime_bound_check(linebuf, len, bound, blen);
370 if(state == 1) {
371 first = 1;
372 part++;
373 } else if(state == 2) {
374 sk_push(parts, (char *)bpart);
375 return 1;
376 } else if(part) {
377 if(first) {
378 first = 0;
379 if(bpart) sk_push(parts, (char *)bpart);
380 bpart = BIO_new(BIO_s_mem());
381
382 } else BIO_write(bpart, "\r\n", 2);
383 /* Strip CR+LF from linebuf */
384 while(iscrlf(linebuf[len - 1])) len--;
385 BIO_write(bpart, linebuf, len);
386 }
387 }
388 return 0;
389}
390
391static int iscrlf(char c)
392{
393 if(c == '\r' || c == '\n') return 1;
394 return 0;
395}
396
397/* This is the big one: parse MIME header lines up to message body */
398
399#define MIME_INVALID 0
400#define MIME_START 1
401#define MIME_TYPE 2
402#define MIME_NAME 3
403#define MIME_VALUE 4
404#define MIME_QUOTE 5
405#define MIME_COMMENT 6
406
407
408static STACK *mime_parse_hdr(BIO *bio)
409{
410 char *p, *q, c;
411 char *ntmp;
412 char linebuf[MAX_SMLEN];
413 MIME_HEADER *mhdr = NULL;
414 STACK *headers;
415 int len, state, save_state = 0;
416 headers = sk_new(mime_hdr_cmp);
417 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
418 /* If whitespace at line start then continuation line */
419 if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
420 else state = MIME_START;
421 ntmp = NULL;
422 /* Go through all characters */
423 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
424
425 /* State machine to handle MIME headers
426 * if this looks horrible that's because it *is*
427 */
428
429 switch(state) {
430 case MIME_START:
431 if(c == ':') {
432 state = MIME_TYPE;
433 *p = 0;
434 ntmp = strip_ends(q);
435 q = p + 1;
436 }
437 break;
438
439 case MIME_TYPE:
440 if(c == ';') {
441 mime_debug("Found End Value\n");
442 *p = 0;
443 mhdr = mime_hdr_new(ntmp, strip_ends(q));
444 sk_push(headers, (char *)mhdr);
445 ntmp = NULL;
446 q = p + 1;
447 state = MIME_NAME;
448 } else if(c == '(') {
449 save_state = state;
450 state = MIME_COMMENT;
451 }
452 break;
453
454 case MIME_COMMENT:
455 if(c == ')') {
456 state = save_state;
457 }
458 break;
459
460 case MIME_NAME:
461 if(c == '=') {
462 state = MIME_VALUE;
463 *p = 0;
464 ntmp = strip_ends(q);
465 q = p + 1;
466 }
467 break ;
468
469 case MIME_VALUE:
470 if(c == ';') {
471 state = MIME_NAME;
472 *p = 0;
473 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
474 ntmp = NULL;
475 q = p + 1;
476 } else if (c == '"') {
477 mime_debug("Found Quote\n");
478 state = MIME_QUOTE;
479 } else if(c == '(') {
480 save_state = state;
481 state = MIME_COMMENT;
482 }
483 break;
484
485 case MIME_QUOTE:
486 if(c == '"') {
487 mime_debug("Found Match Quote\n");
488 state = MIME_VALUE;
489 }
490 break;
491 }
492 }
493
494 if(state == MIME_TYPE) {
495 mhdr = mime_hdr_new(ntmp, strip_ends(q));
496 sk_push(headers, (char *)mhdr);
497 } else if(state == MIME_VALUE)
498 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
499 if(p == linebuf) break; /* Blank line means end of headers */
500}
501
502return headers;
503
504}
505
506static char *strip_ends(char *name)
507{
508 return strip_end(strip_start(name));
509}
510
511/* Strip a parameter of whitespace from start of param */
512static char *strip_start(char *name)
513{
514 char *p, c;
515 /* Look for first non white space or quote */
516 for(p = name; (c = *p) ;p++) {
517 if(c == '"') {
518 /* Next char is start of string if non null */
519 if(p[1]) return p + 1;
520 /* Else null string */
521 return NULL;
522 }
523 if(!isspace((unsigned char)c)) return p;
524 }
525 return NULL;
526}
527
528/* As above but strip from end of string : maybe should handle brackets? */
529static char *strip_end(char *name)
530{
531 char *p, c;
532 if(!name) return NULL;
533 /* Look for first non white space or quote */
534 for(p = name + strlen(name) - 1; p >= name ;p--) {
535 c = *p;
536 if(c == '"') {
537 if(p - 1 == name) return NULL;
538 *p = 0;
539 return name;
540 }
541 if(isspace((unsigned char)c)) *p = 0;
542 else return name;
543 }
544 return NULL;
545}
546
547static MIME_HEADER *mime_hdr_new(char *name, char *value)
548{
549 MIME_HEADER *mhdr;
550 char *tmpname, *tmpval, *p;
551 int c;
552 if(name) {
553 if(!(tmpname = BUF_strdup(name))) return NULL;
554 for(p = tmpname ; *p; p++) {
555 c = *p;
556 if(isupper(c)) {
557 c = tolower(c);
558 *p = c;
559 }
560 }
561 } else tmpname = NULL;
562 if(value) {
563 if(!(tmpval = BUF_strdup(value))) return NULL;
564 for(p = tmpval ; *p; p++) {
565 c = *p;
566 if(isupper(c)) {
567 c = tolower(c);
568 *p = c;
569 }
570 }
571 } else tmpval = NULL;
572 mhdr = (MIME_HEADER *) Malloc(sizeof(MIME_HEADER));
573 if(!mhdr) return NULL;
574 mhdr->name = tmpname;
575 mhdr->value = tmpval;
576 if(!(mhdr->params = sk_new(mime_param_cmp))) return NULL;
577 return mhdr;
578}
579
580static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
581{
582 char *tmpname, *tmpval, *p;
583 int c;
584 MIME_PARAM *mparam;
585 if(name) {
586 tmpname = BUF_strdup(name);
587 if(!tmpname) return 0;
588 for(p = tmpname ; *p; p++) {
589 c = *p;
590 if(isupper(c)) {
591 c = tolower(c);
592 *p = c;
593 }
594 }
595 } else tmpname = NULL;
596 if(value) {
597 tmpval = BUF_strdup(value);
598 if(!tmpval) return 0;
599 } else tmpval = NULL;
600 /* Parameter values are case sensitive so leave as is */
601 mparam = (MIME_PARAM *) Malloc(sizeof(MIME_PARAM));
602 if(!mparam) return 0;
603 mparam->param_name = tmpname;
604 mparam->param_value = tmpval;
605 sk_push(mhdr->params, (char *)mparam);
606 return 1;
607}
608
609static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b)
610{
611 return(strcmp((*a)->name, (*b)->name));
612}
613
614static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b)
615{
616 return(strcmp((*a)->param_name, (*b)->param_name));
617}
618
619/* Find a header with a given name (if possible) */
620
621static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name)
622{
623 MIME_HEADER htmp;
624 int idx;
625 htmp.name = name;
626 idx = sk_find(hdrs, (char *)&htmp);
627 if(idx < 0) return NULL;
628 return (MIME_HEADER *)sk_value(hdrs, idx);
629}
630
631static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
632{
633 MIME_PARAM param;
634 int idx;
635 param.param_name = name;
636 idx = sk_find(hdr->params, (char *)&param);
637 if(idx < 0) return NULL;
638 return (MIME_PARAM *)sk_value(hdr->params, idx);
639}
640
641static void mime_hdr_free(MIME_HEADER *hdr)
642{
643 if(hdr->name) Free(hdr->name);
644 if(hdr->value) Free(hdr->value);
645 if(hdr->params) sk_pop_free(hdr->params, mime_param_free);
646 Free(hdr);
647}
648
649static void mime_param_free(MIME_PARAM *param)
650{
651 if(param->param_name) Free(param->param_name);
652 if(param->param_value) Free(param->param_value);
653 Free(param);
654}
655
656/* Check for a multipart boundary. Returns:
657 * 0 : no boundary
658 * 1 : part boundary
659 * 2 : final boundary
660 */
661static int mime_bound_check(char *line, int linelen, char *bound, int blen)
662{
663 if(linelen == -1) linelen = strlen(line);
664 if(blen == -1) blen = strlen(bound);
665 /* Quickly eliminate if line length too short */
666 if(blen + 2 > linelen) return 0;
667 /* Check for part boundary */
668 if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
669 if(!strncmp(line + blen + 2, "--", 2)) return 2;
670 else return 1;
671 }
672 return 0;
673}
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c
new file mode 100644
index 0000000000..b41f42ed04
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c
@@ -0,0 +1,427 @@
1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple PKCS#7 processing functions */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
67 BIO *data, int flags)
68{
69 PKCS7 *p7;
70 PKCS7_SIGNER_INFO *si;
71 BIO *p7bio;
72 STACK *smcap;
73 int i;
74
75 if(!X509_check_private_key(signcert, pkey)) {
76 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
77 return NULL;
78 }
79
80 if(!(p7 = PKCS7_new())) {
81 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
82 return NULL;
83 }
84
85 PKCS7_set_type(p7, NID_pkcs7_signed);
86
87 PKCS7_content_new(p7, NID_pkcs7_data);
88
89 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
90 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
91 return NULL;
92 }
93
94 if(!(flags & PKCS7_NOCERTS)) {
95 PKCS7_add_certificate(p7, signcert);
96 if(certs) for(i = 0; i < sk_X509_num(certs); i++)
97 PKCS7_add_certificate(p7, sk_X509_value(certs, i));
98 }
99
100 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
101 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104
105
106 SMIME_crlf_copy(data, p7bio, flags);
107
108 if(!(flags & PKCS7_NOATTR)) {
109 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
110 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
111 /* Add SMIMECapabilities */
112 if(!(smcap = sk_new(NULL))) {
113 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116#ifndef NO_DES
117 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
118#endif
119#ifndef NO_RC2
120 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
121 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
122#endif
123#ifndef NO_DES
124 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
125#endif
126#ifndef NO_RC2
127 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
128#endif
129 PKCS7_add_attrib_smimecap (si, smcap);
130 sk_pop_free(smcap, X509_ALGOR_free);
131 }
132
133 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
134
135 if (!PKCS7_dataFinal(p7,p7bio)) {
136 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
137 return NULL;
138 }
139
140 BIO_free_all(p7bio);
141 return p7;
142}
143
144int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
145 BIO *indata, BIO *out, int flags)
146{
147 STACK_OF(X509) *signers;
148 X509 *signer;
149 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
150 PKCS7_SIGNER_INFO *si;
151 X509_STORE_CTX cert_ctx;
152 char buf[4096];
153 int i, j=0;
154 BIO *p7bio;
155 BIO *tmpout;
156
157 if(!p7) {
158 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
159 return 0;
160 }
161
162 if(!PKCS7_type_is_signed(p7)) {
163 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
164 return 0;
165 }
166
167 /* Check for no data and no content: no data to verify signature */
168 if(PKCS7_get_detached(p7) && !indata) {
169 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
170 return 0;
171 }
172
173 /* Check for data and content: two sets of data */
174 if(!PKCS7_get_detached(p7) && indata) {
175 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
176 return 0;
177 }
178
179 sinfos = PKCS7_get_signer_info(p7);
180
181 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
182 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
183 return 0;
184 }
185
186
187 signers = PKCS7_get0_signers(p7, certs, flags);
188
189 if(!signers) return 0;
190
191 /* Now verify the certificates */
192
193 if (!(flags & PKCS7_NOVERIFY)) for (i = 0; i < sk_X509_num(signers); i++) {
194 signer = sk_X509_value (signers, i);
195 if (!(flags & PKCS7_NOCHAIN)) {
196 X509_STORE_CTX_init(&cert_ctx, store, signer,
197 p7->d.sign->cert);
198 X509_STORE_CTX_set_purpose(&cert_ctx,
199 X509_PURPOSE_SMIME_SIGN);
200 } else X509_STORE_CTX_init (&cert_ctx, store, signer, NULL);
201 i = X509_verify_cert(&cert_ctx);
202 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
203 X509_STORE_CTX_cleanup(&cert_ctx);
204 if (i <= 0) {
205 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
206 ERR_add_error_data(2, "Verify error:",
207 X509_verify_cert_error_string(j));
208 sk_X509_free(signers);
209 return 0;
210 }
211 /* Check for revocation status here */
212 }
213
214 p7bio=PKCS7_dataInit(p7,indata);
215
216 if(flags & PKCS7_TEXT) {
217 if(!(tmpout = BIO_new(BIO_s_mem()))) {
218 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
219 goto err;
220 }
221 } else tmpout = out;
222
223 /* We now have to 'read' from p7bio to calculate digests etc. */
224 for (;;)
225 {
226 i=BIO_read(p7bio,buf,sizeof(buf));
227 if (i <= 0) break;
228 if (tmpout) BIO_write(tmpout, buf, i);
229 }
230
231 if(flags & PKCS7_TEXT) {
232 if(!SMIME_text(tmpout, out)) {
233 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
234 BIO_free(tmpout);
235 goto err;
236 }
237 BIO_free(tmpout);
238 }
239
240 /* Now Verify All Signatures */
241 if (!(flags & PKCS7_NOSIGS))
242 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
243 {
244 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
245 signer = sk_X509_value (signers, i);
246 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
247 if (j <= 0) {
248 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
249 goto err;
250 }
251 }
252
253 sk_X509_free(signers);
254 if(indata) BIO_pop(p7bio);
255 BIO_free_all(p7bio);
256
257 return 1;
258
259 err:
260
261 sk_X509_free(signers);
262 BIO_free(p7bio);
263
264 return 0;
265}
266
267STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
268{
269 STACK_OF(X509) *signers;
270 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
271 PKCS7_SIGNER_INFO *si;
272 PKCS7_ISSUER_AND_SERIAL *ias;
273 X509 *signer;
274 int i;
275
276 if(!p7) {
277 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
278 return NULL;
279 }
280
281 if(!PKCS7_type_is_signed(p7)) {
282 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
283 return NULL;
284 }
285 if(!(signers = sk_X509_new(NULL))) {
286 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
287 return NULL;
288 }
289
290 /* Collect all the signers together */
291
292 sinfos = PKCS7_get_signer_info(p7);
293
294 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
295 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
296 return 0;
297 }
298
299 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
300 {
301 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
302 ias = si->issuer_and_serial;
303 signer = NULL;
304 /* If any certificates passed they take priority */
305 if (certs) signer = X509_find_by_issuer_and_serial (certs,
306 ias->issuer, ias->serial);
307 if (!signer && !(flags & PKCS7_NOINTERN)
308 && p7->d.sign->cert) signer =
309 X509_find_by_issuer_and_serial (p7->d.sign->cert,
310 ias->issuer, ias->serial);
311 if (!signer) {
312 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
313 sk_X509_free(signers);
314 return 0;
315 }
316
317 sk_X509_push(signers, signer);
318 }
319 return signers;
320}
321
322
323/* Build a complete PKCS#7 enveloped data */
324
325PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
326 int flags)
327{
328 PKCS7 *p7;
329 BIO *p7bio = NULL;
330 int i;
331 X509 *x509;
332 if(!(p7 = PKCS7_new())) {
333 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
334 return NULL;
335 }
336
337 PKCS7_set_type(p7, NID_pkcs7_enveloped);
338 if(!PKCS7_set_cipher(p7, cipher)) {
339 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
340 goto err;
341 }
342
343 for(i = 0; i < sk_X509_num(certs); i++) {
344 x509 = sk_X509_value(certs, i);
345 if(!PKCS7_add_recipient(p7, x509)) {
346 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
347 PKCS7_R_ERROR_ADDING_RECIPIENT);
348 goto err;
349 }
350 }
351
352 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
353 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
354 goto err;
355 }
356
357 SMIME_crlf_copy(in, p7bio, flags);
358
359 BIO_flush(p7bio);
360
361 if (!PKCS7_dataFinal(p7,p7bio)) {
362 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
363 goto err;
364 }
365 BIO_free_all(p7bio);
366
367 return p7;
368
369 err:
370
371 BIO_free(p7bio);
372 PKCS7_free(p7);
373 return NULL;
374
375}
376
377int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
378{
379 BIO *tmpmem;
380 int ret, i;
381 char buf[4096];
382
383 if(!p7) {
384 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
385 return 0;
386 }
387
388 if(!PKCS7_type_is_enveloped(p7)) {
389 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
390 return 0;
391 }
392
393 if(!X509_check_private_key(cert, pkey)) {
394 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
395 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
396 return 0;
397 }
398
399 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
400 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
401 return 0;
402 }
403
404 if (flags & PKCS7_TEXT) {
405 BIO *tmpbuf, *bread;
406 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
407 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
408 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
409 return 0;
410 }
411 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
412 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
413 return 0;
414 }
415 ret = SMIME_text(bread, data);
416 BIO_free_all(bread);
417 return ret;
418 } else {
419 for(;;) {
420 i = BIO_read(tmpmem, buf, sizeof(buf));
421 if(i <= 0) break;
422 BIO_write(data, buf, i);
423 }
424 BIO_free_all(tmpmem);
425 return 1;
426 }
427}
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/3des.pem b/src/lib/libssl/src/crypto/pkcs7/t/3des.pem
new file mode 100644
index 0000000000..b2b5081a10
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/3des.pem
@@ -0,0 +1,16 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15-----END PKCS7-----
16
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/3dess.pem b/src/lib/libssl/src/crypto/pkcs7/t/3dess.pem
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/3dess.pem
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
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gTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/c.pem b/src/lib/libssl/src/crypto/pkcs7/t/c.pem
new file mode 100644
index 0000000000..a4b55e321a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/c.pem
@@ -0,0 +1,48 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/ff b/src/lib/libssl/src/crypto/pkcs7/t/ff
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/ff
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEz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VBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-e b/src/lib/libssl/src/crypto/pkcs7/t/msie-e
new file mode 100644
index 0000000000..aafae69fc9
--- /dev/null
+++ b/src/lib/libssl/src/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akA4MBZ4J5qfDJhOA2g5lWk1hIeu5Dn/AaLRZd0yz3oY0Ieo/erPWx/bCqtBzYbMe9
16qSFTedKlbc9EGe3opOTdBZVzK8KH3w3zsy5luxKdOUG59YYb5F1IZiWGiDyuo/HuacX+griu5LeD
17bEzOtZnko+TZXvWIko30fD79j3T4MRRhWXbgj2HKza+4vJ0mzcC/1+GPsJjAEAA/JgIEDU4w6/DI
18/HQHhLAO3G+9xKD7MvmrzkoAAAAAAAAAAAAA
19
20
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-e.pem b/src/lib/libssl/src/crypto/pkcs7/t/msie-e.pem
new file mode 100644
index 0000000000..a2a5e24e74
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/msie-e.pem
@@ -0,0 +1,22 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIIDkAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQIzO7zLBD+pls7xwAYxEEX6Y+u6/f4O9
6v1pY1naTyeNSCoXqZx2FUHYyQZywbeZ6ZFckGLG8xhZWRTeorhlW4qwwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQFxbBgUclskaGLO23uXO57ctz0If
11lYBvJH7YFne6/4nFl9GzU+5pY87BFrRWCzdjBImhF/FCPYaTTAWobWq3p3UwggHD
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECPL0ZT/zcdokgIIBmFHmyvHK
13ynLsN+iZEn19/x4wK1o3ASgTHsbbk9lGicLnuEG8ahJwu0Q9Tdan0URs83ugkRJ4
14L4CoxPJMs3LxpCzILmzncT1SSgi+DrZ6RhkFtdmpeyvHHg+GKJfc0fwZWHjamEHQ
15KGPDScodl5EObEZjcKaT4n6XS5UrFs0h8kgo6C4sGeGqacof8+ufMO3n3W7RQvLZ
16pMupGb7j/Vhq39A9vol6gobA08FtL2iAF2sI0Kn1kWDddqvYC1AfPJNAh9h4fdJF
17BSkqZGblTmj2nl6aAR1P5l8mb8ni1Ic6ZuAAWxsdBqQDgwFngnmp8MmE4DaDmVaT
18WEh67kOf8BotFl3TLPehjQh6j96s9bH9sKq0HNhsx72pIVN50qVtz0QZ7eik5N0F
19lXMrwoffDfOzLmW7Ep05Qbn1hhvkXUhmJYaIPK6j8e5pxf6CuK7kt4NsTM61meSj
205Nle9YiSjfR8Pv2PdPgxFGFZduCPYcrNr7i8nSbNwL/X4Y+wmMAQAD8mAgQNTjDr
218Mj8dAeEsA7cb73EoPsy+avOSgAAAAA=
22-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01 b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01
new file mode 100644
index 0000000000..2c93ab6462
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01
@@ -0,0 +1,62 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxgfMwgfACAQAwgZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYD
3VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0
4IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBA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NedXPHtBAiBKX+Mdy3wFQQIqE9gVgvrFNUE
49CKKoTFoMGqnPBAjDPgLCklNfrwQI3Ek1vSq68w8ECBodu2FOZJVkBAgzwjfSr2N9WQQQTCoQ
50KkAbrS9tnjXn1I3+ZwQIrPx3eINo/YUECIeYWCFskxlYBAiDUdvZXwD3vgQIkEyZbbZWbUUE
51CH4+odl1Isk3BBj68fkqJ0fKJRWVLWuW/O3VE4BOPKwFlaIECFseVTdDUho8BAj+cOKvV2WA
52hgQgaXr+wwq+ItblG0Qxz8IVUXX6PV2mIdHwz4SCCvnCsaIECJhBYxdfLI/XBCDswamPn9MR
53yXi2HVQBineV+GtWVkIoZ2dCLFB9mQRMoAQI0nUR5a5AOJoECA+AunKlAlx8BAi5RtFeF4g1
54FQQIz/ie+16LlQcECOmNuVg5DXjMBAjH2nkfpXZgWwQIVdLuO/+kuHAECO/5rEHmyI9vBBD4
5516BU4Rd3YerDQnHtrwOQBCCkho1XxK5Maz8KLCNi20wvcGt8wsIXlj2h5q9ITBq7IgQQvKVY
564OfJ7bKbItP2dylwQgQYPIGxwkkbRXNraONYvN19G8UdF35rFOuIBAjf0sKz/618ZQQIxObr
57xJkRe0sECIC+ssnjEb2NBBBI+XM4OntVWGsRV9Td3sFgBAinGwIroo8O0gQQMGAwgc9PaLaG
58gBCiwSTrYQQIVHjfCQgOtygEUIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/g0thR0lM
59+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy043GNZBAhOqjyB2JbD
60NwQoR23XCYD9x6E20ChHJRXmaHwyMdYXKl5CUxypl7ois+sy2D7jDukS3wQIsTyyPgJi0GsA
61AAAAAAAAAAAA
62
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01.pem b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-01.pem
new file mode 100644
index 0000000000..9abf00b2f2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/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9VHp0HCwlUvkOmdOyncxXi
51P8IA6VF1I9nn762wpsxqmWT5x6pC2kQXPUxhO1VXj6uWtZo1okJyNZ5/tNOwM7B+
52XfOZ0xw+uyVi9v4byTZM2QdsJ+d3YGYLAugTGHISLqQEerD8/gGK+/SL06b2gNed
53XPHtgSl/jHct8BWoT2BWC+sU1aKoTFoMGqnPwz4CwpJTX6/cSTW9KrrzDxodu2FO
54ZJVkM8I30q9jfVlMKhAqQButL22eNefUjf5nrPx3eINo/YWHmFghbJMZWINR29lf
55APe+kEyZbbZWbUV+PqHZdSLJN/rx+SonR8olFZUta5b87dUTgE48rAWVolseVTdD
56Uho8/nDir1dlgIZpev7DCr4i1uUbRDHPwhVRdfo9XaYh0fDPhIIK+cKxophBYxdf
57LI/X7MGpj5/TEcl4th1UAYp3lfhrVlZCKGdnQixQfZkETKDSdRHlrkA4mg+AunKl
58Alx8uUbRXheINRXP+J77XouVB+mNuVg5DXjMx9p5H6V2YFtV0u47/6S4cO/5rEHm
59yI9v+NegVOEXd2Hqw0Jx7a8DkKSGjVfErkxrPwosI2LbTC9wa3zCwheWPaHmr0hM
60GrsivKVY4OfJ7bKbItP2dylwQjyBscJJG0Vza2jjWLzdfRvFHRd+axTriN/SwrP/
61rXxlxObrxJkRe0uAvrLJ4xG9jUj5czg6e1VYaxFX1N3ewWCnGwIroo8O0jBgMIHP
62T2i2hoAQosEk62FUeN8JCA63KIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/
63g0thR0lM+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy04
643GNZTqo8gdiWwzdHbdcJgP3HoTbQKEclFeZofDIx1hcqXkJTHKmXuiKz6zLYPuMO
656RLfsTyyPgJi0GsAAAAA
66-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02 b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02
new file mode 100644
index 0000000000..7017055965
--- /dev/null
+++ b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LTfSRAt9yY6SbUpMsRv7xa8nMZNJBJzJT9b/wNjgiOJgaGuJMkV
852g/DX2jfP3PrMM/Sbnz7edORXHj1Pa5XTT8nG5MS0FuZgvevdq3o/gVVAz+ZCKOH3ShMzZvfp01l
86SX5gaJTflmU6cdNwtn2yZ6IScF7OrjUeA9iEoSVR9dQcA+4lB3RAG3LMwcnxXY35D7+PMJzHIZdF
87cSnq+n03ACY2/E/T31iijRH29rvYHGI+mP/ieYs45iq4fTWo6i1HofeWLdP0fX7xW3XO0/hWYFiw
88BxKu66whAbRhaib3XJNvetVs25ToYXyiDpjG+cd5rCMei8sGQwTBj9Zeh0URoeMW1inTP0JvCmMU
89rZgAAAAAAAAAAAAA
90
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02.pem b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02.pem
new file mode 100644
index 0000000000..279c5d830b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/msie-enc-02.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITQAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQAKvi2eRLO+jdoiUd8ksZt+iQ0JXoWN0
6M/W9CEv6R1c42pwUIR/1F4RMK9oeyUiv9Z6lzmPaGNmx6XOCoueszVkwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1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hAZguEv
912WVTXemfbW5GwNjm4ZxeIjDUgRMWVN2AQ0S/x+61m4mx6Cunt+YVfI2g3IU3LKl4
92OszpmpHi8rEWODe0op5WmTD9bgQCSXMzGY2JrMY0MEeydhXevA+Upr4d54TZjGew
93rAYsI2BFhRdNomTjrW9LXrTPd2+H+Yt91nsxgKSY7ds0TcQtQMDDthCRK6j26PN0
94Uq170sLfiyOD1857HdOECDljnSfBibjMGYYzvISovw7pCCczq0gMVL1evINos3Nw
95aExaoy+HM7qwL8ADZZ8uDBLnXsKnTciQlBaob2rDnb4T4YC2mKgl9zMSGW/0GuGO
962126BFKMmsbxJhVgTjMbcC6vl40GgZoAsg4c60/Dz4mi9CYhZwWhon9ZC6CUWta1
977DnUgroXxGIcA4FVq9k65lw7u1X7l6dV+t453Stfxk7LiFiYeGYXWE6utY6f4R4T
98RJgqidc3TUEz3EywrzQKaZxj01Bo8GzCUYNVSdijIgVh+aCafLcnyAMTLlhXbWi2
99G0Ujg12zgLIT1SvCQGPA0A5M6mgkwJC030kQLfcmOkm1KTLEb+8WvJzGTSQScyU/
100W/8DY4IjiYGhriTJFdoPw19o3z9z6zDP0m58+3nTkVx49T2uV00/JxuTEtBbmYL3
101r3at6P4FVQM/mQijh90oTM2b36dNZUl+YGiU35ZlOnHTcLZ9smeiEnBezq41HgPY
102hKElUfXUHAPuJQd0QBtyzMHJ8V2N+Q+/jzCcxyGXRXEp6vp9NwAmNvxP099Yoo0R
1039va72BxiPpj/4nmLOOYquH01qOotR6H3li3T9H1+8Vt1ztP4VmBYsAcSruusIQG0
104YWom91yTb3rVbNuU6GF8og6YxvnHeawjHovLBkMEwY/WXodFEaHjFtYp0z9Cbwpj
105FK2YAAAAAA==
106-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e b/src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e
new file mode 100644
index 0000000000..0067794d70
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/msie-s-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ptx4nuSjC/O944q1KYtqvQiPFWJqEXIRMNbbYOC47sjLza0tEFrimN
85wxcrWGSzsy5R9beFQ1aHPcMrDWfCoviNRk2qPtxuKIC5Qk2ZuOmJLjCiLwUGEb0/1Mpzv3MqQa7d
86mRayXg3DZWJPajxNZv6eS357ElMvwGQmqafb2mlQJwWLsg9m9PG7uqEoyrqSc6MiuY+icLEFib9j
87OfRQrx70rTSKUfTr4MtP0aZZAefjCrpVIyTekhFDOk0Nmx057eonlyGgmGpl5/Uo+t1J1Z11Ya/l
88bNbfmebRISJeTVW0I8FhseAZMI1GSwp/ludJxSLYOgyRkh+GX134MexNo7O9F1SxLCfWaSG9Fc3s
895ify04ua9/t8SGrYZPm/l3MkAAAAAAAAAAAAAA==
90
91
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e.pem b/src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e.pem
new file mode 100644
index 0000000000..55dbd8f80b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/msie-s-a-e.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITUAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQKOxxpIbRTb31+qIQCBOpMVAGnwCLrPO
6OXnntxVveTrPhBnsJuoGNJcCMtuHl7tLkd38WsVwOfGXUprTqFpUcY8wgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU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
90jcN0hxbDhjYUKV9wmTgzCrwKrYYAsYUSB71hIQT1ibK5To4V5TQgKieJcCBnvZIz
91x8HAk+u4sVt2w1gpb6gB+Y+KxdJYxxmZ1Jt+TQZi/68q27d56BJtbDVSwJW1k6H0
92Tlm5DzeXn0IGo72xX9IVTdausnSo1bGuZe72cmflB/mIJGgUZg0dgeQgbkVLo3TQ
93YQNnEaTGaujZ374B2PktUdz9vVxhaau7H6MSojxkrxzJMHRcxsED8dhvH01drOvv
94Oc/j8yW/ellOgRxi36WAscACu1QB2HJuFssjA0yrSCvoTC0OSUFreezhbH+slTwf
95ssazqBXy6p5pKR62/6fP6xCF9y3FnWvH7mrNd/IU5BWk7bcoNC6cGLUGX2TrUOLi
96r0lZzIAMFc8dcnOnuYvwWTvN28wAR+4QPWmF1GboaANihhSzjJAiuFKMWVbKTuFP
97zjvnGTcEi/76hu9ZIC//f6kXoDpTZFcMKFWacbQmc9r3Bhi13MGYt9koGNf4OMPI
98Qyy6E+wLO43hHq0lUSpisHZGrZqbEAYA8OPLtPwK335efw0ZUvXnvkH3xXnFIrQ3
99QivpLV+S9nxmKy+YOkpbZ3DCHldabceJ7kowvzveOKtSmLar0IjxViahFyETDW22
100DguO7Iy82tLRBa4pjcMXK1hks7MuUfW3hUNWhz3DKw1nwqL4jUZNqj7cbiiAuUJN
101mbjpiS4woi8FBhG9P9TKc79zKkGu3ZkWsl4Nw2ViT2o8TWb+nkt+exJTL8BkJqmn
10229ppUCcFi7IPZvTxu7qhKMq6knOjIrmPonCxBYm/Yzn0UK8e9K00ilH06+DLT9Gm
103WQHn4wq6VSMk3pIRQzpNDZsdOe3qJ5choJhqZef1KPrdSdWddWGv5WzW35nm0SEi
104Xk1VtCPBYbHgGTCNRksKf5bnScUi2DoMkZIfhl9d+DHsTaOzvRdUsSwn1mkhvRXN
1057OYn8tOLmvf7fEhq2GT5v5dzJAAAAAA=
106-----END PKCS7-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/nav-smime b/src/lib/libssl/src/crypto/pkcs7/t/nav-smime
new file mode 100644
index 0000000000..6ee4b597a1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/nav-smime
@@ -0,0 +1,157 @@
1From angela@c2.net.au Thu May 14 13:32:27 1998
2X-UIDL: 83c94dd550e54329bf9571b72038b8c8
3Return-Path: angela@c2.net.au
4Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27838 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:32:26 +1000 (EST)
5Message-ID: <355A6779.4B63E64C@cryptsoft.com>
6Date: Thu, 14 May 1998 13:39:37 +1000
7From: Angela van Lent <angela@c2.net.au>
8X-Mailer: Mozilla 4.03 [en] (Win95; U)
9MIME-Version: 1.0
10To: tjh@cryptsoft.com
11Subject: signed
12Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------ms9A58844C95949ECC78A1C54C"
13Content-Length: 2604
14Status: OR
15
16This is a cryptographically signed message in MIME format.
17
18--------------ms9A58844C95949ECC78A1C54C
19Content-Type: text/plain; charset=us-ascii
20Content-Transfer-Encoding: 7bit
21
22signed body
23
24--------------ms9A58844C95949ECC78A1C54C
25Content-Type: application/x-pkcs7-signature; name="smime.p7s"
26Content-Transfer-Encoding: base64
27Content-Disposition: attachment; filename="smime.p7s"
28Content-Description: S/MIME Cryptographic Signature
29
30MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
31BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
32BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
33ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
34AxM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RVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
49BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
50mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
518o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
52ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
53BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
54REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
55AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
56CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
57SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
58BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
599CWR6g==
60--------------ms9A58844C95949ECC78A1C54C--
61
62
63From angela@c2.net.au Thu May 14 13:33:16 1998
64X-UIDL: 8f076c44ff7c5967fd5b00c4588a8731
65Return-Path: angela@c2.net.au
66Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27847 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:33:15 +1000 (EST)
67Message-ID: <355A67AB.2AF38806@cryptsoft.com>
68Date: Thu, 14 May 1998 13:40:27 +1000
69From: Angela van Lent <angela@c2.net.au>
70X-Mailer: Mozilla 4.03 [en] (Win95; U)
71MIME-Version: 1.0
72To: tjh@cryptsoft.com
73Subject: signed
74Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------msD7863B84BD61E02C407F2F5E"
75Content-Length: 2679
76Status: OR
77
78This is a cryptographically signed message in MIME format.
79
80--------------msD7863B84BD61E02C407F2F5E
81Content-Type: text/plain; charset=us-ascii
82Content-Transfer-Encoding: 7bit
83
84signed body 2
85
86--------------msD7863B84BD61E02C407F2F5E
87Content-Type: application/x-pkcs7-signature; name="smime.p7s"
88Content-Transfer-Encoding: base64
89Content-Disposition: attachment; filename="smime.p7s"
90Content-Description: S/MIME Cryptographic Signature
91
92MIIGVgYJKoZIhvcNAQcCoIIGRzCCBkMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
93BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
94BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
95ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
96AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
97gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
98ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
99A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
100dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8v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QQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
116REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
117AgIEfjAJBgUrDgMCGgUAoIGxMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcN
118AQkFMQ8XDTk4MDUxNDAzNDAyN1owIwYJKoZIhvcNAQkEMRYEFOKcV8mNYJnM8rHQajcSEqJN
119rwdDMFIGCSqGSIb3DQEJDzFFMEMwCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMAcGBSsO
120AwIHMA0GCCqGSIb3DQMCAgFAMA0GCCqGSIb3DQMCAgEoMA0GCSqGSIb3DQEBAQUABEADPE/N
121coH+zTFuX5YpolupTKxKK8eEjc48TuADuO8bIHHDE/fEYaWunlwDuTlcFJl1ig0idffPB1qC
122Zp8SSVVY
123--------------msD7863B84BD61E02C407F2F5E--
124
125
126From angela@c2.net.au Thu May 14 14:05:32 1998
127X-UIDL: a7d629b4b9acacaee8b39371b860a32a
128Return-Path: angela@c2.net.au
129Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id OAA28033 for <tjh@cryptsoft.com>; Thu, 14 May 1998 14:05:32 +1000 (EST)
130Message-ID: <355A6F3B.AC385981@cryptsoft.com>
131Date: Thu, 14 May 1998 14:12:43 +1000
132From: Angela van Lent <angela@c2.net.au>
133X-Mailer: Mozilla 4.03 [en] (Win95; U)
134MIME-Version: 1.0
135To: tjh@cryptsoft.com
136Subject: encrypted
137Content-Type: application/x-pkcs7-mime; name="smime.p7m"
138Content-Transfer-Encoding: base64
139Content-Disposition: attachment; filename="smime.p7m"
140Content-Description: S/MIME Encrypted Message
141Content-Length: 905
142Status: OR
143
144MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
145A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
146dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
147ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEA92N29Yk39RUY2tIVd
148exGT2MFX3J6H8LB8aDRJjw7843ALgJ5zXpM5+f80QkAWwEN2A6Pl3VxiCeKLi435zXVyMIHw
149AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
150QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
151UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0G
152CSqGSIb3DQEBAQUABECR9IfyHtvnjFmZ8B2oUCEs1vxMsG0u1kxKE4RMPFyDqDCEARq7zXMg
153nzSUI7Wgv5USSKDqcLRJeW+jvYURv/nJMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
154oAQIrLqrij2ZMpeggAQoibtn6reRZWuWk5Iv5IAhgitr8EYE4w4ySQ7EMB6mTlBoFpccUMWX
155BwQgQn1UoWCvYAlhDzURdbui64Dc0rS2wtj+kE/InS6y25EEEPe4NUKaF8/UlE+lo3LtILQE
156CL3uV8k7m0iqAAAAAAAAAAAAAA==
157
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/s.pem b/src/lib/libssl/src/crypto/pkcs7/t/s.pem
new file mode 100644
index 0000000000..4fa925b182
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/s.pem
@@ -0,0 +1,57 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
3mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
4fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
5zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
6p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
7bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
8IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
9-----END RSA PRIVATE KEY-----
10issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
11subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
12serial :047D
13
14Certificate:
15 Data:
16 Version: 3 (0x2)
17 Serial Number: 1149 (0x47d)
18 Signature Algorithm: md5withRSAEncryption
19 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
20 Validity
21 Not Before: May 13 05:40:58 1998 GMT
22 Not After : May 12 05:40:58 2000 GMT
23 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
24 Subject Public Key Info:
25 Public Key Algorithm: rsaEncryption
26 Modulus:
27 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
28 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
29 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
30 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
31 e7:e7:0c:4d:0b
32 Exponent: 65537 (0x10001)
33 X509v3 extensions:
34 Netscape Comment:
35 Generated with SSLeay
36 Signature Algorithm: md5withRSAEncryption
37 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
38 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
39 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
40 50:74:ad:92:cb:4e:90:e5:fa:7d
41
42-----BEGIN CERTIFICATE-----
43MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
44MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
45ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
46IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
47NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
48UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
49dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
50aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
519w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
52lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
53hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
54UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
554A3ZItobUHStkstOkOX6fQ==
56-----END CERTIFICATE-----
57
diff --git a/src/lib/libssl/src/crypto/pkcs7/t/server.pem b/src/lib/libssl/src/crypto/pkcs7/t/server.pem
new file mode 100644
index 0000000000..989baf8709
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/t/server.pem
@@ -0,0 +1,57 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
49-----BEGIN RSA PRIVATE KEY-----
50MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
51mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
52fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
53zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
54p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
55bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
56IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
57-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/crypto/rand/rand_egd.c b/src/lib/libssl/src/crypto/rand/rand_egd.c
new file mode 100644
index 0000000000..d834408bd4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_egd.c
@@ -0,0 +1,110 @@
1/* crypto/rand/rand_egd.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#include <openssl/rand.h>
58
59/* Query the EGD <URL: http://www.lothar.com/tech/crypto/>.
60 */
61
62#if defined(WIN32) || defined(VMS) || defined(__VMS)
63int RAND_egd(const char *path)
64 {
65 return(-1);
66 }
67#else
68#include <openssl/opensslconf.h>
69#include OPENSSL_UNISTD
70#include <sys/types.h>
71#include <sys/socket.h>
72#include <sys/un.h>
73#include <string.h>
74
75#ifndef offsetof
76# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
77#endif
78
79int RAND_egd(const char *path)
80 {
81 int ret = -1;
82 struct sockaddr_un addr;
83 int len, num;
84 int fd = -1;
85 unsigned char buf[256];
86
87 memset(&addr, 0, sizeof(addr));
88 addr.sun_family = AF_UNIX;
89 if (strlen(path) > sizeof(addr.sun_path))
90 return (-1);
91 strcpy(addr.sun_path,path);
92 len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
93 fd = socket(AF_UNIX, SOCK_STREAM, 0);
94 if (fd == -1) return (-1);
95 if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err;
96 buf[0] = 1;
97 buf[1] = 255;
98 write(fd, buf, 2);
99 if (read(fd, buf, 1) != 1) goto err;
100 if (buf[0] == 0) goto err;
101 num = read(fd, buf, 255);
102 if (num < 1) goto err;
103 RAND_seed(buf, num);
104 if (RAND_status() == 1)
105 ret = num;
106 err:
107 if (fd != -1) close(fd);
108 return(ret);
109 }
110#endif
diff --git a/src/lib/libssl/src/crypto/rand/rand_err.c b/src/lib/libssl/src/crypto/rand/rand_err.c
new file mode 100644
index 0000000000..d1263edf80
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_err.c
@@ -0,0 +1,93 @@
1/* crypto/rand/rand_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/rand.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA RAND_str_functs[]=
67 {
68{ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"},
69{0,NULL}
70 };
71
72static ERR_STRING_DATA RAND_str_reasons[]=
73 {
74{RAND_R_PRNG_NOT_SEEDED ,"prng not seeded"},
75{0,NULL}
76 };
77
78#endif
79
80void ERR_load_RAND_strings(void)
81 {
82 static int init=1;
83
84 if (init)
85 {
86 init=0;
87#ifndef NO_ERR
88 ERR_load_strings(ERR_LIB_RAND,RAND_str_functs);
89 ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons);
90#endif
91
92 }
93 }
diff --git a/src/lib/libssl/src/crypto/rand/rand_lcl.h b/src/lib/libssl/src/crypto/rand/rand_lcl.h
new file mode 100644
index 0000000000..120e9366d2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_lcl.h
@@ -0,0 +1,184 @@
1/* crypto/rand/md_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_RAND_LCL_H
113#define HEADER_RAND_LCL_H
114
115#define ENTROPY_NEEDED 20 /* require 160 bits = 20 bytes of randomness */
116
117
118#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
119#if !defined(NO_SHA) && !defined(NO_SHA1)
120#define USE_SHA1_RAND
121#elif !defined(NO_MD5)
122#define USE_MD5_RAND
123#elif !defined(NO_MDC2) && !defined(NO_DES)
124#define USE_MDC2_RAND
125#elif !defined(NO_MD2)
126#define USE_MD2_RAND
127#else
128#error No message digest algorithm available
129#endif
130#endif
131
132#if defined(USE_MD5_RAND)
133#include <openssl/md5.h>
134#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
135#define MD(a,b,c) MD5(a,b,c)
136#elif defined(USE_SHA1_RAND)
137#include <openssl/sha.h>
138#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
139#define MD(a,b,c) SHA1(a,b,c)
140#elif defined(USE_MDC2_RAND)
141#include <openssl/mdc2.h>
142#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
143#define MD(a,b,c) MDC2(a,b,c)
144#elif defined(USE_MD2_RAND)
145#include <openssl/md2.h>
146#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
147#define MD(a,b,c) MD2(a,b,c)
148#endif
149#if defined(USE_MD5_RAND)
150#include <openssl/md5.h>
151#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
152#define MD_CTX MD5_CTX
153#define MD_Init(a) MD5_Init(a)
154#define MD_Update(a,b,c) MD5_Update(a,b,c)
155#define MD_Final(a,b) MD5_Final(a,b)
156#define MD(a,b,c) MD5(a,b,c)
157#elif defined(USE_SHA1_RAND)
158#include <openssl/sha.h>
159#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
160#define MD_CTX SHA_CTX
161#define MD_Init(a) SHA1_Init(a)
162#define MD_Update(a,b,c) SHA1_Update(a,b,c)
163#define MD_Final(a,b) SHA1_Final(a,b)
164#define MD(a,b,c) SHA1(a,b,c)
165#elif defined(USE_MDC2_RAND)
166#include <openssl/mdc2.h>
167#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
168#define MD_CTX MDC2_CTX
169#define MD_Init(a) MDC2_Init(a)
170#define MD_Update(a,b,c) MDC2_Update(a,b,c)
171#define MD_Final(a,b) MDC2_Final(a,b)
172#define MD(a,b,c) MDC2(a,b,c)
173#elif defined(USE_MD2_RAND)
174#include <openssl/md2.h>
175#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
176#define MD_CTX MD2_CTX
177#define MD_Init(a) MD2_Init(a)
178#define MD_Update(a,b,c) MD2_Update(a,b,c)
179#define MD_Final(a,b) MD2_Final(a,b)
180#define MD(a,b,c) MD2(a,b,c)
181#endif
182
183
184#endif
diff --git a/src/lib/libssl/src/crypto/rand/rand_lib.c b/src/lib/libssl/src/crypto/rand/rand_lib.c
new file mode 100644
index 0000000000..34c6d5b968
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_lib.c
@@ -0,0 +1,98 @@
1/* crypto/rand/rand_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <sys/types.h>
61#include <time.h>
62#include <openssl/rand.h>
63
64#ifdef NO_RAND
65static RAND_METHOD *rand_meth=NULL;
66#else
67extern RAND_METHOD rand_ssleay_meth;
68static RAND_METHOD *rand_meth= &rand_ssleay_meth;
69#endif
70
71void RAND_set_rand_method(RAND_METHOD *meth)
72 {
73 rand_meth=meth;
74 }
75
76RAND_METHOD *RAND_get_rand_method(void)
77 {
78 return(rand_meth);
79 }
80
81void RAND_cleanup(void)
82 {
83 if (rand_meth != NULL)
84 rand_meth->cleanup();
85 }
86
87void RAND_seed(const void *buf, int num)
88 {
89 if (rand_meth != NULL)
90 rand_meth->seed(buf,num);
91 }
92
93void RAND_bytes(unsigned char *buf, int num)
94 {
95 if (rand_meth != NULL)
96 rand_meth->bytes(buf,num);
97 }
98
diff --git a/src/lib/libssl/src/crypto/rand/rand_os2.c b/src/lib/libssl/src/crypto/rand/rand_os2.c
new file mode 100644
index 0000000000..c3e36d4e5e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_os2.c
@@ -0,0 +1,147 @@
1/* crypto/rand/rand_os2.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "cryptlib.h"
57#include <openssl/rand.h>
58#include "rand_lcl.h"
59
60#ifdef OPENSSL_SYS_OS2
61
62#define INCL_DOSPROCESS
63#define INCL_DOSPROFILE
64#define INCL_DOSMISC
65#define INCL_DOSMODULEMGR
66#include <os2.h>
67
68#define CMD_KI_RDCNT (0x63)
69
70typedef struct _CPUUTIL {
71 ULONG ulTimeLow; /* Low 32 bits of time stamp */
72 ULONG ulTimeHigh; /* High 32 bits of time stamp */
73 ULONG ulIdleLow; /* Low 32 bits of idle time */
74 ULONG ulIdleHigh; /* High 32 bits of idle time */
75 ULONG ulBusyLow; /* Low 32 bits of busy time */
76 ULONG ulBusyHigh; /* High 32 bits of busy time */
77 ULONG ulIntrLow; /* Low 32 bits of interrupt time */
78 ULONG ulIntrHigh; /* High 32 bits of interrupt time */
79} CPUUTIL;
80
81APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
82APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
83HMODULE hDoscalls = 0;
84
85int RAND_poll(void)
86{
87 char failed_module[20];
88 QWORD qwTime;
89 ULONG SysVars[QSV_FOREGROUND_PROCESS];
90
91 if (hDoscalls == 0) {
92 ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls);
93
94 if (rc == 0) {
95 rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall);
96
97 if (rc)
98 DosPerfSysCall = NULL;
99
100 rc = DosQueryProcAddr(hDoscalls, 368, NULL, (PFN *)&DosQuerySysState);
101
102 if (rc)
103 DosQuerySysState = NULL;
104 }
105 }
106
107 /* Sample the hi-res timer, runs at around 1.1 MHz */
108 DosTmrQueryTime(&qwTime);
109 RAND_add(&qwTime, sizeof(qwTime), 2);
110
111 /* Sample a bunch of system variables, includes various process & memory statistics */
112 DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
113 RAND_add(SysVars, sizeof(SysVars), 4);
114
115 /* If available, sample CPU registers that count at CPU MHz
116 * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
117 */
118 if (DosPerfSysCall) {
119 CPUUTIL util;
120
121 if (DosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) {
122 RAND_add(&util, sizeof(util), 10);
123 }
124 else {
125 DosPerfSysCall = NULL;
126 }
127 }
128
129 /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
130 if (DosQuerySysState) {
131 char *buffer = OPENSSL_malloc(256 * 1024);
132
133 if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) {
134 /* First 4 bytes in buffer is a pointer to the thread count
135 * there should be at least 1 byte of entropy per thread
136 */
137 RAND_add(buffer, 256 * 1024, **(ULONG **)buffer);
138 }
139
140 OPENSSL_free(buffer);
141 return 1;
142 }
143
144 return 0;
145}
146
147#endif /* OPENSSL_SYS_OS2 */
diff --git a/src/lib/libssl/src/crypto/rand/rand_unix.c b/src/lib/libssl/src/crypto/rand/rand_unix.c
new file mode 100644
index 0000000000..0b29235130
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_unix.c
@@ -0,0 +1,274 @@
1/* crypto/rand/rand_unix.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2))
117
118#include <sys/types.h>
119#include <sys/time.h>
120#include <sys/times.h>
121#include <fcntl.h>
122#include <unistd.h>
123#include <time.h>
124
125#ifdef __OpenBSD__
126#undef DEVRANDOM
127#define DEVRANDOM "/dev/arandom"
128int RAND_poll(void)
129{
130 unsigned long l;
131 pid_t curr_pid = getpid();
132 FILE *fh;
133
134 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
135 * have this. Use /dev/urandom if you can as /dev/random may block
136 * if it runs out of random entries. */
137
138 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
139 {
140 unsigned char tmpbuf[ENTROPY_NEEDED];
141 int n;
142
143 setvbuf(fh, NULL, _IONBF, 0);
144 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
145 fclose(fh);
146 RAND_add(tmpbuf,sizeof tmpbuf,n);
147 memset(tmpbuf,0,n);
148 }
149
150 /* put in some default random data, we need more than just this */
151 l=curr_pid;
152 RAND_add(&l,sizeof(l),0);
153 l=getuid();
154 RAND_add(&l,sizeof(l),0);
155
156 l=time(NULL);
157 RAND_add(&l,sizeof(l),0);
158
159 return 1;
160}
161#else
162int RAND_poll(void)
163{
164 unsigned long l;
165 pid_t curr_pid = getpid();
166#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
167 unsigned char tmpbuf[ENTROPY_NEEDED];
168 int n = 0;
169#endif
170#ifdef DEVRANDOM
171 static const char *randomfiles[] = { DEVRANDOM, NULL };
172 const char **randomfile = NULL;
173 int fd;
174#endif
175#ifdef DEVRANDOM_EGD
176 static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
177 const char **egdsocket = NULL;
178#endif
179
180#ifdef DEVRANDOM
181 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
182 * have this. Use /dev/urandom if you can as /dev/random may block
183 * if it runs out of random entries. */
184
185 for (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++)
186 {
187 if ((fd = open(*randomfile, O_RDONLY|O_NONBLOCK
188#ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it
189 our controlling tty */
190 |O_NOCTTY
191#endif
192#ifdef O_NOFOLLOW /* Fail if the file is a symbolic link */
193 |O_NOFOLLOW
194#endif
195 )) >= 0)
196 {
197 struct timeval t = { 0, 10*1000 }; /* Spend 10ms on
198 each file. */
199 int r;
200 fd_set fset;
201
202 do
203 {
204 FD_ZERO(&fset);
205 FD_SET(fd, &fset);
206 r = -1;
207
208 if (select(fd+1,&fset,NULL,NULL,&t) < 0)
209 t.tv_usec=0;
210 else if (FD_ISSET(fd, &fset))
211 {
212 r=read(fd,(unsigned char *)tmpbuf+n,
213 ENTROPY_NEEDED-n);
214 if (r > 0)
215 n += r;
216 }
217
218 /* Some Unixen will update t, some
219 won't. For those who won't, give
220 up here, otherwise, we will do
221 this once again for the remaining
222 time. */
223 if (t.tv_usec == 10*1000)
224 t.tv_usec=0;
225 }
226 while ((r > 0 || (errno == EINTR || errno == EAGAIN))
227 && t.tv_usec != 0 && n < ENTROPY_NEEDED);
228
229 close(fd);
230 }
231 }
232#endif
233
234#ifdef DEVRANDOM_EGD
235 /* Use an EGD socket to read entropy from an EGD or PRNGD entropy
236 * collecting daemon. */
237
238 for (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++)
239 {
240 int r;
241
242 r = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n,
243 ENTROPY_NEEDED-n);
244 if (r > 0)
245 n += r;
246 }
247#endif
248
249#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
250 if (n > 0)
251 {
252 RAND_add(tmpbuf,sizeof tmpbuf,n);
253 memset(tmpbuf,0,n);
254 }
255#endif
256
257 /* put in some default random data, we need more than just this */
258 l=curr_pid;
259 RAND_add(&l,sizeof(l),0);
260 l=getuid();
261 RAND_add(&l,sizeof(l),0);
262
263 l=time(NULL);
264 RAND_add(&l,sizeof(l),0);
265
266#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
267 return 1;
268#else
269 return 0;
270#endif
271}
272
273#endif
274#endif
diff --git a/src/lib/libssl/src/crypto/rand/rand_vms.c b/src/lib/libssl/src/crypto/rand/rand_vms.c
new file mode 100644
index 0000000000..29b2d7af0b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_vms.c
@@ -0,0 +1,135 @@
1/* crypto/rand/rand_vms.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/rand.h>
60#include "rand_lcl.h"
61
62#if defined(OPENSSL_SYS_VMS)
63
64#include <descrip.h>
65#include <jpidef.h>
66#include <ssdef.h>
67#include <starlet.h>
68#ifdef __DECC
69# pragma message disable DOLLARID
70#endif
71
72static struct items_data_st
73 {
74 short length, code; /* length is amount of bytes */
75 } items_data[] =
76 { { 4, JPI$_BUFIO },
77 { 4, JPI$_CPUTIM },
78 { 4, JPI$_DIRIO },
79 { 8, JPI$_LOGINTIM },
80 { 4, JPI$_PAGEFLTS },
81 { 4, JPI$_PID },
82 { 4, JPI$_WSSIZE },
83 { 0, 0 }
84 };
85
86int RAND_poll(void)
87 {
88 long pid, iosb[2];
89 int status = 0;
90 struct
91 {
92 short length, code;
93 long *buffer;
94 int *retlen;
95 } item[32], *pitem;
96 unsigned char data_buffer[256];
97 short total_length = 0;
98 struct items_data_st *pitems_data;
99
100 pitems_data = items_data;
101 pitem = item;
102
103 /* Setup */
104 while (pitems_data->length)
105 {
106 pitem->length = pitems_data->length;
107 pitem->code = pitems_data->code;
108 pitem->buffer = (long *)data_buffer[total_length];
109 pitem->retlen = 0;
110 total_length += pitems_data->length;
111 pitems_data++;
112 pitem++;
113 }
114 pitem->length = pitem->code = 0;
115
116 /*
117 * Scan through all the processes in the system and add entropy with
118 * results from the processes that were possible to look at.
119 * However, view the information as only half trustable.
120 */
121 pid = -1; /* search context */
122 while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0))
123 != SS$_NOMOREPROC)
124 {
125 if (status == SS$_NORMAL)
126 {
127 RAND_add(data_buffer, total_length, total_length/2);
128 }
129 }
130 sys$gettim(iosb);
131 RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb)/2);
132 return 1;
133}
134
135#endif
diff --git a/src/lib/libssl/src/crypto/rand/rand_win.c b/src/lib/libssl/src/crypto/rand/rand_win.c
new file mode 100644
index 0000000000..9f2dcff9a9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand_win.c
@@ -0,0 +1,732 @@
1/* crypto/rand/rand_win.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if defined(WINDOWS) || defined(WIN32)
117#include <windows.h>
118#ifndef _WIN32_WINNT
119# define _WIN32_WINNT 0x0400
120#endif
121#include <wincrypt.h>
122#include <tlhelp32.h>
123
124/* Intel hardware RNG CSP -- available from
125 * http://developer.intel.com/design/security/rng/redist_license.htm
126 */
127#define PROV_INTEL_SEC 22
128#define INTEL_DEF_PROV "Intel Hardware Cryptographic Service Provider"
129
130static void readtimer(void);
131static void readscreen(void);
132
133/* It appears like CURSORINFO, PCURSORINFO and LPCURSORINFO are only defined
134 when WINVER is 0x0500 and up, which currently only happens on Win2000.
135 Unfortunately, those are typedefs, so they're a little bit difficult to
136 detect properly. On the other hand, the macro CURSOR_SHOWING is defined
137 within the same conditional, so it can be use to detect the absence of said
138 typedefs. */
139
140#ifndef CURSOR_SHOWING
141/*
142 * Information about the global cursor.
143 */
144typedef struct tagCURSORINFO
145{
146 DWORD cbSize;
147 DWORD flags;
148 HCURSOR hCursor;
149 POINT ptScreenPos;
150} CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
151
152#define CURSOR_SHOWING 0x00000001
153#endif /* CURSOR_SHOWING */
154
155typedef BOOL (WINAPI *CRYPTACQUIRECONTEXT)(HCRYPTPROV *, LPCTSTR, LPCTSTR,
156 DWORD, DWORD);
157typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *);
158typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD);
159
160typedef HWND (WINAPI *GETFOREGROUNDWINDOW)(VOID);
161typedef BOOL (WINAPI *GETCURSORINFO)(PCURSORINFO);
162typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);
163
164typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
165typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
166typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
167typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
168typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32);
169typedef BOOL (WINAPI *THREAD32)(HANDLE, LPTHREADENTRY32);
170typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32);
171
172#include <lmcons.h>
173#include <lmstats.h>
174#if 1 /* The NET API is Unicode only. It requires the use of the UNICODE
175 * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was
176 * was added to the Platform SDK to allow the NET API to be used in
177 * non-Unicode applications provided that Unicode strings were still
178 * used for input. LMSTR is defined as LPWSTR.
179 */
180typedef NET_API_STATUS (NET_API_FUNCTION * NETSTATGET)
181 (LPWSTR, LPWSTR, DWORD, DWORD, LPBYTE*);
182typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE);
183#endif /* 1 */
184
185int RAND_poll(void)
186{
187 MEMORYSTATUS m;
188 HCRYPTPROV hProvider = 0;
189 BYTE buf[64];
190 DWORD w;
191 HWND h;
192
193 HMODULE advapi, kernel, user, netapi;
194 CRYPTACQUIRECONTEXT acquire = 0;
195 CRYPTGENRANDOM gen = 0;
196 CRYPTRELEASECONTEXT release = 0;
197#if 1 /* There was previously a problem with NETSTATGET. Currently, this
198 * section is still experimental, but if all goes well, this conditional
199 * will be removed
200 */
201 NETSTATGET netstatget = 0;
202 NETFREE netfree = 0;
203#endif /* 1 */
204
205 /* Determine the OS version we are on so we can turn off things
206 * that do not work properly.
207 */
208 OSVERSIONINFO osverinfo ;
209 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
210 GetVersionEx( &osverinfo ) ;
211
212 /* load functions dynamically - not available on all systems */
213 advapi = LoadLibrary("ADVAPI32.DLL");
214 kernel = LoadLibrary("KERNEL32.DLL");
215 user = LoadLibrary("USER32.DLL");
216 netapi = LoadLibrary("NETAPI32.DLL");
217
218#if 1 /* There was previously a problem with NETSTATGET. Currently, this
219 * section is still experimental, but if all goes well, this conditional
220 * will be removed
221 */
222 if (netapi)
223 {
224 netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
225 netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree");
226 }
227
228 if (netstatget && netfree)
229 {
230 LPBYTE outbuf;
231 /* NetStatisticsGet() is a Unicode only function
232 * STAT_WORKSTATION_0 contains 45 fields and STAT_SERVER_0
233 * contains 17 fields. We treat each field as a source of
234 * one byte of entropy.
235 */
236
237 if (netstatget(NULL, L"LanmanWorkstation", 0, 0, &outbuf) == 0)
238 {
239 RAND_add(outbuf, sizeof(STAT_WORKSTATION_0), 45);
240 netfree(outbuf);
241 }
242 if (netstatget(NULL, L"LanmanServer", 0, 0, &outbuf) == 0)
243 {
244 RAND_add(outbuf, sizeof(STAT_SERVER_0), 17);
245 netfree(outbuf);
246 }
247 }
248
249 if (netapi)
250 FreeLibrary(netapi);
251#endif /* 1 */
252
253 /* It appears like this can cause an exception deep within ADVAPI32.DLL
254 * at random times on Windows 2000. Reported by Jeffrey Altman.
255 * Only use it on NT.
256 */
257 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
258 osverinfo.dwMajorVersion < 5)
259 {
260 /* Read Performance Statistics from NT/2000 registry
261 * The size of the performance data can vary from call
262 * to call so we must guess the size of the buffer to use
263 * and increase its size if we get an ERROR_MORE_DATA
264 * return instead of ERROR_SUCCESS.
265 */
266 LONG rc=ERROR_MORE_DATA;
267 char * buf=NULL;
268 DWORD bufsz=0;
269 DWORD length;
270
271 while (rc == ERROR_MORE_DATA)
272 {
273 buf = realloc(buf,bufsz+8192);
274 if (!buf)
275 break;
276 bufsz += 8192;
277
278 length = bufsz;
279 rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global",
280 NULL, NULL, buf, &length);
281 }
282 if (rc == ERROR_SUCCESS)
283 {
284 /* For entropy count assume only least significant
285 * byte of each DWORD is random.
286 */
287 RAND_add(&length, sizeof(length), 0);
288 RAND_add(buf, length, length / 4.0);
289 }
290 if (buf)
291 free(buf);
292 }
293
294 if (advapi)
295 {
296 acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi,
297 "CryptAcquireContextA");
298 gen = (CRYPTGENRANDOM) GetProcAddress(advapi,
299 "CryptGenRandom");
300 release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi,
301 "CryptReleaseContext");
302 }
303
304 if (acquire && gen && release)
305 {
306 /* poll the CryptoAPI PRNG */
307 /* The CryptoAPI returns sizeof(buf) bytes of randomness */
308 if (acquire(&hProvider, 0, 0, PROV_RSA_FULL,
309 CRYPT_VERIFYCONTEXT))
310 {
311 if (gen(hProvider, sizeof(buf), buf) != 0)
312 {
313 RAND_add(buf, sizeof(buf), sizeof(buf));
314#ifdef DEBUG
315 printf("randomness from PROV_RSA_FULL\n");
316#endif
317 }
318 release(hProvider, 0);
319 }
320
321 /* poll the Pentium PRG with CryptoAPI */
322 if (acquire(&hProvider, 0, INTEL_DEF_PROV, PROV_INTEL_SEC, 0))
323 {
324 if (gen(hProvider, sizeof(buf), buf) != 0)
325 {
326 RAND_add(buf, sizeof(buf), sizeof(buf));
327#ifdef DEBUG
328 printf("randomness from PROV_INTEL_SEC\n");
329#endif
330 }
331 release(hProvider, 0);
332 }
333 }
334
335 if (advapi)
336 FreeLibrary(advapi);
337
338 /* timer data */
339 readtimer();
340
341 /* memory usage statistics */
342 GlobalMemoryStatus(&m);
343 RAND_add(&m, sizeof(m), 1);
344
345 /* process ID */
346 w = GetCurrentProcessId();
347 RAND_add(&w, sizeof(w), 1);
348
349 if (user)
350 {
351 GETCURSORINFO cursor;
352 GETFOREGROUNDWINDOW win;
353 GETQUEUESTATUS queue;
354
355 win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow");
356 cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo");
357 queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus");
358
359 if (win)
360 {
361 /* window handle */
362 h = win();
363 RAND_add(&h, sizeof(h), 0);
364 }
365 if (cursor)
366 {
367 /* unfortunately, its not safe to call GetCursorInfo()
368 * on NT4 even though it exists in SP3 (or SP6) and
369 * higher.
370 */
371 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
372 osverinfo.dwMajorVersion < 5)
373 cursor = 0;
374 }
375 if (cursor)
376 {
377 /* cursor position */
378 /* assume 2 bytes of entropy */
379 CURSORINFO ci;
380 ci.cbSize = sizeof(CURSORINFO);
381 if (cursor(&ci))
382 RAND_add(&ci, ci.cbSize, 2);
383 }
384
385 if (queue)
386 {
387 /* message queue status */
388 /* assume 1 byte of entropy */
389 w = queue(QS_ALLEVENTS);
390 RAND_add(&w, sizeof(w), 1);
391 }
392
393 FreeLibrary(user);
394 }
395
396 /* Toolhelp32 snapshot: enumerate processes, threads, modules and heap
397 * http://msdn.microsoft.com/library/psdk/winbase/toolhelp_5pfd.htm
398 * (Win 9x and 2000 only, not available on NT)
399 *
400 * This seeding method was proposed in Peter Gutmann, Software
401 * Generation of Practically Strong Random Numbers,
402 * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
403 * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
404 * (The assignment of entropy estimates below is arbitrary, but based
405 * on Peter's analysis the full poll appears to be safe. Additional
406 * interactive seeding is encouraged.)
407 */
408
409 if (kernel)
410 {
411 CREATETOOLHELP32SNAPSHOT snap;
412 HANDLE handle;
413
414 HEAP32FIRST heap_first;
415 HEAP32NEXT heap_next;
416 HEAP32LIST heaplist_first, heaplist_next;
417 PROCESS32 process_first, process_next;
418 THREAD32 thread_first, thread_next;
419 MODULE32 module_first, module_next;
420
421 HEAPLIST32 hlist;
422 HEAPENTRY32 hentry;
423 PROCESSENTRY32 p;
424 THREADENTRY32 t;
425 MODULEENTRY32 m;
426
427 snap = (CREATETOOLHELP32SNAPSHOT)
428 GetProcAddress(kernel, "CreateToolhelp32Snapshot");
429 heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First");
430 heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next");
431 heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst");
432 heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext");
433 process_first = (PROCESS32) GetProcAddress(kernel, "Process32First");
434 process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next");
435 thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First");
436 thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next");
437 module_first = (MODULE32) GetProcAddress(kernel, "Module32First");
438 module_next = (MODULE32) GetProcAddress(kernel, "Module32Next");
439
440 if (snap && heap_first && heap_next && heaplist_first &&
441 heaplist_next && process_first && process_next &&
442 thread_first && thread_next && module_first &&
443 module_next && (handle = snap(TH32CS_SNAPALL,0))
444 != NULL)
445 {
446 /* heap list and heap walking */
447 /* HEAPLIST32 contains 3 fields that will change with
448 * each entry. Consider each field a source of 1 byte
449 * of entropy.
450 * HEAPENTRY32 contains 5 fields that will change with
451 * each entry. Consider each field a source of 1 byte
452 * of entropy.
453 */
454 hlist.dwSize = sizeof(HEAPLIST32);
455 if (heaplist_first(handle, &hlist))
456 do
457 {
458 RAND_add(&hlist, hlist.dwSize, 3);
459 hentry.dwSize = sizeof(HEAPENTRY32);
460 if (heap_first(&hentry,
461 hlist.th32ProcessID,
462 hlist.th32HeapID))
463 {
464 int entrycnt = 50;
465 do
466 RAND_add(&hentry,
467 hentry.dwSize, 5);
468 while (heap_next(&hentry)
469 && --entrycnt > 0);
470 }
471 } while (heaplist_next(handle,
472 &hlist));
473
474 /* process walking */
475 /* PROCESSENTRY32 contains 9 fields that will change
476 * with each entry. Consider each field a source of
477 * 1 byte of entropy.
478 */
479 p.dwSize = sizeof(PROCESSENTRY32);
480 if (process_first(handle, &p))
481 do
482 RAND_add(&p, p.dwSize, 9);
483 while (process_next(handle, &p));
484
485 /* thread walking */
486 /* THREADENTRY32 contains 6 fields that will change
487 * with each entry. Consider each field a source of
488 * 1 byte of entropy.
489 */
490 t.dwSize = sizeof(THREADENTRY32);
491 if (thread_first(handle, &t))
492 do
493 RAND_add(&t, t.dwSize, 6);
494 while (thread_next(handle, &t));
495
496 /* module walking */
497 /* MODULEENTRY32 contains 9 fields that will change
498 * with each entry. Consider each field a source of
499 * 1 byte of entropy.
500 */
501 m.dwSize = sizeof(MODULEENTRY32);
502 if (module_first(handle, &m))
503 do
504 RAND_add(&m, m.dwSize, 9);
505 while (module_next(handle, &m));
506
507 CloseHandle(handle);
508 }
509
510 FreeLibrary(kernel);
511 }
512
513#ifdef DEBUG
514 printf("Exiting RAND_poll\n");
515#endif
516
517 return(1);
518}
519
520int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam)
521 {
522 double add_entropy=0;
523
524 switch (iMsg)
525 {
526 case WM_KEYDOWN:
527 {
528 static WPARAM key;
529 if (key != wParam)
530 add_entropy = 0.05;
531 key = wParam;
532 }
533 break;
534 case WM_MOUSEMOVE:
535 {
536 static int lastx,lasty,lastdx,lastdy;
537 int x,y,dx,dy;
538
539 x=LOWORD(lParam);
540 y=HIWORD(lParam);
541 dx=lastx-x;
542 dy=lasty-y;
543 if (dx != 0 && dy != 0 && dx-lastdx != 0 && dy-lastdy != 0)
544 add_entropy=.2;
545 lastx=x, lasty=y;
546 lastdx=dx, lastdy=dy;
547 }
548 break;
549 }
550
551 readtimer();
552 RAND_add(&iMsg, sizeof(iMsg), add_entropy);
553 RAND_add(&wParam, sizeof(wParam), 0);
554 RAND_add(&lParam, sizeof(lParam), 0);
555
556 return (RAND_status());
557 }
558
559
560void RAND_screen(void) /* function available for backward compatibility */
561{
562 RAND_poll();
563 readscreen();
564}
565
566
567/* feed timing information to the PRNG */
568static void readtimer(void)
569{
570 DWORD w;
571 LARGE_INTEGER l;
572 static int have_perfc = 1;
573#ifndef __GNUC__
574 static int have_tsc = 1;
575 DWORD cyclecount;
576
577 if (have_tsc) {
578 __try {
579 __asm {
580 rdtsc
581 mov cyclecount, eax
582 }
583 RAND_add(&cyclecount, sizeof(cyclecount), 1);
584 } __except(EXCEPTION_EXECUTE_HANDLER) {
585 have_tsc = 0;
586 }
587 }
588#else
589# define have_tsc 0
590#endif
591
592 if (have_perfc) {
593 if (QueryPerformanceCounter(&l) == 0)
594 have_perfc = 0;
595 else
596 RAND_add(&l, sizeof(l), 0);
597 }
598
599 if (!have_tsc && !have_perfc) {
600 w = GetTickCount();
601 RAND_add(&w, sizeof(w), 0);
602 }
603}
604
605/* feed screen contents to PRNG */
606/*****************************************************************************
607 *
608 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
609 *
610 * Code adapted from
611 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
612 * the original copyright message is:
613 *
614 * (C) Copyright Microsoft Corp. 1993. All rights reserved.
615 *
616 * You have a royalty-free right to use, modify, reproduce and
617 * distribute the Sample Files (and/or any modified version) in
618 * any way you find useful, provided that you agree that
619 * Microsoft has no warranty obligations or liability for any
620 * Sample Application Files which are modified.
621 */
622
623static void readscreen(void)
624{
625 HDC hScrDC; /* screen DC */
626 HDC hMemDC; /* memory DC */
627 HBITMAP hBitmap; /* handle for our bitmap */
628 HBITMAP hOldBitmap; /* handle for previous bitmap */
629 BITMAP bm; /* bitmap properties */
630 unsigned int size; /* size of bitmap */
631 char *bmbits; /* contents of bitmap */
632 int w; /* screen width */
633 int h; /* screen height */
634 int y; /* y-coordinate of screen lines to grab */
635 int n = 16; /* number of screen lines to grab at a time */
636
637 /* Create a screen DC and a memory DC compatible to screen DC */
638 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
639 hMemDC = CreateCompatibleDC(hScrDC);
640
641 /* Get screen resolution */
642 w = GetDeviceCaps(hScrDC, HORZRES);
643 h = GetDeviceCaps(hScrDC, VERTRES);
644
645 /* Create a bitmap compatible with the screen DC */
646 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
647
648 /* Select new bitmap into memory DC */
649 hOldBitmap = SelectObject(hMemDC, hBitmap);
650
651 /* Get bitmap properties */
652 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
653 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
654
655 bmbits = OPENSSL_malloc(size);
656 if (bmbits) {
657 /* Now go through the whole screen, repeatedly grabbing n lines */
658 for (y = 0; y < h-n; y += n)
659 {
660 unsigned char md[MD_DIGEST_LENGTH];
661
662 /* Bitblt screen DC to memory DC */
663 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
664
665 /* Copy bitmap bits from memory DC to bmbits */
666 GetBitmapBits(hBitmap, size, bmbits);
667
668 /* Get the hash of the bitmap */
669 MD(bmbits,size,md);
670
671 /* Seed the random generator with the hash value */
672 RAND_add(md, MD_DIGEST_LENGTH, 0);
673 }
674
675 OPENSSL_free(bmbits);
676 }
677
678 /* Select old bitmap back into memory DC */
679 hBitmap = SelectObject(hMemDC, hOldBitmap);
680
681 /* Clean up */
682 DeleteObject(hBitmap);
683 DeleteDC(hMemDC);
684 DeleteDC(hScrDC);
685}
686
687#else /* Unix version */
688
689#include <time.h>
690
691int RAND_poll(void)
692{
693 unsigned long l;
694 pid_t curr_pid = getpid();
695#ifdef DEVRANDOM
696 FILE *fh;
697#endif
698
699#ifdef DEVRANDOM
700 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
701 * have this. Use /dev/urandom if you can as /dev/random may block
702 * if it runs out of random entries. */
703
704 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
705 {
706 unsigned char tmpbuf[ENTROPY_NEEDED];
707 int n;
708
709 setvbuf(fh, NULL, _IONBF, 0);
710 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
711 fclose(fh);
712 RAND_add(tmpbuf,sizeof tmpbuf,n);
713 memset(tmpbuf,0,n);
714 }
715#endif
716
717 /* put in some default random data, we need more than just this */
718 l=curr_pid;
719 RAND_add(&l,sizeof(l),0);
720 l=getuid();
721 RAND_add(&l,sizeof(l),0);
722
723 l=time(NULL);
724 RAND_add(&l,sizeof(l),0);
725
726#ifdef DEVRANDOM
727 return 1;
728#endif
729 return 0;
730}
731
732#endif
diff --git a/src/lib/libssl/src/crypto/rc2/rc2.h b/src/lib/libssl/src/crypto/rc2/rc2.h
new file mode 100644
index 0000000000..9571efb755
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2.h
@@ -0,0 +1,99 @@
1/* crypto/rc2/rc2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC2_H
60#define HEADER_RC2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_RC2
67#error RC2 is disabled.
68#endif
69
70#define RC2_ENCRYPT 1
71#define RC2_DECRYPT 0
72
73#include <openssl/opensslconf.h> /* RC2_INT */
74#define RC2_BLOCK 8
75#define RC2_KEY_LENGTH 16
76
77typedef struct rc2_key_st
78 {
79 RC2_INT data[64];
80 } RC2_KEY;
81
82
83void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits);
84void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key,
85 int enc);
86void RC2_encrypt(unsigned long *data,RC2_KEY *key);
87void RC2_decrypt(unsigned long *data,RC2_KEY *key);
88void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
89 RC2_KEY *ks, unsigned char *iv, int enc);
90void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
91 RC2_KEY *schedule, unsigned char *ivec, int *num, int enc);
92void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
93 RC2_KEY *schedule, unsigned char *ivec, int *num);
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libssl/src/crypto/rc2/tab.c b/src/lib/libssl/src/crypto/rc2/tab.c
new file mode 100644
index 0000000000..25dc14eeba
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/tab.c
@@ -0,0 +1,86 @@
1#include <stdio.h>
2
3unsigned char ebits_to_num[256]={
4 0xbd,0x56,0xea,0xf2,0xa2,0xf1,0xac,0x2a,
5 0xb0,0x93,0xd1,0x9c,0x1b,0x33,0xfd,0xd0,
6 0x30,0x04,0xb6,0xdc,0x7d,0xdf,0x32,0x4b,
7 0xf7,0xcb,0x45,0x9b,0x31,0xbb,0x21,0x5a,
8 0x41,0x9f,0xe1,0xd9,0x4a,0x4d,0x9e,0xda,
9 0xa0,0x68,0x2c,0xc3,0x27,0x5f,0x80,0x36,
10 0x3e,0xee,0xfb,0x95,0x1a,0xfe,0xce,0xa8,
11 0x34,0xa9,0x13,0xf0,0xa6,0x3f,0xd8,0x0c,
12 0x78,0x24,0xaf,0x23,0x52,0xc1,0x67,0x17,
13 0xf5,0x66,0x90,0xe7,0xe8,0x07,0xb8,0x60,
14 0x48,0xe6,0x1e,0x53,0xf3,0x92,0xa4,0x72,
15 0x8c,0x08,0x15,0x6e,0x86,0x00,0x84,0xfa,
16 0xf4,0x7f,0x8a,0x42,0x19,0xf6,0xdb,0xcd,
17 0x14,0x8d,0x50,0x12,0xba,0x3c,0x06,0x4e,
18 0xec,0xb3,0x35,0x11,0xa1,0x88,0x8e,0x2b,
19 0x94,0x99,0xb7,0x71,0x74,0xd3,0xe4,0xbf,
20 0x3a,0xde,0x96,0x0e,0xbc,0x0a,0xed,0x77,
21 0xfc,0x37,0x6b,0x03,0x79,0x89,0x62,0xc6,
22 0xd7,0xc0,0xd2,0x7c,0x6a,0x8b,0x22,0xa3,
23 0x5b,0x05,0x5d,0x02,0x75,0xd5,0x61,0xe3,
24 0x18,0x8f,0x55,0x51,0xad,0x1f,0x0b,0x5e,
25 0x85,0xe5,0xc2,0x57,0x63,0xca,0x3d,0x6c,
26 0xb4,0xc5,0xcc,0x70,0xb2,0x91,0x59,0x0d,
27 0x47,0x20,0xc8,0x4f,0x58,0xe0,0x01,0xe2,
28 0x16,0x38,0xc4,0x6f,0x3b,0x0f,0x65,0x46,
29 0xbe,0x7e,0x2d,0x7b,0x82,0xf9,0x40,0xb5,
30 0x1d,0x73,0xf8,0xeb,0x26,0xc7,0x87,0x97,
31 0x25,0x54,0xb1,0x28,0xaa,0x98,0x9d,0xa5,
32 0x64,0x6d,0x7a,0xd4,0x10,0x81,0x44,0xef,
33 0x49,0xd6,0xae,0x2e,0xdd,0x76,0x5c,0x2f,
34 0xa7,0x1c,0xc9,0x09,0x69,0x9a,0x83,0xcf,
35 0x29,0x39,0xb9,0xe9,0x4c,0xff,0x43,0xab,
36 };
37
38unsigned char num_to_ebits[256]={
39 0x5d,0xbe,0x9b,0x8b,0x11,0x99,0x6e,0x4d,
40 0x59,0xf3,0x85,0xa6,0x3f,0xb7,0x83,0xc5,
41 0xe4,0x73,0x6b,0x3a,0x68,0x5a,0xc0,0x47,
42 0xa0,0x64,0x34,0x0c,0xf1,0xd0,0x52,0xa5,
43 0xb9,0x1e,0x96,0x43,0x41,0xd8,0xd4,0x2c,
44 0xdb,0xf8,0x07,0x77,0x2a,0xca,0xeb,0xef,
45 0x10,0x1c,0x16,0x0d,0x38,0x72,0x2f,0x89,
46 0xc1,0xf9,0x80,0xc4,0x6d,0xae,0x30,0x3d,
47 0xce,0x20,0x63,0xfe,0xe6,0x1a,0xc7,0xb8,
48 0x50,0xe8,0x24,0x17,0xfc,0x25,0x6f,0xbb,
49 0x6a,0xa3,0x44,0x53,0xd9,0xa2,0x01,0xab,
50 0xbc,0xb6,0x1f,0x98,0xee,0x9a,0xa7,0x2d,
51 0x4f,0x9e,0x8e,0xac,0xe0,0xc6,0x49,0x46,
52 0x29,0xf4,0x94,0x8a,0xaf,0xe1,0x5b,0xc3,
53 0xb3,0x7b,0x57,0xd1,0x7c,0x9c,0xed,0x87,
54 0x40,0x8c,0xe2,0xcb,0x93,0x14,0xc9,0x61,
55 0x2e,0xe5,0xcc,0xf6,0x5e,0xa8,0x5c,0xd6,
56 0x75,0x8d,0x62,0x95,0x58,0x69,0x76,0xa1,
57 0x4a,0xb5,0x55,0x09,0x78,0x33,0x82,0xd7,
58 0xdd,0x79,0xf5,0x1b,0x0b,0xde,0x26,0x21,
59 0x28,0x74,0x04,0x97,0x56,0xdf,0x3c,0xf0,
60 0x37,0x39,0xdc,0xff,0x06,0xa4,0xea,0x42,
61 0x08,0xda,0xb4,0x71,0xb0,0xcf,0x12,0x7a,
62 0x4e,0xfa,0x6c,0x1d,0x84,0x00,0xc8,0x7f,
63 0x91,0x45,0xaa,0x2b,0xc2,0xb1,0x8f,0xd5,
64 0xba,0xf2,0xad,0x19,0xb2,0x67,0x36,0xf7,
65 0x0f,0x0a,0x92,0x7d,0xe3,0x9d,0xe9,0x90,
66 0x3e,0x23,0x27,0x66,0x13,0xec,0x81,0x15,
67 0xbd,0x22,0xbf,0x9f,0x7e,0xa9,0x51,0x4b,
68 0x4c,0xfb,0x02,0xd3,0x70,0x86,0x31,0xe7,
69 0x3b,0x05,0x03,0x54,0x60,0x48,0x65,0x18,
70 0xd2,0xcd,0x5f,0x32,0x88,0x0e,0x35,0xfd,
71 };
72
73main()
74 {
75 int i,j;
76
77 for (i=0; i<256; i++)
78 {
79 for (j=0; j<256; j++)
80 if (ebits_to_num[j] == i)
81 {
82 printf("0x%02x,",j);
83 break;
84 }
85 }
86 }
diff --git a/src/lib/libssl/src/crypto/rc4/rc4.h b/src/lib/libssl/src/crypto/rc4/rc4.h
new file mode 100644
index 0000000000..7418c2a9a2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4.h
@@ -0,0 +1,88 @@
1/* crypto/rc4/rc4.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC4_H
60#define HEADER_RC4_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_RC4
67#error RC4 is disabled.
68#endif
69
70#include <openssl/opensslconf.h> /* RC4_INT */
71
72typedef struct rc4_key_st
73 {
74 RC4_INT x,y;
75 RC4_INT data[256];
76 } RC4_KEY;
77
78
79const char *RC4_options(void);
80void RC4_set_key(RC4_KEY *key, int len, unsigned char *data);
81void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata,
82 unsigned char *outdata);
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif
diff --git a/src/lib/libssl/src/crypto/rc4/rc4_locl.h b/src/lib/libssl/src/crypto/rc4/rc4_locl.h
new file mode 100644
index 0000000000..3bb80b6ce9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4_locl.h
@@ -0,0 +1,4 @@
1#ifndef HEADER_RC4_LOCL_H
2#define HEADER_RC4_LOCL_H
3#include <openssl/opensslconf.h>
4#endif
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_asn1.c b/src/lib/libssl/src/crypto/rsa/rsa_asn1.c
new file mode 100644
index 0000000000..1455a7e0e4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_asn1.c
@@ -0,0 +1,121 @@
1/* rsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/asn1t.h>
64
65static ASN1_METHOD method={
66 (int (*)()) i2d_RSAPrivateKey,
67 (char *(*)())d2i_RSAPrivateKey,
68 (char *(*)())RSA_new,
69 (void (*)()) RSA_free};
70
71ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
72 {
73 return(&method);
74 }
75
76/* Override the default free and new methods */
77static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{
79 if(operation == ASN1_OP_NEW_PRE) {
80 *pval = (ASN1_VALUE *)RSA_new();
81 if(*pval) return 2;
82 return 0;
83 } else if(operation == ASN1_OP_FREE_PRE) {
84 RSA_free((RSA *)*pval);
85 *pval = NULL;
86 return 2;
87 }
88 return 1;
89}
90
91ASN1_SEQUENCE_cb(RSAPrivateKey, rsa_cb) = {
92 ASN1_SIMPLE(RSA, version, LONG),
93 ASN1_SIMPLE(RSA, n, BIGNUM),
94 ASN1_SIMPLE(RSA, e, BIGNUM),
95 ASN1_SIMPLE(RSA, d, BIGNUM),
96 ASN1_SIMPLE(RSA, p, BIGNUM),
97 ASN1_SIMPLE(RSA, q, BIGNUM),
98 ASN1_SIMPLE(RSA, dmp1, BIGNUM),
99 ASN1_SIMPLE(RSA, dmq1, BIGNUM),
100 ASN1_SIMPLE(RSA, iqmp, BIGNUM)
101} ASN1_SEQUENCE_END_cb(RSA, RSAPrivateKey)
102
103
104ASN1_SEQUENCE_cb(RSAPublicKey, rsa_cb) = {
105 ASN1_SIMPLE(RSA, n, BIGNUM),
106 ASN1_SIMPLE(RSA, e, BIGNUM),
107} ASN1_SEQUENCE_END_cb(RSA, RSAPublicKey)
108
109IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPrivateKey, RSAPrivateKey)
110
111IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPublicKey, RSAPublicKey)
112
113RSA *RSAPublicKey_dup(RSA *rsa)
114 {
115 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPublicKey), rsa);
116 }
117
118RSA *RSAPrivateKey_dup(RSA *rsa)
119 {
120 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPrivateKey), rsa);
121 }
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_chk.c b/src/lib/libssl/src/crypto/rsa/rsa_chk.c
new file mode 100644
index 0000000000..91b9115798
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_chk.c
@@ -0,0 +1,184 @@
1/* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 */
50
51#include <openssl/bn.h>
52#include <openssl/err.h>
53#include <openssl/rsa.h>
54
55
56int RSA_check_key(RSA *key)
57 {
58 BIGNUM *i, *j, *k, *l, *m;
59 BN_CTX *ctx;
60 int r;
61 int ret=1;
62
63 i = BN_new();
64 j = BN_new();
65 k = BN_new();
66 l = BN_new();
67 m = BN_new();
68 ctx = BN_CTX_new();
69 if (i == NULL || j == NULL || k == NULL || l == NULL ||
70 m == NULL || ctx == NULL)
71 {
72 ret = -1;
73 RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);
74 goto err;
75 }
76
77 /* p prime? */
78 r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);
79 if (r != 1)
80 {
81 ret = r;
82 if (r != 0)
83 goto err;
84 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);
85 }
86
87 /* q prime? */
88 r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);
89 if (r != 1)
90 {
91 ret = r;
92 if (r != 0)
93 goto err;
94 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);
95 }
96
97 /* n = p*q? */
98 r = BN_mul(i, key->p, key->q, ctx);
99 if (!r) { ret = -1; goto err; }
100
101 if (BN_cmp(i, key->n) != 0)
102 {
103 ret = 0;
104 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);
105 }
106
107 /* d*e = 1 mod lcm(p-1,q-1)? */
108
109 r = BN_sub(i, key->p, BN_value_one());
110 if (!r) { ret = -1; goto err; }
111 r = BN_sub(j, key->q, BN_value_one());
112 if (!r) { ret = -1; goto err; }
113
114 /* now compute k = lcm(i,j) */
115 r = BN_mul(l, i, j, ctx);
116 if (!r) { ret = -1; goto err; }
117 r = BN_gcd(m, i, j, ctx);
118 if (!r) { ret = -1; goto err; }
119 r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */
120 if (!r) { ret = -1; goto err; }
121
122 r = BN_mod_mul(i, key->d, key->e, k, ctx);
123 if (!r) { ret = -1; goto err; }
124
125 if (!BN_is_one(i))
126 {
127 ret = 0;
128 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);
129 }
130
131 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)
132 {
133 /* dmp1 = d mod (p-1)? */
134 r = BN_sub(i, key->p, BN_value_one());
135 if (!r) { ret = -1; goto err; }
136
137 r = BN_mod(j, key->d, i, ctx);
138 if (!r) { ret = -1; goto err; }
139
140 if (BN_cmp(j, key->dmp1) != 0)
141 {
142 ret = 0;
143 RSAerr(RSA_F_RSA_CHECK_KEY,
144 RSA_R_DMP1_NOT_CONGRUENT_TO_D);
145 }
146
147 /* dmq1 = d mod (q-1)? */
148 r = BN_sub(i, key->q, BN_value_one());
149 if (!r) { ret = -1; goto err; }
150
151 r = BN_mod(j, key->d, i, ctx);
152 if (!r) { ret = -1; goto err; }
153
154 if (BN_cmp(j, key->dmq1) != 0)
155 {
156 ret = 0;
157 RSAerr(RSA_F_RSA_CHECK_KEY,
158 RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
159 }
160
161 /* iqmp = q^-1 mod p? */
162 if(!BN_mod_inverse(i, key->q, key->p, ctx))
163 {
164 ret = -1;
165 goto err;
166 }
167
168 if (BN_cmp(i, key->iqmp) != 0)
169 {
170 ret = 0;
171 RSAerr(RSA_F_RSA_CHECK_KEY,
172 RSA_R_IQMP_NOT_INVERSE_OF_Q);
173 }
174 }
175
176 err:
177 if (i != NULL) BN_free(i);
178 if (j != NULL) BN_free(j);
179 if (k != NULL) BN_free(k);
180 if (l != NULL) BN_free(l);
181 if (m != NULL) BN_free(m);
182 if (ctx != NULL) BN_CTX_free(ctx);
183 return (ret);
184 }
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_null.c b/src/lib/libssl/src/crypto/rsa/rsa_null.c
new file mode 100644
index 0000000000..7b58a0eca3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_null.c
@@ -0,0 +1,149 @@
1/* rsa_null.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65/* This is a dummy RSA implementation that just returns errors when called.
66 * It is designed to allow some RSA functions to work while stopping those
67 * covered by the RSA patent. That is RSA, encryption, decryption, signing
68 * and verify is not allowed but RSA key generation, key checking and other
69 * operations (like storing RSA keys) are permitted.
70 */
71
72static int RSA_null_public_encrypt(int flen, unsigned char *from,
73 unsigned char *to, RSA *rsa,int padding);
74static int RSA_null_private_encrypt(int flen, unsigned char *from,
75 unsigned char *to, RSA *rsa,int padding);
76static int RSA_null_public_decrypt(int flen, unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static int RSA_null_private_decrypt(int flen, unsigned char *from,
79 unsigned char *to, RSA *rsa,int padding);
80#if 0 /* not currently used */
81static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
82#endif
83static int RSA_null_init(RSA *rsa);
84static int RSA_null_finish(RSA *rsa);
85static RSA_METHOD rsa_null_meth={
86 "Null RSA",
87 RSA_null_public_encrypt,
88 RSA_null_public_decrypt,
89 RSA_null_private_encrypt,
90 RSA_null_private_decrypt,
91 NULL, NULL,
92 RSA_null_init,
93 RSA_null_finish,
94 0,
95 NULL,
96 };
97
98RSA_METHOD *RSA_null_method(void)
99 {
100 return(&rsa_null_meth);
101 }
102
103static int RSA_null_public_encrypt(int flen, unsigned char *from,
104 unsigned char *to, RSA *rsa, int padding)
105 {
106 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
107 return -1;
108 }
109
110static int RSA_null_private_encrypt(int flen, unsigned char *from,
111 unsigned char *to, RSA *rsa, int padding)
112 {
113 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
114 return -1;
115 }
116
117static int RSA_null_private_decrypt(int flen, unsigned char *from,
118 unsigned char *to, RSA *rsa, int padding)
119 {
120 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
121 return -1;
122 }
123
124static int RSA_null_public_decrypt(int flen, unsigned char *from,
125 unsigned char *to, RSA *rsa, int padding)
126 {
127 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
128 return -1;
129 }
130
131#if 0 /* not currently used */
132static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
133 {
134 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
135 return -1;
136 }
137#endif
138
139static int RSA_null_init(RSA *rsa)
140 {
141 return(1);
142 }
143
144static int RSA_null_finish(RSA *rsa)
145 {
146 return(1);
147 }
148
149
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_oaep.c b/src/lib/libssl/src/crypto/rsa/rsa_oaep.c
new file mode 100644
index 0000000000..843c40c864
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_oaep.c
@@ -0,0 +1,162 @@
1/* crypto/rsa/rsa_oaep.c */
2/* Written by Ulf Moeller. This software is distributed on an "AS IS"
3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */
4
5/* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */
6
7#if !defined(NO_SHA) && !defined(NO_SHA1)
8#include <stdio.h>
9#include "cryptlib.h"
10#include <openssl/bn.h>
11#include <openssl/rsa.h>
12#include <openssl/sha.h>
13#include <openssl/rand.h>
14
15int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen);
16
17int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
18 unsigned char *from, int flen, unsigned char *param, int plen)
19 {
20 int i, emlen = tlen - 1;
21 unsigned char *db, *seed;
22 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
23
24 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)
25 {
26 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,
27 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
28 return (0);
29 }
30
31 if (emlen < 2 * SHA_DIGEST_LENGTH + 1)
32 {
33 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);
34 return (0);
35 }
36
37 dbmask = Malloc(emlen - SHA_DIGEST_LENGTH);
38 if (dbmask == NULL)
39 {
40 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
41 return (0);
42 }
43
44 to[0] = 0;
45 seed = to + 1;
46 db = to + SHA_DIGEST_LENGTH + 1;
47
48 SHA1(param, plen, db);
49 memset(db + SHA_DIGEST_LENGTH, 0,
50 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
51 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
52 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
53 RAND_bytes(seed, SHA_DIGEST_LENGTH);
54#ifdef PKCS_TESTVECT
55 memcpy(seed,
56 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
57 20);
58#endif
59
60 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
61 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
62 db[i] ^= dbmask[i];
63
64 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
65 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
66 seed[i] ^= seedmask[i];
67
68 Free(dbmask);
69 return (1);
70 }
71
72int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
73 unsigned char *from, int flen, int num, unsigned char *param,
74 int plen)
75 {
76 int i, dblen, mlen = -1;
77 unsigned char *maskeddb;
78 int lzero;
79 unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
80
81 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
82 {
83 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
84 return (-1);
85 }
86
87 dblen = num - SHA_DIGEST_LENGTH;
88 db = Malloc(dblen);
89 if (db == NULL)
90 {
91 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
92 return (-1);
93 }
94
95 lzero = num - flen;
96 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
97
98 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
99 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
100 seed[i] ^= from[i - lzero];
101
102 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
103 for (i = 0; i < dblen; i++)
104 db[i] ^= maskeddb[i];
105
106 SHA1(param, plen, phash);
107
108 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0)
109 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
110 else
111 {
112 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
113 if (db[i] != 0x00)
114 break;
115 if (db[i] != 0x01 || i++ >= dblen)
116 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,
117 RSA_R_OAEP_DECODING_ERROR);
118 else
119 {
120 mlen = dblen - i;
121 if (tlen < mlen)
122 {
123 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
124 mlen = -1;
125 }
126 else
127 memcpy(to, db + i, mlen);
128 }
129 }
130 Free(db);
131 return (mlen);
132 }
133
134int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen)
135 {
136 long i, outlen = 0;
137 unsigned char cnt[4];
138 SHA_CTX c;
139 unsigned char md[SHA_DIGEST_LENGTH];
140
141 for (i = 0; outlen < len; i++)
142 {
143 cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255,
144 cnt[2] = (i >> 8) & 255, cnt[3] = i & 255;
145 SHA1_Init(&c);
146 SHA1_Update(&c, seed, seedlen);
147 SHA1_Update(&c, cnt, 4);
148 if (outlen + SHA_DIGEST_LENGTH <= len)
149 {
150 SHA1_Final(mask + outlen, &c);
151 outlen += SHA_DIGEST_LENGTH;
152 }
153 else
154 {
155 SHA1_Final(md, &c);
156 memcpy(mask + outlen, md, len - outlen);
157 outlen = len;
158 }
159 }
160 return (0);
161 }
162#endif
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_test.c b/src/lib/libssl/src/crypto/rsa/rsa_test.c
new file mode 100644
index 0000000000..e5ae0c1f69
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_test.c
@@ -0,0 +1,314 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "openssl/e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#include <openssl/rand.h>
11#ifdef NO_RSA
12int main(int argc, char *argv[])
13{
14 printf("No RSA support\n");
15 return(0);
16}
17#else
18#include <openssl/rsa.h>
19
20#define SetKey \
21 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
22 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
23 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
24 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
25 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
26 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
27 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
28 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
29 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
30 return (sizeof(ctext_ex) - 1);
31
32static int key1(RSA *key, unsigned char *c)
33 {
34 static unsigned char n[] =
35"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
36"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
37"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
38"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
39"\xF5";
40
41 static unsigned char e[] = "\x11";
42
43 static unsigned char d[] =
44"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
45"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
46"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
47"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
48
49 static unsigned char p[] =
50"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
51"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
52"\x0D";
53
54 static unsigned char q[] =
55"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
56"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
57"\x89";
58
59 static unsigned char dmp1[] =
60"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
61"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
62
63 static unsigned char dmq1[] =
64"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
65"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
66"\x51";
67
68 static unsigned char iqmp[] =
69"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
70"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
71
72 static unsigned char ctext_ex[] =
73"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
74"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
75"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
76"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
77
78 SetKey;
79 }
80
81static int key2(RSA *key, unsigned char *c)
82 {
83 static unsigned char n[] =
84"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
85"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
86"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
87"\x34\x77\xCF";
88
89 static unsigned char e[] = "\x3";
90
91 static unsigned char d[] =
92"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
93"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
94"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
95"\xE5\xEB";
96
97 static unsigned char p[] =
98"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
99"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
100
101 static unsigned char q[] =
102"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
103"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
104
105 static unsigned char dmp1[] =
106"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
107"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
108
109 static unsigned char dmq1[] =
110"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
111"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
112
113 static unsigned char iqmp[] =
114"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
115"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
116
117 static unsigned char ctext_ex[] =
118"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
119"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
120"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
121"\x62\x51";
122
123 SetKey;
124 }
125
126static int key3(RSA *key, unsigned char *c)
127 {
128 static unsigned char n[] =
129"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
130"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
131"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
132"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
133"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
134"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
135"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
136"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
137"\xCB";
138
139 static unsigned char e[] = "\x11";
140
141 static unsigned char d[] =
142"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
143"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
144"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
145"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
146"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
147"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
148"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
149"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
150"\xC1";
151
152 static unsigned char p[] =
153"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
154"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
155"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
156"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
157"\x99";
158
159 static unsigned char q[] =
160"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
161"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
162"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
163"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
164"\x03";
165
166 static unsigned char dmp1[] =
167"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
168"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
169"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
170"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
171
172 static unsigned char dmq1[] =
173"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
174"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
175"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
176"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
177
178 static unsigned char iqmp[] =
179"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
180"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
181"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
182"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
183"\xF7";
184
185 static unsigned char ctext_ex[] =
186"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
187"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
188"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
189"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
190"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
191"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
192"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
193"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
194
195 SetKey;
196 }
197
198static int pad_unknown(void)
199{
200 unsigned long l;
201 while ((l = ERR_get_error()) != 0)
202 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
203 return(1);
204 return(0);
205}
206
207static const char rnd_seed[] = "string to make the random number generator think it has entropy";
208
209int main(int argc, char *argv[])
210 {
211 int err=0;
212 int v;
213 RSA *key;
214 unsigned char ptext[256];
215 unsigned char ctext[256];
216 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
217 unsigned char ctext_ex[256];
218 int plen;
219 int clen = 0;
220 int num;
221
222 RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
223
224 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
225
226 plen = sizeof(ptext_ex) - 1;
227
228 for (v = 0; v < 3; v++)
229 {
230 key = RSA_new();
231 switch (v) {
232 case 0:
233 clen = key1(key, ctext_ex);
234 break;
235 case 1:
236 clen = key2(key, ctext_ex);
237 break;
238 case 2:
239 clen = key3(key, ctext_ex);
240 break;
241 }
242
243 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
244 RSA_PKCS1_PADDING);
245 if (num != clen)
246 {
247 printf("PKCS#1 v1.5 encryption failed!\n");
248 err=1;
249 goto oaep;
250 }
251
252 num = RSA_private_decrypt(num, ctext, ptext, key,
253 RSA_PKCS1_PADDING);
254 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
255 {
256 printf("PKCS#1 v1.5 decryption failed!\n");
257 err=1;
258 }
259 else
260 printf("PKCS #1 v1.5 encryption/decryption ok\n");
261
262 oaep:
263 ERR_clear_error();
264 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
265 RSA_PKCS1_OAEP_PADDING);
266 if (num == -1 && pad_unknown())
267 {
268 printf("No OAEP support\n");
269 goto next;
270 }
271 if (num != clen)
272 {
273 printf("OAEP encryption failed!\n");
274 err=1;
275 goto next;
276 }
277
278 num = RSA_private_decrypt(num, ctext, ptext, key,
279 RSA_PKCS1_OAEP_PADDING);
280 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
281 {
282 printf("OAEP decryption (encrypted data) failed!\n");
283 err=1;
284 }
285 else if (memcmp(ctext, ctext_ex, num) == 0)
286 {
287 printf("OAEP test vector %d passed!\n", v);
288 goto next;
289 }
290
291 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
292 Try decrypting ctext_ex */
293
294 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
295 RSA_PKCS1_OAEP_PADDING);
296
297 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
298 {
299 printf("OAEP decryption (test vector data) failed!\n");
300 err=1;
301 }
302 else
303 printf("OAEP encryption/decryption ok\n");
304 next:
305 RSA_free(key);
306 }
307
308 ERR_remove_state(0);
309
310 CRYPTO_mem_leaks_fp(stdout);
311
312 return err;
313 }
314#endif
diff --git a/src/lib/libssl/src/crypto/stack/safestack.h b/src/lib/libssl/src/crypto/stack/safestack.h
new file mode 100644
index 0000000000..38934981e3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/stack/safestack.h
@@ -0,0 +1,129 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SAFESTACK_H
56#define HEADER_SAFESTACK_H
57
58#include <openssl/stack.h>
59
60#define STACK_OF(type) STACK_##type
61
62#define DECLARE_STACK_OF(type) \
63typedef struct stack_st_##type \
64 { \
65 STACK stack; \
66 } STACK_OF(type); \
67STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \
68STACK_OF(type) *sk_##type##_new_null(void); \
69void sk_##type##_free(STACK_OF(type) *sk); \
70int sk_##type##_num(const STACK_OF(type) *sk); \
71type *sk_##type##_value(const STACK_OF(type) *sk,int n); \
72type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \
73void sk_##type##_zero(STACK_OF(type) *sk); \
74int sk_##type##_push(STACK_OF(type) *sk,type *v); \
75int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \
76int sk_##type##_find(STACK_OF(type) *sk,type *v); \
77type *sk_##type##_delete(STACK_OF(type) *sk,int n); \
78void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
79int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \
80int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
81 int (*cmp)(type **,type **)))(type **,type **); \
82STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \
83void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \
84type *sk_##type##_shift(STACK_OF(type) *sk); \
85type *sk_##type##_pop(STACK_OF(type) *sk); \
86void sk_##type##_sort(STACK_OF(type) *sk);
87
88#define IMPLEMENT_STACK_OF(type) \
89STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \
90 { return (STACK_OF(type) *)sk_new(cmp); } \
91STACK_OF(type) *sk_##type##_new_null() \
92 { return (STACK_OF(type) *)sk_new_null(); } \
93void sk_##type##_free(STACK_OF(type) *sk) \
94 { sk_free((STACK *)sk); } \
95int sk_##type##_num(const STACK_OF(type) *sk) \
96 { return M_sk_num((const STACK *)sk); } \
97type *sk_##type##_value(const STACK_OF(type) *sk,int n) \
98 { return (type *)sk_value((STACK *)sk,n); } \
99type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \
100 { return (type *)(sk_set((STACK *)sk,n,(char *)v)); } \
101void sk_##type##_zero(STACK_OF(type) *sk) \
102 { sk_zero((STACK *)sk); } \
103int sk_##type##_push(STACK_OF(type) *sk,type *v) \
104 { return sk_push((STACK *)sk,(char *)v); } \
105int sk_##type##_unshift(STACK_OF(type) *sk,type *v) \
106 { return sk_unshift((STACK *)sk,(char *)v); } \
107int sk_##type##_find(STACK_OF(type) *sk,type *v) \
108 { return sk_find((STACK *)sk,(char *)v); } \
109type *sk_##type##_delete(STACK_OF(type) *sk,int n) \
110 { return (type *)sk_delete((STACK *)sk,n); } \
111void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
112 { sk_delete_ptr((STACK *)sk,(char *)v); } \
113int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \
114 { return sk_insert((STACK *)sk,(char *)v,n); } \
115int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
116 int (*cmp)(type **,type **)))(type **,type **) \
117 { return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,cmp); } \
118STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \
119 { return (STACK_OF(type) *)sk_dup((STACK *)sk); } \
120void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \
121 { sk_pop_free((STACK *)sk,func); } \
122type *sk_##type##_shift(STACK_OF(type) *sk) \
123 { return (type *)sk_shift((STACK *)sk); } \
124type *sk_##type##_pop(STACK_OF(type) *sk) \
125 { return (type *)sk_pop((STACK *)sk); } \
126void sk_##type##_sort(STACK_OF(type) *sk) \
127 { sk_sort((STACK *)sk); }
128
129#endif /* ndef HEADER_SAFESTACK_H */
diff --git a/src/lib/libssl/src/crypto/symhacks.h b/src/lib/libssl/src/crypto/symhacks.h
new file mode 100644
index 0000000000..358ad355bb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/symhacks.h
@@ -0,0 +1,154 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SYMHACKS_H
56#define HEADER_SYMHACKS_H
57
58/* Hacks to solve the problem with linkers incapable of handling very long
59 symbol names. In the case of VMS, the limit is 31 characters on VMS for
60 VAX. */
61#ifdef VMS
62
63/* Hack a long name in crypto/asn1/a_mbstr.c */
64#undef ASN1_STRING_set_default_mask_asc
65#define ASN1_STRING_set_default_mask_asc ASN1_STRING_set_def_mask_asc
66
67#if 0 /* No longer needed, since safestack macro magic does the job */
68/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */
69#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO
70#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF
71#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO
72#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF
73#endif
74
75#if 0 /* No longer needed, since safestack macro magic does the job */
76/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */
77#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO
78#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECINF
79#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO
80#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECINF
81#endif
82
83#if 0 /* No longer needed, since safestack macro magic does the job */
84/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */
85#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION
86#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION i2d_ASN1_SET_OF_ACC_DESC
87#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION
88#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION d2i_ASN1_SET_OF_ACC_DESC
89#endif
90
91/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */
92#undef PEM_read_NETSCAPE_CERT_SEQUENCE
93#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQ
94#undef PEM_write_NETSCAPE_CERT_SEQUENCE
95#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQ
96#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE
97#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQ
98#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE
99#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQ
100#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE
101#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQ
102
103/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */
104#undef PEM_read_PKCS8_PRIV_KEY_INFO
105#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO
106#undef PEM_write_PKCS8_PRIV_KEY_INFO
107#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO
108#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO
109#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO
110#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO
111#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO
112#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO
113#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_wrt_cb_bio_P8_PRIV_KEY_INFO
114
115/* Hack other PEM names */
116#undef PEM_write_bio_PKCS8PrivateKey_nid
117#define PEM_write_bio_PKCS8PrivateKey_nid PEM_write_bio_PKCS8PrivKey_nid
118
119/* Hack some long X509 names */
120#undef X509_REVOKED_get_ext_by_critical
121#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
122
123/* Hack some long CRYPTO names */
124#define CRYPTO_set_dynlock_destroy_callback CRYPTO_set_dynlock_destroy_cb
125#define CRYPTO_set_dynlock_create_callback CRYPTO_set_dynlock_create_cb
126#define CRYPTO_set_dynlock_lock_callback CRYPTO_set_dynlock_lock_cb
127#define CRYPTO_get_dynlock_lock_callback CRYPTO_get_dynlock_lock_cb
128#define CRYPTO_get_dynlock_destroy_callback CRYPTO_get_dynlock_destroy_cb
129#define CRYPTO_get_dynlock_create_callback CRYPTO_get_dynlock_create_cb
130
131/* Hack some long SSL names */
132#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
133#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_d_X509_STORE_CTX_idx
134#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_subjs_to_stk
135#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_subjs_to_stk
136#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
137#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
138#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
139
140/* Hack some long ENGINE names */
141#define ENGINE_get_default_BN_mod_exp_crt ENGINE_get_def_BN_mod_exp_crt
142#define ENGINE_set_default_BN_mod_exp_crt ENGINE_set_def_BN_mod_exp_crt
143
144#endif /* defined VMS */
145
146
147/* Case insensiteve linking causes problems.... */
148#if defined(WIN16) || defined(VMS)
149#undef ERR_load_CRYPTO_strings
150#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
151#endif
152
153
154#endif /* ! defined HEADER_VMS_IDHACKS_H */
diff --git a/src/lib/libssl/src/crypto/threads/README b/src/lib/libssl/src/crypto/threads/README
new file mode 100644
index 0000000000..df6b26e146
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/README
@@ -0,0 +1,14 @@
1Mutithreading testing area.
2
3Since this stuff is very very platorm specific, this is not part of the
4normal build. Have a read of doc/threads.doc.
5
6mttest will do some testing and will currently build under Windows NT/95,
7Solaris and Linux. The IRIX stuff is not finished.
8
9I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1)
10and things seem to work ok.
11
12The Linux pthreads package can be retrieved from
13http://www.mit.edu:8001/people/proven/pthreads.html
14
diff --git a/src/lib/libssl/src/crypto/threads/profile.sh b/src/lib/libssl/src/crypto/threads/profile.sh
new file mode 100644
index 0000000000..6e3e342fc0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/profile.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libssl/src/crypto/threads/ptest.bat b/src/lib/libssl/src/crypto/threads/ptest.bat
new file mode 100644
index 0000000000..4071b5ffea
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/ptest.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3purify cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssl32.lib ..\..\out\crypt32.lib
4
diff --git a/src/lib/libssl/src/crypto/threads/pthread.sh b/src/lib/libssl/src/crypto/threads/pthread.sh
new file mode 100644
index 0000000000..f1c49821d2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/pthread.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2#
3# build using pthreads
4#
5# http://www.mit.edu:8001/people/proven/pthreads.html
6#
7/bin/rm -f mttest
8pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto
9
diff --git a/src/lib/libssl/src/crypto/threads/pthread2.sh b/src/lib/libssl/src/crypto/threads/pthread2.sh
new file mode 100644
index 0000000000..41264c6a50
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/pthread2.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2#
3# build using pthreads where it's already built into the system
4#
5/bin/rm -f mttest
6gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
7
diff --git a/src/lib/libssl/src/crypto/threads/pthreads-vms.com b/src/lib/libssl/src/crypto/threads/pthreads-vms.com
new file mode 100644
index 0000000000..63f5b8cc2e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/pthreads-vms.com
@@ -0,0 +1,9 @@
1$! To compile mttest on VMS.
2$!
3$! WARNING: only tested with DEC C so far.
4$
5$ arch := vax
6$ if f$getsyi("CPU") .ge. 128 then arch := axp
7$ define/user openssl [--.include.openssl]
8$ cc/def=PTHREADS mttest.c
9$ link mttest,[--.'arch'.exe.ssl]libssl/lib,[--.'arch'.exe.crypto]libcrypto/lib
diff --git a/src/lib/libssl/src/crypto/threads/purify.sh b/src/lib/libssl/src/crypto/threads/purify.sh
new file mode 100644
index 0000000000..6d44fe26b7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/purify.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libssl/src/crypto/threads/solaris.sh b/src/lib/libssl/src/crypto/threads/solaris.sh
new file mode 100644
index 0000000000..bc93094a27
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/solaris.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libssl/src/crypto/threads/win32.bat b/src/lib/libssl/src/crypto/threads/win32.bat
new file mode 100644
index 0000000000..ee6da80a07
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/win32.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssleay32.lib ..\..\out\libeay32.lib
4
diff --git a/src/lib/libssl/src/crypto/tmdiff.h b/src/lib/libssl/src/crypto/tmdiff.h
new file mode 100644
index 0000000000..41a8a1e0e0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/tmdiff.h
@@ -0,0 +1,81 @@
1/* crypto/tmdiff.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Header for dynamic hash table routines
60 * Author - Eric Young
61 */
62
63#ifndef HEADER_TMDIFF_H
64#define HEADER_TMDIFF_H
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70char *ms_time_new(void );
71void ms_time_free(char *a);
72void ms_time_get(char *a);
73double ms_time_diff(char *start,char *end);
74int ms_time_cmp(char *ap,char *bp);
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif
81
diff --git a/src/lib/libssl/src/crypto/ui/ui.h b/src/lib/libssl/src/crypto/ui/ui.h
new file mode 100644
index 0000000000..735a2d988e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui.h
@@ -0,0 +1,387 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_H
60#define HEADER_UI_H
61
62#include <openssl/crypto.h>
63#include <openssl/safestack.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The UI type is a holder for a specific user interface session. It can
70 contain an illimited number of informational or error strings as well
71 as things to prompt for, both passwords (noecho mode) and others (echo
72 mode), and verification of the same. All of these are called strings,
73 and are further described below. */
74typedef struct ui_st UI;
75
76/* All instances of UI have a reference to a method structure, which is a
77 ordered vector of functions that implement the lower level things to do.
78 There is an instruction on the implementation further down, in the section
79 for method implementors. */
80typedef struct ui_method_st UI_METHOD;
81
82
83/* All the following functions return -1 or NULL on error and in some cases
84 (UI_process()) -2 if interrupted or in some other way cancelled.
85 When everything is fine, they return 0, a positive value or a non-NULL
86 pointer, all depending on their purpose. */
87
88/* Creators and destructor. */
89UI *UI_new(void);
90UI *UI_new_method(const UI_METHOD *method);
91void UI_free(UI *ui);
92
93/* The following functions are used to add strings to be printed and prompt
94 strings to prompt for data. The names are UI_{add,dup}_<function>_string
95 and UI_{add,dup}_input_boolean.
96
97 UI_{add,dup}_<function>_string have the following meanings:
98 add add a text or prompt string. The pointers given to these
99 functions are used verbatim, no copying is done.
100 dup make a copy of the text or prompt string, then add the copy
101 to the collection of strings in the user interface.
102 <function>
103 The function is a name for the functionality that the given
104 string shall be used for. It can be one of:
105 input use the string as data prompt.
106 verify use the string as verification prompt. This
107 is used to verify a previous input.
108 info use the string for informational output.
109 error use the string for error output.
110 Honestly, there's currently no difference between info and error for the
111 moment.
112
113 UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
114 and are typically used when one wants to prompt for a yes/no response.
115
116
117 All of the functions in this group take a UI and a prompt string.
118 The string input and verify addition functions also take a flag argument,
119 a buffer for the result to end up with, a minimum input size and a maximum
120 input size (the result buffer MUST be large enough to be able to contain
121 the maximum number of characters). Additionally, the verify addition
122 functions takes another buffer to compare the result against.
123 The boolean input functions take an action description string (which should
124 be safe to ignore if the expected user action is obvious, for example with
125 a dialog box with an OK button and a Cancel button), a string of acceptable
126 characters to mean OK and to mean Cancel. The two last strings are checked
127 to make sure they don't have common characters. Additionally, the same
128 flag argument as for the string input is taken, as well as a result buffer.
129 The result buffer is required to be at least one byte long. Depending on
130 the answer, the first character from the OK or the Cancel character strings
131 will be stored in the first byte of the result buffer. No NUL will be
132 added, so the result is *not* a string.
133
134 On success, the all return an index of the added information. That index
135 is usefull when retrieving results with UI_get0_result(). */
136int UI_add_input_string(UI *ui, const char *prompt, int flags,
137 char *result_buf, int minsize, int maxsize);
138int UI_dup_input_string(UI *ui, const char *prompt, int flags,
139 char *result_buf, int minsize, int maxsize);
140int UI_add_verify_string(UI *ui, const char *prompt, int flags,
141 char *result_buf, int minsize, int maxsize, const char *test_buf);
142int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
143 char *result_buf, int minsize, int maxsize, const char *test_buf);
144int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
145 const char *ok_chars, const char *cancel_chars,
146 int flags, char *result_buf);
147int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
148 const char *ok_chars, const char *cancel_chars,
149 int flags, char *result_buf);
150int UI_add_info_string(UI *ui, const char *text);
151int UI_dup_info_string(UI *ui, const char *text);
152int UI_add_error_string(UI *ui, const char *text);
153int UI_dup_error_string(UI *ui, const char *text);
154
155/* These are the possible flags. They can be or'ed together. */
156/* Use to have echoing of input */
157#define UI_INPUT_FLAG_ECHO 0x01
158/* Use a default password. Where that password is found is completely
159 up to the application, it might for example be in the user data set
160 with UI_add_user_data(). It is not recommended to have more than
161 one input in each UI being marked with this flag, or the application
162 might get confused. */
163#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
164
165/* The user of these routines may want to define flags of their own. The core
166 UI won't look at those, but will pass them on to the method routines. They
167 must use higher bits so they don't get confused with the UI bits above.
168 UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good
169 example of use is this:
170
171 #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE)
172
173*/
174#define UI_INPUT_FLAG_USER_BASE 16
175
176
177/* The following function helps construct a prompt. object_desc is a
178 textual short description of the object, for example "pass phrase",
179 and object_name is the name of the object (might be a card name or
180 a file name.
181 The returned string shall always be allocated on the heap with
182 OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
183
184 If the ui_method doesn't contain a pointer to a user-defined prompt
185 constructor, a default string is built, looking like this:
186
187 "Enter {object_desc} for {object_name}:"
188
189 So, if object_desc has the value "pass phrase" and object_name has
190 the value "foo.key", the resulting string is:
191
192 "Enter pass phrase for foo.key:"
193*/
194char *UI_construct_prompt(UI *ui_method,
195 const char *object_desc, const char *object_name);
196
197
198/* The following function is used to store a pointer to user-specific data.
199 Any previous such pointer will be returned and replaced.
200
201 For callback purposes, this function makes a lot more sense than using
202 ex_data, since the latter requires that different parts of OpenSSL or
203 applications share the same ex_data index.
204
205 Note that the UI_OpenSSL() method completely ignores the user data.
206 Other methods may not, however. */
207void *UI_add_user_data(UI *ui, void *user_data);
208/* We need a user data retrieving function as well. */
209void *UI_get0_user_data(UI *ui);
210
211/* Return the result associated with a prompt given with the index i. */
212const char *UI_get0_result(UI *ui, int i);
213
214/* When all strings have been added, process the whole thing. */
215int UI_process(UI *ui);
216
217/* Give a user interface parametrised control commands. This can be used to
218 send down an integer, a data pointer or a function pointer, as well as
219 be used to get information from a UI. */
220int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
221
222/* The commands */
223/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
224 OpenSSL error stack before printing any info or added error messages and
225 before any prompting. */
226#define UI_CTRL_PRINT_ERRORS 1
227/* Check if a UI_process() is possible to do again with the same instance of
228 a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0
229 if not. */
230#define UI_CTRL_IS_REDOABLE 2
231
232
233/* Some methods may use extra data */
234#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
235#define UI_get_app_data(s) UI_get_ex_data(s,0)
236int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
237 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
238int UI_set_ex_data(UI *r,int idx,void *arg);
239void *UI_get_ex_data(UI *r, int idx);
240
241/* Use specific methods instead of the built-in one */
242void UI_set_default_method(const UI_METHOD *meth);
243const UI_METHOD *UI_get_default_method(void);
244const UI_METHOD *UI_get_method(UI *ui);
245const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
246
247/* The method with all the built-in thingies */
248UI_METHOD *UI_OpenSSL(void);
249
250
251/* ---------- For method writers ---------- */
252/* A method contains a number of functions that implement the low level
253 of the User Interface. The functions are:
254
255 an opener This function starts a session, maybe by opening
256 a channel to a tty, or by opening a window.
257 a writer This function is called to write a given string,
258 maybe to the tty, maybe as a field label in a
259 window.
260 a flusher This function is called to flush everything that
261 has been output so far. It can be used to actually
262 display a dialog box after it has been built.
263 a reader This function is called to read a given prompt,
264 maybe from the tty, maybe from a field in a
265 window. Note that it's called wth all string
266 structures, not only the prompt ones, so it must
267 check such things itself.
268 a closer This function closes the session, maybe by closing
269 the channel to the tty, or closing the window.
270
271 All these functions are expected to return:
272
273 0 on error.
274 1 on success.
275 -1 on out-of-band events, for example if some prompting has
276 been canceled (by pressing Ctrl-C, for example). This is
277 only checked when returned by the flusher or the reader.
278
279 The way this is used, the opener is first called, then the writer for all
280 strings, then the flusher, then the reader for all strings and finally the
281 closer. Note that if you want to prompt from a terminal or other command
282 line interface, the best is to have the reader also write the prompts
283 instead of having the writer do it. If you want to prompt from a dialog
284 box, the writer can be used to build up the contents of the box, and the
285 flusher to actually display the box and run the event loop until all data
286 has been given, after which the reader only grabs the given data and puts
287 them back into the UI strings.
288
289 All method functions take a UI as argument. Additionally, the writer and
290 the reader take a UI_STRING.
291*/
292
293/* The UI_STRING type is the data structure that contains all the needed info
294 about a string or a prompt, including test data for a verification prompt.
295*/
296DECLARE_STACK_OF(UI_STRING)
297typedef struct ui_string_st UI_STRING;
298
299/* The different types of strings that are currently supported.
300 This is only needed by method authors. */
301enum UI_string_types
302 {
303 UIT_NONE=0,
304 UIT_PROMPT, /* Prompt for a string */
305 UIT_VERIFY, /* Prompt for a string and verify */
306 UIT_BOOLEAN, /* Prompt for a yes/no response */
307 UIT_INFO, /* Send info to the user */
308 UIT_ERROR /* Send an error message to the user */
309 };
310
311/* Create and manipulate methods */
312UI_METHOD *UI_create_method(char *name);
313void UI_destroy_method(UI_METHOD *ui_method);
314int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
315int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));
316int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
317int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
318int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
319int (*UI_method_get_opener(UI_METHOD *method))(UI*);
320int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
321int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
322int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
323int (*UI_method_get_closer(UI_METHOD *method))(UI*);
324
325/* The following functions are helpers for method writers to access relevant
326 data from a UI_STRING. */
327
328/* Return type of the UI_STRING */
329enum UI_string_types UI_get_string_type(UI_STRING *uis);
330/* Return input flags of the UI_STRING */
331int UI_get_input_flags(UI_STRING *uis);
332/* Return the actual string to output (the prompt, info or error) */
333const char *UI_get0_output_string(UI_STRING *uis);
334/* Return the optional action string to output (the boolean promtp instruction) */
335const char *UI_get0_action_string(UI_STRING *uis);
336/* Return the result of a prompt */
337const char *UI_get0_result_string(UI_STRING *uis);
338/* Return the string to test the result against. Only useful with verifies. */
339const char *UI_get0_test_string(UI_STRING *uis);
340/* Return the required minimum size of the result */
341int UI_get_result_minsize(UI_STRING *uis);
342/* Return the required maximum size of the result */
343int UI_get_result_maxsize(UI_STRING *uis);
344/* Set the result of a UI_STRING. */
345int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
346
347
348/* A couple of popular utility functions */
349int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
350int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
351
352
353/* BEGIN ERROR CODES */
354/* The following lines are auto generated by the script mkerr.pl. Any changes
355 * made after this point may be overwritten when the script is next run.
356 */
357void ERR_load_UI_strings(void);
358
359/* Error codes for the UI functions. */
360
361/* Function codes. */
362#define UI_F_GENERAL_ALLOCATE_BOOLEAN 108
363#define UI_F_GENERAL_ALLOCATE_PROMPT 109
364#define UI_F_GENERAL_ALLOCATE_STRING 100
365#define UI_F_UI_CTRL 111
366#define UI_F_UI_DUP_ERROR_STRING 101
367#define UI_F_UI_DUP_INFO_STRING 102
368#define UI_F_UI_DUP_INPUT_BOOLEAN 110
369#define UI_F_UI_DUP_INPUT_STRING 103
370#define UI_F_UI_DUP_VERIFY_STRING 106
371#define UI_F_UI_GET0_RESULT 107
372#define UI_F_UI_NEW_METHOD 104
373#define UI_F_UI_SET_RESULT 105
374
375/* Reason codes. */
376#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104
377#define UI_R_INDEX_TOO_LARGE 102
378#define UI_R_INDEX_TOO_SMALL 103
379#define UI_R_NO_RESULT_BUFFER 105
380#define UI_R_RESULT_TOO_LARGE 100
381#define UI_R_RESULT_TOO_SMALL 101
382#define UI_R_UNKNOWN_CONTROL_COMMAND 106
383
384#ifdef __cplusplus
385}
386#endif
387#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_compat.c b/src/lib/libssl/src/crypto/ui/ui_compat.c
new file mode 100644
index 0000000000..13e0f70d90
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_compat.c
@@ -0,0 +1,67 @@
1/* crypto/ui/ui_compat.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui_compat.h>
58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 }
63
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
65 {
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 }
diff --git a/src/lib/libssl/src/crypto/ui/ui_compat.h b/src/lib/libssl/src/crypto/ui/ui_compat.h
new file mode 100644
index 0000000000..b35c9bb7fd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_compat.h
@@ -0,0 +1,83 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_COMPAT_H
60#define HEADER_UI_COMPAT_H
61
62#include <openssl/opensslconf.h>
63#include <openssl/ui.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The following functions were previously part of the DES section,
70 and are provided here for backward compatibility reasons. */
71
72#define des_read_pw_string(b,l,p,v) \
73 _ossl_old_des_read_pw_string((b),(l),(p),(v))
74#define des_read_pw(b,bf,s,p,v) \
75 _ossl_old_des_read_pw((b),(bf),(s),(p),(v))
76
77int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
78int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
79
80#ifdef __cplusplus
81}
82#endif
83#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_err.c b/src/lib/libssl/src/crypto/ui/ui_err.c
new file mode 100644
index 0000000000..39a62ae737
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_err.c
@@ -0,0 +1,111 @@
1/* crypto/ui/ui_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ui.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UI_str_functs[]=
68 {
69{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_BOOLEAN,0), "GENERAL_ALLOCATE_BOOLEAN"},
70{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_PROMPT,0), "GENERAL_ALLOCATE_PROMPT"},
71{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_STRING,0), "GENERAL_ALLOCATE_STRING"},
72{ERR_PACK(0,UI_F_UI_CTRL,0), "UI_ctrl"},
73{ERR_PACK(0,UI_F_UI_DUP_ERROR_STRING,0), "UI_dup_error_string"},
74{ERR_PACK(0,UI_F_UI_DUP_INFO_STRING,0), "UI_dup_info_string"},
75{ERR_PACK(0,UI_F_UI_DUP_INPUT_BOOLEAN,0), "UI_dup_input_boolean"},
76{ERR_PACK(0,UI_F_UI_DUP_INPUT_STRING,0), "UI_dup_input_string"},
77{ERR_PACK(0,UI_F_UI_DUP_VERIFY_STRING,0), "UI_dup_verify_string"},
78{ERR_PACK(0,UI_F_UI_GET0_RESULT,0), "UI_get0_result"},
79{ERR_PACK(0,UI_F_UI_NEW_METHOD,0), "UI_new_method"},
80{ERR_PACK(0,UI_F_UI_SET_RESULT,0), "UI_set_result"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA UI_str_reasons[]=
85 {
86{UI_R_COMMON_OK_AND_CANCEL_CHARACTERS ,"common ok and cancel characters"},
87{UI_R_INDEX_TOO_LARGE ,"index too large"},
88{UI_R_INDEX_TOO_SMALL ,"index too small"},
89{UI_R_NO_RESULT_BUFFER ,"no result buffer"},
90{UI_R_RESULT_TOO_LARGE ,"result too large"},
91{UI_R_RESULT_TOO_SMALL ,"result too small"},
92{UI_R_UNKNOWN_CONTROL_COMMAND ,"unknown control command"},
93{0,NULL}
94 };
95
96#endif
97
98void ERR_load_UI_strings(void)
99 {
100 static int init=1;
101
102 if (init)
103 {
104 init=0;
105#ifndef OPENSSL_NO_ERR
106 ERR_load_strings(ERR_LIB_UI,UI_str_functs);
107 ERR_load_strings(ERR_LIB_UI,UI_str_reasons);
108#endif
109
110 }
111 }
diff --git a/src/lib/libssl/src/crypto/ui/ui_lib.c b/src/lib/libssl/src/crypto/ui/ui_lib.c
new file mode 100644
index 0000000000..16946cad95
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_lib.c
@@ -0,0 +1,899 @@
1/* crypto/ui/ui_lib.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/e_os2.h>
61#include <openssl/buffer.h>
62#include <openssl/ui.h>
63#include <openssl/err.h>
64#include "ui_locl.h"
65
66IMPLEMENT_STACK_OF(UI_STRING_ST)
67
68static const UI_METHOD *default_UI_meth=NULL;
69
70UI *UI_new(void)
71 {
72 return(UI_new_method(NULL));
73 }
74
75UI *UI_new_method(const UI_METHOD *method)
76 {
77 UI *ret;
78
79 ret=(UI *)OPENSSL_malloc(sizeof(UI));
80 if (ret == NULL)
81 {
82 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
83 return NULL;
84 }
85 if (method == NULL)
86 ret->meth=UI_get_default_method();
87 else
88 ret->meth=method;
89
90 ret->strings=NULL;
91 ret->user_data=NULL;
92 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
93 return ret;
94 }
95
96static void free_string(UI_STRING *uis)
97 {
98 if (uis->flags & OUT_STRING_FREEABLE)
99 {
100 OPENSSL_free((char *)uis->out_string);
101 switch(uis->type)
102 {
103 case UIT_BOOLEAN:
104 OPENSSL_free((char *)uis->_.boolean_data.action_desc);
105 OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
106 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
107 break;
108 default:
109 break;
110 }
111 }
112 OPENSSL_free(uis);
113 }
114
115void UI_free(UI *ui)
116 {
117 if (ui == NULL)
118 return;
119 sk_UI_STRING_pop_free(ui->strings,free_string);
120 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
121 OPENSSL_free(ui);
122 }
123
124static int allocate_string_stack(UI *ui)
125 {
126 if (ui->strings == NULL)
127 {
128 ui->strings=sk_UI_STRING_new_null();
129 if (ui->strings == NULL)
130 {
131 return -1;
132 }
133 }
134 return 0;
135 }
136
137static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
138 int prompt_freeable, enum UI_string_types type, int input_flags,
139 char *result_buf)
140 {
141 UI_STRING *ret = NULL;
142
143 if (prompt == NULL)
144 {
145 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER);
146 }
147 else if (result_buf == NULL)
148 {
149 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
150 }
151 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING))))
152 {
153 ret->out_string=prompt;
154 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
155 ret->input_flags=input_flags;
156 ret->type=type;
157 ret->result_buf=result_buf;
158 }
159 return ret;
160 }
161
162static int general_allocate_string(UI *ui, const char *prompt,
163 int prompt_freeable, enum UI_string_types type, int input_flags,
164 char *result_buf, int minsize, int maxsize, const char *test_buf)
165 {
166 int ret = -1;
167 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
168 type, input_flags, result_buf);
169
170 if (s)
171 {
172 if (allocate_string_stack(ui) >= 0)
173 {
174 s->_.string_data.result_minsize=minsize;
175 s->_.string_data.result_maxsize=maxsize;
176 s->_.string_data.test_buf=test_buf;
177 ret=sk_UI_STRING_push(ui->strings, s);
178 /* sk_push() returns 0 on error. Let's addapt that */
179 if (ret <= 0) ret--;
180 }
181 else
182 free_string(s);
183 }
184 return ret;
185 }
186
187static int general_allocate_boolean(UI *ui,
188 const char *prompt, const char *action_desc,
189 const char *ok_chars, const char *cancel_chars,
190 int prompt_freeable, enum UI_string_types type, int input_flags,
191 char *result_buf)
192 {
193 int ret = -1;
194 UI_STRING *s;
195 const char *p;
196
197 if (ok_chars == NULL)
198 {
199 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
200 }
201 else if (cancel_chars == NULL)
202 {
203 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
204 }
205 else
206 {
207 for(p = ok_chars; *p; p++)
208 {
209 if (strchr(cancel_chars, *p))
210 {
211 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
212 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
213 }
214 }
215
216 s = general_allocate_prompt(ui, prompt, prompt_freeable,
217 type, input_flags, result_buf);
218
219 if (s)
220 {
221 if (allocate_string_stack(ui) >= 0)
222 {
223 s->_.boolean_data.action_desc = action_desc;
224 s->_.boolean_data.ok_chars = ok_chars;
225 s->_.boolean_data.cancel_chars = cancel_chars;
226 ret=sk_UI_STRING_push(ui->strings, s);
227 /* sk_push() returns 0 on error.
228 Let's addapt that */
229 if (ret <= 0) ret--;
230 }
231 else
232 free_string(s);
233 }
234 }
235 return ret;
236 }
237
238/* Returns the index to the place in the stack or 0 for error. Uses a
239 direct reference to the prompt. */
240int UI_add_input_string(UI *ui, const char *prompt, int flags,
241 char *result_buf, int minsize, int maxsize)
242 {
243 return general_allocate_string(ui, prompt, 0,
244 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
245 }
246
247/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
248int UI_dup_input_string(UI *ui, const char *prompt, int flags,
249 char *result_buf, int minsize, int maxsize)
250 {
251 char *prompt_copy=NULL;
252
253 if (prompt)
254 {
255 prompt_copy=BUF_strdup(prompt);
256 if (prompt_copy == NULL)
257 {
258 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
259 return 0;
260 }
261 }
262
263 return general_allocate_string(ui, prompt_copy, 1,
264 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
265 }
266
267int UI_add_verify_string(UI *ui, const char *prompt, int flags,
268 char *result_buf, int minsize, int maxsize, const char *test_buf)
269 {
270 return general_allocate_string(ui, prompt, 0,
271 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
272 }
273
274int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
275 char *result_buf, int minsize, int maxsize, const char *test_buf)
276 {
277 char *prompt_copy=NULL;
278
279 if (prompt)
280 {
281 prompt_copy=BUF_strdup(prompt);
282 if (prompt_copy == NULL)
283 {
284 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
285 return -1;
286 }
287 }
288
289 return general_allocate_string(ui, prompt_copy, 1,
290 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
291 }
292
293int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
294 const char *ok_chars, const char *cancel_chars,
295 int flags, char *result_buf)
296 {
297 return general_allocate_boolean(ui, prompt, action_desc,
298 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
299 }
300
301int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
302 const char *ok_chars, const char *cancel_chars,
303 int flags, char *result_buf)
304 {
305 char *prompt_copy = NULL;
306 char *action_desc_copy = NULL;
307 char *ok_chars_copy = NULL;
308 char *cancel_chars_copy = NULL;
309
310 if (prompt)
311 {
312 prompt_copy=BUF_strdup(prompt);
313 if (prompt_copy == NULL)
314 {
315 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
316 goto err;
317 }
318 }
319
320 if (action_desc)
321 {
322 action_desc_copy=BUF_strdup(action_desc);
323 if (action_desc_copy == NULL)
324 {
325 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
326 goto err;
327 }
328 }
329
330 if (ok_chars)
331 {
332 ok_chars_copy=BUF_strdup(ok_chars);
333 if (ok_chars_copy == NULL)
334 {
335 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
336 goto err;
337 }
338 }
339
340 if (cancel_chars)
341 {
342 cancel_chars_copy=BUF_strdup(cancel_chars);
343 if (cancel_chars_copy == NULL)
344 {
345 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
346 goto err;
347 }
348 }
349
350 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
351 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
352 result_buf);
353 err:
354 if (prompt_copy) OPENSSL_free(prompt_copy);
355 if (action_desc_copy) OPENSSL_free(action_desc_copy);
356 if (ok_chars_copy) OPENSSL_free(ok_chars_copy);
357 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy);
358 return -1;
359 }
360
361int UI_add_info_string(UI *ui, const char *text)
362 {
363 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
364 NULL);
365 }
366
367int UI_dup_info_string(UI *ui, const char *text)
368 {
369 char *text_copy=NULL;
370
371 if (text)
372 {
373 text_copy=BUF_strdup(text);
374 if (text_copy == NULL)
375 {
376 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
377 return -1;
378 }
379 }
380
381 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
382 0, 0, NULL);
383 }
384
385int UI_add_error_string(UI *ui, const char *text)
386 {
387 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
388 NULL);
389 }
390
391int UI_dup_error_string(UI *ui, const char *text)
392 {
393 char *text_copy=NULL;
394
395 if (text)
396 {
397 text_copy=BUF_strdup(text);
398 if (text_copy == NULL)
399 {
400 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
401 return -1;
402 }
403 }
404 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
405 0, 0, NULL);
406 }
407
408char *UI_construct_prompt(UI *ui, const char *object_desc,
409 const char *object_name)
410 {
411 char *prompt = NULL;
412
413 if (ui->meth->ui_construct_prompt)
414 prompt = ui->meth->ui_construct_prompt(ui,
415 object_desc, object_name);
416 else
417 {
418 char prompt1[] = "Enter ";
419 char prompt2[] = " for ";
420 char prompt3[] = ":";
421 int len = 0;
422
423 if (object_desc == NULL)
424 return NULL;
425 len = sizeof(prompt1) - 1 + strlen(object_desc);
426 if (object_name)
427 len += sizeof(prompt2) - 1 + strlen(object_name);
428 len += sizeof(prompt3) - 1;
429
430 prompt = (char *)OPENSSL_malloc(len + 1);
431 strcpy(prompt, prompt1);
432 strcat(prompt, object_desc);
433 if (object_name)
434 {
435 strcat(prompt, prompt2);
436 strcat(prompt, object_name);
437 }
438 strcat(prompt, prompt3);
439 }
440 return prompt;
441 }
442
443void *UI_add_user_data(UI *ui, void *user_data)
444 {
445 void *old_data = ui->user_data;
446 ui->user_data = user_data;
447 return old_data;
448 }
449
450void *UI_get0_user_data(UI *ui)
451 {
452 return ui->user_data;
453 }
454
455const char *UI_get0_result(UI *ui, int i)
456 {
457 if (i < 0)
458 {
459 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL);
460 return NULL;
461 }
462 if (i >= sk_UI_STRING_num(ui->strings))
463 {
464 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
465 return NULL;
466 }
467 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
468 }
469
470static int print_error(const char *str, size_t len, UI *ui)
471 {
472 UI_STRING uis;
473
474 memset(&uis, 0, sizeof(uis));
475 uis.type = UIT_ERROR;
476 uis.out_string = str;
477
478 if (ui->meth->ui_write_string
479 && !ui->meth->ui_write_string(ui, &uis))
480 return -1;
481 return 0;
482 }
483
484int UI_process(UI *ui)
485 {
486 int i, ok=0;
487
488 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
489 return -1;
490
491 if (ui->flags & UI_FLAG_PRINT_ERRORS)
492 ERR_print_errors_cb(
493 (int (*)(const char *, size_t, void *))print_error,
494 (void *)ui);
495
496 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
497 {
498 if (ui->meth->ui_write_string
499 && !ui->meth->ui_write_string(ui,
500 sk_UI_STRING_value(ui->strings, i)))
501 {
502 ok=-1;
503 goto err;
504 }
505 }
506
507 if (ui->meth->ui_flush)
508 switch(ui->meth->ui_flush(ui))
509 {
510 case -1: /* Interrupt/Cancel/something... */
511 ok = -2;
512 goto err;
513 case 0: /* Errors */
514 ok = -1;
515 goto err;
516 default: /* Success */
517 ok = 0;
518 break;
519 }
520
521 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
522 {
523 if (ui->meth->ui_read_string)
524 {
525 switch(ui->meth->ui_read_string(ui,
526 sk_UI_STRING_value(ui->strings, i)))
527 {
528 case -1: /* Interrupt/Cancel/something... */
529 ok = -2;
530 goto err;
531 case 0: /* Errors */
532 ok = -1;
533 goto err;
534 default: /* Success */
535 ok = 0;
536 break;
537 }
538 }
539 }
540 err:
541 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
542 return -1;
543 return ok;
544 }
545
546int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
547 {
548 if (ui == NULL)
549 {
550 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER);
551 return -1;
552 }
553 switch(cmd)
554 {
555 case UI_CTRL_PRINT_ERRORS:
556 {
557 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
558 if (i)
559 ui->flags |= UI_FLAG_PRINT_ERRORS;
560 else
561 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
562 return save_flag;
563 }
564 case UI_CTRL_IS_REDOABLE:
565 return !!(ui->flags & UI_FLAG_REDOABLE);
566 default:
567 break;
568 }
569 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
570 return -1;
571 }
572
573int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
574 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
575 {
576 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
577 new_func, dup_func, free_func);
578 }
579
580int UI_set_ex_data(UI *r, int idx, void *arg)
581 {
582 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
583 }
584
585void *UI_get_ex_data(UI *r, int idx)
586 {
587 return(CRYPTO_get_ex_data(&r->ex_data,idx));
588 }
589
590void UI_set_default_method(const UI_METHOD *meth)
591 {
592 default_UI_meth=meth;
593 }
594
595const UI_METHOD *UI_get_default_method(void)
596 {
597 if (default_UI_meth == NULL)
598 {
599 default_UI_meth=UI_OpenSSL();
600 }
601 return default_UI_meth;
602 }
603
604const UI_METHOD *UI_get_method(UI *ui)
605 {
606 return ui->meth;
607 }
608
609const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
610 {
611 ui->meth=meth;
612 return ui->meth;
613 }
614
615
616UI_METHOD *UI_create_method(char *name)
617 {
618 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
619
620 if (ui_method)
621 memset(ui_method, 0, sizeof(*ui_method));
622 ui_method->name = BUF_strdup(name);
623 return ui_method;
624 }
625
626/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
627 (that is, it hasn't been allocated using UI_create_method(), you deserve
628 anything Murphy can throw at you and more! You have been warned. */
629void UI_destroy_method(UI_METHOD *ui_method)
630 {
631 OPENSSL_free(ui_method->name);
632 ui_method->name = NULL;
633 OPENSSL_free(ui_method);
634 }
635
636int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
637 {
638 if (method)
639 {
640 method->ui_open_session = opener;
641 return 0;
642 }
643 else
644 return -1;
645 }
646
647int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
648 {
649 if (method)
650 {
651 method->ui_write_string = writer;
652 return 0;
653 }
654 else
655 return -1;
656 }
657
658int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
659 {
660 if (method)
661 {
662 method->ui_flush = flusher;
663 return 0;
664 }
665 else
666 return -1;
667 }
668
669int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
670 {
671 if (method)
672 {
673 method->ui_read_string = reader;
674 return 0;
675 }
676 else
677 return -1;
678 }
679
680int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
681 {
682 if (method)
683 {
684 method->ui_close_session = closer;
685 return 0;
686 }
687 else
688 return -1;
689 }
690
691int (*UI_method_get_opener(UI_METHOD *method))(UI*)
692 {
693 if (method)
694 return method->ui_open_session;
695 else
696 return NULL;
697 }
698
699int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
700 {
701 if (method)
702 return method->ui_write_string;
703 else
704 return NULL;
705 }
706
707int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
708 {
709 if (method)
710 return method->ui_flush;
711 else
712 return NULL;
713 }
714
715int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
716 {
717 if (method)
718 return method->ui_read_string;
719 else
720 return NULL;
721 }
722
723int (*UI_method_get_closer(UI_METHOD *method))(UI*)
724 {
725 if (method)
726 return method->ui_close_session;
727 else
728 return NULL;
729 }
730
731enum UI_string_types UI_get_string_type(UI_STRING *uis)
732 {
733 if (!uis)
734 return UIT_NONE;
735 return uis->type;
736 }
737
738int UI_get_input_flags(UI_STRING *uis)
739 {
740 if (!uis)
741 return 0;
742 return uis->input_flags;
743 }
744
745const char *UI_get0_output_string(UI_STRING *uis)
746 {
747 if (!uis)
748 return NULL;
749 return uis->out_string;
750 }
751
752const char *UI_get0_action_string(UI_STRING *uis)
753 {
754 if (!uis)
755 return NULL;
756 switch(uis->type)
757 {
758 case UIT_PROMPT:
759 case UIT_BOOLEAN:
760 return uis->_.boolean_data.action_desc;
761 default:
762 return NULL;
763 }
764 }
765
766const char *UI_get0_result_string(UI_STRING *uis)
767 {
768 if (!uis)
769 return NULL;
770 switch(uis->type)
771 {
772 case UIT_PROMPT:
773 case UIT_VERIFY:
774 return uis->result_buf;
775 default:
776 return NULL;
777 }
778 }
779
780const char *UI_get0_test_string(UI_STRING *uis)
781 {
782 if (!uis)
783 return NULL;
784 switch(uis->type)
785 {
786 case UIT_VERIFY:
787 return uis->_.string_data.test_buf;
788 default:
789 return NULL;
790 }
791 }
792
793int UI_get_result_minsize(UI_STRING *uis)
794 {
795 if (!uis)
796 return -1;
797 switch(uis->type)
798 {
799 case UIT_PROMPT:
800 case UIT_VERIFY:
801 return uis->_.string_data.result_minsize;
802 default:
803 return -1;
804 }
805 }
806
807int UI_get_result_maxsize(UI_STRING *uis)
808 {
809 if (!uis)
810 return -1;
811 switch(uis->type)
812 {
813 case UIT_PROMPT:
814 case UIT_VERIFY:
815 return uis->_.string_data.result_maxsize;
816 default:
817 return -1;
818 }
819 }
820
821int UI_set_result(UI *ui, UI_STRING *uis, const char *result)
822 {
823 int l = strlen(result);
824
825 ui->flags &= ~UI_FLAG_REDOABLE;
826
827 if (!uis)
828 return -1;
829 switch (uis->type)
830 {
831 case UIT_PROMPT:
832 case UIT_VERIFY:
833 {
834 char number1[20];
835 char number2[20];
836
837 BIO_snprintf(number1, sizeof(number1), "%d",
838 uis->_.string_data.result_minsize);
839 BIO_snprintf(number2, sizeof(number2), "%d",
840 uis->_.string_data.result_maxsize);
841
842 if (l < uis->_.string_data.result_minsize)
843 {
844 ui->flags |= UI_FLAG_REDOABLE;
845 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL);
846 ERR_add_error_data(5,"You must type in ",
847 number1," to ",number2," characters");
848 return -1;
849 }
850 if (l > uis->_.string_data.result_maxsize)
851 {
852 ui->flags |= UI_FLAG_REDOABLE;
853 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE);
854 ERR_add_error_data(5,"You must type in ",
855 number1," to ",number2," characters");
856 return -1;
857 }
858 }
859
860 if (!uis->result_buf)
861 {
862 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
863 return -1;
864 }
865
866 strcpy(uis->result_buf, result);
867 break;
868 case UIT_BOOLEAN:
869 {
870 const char *p;
871
872 if (!uis->result_buf)
873 {
874 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
875 return -1;
876 }
877
878 uis->result_buf[0] = '\0';
879 for(p = result; *p; p++)
880 {
881 if (strchr(uis->_.boolean_data.ok_chars, *p))
882 {
883 uis->result_buf[0] =
884 uis->_.boolean_data.ok_chars[0];
885 break;
886 }
887 if (strchr(uis->_.boolean_data.cancel_chars, *p))
888 {
889 uis->result_buf[0] =
890 uis->_.boolean_data.cancel_chars[0];
891 break;
892 }
893 }
894 default:
895 break;
896 }
897 }
898 return 0;
899 }
diff --git a/src/lib/libssl/src/crypto/ui/ui_locl.h b/src/lib/libssl/src/crypto/ui/ui_locl.h
new file mode 100644
index 0000000000..7d3a75a619
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_locl.h
@@ -0,0 +1,148 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_LOCL_H
60#define HEADER_UI_LOCL_H
61
62#include <openssl/ui.h>
63
64struct ui_method_st
65 {
66 char *name;
67
68 /* All the functions return 1 or non-NULL for success and 0 or NULL
69 for failure */
70
71 /* Open whatever channel for this, be it the console, an X window
72 or whatever.
73 This function should use the ex_data structure to save
74 intermediate data. */
75 int (*ui_open_session)(UI *ui);
76
77 int (*ui_write_string)(UI *ui, UI_STRING *uis);
78
79 /* Flush the output. If a GUI dialog box is used, this function can
80 be used to actually display it. */
81 int (*ui_flush)(UI *ui);
82
83 int (*ui_read_string)(UI *ui, UI_STRING *uis);
84
85 int (*ui_close_session)(UI *ui);
86
87 /* Construct a prompt in a user-defined manner. object_desc is a
88 textual short description of the object, for example "pass phrase",
89 and object_name is the name of the object (might be a card name or
90 a file name.
91 The returned string shall always be allocated on the heap with
92 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). */
93 char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
94 const char *object_name);
95 };
96
97struct ui_string_st
98 {
99 enum UI_string_types type; /* Input */
100 const char *out_string; /* Input */
101 int input_flags; /* Flags from the user */
102
103 /* The following parameters are completely irrelevant for UIT_INFO,
104 and can therefore be set to 0 or NULL */
105 char *result_buf; /* Input and Output: If not NULL, user-defined
106 with size in result_maxsize. Otherwise, it
107 may be allocated by the UI routine, meaning
108 result_minsize is going to be overwritten.*/
109 union
110 {
111 struct
112 {
113 int result_minsize; /* Input: minimum required
114 size of the result.
115 */
116 int result_maxsize; /* Input: maximum permitted
117 size of the result */
118
119 const char *test_buf; /* Input: test string to verify
120 against */
121 } string_data;
122 struct
123 {
124 const char *action_desc; /* Input */
125 const char *ok_chars; /* Input */
126 const char *cancel_chars; /* Input */
127 } boolean_data;
128 } _;
129
130#define OUT_STRING_FREEABLE 0x01
131 int flags; /* flags for internal use */
132 };
133
134struct ui_st
135 {
136 const UI_METHOD *meth;
137 STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
138 than one thing at a time, and
139 with different echoing status. */
140 void *user_data;
141 CRYPTO_EX_DATA ex_data;
142
143#define UI_FLAG_REDOABLE 0x0001
144#define UI_FLAG_PRINT_ERRORS 0x0100
145 int flags;
146 };
147
148#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_openssl.c b/src/lib/libssl/src/crypto/ui/ui_openssl.c
new file mode 100644
index 0000000000..3aa03f74aa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_openssl.c
@@ -0,0 +1,661 @@
1/* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* The lowest level part of this file was previously in crypto/des/read_pwd.c,
60 * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
61 * All rights reserved.
62 *
63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL.
66 *
67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package.
80 *
81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions
83 * are met:
84 * 1. Redistributions of source code must retain the copyright
85 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 * 3. All advertising materials mentioning features or use of this software
90 * must display the following acknowledgement:
91 * "This product includes cryptographic software written by
92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE.
110 *
111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence
114 * [including the GNU Public Licence.]
115 */
116
117
118#include <openssl/e_os2.h>
119
120#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
121# ifdef OPENSSL_UNISTD
122# include OPENSSL_UNISTD
123# else
124# include <unistd.h>
125# endif
126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION)
129
130# define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS
133# endif
134
135# endif
136#endif
137
138#ifdef WIN16TTY
139# undef OPENSSL_SYS_WIN16
140# undef WIN16
141# undef _WINDOWS
142# include <graph.h>
143#endif
144
145/* 06-Apr-92 Luke Brennan Support for VMS */
146#include "ui_locl.h"
147#include "cryptlib.h"
148#include <signal.h>
149#include <stdio.h>
150#include <string.h>
151#include <errno.h>
152
153#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
154# include <starlet.h>
155# ifdef __DECC
156# pragma message disable DOLLARID
157# endif
158#endif
159
160#ifdef WIN_CONSOLE_BUG
161# include <windows.h>
162# include <wincon.h>
163#endif
164
165
166/* There are 5 types of terminal interface supported,
167 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
168 */
169
170#if defined(__sgi) && !defined(TERMIOS)
171# define TERMIOS
172# undef TERMIO
173# undef SGTTY
174#endif
175
176#if defined(linux) && !defined(TERMIO)
177# undef TERMIOS
178# define TERMIO
179# undef SGTTY
180#endif
181
182#ifdef _LIBC
183# undef TERMIOS
184# define TERMIO
185# undef SGTTY
186#endif
187
188#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
189# undef TERMIOS
190# undef TERMIO
191# define SGTTY
192#endif
193
194#if defined(OPENSSL_SYS_VSWORKS)
195#undef TERMIOS
196#undef TERMIO
197#undef SGTTY
198#endif
199
200#ifdef TERMIOS
201# include <termios.h>
202# define TTY_STRUCT struct termios
203# define TTY_FLAGS c_lflag
204# define TTY_get(tty,data) tcgetattr(tty,data)
205# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
206#endif
207
208#ifdef TERMIO
209# include <termio.h>
210# define TTY_STRUCT struct termio
211# define TTY_FLAGS c_lflag
212# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
213# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
214#endif
215
216#ifdef SGTTY
217# include <sgtty.h>
218# define TTY_STRUCT struct sgttyb
219# define TTY_FLAGS sg_flags
220# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
221# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
222#endif
223
224#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
225# include <sys/ioctl.h>
226#endif
227
228#ifdef OPENSSL_SYS_MSDOS
229# include <conio.h>
230#endif
231
232#ifdef OPENSSL_SYS_VMS
233# include <ssdef.h>
234# include <iodef.h>
235# include <ttdef.h>
236# include <descrip.h>
237struct IOSB {
238 short iosb$w_value;
239 short iosb$w_count;
240 long iosb$l_info;
241 };
242#endif
243
244#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
245/*
246 * This one needs work. As a matter of fact the code is unoperational
247 * and this is only a trick to get it compiled.
248 * <appro@fy.chalmers.se>
249 */
250# define TTY_STRUCT int
251#endif
252
253#ifndef NX509_SIG
254# define NX509_SIG 32
255#endif
256
257
258/* Define globals. They are protected by a lock */
259#ifdef SIGACTION
260static struct sigaction savsig[NX509_SIG];
261#else
262static void (*savsig[NX509_SIG])(int );
263#endif
264
265#ifdef OPENSSL_SYS_VMS
266static struct IOSB iosb;
267static $DESCRIPTOR(terminal,"TT");
268static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
269static long status;
270static unsigned short channel = 0;
271#else
272#ifndef OPENSSL_SYS_MSDOS
273static TTY_STRUCT tty_orig,tty_new;
274#endif
275#endif
276static FILE *tty_in, *tty_out;
277static int is_a_tty;
278
279/* Declare static functions */
280static void read_till_nl(FILE *);
281static void recsig(int);
282static void pushsig(void);
283static void popsig(void);
284#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
285static int noecho_fgets(char *buf, int size, FILE *tty);
286#endif
287static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
288
289static int read_string(UI *ui, UI_STRING *uis);
290static int write_string(UI *ui, UI_STRING *uis);
291
292static int open_console(UI *ui);
293static int echo_console(UI *ui);
294static int noecho_console(UI *ui);
295static int close_console(UI *ui);
296
297static UI_METHOD ui_openssl =
298 {
299 "OpenSSL default user interface",
300 open_console,
301 write_string,
302 NULL, /* No flusher is needed for command lines */
303 read_string,
304 close_console,
305 NULL
306 };
307
308/* The method with all the built-in thingies */
309UI_METHOD *UI_OpenSSL(void)
310 {
311 return &ui_openssl;
312 }
313
314/* The following function makes sure that info and error strings are printed
315 before any prompt. */
316static int write_string(UI *ui, UI_STRING *uis)
317 {
318 switch (UI_get_string_type(uis))
319 {
320 case UIT_ERROR:
321 case UIT_INFO:
322 fputs(UI_get0_output_string(uis), tty_out);
323 fflush(tty_out);
324 break;
325 default:
326 break;
327 }
328 return 1;
329 }
330
331static int read_string(UI *ui, UI_STRING *uis)
332 {
333 int ok = 0;
334
335 switch (UI_get_string_type(uis))
336 {
337 case UIT_BOOLEAN:
338 fputs(UI_get0_output_string(uis), tty_out);
339 fputs(UI_get0_action_string(uis), tty_out);
340 fflush(tty_out);
341 return read_string_inner(ui, uis,
342 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
343 case UIT_PROMPT:
344 fputs(UI_get0_output_string(uis), tty_out);
345 fflush(tty_out);
346 return read_string_inner(ui, uis,
347 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
348 case UIT_VERIFY:
349 fprintf(tty_out,"Verifying - %s",
350 UI_get0_output_string(uis));
351 fflush(tty_out);
352 if ((ok = read_string_inner(ui, uis,
353 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
354 return ok;
355 if (strcmp(UI_get0_result_string(uis),
356 UI_get0_test_string(uis)) != 0)
357 {
358 fprintf(tty_out,"Verify failure\n");
359 fflush(tty_out);
360 return 0;
361 }
362 break;
363 default:
364 break;
365 }
366 return 1;
367 }
368
369
370/* Internal functions to read a string without echoing */
371static void read_till_nl(FILE *in)
372 {
373#define SIZE 4
374 char buf[SIZE+1];
375
376 do {
377 fgets(buf,SIZE,in);
378 } while (strchr(buf,'\n') == NULL);
379 }
380
381static sig_atomic_t intr_signal;
382
383static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
384 {
385 static int ps;
386 int ok;
387 char result[BUFSIZ];
388 int maxsize = BUFSIZ-1;
389 char *p;
390
391#ifndef OPENSSL_SYS_WIN16
392 intr_signal=0;
393 ok=0;
394 ps=0;
395
396 pushsig();
397 ps=1;
398
399 if (!echo && !noecho_console(ui))
400 goto error;
401 ps=2;
402
403 result[0]='\0';
404#ifdef OPENSSL_SYS_MSDOS
405 if (!echo)
406 {
407 noecho_fgets(result,maxsize,tty_in);
408 p=result; /* FIXME: noecho_fgets doesn't return errors */
409 }
410 else
411 p=fgets(result,maxsize,tty_in);
412#else
413 p=fgets(result,maxsize,tty_in);
414#endif
415 if(!p)
416 goto error;
417 if (feof(tty_in)) goto error;
418 if (ferror(tty_in)) goto error;
419 if ((p=(char *)strchr(result,'\n')) != NULL)
420 {
421 if (strip_nl)
422 *p='\0';
423 }
424 else
425 read_till_nl(tty_in);
426 if (UI_set_result(ui, uis, result) >= 0)
427 ok=1;
428
429error:
430 if (intr_signal == SIGINT)
431 ok=-1;
432 if (!echo) fprintf(tty_out,"\n");
433 if (ps >= 2 && !echo && !echo_console(ui))
434 ok=0;
435
436 if (ps >= 1)
437 popsig();
438#else
439 ok=1;
440#endif
441
442 memset(result,0,BUFSIZ);
443 return ok;
444 }
445
446
447/* Internal functions to open, handle and close a channel to the console. */
448static int open_console(UI *ui)
449 {
450 CRYPTO_w_lock(CRYPTO_LOCK_UI);
451 is_a_tty = 1;
452
453#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VSWORKS)
454 tty_in=stdin;
455 tty_out=stderr;
456#else
457# ifdef OPENSSL_SYS_MSDOS
458# define DEV_TTY "con"
459# else
460# define DEV_TTY "/dev/tty"
461# endif
462 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
463 tty_in=stdin;
464 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
465 tty_out=stderr;
466#endif
467
468#if defined(TTY_get) && !defined(VMS)
469 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
470 {
471#ifdef ENOTTY
472 if (errno == ENOTTY)
473 is_a_tty=0;
474 else
475#endif
476#ifdef EINVAL
477 /* Ariel Glenn ariel@columbia.edu reports that solaris
478 * can return EINVAL instead. This should be ok */
479 if (errno == EINVAL)
480 is_a_tty=0;
481 else
482#endif
483 return 0;
484 }
485#endif
486#ifdef OPENSSL_SYS_VMS
487 status = sys$assign(&terminal,&channel,0,0);
488 if (status != SS$_NORMAL)
489 return 0;
490 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
491 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
492 return 0;
493#endif
494 return 1;
495 }
496
497static int noecho_console(UI *ui)
498 {
499#ifdef TTY_FLAGS
500 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
501 tty_new.TTY_FLAGS &= ~ECHO;
502#endif
503
504#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
505 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
506 return 0;
507#endif
508#ifdef OPENSSL_SYS_VMS
509 tty_new[0] = tty_orig[0];
510 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
511 tty_new[2] = tty_orig[2];
512 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
513 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
514 return 0;
515#endif
516 return 1;
517 }
518
519static int echo_console(UI *ui)
520 {
521#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
522 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
523 tty_new.TTY_FLAGS |= ECHO;
524#endif
525
526#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
527 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
528 return 0;
529#endif
530#ifdef OPENSSL_SYS_VMS
531 tty_new[0] = tty_orig[0];
532 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
533 tty_new[2] = tty_orig[2];
534 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
535 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
536 return 0;
537#endif
538 return 1;
539 }
540
541static int close_console(UI *ui)
542 {
543 if (tty_in != stderr) fclose(tty_in);
544 if (tty_out != stderr) fclose(tty_out);
545#ifdef OPENSSL_SYS_VMS
546 status = sys$dassgn(channel);
547#endif
548 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
549
550 return 1;
551 }
552
553
554/* Internal functions to handle signals and act on them */
555static void pushsig(void)
556 {
557 int i;
558#ifdef SIGACTION
559 struct sigaction sa;
560
561 memset(&sa,0,sizeof sa);
562 sa.sa_handler=recsig;
563#endif
564
565 for (i=1; i<NX509_SIG; i++)
566 {
567#ifdef SIGUSR1
568 if (i == SIGUSR1)
569 continue;
570#endif
571#ifdef SIGUSR2
572 if (i == SIGUSR2)
573 continue;
574#endif
575#ifdef SIGKILL
576 if (i == SIGKILL) /* We can't make any action on that. */
577 continue;
578#endif
579#ifdef SIGACTION
580 sigaction(i,&sa,&savsig[i]);
581#else
582 savsig[i]=signal(i,recsig);
583#endif
584 }
585
586#ifdef SIGWINCH
587 signal(SIGWINCH,SIG_DFL);
588#endif
589 }
590
591static void popsig(void)
592 {
593 int i;
594
595 for (i=1; i<NX509_SIG; i++)
596 {
597#ifdef SIGUSR1
598 if (i == SIGUSR1)
599 continue;
600#endif
601#ifdef SIGUSR2
602 if (i == SIGUSR2)
603 continue;
604#endif
605#ifdef SIGACTION
606 sigaction(i,&savsig[i],NULL);
607#else
608 signal(i,savsig[i]);
609#endif
610 }
611 }
612
613static void recsig(int i)
614 {
615 intr_signal=i;
616 }
617
618/* Internal functions specific for Windows */
619#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
620static int noecho_fgets(char *buf, int size, FILE *tty)
621 {
622 int i;
623 char *p;
624
625 p=buf;
626 for (;;)
627 {
628 if (size == 0)
629 {
630 *p='\0';
631 break;
632 }
633 size--;
634#ifdef WIN16TTY
635 i=_inchar();
636#else
637 i=getch();
638#endif
639 if (i == '\r') i='\n';
640 *(p++)=i;
641 if (i == '\n')
642 {
643 *p='\0';
644 break;
645 }
646 }
647#ifdef WIN_CONSOLE_BUG
648/* Win95 has several evil console bugs: one of these is that the
649 * last character read using getch() is passed to the next read: this is
650 * usually a CR so this can be trouble. No STDIO fix seems to work but
651 * flushing the console appears to do the trick.
652 */
653 {
654 HANDLE inh;
655 inh = GetStdHandle(STD_INPUT_HANDLE);
656 FlushConsoleInputBuffer(inh);
657 }
658#endif
659 return(strlen(buf));
660 }
661#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_util.c b/src/lib/libssl/src/crypto/ui/ui_util.c
new file mode 100644
index 0000000000..7c6f7d3a73
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ui/ui_util.c
@@ -0,0 +1,86 @@
1/* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui.h>
58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 char buff[BUFSIZ];
62 int ret;
63
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
65 memset(buff,0,BUFSIZ);
66 return(ret);
67 }
68
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
70 {
71 int ok = 0;
72 UI *ui;
73
74 ui = UI_new();
75 if (ui)
76 {
77 ok = UI_add_input_string(ui,prompt,0,buf,0,BUFSIZ-1);
78 if (ok == 0 && verify)
79 ok = UI_add_verify_string(ui,prompt,0,buff,0,BUFSIZ-1,
80 buf);
81 if (ok == 0)
82 ok=UI_process(ui);
83 UI_free(ui);
84 }
85 return(ok);
86 }
diff --git a/src/lib/libssl/src/crypto/uid.c b/src/lib/libssl/src/crypto/uid.c
new file mode 100644
index 0000000000..b5b61b76d4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/uid.c
@@ -0,0 +1,88 @@
1/* crypto/uid.c */
2/* ====================================================================
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57
58#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2)
59
60#include <unistd.h>
61
62int OPENSSL_issetugid(void)
63 {
64 return issetugid();
65 }
66
67#elif defined(WIN32)
68
69int OPENSSL_issetugid(void)
70 {
71 return 0;
72 }
73
74#else
75
76#include <unistd.h>
77#include <sys/types.h>
78
79int OPENSSL_issetugid(void)
80 {
81 if (getuid() != geteuid()) return 1;
82 if (getgid() != getegid()) return 1;
83 return 0;
84 }
85#endif
86
87
88
diff --git a/src/lib/libssl/src/crypto/x509/x509_att.c b/src/lib/libssl/src/crypto/x509/x509_att.c
new file mode 100644
index 0000000000..caafde658f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_att.c
@@ -0,0 +1,326 @@
1/* crypto/x509/x509_att.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{
70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
72}
73
74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
75 int lastpos)
76{
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509at_get_attr_by_OBJ(x,obj,lastpos));
82}
83
84int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86{
87 int n;
88 X509_ATTRIBUTE *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_ATTRIBUTE_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_ATTRIBUTE_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102}
103
104X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc)
105{
106 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
107 return NULL;
108 else
109 return sk_X509_ATTRIBUTE_value(x,loc);
110}
111
112X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc)
113{
114 X509_ATTRIBUTE *ret;
115
116 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
117 return(NULL);
118 ret=sk_X509_ATTRIBUTE_delete(x,loc);
119 return(ret);
120}
121
122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
123 X509_ATTRIBUTE *attr)
124{
125 X509_ATTRIBUTE *new_attr=NULL;
126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
127
128 if ((x != NULL) && (*x == NULL))
129 {
130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
131 goto err;
132 }
133 else
134 sk= *x;
135
136 if ((new_attr=X509_ATTRIBUTE_dup(attr)) == NULL)
137 goto err2;
138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
139 goto err;
140 if ((x != NULL) && (*x == NULL))
141 *x=sk;
142 return(sk);
143err:
144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
145err2:
146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
148 return(NULL);
149}
150
151STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
152 ASN1_OBJECT *obj, int type,
153 unsigned char *bytes, int len)
154{
155 X509_ATTRIBUTE *attr;
156 STACK_OF(X509_ATTRIBUTE) *ret;
157 attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, type, bytes, len);
158 if(!attr) return 0;
159 ret = X509at_add1_attr(x, attr);
160 X509_ATTRIBUTE_free(attr);
161 return ret;
162}
163
164STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
165 int nid, int type,
166 unsigned char *bytes, int len)
167{
168 X509_ATTRIBUTE *attr;
169 STACK_OF(X509_ATTRIBUTE) *ret;
170 attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, bytes, len);
171 if(!attr) return 0;
172 ret = X509at_add1_attr(x, attr);
173 X509_ATTRIBUTE_free(attr);
174 return ret;
175}
176
177STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
178 char *attrname, int type,
179 unsigned char *bytes, int len)
180{
181 X509_ATTRIBUTE *attr;
182 STACK_OF(X509_ATTRIBUTE) *ret;
183 attr = X509_ATTRIBUTE_create_by_txt(NULL, attrname, type, bytes, len);
184 if(!attr) return 0;
185 ret = X509at_add1_attr(x, attr);
186 X509_ATTRIBUTE_free(attr);
187 return ret;
188}
189
190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
191 int atrtype, void *data, int len)
192{
193 ASN1_OBJECT *obj;
194 X509_ATTRIBUTE *ret;
195
196 obj=OBJ_nid2obj(nid);
197 if (obj == NULL)
198 {
199 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID,X509_R_UNKNOWN_NID);
200 return(NULL);
201 }
202 ret=X509_ATTRIBUTE_create_by_OBJ(attr,obj,atrtype,data,len);
203 if (ret == NULL) ASN1_OBJECT_free(obj);
204 return(ret);
205}
206
207X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
208 ASN1_OBJECT *obj, int atrtype, void *data, int len)
209{
210 X509_ATTRIBUTE *ret;
211
212 if ((attr == NULL) || (*attr == NULL))
213 {
214 if ((ret=X509_ATTRIBUTE_new()) == NULL)
215 {
216 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
217 return(NULL);
218 }
219 }
220 else
221 ret= *attr;
222
223 if (!X509_ATTRIBUTE_set1_object(ret,obj))
224 goto err;
225 if (!X509_ATTRIBUTE_set1_data(ret,atrtype,data,len))
226 goto err;
227
228 if ((attr != NULL) && (*attr == NULL)) *attr=ret;
229 return(ret);
230err:
231 if ((attr == NULL) || (ret != *attr))
232 X509_ATTRIBUTE_free(ret);
233 return(NULL);
234}
235
236X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
237 char *atrname, int type, unsigned char *bytes, int len)
238 {
239 ASN1_OBJECT *obj;
240 X509_ATTRIBUTE *nattr;
241
242 obj=OBJ_txt2obj(atrname, 0);
243 if (obj == NULL)
244 {
245 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,
246 X509_R_INVALID_FIELD_NAME);
247 ERR_add_error_data(2, "name=", atrname);
248 return(NULL);
249 }
250 nattr = X509_ATTRIBUTE_create_by_OBJ(attr,obj,type,bytes,len);
251 ASN1_OBJECT_free(obj);
252 return nattr;
253 }
254
255int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj)
256{
257 if ((attr == NULL) || (obj == NULL))
258 return(0);
259 ASN1_OBJECT_free(attr->object);
260 attr->object=OBJ_dup(obj);
261 return(1);
262}
263
264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len)
265{
266 ASN1_TYPE *ttmp;
267 ASN1_STRING *stmp;
268 int atype;
269 if (!attr) return 0;
270 if(attrtype & MBSTRING_FLAG) {
271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
272 OBJ_obj2nid(attr->object));
273 if(!stmp) {
274 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);
275 return 0;
276 }
277 atype = stmp->type;
278 } else {
279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
281 atype = attrtype;
282 }
283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
284 if(!(ttmp = ASN1_TYPE_new())) goto err;
285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
286 attr->set = 1;
287 ASN1_TYPE_set(ttmp, atype, stmp);
288 return 1;
289 err:
290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
291 return 0;
292}
293
294int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr)
295{
296 if(attr->set) return sk_ASN1_TYPE_num(attr->value.set);
297 if(attr->value.single) return 1;
298 return 0;
299}
300
301ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr)
302{
303 if (attr == NULL) return(NULL);
304 return(attr->object);
305}
306
307void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
308 int atrtype, void *data)
309{
310 ASN1_TYPE *ttmp;
311 ttmp = X509_ATTRIBUTE_get0_type(attr, idx);
312 if(!ttmp) return NULL;
313 if(atrtype != ASN1_TYPE_get(ttmp)){
314 X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE);
315 return NULL;
316 }
317 return ttmp->value.ptr;
318}
319
320ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx)
321{
322 if (attr == NULL) return(NULL);
323 if(idx >= X509_ATTRIBUTE_count(attr)) return NULL;
324 if(attr->set) return sk_ASN1_TYPE_value(attr->value.set, idx);
325 else return attr->value.single;
326}
diff --git a/src/lib/libssl/src/crypto/x509/x509_trs.c b/src/lib/libssl/src/crypto/x509/x509_trs.c
new file mode 100644
index 0000000000..9f7d67952d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_trs.c
@@ -0,0 +1,263 @@
1/* x509_trs.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static int tr_cmp(X509_TRUST **a, X509_TRUST **b);
65static void trtable_free(X509_TRUST *p);
66
67static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
68static int trust_any(X509_TRUST *trust, X509 *x, int flags);
69
70static int obj_trust(int id, X509 *x, int flags);
71static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
72
73/* WARNING: the following table should be kept in order of trust
74 * and without any gaps so we can just subtract the minimum trust
75 * value to get an index into the table
76 */
77
78static X509_TRUST trstandard[] = {
79{X509_TRUST_ANY, 0, trust_any, "Any", 0, NULL},
80{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},
81{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Client", NID_server_auth, NULL},
82{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
83};
84
85#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
86
87IMPLEMENT_STACK_OF(X509_TRUST)
88
89static STACK_OF(X509_TRUST) *trtable = NULL;
90
91static int tr_cmp(X509_TRUST **a, X509_TRUST **b)
92{
93 return (*a)->trust - (*b)->trust;
94}
95
96int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
97{
98int (*oldtrust)(int , X509 *, int);
99oldtrust = default_trust;
100default_trust = trust;
101return oldtrust;
102}
103
104
105int X509_check_trust(X509 *x, int id, int flags)
106{
107 X509_TRUST *pt;
108 int idx;
109 if(id == -1) return 1;
110 if(!(idx = X509_TRUST_get_by_id(id)))
111 return default_trust(id, x, flags);
112 pt = X509_TRUST_get0(idx);
113 return pt->check_trust(pt, x, flags);
114}
115
116int X509_TRUST_get_count(void)
117{
118 if(!trtable) return X509_TRUST_COUNT;
119 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
120}
121
122X509_TRUST * X509_TRUST_get0(int idx)
123{
124 if(idx < 0) return NULL;
125 if(idx < X509_TRUST_COUNT) return trstandard + idx;
126 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
127}
128
129int X509_TRUST_get_by_id(int id)
130{
131 X509_TRUST tmp;
132 int idx;
133 if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
134 return id - X509_TRUST_MIN;
135 tmp.trust = id;
136 if(!trtable) return -1;
137 idx = sk_X509_TRUST_find(trtable, &tmp);
138 if(idx == -1) return -1;
139 return idx + X509_TRUST_COUNT;
140}
141
142int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
143 char *name, int arg1, void *arg2)
144{
145 int idx;
146 X509_TRUST *trtmp;
147 /* This is set according to what we change: application can't set it */
148 flags &= ~X509_TRUST_DYNAMIC;
149 /* This will always be set for application modified trust entries */
150 flags |= X509_TRUST_DYNAMIC_NAME;
151 /* Get existing entry if any */
152 idx = X509_TRUST_get_by_id(id);
153 /* Need a new entry */
154 if(idx == -1) {
155 if(!(trtmp = Malloc(sizeof(X509_TRUST)))) {
156 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 trtmp->flags = X509_TRUST_DYNAMIC;
160 } else trtmp = X509_TRUST_get0(idx);
161
162 /* Free existing name if dynamic */
163 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);
164 /* dup supplied name */
165 if(!(trtmp->name = BUF_strdup(name))) {
166 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
167 return 0;
168 }
169 /* Keep the dynamic flag of existing entry */
170 trtmp->flags &= X509_TRUST_DYNAMIC;
171 /* Set all other flags */
172 trtmp->flags |= flags;
173
174 trtmp->trust = id;
175 trtmp->check_trust = ck;
176 trtmp->arg1 = arg1;
177 trtmp->arg2 = arg2;
178
179 /* If its a new entry manage the dynamic table */
180 if(idx == -1) {
181 if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
182 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 if (!sk_X509_TRUST_push(trtable, trtmp)) {
186 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
187 return 0;
188 }
189 }
190 return 1;
191}
192
193static void trtable_free(X509_TRUST *p)
194 {
195 if(!p) return;
196 if (p->flags & X509_TRUST_DYNAMIC)
197 {
198 if (p->flags & X509_TRUST_DYNAMIC_NAME)
199 Free(p->name);
200 Free(p);
201 }
202 }
203
204void X509_TRUST_cleanup(void)
205{
206 int i;
207 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
208 sk_X509_TRUST_pop_free(trtable, trtable_free);
209 trtable = NULL;
210}
211
212int X509_TRUST_get_flags(X509_TRUST *xp)
213{
214 return xp->flags;
215}
216
217char *X509_TRUST_get0_name(X509_TRUST *xp)
218{
219 return xp->name;
220}
221
222int X509_TRUST_get_trust(X509_TRUST *xp)
223{
224 return xp->trust;
225}
226
227static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)
228{
229 if(x->aux) return obj_trust(trust->arg1, x, flags);
230 /* we don't have any trust settings: for compatibility
231 * we return trusted if it is self signed
232 */
233 X509_check_purpose(x, -1, 0);
234 if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED;
235 else return X509_TRUST_UNTRUSTED;
236}
237
238static int obj_trust(int id, X509 *x, int flags)
239{
240 ASN1_OBJECT *obj;
241 int i;
242 X509_CERT_AUX *ax;
243 ax = x->aux;
244 if(!ax) return X509_TRUST_UNTRUSTED;
245 if(ax->reject) {
246 for(i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
247 obj = sk_ASN1_OBJECT_value(ax->reject, i);
248 if(OBJ_obj2nid(obj) == id) return X509_TRUST_REJECTED;
249 }
250 }
251 if(ax->trust) {
252 for(i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
253 obj = sk_ASN1_OBJECT_value(ax->trust, i);
254 if(OBJ_obj2nid(obj) == id) return X509_TRUST_TRUSTED;
255 }
256 }
257 return X509_TRUST_UNTRUSTED;
258}
259
260static int trust_any(X509_TRUST *trust, X509 *x, int flags)
261{
262 return X509_TRUST_TRUSTED;
263}
diff --git a/src/lib/libssl/src/crypto/x509/x509cset.c b/src/lib/libssl/src/crypto/x509/x509cset.c
new file mode 100644
index 0000000000..6cac440ea9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509cset.c
@@ -0,0 +1,169 @@
1/* crypto/x509/x509cset.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_CRL_set_version(X509_CRL *x, long version)
67 {
68 if (x == NULL) return(0);
69 if (x->crl->version == NULL)
70 {
71 if ((x->crl->version=M_ASN1_INTEGER_new()) == NULL)
72 return(0);
73 }
74 return(ASN1_INTEGER_set(x->crl->version,version));
75 }
76
77int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
78 {
79 if ((x == NULL) || (x->crl == NULL)) return(0);
80 return(X509_NAME_set(&x->crl->issuer,name));
81 }
82
83
84int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm)
85 {
86 ASN1_TIME *in;
87
88 if (x == NULL) return(0);
89 in=x->crl->lastUpdate;
90 if (in != tm)
91 {
92 in=M_ASN1_TIME_dup(tm);
93 if (in != NULL)
94 {
95 M_ASN1_TIME_free(x->crl->lastUpdate);
96 x->crl->lastUpdate=in;
97 }
98 }
99 return(in != NULL);
100 }
101
102int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm)
103 {
104 ASN1_TIME *in;
105
106 if (x == NULL) return(0);
107 in=x->crl->nextUpdate;
108 if (in != tm)
109 {
110 in=M_ASN1_TIME_dup(tm);
111 if (in != NULL)
112 {
113 M_ASN1_TIME_free(x->crl->nextUpdate);
114 x->crl->nextUpdate=in;
115 }
116 }
117 return(in != NULL);
118 }
119
120int X509_CRL_sort(X509_CRL *c)
121 {
122 int i;
123 X509_REVOKED *r;
124 /* sort the data so it will be written in serial
125 * number order */
126 sk_X509_REVOKED_sort(c->crl->revoked);
127 for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++)
128 {
129 r=sk_X509_REVOKED_value(c->crl->revoked,i);
130 r->sequence=i;
131 }
132 return 1;
133 }
134
135int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
136 {
137 ASN1_TIME *in;
138
139 if (x == NULL) return(0);
140 in=x->revocationDate;
141 if (in != tm)
142 {
143 in=M_ASN1_TIME_dup(tm);
144 if (in != NULL)
145 {
146 M_ASN1_TIME_free(x->revocationDate);
147 x->revocationDate=in;
148 }
149 }
150 return(in != NULL);
151 }
152
153int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
154 {
155 ASN1_INTEGER *in;
156
157 if (x == NULL) return(0);
158 in=x->serialNumber;
159 if (in != serial)
160 {
161 in=M_ASN1_INTEGER_dup(serial);
162 if (in != NULL)
163 {
164 M_ASN1_INTEGER_free(x->serialNumber);
165 x->serialNumber=in;
166 }
167 }
168 return(in != NULL);
169 }
diff --git a/src/lib/libssl/src/crypto/x509/x509spki.c b/src/lib/libssl/src/crypto/x509/x509spki.c
new file mode 100644
index 0000000000..b35c3f92e7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509spki.c
@@ -0,0 +1,121 @@
1/* x509spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
65{
66 if ((x == NULL) || (x->spkac == NULL)) return(0);
67 return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey));
68}
69
70EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
71{
72 if ((x == NULL) || (x->spkac == NULL))
73 return(NULL);
74 return(X509_PUBKEY_get(x->spkac->pubkey));
75}
76
77/* Load a Netscape SPKI from a base64 encoded string */
78
79NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
80{
81 unsigned char *spki_der, *p;
82 int spki_len;
83 NETSCAPE_SPKI *spki;
84 if(len <= 0) len = strlen(str);
85 if (!(spki_der = Malloc(len + 1))) {
86 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
90 if(spki_len < 0) {
91 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
92 X509_R_BASE64_DECODE_ERROR);
93 Free(spki_der);
94 return NULL;
95 }
96 p = spki_der;
97 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
98 Free(spki_der);
99 return spki;
100}
101
102/* Generate a base64 encoded string from an SPKI */
103
104char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
105{
106 unsigned char *der_spki, *p;
107 char *b64_str;
108 int der_len;
109 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
110 der_spki = Malloc(der_len);
111 b64_str = Malloc(der_len * 2);
112 if(!der_spki || !b64_str) {
113 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116 p = der_spki;
117 i2d_NETSCAPE_SPKI(spki, &p);
118 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
119 Free(der_spki);
120 return b64_str;
121}
diff --git a/src/lib/libssl/src/crypto/x509v3/ext_dat.h b/src/lib/libssl/src/crypto/x509v3/ext_dat.h
new file mode 100644
index 0000000000..801a585a52
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/ext_dat.h
@@ -0,0 +1,97 @@
1/* ext_dat.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* This file contains a table of "standard" extensions */
59
60extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
61extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info;
62extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
63extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
64
65/* This table will be searched using OBJ_bsearch so it *must* kept in
66 * order of the ext_nid values.
67 */
68
69static X509V3_EXT_METHOD *standard_exts[] = {
70&v3_nscert,
71&v3_ns_ia5_list[0],
72&v3_ns_ia5_list[1],
73&v3_ns_ia5_list[2],
74&v3_ns_ia5_list[3],
75&v3_ns_ia5_list[4],
76&v3_ns_ia5_list[5],
77&v3_ns_ia5_list[6],
78&v3_skey_id,
79&v3_key_usage,
80&v3_pkey_usage_period,
81&v3_alt[0],
82&v3_alt[1],
83&v3_bcons,
84&v3_crl_num,
85&v3_cpols,
86&v3_akey_id,
87&v3_crld,
88&v3_ext_ku,
89&v3_crl_reason,
90&v3_sxnet,
91&v3_info,
92};
93
94/* Number of standard extensions */
95
96#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
97
diff --git a/src/lib/libssl/src/crypto/x509v3/tabtest.c b/src/lib/libssl/src/crypto/x509v3/tabtest.c
new file mode 100644
index 0000000000..dad0d38dd5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/tabtest.c
@@ -0,0 +1,88 @@
1/* tabtest.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple program to check the ext_dat.h is correct and print out
60 * problems if it is not.
61 */
62
63#include <stdio.h>
64
65#include <openssl/x509v3.h>
66
67#include "ext_dat.h"
68
69main()
70{
71 int i, prev = -1, bad = 0;
72 X509V3_EXT_METHOD **tmp;
73 i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
74 if(i != STANDARD_EXTENSION_COUNT)
75 fprintf(stderr, "Extension number invalid expecting %d\n", i);
76 tmp = standard_exts;
77 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
78 if((*tmp)->ext_nid < prev) bad = 1;
79 prev = (*tmp)->ext_nid;
80
81 }
82 if(bad) {
83 tmp = standard_exts;
84 fprintf(stderr, "Extensions out of order!\n");
85 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
86 printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
87 } else fprintf(stderr, "Order OK\n");
88}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_akey.c b/src/lib/libssl/src/crypto/x509v3/v3_akey.c
new file mode 100644
index 0000000000..4099e6019e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_akey.c
@@ -0,0 +1,249 @@
1/* v3_akey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
67 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist);
68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
70
71X509V3_EXT_METHOD v3_akey_id = {
72NID_authority_key_identifier, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)AUTHORITY_KEYID_new,
74(X509V3_EXT_FREE)AUTHORITY_KEYID_free,
75(X509V3_EXT_D2I)d2i_AUTHORITY_KEYID,
76(X509V3_EXT_I2D)i2d_AUTHORITY_KEYID,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
79(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
80NULL,NULL,
81NULL
82};
83
84
85int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp)
86{
87 M_ASN1_I2D_vars(a);
88
89 M_ASN1_I2D_len_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING);
90 M_ASN1_I2D_len_IMP_opt (a->issuer, i2d_GENERAL_NAMES);
91 M_ASN1_I2D_len_IMP_opt (a->serial, i2d_ASN1_INTEGER);
92
93 M_ASN1_I2D_seq_total();
94
95 M_ASN1_I2D_put_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING, 0);
96 M_ASN1_I2D_put_IMP_opt (a->issuer, i2d_GENERAL_NAMES, 1);
97 M_ASN1_I2D_put_IMP_opt (a->serial, i2d_ASN1_INTEGER, 2);
98
99 M_ASN1_I2D_finish();
100}
101
102AUTHORITY_KEYID *AUTHORITY_KEYID_new(void)
103{
104 AUTHORITY_KEYID *ret=NULL;
105 ASN1_CTX c;
106 M_ASN1_New_Malloc(ret, AUTHORITY_KEYID);
107 ret->keyid = NULL;
108 ret->issuer = NULL;
109 ret->serial = NULL;
110 return (ret);
111 M_ASN1_New_Error(ASN1_F_AUTHORITY_KEYID_NEW);
112}
113
114AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp,
115 long length)
116{
117 M_ASN1_D2I_vars(a,AUTHORITY_KEYID *,AUTHORITY_KEYID_new);
118 M_ASN1_D2I_Init();
119 M_ASN1_D2I_start_sequence();
120 M_ASN1_D2I_get_IMP_opt (ret->keyid, d2i_ASN1_OCTET_STRING, 0,
121 V_ASN1_OCTET_STRING);
122 M_ASN1_D2I_get_IMP_opt (ret->issuer, d2i_GENERAL_NAMES, 1,
123 V_ASN1_SEQUENCE);
124 M_ASN1_D2I_get_IMP_opt (ret->serial, d2i_ASN1_INTEGER, 2,
125 V_ASN1_INTEGER);
126 M_ASN1_D2I_Finish(a, AUTHORITY_KEYID_free, ASN1_F_D2I_AUTHORITY_KEYID);
127}
128
129void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a)
130{
131 if (a == NULL) return;
132 ASN1_OCTET_STRING_free(a->keyid);
133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free);
134 ASN1_INTEGER_free (a->serial);
135 Free ((char *)a);
136}
137
138static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
139 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
140{
141 char *tmp;
142 if(akeyid->keyid) {
143 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
144 X509V3_add_value("keyid", tmp, &extlist);
145 Free(tmp);
146 }
147 if(akeyid->issuer)
148 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
149 if(akeyid->serial) {
150 tmp = hex_to_string(akeyid->serial->data,
151 akeyid->serial->length);
152 X509V3_add_value("serial", tmp, &extlist);
153 Free(tmp);
154 }
155 return extlist;
156}
157
158/* Currently two options:
159 * keyid: use the issuers subject keyid, the value 'always' means its is
160 * an error if the issuer certificate doesn't have a key id.
161 * issuer: use the issuers cert issuer and serial number. The default is
162 * to only use this if keyid is not present. With the option 'always'
163 * this is always included.
164 */
165
166static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
167 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
168{
169char keyid=0, issuer=0;
170int i;
171CONF_VALUE *cnf;
172ASN1_OCTET_STRING *ikeyid = NULL;
173X509_NAME *isname = NULL;
174STACK_OF(GENERAL_NAME) * gens = NULL;
175GENERAL_NAME *gen = NULL;
176ASN1_INTEGER *serial = NULL;
177X509_EXTENSION *ext;
178X509 *cert;
179AUTHORITY_KEYID *akeyid;
180for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
181 cnf = sk_CONF_VALUE_value(values, i);
182 if(!strcmp(cnf->name, "keyid")) {
183 keyid = 1;
184 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
185 } else if(!strcmp(cnf->name, "issuer")) {
186 issuer = 1;
187 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
188 } else {
189 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
190 ERR_add_error_data(2, "name=", cnf->name);
191 return NULL;
192 }
193}
194
195
196
197if(!ctx || !ctx->issuer_cert) {
198 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
199 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
200 return NULL;
201}
202
203cert = ctx->issuer_cert;
204
205if(keyid) {
206 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
207 if((i >= 0) && (ext = X509_get_ext(cert, i)))
208 ikeyid = X509V3_EXT_d2i(ext);
209 if(keyid==2 && !ikeyid) {
210 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
211 return NULL;
212 }
213}
214
215if((issuer && !ikeyid) || (issuer == 2)) {
216 isname = X509_NAME_dup(X509_get_issuer_name(cert));
217 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert));
218 if(!isname || !serial) {
219 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
220 goto err;
221 }
222}
223
224if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
225
226if(isname) {
227 if(!(gens = sk_GENERAL_NAME_new(NULL)) || !(gen = GENERAL_NAME_new())
228 || !sk_GENERAL_NAME_push(gens, gen)) {
229 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
230 goto err;
231 }
232 gen->type = GEN_DIRNAME;
233 gen->d.dirn = isname;
234}
235
236akeyid->issuer = gens;
237akeyid->serial = serial;
238akeyid->keyid = ikeyid;
239
240return akeyid;
241
242err:
243X509_NAME_free(isname);
244ASN1_INTEGER_free(serial);
245ASN1_OCTET_STRING_free(ikeyid);
246return NULL;
247
248}
249
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_akeya.c b/src/lib/libssl/src/crypto/x509v3/v3_akeya.c
new file mode 100644
index 0000000000..2aafa26ba7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_akeya.c
@@ -0,0 +1,72 @@
1/* v3_akey_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(AUTHORITY_KEYID) = {
67 ASN1_IMP_OPT(AUTHORITY_KEYID, keyid, ASN1_OCTET_STRING, 0),
68 ASN1_IMP_SEQUENCE_OF_OPT(AUTHORITY_KEYID, issuer, GENERAL_NAME, 1),
69 ASN1_IMP_OPT(AUTHORITY_KEYID, serial, ASN1_INTEGER, 2)
70} ASN1_SEQUENCE_END(AUTHORITY_KEYID)
71
72IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_KEYID)
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_alt.c b/src/lib/libssl/src/crypto/x509v3/v3_alt.c
new file mode 100644
index 0000000000..b5e1f8af96
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_alt.c
@@ -0,0 +1,402 @@
1/* v3_alt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
65static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
67static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
68X509V3_EXT_METHOD v3_alt[] = {
69{ NID_subject_alt_name, 0,
70(X509V3_EXT_NEW)GENERAL_NAMES_new,
71(X509V3_EXT_FREE)GENERAL_NAMES_free,
72(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
73(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
74NULL, NULL,
75(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
76(X509V3_EXT_V2I)v2i_subject_alt,
77NULL, NULL, NULL},
78{ NID_issuer_alt_name, 0,
79(X509V3_EXT_NEW)GENERAL_NAMES_new,
80(X509V3_EXT_FREE)GENERAL_NAMES_free,
81(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
82(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
83NULL, NULL,
84(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
85(X509V3_EXT_V2I)v2i_issuer_alt,
86NULL, NULL, NULL},
87EXT_END
88};
89
90STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
91 STACK_OF(GENERAL_NAME) *gens, STACK_OF(CONF_VALUE) *ret)
92{
93 int i;
94 GENERAL_NAME *gen;
95 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
96 gen = sk_GENERAL_NAME_value(gens, i);
97 ret = i2v_GENERAL_NAME(method, gen, ret);
98 }
99 if(!ret) return sk_CONF_VALUE_new_null();
100 return ret;
101}
102
103STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
104 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
105{
106 char oline[256];
107 unsigned char *p;
108 switch (gen->type)
109 {
110 case GEN_OTHERNAME:
111 X509V3_add_value("othername","<unsupported>", &ret);
112 break;
113
114 case GEN_X400:
115 X509V3_add_value("X400Name","<unsupported>", &ret);
116 break;
117
118 case GEN_EDIPARTY:
119 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
120 break;
121
122 case GEN_EMAIL:
123 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
124 break;
125
126 case GEN_DNS:
127 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
128 break;
129
130 case GEN_URI:
131 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
132 break;
133
134 case GEN_DIRNAME:
135 X509_NAME_oneline(gen->d.dirn, oline, 256);
136 X509V3_add_value("DirName",oline, &ret);
137 break;
138
139 case GEN_IPADD:
140 p = gen->d.ip->data;
141 /* BUG: doesn't support IPV6 */
142 if(gen->d.ip->length != 4) {
143 X509V3_add_value("IP Address","<invalid>", &ret);
144 break;
145 }
146 sprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
147 X509V3_add_value("IP Address",oline, &ret);
148 break;
149
150 case GEN_RID:
151 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
152 X509V3_add_value("Registered ID",oline, &ret);
153 break;
154 }
155 return ret;
156}
157
158static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method,
159 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
160{
161 STACK_OF(GENERAL_NAME) *gens = NULL;
162 CONF_VALUE *cnf;
163 int i;
164 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
165 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
166 return NULL;
167 }
168 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
169 cnf = sk_CONF_VALUE_value(nval, i);
170 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
171 !strcmp(cnf->value, "copy")) {
172 if(!copy_issuer(ctx, gens)) goto err;
173 } else {
174 GENERAL_NAME *gen;
175 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
176 goto err;
177 sk_GENERAL_NAME_push(gens, gen);
178 }
179 }
180 return gens;
181 err:
182 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
183 return NULL;
184}
185
186/* Append subject altname of issuer to issuer alt name of subject */
187
188static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
189{
190 STACK_OF(GENERAL_NAME) *ialt;
191 GENERAL_NAME *gen;
192 X509_EXTENSION *ext;
193 int i;
194 if(ctx && (ctx->flags == CTX_TEST)) return 1;
195 if(!ctx || !ctx->issuer_cert) {
196 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
197 goto err;
198 }
199 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
200 if(i < 0) return 1;
201 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
202 !(ialt = X509V3_EXT_d2i(ext)) ) {
203 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
204 goto err;
205 }
206
207 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
208 gen = sk_GENERAL_NAME_value(ialt, i);
209 if(!sk_GENERAL_NAME_push(gens, gen)) {
210 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
211 goto err;
212 }
213 }
214 sk_GENERAL_NAME_free(ialt);
215
216 return 1;
217
218 err:
219 return 0;
220
221}
222
223static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method,
224 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
225{
226 STACK_OF(GENERAL_NAME) *gens = NULL;
227 CONF_VALUE *cnf;
228 int i;
229 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
230 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
231 return NULL;
232 }
233 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
234 cnf = sk_CONF_VALUE_value(nval, i);
235 if(!name_cmp(cnf->name, "email") && cnf->value &&
236 !strcmp(cnf->value, "copy")) {
237 if(!copy_email(ctx, gens)) goto err;
238 } else {
239 GENERAL_NAME *gen;
240 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
241 goto err;
242 sk_GENERAL_NAME_push(gens, gen);
243 }
244 }
245 return gens;
246 err:
247 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
248 return NULL;
249}
250
251/* Copy any email addresses in a certificate or request to
252 * GENERAL_NAMES
253 */
254
255static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
256{
257 X509_NAME *nm;
258 ASN1_IA5STRING *email = NULL;
259 X509_NAME_ENTRY *ne;
260 GENERAL_NAME *gen = NULL;
261 int i;
262 if(ctx->flags == CTX_TEST) return 1;
263 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
264 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
265 goto err;
266 }
267 /* Find the subject name */
268 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
269 else nm = X509_REQ_get_subject_name(ctx->subject_req);
270
271 /* Now add any email address(es) to STACK */
272 i = -1;
273 while((i = X509_NAME_get_index_by_NID(nm,
274 NID_pkcs9_emailAddress, i)) > 0) {
275 ne = X509_NAME_get_entry(nm, i);
276 email = ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
277 if(!email || !(gen = GENERAL_NAME_new())) {
278 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
279 goto err;
280 }
281 gen->d.ia5 = email;
282 email = NULL;
283 gen->type = GEN_EMAIL;
284 if(!sk_GENERAL_NAME_push(gens, gen)) {
285 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
286 goto err;
287 }
288 gen = NULL;
289 }
290
291
292 return 1;
293
294 err:
295 GENERAL_NAME_free(gen);
296 ASN1_IA5STRING_free(email);
297 return 0;
298
299}
300
301STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
302 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
303{
304 GENERAL_NAME *gen;
305 STACK_OF(GENERAL_NAME) *gens = NULL;
306 CONF_VALUE *cnf;
307 int i;
308 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
309 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
310 return NULL;
311 }
312 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
313 cnf = sk_CONF_VALUE_value(nval, i);
314 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
315 sk_GENERAL_NAME_push(gens, gen);
316 }
317 return gens;
318 err:
319 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
320 return NULL;
321}
322
323GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
324 CONF_VALUE *cnf)
325{
326char is_string = 0;
327int type;
328GENERAL_NAME *gen = NULL;
329
330char *name, *value;
331
332name = cnf->name;
333value = cnf->value;
334
335if(!value) {
336 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
337 return NULL;
338}
339
340if(!(gen = GENERAL_NAME_new())) {
341 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
342 return NULL;
343}
344
345if(!name_cmp(name, "email")) {
346 is_string = 1;
347 type = GEN_EMAIL;
348} else if(!name_cmp(name, "URI")) {
349 is_string = 1;
350 type = GEN_URI;
351} else if(!name_cmp(name, "DNS")) {
352 is_string = 1;
353 type = GEN_DNS;
354} else if(!name_cmp(name, "RID")) {
355 ASN1_OBJECT *obj;
356 if(!(obj = OBJ_txt2obj(value,0))) {
357 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
358 ERR_add_error_data(2, "value=", value);
359 goto err;
360 }
361 gen->d.rid = obj;
362 type = GEN_RID;
363} else if(!name_cmp(name, "IP")) {
364 int i1,i2,i3,i4;
365 unsigned char ip[4];
366 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
367 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
368 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
369 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
370 ERR_add_error_data(2, "value=", value);
371 goto err;
372 }
373 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
374 if(!(gen->d.ip = ASN1_OCTET_STRING_new()) ||
375 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
376 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
377 goto err;
378 }
379 type = GEN_IPADD;
380} else {
381 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
382 ERR_add_error_data(2, "name=", name);
383 goto err;
384}
385
386if(is_string) {
387 if(!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
388 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
389 strlen(value))) {
390 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
391 goto err;
392 }
393}
394
395gen->type = type;
396
397return gen;
398
399err:
400GENERAL_NAME_free(gen);
401return NULL;
402}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_bcons.c b/src/lib/libssl/src/crypto/x509v3/v3_bcons.c
new file mode 100644
index 0000000000..de2f855c35
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_bcons.c
@@ -0,0 +1,164 @@
1/* v3_bcons.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist);
68static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
69
70X509V3_EXT_METHOD v3_bcons = {
71NID_basic_constraints, 0,
72(X509V3_EXT_NEW)BASIC_CONSTRAINTS_new,
73(X509V3_EXT_FREE)BASIC_CONSTRAINTS_free,
74(X509V3_EXT_D2I)d2i_BASIC_CONSTRAINTS,
75(X509V3_EXT_I2D)i2d_BASIC_CONSTRAINTS,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS,
78(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
79NULL,NULL,
80NULL
81};
82
83
84int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp)
85{
86 M_ASN1_I2D_vars(a);
87 if(a->ca) M_ASN1_I2D_len (a->ca, i2d_ASN1_BOOLEAN);
88 M_ASN1_I2D_len (a->pathlen, i2d_ASN1_INTEGER);
89
90 M_ASN1_I2D_seq_total();
91
92 if (a->ca) M_ASN1_I2D_put (a->ca, i2d_ASN1_BOOLEAN);
93 M_ASN1_I2D_put (a->pathlen, i2d_ASN1_INTEGER);
94 M_ASN1_I2D_finish();
95}
96
97BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void)
98{
99 BASIC_CONSTRAINTS *ret=NULL;
100 ASN1_CTX c;
101 M_ASN1_New_Malloc(ret, BASIC_CONSTRAINTS);
102 ret->ca = 0;
103 ret->pathlen = NULL;
104 return (ret);
105 M_ASN1_New_Error(ASN1_F_BASIC_CONSTRAINTS_NEW);
106}
107
108BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a,
109 unsigned char **pp, long length)
110{
111 M_ASN1_D2I_vars(a,BASIC_CONSTRAINTS *,BASIC_CONSTRAINTS_new);
112 M_ASN1_D2I_Init();
113 M_ASN1_D2I_start_sequence();
114 if((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) ==
115 (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN) ) {
116 M_ASN1_D2I_get_int (ret->ca, d2i_ASN1_BOOLEAN);
117 }
118 M_ASN1_D2I_get_opt (ret->pathlen, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
119 M_ASN1_D2I_Finish(a, BASIC_CONSTRAINTS_free, ASN1_F_D2I_BASIC_CONSTRAINTS);
120}
121
122void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a)
123{
124 if (a == NULL) return;
125 ASN1_INTEGER_free (a->pathlen);
126 Free ((char *)a);
127}
128
129static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
130 BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist)
131{
132 X509V3_add_value_bool("CA", bcons->ca, &extlist);
133 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
134 return extlist;
135}
136
137static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
138 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
139{
140 BASIC_CONSTRAINTS *bcons=NULL;
141 CONF_VALUE *val;
142 int i;
143 if(!(bcons = BASIC_CONSTRAINTS_new())) {
144 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147 for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
148 val = sk_CONF_VALUE_value(values, i);
149 if(!strcmp(val->name, "CA")) {
150 if(!X509V3_get_value_bool(val, &bcons->ca)) goto err;
151 } else if(!strcmp(val->name, "pathlen")) {
152 if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err;
153 } else {
154 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
155 X509V3_conf_err(val);
156 goto err;
157 }
158 }
159 return bcons;
160 err:
161 BASIC_CONSTRAINTS_free(bcons);
162 return NULL;
163}
164
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_bitst.c b/src/lib/libssl/src/crypto/x509v3/v3_bitst.c
new file mode 100644
index 0000000000..9828ba15b3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_bitst.c
@@ -0,0 +1,147 @@
1/* v3_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static ASN1_BIT_STRING *asn1_bit_string_new(void);
65static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
67static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
68 ASN1_BIT_STRING *bits,
69 STACK_OF(CONF_VALUE) *extlist);
70static BIT_STRING_BITNAME ns_cert_type_table[] = {
71{0, "SSL Client", "client"},
72{1, "SSL Server", "server"},
73{2, "S/MIME", "email"},
74{3, "Object Signing", "objsign"},
75{4, "Unused", "reserved"},
76{5, "SSL CA", "sslCA"},
77{6, "S/MIME CA", "emailCA"},
78{7, "Object Signing CA", "objCA"},
79{-1, NULL, NULL}
80};
81
82static BIT_STRING_BITNAME key_usage_type_table[] = {
83{0, "Digital Signature", "digitalSignature"},
84{1, "Non Repudiation", "nonRepudiation"},
85{2, "Key Encipherment", "keyEncipherment"},
86{3, "Data Encipherment", "dataEncipherment"},
87{4, "Key Agreement", "keyAgreement"},
88{5, "Certificate Sign", "keyCertSign"},
89{6, "CRL Sign", "cRLSign"},
90{7, "Encipher Only", "encipherOnly"},
91{8, "Decipher Only", "decipherOnly"},
92{-1, NULL, NULL}
93};
94
95
96
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99
100static ASN1_BIT_STRING *asn1_bit_string_new(void)
101{
102 return ASN1_BIT_STRING_new();
103}
104
105static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
106 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
107{
108 BIT_STRING_BITNAME *bnam;
109 for(bnam =method->usr_data; bnam->lname; bnam++) {
110 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
111 X509V3_add_value(bnam->lname, NULL, &ret);
112 }
113 return ret;
114}
115
116static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
117 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
118{
119 CONF_VALUE *val;
120 ASN1_BIT_STRING *bs;
121 int i;
122 BIT_STRING_BITNAME *bnam;
123 if(!(bs = ASN1_BIT_STRING_new())) {
124 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
125 return NULL;
126 }
127 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
128 val = sk_CONF_VALUE_value(nval, i);
129 for(bnam = method->usr_data; bnam->lname; bnam++) {
130 if(!strcmp(bnam->sname, val->name) ||
131 !strcmp(bnam->lname, val->name) ) {
132 ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1);
133 break;
134 }
135 }
136 if(!bnam->lname) {
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val);
140 ASN1_BIT_STRING_free(bs);
141 return NULL;
142 }
143 }
144 return bs;
145}
146
147
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_conf.c b/src/lib/libssl/src/crypto/x509v3/v3_conf.c
new file mode 100644
index 0000000000..f19bb3ad84
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_conf.c
@@ -0,0 +1,366 @@
1/* v3_conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* extension creation utilities */
59
60
61
62#include <stdio.h>
63#include <ctype.h>
64#include "cryptlib.h"
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69static int v3_check_critical(char **value);
70static int v3_check_generic(char **value);
71static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
72static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type);
73static char *conf_lhash_get_string(void *db, char *section, char *value);
74static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
75static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
76 int crit, void *ext_struc);
77/* LHASH *conf: Config file */
78/* char *name: Name */
79/* char *value: Value */
80X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
81 char *value)
82{
83 int crit;
84 int ext_type;
85 X509_EXTENSION *ret;
86 crit = v3_check_critical(&value);
87 if((ext_type = v3_check_generic(&value)))
88 return v3_generic_extension(name, value, crit, ext_type);
89 ret = do_ext_conf(conf, ctx, OBJ_sn2nid(name), crit, value);
90 if(!ret) {
91 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
92 ERR_add_error_data(4,"name=", name, ", value=", value);
93 }
94 return ret;
95}
96
97/* LHASH *conf: Config file */
98/* char *value: Value */
99X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
100 char *value)
101{
102 int crit;
103 int ext_type;
104 crit = v3_check_critical(&value);
105 if((ext_type = v3_check_generic(&value)))
106 return v3_generic_extension(OBJ_nid2sn(ext_nid),
107 value, crit, ext_type);
108 return do_ext_conf(conf, ctx, ext_nid, crit, value);
109}
110
111/* LHASH *conf: Config file */
112/* char *value: Value */
113static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
114 int crit, char *value)
115{
116 X509V3_EXT_METHOD *method;
117 X509_EXTENSION *ext;
118 STACK_OF(CONF_VALUE) *nval;
119 void *ext_struc;
120 if(ext_nid == NID_undef) {
121 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
122 return NULL;
123 }
124 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
125 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
126 return NULL;
127 }
128 /* Now get internal extension representation based on type */
129 if(method->v2i) {
130 if(*value == '@') nval = CONF_get_section(conf, value + 1);
131 else nval = X509V3_parse_list(value);
132 if(!nval) {
133 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
134 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
135 return NULL;
136 }
137 ext_struc = method->v2i(method, ctx, nval);
138 if(*value != '@') sk_CONF_VALUE_pop_free(nval,
139 X509V3_conf_free);
140 if(!ext_struc) return NULL;
141 } else if(method->s2i) {
142 if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
143 } else if(method->r2i) {
144 if(!ctx->db) {
145 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
146 return NULL;
147 }
148 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
149 } else {
150 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
151 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
152 return NULL;
153 }
154
155 ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
156 method->ext_free(ext_struc);
157 return ext;
158
159}
160
161static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
162 int crit, void *ext_struc)
163{
164 unsigned char *ext_der, *p;
165 int ext_len;
166 ASN1_OCTET_STRING *ext_oct;
167 X509_EXTENSION *ext;
168 /* Convert internal representation to DER */
169 ext_len = method->i2d(ext_struc, NULL);
170 if(!(ext_der = Malloc(ext_len))) goto merr;
171 p = ext_der;
172 method->i2d(ext_struc, &p);
173 if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr;
174 ext_oct->data = ext_der;
175 ext_oct->length = ext_len;
176
177 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
178 if(!ext) goto merr;
179 ASN1_OCTET_STRING_free(ext_oct);
180
181 return ext;
182
183 merr:
184 X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
185 return NULL;
186
187}
188
189/* Given an internal structure, nid and critical flag create an extension */
190
191X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
192{
193 X509V3_EXT_METHOD *method;
194 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
195 X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
196 return NULL;
197 }
198 return do_ext_i2d(method, ext_nid, crit, ext_struc);
199}
200
201/* Check the extension string for critical flag */
202static int v3_check_critical(char **value)
203{
204 char *p = *value;
205 if((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
206 p+=9;
207 while(isspace((unsigned char)*p)) p++;
208 *value = p;
209 return 1;
210}
211
212/* Check extension string for generic extension and return the type */
213static int v3_check_generic(char **value)
214{
215 char *p = *value;
216 if((strlen(p) < 4) || strncmp(p, "DER:,", 4)) return 0;
217 p+=4;
218 while(isspace((unsigned char)*p)) p++;
219 *value = p;
220 return 1;
221}
222
223/* Create a generic extension: for now just handle RAW type */
224static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
225 int crit, int type)
226{
227unsigned char *ext_der=NULL;
228long ext_len;
229ASN1_OBJECT *obj=NULL;
230ASN1_OCTET_STRING *oct=NULL;
231X509_EXTENSION *extension=NULL;
232if(!(obj = OBJ_txt2obj(ext, 0))) {
233 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
234 ERR_add_error_data(2, "name=", ext);
235 goto err;
236}
237
238if(!(ext_der = string_to_hex(value, &ext_len))) {
239 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
240 ERR_add_error_data(2, "value=", value);
241 goto err;
242}
243
244if(!(oct = ASN1_OCTET_STRING_new())) {
245 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
246 goto err;
247}
248
249oct->data = ext_der;
250oct->length = ext_len;
251ext_der = NULL;
252
253extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
254
255err:
256ASN1_OBJECT_free(obj);
257ASN1_OCTET_STRING_free(oct);
258if(ext_der) Free(ext_der);
259return extension;
260}
261
262
263/* This is the main function: add a bunch of extensions based on a config file
264 * section
265 */
266
267int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
268 X509 *cert)
269{
270 X509_EXTENSION *ext;
271 STACK_OF(CONF_VALUE) *nval;
272 CONF_VALUE *val;
273 int i;
274 if(!(nval = CONF_get_section(conf, section))) return 0;
275 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
276 val = sk_CONF_VALUE_value(nval, i);
277 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
278 return 0;
279 if(cert) X509_add_ext(cert, ext, -1);
280 X509_EXTENSION_free(ext);
281 }
282 return 1;
283}
284
285/* Same as above but for a CRL */
286
287int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
288 X509_CRL *crl)
289{
290 X509_EXTENSION *ext;
291 STACK_OF(CONF_VALUE) *nval;
292 CONF_VALUE *val;
293 int i;
294 if(!(nval = CONF_get_section(conf, section))) return 0;
295 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
296 val = sk_CONF_VALUE_value(nval, i);
297 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
298 return 0;
299 if(crl) X509_CRL_add_ext(crl, ext, -1);
300 X509_EXTENSION_free(ext);
301 }
302 return 1;
303}
304
305/* Config database functions */
306
307char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
308{
309 if(ctx->db_meth->get_string)
310 return ctx->db_meth->get_string(ctx->db, name, section);
311 return NULL;
312}
313
314STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
315{
316 if(ctx->db_meth->get_section)
317 return ctx->db_meth->get_section(ctx->db, section);
318 return NULL;
319}
320
321void X509V3_string_free(X509V3_CTX *ctx, char *str)
322{
323 if(!str) return;
324 if(ctx->db_meth->free_string)
325 ctx->db_meth->free_string(ctx->db, str);
326}
327
328void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
329{
330 if(!section) return;
331 if(ctx->db_meth->free_section)
332 ctx->db_meth->free_section(ctx->db, section);
333}
334
335static char *conf_lhash_get_string(void *db, char *section, char *value)
336{
337 return CONF_get_string(db, section, value);
338}
339
340static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
341{
342 return CONF_get_section(db, section);
343}
344
345static X509V3_CONF_METHOD conf_lhash_method = {
346conf_lhash_get_string,
347conf_lhash_get_section,
348NULL,
349NULL
350};
351
352void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
353{
354 ctx->db_meth = &conf_lhash_method;
355 ctx->db = lhash;
356}
357
358void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
359 X509_CRL *crl, int flags)
360{
361 ctx->issuer_cert = issuer;
362 ctx->subject_cert = subj;
363 ctx->crl = crl;
364 ctx->subject_req = req;
365 ctx->flags = flags;
366}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_cpols.c b/src/lib/libssl/src/crypto/x509v3/v3_cpols.c
new file mode 100644
index 0000000000..b4d4883545
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_cpols.c
@@ -0,0 +1,655 @@
1/* v3_cpols.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Certificate policies extension support: this one is a bit complex... */
67
68static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
69static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
70static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
71static void print_notice(BIO *out, USERNOTICE *notice, int indent);
72static POLICYINFO *policy_section(X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *polstrs, int ia5org);
74static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
75 STACK_OF(CONF_VALUE) *unot, int ia5org);
76static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos);
77
78X509V3_EXT_METHOD v3_cpols = {
79NID_certificate_policies, 0,
80(X509V3_EXT_NEW)CERTIFICATEPOLICIES_new,
81(X509V3_EXT_FREE)CERTIFICATEPOLICIES_free,
82(X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES,
83(X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES,
84NULL, NULL,
85NULL, NULL,
86(X509V3_EXT_I2R)i2r_certpol,
87(X509V3_EXT_R2I)r2i_certpol,
88NULL
89};
90
91
92static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
93 X509V3_CTX *ctx, char *value)
94{
95 STACK_OF(POLICYINFO) *pols = NULL;
96 char *pstr;
97 POLICYINFO *pol;
98 ASN1_OBJECT *pobj;
99 STACK_OF(CONF_VALUE) *vals;
100 CONF_VALUE *cnf;
101 int i, ia5org;
102 pols = sk_POLICYINFO_new_null();
103 vals = X509V3_parse_list(value);
104 ia5org = 0;
105 for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
106 cnf = sk_CONF_VALUE_value(vals, i);
107 if(cnf->value || !cnf->name ) {
108 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
109 X509V3_conf_err(cnf);
110 goto err;
111 }
112 pstr = cnf->name;
113 if(!strcmp(pstr,"ia5org")) {
114 ia5org = 1;
115 continue;
116 } else if(*pstr == '@') {
117 STACK_OF(CONF_VALUE) *polsect;
118 polsect = X509V3_get_section(ctx, pstr + 1);
119 if(!polsect) {
120 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
121
122 X509V3_conf_err(cnf);
123 goto err;
124 }
125 pol = policy_section(ctx, polsect, ia5org);
126 X509V3_section_free(ctx, polsect);
127 if(!pol) goto err;
128 } else {
129 if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
130 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
131 X509V3_conf_err(cnf);
132 goto err;
133 }
134 pol = POLICYINFO_new();
135 pol->policyid = pobj;
136 }
137 sk_POLICYINFO_push(pols, pol);
138 }
139 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
140 return pols;
141 err:
142 sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
143 return NULL;
144}
145
146static POLICYINFO *policy_section(X509V3_CTX *ctx,
147 STACK_OF(CONF_VALUE) *polstrs, int ia5org)
148{
149 int i;
150 CONF_VALUE *cnf;
151 POLICYINFO *pol;
152 POLICYQUALINFO *qual;
153 if(!(pol = POLICYINFO_new())) goto merr;
154 for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
155 cnf = sk_CONF_VALUE_value(polstrs, i);
156 if(!strcmp(cnf->name, "policyIdentifier")) {
157 ASN1_OBJECT *pobj;
158 if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
159 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
160 X509V3_conf_err(cnf);
161 goto err;
162 }
163 pol->policyid = pobj;
164
165 } else if(!name_cmp(cnf->name, "CPS")) {
166 if(!pol->qualifiers) pol->qualifiers =
167 sk_POLICYQUALINFO_new_null();
168 if(!(qual = POLICYQUALINFO_new())) goto merr;
169 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
170 goto merr;
171 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
172 qual->d.cpsuri = ASN1_IA5STRING_new();
173 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
174 strlen(cnf->value))) goto merr;
175 } else if(!name_cmp(cnf->name, "userNotice")) {
176 STACK_OF(CONF_VALUE) *unot;
177 if(*cnf->value != '@') {
178 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
179 X509V3_conf_err(cnf);
180 goto err;
181 }
182 unot = X509V3_get_section(ctx, cnf->value + 1);
183 if(!unot) {
184 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
185
186 X509V3_conf_err(cnf);
187 goto err;
188 }
189 qual = notice_section(ctx, unot, ia5org);
190 X509V3_section_free(ctx, unot);
191 if(!qual) goto err;
192 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
193 goto merr;
194 } else {
195 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
196
197 X509V3_conf_err(cnf);
198 goto err;
199 }
200 }
201 if(!pol->policyid) {
202 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
203 goto err;
204 }
205
206 return pol;
207
208 merr:
209 X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
210
211 err:
212 POLICYINFO_free(pol);
213 return NULL;
214
215
216}
217
218static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
219 STACK_OF(CONF_VALUE) *unot, int ia5org)
220{
221 int i;
222 CONF_VALUE *cnf;
223 USERNOTICE *not;
224 POLICYQUALINFO *qual;
225 if(!(qual = POLICYQUALINFO_new())) goto merr;
226 qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
227 if(!(not = USERNOTICE_new())) goto merr;
228 qual->d.usernotice = not;
229 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
230 cnf = sk_CONF_VALUE_value(unot, i);
231 if(!strcmp(cnf->name, "explicitText")) {
232 not->exptext = ASN1_VISIBLESTRING_new();
233 if(!ASN1_STRING_set(not->exptext, cnf->value,
234 strlen(cnf->value))) goto merr;
235 } else if(!strcmp(cnf->name, "organization")) {
236 NOTICEREF *nref;
237 if(!not->noticeref) {
238 if(!(nref = NOTICEREF_new())) goto merr;
239 not->noticeref = nref;
240 } else nref = not->noticeref;
241 if(ia5org) nref->organization = ASN1_IA5STRING_new();
242 else nref->organization = ASN1_VISIBLESTRING_new();
243 if(!ASN1_STRING_set(nref->organization, cnf->value,
244 strlen(cnf->value))) goto merr;
245 } else if(!strcmp(cnf->name, "noticeNumbers")) {
246 NOTICEREF *nref;
247 STACK_OF(CONF_VALUE) *nos;
248 if(!not->noticeref) {
249 if(!(nref = NOTICEREF_new())) goto merr;
250 not->noticeref = nref;
251 } else nref = not->noticeref;
252 nos = X509V3_parse_list(cnf->value);
253 if(!nos || !sk_CONF_VALUE_num(nos)) {
254 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
255 X509V3_conf_err(cnf);
256 goto err;
257 }
258 nref->noticenos = nref_nos(nos);
259 sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
260 if(!nref->noticenos) goto err;
261 } else {
262 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
263
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268
269 if(not->noticeref &&
270 (!not->noticeref->noticenos || !not->noticeref->organization)) {
271 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
272 goto err;
273 }
274
275 return qual;
276
277 merr:
278 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
279
280 err:
281 POLICYQUALINFO_free(qual);
282 return NULL;
283}
284
285static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos)
286{
287 STACK *nnums;
288 CONF_VALUE *cnf;
289 ASN1_INTEGER *aint;
290 int i;
291 if(!(nnums = sk_new_null())) goto merr;
292 for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
293 cnf = sk_CONF_VALUE_value(nos, i);
294 if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
295 X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
296 goto err;
297 }
298 if(!sk_push(nnums, (char *)aint)) goto merr;
299 }
300 return nnums;
301
302 merr:
303 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
304
305 err:
306 sk_pop_free(nnums, ASN1_STRING_free);
307 return NULL;
308}
309
310
311static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
312 BIO *out, int indent)
313{
314 int i;
315 POLICYINFO *pinfo;
316 /* First print out the policy OIDs */
317 for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
318 pinfo = sk_POLICYINFO_value(pol, i);
319 BIO_printf(out, "%*sPolicy: ", indent, "");
320 i2a_ASN1_OBJECT(out, pinfo->policyid);
321 BIO_puts(out, "\n");
322 if(pinfo->qualifiers)
323 print_qualifiers(out, pinfo->qualifiers, indent + 2);
324 }
325 return 1;
326}
327
328
329int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp)
330{
331
332return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE,
333 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
334
335STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void)
336{
337 return sk_POLICYINFO_new_null();
338}
339
340void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a)
341{
342 sk_POLICYINFO_pop_free(a, POLICYINFO_free);
343}
344
345STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a,
346 unsigned char **pp,long length)
347{
348return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO,
349 POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
350
351}
352
353IMPLEMENT_STACK_OF(POLICYINFO)
354IMPLEMENT_ASN1_SET_OF(POLICYINFO)
355
356int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp)
357{
358 M_ASN1_I2D_vars(a);
359
360 M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT);
361 M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
362 i2d_POLICYQUALINFO);
363
364 M_ASN1_I2D_seq_total();
365
366 M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT);
367 M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
368 i2d_POLICYQUALINFO);
369
370 M_ASN1_I2D_finish();
371}
372
373POLICYINFO *POLICYINFO_new(void)
374{
375 POLICYINFO *ret=NULL;
376 ASN1_CTX c;
377 M_ASN1_New_Malloc(ret, POLICYINFO);
378 ret->policyid = NULL;
379 ret->qualifiers = NULL;
380 return (ret);
381 M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW);
382}
383
384POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length)
385{
386 M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new);
387 M_ASN1_D2I_Init();
388 M_ASN1_D2I_start_sequence();
389 M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT);
390 if(!M_ASN1_D2I_end_sequence()) {
391 M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers,
392 d2i_POLICYQUALINFO, POLICYQUALINFO_free);
393 }
394 M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO);
395}
396
397void POLICYINFO_free(POLICYINFO *a)
398{
399 if (a == NULL) return;
400 ASN1_OBJECT_free(a->policyid);
401 sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free);
402 Free (a);
403}
404
405static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
406 int indent)
407{
408 POLICYQUALINFO *qualinfo;
409 int i;
410 for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
411 qualinfo = sk_POLICYQUALINFO_value(quals, i);
412 switch(OBJ_obj2nid(qualinfo->pqualid))
413 {
414 case NID_id_qt_cps:
415 BIO_printf(out, "%*sCPS: %s\n", indent, "",
416 qualinfo->d.cpsuri->data);
417 break;
418
419 case NID_id_qt_unotice:
420 BIO_printf(out, "%*sUser Notice:\n", indent, "");
421 print_notice(out, qualinfo->d.usernotice, indent + 2);
422 break;
423
424 default:
425 BIO_printf(out, "%*sUnknown Qualifier: ",
426 indent + 2, "");
427
428 i2a_ASN1_OBJECT(out, qualinfo->pqualid);
429 BIO_puts(out, "\n");
430 break;
431 }
432 }
433}
434
435static void print_notice(BIO *out, USERNOTICE *notice, int indent)
436{
437 int i;
438 if(notice->noticeref) {
439 NOTICEREF *ref;
440 ref = notice->noticeref;
441 BIO_printf(out, "%*sOrganization: %s\n", indent, "",
442 ref->organization->data);
443 BIO_printf(out, "%*sNumber%s: ", indent, "",
444 (sk_num(ref->noticenos) > 1) ? "s" : "");
445 for(i = 0; i < sk_num(ref->noticenos); i++) {
446 ASN1_INTEGER *num;
447 char *tmp;
448 num = (ASN1_INTEGER *)sk_value(ref->noticenos, i);
449 if(i) BIO_puts(out, ", ");
450 tmp = i2s_ASN1_INTEGER(NULL, num);
451 BIO_puts(out, tmp);
452 Free(tmp);
453 }
454 BIO_puts(out, "\n");
455 }
456 if(notice->exptext)
457 BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
458 notice->exptext->data);
459}
460
461
462
463int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp)
464{
465 M_ASN1_I2D_vars(a);
466
467 M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT);
468 switch(OBJ_obj2nid(a->pqualid)) {
469 case NID_id_qt_cps:
470 M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING);
471 break;
472
473 case NID_id_qt_unotice:
474 M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE);
475 break;
476
477 default:
478 M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE);
479 break;
480 }
481
482 M_ASN1_I2D_seq_total();
483
484 M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT);
485 switch(OBJ_obj2nid(a->pqualid)) {
486 case NID_id_qt_cps:
487 M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING);
488 break;
489
490 case NID_id_qt_unotice:
491 M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE);
492 break;
493
494 default:
495 M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE);
496 break;
497 }
498
499 M_ASN1_I2D_finish();
500}
501
502POLICYQUALINFO *POLICYQUALINFO_new(void)
503{
504 POLICYQUALINFO *ret=NULL;
505 ASN1_CTX c;
506 M_ASN1_New_Malloc(ret, POLICYQUALINFO);
507 ret->pqualid = NULL;
508 ret->d.other = NULL;
509 return (ret);
510 M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW);
511}
512
513POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
514 long length)
515{
516 M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new);
517 M_ASN1_D2I_Init();
518 M_ASN1_D2I_start_sequence();
519 M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT);
520 switch(OBJ_obj2nid(ret->pqualid)) {
521 case NID_id_qt_cps:
522 M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING);
523 break;
524
525 case NID_id_qt_unotice:
526 M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE);
527 break;
528
529 default:
530 M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE);
531 break;
532 }
533 M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO);
534}
535
536void POLICYQUALINFO_free(POLICYQUALINFO *a)
537{
538 if (a == NULL) return;
539 switch(OBJ_obj2nid(a->pqualid)) {
540 case NID_id_qt_cps:
541 ASN1_IA5STRING_free(a->d.cpsuri);
542 break;
543
544 case NID_id_qt_unotice:
545 USERNOTICE_free(a->d.usernotice);
546 break;
547
548 default:
549 ASN1_TYPE_free(a->d.other);
550 break;
551 }
552
553 ASN1_OBJECT_free(a->pqualid);
554 Free (a);
555}
556
557int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp)
558{
559 M_ASN1_I2D_vars(a);
560
561 M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF);
562 M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT);
563
564 M_ASN1_I2D_seq_total();
565
566 M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF);
567 M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT);
568
569 M_ASN1_I2D_finish();
570}
571
572USERNOTICE *USERNOTICE_new(void)
573{
574 USERNOTICE *ret=NULL;
575 ASN1_CTX c;
576 M_ASN1_New_Malloc(ret, USERNOTICE);
577 ret->noticeref = NULL;
578 ret->exptext = NULL;
579 return (ret);
580 M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW);
581}
582
583USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length)
584{
585 M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new);
586 M_ASN1_D2I_Init();
587 M_ASN1_D2I_start_sequence();
588 M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE);
589 if (!M_ASN1_D2I_end_sequence()) {
590 M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT);
591 }
592 M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE);
593}
594
595void USERNOTICE_free(USERNOTICE *a)
596{
597 if (a == NULL) return;
598 NOTICEREF_free(a->noticeref);
599 DISPLAYTEXT_free(a->exptext);
600 Free (a);
601}
602
603int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp)
604{
605 M_ASN1_I2D_vars(a);
606
607 M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT);
608 M_ASN1_I2D_len_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
609
610 M_ASN1_I2D_seq_total();
611
612 M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT);
613 M_ASN1_I2D_put_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
614
615 M_ASN1_I2D_finish();
616}
617
618NOTICEREF *NOTICEREF_new(void)
619{
620 NOTICEREF *ret=NULL;
621 ASN1_CTX c;
622 M_ASN1_New_Malloc(ret, NOTICEREF);
623 ret->organization = NULL;
624 ret->noticenos = NULL;
625 return (ret);
626 M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW);
627}
628
629NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length)
630{
631 M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new);
632 M_ASN1_D2I_Init();
633 M_ASN1_D2I_start_sequence();
634 /* This is to cope with some broken encodings that use IA5STRING for
635 * the organization field
636 */
637 M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING,
638 V_ASN1_IA5STRING);
639 if(!ret->organization) {
640 M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT);
641 }
642 M_ASN1_D2I_get_seq(ret->noticenos, d2i_ASN1_INTEGER, ASN1_STRING_free);
643 M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF);
644}
645
646void NOTICEREF_free(NOTICEREF *a)
647{
648 if (a == NULL) return;
649 DISPLAYTEXT_free(a->organization);
650 sk_pop_free(a->noticenos, ASN1_STRING_free);
651 Free (a);
652}
653
654IMPLEMENT_STACK_OF(POLICYQUALINFO)
655IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO)
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_crld.c b/src/lib/libssl/src/crypto/x509v3/v3_crld.c
new file mode 100644
index 0000000000..897ffb63e4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_crld.c
@@ -0,0 +1,283 @@
1/* v3_crld.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
67 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70
71X509V3_EXT_METHOD v3_crld = {
72NID_crl_distribution_points, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)CRL_DIST_POINTS_new,
74(X509V3_EXT_FREE)CRL_DIST_POINTS_free,
75(X509V3_EXT_D2I)d2i_CRL_DIST_POINTS,
76(X509V3_EXT_I2D)i2d_CRL_DIST_POINTS,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_crld,
79(X509V3_EXT_V2I)v2i_crld,
80NULL, NULL, NULL
81};
82
83static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
84 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
85{
86 DIST_POINT *point;
87 int i;
88 for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
89 point = sk_DIST_POINT_value(crld, i);
90 if(point->distpoint->fullname) {
91 exts = i2v_GENERAL_NAMES(NULL,
92 point->distpoint->fullname, exts);
93 }
94 if(point->reasons)
95 X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
96 if(point->CRLissuer)
97 X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
98 if(point->distpoint->relativename)
99 X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
100 }
101 return exts;
102}
103
104static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
105 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
106{
107 STACK_OF(DIST_POINT) *crld = NULL;
108 STACK_OF(GENERAL_NAME) *gens = NULL;
109 GENERAL_NAME *gen = NULL;
110 CONF_VALUE *cnf;
111 int i;
112 if(!(crld = sk_DIST_POINT_new(NULL))) goto merr;
113 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
114 DIST_POINT *point;
115 cnf = sk_CONF_VALUE_value(nval, i);
116 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
117 if(!(gens = GENERAL_NAMES_new())) goto merr;
118 if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
119 gen = NULL;
120 if(!(point = DIST_POINT_new())) goto merr;
121 if(!sk_DIST_POINT_push(crld, point)) {
122 DIST_POINT_free(point);
123 goto merr;
124 }
125 if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
126 point->distpoint->fullname = gens;
127 gens = NULL;
128 }
129 return crld;
130
131 merr:
132 X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
133 err:
134 GENERAL_NAME_free(gen);
135 GENERAL_NAMES_free(gens);
136 sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
137 return NULL;
138}
139
140int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp)
141{
142
143return i2d_ASN1_SET_OF_DIST_POINT(a, pp, i2d_DIST_POINT, V_ASN1_SEQUENCE,
144 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
145
146STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void)
147{
148 return sk_DIST_POINT_new_null();
149}
150
151void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a)
152{
153 sk_DIST_POINT_pop_free(a, DIST_POINT_free);
154}
155
156STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
157 unsigned char **pp,long length)
158{
159return d2i_ASN1_SET_OF_DIST_POINT(a, pp, length, d2i_DIST_POINT,
160 DIST_POINT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
161
162}
163
164IMPLEMENT_STACK_OF(DIST_POINT)
165IMPLEMENT_ASN1_SET_OF(DIST_POINT)
166
167int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp)
168{
169 int v = 0;
170 M_ASN1_I2D_vars(a);
171 /* NB: underlying type is a CHOICE so need EXPLICIT tagging */
172 M_ASN1_I2D_len_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
173 M_ASN1_I2D_len_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING);
174 M_ASN1_I2D_len_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES);
175
176 M_ASN1_I2D_seq_total();
177
178 M_ASN1_I2D_put_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
179 M_ASN1_I2D_put_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING, 1);
180 M_ASN1_I2D_put_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES, 2);
181
182 M_ASN1_I2D_finish();
183}
184
185DIST_POINT *DIST_POINT_new(void)
186{
187 DIST_POINT *ret=NULL;
188 ASN1_CTX c;
189 M_ASN1_New_Malloc(ret, DIST_POINT);
190 ret->distpoint = NULL;
191 ret->reasons = NULL;
192 ret->CRLissuer = NULL;
193 return (ret);
194 M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW);
195}
196
197DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length)
198{
199 M_ASN1_D2I_vars(a,DIST_POINT *,DIST_POINT_new);
200 M_ASN1_D2I_Init();
201 M_ASN1_D2I_start_sequence();
202 M_ASN1_D2I_get_EXP_opt (ret->distpoint, d2i_DIST_POINT_NAME, 0);
203 M_ASN1_D2I_get_IMP_opt (ret->reasons, d2i_ASN1_BIT_STRING, 1,
204 V_ASN1_BIT_STRING);
205 M_ASN1_D2I_get_IMP_opt (ret->CRLissuer, d2i_GENERAL_NAMES, 2,
206 V_ASN1_SEQUENCE);
207 M_ASN1_D2I_Finish(a, DIST_POINT_free, ASN1_F_D2I_DIST_POINT);
208}
209
210void DIST_POINT_free(DIST_POINT *a)
211{
212 if (a == NULL) return;
213 DIST_POINT_NAME_free(a->distpoint);
214 ASN1_BIT_STRING_free(a->reasons);
215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
216 Free ((char *)a);
217}
218
219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
220{
221 int v = 0;
222 M_ASN1_I2D_vars(a);
223
224 if(a->fullname) {
225 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
226 } else {
227 M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
228 }
229
230 /* Don't want a SEQUENCE so... */
231 if(pp == NULL) return ret;
232 p = *pp;
233
234 if(a->fullname) {
235 M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
236 } else {
237 M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
238 }
239 M_ASN1_I2D_finish();
240}
241
242DIST_POINT_NAME *DIST_POINT_NAME_new(void)
243{
244 DIST_POINT_NAME *ret=NULL;
245 ASN1_CTX c;
246 M_ASN1_New_Malloc(ret, DIST_POINT_NAME);
247 ret->fullname = NULL;
248 ret->relativename = NULL;
249 return (ret);
250 M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW);
251}
252
253void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
254{
255 if (a == NULL) return;
256 X509_NAME_free(a->relativename);
257 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
258 Free ((char *)a);
259}
260
261DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
262 long length)
263{
264 unsigned char _tmp, tag;
265 M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new);
266 M_ASN1_D2I_Init();
267 c.slen = length;
268
269 _tmp = M_ASN1_next;
270 tag = _tmp & ~V_ASN1_CONSTRUCTED;
271
272 if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) {
273 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
274 V_ASN1_SEQUENCE);
275 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
276 M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1);
277 } else {
278 c.error = ASN1_R_BAD_TAG;
279 goto err;
280 }
281
282 M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME);
283}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_enum.c b/src/lib/libssl/src/crypto/x509v3/v3_enum.c
new file mode 100644
index 0000000000..db423548ff
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_enum.c
@@ -0,0 +1,103 @@
1/* v3_enum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_ENUMERATED *asn1_enumerated_new(void);
64
65static ENUMERATED_NAMES crl_reasons[] = {
66{0, "Unspecified", "unspecified"},
67{1, "Key Compromise", "keyCompromise"},
68{2, "CA Compromise", "CACompromise"},
69{3, "Affiliation Changed", "affiliationChanged"},
70{4, "Superseded", "superseded"},
71{5, "Cessation Of Operation", "cessationOfOperation"},
72{6, "Certificate Hold", "certificateHold"},
73{8, "Remove From CRL", "removeFromCRL"},
74{-1, NULL, NULL}
75};
76
77X509V3_EXT_METHOD v3_crl_reason = {
78NID_crl_reason, 0,
79(X509V3_EXT_NEW)asn1_enumerated_new,
80(X509V3_EXT_FREE)ASN1_STRING_free,
81(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED,
82(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED,
83(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
84(X509V3_EXT_S2I)NULL,
85NULL, NULL, NULL, NULL, crl_reasons};
86
87
88static ASN1_ENUMERATED *asn1_enumerated_new(void)
89{
90 return ASN1_ENUMERATED_new();
91}
92
93char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
94 ASN1_ENUMERATED *e)
95{
96 ENUMERATED_NAMES *enam;
97 long strval;
98 strval = ASN1_ENUMERATED_get(e);
99 for(enam = method->usr_data; enam->lname; enam++) {
100 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
101 }
102 return i2s_ASN1_ENUMERATED(method, e);
103}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_extku.c b/src/lib/libssl/src/crypto/x509v3/v3_extku.c
new file mode 100644
index 0000000000..e039d21cbf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_extku.c
@@ -0,0 +1,150 @@
1/* v3_extku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
67 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
69 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *extlist);
70X509V3_EXT_METHOD v3_ext_ku = {
71NID_ext_key_usage, 0,
72(X509V3_EXT_NEW)ext_ku_new,
73(X509V3_EXT_FREE)ext_ku_free,
74(X509V3_EXT_D2I)d2i_ext_ku,
75(X509V3_EXT_I2D)i2d_ext_ku,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_ext_ku,
78(X509V3_EXT_V2I)v2i_ext_ku,
79NULL,NULL,
80NULL
81};
82
83STACK_OF(ASN1_OBJECT) *ext_ku_new(void)
84{
85 return sk_ASN1_OBJECT_new_null();
86}
87
88void ext_ku_free(STACK_OF(ASN1_OBJECT) *eku)
89{
90 sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
91 return;
92}
93
94int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp)
95{
96 return i2d_ASN1_SET_OF_ASN1_OBJECT(a, pp, i2d_ASN1_OBJECT,
97 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
98}
99
100STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
101 unsigned char **pp, long length)
102{
103 return d2i_ASN1_SET_OF_ASN1_OBJECT(a, pp, length, d2i_ASN1_OBJECT,
104 ASN1_OBJECT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
105}
106
107
108
109static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
110 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *ext_list)
111{
112int i;
113ASN1_OBJECT *obj;
114char obj_tmp[80];
115for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
116 obj = sk_ASN1_OBJECT_value(eku, i);
117 i2t_ASN1_OBJECT(obj_tmp, 80, obj);
118 X509V3_add_value(NULL, obj_tmp, &ext_list);
119}
120return ext_list;
121}
122
123static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
124 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
125{
126STACK_OF(ASN1_OBJECT) *extku;
127char *extval;
128ASN1_OBJECT *objtmp;
129CONF_VALUE *val;
130int i;
131
132if(!(extku = sk_ASN1_OBJECT_new(NULL))) {
133 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
134 return NULL;
135}
136
137for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138 val = sk_CONF_VALUE_value(nval, i);
139 if(val->value) extval = val->value;
140 else extval = val->name;
141 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
142 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
143 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
144 X509V3_conf_err(val);
145 return NULL;
146 }
147 sk_ASN1_OBJECT_push(extku, objtmp);
148}
149return extku;
150}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_genn.c b/src/lib/libssl/src/crypto/x509v3/v3_genn.c
new file mode 100644
index 0000000000..af716232f8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_genn.c
@@ -0,0 +1,237 @@
1/* v3_genn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp)
68{
69 unsigned char *p;
70 int ret;
71
72 ret = 0;
73
74 /* Save the location of initial TAG */
75 if(pp) p = *pp;
76 else p = NULL;
77
78 /* GEN_DNAME needs special treatment because of EXPLICIT tag */
79
80 if(a->type == GEN_DIRNAME) {
81 int v = 0;
82 M_ASN1_I2D_len_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
83 if(!p) return ret;
84 M_ASN1_I2D_put_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
85 *pp = p;
86 return ret;
87 }
88
89 switch(a->type) {
90
91 case GEN_OTHERNAME:
92 case GEN_X400:
93 case GEN_EDIPARTY:
94 ret = i2d_ASN1_TYPE(a->d.other, pp);
95 break;
96
97 case GEN_EMAIL:
98 case GEN_DNS:
99 case GEN_URI:
100 ret = i2d_ASN1_IA5STRING(a->d.ia5, pp);
101 break;
102
103 case GEN_IPADD:
104 ret = i2d_ASN1_OCTET_STRING(a->d.ip, pp);
105 break;
106
107 case GEN_RID:
108 ret = i2d_ASN1_OBJECT(a->d.rid, pp);
109 break;
110 }
111 /* Replace TAG with IMPLICIT value */
112 if(p) *p = (*p & V_ASN1_CONSTRUCTED) | a->type;
113 return ret;
114}
115
116GENERAL_NAME *GENERAL_NAME_new()
117{
118 GENERAL_NAME *ret=NULL;
119 ASN1_CTX c;
120 M_ASN1_New_Malloc(ret, GENERAL_NAME);
121 ret->type = -1;
122 ret->d.ptr = NULL;
123 return (ret);
124 M_ASN1_New_Error(ASN1_F_GENERAL_NAME_NEW);
125}
126
127GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp,
128 long length)
129{
130 unsigned char _tmp;
131 M_ASN1_D2I_vars(a,GENERAL_NAME *,GENERAL_NAME_new);
132 M_ASN1_D2I_Init();
133 c.slen = length;
134
135 _tmp = M_ASN1_next;
136 ret->type = _tmp & ~V_ASN1_CONSTRUCTED;
137
138 switch(ret->type) {
139 /* Just put these in a "blob" for now */
140 case GEN_OTHERNAME:
141 case GEN_X400:
142 case GEN_EDIPARTY:
143 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE);
144 break;
145
146 case GEN_EMAIL:
147 case GEN_DNS:
148 case GEN_URI:
149 M_ASN1_D2I_get_imp(ret->d.ia5, d2i_ASN1_IA5STRING,
150 V_ASN1_IA5STRING);
151 break;
152
153 case GEN_DIRNAME:
154 M_ASN1_D2I_get_EXP_opt(ret->d.dirn, d2i_X509_NAME, 4);
155 break;
156
157 case GEN_IPADD:
158 M_ASN1_D2I_get_imp(ret->d.ip, d2i_ASN1_OCTET_STRING,
159 V_ASN1_OCTET_STRING);
160 break;
161
162 case GEN_RID:
163 M_ASN1_D2I_get_imp(ret->d.rid, d2i_ASN1_OBJECT,V_ASN1_OBJECT);
164 break;
165
166 default:
167 c.error = ASN1_R_BAD_TAG;
168 goto err;
169 }
170
171 c.slen = 0;
172 M_ASN1_D2I_Finish(a, GENERAL_NAME_free, ASN1_F_D2I_GENERAL_NAME);
173}
174
175void GENERAL_NAME_free(GENERAL_NAME *a)
176{
177 if (a == NULL) return;
178 switch(a->type) {
179 case GEN_OTHERNAME:
180 case GEN_X400:
181 case GEN_EDIPARTY:
182 ASN1_TYPE_free(a->d.other);
183 break;
184
185 case GEN_EMAIL:
186 case GEN_DNS:
187 case GEN_URI:
188
189 ASN1_IA5STRING_free(a->d.ia5);
190 break;
191
192 case GEN_DIRNAME:
193 X509_NAME_free(a->d.dirn);
194 break;
195
196 case GEN_IPADD:
197 ASN1_OCTET_STRING_free(a->d.ip);
198 break;
199
200 case GEN_RID:
201 ASN1_OBJECT_free(a->d.rid);
202 break;
203
204 }
205 Free ((char *)a);
206}
207
208/* Now the GeneralNames versions: a SEQUENCE OF GeneralName These are needed as
209 * an explicit functions.
210 */
211
212STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new()
213{
214 return sk_GENERAL_NAME_new(NULL);
215}
216
217void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a)
218{
219 sk_GENERAL_NAME_pop_free(a, GENERAL_NAME_free);
220}
221
222STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a,
223 unsigned char **pp, long length)
224{
225return d2i_ASN1_SET_OF_GENERAL_NAME(a, pp, length, d2i_GENERAL_NAME,
226 GENERAL_NAME_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
227}
228
229int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp)
230{
231return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE,
232 V_ASN1_UNIVERSAL, IS_SEQUENCE);
233}
234
235IMPLEMENT_STACK_OF(GENERAL_NAME)
236IMPLEMENT_ASN1_SET_OF(GENERAL_NAME)
237
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_ia5.c b/src/lib/libssl/src/crypto/x509v3/v3_ia5.c
new file mode 100644
index 0000000000..3446c5cd6a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_ia5.c
@@ -0,0 +1,116 @@
1/* v3_ia5.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static ASN1_IA5STRING *ia5string_new(void);
67static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
68static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
69X509V3_EXT_METHOD v3_ns_ia5_list[] = {
70EXT_IA5STRING(NID_netscape_base_url),
71EXT_IA5STRING(NID_netscape_revocation_url),
72EXT_IA5STRING(NID_netscape_ca_revocation_url),
73EXT_IA5STRING(NID_netscape_renewal_url),
74EXT_IA5STRING(NID_netscape_ca_policy_url),
75EXT_IA5STRING(NID_netscape_ssl_server_name),
76EXT_IA5STRING(NID_netscape_comment),
77EXT_END
78};
79
80
81static ASN1_IA5STRING *ia5string_new(void)
82{
83 return ASN1_IA5STRING_new();
84}
85
86static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
87 ASN1_IA5STRING *ia5)
88{
89 char *tmp;
90 if(!ia5 || !ia5->length) return NULL;
91 tmp = Malloc(ia5->length + 1);
92 memcpy(tmp, ia5->data, ia5->length);
93 tmp[ia5->length] = 0;
94 return tmp;
95}
96
97static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
98 X509V3_CTX *ctx, char *str)
99{
100 ASN1_IA5STRING *ia5;
101 if(!str) {
102 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
103 return NULL;
104 }
105 if(!(ia5 = ASN1_IA5STRING_new())) goto err;
106 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
107 strlen(str))) {
108 ASN1_IA5STRING_free(ia5);
109 goto err;
110 }
111 return ia5;
112 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
114 return NULL;
115}
116
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_info.c b/src/lib/libssl/src/crypto/x509v3/v3_info.c
new file mode 100644
index 0000000000..78d2135046
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_info.c
@@ -0,0 +1,236 @@
1/* v3_info.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
67 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
68 STACK_OF(CONF_VALUE) *ret);
69static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
71
72X509V3_EXT_METHOD v3_info =
73{ NID_info_access, X509V3_EXT_MULTILINE,
74(X509V3_EXT_NEW)AUTHORITY_INFO_ACCESS_new,
75(X509V3_EXT_FREE)AUTHORITY_INFO_ACCESS_free,
76(X509V3_EXT_D2I)d2i_AUTHORITY_INFO_ACCESS,
77(X509V3_EXT_I2D)i2d_AUTHORITY_INFO_ACCESS,
78NULL, NULL,
79(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
80(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
81NULL, NULL, NULL};
82
83static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
84 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
85 STACK_OF(CONF_VALUE) *ret)
86{
87 ACCESS_DESCRIPTION *desc;
88 int i;
89 char objtmp[80], *ntmp;
90 CONF_VALUE *vtmp;
91 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
92 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
93 ret = i2v_GENERAL_NAME(method, desc->location, ret);
94 if(!ret) break;
95 vtmp = sk_CONF_VALUE_value(ret, i);
96 i2t_ASN1_OBJECT(objtmp, 80, desc->method);
97 ntmp = Malloc(strlen(objtmp) + strlen(vtmp->name) + 5);
98 if(!ntmp) {
99 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
100 ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103 strcpy(ntmp, objtmp);
104 strcat(ntmp, " - ");
105 strcat(ntmp, vtmp->name);
106 Free(vtmp->name);
107 vtmp->name = ntmp;
108
109 }
110 if(!ret) return sk_CONF_VALUE_new_null();
111 return ret;
112}
113
114static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
115 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
116{
117 STACK_OF(ACCESS_DESCRIPTION) *ainfo = NULL;
118 CONF_VALUE *cnf, ctmp;
119 ACCESS_DESCRIPTION *acc;
120 int i, objlen;
121 char *objtmp, *ptmp;
122 if(!(ainfo = sk_ACCESS_DESCRIPTION_new(NULL))) {
123 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
124 return NULL;
125 }
126 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
127 cnf = sk_CONF_VALUE_value(nval, i);
128 if(!(acc = ACCESS_DESCRIPTION_new())
129 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
130 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
131 goto err;
132 }
133 ptmp = strchr(cnf->name, ';');
134 if(!ptmp) {
135 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
136 goto err;
137 }
138 objlen = ptmp - cnf->name;
139 ctmp.name = ptmp + 1;
140 ctmp.value = cnf->value;
141 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
142 goto err;
143 if(!(objtmp = Malloc(objlen + 1))) {
144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 goto err;
146 }
147 strncpy(objtmp, cnf->name, objlen);
148 objtmp[objlen] = 0;
149 acc->method = OBJ_txt2obj(objtmp, 0);
150 if(!acc->method) {
151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
152 ERR_add_error_data(2, "value=", objtmp);
153 Free(objtmp);
154 goto err;
155 }
156 Free(objtmp);
157
158 }
159 return ainfo;
160 err:
161 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
162 return NULL;
163}
164
165int i2d_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION *a, unsigned char **pp)
166{
167 M_ASN1_I2D_vars(a);
168
169 M_ASN1_I2D_len(a->method, i2d_ASN1_OBJECT);
170 M_ASN1_I2D_len(a->location, i2d_GENERAL_NAME);
171
172 M_ASN1_I2D_seq_total();
173
174 M_ASN1_I2D_put(a->method, i2d_ASN1_OBJECT);
175 M_ASN1_I2D_put(a->location, i2d_GENERAL_NAME);
176
177 M_ASN1_I2D_finish();
178}
179
180ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void)
181{
182 ACCESS_DESCRIPTION *ret=NULL;
183 ASN1_CTX c;
184 M_ASN1_New_Malloc(ret, ACCESS_DESCRIPTION);
185 ret->method = OBJ_nid2obj(NID_undef);
186 ret->location = NULL;
187 return (ret);
188 M_ASN1_New_Error(ASN1_F_ACCESS_DESCRIPTION_NEW);
189}
190
191ACCESS_DESCRIPTION *d2i_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION **a, unsigned char **pp,
192 long length)
193{
194 M_ASN1_D2I_vars(a,ACCESS_DESCRIPTION *,ACCESS_DESCRIPTION_new);
195 M_ASN1_D2I_Init();
196 M_ASN1_D2I_start_sequence();
197 M_ASN1_D2I_get(ret->method, d2i_ASN1_OBJECT);
198 M_ASN1_D2I_get(ret->location, d2i_GENERAL_NAME);
199 M_ASN1_D2I_Finish(a, ACCESS_DESCRIPTION_free, ASN1_F_D2I_ACCESS_DESCRIPTION);
200}
201
202void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *a)
203{
204 if (a == NULL) return;
205 ASN1_OBJECT_free(a->method);
206 GENERAL_NAME_free(a->location);
207 Free (a);
208}
209
210STACK_OF(ACCESS_DESCRIPTION) *AUTHORITY_INFO_ACCESS_new(void)
211{
212 return sk_ACCESS_DESCRIPTION_new(NULL);
213}
214
215void AUTHORITY_INFO_ACCESS_free(STACK_OF(ACCESS_DESCRIPTION) *a)
216{
217 sk_ACCESS_DESCRIPTION_pop_free(a, ACCESS_DESCRIPTION_free);
218}
219
220STACK_OF(ACCESS_DESCRIPTION) *d2i_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) **a,
221 unsigned char **pp, long length)
222{
223return d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, length, d2i_ACCESS_DESCRIPTION,
224 ACCESS_DESCRIPTION_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
225}
226
227int i2d_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) *a, unsigned char **pp)
228{
229return i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, i2d_ACCESS_DESCRIPTION, V_ASN1_SEQUENCE,
230 V_ASN1_UNIVERSAL, IS_SEQUENCE);
231}
232
233IMPLEMENT_STACK_OF(ACCESS_DESCRIPTION)
234IMPLEMENT_ASN1_SET_OF(ACCESS_DESCRIPTION)
235
236
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_int.c b/src/lib/libssl/src/crypto/x509v3/v3_int.c
new file mode 100644
index 0000000000..637dd5e128
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_int.c
@@ -0,0 +1,79 @@
1/* v3_int.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_INTEGER *asn1_integer_new(void);
64
65X509V3_EXT_METHOD v3_crl_num = {
66NID_crl_number, 0,
67(X509V3_EXT_NEW)asn1_integer_new,
68(X509V3_EXT_FREE)ASN1_STRING_free,
69(X509V3_EXT_D2I)d2i_ASN1_INTEGER,
70(X509V3_EXT_I2D)i2d_ASN1_INTEGER,
71(X509V3_EXT_I2S)i2s_ASN1_INTEGER,
72(X509V3_EXT_S2I)NULL,
73NULL, NULL, NULL, NULL, NULL};
74
75
76static ASN1_INTEGER *asn1_integer_new(void)
77{
78 return ASN1_INTEGER_new();
79}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_lib.c b/src/lib/libssl/src/crypto/x509v3/v3_lib.c
new file mode 100644
index 0000000000..a0aa5de794
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_lib.c
@@ -0,0 +1,177 @@
1/* v3_lib.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65static STACK *ext_list = NULL;
66
67static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
68static void ext_list_free(X509V3_EXT_METHOD *ext);
69
70int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
71{
72 if(!ext_list && !(ext_list = sk_new(ext_cmp))) {
73 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!sk_push(ext_list, (char *)ext)) {
77 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 return 1;
81}
82
83static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
84{
85 return ((*a)->ext_nid - (*b)->ext_nid);
86}
87
88X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
89{
90 X509V3_EXT_METHOD tmp;
91 int idx;
92 tmp.ext_nid = nid;
93 if(!ext_list || (tmp.ext_nid < 0) ) return NULL;
94 idx = sk_find(ext_list, (char *)&tmp);
95 if(idx == -1) return NULL;
96 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
97}
98
99X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
100{
101 int nid;
102 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
103 return X509V3_EXT_get_nid(nid);
104}
105
106
107int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
108{
109 for(;extlist->ext_nid!=-1;extlist++)
110 if(!X509V3_EXT_add(extlist)) return 0;
111 return 1;
112}
113
114int X509V3_EXT_add_alias(int nid_to, int nid_from)
115{
116 X509V3_EXT_METHOD *ext, *tmpext;
117 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
118 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
119 return 0;
120 }
121 if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) {
122 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
123 return 0;
124 }
125 *tmpext = *ext;
126 tmpext->ext_nid = nid_to;
127 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
128 return 1;
129}
130
131void X509V3_EXT_cleanup(void)
132{
133 sk_pop_free(ext_list, ext_list_free);
134 ext_list = NULL;
135}
136
137static void ext_list_free(X509V3_EXT_METHOD *ext)
138{
139 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
140}
141
142extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
143extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet;
144extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
145
146extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
147
148int X509V3_add_standard_extensions(void)
149{
150 X509V3_EXT_add_list(v3_ns_ia5_list);
151 X509V3_EXT_add_list(v3_alt);
152 X509V3_EXT_add(&v3_bcons);
153 X509V3_EXT_add(&v3_nscert);
154 X509V3_EXT_add(&v3_key_usage);
155 X509V3_EXT_add(&v3_ext_ku);
156 X509V3_EXT_add(&v3_skey_id);
157 X509V3_EXT_add(&v3_akey_id);
158 X509V3_EXT_add(&v3_pkey_usage_period);
159 X509V3_EXT_add(&v3_crl_num);
160 X509V3_EXT_add(&v3_sxnet);
161 X509V3_EXT_add(&v3_crl_reason);
162 X509V3_EXT_add(&v3_cpols);
163 X509V3_EXT_add(&v3_crld);
164 return 1;
165}
166
167/* Return an extension internal structure */
168
169void *X509V3_EXT_d2i(X509_EXTENSION *ext)
170{
171 X509V3_EXT_METHOD *method;
172 unsigned char *p;
173 if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL;
174 p = ext->value->data;
175 return method->d2i(NULL, &p, ext->value->length);
176}
177
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_ocsp.c b/src/lib/libssl/src/crypto/x509v3/v3_ocsp.c
new file mode 100644
index 0000000000..083112314e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_ocsp.c
@@ -0,0 +1,272 @@
1/* v3_ocsp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/ocsp.h>
64#include <openssl/x509v3.h>
65
66/* OCSP extensions and a couple of CRL entry extensions
67 */
68
69static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
70static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
71static int i2r_object(X509V3_EXT_METHOD *method, void *obj, BIO *out, int indent);
72
73static void *ocsp_nonce_new(void);
74static int i2d_ocsp_nonce(void *a, unsigned char **pp);
75static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length);
76static void ocsp_nonce_free(void *a);
77static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
78
79static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent);
80static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
81static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind);
82
83X509V3_EXT_METHOD v3_ocsp_crlid = {
84 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),
85 0,0,0,0,
86 0,0,
87 0,0,
88 i2r_ocsp_crlid,0,
89 NULL
90};
91
92X509V3_EXT_METHOD v3_ocsp_acutoff = {
93 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
94 0,0,0,0,
95 0,0,
96 0,0,
97 i2r_ocsp_acutoff,0,
98 NULL
99};
100
101X509V3_EXT_METHOD v3_crl_invdate = {
102 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
103 0,0,0,0,
104 0,0,
105 0,0,
106 i2r_ocsp_acutoff,0,
107 NULL
108};
109
110X509V3_EXT_METHOD v3_crl_hold = {
111 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT),
112 0,0,0,0,
113 0,0,
114 0,0,
115 i2r_object,0,
116 NULL
117};
118
119X509V3_EXT_METHOD v3_ocsp_nonce = {
120 NID_id_pkix_OCSP_Nonce, 0, NULL,
121 ocsp_nonce_new,
122 ocsp_nonce_free,
123 d2i_ocsp_nonce,
124 i2d_ocsp_nonce,
125 0,0,
126 0,0,
127 i2r_ocsp_nonce,0,
128 NULL
129};
130
131X509V3_EXT_METHOD v3_ocsp_nocheck = {
132 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL),
133 0,0,0,0,
134 0,s2i_ocsp_nocheck,
135 0,0,
136 i2r_ocsp_nocheck,0,
137 NULL
138};
139
140X509V3_EXT_METHOD v3_ocsp_serviceloc = {
141 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC),
142 0,0,0,0,
143 0,0,
144 0,0,
145 i2r_ocsp_serviceloc,0,
146 NULL
147};
148
149static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
150{
151 OCSP_CRLID *a = in;
152 if (a->crlUrl)
153 {
154 if (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;
155 if (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;
156 if (!BIO_write(bp, "\n", 1)) goto err;
157 }
158 if (a->crlNum)
159 {
160 if (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;
161 if (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;
162 if (!BIO_write(bp, "\n", 1)) goto err;
163 }
164 if (a->crlTime)
165 {
166 if (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;
167 if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;
168 if (!BIO_write(bp, "\n", 1)) goto err;
169 }
170 return 1;
171 err:
172 return 0;
173}
174
175static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *cutoff, BIO *bp, int ind)
176{
177 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
178 if(!ASN1_GENERALIZEDTIME_print(bp, cutoff)) return 0;
179 return 1;
180}
181
182
183static int i2r_object(X509V3_EXT_METHOD *method, void *oid, BIO *bp, int ind)
184{
185 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
186 if(!i2a_ASN1_OBJECT(bp, oid)) return 0;
187 return 1;
188}
189
190/* OCSP nonce. This is needs special treatment because it doesn't have
191 * an ASN1 encoding at all: it just contains arbitrary data.
192 */
193
194static void *ocsp_nonce_new(void)
195{
196 return ASN1_OCTET_STRING_new();
197}
198
199static int i2d_ocsp_nonce(void *a, unsigned char **pp)
200{
201 ASN1_OCTET_STRING *os = a;
202 if(pp) {
203 memcpy(*pp, os->data, os->length);
204 *pp += os->length;
205 }
206 return os->length;
207}
208
209static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length)
210{
211 ASN1_OCTET_STRING *os, **pos;
212 pos = a;
213 if(!pos || !*pos) os = ASN1_OCTET_STRING_new();
214 else os = *pos;
215 if(!ASN1_OCTET_STRING_set(os, *pp, length)) goto err;
216
217 *pp += length;
218
219 if(pos) *pos = os;
220 return os;
221
222 err:
223 if(os && (!pos || (*pos != os))) M_ASN1_OCTET_STRING_free(os);
224 OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE);
225 return NULL;
226}
227
228static void ocsp_nonce_free(void *a)
229{
230 M_ASN1_OCTET_STRING_free(a);
231}
232
233static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent)
234{
235 if(BIO_printf(out, "%*s", indent, "") <= 0) return 0;
236 if(i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0) return 0;
237 return 1;
238}
239
240/* Nocheck is just a single NULL. Don't print anything and always set it */
241
242static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent)
243{
244 return 1;
245}
246
247static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
248{
249 return ASN1_NULL_new();
250}
251
252static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
253 {
254 int i;
255 OCSP_SERVICELOC *a = in;
256 ACCESS_DESCRIPTION *ad;
257
258 if (BIO_printf(bp, "%*sIssuer: ", ind, "") <= 0) goto err;
259 if (X509_NAME_print_ex(bp, a->issuer, 0, XN_FLAG_ONELINE) <= 0) goto err;
260 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++)
261 {
262 ad = sk_ACCESS_DESCRIPTION_value(a->locator,i);
263 if (BIO_printf(bp, "\n%*s", (2*ind), "") <= 0)
264 goto err;
265 if(i2a_ASN1_OBJECT(bp, ad->method) <= 0) goto err;
266 if(BIO_puts(bp, " - ") <= 0) goto err;
267 if(GENERAL_NAME_print(bp, ad->location) <= 0) goto err;
268 }
269 return 1;
270err:
271 return 0;
272 }
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_pku.c b/src/lib/libssl/src/crypto/x509v3/v3_pku.c
new file mode 100644
index 0000000000..c13e7d8f45
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_pku.c
@@ -0,0 +1,151 @@
1/* v3_pku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509v3.h>
64
65static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage, BIO *out, int indent);
66/*
67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
68*/
69X509V3_EXT_METHOD v3_pkey_usage_period = {
70NID_private_key_usage_period, 0,
71(X509V3_EXT_NEW)PKEY_USAGE_PERIOD_new,
72(X509V3_EXT_FREE)PKEY_USAGE_PERIOD_free,
73(X509V3_EXT_D2I)d2i_PKEY_USAGE_PERIOD,
74(X509V3_EXT_I2D)i2d_PKEY_USAGE_PERIOD,
75NULL, NULL, NULL, NULL,
76(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
77NULL
78};
79
80int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp)
81{
82 M_ASN1_I2D_vars(a);
83
84 M_ASN1_I2D_len_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME);
85 M_ASN1_I2D_len_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME);
86
87 M_ASN1_I2D_seq_total();
88
89 M_ASN1_I2D_put_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME, 0);
90 M_ASN1_I2D_put_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME, 1);
91
92 M_ASN1_I2D_finish();
93}
94
95PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void)
96{
97 PKEY_USAGE_PERIOD *ret=NULL;
98 ASN1_CTX c;
99 M_ASN1_New_Malloc(ret, PKEY_USAGE_PERIOD);
100 ret->notBefore = NULL;
101 ret->notAfter = NULL;
102 return (ret);
103 M_ASN1_New_Error(ASN1_F_PKEY_USAGE_PERIOD_NEW);
104}
105
106PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a,
107 unsigned char **pp, long length)
108{
109 M_ASN1_D2I_vars(a,PKEY_USAGE_PERIOD *,PKEY_USAGE_PERIOD_new);
110 M_ASN1_D2I_Init();
111 M_ASN1_D2I_start_sequence();
112 M_ASN1_D2I_get_IMP_opt (ret->notBefore, d2i_ASN1_GENERALIZEDTIME, 0,
113 V_ASN1_GENERALIZEDTIME);
114 M_ASN1_D2I_get_IMP_opt (ret->notAfter, d2i_ASN1_GENERALIZEDTIME, 1,
115 V_ASN1_GENERALIZEDTIME);
116 M_ASN1_D2I_Finish(a, PKEY_USAGE_PERIOD_free, ASN1_F_D2I_PKEY_USAGE_PERIOD);
117}
118
119void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a)
120{
121 if (a == NULL) return;
122 ASN1_GENERALIZEDTIME_free(a->notBefore);
123 ASN1_GENERALIZEDTIME_free(a->notAfter);
124 Free ((char *)a);
125}
126
127static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
128 PKEY_USAGE_PERIOD *usage, BIO *out, int indent)
129{
130 BIO_printf(out, "%*s", indent, "");
131 if(usage->notBefore) {
132 BIO_write(out, "Not Before: ", 12);
133 ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
134 if(usage->notAfter) BIO_write(out, ", ", 2);
135 }
136 if(usage->notAfter) {
137 BIO_write(out, "Not After: ", 11);
138 ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
139 }
140 return 1;
141}
142
143/*
144static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
145X509V3_EXT_METHOD *method;
146X509V3_CTX *ctx;
147STACK_OF(CONF_VALUE) *values;
148{
149return NULL;
150}
151*/
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_prn.c b/src/lib/libssl/src/crypto/x509v3/v3_prn.c
new file mode 100644
index 0000000000..dc20c6bdba
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_prn.c
@@ -0,0 +1,135 @@
1/* v3_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65/* Extension printing routines */
66
67/* Print out a name+value stack */
68
69void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
70{
71 int i;
72 CONF_VALUE *nval;
73 if(!val) return;
74 if(!ml || !sk_CONF_VALUE_num(val)) {
75 BIO_printf(out, "%*s", indent, "");
76 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
77 }
78 for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
79 if(ml) BIO_printf(out, "%*s", indent, "");
80 else if(i > 0) BIO_printf(out, ", ");
81 nval = sk_CONF_VALUE_value(val, i);
82 if(!nval->name) BIO_puts(out, nval->value);
83 else if(!nval->value) BIO_puts(out, nval->name);
84 else BIO_printf(out, "%s:%s", nval->name, nval->value);
85 if(ml) BIO_puts(out, "\n");
86 }
87}
88
89/* Main routine: print out a general extension */
90
91int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent)
92{
93 char *ext_str = NULL, *value = NULL;
94 unsigned char *p;
95 X509V3_EXT_METHOD *method;
96 STACK_OF(CONF_VALUE) *nval = NULL;
97 int ok = 1;
98 if(!(method = X509V3_EXT_get(ext))) return 0;
99 p = ext->value->data;
100 if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0;
101 if(method->i2s) {
102 if(!(value = method->i2s(method, ext_str))) {
103 ok = 0;
104 goto err;
105 }
106 BIO_printf(out, "%*s%s", indent, "", value);
107 } else if(method->i2v) {
108 if(!(nval = method->i2v(method, ext_str, NULL))) {
109 ok = 0;
110 goto err;
111 }
112 X509V3_EXT_val_prn(out, nval, indent,
113 method->ext_flags & X509V3_EXT_MULTILINE);
114 } else if(method->i2r) {
115 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
116 } else ok = 0;
117
118 err:
119 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
120 if(value) Free(value);
121 method->ext_free(ext_str);
122 return ok;
123}
124
125#ifndef NO_FP_API
126int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
127{
128 BIO *bio_tmp;
129 int ret;
130 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
131 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
132 BIO_free(bio_tmp);
133 return ret;
134}
135#endif
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_purp.c b/src/lib/libssl/src/crypto/x509v3/v3_purp.c
new file mode 100644
index 0000000000..b7494ebcd5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_purp.c
@@ -0,0 +1,456 @@
1/* v3_purp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static void x509v3_cache_extensions(X509 *x);
65
66static int ca_check(X509 *x);
67static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca);
68static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
69static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
70static int purpose_smime(X509 *x, int ca);
71static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca);
72static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca);
73static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca);
74
75static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b);
76static void xptable_free(X509_PURPOSE *p);
77
78static X509_PURPOSE xstandard[] = {
79 {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, check_purpose_ssl_client, "SSL client", "sslclient", NULL},
80 {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ssl_server, "SSL server", "sslserver", NULL},
81 {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ns_ssl_server, "Netscape SSL server", "nssslserver", NULL},
82 {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, "S/MIME signing", "smimesign", NULL},
83 {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, check_purpose_smime_encrypt, "S/MIME encryption", "smimeencrypt", NULL},
84 {X509_PURPOSE_CRL_SIGN, X509_TRUST_ANY, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
85};
86
87#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
88
89IMPLEMENT_STACK_OF(X509_PURPOSE)
90
91static STACK_OF(X509_PURPOSE) *xptable = NULL;
92
93static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b)
94{
95 return (*a)->purpose - (*b)->purpose;
96}
97
98int X509_check_purpose(X509 *x, int id, int ca)
99{
100 int idx;
101 X509_PURPOSE *pt;
102 if(!(x->ex_flags & EXFLAG_SET)) {
103 CRYPTO_w_lock(CRYPTO_LOCK_X509);
104 x509v3_cache_extensions(x);
105 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
106 }
107 if(id == -1) return 1;
108 idx = X509_PURPOSE_get_by_id(id);
109 if(idx == -1) return -1;
110 pt = X509_PURPOSE_get0(idx);
111 return pt->check_purpose(pt, x, ca);
112}
113
114int X509_PURPOSE_get_count(void)
115{
116 if(!xptable) return X509_PURPOSE_COUNT;
117 return sk_X509_PURPOSE_num(xptable) + X509_PURPOSE_COUNT;
118}
119
120X509_PURPOSE * X509_PURPOSE_get0(int idx)
121{
122 if(idx < 0) return NULL;
123 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
124 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
125}
126
127int X509_PURPOSE_get_by_sname(char *sname)
128{
129 int i;
130 X509_PURPOSE *xptmp;
131 for(i = 0; i < X509_PURPOSE_get_count(); i++) {
132 xptmp = X509_PURPOSE_get0(i);
133 if(!strcmp(xptmp->sname, sname)) return i;
134 }
135 return -1;
136}
137
138
139int X509_PURPOSE_get_by_id(int purpose)
140{
141 X509_PURPOSE tmp;
142 int idx;
143 if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
144 return purpose - X509_PURPOSE_MIN;
145 tmp.purpose = purpose;
146 if(!xptable) return -1;
147 idx = sk_X509_PURPOSE_find(xptable, &tmp);
148 if(idx == -1) return -1;
149 return idx + X509_PURPOSE_COUNT;
150}
151
152int X509_PURPOSE_add(int id, int trust, int flags,
153 int (*ck)(X509_PURPOSE *, X509 *, int),
154 char *name, char *sname, void *arg)
155{
156 int idx;
157 X509_PURPOSE *ptmp;
158 /* This is set according to what we change: application can't set it */
159 flags &= ~X509_PURPOSE_DYNAMIC;
160 /* This will always be set for application modified trust entries */
161 flags |= X509_PURPOSE_DYNAMIC_NAME;
162 /* Get existing entry if any */
163 idx = X509_PURPOSE_get_by_id(id);
164 /* Need a new entry */
165 if(idx == -1) {
166 if(!(ptmp = Malloc(sizeof(X509_PURPOSE)))) {
167 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
168 return 0;
169 }
170 ptmp->flags = X509_PURPOSE_DYNAMIC;
171 } else ptmp = X509_PURPOSE_get0(idx);
172
173 /* Free existing name if dynamic */
174 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
175 Free(ptmp->name);
176 Free(ptmp->sname);
177 }
178 /* dup supplied name */
179 ptmp->name = BUF_strdup(name);
180 ptmp->sname = BUF_strdup(sname);
181 if(!ptmp->name || !ptmp->sname) {
182 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 /* Keep the dynamic flag of existing entry */
186 ptmp->flags &= X509_PURPOSE_DYNAMIC;
187 /* Set all other flags */
188 ptmp->flags |= flags;
189
190 ptmp->purpose = id;
191 ptmp->trust = trust;
192 ptmp->check_purpose = ck;
193 ptmp->usr_data = arg;
194
195 /* If its a new entry manage the dynamic table */
196 if(idx == -1) {
197 if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
198 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
199 return 0;
200 }
201 if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
202 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
203 return 0;
204 }
205 }
206 return 1;
207}
208
209static void xptable_free(X509_PURPOSE *p)
210 {
211 if(!p) return;
212 if (p->flags & X509_PURPOSE_DYNAMIC)
213 {
214 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
215 Free(p->name);
216 Free(p->sname);
217 }
218 Free(p);
219 }
220 }
221
222void X509_PURPOSE_cleanup(void)
223{
224 int i;
225 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
226 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
227 xptable = NULL;
228}
229
230int X509_PURPOSE_get_id(X509_PURPOSE *xp)
231{
232 return xp->purpose;
233}
234
235char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
236{
237 return xp->name;
238}
239
240char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
241{
242 return xp->sname;
243}
244
245int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
246{
247 return xp->trust;
248}
249
250#ifndef NO_SHA
251static void x509v3_cache_extensions(X509 *x)
252{
253 BASIC_CONSTRAINTS *bs;
254 ASN1_BIT_STRING *usage;
255 ASN1_BIT_STRING *ns;
256 STACK_OF(ASN1_OBJECT) *extusage;
257 int i;
258 if(x->ex_flags & EXFLAG_SET) return;
259 X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
260 /* Does subject name match issuer ? */
261 if(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))
262 x->ex_flags |= EXFLAG_SS;
263 /* V1 should mean no extensions ... */
264 if(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;
265 /* Handle basic constraints */
266 if((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
267 if(bs->ca) x->ex_flags |= EXFLAG_CA;
268 if(bs->pathlen) {
269 if((bs->pathlen->type == V_ASN1_NEG_INTEGER)
270 || !bs->ca) {
271 x->ex_flags |= EXFLAG_INVALID;
272 x->ex_pathlen = 0;
273 } else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
274 } else x->ex_pathlen = -1;
275 BASIC_CONSTRAINTS_free(bs);
276 x->ex_flags |= EXFLAG_BCONS;
277 }
278 /* Handle key usage */
279 if((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
280 if(usage->length > 0) {
281 x->ex_kusage = usage->data[0];
282 if(usage->length > 1)
283 x->ex_kusage |= usage->data[1] << 8;
284 } else x->ex_kusage = 0;
285 x->ex_flags |= EXFLAG_KUSAGE;
286 ASN1_BIT_STRING_free(usage);
287 }
288 x->ex_xkusage = 0;
289 if((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
290 x->ex_flags |= EXFLAG_XKUSAGE;
291 for(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
292 switch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {
293 case NID_server_auth:
294 x->ex_xkusage |= XKU_SSL_SERVER;
295 break;
296
297 case NID_client_auth:
298 x->ex_xkusage |= XKU_SSL_CLIENT;
299 break;
300
301 case NID_email_protect:
302 x->ex_xkusage |= XKU_SMIME;
303 break;
304
305 case NID_code_sign:
306 x->ex_xkusage |= XKU_CODE_SIGN;
307 break;
308
309 case NID_ms_sgc:
310 case NID_ns_sgc:
311 x->ex_xkusage |= XKU_SGC;
312 }
313 }
314 sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
315 }
316
317 if((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
318 if(ns->length > 0) x->ex_nscert = ns->data[0];
319 else x->ex_nscert = 0;
320 x->ex_flags |= EXFLAG_NSCERT;
321 ASN1_BIT_STRING_free(ns);
322 }
323 x->ex_flags |= EXFLAG_SET;
324}
325#endif
326
327/* CA checks common to all purposes
328 * return codes:
329 * 0 not a CA
330 * 1 is a CA
331 * 2 basicConstraints absent so "maybe" a CA
332 * 3 basicConstraints absent but self signed V1.
333 */
334
335#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
336#define ku_reject(x, usage) \
337 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
338#define xku_reject(x, usage) \
339 (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage)))
340#define ns_reject(x, usage) \
341 (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
342
343static int ca_check(X509 *x)
344{
345 /* keyUsage if present should allow cert signing */
346 if(ku_reject(x, KU_KEY_CERT_SIGN)) return 0;
347 if(x->ex_flags & EXFLAG_BCONS) {
348 if(x->ex_flags & EXFLAG_CA) return 1;
349 /* If basicConstraints says not a CA then say so */
350 else return 0;
351 } else {
352 if((x->ex_flags & V1_ROOT) == V1_ROOT) return 3;
353 else return 2;
354 }
355}
356
357
358static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca)
359{
360 if(xku_reject(x,XKU_SSL_CLIENT)) return 0;
361 if(ca) {
362 int ca_ret;
363 ca_ret = ca_check(x);
364 if(!ca_ret) return 0;
365 /* check nsCertType if present */
366 if(x->ex_flags & EXFLAG_NSCERT) {
367 if(x->ex_nscert & NS_SSL_CA) return ca_ret;
368 return 0;
369 }
370 if(ca_ret != 2) return ca_ret;
371 else return 0;
372 }
373 /* We need to do digital signatures with it */
374 if(ku_reject(x,KU_DIGITAL_SIGNATURE)) return 0;
375 /* nsCertType if present should allow SSL client use */
376 if(ns_reject(x, NS_SSL_CLIENT)) return 0;
377 return 1;
378}
379
380static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
381{
382 if(xku_reject(x,XKU_SSL_SERVER|XKU_SGC)) return 0;
383 /* Otherwise same as SSL client for a CA */
384 if(ca) return check_purpose_ssl_client(xp, x, 1);
385
386 if(ns_reject(x, NS_SSL_SERVER)) return 0;
387 /* Now as for keyUsage: we'll at least need to sign OR encipher */
388 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT)) return 0;
389
390 return 1;
391
392}
393
394static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
395{
396 int ret;
397 ret = check_purpose_ssl_server(xp, x, ca);
398 if(!ret || ca) return ret;
399 /* We need to encipher or Netscape complains */
400 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
401 return ret;
402}
403
404/* common S/MIME checks */
405static int purpose_smime(X509 *x, int ca)
406{
407 if(xku_reject(x,XKU_SMIME)) return 0;
408 if(ca) {
409 int ca_ret;
410 ca_ret = ca_check(x);
411 if(!ca_ret) return 0;
412 /* check nsCertType if present */
413 if(x->ex_flags & EXFLAG_NSCERT) {
414 if(x->ex_nscert & NS_SMIME_CA) return ca_ret;
415 return 0;
416 }
417 if(ca_ret != 2) return ca_ret;
418 else return 0;
419 }
420 if(x->ex_flags & EXFLAG_NSCERT) {
421 if(x->ex_nscert & NS_SMIME) return 1;
422 /* Workaround for some buggy certificates */
423 if(x->ex_nscert & NS_SSL_CLIENT) return 2;
424 return 0;
425 }
426 return 1;
427}
428
429static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca)
430{
431 int ret;
432 ret = purpose_smime(x, ca);
433 if(!ret || ca) return ret;
434 if(ku_reject(x, KU_DIGITAL_SIGNATURE)) return 0;
435 return ret;
436}
437
438static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca)
439{
440 int ret;
441 ret = purpose_smime(x, ca);
442 if(!ret || ca) return ret;
443 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
444 return ret;
445}
446
447static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca)
448{
449 if(ca) {
450 int ca_ret;
451 if((ca_ret = ca_check(x)) != 2) return ca_ret;
452 else return 0;
453 }
454 if(ku_reject(x, KU_CRL_SIGN)) return 0;
455 return 1;
456}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_skey.c b/src/lib/libssl/src/crypto/x509v3/v3_skey.c
new file mode 100644
index 0000000000..fb3e36014d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_skey.c
@@ -0,0 +1,156 @@
1/* v3_skey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/x509v3.h>
63
64static ASN1_OCTET_STRING *octet_string_new(void);
65static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
66X509V3_EXT_METHOD v3_skey_id = {
67NID_subject_key_identifier, 0,
68(X509V3_EXT_NEW)octet_string_new,
69(X509V3_EXT_FREE)ASN1_STRING_free,
70(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING,
71(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING,
72(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
73(X509V3_EXT_S2I)s2i_skey_id,
74NULL, NULL, NULL, NULL, NULL};
75
76
77static ASN1_OCTET_STRING *octet_string_new(void)
78{
79 return ASN1_OCTET_STRING_new();
80}
81
82char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
83 ASN1_OCTET_STRING *oct)
84{
85 return hex_to_string(oct->data, oct->length);
86}
87
88ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
89 X509V3_CTX *ctx, char *str)
90{
91 ASN1_OCTET_STRING *oct;
92 long length;
93
94 if(!(oct = ASN1_OCTET_STRING_new())) {
95 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
96 return NULL;
97 }
98
99 if(!(oct->data = string_to_hex(str, &length))) {
100 ASN1_OCTET_STRING_free(oct);
101 return NULL;
102 }
103
104 oct->length = length;
105
106 return oct;
107
108}
109
110static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
111 X509V3_CTX *ctx, char *str)
112{
113 ASN1_OCTET_STRING *oct;
114 ASN1_BIT_STRING *pk;
115 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
116 EVP_MD_CTX md;
117 unsigned int diglen;
118
119 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
120
121 if(!(oct = ASN1_OCTET_STRING_new())) {
122 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
123 return NULL;
124 }
125
126 if(ctx && (ctx->flags == CTX_TEST)) return oct;
127
128 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
129 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
130 goto err;
131 }
132
133 if(ctx->subject_req)
134 pk = ctx->subject_req->req_info->pubkey->public_key;
135 else pk = ctx->subject_cert->cert_info->key->public_key;
136
137 if(!pk) {
138 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
139 goto err;
140 }
141
142 EVP_DigestInit(&md, EVP_sha1());
143 EVP_DigestUpdate(&md, pk->data, pk->length);
144 EVP_DigestFinal(&md, pkey_dig, &diglen);
145
146 if(!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
147 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150
151 return oct;
152
153 err:
154 ASN1_OCTET_STRING_free(oct);
155 return NULL;
156}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_sxnet.c b/src/lib/libssl/src/crypto/x509v3/v3_sxnet.c
new file mode 100644
index 0000000000..0687bb4e3d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_sxnet.c
@@ -0,0 +1,340 @@
1/* v3_sxnet.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Support for Thawte strong extranet extension */
67
68#define SXNET_TEST
69
70static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent);
71#ifdef SXNET_TEST
72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *nval);
74#endif
75X509V3_EXT_METHOD v3_sxnet = {
76NID_sxnet, X509V3_EXT_MULTILINE,
77(X509V3_EXT_NEW)SXNET_new,
78(X509V3_EXT_FREE)SXNET_free,
79(X509V3_EXT_D2I)d2i_SXNET,
80(X509V3_EXT_I2D)i2d_SXNET,
81NULL, NULL,
82NULL,
83#ifdef SXNET_TEST
84(X509V3_EXT_V2I)sxnet_v2i,
85#else
86NULL,
87#endif
88(X509V3_EXT_I2R)sxnet_i2r,
89NULL,
90NULL
91};
92
93
94int i2d_SXNET(SXNET *a, unsigned char **pp)
95{
96 M_ASN1_I2D_vars(a);
97
98 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
99 M_ASN1_I2D_len_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
100
101 M_ASN1_I2D_seq_total();
102
103 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
104 M_ASN1_I2D_put_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
105
106 M_ASN1_I2D_finish();
107}
108
109SXNET *SXNET_new(void)
110{
111 SXNET *ret=NULL;
112 ASN1_CTX c;
113 M_ASN1_New_Malloc(ret, SXNET);
114 M_ASN1_New(ret->version,ASN1_INTEGER_new);
115 M_ASN1_New(ret->ids,sk_SXNETID_new_null);
116 return (ret);
117 M_ASN1_New_Error(ASN1_F_SXNET_NEW);
118}
119
120SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length)
121{
122 M_ASN1_D2I_vars(a,SXNET *,SXNET_new);
123 M_ASN1_D2I_Init();
124 M_ASN1_D2I_start_sequence();
125 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
126 M_ASN1_D2I_get_seq_type (SXNETID, ret->ids, d2i_SXNETID, SXNETID_free);
127 M_ASN1_D2I_Finish(a, SXNET_free, ASN1_F_D2I_SXNET);
128}
129
130void SXNET_free(SXNET *a)
131{
132 if (a == NULL) return;
133 ASN1_INTEGER_free(a->version);
134 sk_SXNETID_pop_free(a->ids, SXNETID_free);
135 Free (a);
136}
137
138int i2d_SXNETID(SXNETID *a, unsigned char **pp)
139{
140 M_ASN1_I2D_vars(a);
141
142 M_ASN1_I2D_len (a->zone, i2d_ASN1_INTEGER);
143 M_ASN1_I2D_len (a->user, i2d_ASN1_OCTET_STRING);
144
145 M_ASN1_I2D_seq_total();
146
147 M_ASN1_I2D_put (a->zone, i2d_ASN1_INTEGER);
148 M_ASN1_I2D_put (a->user, i2d_ASN1_OCTET_STRING);
149
150 M_ASN1_I2D_finish();
151}
152
153SXNETID *SXNETID_new(void)
154{
155 SXNETID *ret=NULL;
156 ASN1_CTX c;
157 M_ASN1_New_Malloc(ret, SXNETID);
158 ret->zone = NULL;
159 M_ASN1_New(ret->user,ASN1_OCTET_STRING_new);
160 return (ret);
161 M_ASN1_New_Error(ASN1_F_SXNETID_NEW);
162}
163
164SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length)
165{
166 M_ASN1_D2I_vars(a,SXNETID *,SXNETID_new);
167 M_ASN1_D2I_Init();
168 M_ASN1_D2I_start_sequence();
169 M_ASN1_D2I_get(ret->zone, d2i_ASN1_INTEGER);
170 M_ASN1_D2I_get(ret->user, d2i_ASN1_OCTET_STRING);
171 M_ASN1_D2I_Finish(a, SXNETID_free, ASN1_F_D2I_SXNETID);
172}
173
174void SXNETID_free(SXNETID *a)
175{
176 if (a == NULL) return;
177 ASN1_INTEGER_free(a->zone);
178 ASN1_OCTET_STRING_free(a->user);
179 Free (a);
180}
181
182static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
183 int indent)
184{
185 long v;
186 char *tmp;
187 SXNETID *id;
188 int i;
189 v = ASN1_INTEGER_get(sx->version);
190 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
191 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
192 id = sk_SXNETID_value(sx->ids, i);
193 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
194 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
195 Free(tmp);
196 ASN1_OCTET_STRING_print(out, id->user);
197 }
198 return 1;
199}
200
201#ifdef SXNET_TEST
202
203/* NBB: this is used for testing only. It should *not* be used for anything
204 * else because it will just take static IDs from the configuration file and
205 * they should really be separate values for each user.
206 */
207
208
209static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
210 STACK_OF(CONF_VALUE) *nval)
211{
212 CONF_VALUE *cnf;
213 SXNET *sx = NULL;
214 int i;
215 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
216 cnf = sk_CONF_VALUE_value(nval, i);
217 if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
218 return NULL;
219 }
220 return sx;
221}
222
223
224#endif
225
226/* Strong Extranet utility functions */
227
228/* Add an id given the zone as an ASCII number */
229
230int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
231 int userlen)
232{
233 ASN1_INTEGER *izone = NULL;
234 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
235 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
236 return 0;
237 }
238 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
239}
240
241/* Add an id given the zone as an unsigned long */
242
243int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
244 int userlen)
245{
246 ASN1_INTEGER *izone = NULL;
247 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
249 ASN1_INTEGER_free(izone);
250 return 0;
251 }
252 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
253
254}
255
256/* Add an id given the zone as an ASN1_INTEGER.
257 * Note this version uses the passed integer and doesn't make a copy so don't
258 * free it up afterwards.
259 */
260
261int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
262 int userlen)
263{
264 SXNET *sx = NULL;
265 SXNETID *id = NULL;
266 if(!psx || !zone || !user) {
267 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
268 return 0;
269 }
270 if(userlen == -1) userlen = strlen(user);
271 if(userlen > 64) {
272 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
273 return 0;
274 }
275 if(!*psx) {
276 if(!(sx = SXNET_new())) goto err;
277 if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
278 *psx = sx;
279 } else sx = *psx;
280 if(SXNET_get_id_INTEGER(sx, zone)) {
281 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
282 return 0;
283 }
284
285 if(!(id = SXNETID_new())) goto err;
286 if(userlen == -1) userlen = strlen(user);
287
288 if(!ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
289 if(!sk_SXNETID_push(sx->ids, id)) goto err;
290 id->zone = zone;
291 return 1;
292
293 err:
294 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
295 SXNETID_free(id);
296 SXNET_free(sx);
297 *psx = NULL;
298 return 0;
299}
300
301ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
302{
303 ASN1_INTEGER *izone = NULL;
304 ASN1_OCTET_STRING *oct;
305 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
306 X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
307 return NULL;
308 }
309 oct = SXNET_get_id_INTEGER(sx, izone);
310 ASN1_INTEGER_free(izone);
311 return oct;
312}
313
314ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
315{
316 ASN1_INTEGER *izone = NULL;
317 ASN1_OCTET_STRING *oct;
318 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
320 ASN1_INTEGER_free(izone);
321 return NULL;
322 }
323 oct = SXNET_get_id_INTEGER(sx, izone);
324 ASN1_INTEGER_free(izone);
325 return oct;
326}
327
328ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
329{
330 SXNETID *id;
331 int i;
332 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
333 id = sk_SXNETID_value(sx->ids, i);
334 if(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
335 }
336 return NULL;
337}
338
339IMPLEMENT_STACK_OF(SXNETID)
340IMPLEMENT_ASN1_SET_OF(SXNETID)
diff --git a/src/lib/libssl/src/crypto/x509v3/v3_utl.c b/src/lib/libssl/src/crypto/x509v3/v3_utl.c
new file mode 100644
index 0000000000..40f71c71b4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3_utl.c
@@ -0,0 +1,418 @@
1/* v3_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60
61#include <stdio.h>
62#include <ctype.h>
63#include "cryptlib.h"
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static char *strip_spaces(char *name);
68
69/* Add a CONF_VALUE name value pair to stack */
70
71int X509V3_add_value(const char *name, const char *value,
72 STACK_OF(CONF_VALUE) **extlist)
73{
74 CONF_VALUE *vtmp = NULL;
75 char *tname = NULL, *tvalue = NULL;
76 if(name && !(tname = BUF_strdup(name))) goto err;
77 if(value && !(tvalue = BUF_strdup(value))) goto err;;
78 if(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err;
79 if(!*extlist && !(*extlist = sk_CONF_VALUE_new(NULL))) goto err;
80 vtmp->section = NULL;
81 vtmp->name = tname;
82 vtmp->value = tvalue;
83 if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
84 return 1;
85 err:
86 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
87 if(vtmp) Free(vtmp);
88 if(tname) Free(tname);
89 if(tvalue) Free(tvalue);
90 return 0;
91}
92
93int X509V3_add_value_uchar(const char *name, const unsigned char *value,
94 STACK_OF(CONF_VALUE) **extlist)
95 {
96 return X509V3_add_value(name,(const char *)value,extlist);
97 }
98
99/* Free function for STACK_OF(CONF_VALUE) */
100
101void X509V3_conf_free(CONF_VALUE *conf)
102{
103 if(!conf) return;
104 if(conf->name) Free(conf->name);
105 if(conf->value) Free(conf->value);
106 if(conf->section) Free(conf->section);
107 Free((char *)conf);
108}
109
110int X509V3_add_value_bool(const char *name, int asn1_bool,
111 STACK_OF(CONF_VALUE) **extlist)
112{
113 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
114 return X509V3_add_value(name, "FALSE", extlist);
115}
116
117int X509V3_add_value_bool_nf(char *name, int asn1_bool,
118 STACK_OF(CONF_VALUE) **extlist)
119{
120 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
121 return 1;
122}
123
124
125char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
126{
127 BIGNUM *bntmp = NULL;
128 char *strtmp = NULL;
129 if(!a) return NULL;
130 if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
131 !(strtmp = BN_bn2dec(bntmp)) )
132 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
133 BN_free(bntmp);
134 return strtmp;
135}
136
137char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
138{
139 BIGNUM *bntmp = NULL;
140 char *strtmp = NULL;
141 if(!a) return NULL;
142 if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
143 !(strtmp = BN_bn2dec(bntmp)) )
144 X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
145 BN_free(bntmp);
146 return strtmp;
147}
148
149ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
150{
151 BIGNUM *bn = NULL;
152 ASN1_INTEGER *aint;
153 bn = BN_new();
154 if(!value) {
155 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
156 return 0;
157 }
158 if(!BN_dec2bn(&bn, value)) {
159 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
160 return 0;
161 }
162
163 if(!(aint = BN_to_ASN1_INTEGER(bn, NULL))) {
164 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
165 return 0;
166 }
167 BN_free(bn);
168 return aint;
169}
170
171int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
172 STACK_OF(CONF_VALUE) **extlist)
173{
174 char *strtmp;
175 int ret;
176 if(!aint) return 1;
177 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
178 ret = X509V3_add_value(name, strtmp, extlist);
179 Free(strtmp);
180 return ret;
181}
182
183int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
184{
185 char *btmp;
186 if(!(btmp = value->value)) goto err;
187 if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
188 || !strcmp(btmp, "Y") || !strcmp(btmp, "y")
189 || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
190 *asn1_bool = 0xff;
191 return 1;
192 } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
193 || !strcmp(btmp, "N") || !strcmp(btmp, "n")
194 || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
195 *asn1_bool = 0;
196 return 1;
197 }
198 err:
199 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING);
200 X509V3_conf_err(value);
201 return 0;
202}
203
204int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
205{
206 ASN1_INTEGER *itmp;
207 if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
208 X509V3_conf_err(value);
209 return 0;
210 }
211 *aint = itmp;
212 return 1;
213}
214
215#define HDR_NAME 1
216#define HDR_VALUE 2
217
218/*#define DEBUG*/
219
220STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
221{
222 char *p, *q, c;
223 char *ntmp, *vtmp;
224 STACK_OF(CONF_VALUE) *values = NULL;
225 char *linebuf;
226 int state;
227 /* We are going to modify the line so copy it first */
228 linebuf = BUF_strdup(line);
229 state = HDR_NAME;
230 ntmp = NULL;
231 /* Go through all characters */
232 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
233
234 switch(state) {
235 case HDR_NAME:
236 if(c == ':') {
237 state = HDR_VALUE;
238 *p = 0;
239 ntmp = strip_spaces(q);
240 if(!ntmp) {
241 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
242 goto err;
243 }
244 q = p + 1;
245 } else if(c == ',') {
246 *p = 0;
247 ntmp = strip_spaces(q);
248 q = p + 1;
249#ifdef DEBUG
250 printf("%s\n", ntmp);
251#endif
252 if(!ntmp) {
253 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
254 goto err;
255 }
256 X509V3_add_value(ntmp, NULL, &values);
257 }
258 break ;
259
260 case HDR_VALUE:
261 if(c == ',') {
262 state = HDR_NAME;
263 *p = 0;
264 vtmp = strip_spaces(q);
265#ifdef DEBUG
266 printf("%s\n", ntmp);
267#endif
268 if(!vtmp) {
269 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
270 goto err;
271 }
272 X509V3_add_value(ntmp, vtmp, &values);
273 ntmp = NULL;
274 q = p + 1;
275 }
276
277 }
278 }
279
280 if(state == HDR_VALUE) {
281 vtmp = strip_spaces(q);
282#ifdef DEBUG
283 printf("%s=%s\n", ntmp, vtmp);
284#endif
285 if(!vtmp) {
286 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
287 goto err;
288 }
289 X509V3_add_value(ntmp, vtmp, &values);
290 } else {
291 ntmp = strip_spaces(q);
292#ifdef DEBUG
293 printf("%s\n", ntmp);
294#endif
295 if(!ntmp) {
296 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
297 goto err;
298 }
299 X509V3_add_value(ntmp, NULL, &values);
300 }
301Free(linebuf);
302return values;
303
304err:
305Free(linebuf);
306sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
307return NULL;
308
309}
310
311/* Delete leading and trailing spaces from a string */
312static char *strip_spaces(char *name)
313{
314 char *p, *q;
315 /* Skip over leading spaces */
316 p = name;
317 while(*p && isspace((unsigned char)*p)) p++;
318 if(!*p) return NULL;
319 q = p + strlen(p) - 1;
320 while((q != p) && isspace((unsigned char)*q)) q--;
321 if(p != q) q[1] = 0;
322 if(!*p) return NULL;
323 return p;
324}
325
326/* hex string utilities */
327
328/* Given a buffer of length 'len' return a Malloc'ed string with its
329 * hex representation
330 */
331
332char *hex_to_string(unsigned char *buffer, long len)
333{
334 char *tmp, *q;
335 unsigned char *p;
336 int i;
337 static char hexdig[] = "0123456789ABCDEF";
338 if(!buffer || !len) return NULL;
339 if(!(tmp = Malloc(len * 3 + 1))) {
340 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
341 return NULL;
342 }
343 q = tmp;
344 for(i = 0, p = buffer; i < len; i++,p++) {
345 *q++ = hexdig[(*p >> 4) & 0xf];
346 *q++ = hexdig[*p & 0xf];
347 *q++ = ':';
348 }
349 q[-1] = 0;
350 return tmp;
351}
352
353/* Give a string of hex digits convert to
354 * a buffer
355 */
356
357unsigned char *string_to_hex(char *str, long *len)
358{
359 unsigned char *hexbuf, *q;
360 unsigned char ch, cl, *p;
361 if(!str) {
362 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
363 return NULL;
364 }
365 if(!(hexbuf = Malloc(strlen(str) >> 1))) goto err;
366 for(p = (unsigned char *)str, q = hexbuf; *p;) {
367 ch = *p++;
368 if(ch == ':') continue;
369 cl = *p++;
370 if(!cl) {
371 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
372 Free(hexbuf);
373 return NULL;
374 }
375 if(isupper(ch)) ch = tolower(ch);
376 if(isupper(cl)) cl = tolower(cl);
377
378 if((ch >= '0') && (ch <= '9')) ch -= '0';
379 else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
380 else goto badhex;
381
382 if((cl >= '0') && (cl <= '9')) cl -= '0';
383 else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
384 else goto badhex;
385
386 *q++ = (ch << 4) | cl;
387 }
388
389 if(len) *len = q - hexbuf;
390
391 return hexbuf;
392
393 err:
394 if(hexbuf) Free(hexbuf);
395 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
396 return NULL;
397
398 badhex:
399 Free(hexbuf);
400 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
401 return NULL;
402
403}
404
405/* V2I name comparison function: returns zero if 'name' matches
406 * cmp or cmp.*
407 */
408
409int name_cmp(const char *name, const char *cmp)
410{
411 int len, ret;
412 char c;
413 len = strlen(cmp);
414 if((ret = strncmp(name, cmp, len))) return ret;
415 c = name[len];
416 if(!c || (c=='.')) return 0;
417 return 1;
418}
diff --git a/src/lib/libssl/src/crypto/x509v3/v3conf.c b/src/lib/libssl/src/crypto/x509v3/v3conf.c
new file mode 100644
index 0000000000..21cf746f45
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3conf.c
@@ -0,0 +1,128 @@
1/* v3conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68/* Test application to add extensions from a config file */
69
70int main(int argc, char **argv)
71{
72 LHASH *conf;
73 X509 *cert;
74 FILE *inf;
75 char *conf_file;
76 int i;
77 int count;
78 X509_EXTENSION *ext;
79 X509V3_add_standard_extensions();
80 ERR_load_crypto_strings();
81 if(!argv[1]) {
82 fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
83 exit(1);
84 }
85 conf_file = argv[2];
86 if(!conf_file) conf_file = "test.cnf";
87 conf = CONF_load(NULL, "test.cnf", NULL);
88 if(!conf) {
89 fprintf(stderr, "Error opening Config file %s\n", conf_file);
90 ERR_print_errors_fp(stderr);
91 exit(1);
92 }
93
94 inf = fopen(argv[1], "r");
95 if(!inf) {
96 fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
97 exit(1);
98 }
99 cert = PEM_read_X509(inf, NULL, NULL);
100 if(!cert) {
101 fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
102 exit(1);
103 }
104 fclose(inf);
105
106 sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
107 cert->cert_info->extensions = NULL;
108
109 if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
110 fprintf(stderr, "Error adding extensions\n");
111 ERR_print_errors_fp(stderr);
112 exit(1);
113 }
114
115 count = X509_get_ext_count(cert);
116 printf("%d extensions\n", count);
117 for(i = 0; i < count; i++) {
118 ext = X509_get_ext(cert, i);
119 printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
120 if(ext->critical) printf(",critical:\n");
121 else printf(":\n");
122 X509V3_EXT_print_fp(stdout, ext, 0);
123 printf("\n");
124
125 }
126 return 0;
127}
128
diff --git a/src/lib/libssl/src/crypto/x509v3/v3err.c b/src/lib/libssl/src/crypto/x509v3/v3err.c
new file mode 100644
index 0000000000..50efa8d99d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3err.c
@@ -0,0 +1,171 @@
1/* crypto/x509v3/v3err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/x509v3.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA X509V3_str_functs[]=
67 {
68{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"},
69{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"},
70{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"},
71{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"},
72{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
73{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
75{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
76{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
77{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
78{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"},
79{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"},
80{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"},
81{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"},
82{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"},
83{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"},
84{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"},
85{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"},
86{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"},
87{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
88{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
89{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
90{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
91{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
92{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
93{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"},
94{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"},
95{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"},
96{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"},
97{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"},
98{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"},
99{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"},
100{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"},
101{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"},
102{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
103{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
104{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
105{0,NULL}
106 };
107
108static ERR_STRING_DATA X509V3_str_reasons[]=
109 {
110{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"},
111{X509V3_R_BAD_OBJECT ,"bad object"},
112{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"},
113{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"},
114{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"},
115{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"},
116{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"},
117{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"},
118{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"},
119{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"},
120{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"},
121{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"},
122{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"},
123{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"},
124{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"},
125{X509V3_R_INVALID_NAME ,"invalid name"},
126{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
127{X509V3_R_INVALID_NULL_NAME ,"invalid null name"},
128{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"},
129{X509V3_R_INVALID_NUMBER ,"invalid number"},
130{X509V3_R_INVALID_NUMBERS ,"invalid numbers"},
131{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"},
132{X509V3_R_INVALID_OPTION ,"invalid option"},
133{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
134{X509V3_R_INVALID_SECTION ,"invalid section"},
135{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
136{X509V3_R_MISSING_VALUE ,"missing value"},
137{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
138{X509V3_R_NO_CONFIG_DATABASE ,"no config database"},
139{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"},
140{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"},
141{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"},
142{X509V3_R_NO_PUBLIC_KEY ,"no public key"},
143{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"},
144{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"},
145{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"},
146{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"},
147{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"},
148{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"},
149{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"},
150{X509V3_R_UNKNOWN_OPTION ,"unknown option"},
151{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"},
152{X509V3_R_USER_TOO_LONG ,"user too long"},
153{0,NULL}
154 };
155
156#endif
157
158void ERR_load_X509V3_strings(void)
159 {
160 static int init=1;
161
162 if (init)
163 {
164 init=0;
165#ifndef NO_ERR
166 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs);
167 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons);
168#endif
169
170 }
171 }
diff --git a/src/lib/libssl/src/crypto/x509v3/v3prin.c b/src/lib/libssl/src/crypto/x509v3/v3prin.c
new file mode 100644
index 0000000000..ee798859f0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/v3prin.c
@@ -0,0 +1,101 @@
1/* v3prin.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/asn1.h>
64#include <openssl/asn1_mac.h>
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69int main(int argc, char **argv)
70{
71 X509 *cert;
72 FILE *inf;
73 int i, count;
74 X509_EXTENSION *ext;
75 X509V3_add_standard_extensions();
76 ERR_load_crypto_strings();
77 if(!argv[1]) {
78 fprintf(stderr, "Usage v3prin cert.pem\n");
79 exit(1);
80 }
81 if(!(inf = fopen(argv[1], "r"))) {
82 fprintf(stderr, "Can't open %s\n", argv[1]);
83 exit(1);
84 }
85 if(!(cert = PEM_read_X509(inf, NULL, NULL))) {
86 fprintf(stderr, "Can't read certificate %s\n", argv[1]);
87 ERR_print_errors_fp(stderr);
88 exit(1);
89 }
90 fclose(inf);
91 count = X509_get_ext_count(cert);
92 printf("%d extensions\n", count);
93 for(i = 0; i < count; i++) {
94 ext = X509_get_ext(cert, i);
95 printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
96 if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr);
97 printf("\n");
98
99 }
100 return 0;
101}
diff --git a/src/lib/libssl/src/demos/asn1/README.ASN1 b/src/lib/libssl/src/demos/asn1/README.ASN1
new file mode 100644
index 0000000000..ac497be184
--- /dev/null
+++ b/src/lib/libssl/src/demos/asn1/README.ASN1
@@ -0,0 +1,7 @@
1This is a demo of the new ASN1 code. Its an OCSP ASN1 module. Doesn't
2do much yet other than demonstrate what the new ASN1 modules might look
3like.
4
5It wont even compile yet: the new code isn't in place.
6
7
diff --git a/src/lib/libssl/src/demos/asn1/ocsp.c b/src/lib/libssl/src/demos/asn1/ocsp.c
new file mode 100644
index 0000000000..0199fe1004
--- /dev/null
+++ b/src/lib/libssl/src/demos/asn1/ocsp.c
@@ -0,0 +1,366 @@
1/* ocsp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/x509v3.h>
61
62
63
64
65/* Example of new ASN1 code, OCSP request
66
67 OCSPRequest ::= SEQUENCE {
68 tbsRequest TBSRequest,
69 optionalSignature [0] EXPLICIT Signature OPTIONAL }
70
71 TBSRequest ::= SEQUENCE {
72 version [0] EXPLICIT Version DEFAULT v1,
73 requestorName [1] EXPLICIT GeneralName OPTIONAL,
74 requestList SEQUENCE OF Request,
75 requestExtensions [2] EXPLICIT Extensions OPTIONAL }
76
77 Signature ::= SEQUENCE {
78 signatureAlgorithm AlgorithmIdentifier,
79 signature BIT STRING,
80 certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
81
82 Version ::= INTEGER { v1(0) }
83
84 Request ::= SEQUENCE {
85 reqCert CertID,
86 singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
87
88 CertID ::= SEQUENCE {
89 hashAlgorithm AlgorithmIdentifier,
90 issuerNameHash OCTET STRING, -- Hash of Issuer's DN
91 issuerKeyHash OCTET STRING, -- Hash of Issuers public key
92 serialNumber CertificateSerialNumber }
93
94 OCSPResponse ::= SEQUENCE {
95 responseStatus OCSPResponseStatus,
96 responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
97
98 OCSPResponseStatus ::= ENUMERATED {
99 successful (0), --Response has valid confirmations
100 malformedRequest (1), --Illegal confirmation request
101 internalError (2), --Internal error in issuer
102 tryLater (3), --Try again later
103 --(4) is not used
104 sigRequired (5), --Must sign the request
105 unauthorized (6) --Request unauthorized
106 }
107
108 ResponseBytes ::= SEQUENCE {
109 responseType OBJECT IDENTIFIER,
110 response OCTET STRING }
111
112 BasicOCSPResponse ::= SEQUENCE {
113 tbsResponseData ResponseData,
114 signatureAlgorithm AlgorithmIdentifier,
115 signature BIT STRING,
116 certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
117
118 ResponseData ::= SEQUENCE {
119 version [0] EXPLICIT Version DEFAULT v1,
120 responderID ResponderID,
121 producedAt GeneralizedTime,
122 responses SEQUENCE OF SingleResponse,
123 responseExtensions [1] EXPLICIT Extensions OPTIONAL }
124
125 ResponderID ::= CHOICE {
126 byName [1] Name, --EXPLICIT
127 byKey [2] KeyHash }
128
129 KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key
130 --(excluding the tag and length fields)
131
132 SingleResponse ::= SEQUENCE {
133 certID CertID,
134 certStatus CertStatus,
135 thisUpdate GeneralizedTime,
136 nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
137 singleExtensions [1] EXPLICIT Extensions OPTIONAL }
138
139 CertStatus ::= CHOICE {
140 good [0] IMPLICIT NULL,
141 revoked [1] IMPLICIT RevokedInfo,
142 unknown [2] IMPLICIT UnknownInfo }
143
144 RevokedInfo ::= SEQUENCE {
145 revocationTime GeneralizedTime,
146 revocationReason [0] EXPLICIT CRLReason OPTIONAL }
147
148 UnknownInfo ::= NULL -- this can be replaced with an enumeration
149
150 ArchiveCutoff ::= GeneralizedTime
151
152 AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER
153
154 ServiceLocator ::= SEQUENCE {
155 issuer Name,
156 locator AuthorityInfoAccessSyntax }
157
158 -- Object Identifiers
159
160 id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 }
161 id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp }
162 id-pkix-ocsp-basic OBJECT IDENTIFIER ::= { id-pkix-ocsp 1 }
163 id-pkix-ocsp-nonce OBJECT IDENTIFIER ::= { id-pkix-ocsp 2 }
164 id-pkix-ocsp-crl OBJECT IDENTIFIER ::= { id-pkix-ocsp 3 }
165 id-pkix-ocsp-response OBJECT IDENTIFIER ::= { id-pkix-ocsp 4 }
166 id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 }
167 id-pkix-ocsp-archive-cutoff OBJECT IDENTIFIER ::= { id-pkix-ocsp 6 }
168 id-pkix-ocsp-service-locator OBJECT IDENTIFIER ::= { id-pkix-ocsp 7 }
169
170*/
171
172/* Request Structures */
173
174DECLARE_STACK_OF(Request)
175
176typedef struct {
177 ASN1_INTEGER *version;
178 GENERAL_NAME *requestorName;
179 STACK_OF(Request) *requestList;
180 STACK_OF(X509_EXTENSION) *requestExtensions;
181} TBSRequest;
182
183typedef struct {
184 X509_ALGOR *signatureAlgorithm;
185 ASN1_BIT_STRING *signature;
186 STACK_OF(X509) *certs;
187} Signature;
188
189typedef struct {
190 TBSRequest *tbsRequest;
191 Signature *optionalSignature;
192} OCSPRequest;
193
194typedef struct {
195 X509_ALGOR *hashAlgorithm;
196 ASN1_OCTET_STRING *issuerNameHash;
197 ASN1_OCTET_STRING *issuerKeyHash;
198 ASN1_INTEGER *certificateSerialNumber;
199} CertID;
200
201typedef struct {
202 CertID *reqCert;
203 STACK_OF(X509_EXTENSION) *singleRequestExtensions;
204} Request;
205
206/* Response structures */
207
208typedef struct {
209 ASN1_OBJECT *responseType;
210 ASN1_OCTET_STRING *response;
211} ResponseBytes;
212
213typedef struct {
214 ASN1_ENUMERATED *responseStatus;
215 ResponseBytes *responseBytes;
216} OCSPResponse;
217
218typedef struct {
219 int type;
220 union {
221 X509_NAME *byName;
222 ASN1_OCTET_STRING *byKey;
223 }d;
224} ResponderID;
225
226typedef struct {
227 ASN1_INTEGER *version;
228 ResponderID *responderID;
229 ASN1_GENERALIZEDTIME *producedAt;
230 STACK_OF(SingleResponse) *responses;
231 STACK_OF(X509_EXTENSION) *responseExtensions;
232} ResponseData;
233
234typedef struct {
235 ResponseData *tbsResponseData;
236 X509_ALGOR *signatureAlgorithm;
237 ASN1_BIT_STRING *signature;
238 STACK_OF(X509) *certs;
239} BasicOCSPResponse;
240
241typedef struct {
242 ASN1_GENERALIZEDTIME *revocationTime;
243 ASN1_ENUMERATED * revocationReason;
244} RevokedInfo;
245
246typedef struct {
247 int type;
248 union {
249 ASN1_NULL *good;
250 RevokedInfo *revoked;
251 ASN1_NULL *unknown;
252 } d;
253} CertStatus;
254
255typedef struct {
256 CertID *certID;
257 CertStatus *certStatus;
258 ASN1_GENERALIZEDTIME *thisUpdate;
259 ASN1_GENERALIZEDTIME *nextUpdate;
260 STACK_OF(X509_EXTENSION) *singleExtensions;
261} SingleResponse;
262
263
264typedef struct {
265 X509_NAME *issuer;
266 STACK_OF(ACCESS_DESCRIPTION) *locator;
267} ServiceLocator;
268
269
270/* Now the ASN1 templates */
271
272IMPLEMENT_COMPAT_ASN1(X509);
273IMPLEMENT_COMPAT_ASN1(X509_ALGOR);
274//IMPLEMENT_COMPAT_ASN1(X509_EXTENSION);
275IMPLEMENT_COMPAT_ASN1(GENERAL_NAME);
276IMPLEMENT_COMPAT_ASN1(X509_NAME);
277
278ASN1_SEQUENCE(X509_EXTENSION) = {
279 ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT),
280 ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN),
281 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
282} ASN1_SEQUENCE_END(X509_EXTENSION);
283
284
285ASN1_SEQUENCE(Signature) = {
286 ASN1_SIMPLE(Signature, signatureAlgorithm, X509_ALGOR),
287 ASN1_SIMPLE(Signature, signature, ASN1_BIT_STRING),
288 ASN1_SEQUENCE_OF(Signature, certs, X509)
289} ASN1_SEQUENCE_END(Signature);
290
291ASN1_SEQUENCE(CertID) = {
292 ASN1_SIMPLE(CertID, hashAlgorithm, X509_ALGOR),
293 ASN1_SIMPLE(CertID, issuerNameHash, ASN1_OCTET_STRING),
294 ASN1_SIMPLE(CertID, issuerKeyHash, ASN1_OCTET_STRING),
295 ASN1_SIMPLE(CertID, certificateSerialNumber, ASN1_INTEGER)
296} ASN1_SEQUENCE_END(CertID);
297
298ASN1_SEQUENCE(Request) = {
299 ASN1_SIMPLE(Request, reqCert, CertID),
300 ASN1_EXP_SEQUENCE_OF_OPT(Request, singleRequestExtensions, X509_EXTENSION, 0)
301} ASN1_SEQUENCE_END(Request);
302
303ASN1_SEQUENCE(TBSRequest) = {
304 ASN1_EXP_OPT(TBSRequest, version, ASN1_INTEGER, 0),
305 ASN1_EXP_OPT(TBSRequest, requestorName, GENERAL_NAME, 1),
306 ASN1_SEQUENCE_OF(TBSRequest, requestList, Request),
307 ASN1_EXP_SEQUENCE_OF_OPT(TBSRequest, requestExtensions, X509_EXTENSION, 2)
308} ASN1_SEQUENCE_END(TBSRequest);
309
310ASN1_SEQUENCE(OCSPRequest) = {
311 ASN1_SIMPLE(OCSPRequest, tbsRequest, TBSRequest),
312 ASN1_EXP_OPT(OCSPRequest, optionalSignature, Signature, 0)
313} ASN1_SEQUENCE_END(OCSPRequest);
314
315
316/* Response templates */
317
318ASN1_SEQUENCE(ResponseBytes) = {
319 ASN1_SIMPLE(ResponseBytes, responseType, ASN1_OBJECT),
320 ASN1_SIMPLE(ResponseBytes, response, ASN1_OCTET_STRING)
321} ASN1_SEQUENCE_END(ResponseBytes);
322
323ASN1_SEQUENCE(OCSPResponse) = {
324 ASN1_SIMPLE(OCSPResponse, responseStatus, ASN1_ENUMERATED),
325 ASN1_EXP_OPT(OCSPResponse, responseBytes, ResponseBytes, 0)
326} ASN1_SEQUENCE_END(OCSPResponse);
327
328ASN1_CHOICE(ResponderID) = {
329 ASN1_EXP(ResponderID, d.byName, X509_NAME, 1),
330 ASN1_IMP(ResponderID, d.byKey, ASN1_OCTET_STRING, 2)
331} ASN1_CHOICE_END(ResponderID);
332
333ASN1_SEQUENCE(RevokedInfo) = {
334 ASN1_SIMPLE(RevokedInfo, revocationTime, ASN1_GENERALIZEDTIME),
335 ASN1_EXP_OPT(RevokedInfo, revocationReason, ASN1_ENUMERATED, 0)
336} ASN1_SEQUENCE_END(RevokedInfo);
337
338ASN1_CHOICE(CertStatus) = {
339 ASN1_IMP(CertStatus, d.good, ASN1_NULL, 0),
340 ASN1_IMP(CertStatus, d.revoked, RevokedInfo, 1),
341 ASN1_IMP(CertStatus, d.unknown, ASN1_NULL, 2)
342} ASN1_CHOICE_END(CertStatus);
343
344ASN1_SEQUENCE(SingleResponse) = {
345 ASN1_SIMPLE(SingleResponse, certID, CertID),
346 ASN1_SIMPLE(SingleResponse, certStatus, CertStatus),
347 ASN1_SIMPLE(SingleResponse, thisUpdate, ASN1_GENERALIZEDTIME),
348 ASN1_EXP_OPT(SingleResponse, nextUpdate, ASN1_GENERALIZEDTIME, 0),
349 ASN1_EXP_SEQUENCE_OF_OPT(SingleResponse, singleExtensions, X509_EXTENSION, 1)
350} ASN1_SEQUENCE_END(SingleResponse);
351
352ASN1_SEQUENCE(ResponseData) = {
353 ASN1_EXP_OPT(ResponseData, version, ASN1_INTEGER, 0),
354 ASN1_SIMPLE(ResponseData, responderID, ResponderID),
355 ASN1_SIMPLE(ResponseData, producedAt, ASN1_GENERALIZEDTIME),
356 ASN1_SEQUENCE_OF(ResponseData, responses, SingleResponse),
357 ASN1_EXP_SEQUENCE_OF_OPT(ResponseData, responseExtensions, X509_EXTENSION, 1)
358} ASN1_SEQUENCE_END(ResponseData);
359
360ASN1_SEQUENCE(BasicOCSPResponse) = {
361 ASN1_SIMPLE(BasicOCSPResponse, tbsResponseData, ResponseData),
362 ASN1_SIMPLE(BasicOCSPResponse, signatureAlgorithm, X509_ALGOR),
363 ASN1_SIMPLE(BasicOCSPResponse, signature, ASN1_BIT_STRING),
364 ASN1_EXP_SEQUENCE_OF_OPT(BasicOCSPResponse, certs, X509, 0)
365} ASN1_SEQUENCE_END(BasicOCSPResponse);
366
diff --git a/src/lib/libssl/src/demos/bio/Makefile b/src/lib/libssl/src/demos/bio/Makefile
new file mode 100644
index 0000000000..4351540532
--- /dev/null
+++ b/src/lib/libssl/src/demos/bio/Makefile
@@ -0,0 +1,16 @@
1CC=cc
2CFLAGS= -g -I../../include
3LIBS= -L../.. ../../libssl.a ../../libcrypto.a
4EXAMPLES=saccept sconnect
5
6all: $(EXAMPLES)
7
8saccept: saccept.o
9 $(CC) -o saccept saccept.o $(LIBS)
10
11sconnect: sconnect.o
12 $(CC) -o sconnect sconnect.o $(LIBS)
13
14clean:
15 rm -f $(EXAMPLES) *.o
16
diff --git a/src/lib/libssl/src/demos/easy_tls/Makefile b/src/lib/libssl/src/demos/easy_tls/Makefile
new file mode 100644
index 0000000000..fd3c246ef4
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/Makefile
@@ -0,0 +1,123 @@
1# Makefile for easy-tls example application (rudimentary client and server)
2# $Id: Makefile,v 1.1 2002/05/15 02:29:18 beck Exp $
3
4SOLARIS_CFLAGS=-Wall -pedantic -g -O2
5SOLARIS_LIBS=-lxnet
6
7LINUX_CFLAGS=-Wall -pedantic -g -O2
8LINUX_LIBS=
9
10
11auto-all:
12 case `uname -s` in \
13 SunOS) echo Using SunOS configuration; \
14 make SYSCFLAGS="$(SOLARIS_CFLAGS)" SYSLIBS="$(SOLARIS_LIBS)" all;; \
15 Linux) echo Using Linux configuration; \
16 make SYSCFLAGS="$(LINUX_CFLAGS)" SYSLIBS="$(LINUX_LIBS)" all;; \
17 *) echo "unknown system"; exit 1;; \
18 esac
19
20all: test TAGS
21
22# For adapting this Makefile to a different system, only the following
23# definitions should need customizing:
24
25OPENSSLDIR=../..
26CC=gcc
27
28SYSCFLAGS=whatever
29SYSLIBS=whatever
30
31
32#############################################################################
33#
34# SSLeay/OpenSSL imports
35#
36# OPENSSLDIR (set above) can be either the directory where OpenSSL is
37# installed or the directory where it was compiled.
38
39# We rely on having a new OpenSSL release where include files
40# have names like <openssl/ssl.h> (not just <ssl.h>).
41OPENSSLINCLUDES=-I$(OPENSSLDIR)/include
42
43# libcrypto.a and libssl.a are directly in $(OPENSSLDIR) if this is
44# the compile directory, or in $(OPENSSLDIR)/lib if we use an installed
45# library. With the following definition, we can handle either case.
46OPENSSLLIBS=-L$(OPENSSLDIR) -L$(OPENSSLDIR)/lib -lssl -lcrypto
47
48
49#############################################################################
50#
51# Stuff for handling the source files
52#
53
54SOURCES=easy-tls.c test.c
55HEADERS=easy-tls.h test.h
56DOCSandEXAMPLESetc=Makefile cert.pem cacerts.pem
57EVERYTHING=$(SOURCES) $(HEADERS) $(DOCSandEXAMPLESetc)
58
59ls: ls-l
60ls-l:
61 ls -l $(EVERYTHING)
62# For RCS:
63tag:
64 -rcs -n_`date +%y%m%d`: $(EVERYTHING)
65 rcs -nMYTAG $(EVERYTHING)
66 rcs -nMYTAG: $(EVERYTHING)
67diff:
68 -rcsdiff -rMYTAG -u $(EVERYTHING)
69today:
70 -rcsdiff -r_`date +%y%m%d` -u $(EVERYTHING)
71ident:
72 for a in $(EVERYTHING); do ident $$a; done
73
74# Distribution .tar:
75easy-tls.tar.gz: $(EVERYTHING)
76 tar cvf - $(EVERYTHING) | \
77 gzip -9 > easy-tls.tar.gz
78
79# Working .tar:
80tls.tgz: $(EVERYTHING)
81 tar cfv - `find . -type f -a ! -name '*.tgz' -a ! -name '*.tar.gz'` | \
82 gzip -9 > tls.tgz
83
84# For emacs:
85etags: TAGS
86TAGS: $(SOURCES) $(HEADERS)
87 -etags $(SOURCES) $(HEADERS)
88
89
90#############################################################################
91#
92# Compilation
93#
94# The following definitions are system dependent (and hence defined
95# at the beginning of this Makefile, where they are more easily found):
96
97### CC=gcc
98### SYSCFLAGS=-Wall -pedantic -g -O2
99### SYSLIBS=-lxnet
100
101EXTRACFLAGS=-DTLS_APP=\"test.h\"
102# EXTRACFLAGS=-DTLS_APP=\"test.h\" -DDEBUG_TLS
103
104#
105# The rest shouldn't need to be touched.
106#
107LDFLAGS=$(SYSLIBS) $(OPENSSLLIBS)
108INCLUDES=$(OPENSSLINCLUDES)
109CFLAGS=$(SYSCFLAGS) $(EXTRACFLAGS) $(INCLUDES)
110
111OBJS=easy-tls.o test.o
112
113clean:
114 @rm -f test
115 @rm -f TAGS
116 @rm -f *.o
117 @rm -f core
118
119test: $(OBJS)
120 $(CC) $(OBJS) $(LDFLAGS) -o test
121
122test.o: $(HEADERS)
123easy-tls.o: $(HEADERS)
diff --git a/src/lib/libssl/src/demos/easy_tls/README b/src/lib/libssl/src/demos/easy_tls/README
new file mode 100644
index 0000000000..816a58009c
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/README
@@ -0,0 +1,65 @@
1easy_tls - generic SSL/TLS proxy
2========
3
4(... and example for non-blocking SSL/TLS I/O multiplexing.)
5
6
7 easy_tls.c, easy_tls.h:
8
9 Small generic SSL/TLS proxy library: With a few function calls,
10 an application socket will be replaced by a pipe handled by a
11 separate SSL/TLS proxy process. This allows easily adding
12 SSL/TLS support to many programs not originally designed for it.
13
14 [Actually easy_tls.c is not a proper library: Customization
15 requires defining preprocessor macros while compiling it.
16 This is quite confusing, so I'll probably change it.]
17
18 These files may be used under the OpenSSL license.
19
20
21
22 test.c, test.h, Makefile, cert.pem, cacerts.pem:
23
24 Rudimentary example program using the easy_tls library, and
25 example key and certificates for it. Usage examples:
26
27 $ ./test 8443 # create server listening at port 8443
28 $ ./test 127.0.0.1 8443 # create client, connect to port 8443
29 # at IP address 127.0.0.1
30
31 'test' will not automatically do SSL/TLS, or even read or write
32 data -- it must be told to do so on input lines starting
33 with a command letter. 'W' means write a line, 'R' means
34 read a line, 'C' means close the connection, 'T' means
35 start an SSL/TLS proxy. E.g. (user input tagged with '*'):
36
37 * R
38 <<< 220 mail.example.net
39 * WSTARTTLS
40 >>> STARTTLS
41 * R
42 <<< 220 Ready to start TLS
43 * T
44 test_process_init(fd = 3, client_p = 1, apparg = (nil))
45 +++ `E:self signed certificate in certificate chain'
46 +++ `<... certificate info ...>'
47 * WHELO localhost
48 >>> HELO localhost
49 R
50 <<< 250 mail.example.net
51
52 You can even do SSL/TLS over SSL/TLS over SSL/TLS ... by using
53 'T' multiple times. I have no idea why you would want to though.
54
55
56This code is rather old. When I find time I will update anything that
57should be changed, and improve code comments. To compile the sample
58program 'test' on platforms other then Linux or Solaris, you will have
59to edit the Makefile.
60
61As noted above, easy_tls.c will be changed to become a library one
62day, which means that future revisions will not be fully compatible to
63the current version.
64
65Bodo Möller <bodo@openssl.org>
diff --git a/src/lib/libssl/src/demos/easy_tls/cacerts.pem b/src/lib/libssl/src/demos/easy_tls/cacerts.pem
new file mode 100644
index 0000000000..0b1c91f95e
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/cacerts.pem
@@ -0,0 +1,18 @@
1$Id: cacerts.pem,v 1.1 2002/05/15 02:29:18 beck Exp $
2
3issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
4subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
5-----BEGIN CERTIFICATE-----
6MIICJjCCAY8CAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV
7BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD
8VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0M1oXDTAxMDYw
9OTEzNTc0M1owWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY
10BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYDVQQDExJUZXN0IENBICgxMDI0
11IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKO7o8t116VP6cgybTsZ
12DCZhr95nYlZuya3aCi1IKoztqwWnjbmDFIriOqGFPrZQ+moMETC9D59iRW/dFXSv
131F65ka/XY2hLh9exCCo7XuUcDs53Qp3bI3AmMqHjgzE8oO3ajyJAzJkTTOUecQU2
14mw/gI4tMM0LqWMQS7luTy4+xAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAM7achv3v
15hLQJcv/65eGEpBXM40ZDVoFQFFJWaY5p883HTqLB1x4FdzsXHH0QKBTcKpWwqyu4
16YDm3fb8oDugw72bCzfyZK/zVZPR/hVlqI/fvU109Qoc+7oPvIXWky71HfcK6ZBCA
17q30KIqGM/uoM60INq97qjDmCJapagcNBGQs=
18-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/demos/easy_tls/cert.pem b/src/lib/libssl/src/demos/easy_tls/cert.pem
new file mode 100644
index 0000000000..d4d19d9ad1
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/cert.pem
@@ -0,0 +1,31 @@
1$Id: cert.pem,v 1.1 2002/05/15 02:29:18 beck Exp $
2
3Example certificate and key.
4
5-----BEGIN CERTIFICATE-----
6MIIB1jCCAT8CAQEwDQYJKoZIhvcNAQEEBQAwRTELMAkGA1UEBhMCQVUxEzARBgNV
7BAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0
8ZDAeFw05OTA1MDEwMTI2MzVaFw05OTA1MzEwMTI2MzVaMCIxCzAJBgNVBAYTAkRF
9MRMwEQYDVQQDEwpUZXN0c2VydmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
10gQD6I3oDKiexwwlkzjar69AIFnVUaG85LtCege2R+CtIDlkQYw68/8MbT3ou0pdF
11AcL9IGiYY3Y0SHM9PqF00RO1MCtNpqTnF3ScLpbmggGjKilmWYn2ai7emdjMjXVL
12tzWW2xGgIGATWQN32KgfJng4jXi1UjEiyLhkw0Zf1I/ggwIDAQABMA0GCSqGSIb3
13DQEBBAUAA4GBAMgM+sbAk8DfjSfa+Rf2gcGXmbrvZAzKzC+5RU3kaq/NyxIXAGco
149dZjozzWfN/xuGup5boFk+KrP+xdgsaqGHsyzlgEoqz4ekqLjQeVbnoj339hVFU9
15MhPi6JULPxjXKumjfX2LLNkikW5puz8Df3UiX0EiaJvd7EwP8J75tiUT
16-----END CERTIFICATE-----
17-----BEGIN RSA PRIVATE KEY-----
18MIICXQIBAAKBgQD6I3oDKiexwwlkzjar69AIFnVUaG85LtCege2R+CtIDlkQYw68
19/8MbT3ou0pdFAcL9IGiYY3Y0SHM9PqF00RO1MCtNpqTnF3ScLpbmggGjKilmWYn2
20ai7emdjMjXVLtzWW2xGgIGATWQN32KgfJng4jXi1UjEiyLhkw0Zf1I/ggwIDAQAB
21AoGANST8c1etf1MU19oIO5aqaE19OCXIG7oakNLCCtVTPMfvnE+vffBJH7BPIUuU
224BBzwRv1nQrkvk72TPjVjOAu81B1SStKQueun2flVuYxp9NyupNWCBley4QdohlP
23I92ml2tzTSPmNIoA6jdGyNzFcGchapRRmejsC39F1RUbHQECQQD9KX81Wt8ZOrri
24dWiEXja1L3X8Bkb9vvUjVMQDTJJPxBJjehC6eurgE6PP6SJD5p/f3RHPCcLr8tSM
25D4P/OpKhAkEA/PFNlhIZUDKK6aTvG2mn7qQ5phbadOoyN1Js3ttWG5OMOZ6b/QlC
26Wvp84h44506BIlv+Tg2YAI0AdBUrf7oEowJAM4joAVd/ROaEtqbJ4PBA2L9RmD06
275FqkEk4mHLnQqvYx/BgUIbH18ClvVlqSBBqFfw/EmU3WZSuogt6Bs0ocIQJBAOxB
28AoPiYcxbeQ5kZIVJOXaX49SzUdaUDNVJYrEBUzsspHQJJo/Avz606kJVkjbSR6Ft
29JWmIHuqcyMikIV4KxFsCQQCU2evoVjVsqkkbHi7W28f73PGBsyu0KIwlK7nu4h08
30Daf7TAI+A6jW/WRUsJ6dFhUYi7/Jvkcdrlnbgm2fxziX
31-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/easy_tls/easy-tls.c b/src/lib/libssl/src/demos/easy_tls/easy-tls.c
new file mode 100644
index 0000000000..9fa0ef9a6b
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/easy-tls.c
@@ -0,0 +1,1235 @@
1/* -*- Mode: C; c-file-style: "bsd" -*- */
2/*
3 * easy-tls.c -- generic TLS proxy.
4 * $Id: easy-tls.c,v 1.1 2002/05/15 02:29:18 beck Exp $
5 */
6/*
7 (c) Copyright 1999 Bodo Moeller. All rights reserved.
8
9 This is free software; you can redistributed and/or modify it
10 unter the terms of either
11 - the GNU General Public License as published by the
12 Free Software Foundation, version 1, or (at your option)
13 any later version,
14 or
15 - the following license:
16*/
17/*
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that each of the following
20 * conditions is met:
21 *
22 * 1. Redistributions qualify as "freeware" or "Open Source Software" under
23 * one of the following terms:
24 *
25 * (a) Redistributions are made at no charge beyond the reasonable cost of
26 * materials and delivery.
27 *
28 * (b) Redistributions are accompanied by a copy of the Source Code
29 * or by an irrevocable offer to provide a copy of the Source Code
30 * for up to three years at the cost of materials and delivery.
31 * Such redistributions must allow further use, modification, and
32 * redistribution of the Source Code under substantially the same
33 * terms as this license.
34 *
35 * 2. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 *
38 * 3. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in
40 * the documentation and/or other materials provided with the
41 * distribution.
42 *
43 * 4. All advertising materials mentioning features or use of this
44 * software must display the following acknowledgment:
45 * "This product includes software developed by Bodo Moeller."
46 * (If available, substitute umlauted o for oe.)
47 *
48 * 5. Redistributions of any form whatsoever must retain the following
49 * acknowledgment:
50 * "This product includes software developed by Bodo Moeller."
51 *
52 * THIS SOFTWARE IS PROVIDED BY BODO MOELLER ``AS IS'' AND ANY
53 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BODO MOELLER OR
56 * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
59 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
61 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
63 * OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65/*
66 * Attribution for OpenSSL library:
67 *
68 * This product includes cryptographic software written by Eric Young
69 * (eay@cryptsoft.com). This product includes software written by Tim
70 * Hudson (tjh@cryptsoft.com).
71 * This product includes software developed by the OpenSSL Project
72 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)
73 */
74
75static char const rcsid[] =
76"$Id: easy-tls.c,v 1.1 2002/05/15 02:29:18 beck Exp $";
77
78#include <assert.h>
79#include <errno.h>
80#include <fcntl.h>
81#include <limits.h>
82#include <stdarg.h>
83#include <stdio.h>
84#include <string.h>
85#include <sys/select.h>
86#include <sys/socket.h>
87#include <sys/stat.h>
88#include <sys/time.h>
89#include <sys/types.h>
90#include <sys/utsname.h>
91#include <unistd.h>
92
93#include <openssl/crypto.h>
94#include <openssl/dh.h>
95#include <openssl/dsa.h>
96#include <openssl/err.h>
97#include <openssl/evp.h>
98#include <openssl/opensslv.h>
99#include <openssl/pem.h>
100#include <openssl/rand.h>
101#ifndef NO_RSA
102 #include <openssl/rsa.h>
103#endif
104#include <openssl/ssl.h>
105#include <openssl/x509.h>
106#include <openssl/x509_vfy.h>
107
108#if OPENSSL_VERSION_NUMBER < 0x00904000L /* 0.9.4-dev */
109# error "This program needs OpenSSL 0.9.4 or later."
110#endif
111
112#include "easy-tls.h" /* include after <openssl/ssl.h> if both are needed */
113
114#if TLS_INFO_SIZE > PIPE_BUF
115# if PIPE_BUF < 512
116# error "PIPE_BUF < 512" /* non-POSIX */
117# endif
118# error "TLS_INFO_SIZE > PIPE_BUF"
119#endif
120
121/*****************************************************************************/
122
123#ifdef TLS_APP
124# include TLS_APP
125#endif
126
127/* Applications can define:
128 * TLS_APP_PROCESS_INIT -- void ...(int fd, int client_p, void *apparg)
129 * TLS_CUMULATE_ERRORS
130 * TLS_ERROR_BUFSIZ
131 * TLS_APP_ERRFLUSH -- void ...(int child_p, char *, size_t, void *apparg)
132 */
133
134#ifndef TLS_APP_PROCESS_INIT
135# define TLS_APP_PROCESS_INIT(fd, client_p, apparg) ((void) 0)
136#endif
137
138#ifndef TLS_ERROR_BUFSIZ
139# define TLS_ERROR_BUFSIZ (10*160)
140#endif
141#if TLS_ERROR_BUFSIZ < 2 /* {'\n',0} */
142# error "TLS_ERROR_BUFSIZE is too small."
143#endif
144
145#ifndef TLS_APP_ERRFLUSH
146# define TLS_APP_ERRFLUSH tls_app_errflush
147static void
148tls_app_errflush(int child_p, char *errbuf, size_t num, void *apparg)
149{
150 fputs(errbuf, stderr);
151}
152#endif
153
154/*****************************************************************************/
155
156#ifdef DEBUG_TLS
157# define DEBUG_MSG(x) fprintf(stderr," %s\n",x)
158# define DEBUG_MSG2(x,y) fprintf(stderr, " %s: %d\n",x,y)
159static int tls_loop_count = 0;
160static int tls_select_count = 0;
161#else
162# define DEBUG_MSG(x) (void)0
163# define DEBUG_MSG2(x,y) (void)0
164#endif
165
166static void tls_rand_seed_uniquely(void);
167static void tls_proxy(int clear_fd, int tls_fd, int info_fd, SSL_CTX *ctx, int client_p);
168static int tls_socket_nonblocking(int fd);
169
170static int tls_child_p = 0;
171static void *tls_child_apparg;
172
173
174struct tls_start_proxy_args
175tls_start_proxy_defaultargs(void)
176{
177 struct tls_start_proxy_args ret;
178
179 ret.fd = -1;
180 ret.client_p = -1;
181 ret.ctx = NULL;
182 ret.pid = NULL;
183 ret.infofd = NULL;
184
185 return ret;
186}
187
188/* Slice in TLS proxy process at fd.
189 * Return value:
190 * 0 ok (*pid is set to child's PID if pid != NULL),
191 * < 0 look at errno
192 * > 0 other error
193 * (return value encodes place of error)
194 *
195 */
196int
197tls_start_proxy(struct tls_start_proxy_args a, void *apparg)
198{
199 int fds[2] = {-1, -1};
200 int infofds[2] = {-1, -1};
201 int r, getfd, getfl;
202 int ret;
203
204 DEBUG_MSG2("tls_start_proxy fd", a.fd);
205 DEBUG_MSG2("tls_start_proxy client_p", a.client_p);
206
207 if (a.fd == -1 || a.client_p == -1 || a.ctx == NULL)
208 return 1;
209
210 if (a.pid != NULL) {
211 *a.pid = 0;
212 }
213 if (a.infofd != NULL) {
214 *a.infofd = -1;
215 }
216
217 r = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
218 if (r == -1)
219 return -1;
220 if (a.fd >= FD_SETSIZE || fds[0] >= FD_SETSIZE) {
221 ret = 2;
222 goto err;
223 }
224 if (a.infofd != NULL) {
225 r = pipe(infofds);
226 if (r == -1) {
227 ret = -3;
228 goto err;
229 }
230 }
231
232 r = fork();
233 if (r == -1) {
234 ret = -4;
235 goto err;
236 }
237 if (r == 0) {
238 DEBUG_MSG("fork");
239 tls_child_p = 1;
240 tls_child_apparg = apparg;
241 close(fds[1]);
242 if (infofds[0] != -1)
243 close(infofds[0]);
244 TLS_APP_PROCESS_INIT(a.fd, a.client_p, apparg);
245 DEBUG_MSG("TLS_APP_PROCESS_INIT");
246 tls_proxy(fds[0], a.fd, infofds[1], a.ctx, a.client_p);
247 exit(0);
248 }
249 if (a.pid != NULL)
250 *a.pid = r;
251 if (infofds[1] != -1) {
252 close(infofds[1]);
253 infofds[1] = -1;
254 }
255 /* install fds[1] in place of fd: */
256 close(fds[0]);
257 fds[0] = -1;
258 getfd = fcntl(a.fd, F_GETFD);
259 getfl = fcntl(a.fd, F_GETFL);
260 r = dup2(fds[1], a.fd);
261 close(fds[1]);
262 fds[1] = -1;
263 if (r == -1) {
264 ret = -5;
265 goto err;
266 }
267 if (getfd != 1)
268 fcntl(a.fd, F_SETFD, getfd);
269 if (getfl & O_NONBLOCK)
270 (void)tls_socket_nonblocking(a.fd);
271 if (a.infofd != NULL)
272 *a.infofd = infofds[0];
273 return 0;
274
275 err:
276 if (fds[0] != -1)
277 close(fds[0]);
278 if (fds[1] != -1)
279 close(fds[1]);
280 if (infofds[0] != -1)
281 close(infofds[0]);
282 if (infofds[1] != -1)
283 close(infofds[1]);
284 return ret;
285}
286
287/*****************************************************************************/
288
289static char errbuf[TLS_ERROR_BUFSIZ];
290static size_t errbuf_i = 0;
291
292static void
293tls_errflush(void *apparg)
294{
295 if (errbuf_i == 0)
296 return;
297
298 assert(errbuf_i < sizeof errbuf);
299 assert(errbuf[errbuf_i] == 0);
300 if (errbuf_i == sizeof errbuf - 1) {
301 /* make sure we have a newline, even if string has been truncated */
302 errbuf[errbuf_i - 1] = '\n';
303 }
304
305 /* TLS_APP_ERRFLUSH may modify the string as needed,
306 * e.g. substitute other characters for \n for convenience */
307 TLS_APP_ERRFLUSH(tls_child_p, errbuf, errbuf_i, apparg);
308
309 errbuf_i = 0;
310}
311
312static void
313tls_errprintf(int flush, void *apparg, const char *fmt, ...)
314{
315 va_list args;
316 int r;
317
318 if (errbuf_i < sizeof errbuf - 1) {
319 size_t n;
320
321 va_start(args, fmt);
322 n = (sizeof errbuf) - errbuf_i;
323 r = vsnprintf(errbuf + errbuf_i, n, fmt, args);
324 if (r >= n)
325 r = n - 1;
326 if (r >= 0) {
327 errbuf_i += r;
328 } else {
329 errbuf_i = sizeof errbuf - 1;
330 errbuf[errbuf_i] = '\0';
331 }
332 assert(errbuf_i < sizeof errbuf);
333 assert(errbuf[errbuf_i] == 0);
334 }
335#ifndef TLS_CUMULATE_ERRORS
336 tls_errflush(apparg);
337#else
338 if (flush)
339 tls_errflush(apparg);
340#endif
341}
342
343/* app_prefix.. are for additional information provided by caller.
344 * If OpenSSL error queue is empty, print default_text ("???" if NULL).
345 */
346static char *
347tls_openssl_errors(const char *app_prefix_1, const char *app_prefix_2, const char *default_text, void *apparg)
348{
349 static char reasons[255];
350 size_t reasons_i;
351 unsigned long err;
352 const char *file;
353 int line;
354 const char *data;
355 int flags;
356 char *errstring;
357 int printed_something = 0;
358
359 reasons_i = 0;
360
361 assert(app_prefix_1 != NULL);
362 assert(app_prefix_2 != NULL);
363
364 if (default_text == NULL)
365 default_text = "?""?""?";
366
367 while ((err = ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) {
368 if (reasons_i < sizeof reasons) {
369 size_t n;
370 int r;
371
372 n = (sizeof reasons) - reasons_i;
373 r = snprintf(reasons + reasons_i, n, "%s%s", (reasons_i > 0 ? ", " : ""), ERR_reason_error_string(err));
374 if (r >= n)
375 r = n - 1;
376 if (r >= 0) {
377 reasons_i += r;
378 } else {
379 reasons_i = sizeof reasons;
380 }
381 assert(reasons_i <= sizeof reasons);
382 }
383
384 errstring = ERR_error_string(err, NULL);
385 assert(errstring != NULL);
386 tls_errprintf(0, apparg, "OpenSSL error%s%s: %s:%s:%d:%s\n", app_prefix_1, app_prefix_2, errstring, file, line, (flags & ERR_TXT_STRING) ? data : "");
387 printed_something = 1;
388 }
389
390 if (!printed_something) {
391 assert(reasons_i == 0);
392 snprintf(reasons, sizeof reasons, "%s", default_text);
393 tls_errprintf(0, apparg, "OpenSSL error%s%s: %s\n", app_prefix_1, app_prefix_2, default_text);
394 }
395
396#ifdef TLS_CUMULATE_ERRORS
397 tls_errflush(apparg);
398#endif
399 assert(errbuf_i == 0);
400
401 return reasons;
402}
403
404/*****************************************************************************/
405
406static int tls_init_done = 0;
407
408static int
409tls_init(void *apparg)
410{
411 if (tls_init_done)
412 return 0;
413
414 SSL_load_error_strings();
415 if (!SSL_library_init() /* aka SSLeay_add_ssl_algorithms() */ ) {
416 tls_errprintf(1, apparg, "SSL_library_init failed.\n");
417 return -1;
418 }
419 tls_init_done = 1;
420 tls_rand_seed();
421 return 0;
422}
423
424/*****************************************************************************/
425
426static void
427tls_rand_seed_uniquely(void)
428{
429 struct {
430 pid_t pid;
431 time_t time;
432 void *stack;
433 } data;
434
435 data.pid = getpid();
436 data.time = time(NULL);
437 data.stack = (void *)&data;
438
439 RAND_seed((const void *)&data, sizeof data);
440}
441
442void
443tls_rand_seed(void)
444{
445 struct {
446 struct utsname uname;
447 int uname_1;
448 int uname_2;
449 uid_t uid;
450 uid_t euid;
451 gid_t gid;
452 gid_t egid;
453 } data;
454
455 data.uname_1 = uname(&data.uname);
456 data.uname_2 = errno; /* Let's hope that uname fails randomly :-) */
457
458 data.uid = getuid();
459 data.euid = geteuid();
460 data.gid = getgid();
461 data.egid = getegid();
462
463 RAND_seed((const void *)&data, sizeof data);
464 tls_rand_seed_uniquely();
465}
466
467static int tls_rand_seeded_p = 0;
468
469#define my_MIN_SEED_BYTES 256 /* struct stat can be larger than 128 */
470int
471tls_rand_seed_from_file(const char *filename, size_t n, void *apparg)
472{
473 /* Seed OpenSSL's random number generator from file.
474 Try to read n bytes if n > 0, whole file if n == 0. */
475
476 int r;
477
478 if (tls_init(apparg) == -1)
479 return -1;
480 tls_rand_seed();
481
482 r = RAND_load_file(filename, (n > 0 && n < LONG_MAX) ? (long)n : LONG_MAX);
483 /* r is the number of bytes filled into the random number generator,
484 * which are taken from "stat(filename, ...)" in addition to the
485 * file contents.
486 */
487 assert(1 < my_MIN_SEED_BYTES);
488 /* We need to detect at least those cases when the file does not exist
489 * at all. With current versions of OpenSSL, this should do it: */
490 if (n == 0)
491 n = my_MIN_SEED_BYTES;
492 if (r < n) {
493 tls_errprintf(1, apparg, "rand_seed_from_file: could not read %d bytes from %s.\n", n, filename);
494 return -1;
495 } else {
496 tls_rand_seeded_p = 1;
497 return 0;
498 }
499}
500
501void
502tls_rand_seed_from_memory(const void *buf, size_t n)
503{
504 size_t i = 0;
505
506 while (i < n) {
507 size_t rest = n - i;
508 int chunk = rest < INT_MAX ? (int)rest : INT_MAX;
509 RAND_seed((const char *)buf + i, chunk);
510 i += chunk;
511 }
512 tls_rand_seeded_p = 1;
513}
514
515
516/*****************************************************************************/
517
518struct tls_x509_name_string {
519 char str[100];
520};
521
522static void
523tls_get_x509_subject_name_oneline(X509 *cert, struct tls_x509_name_string *namestring)
524{
525 X509_NAME *name;
526
527 if (cert == NULL) {
528 namestring->str[0] = '\0';
529 return;
530 }
531
532 name = X509_get_subject_name(cert); /* does not increment any reference counter */
533
534 assert(sizeof namestring->str >= 4); /* "?" or "...", plus 0 */
535
536 if (name == NULL) {
537 namestring->str[0] = '?';
538 namestring->str[1] = 0;
539 } else {
540 size_t len;
541
542 X509_NAME_oneline(name, namestring->str, sizeof namestring->str);
543 len = strlen(namestring->str);
544 assert(namestring->str[len] == 0);
545 assert(len < sizeof namestring->str);
546
547 if (len+1 == sizeof namestring->str) {
548 /* (Probably something was cut off.)
549 * Does not really work -- X509_NAME_oneline truncates after
550 * name components, we cannot tell from the result whether
551 * anything is missing. */
552
553 assert(namestring->str[len] == 0);
554 namestring->str[--len] = '.';
555 namestring->str[--len] = '.';
556 namestring->str[--len] = '.';
557 }
558 }
559}
560
561/*****************************************************************************/
562
563/* to hinder OpenSSL from asking for passphrases */
564static int
565no_passphrase_callback(char *buf, int num, int w, void *arg)
566{
567 return -1;
568}
569
570static int
571verify_dont_fail_cb(X509_STORE_CTX *c, void *unused_arg)
572{
573 int i;
574
575 i = X509_verify_cert(c); /* sets c->error */
576#if OPENSSL_VERSION_NUMBER >= 0x00905000L /* don't allow unverified
577 * certificates -- they could
578 * survive session reuse, but
579 * OpenSSL < 0.9.5-dev does not
580 * preserve their verify_result */
581 if (i == 0)
582 return 1;
583 else
584#endif
585 return i;
586}
587
588static DH *tls_dhe1024 = NULL; /* generating these takes a while, so do it just once */
589
590void
591tls_set_dhe1024(int i, void *apparg)
592{
593 DSA *dsaparams;
594 DH *dhparams;
595 const char *seed[] = { ";-) :-( :-) :-( ",
596 ";-) :-( :-) :-( ",
597 "Random String no. 12",
598 ";-) :-( :-) :-( ",
599 "hackers have even mo", /* from jargon file */
600 };
601 unsigned char seedbuf[20];
602
603 tls_init(apparg);
604 if (i >= 0) {
605 i %= sizeof seed / sizeof seed[0];
606 assert(strlen(seed[i]) == 20);
607 memcpy(seedbuf, seed[i], 20);
608 dsaparams = DSA_generate_parameters(1024, seedbuf, 20, NULL, NULL, 0, NULL);
609 } else {
610 /* random parameters (may take a while) */
611 dsaparams = DSA_generate_parameters(1024, NULL, 0, NULL, NULL, 0, NULL);
612 }
613
614 if (dsaparams == NULL) {
615 tls_openssl_errors("", "", NULL, apparg);
616 return;
617 }
618 dhparams = DSA_dup_DH(dsaparams);
619 DSA_free(dsaparams);
620 if (dhparams == NULL) {
621 tls_openssl_errors("", "", NULL, apparg);
622 return;
623 }
624 if (tls_dhe1024 != NULL)
625 DH_free(tls_dhe1024);
626 tls_dhe1024 = dhparams;
627}
628
629struct tls_create_ctx_args
630tls_create_ctx_defaultargs(void)
631{
632 struct tls_create_ctx_args ret;
633
634 ret.client_p = 0;
635 ret.certificate_file = NULL;
636 ret.key_file = NULL;
637 ret.ca_file = NULL;
638 ret.verify_depth = -1;
639 ret.fail_unless_verified = 0;
640 ret.export_p = 0;
641
642 return ret;
643}
644
645SSL_CTX *
646tls_create_ctx(struct tls_create_ctx_args a, void *apparg)
647{
648 int r;
649 static long context_num = 0;
650 SSL_CTX *ret;
651 const char *err_pref_1 = "", *err_pref_2 = "";
652
653 if (tls_init(apparg) == -1)
654 return NULL;
655
656 ret = SSL_CTX_new((a.client_p? SSLv23_client_method:SSLv23_server_method)());
657
658 if (ret == NULL)
659 goto err;
660
661 SSL_CTX_set_default_passwd_cb(ret, no_passphrase_callback);
662 SSL_CTX_set_mode(ret, SSL_MODE_ENABLE_PARTIAL_WRITE);
663
664 if ((a.certificate_file != NULL) || (a.key_file != NULL)) {
665 if (a.key_file == NULL) {
666 tls_errprintf(1, apparg, "Need a key file.\n");
667 goto err_return;
668 }
669 if (a.certificate_file == NULL) {
670 tls_errprintf(1, apparg, "Need a certificate chain file.\n");
671 goto err_return;
672 }
673
674 if (!SSL_CTX_use_PrivateKey_file(ret, a.key_file, SSL_FILETYPE_PEM))
675 goto err;
676 if (!tls_rand_seeded_p) {
677 /* particularly paranoid people may not like this --
678 * so provide your own random seeding before calling this */
679 if (tls_rand_seed_from_file(a.key_file, 0, apparg) == -1)
680 goto err_return;
681 }
682 if (!SSL_CTX_use_certificate_chain_file(ret, a.certificate_file))
683 goto err;
684 if (!SSL_CTX_check_private_key(ret)) {
685 tls_errprintf(1, apparg, "Private key \"%s\" does not match certificate \"%s\".\n", a.key_file, a.certificate_file);
686 goto err_peek;
687 }
688 }
689
690 if ((a.ca_file != NULL) || (a.verify_depth > 0)) {
691 context_num++;
692 r = SSL_CTX_set_session_id_context(ret, (const void *)&context_num, (unsigned int)sizeof context_num);
693 if (!r)
694 goto err;
695
696 SSL_CTX_set_verify(ret, SSL_VERIFY_PEER | (a.fail_unless_verified ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0), 0);
697 if (!a.fail_unless_verified)
698 SSL_CTX_set_cert_verify_callback(ret, verify_dont_fail_cb, NULL);
699
700 if (a.verify_depth > 0)
701 SSL_CTX_set_verify_depth(ret, a.verify_depth);
702
703 if (a.ca_file != NULL) {
704 r = SSL_CTX_load_verify_locations(ret, a.ca_file, NULL /* no CA-directory */); /* does not report failure if file does not exist ... */
705 if (!r) {
706 err_pref_1 = " while processing certificate file ";
707 err_pref_2 = a.ca_file;
708 goto err;
709 }
710
711 if (!a.client_p) {
712 /* SSL_load_client_CA_file is a misnomer, it just creates a list of CNs. */
713 SSL_CTX_set_client_CA_list(ret, SSL_load_client_CA_file(a.ca_file));
714 /* SSL_CTX_set_client_CA_list does not have a return value;
715 * it does not really need one, but make sure
716 * (we really test if SSL_load_client_CA_file worked) */
717 if (SSL_CTX_get_client_CA_list(ret) == NULL) {
718 tls_errprintf(1, apparg, "Could not set client CA list from \"%s\".\n", a.ca_file);
719 goto err_peek;
720 }
721 }
722 }
723 }
724
725 if (!a.client_p) {
726 if (tls_dhe1024 == NULL) {
727 int i;
728
729 RAND_bytes((unsigned char *) &i, sizeof i);
730 /* make sure that i is non-negative -- pick one of the provided
731 * seeds */
732 if (i < 0)
733 i = -i;
734 if (i < 0)
735 i = 0;
736 tls_set_dhe1024(i, apparg);
737 if (tls_dhe1024 == NULL)
738 goto err_return;
739 }
740
741 if (!SSL_CTX_set_tmp_dh(ret, tls_dhe1024))
742 goto err;
743
744 /* avoid small subgroup attacks: */
745 SSL_CTX_set_options(ret, SSL_OP_SINGLE_DH_USE);
746 }
747
748#ifndef NO_RSA
749 if (!a.client_p && a.export_p) {
750 RSA *tmpkey;
751
752 tmpkey = RSA_generate_key(512, RSA_F4, 0, NULL);
753 if (tmpkey == NULL)
754 goto err;
755 if (!SSL_CTX_set_tmp_rsa(ret, tmpkey)) {
756 RSA_free(tmpkey);
757 goto err;
758 }
759 RSA_free(tmpkey); /* SSL_CTX_set_tmp_rsa uses a duplicate. */
760 }
761#endif
762
763 return ret;
764
765 err_peek:
766 if (!ERR_peek_error())
767 goto err_return;
768 err:
769 tls_openssl_errors(err_pref_1, err_pref_2, NULL, apparg);
770 err_return:
771 if (ret != NULL)
772 SSL_CTX_free(ret);
773 return NULL;
774}
775
776
777/*****************************************************************************/
778
779static int
780tls_socket_nonblocking(int fd)
781{
782 int v, r;
783
784 v = fcntl(fd, F_GETFL, 0);
785 if (v == -1) {
786 if (errno == EINVAL)
787 return 0; /* already shut down -- ignore */
788 return -1;
789 }
790 r = fcntl(fd, F_SETFL, v | O_NONBLOCK);
791 if (r == -1) {
792 if (errno == EINVAL)
793 return 0; /* already shut down -- ignore */
794 return -1;
795 }
796 return 0;
797}
798
799static int
800max(int a, int b)
801{
802 return a > b ? a : b;
803}
804
805static void
806tls_sockets_select(int read_select_1, int read_select_2, int write_select_1, int write_select_2, int seconds /* timeout, -1 means no timeout */)
807{
808 int maxfd, n;
809 fd_set reads, writes;
810 struct timeval timeout;
811 struct timeval *timeout_p;
812
813 assert(read_select_1 >= -1 && read_select_2 >= -1 && write_select_1 >= -1 && write_select_2 >= -1);
814 assert(read_select_1 < FD_SETSIZE && read_select_2 < FD_SETSIZE -1 && write_select_1 < FD_SETSIZE -1 && write_select_2 < FD_SETSIZE -1);
815
816 maxfd = max(max(read_select_1, read_select_2), max(write_select_1, write_select_2));
817 assert(maxfd >= 0);
818
819 FD_ZERO(&reads);
820 FD_ZERO(&writes);
821
822 for(n = 0; n < 4; ++n) {
823 int i = n % 2;
824 int w = n >= 2;
825 /* loop over all (i, w) in {0,1}x{0,1} */
826 int fd;
827
828 if (i == 0 && w == 0)
829 fd = read_select_1;
830 else if (i == 1 && w == 0)
831 fd = read_select_2;
832 else if (i == 0 && w == 1)
833 fd = write_select_1;
834 else {
835 assert(i == 1 && w == 1);
836 fd = write_select_2;
837 }
838
839 if (fd >= 0) {
840 if (w == 0)
841 FD_SET(fd, &reads);
842 else /* w == 1 */
843 FD_SET(fd, &writes);
844 }
845 }
846
847 if (seconds >= 0) {
848 timeout.tv_sec = seconds;
849 timeout.tv_usec = 0;
850 timeout_p = &timeout;
851 } else
852 timeout_p = NULL;
853
854 DEBUG_MSG2("select no.", ++tls_select_count);
855 select(maxfd + 1, &reads, &writes, (fd_set *) NULL, timeout_p);
856 DEBUG_MSG("cont.");
857}
858
859/*****************************************************************************/
860
861#define TUNNELBUFSIZE (16*1024)
862struct tunnelbuf {
863 char buf[TUNNELBUFSIZE];
864 size_t len;
865 size_t offset;
866};
867
868static int tls_connect_attempt(SSL *, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref);
869
870static int tls_accept_attempt(SSL *, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref);
871
872static int tls_write_attempt(SSL *, struct tunnelbuf *, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref);
873
874static int tls_read_attempt(SSL *, struct tunnelbuf *, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref);
875
876static int write_attempt(int fd, struct tunnelbuf *, int *select, int *closed, int *progress);
877
878static int read_attempt(int fd, struct tunnelbuf *, int *select, int *closed, int *progress);
879
880static void write_info(SSL *ssl, int *info_fd)
881{
882 if (*info_fd != -1) {
883 long v;
884 int v_ok;
885 struct tls_x509_name_string peer;
886 char infobuf[TLS_INFO_SIZE];
887 int r;
888
889 DEBUG_MSG("write_info");
890 v = SSL_get_verify_result(ssl);
891 v_ok = (v == X509_V_OK) ? 'A' : 'E'; /* Auth./Error */
892 {
893 X509 *peercert;
894
895 peercert = SSL_get_peer_certificate(ssl);
896 tls_get_x509_subject_name_oneline(peercert, &peer);
897 if (peercert != NULL)
898 X509_free(peercert);
899 }
900 if (peer.str[0] == '\0')
901 v_ok = '0'; /* no cert at all */
902 else
903 if (strchr(peer.str, '\n')) {
904 /* should not happen, but make sure */
905 *strchr(peer.str, '\n') = '\0';
906 }
907 r = snprintf(infobuf, sizeof infobuf, "%c:%s\n%s\n", v_ok, X509_verify_cert_error_string(v), peer.str);
908 DEBUG_MSG2("snprintf", r);
909 if (r == -1 || r >= sizeof infobuf)
910 r = sizeof infobuf - 1;
911 write(*info_fd, infobuf, r);
912 close (*info_fd);
913 *info_fd = -1;
914 }
915}
916
917
918/* tls_proxy expects that all fds are closed after return */
919static void
920tls_proxy(int clear_fd, int tls_fd, int info_fd, SSL_CTX *ctx, int client_p)
921{
922 struct tunnelbuf clear_to_tls, tls_to_clear;
923 SSL *ssl;
924 BIO *rbio, *wbio;
925 int closed, in_handshake;
926 const char *err_pref_1 = "", *err_pref_2 = "";
927 const char *err_def = NULL;
928
929 assert(clear_fd != -1);
930 assert(tls_fd != -1);
931 assert(clear_fd < FD_SETSIZE);
932 assert(tls_fd < FD_SETSIZE);
933 /* info_fd may be -1 */
934 assert(ctx != NULL);
935
936 tls_rand_seed_uniquely();
937
938 tls_socket_nonblocking(clear_fd);
939 DEBUG_MSG2("clear_fd", clear_fd);
940 tls_socket_nonblocking(tls_fd);
941 DEBUG_MSG2("tls_fd", tls_fd);
942
943 ssl = SSL_new(ctx);
944 if (ssl == NULL)
945 goto err;
946 DEBUG_MSG("SSL_new");
947 if (!SSL_set_fd(ssl, tls_fd))
948 goto err;
949 rbio = SSL_get_rbio(ssl);
950 wbio = SSL_get_wbio(ssl); /* should be the same, but who cares */
951 assert(rbio != NULL);
952 assert(wbio != NULL);
953 if (client_p)
954 SSL_set_connect_state(ssl);
955 else
956 SSL_set_accept_state(ssl);
957
958 closed = 0;
959 in_handshake = 1;
960 tls_to_clear.len = 0;
961 tls_to_clear.offset = 0;
962 clear_to_tls.len = 0;
963 clear_to_tls.offset = 0;
964
965 err_def = "I/O error";
966
967 /* loop finishes as soon as we detect that one side closed;
968 * when all (program and OS) buffers have enough space,
969 * the data from the last succesful read in each direction is transferred
970 * before close */
971 do {
972 int clear_read_select = 0, clear_write_select = 0,
973 tls_read_select = 0, tls_write_select = 0,
974 progress = 0;
975 int r;
976 unsigned long num_read = BIO_number_read(rbio),
977 num_written = BIO_number_written(wbio);
978
979 DEBUG_MSG2("loop iteration", ++tls_loop_count);
980
981 if (in_handshake) {
982 DEBUG_MSG("in_handshake");
983 if (client_p)
984 r = tls_connect_attempt(ssl, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
985 else
986 r = tls_accept_attempt(ssl, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
987 if (r != 0) {
988 write_info(ssl, &info_fd);
989 goto err;
990 }
991 if (closed)
992 goto err_return;
993 if (!SSL_in_init(ssl)) {
994 in_handshake = 0;
995 write_info(ssl, &info_fd);
996 }
997 }
998
999 if (clear_to_tls.len != 0 && !in_handshake) {
1000 assert(!closed);
1001
1002 r = tls_write_attempt(ssl, &clear_to_tls, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
1003 if (r != 0)
1004 goto err;
1005 if (closed) {
1006 assert(progress);
1007 tls_to_clear.offset = 0;
1008 tls_to_clear.len = 0;
1009 }
1010 }
1011
1012 if (tls_to_clear.len != 0) {
1013 assert(!closed);
1014
1015 r = write_attempt(clear_fd, &tls_to_clear, &clear_write_select, &closed, &progress);
1016 if (r != 0)
1017 goto err_return;
1018 if (closed) {
1019 assert(progress);
1020 clear_to_tls.offset = 0;
1021 clear_to_tls.len = 0;
1022 }
1023 }
1024
1025 if (!closed) {
1026 if (clear_to_tls.offset + clear_to_tls.len < sizeof clear_to_tls.buf) {
1027 r = read_attempt(clear_fd, &clear_to_tls, &clear_read_select, &closed, &progress);
1028 if (r != 0)
1029 goto err_return;
1030 if (closed) {
1031 r = SSL_shutdown(ssl);
1032 DEBUG_MSG2("SSL_shutdown", r);
1033 }
1034 }
1035 }
1036
1037 if (!closed && !in_handshake) {
1038 if (tls_to_clear.offset + tls_to_clear.len < sizeof tls_to_clear.buf) {
1039 r = tls_read_attempt(ssl, &tls_to_clear, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
1040 if (r != 0)
1041 goto err;
1042 if (closed) {
1043 r = SSL_shutdown(ssl);
1044 DEBUG_MSG2("SSL_shutdown", r);
1045 }
1046 }
1047 }
1048
1049 if (!progress) {
1050 DEBUG_MSG("!progress?");
1051 if (num_read != BIO_number_read(rbio) || num_written != BIO_number_written(wbio))
1052 progress = 1;
1053
1054 if (!progress) {
1055 DEBUG_MSG("!progress");
1056 assert(clear_read_select || tls_read_select || clear_write_select || tls_write_select);
1057 tls_sockets_select(clear_read_select ? clear_fd : -1, tls_read_select ? tls_fd : -1, clear_write_select ? clear_fd : -1, tls_write_select ? tls_fd : -1, -1);
1058 }
1059 }
1060 } while (!closed);
1061 return;
1062
1063 err:
1064 tls_openssl_errors(err_pref_1, err_pref_2, err_def, tls_child_apparg);
1065 err_return:
1066 return;
1067}
1068
1069
1070static int
1071tls_get_error(SSL *ssl, int r, int *write_select, int *read_select, int *closed, int *progress)
1072{
1073 int err = SSL_get_error(ssl, r);
1074
1075 if (err == SSL_ERROR_NONE) {
1076 assert(r > 0);
1077 *progress = 1;
1078 return 0;
1079 }
1080
1081 assert(r <= 0);
1082
1083 switch (err) {
1084 case SSL_ERROR_ZERO_RETURN:
1085 assert(r == 0);
1086 *closed = 1;
1087 *progress = 1;
1088 return 0;
1089
1090 case SSL_ERROR_WANT_WRITE:
1091 *write_select = 1;
1092 return 0;
1093
1094 case SSL_ERROR_WANT_READ:
1095 *read_select = 1;
1096 return 0;
1097 }
1098
1099 return -1;
1100}
1101
1102static int
1103tls_connect_attempt(SSL *ssl, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref)
1104{
1105 int n, r;
1106
1107 DEBUG_MSG("tls_connect_attempt");
1108 n = SSL_connect(ssl);
1109 DEBUG_MSG2("SSL_connect",n);
1110 r = tls_get_error(ssl, n, write_select, read_select, closed, progress);
1111 if (r == -1)
1112 *err_pref = " during SSL_connect";
1113 return r;
1114}
1115
1116static int
1117tls_accept_attempt(SSL *ssl, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref)
1118{
1119 int n, r;
1120
1121 DEBUG_MSG("tls_accept_attempt");
1122 n = SSL_accept(ssl);
1123 DEBUG_MSG2("SSL_accept",n);
1124 r = tls_get_error(ssl, n, write_select, read_select, closed, progress);
1125 if (r == -1)
1126 *err_pref = " during SSL_accept";
1127 return r;
1128}
1129
1130static int
1131tls_write_attempt(SSL *ssl, struct tunnelbuf *buf, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref)
1132{
1133 int n, r;
1134
1135 DEBUG_MSG("tls_write_attempt");
1136 n = SSL_write(ssl, buf->buf + buf->offset, buf->len);
1137 DEBUG_MSG2("SSL_write",n);
1138 r = tls_get_error(ssl, n, write_select, read_select, closed, progress);
1139 if (n > 0) {
1140 buf->len -= n;
1141 assert(buf->len >= 0);
1142 if (buf->len == 0)
1143 buf->offset = 0;
1144 else
1145 buf->offset += n;
1146 }
1147 if (r == -1)
1148 *err_pref = " during SSL_write";
1149 return r;
1150}
1151
1152static int
1153tls_read_attempt(SSL *ssl, struct tunnelbuf *buf, int *write_select, int *read_select, int *closed, int *progress, const char **err_pref)
1154{
1155 int n, r;
1156 size_t total;
1157
1158 DEBUG_MSG("tls_read_attempt");
1159 total = buf->offset + buf->len;
1160 assert(total < sizeof buf->buf);
1161 n = SSL_read(ssl, buf->buf + total, (sizeof buf->buf) - total);
1162 DEBUG_MSG2("SSL_read",n);
1163 r = tls_get_error(ssl, n, write_select, read_select, closed, progress);
1164 if (n > 0) {
1165 buf->len += n;
1166 assert(buf->offset + buf->len <= sizeof buf->buf);
1167 }
1168 if (r == -1)
1169 *err_pref = " during SSL_read";
1170 return r;
1171}
1172
1173static int
1174get_error(int r, int *select, int *closed, int *progress)
1175{
1176 if (r >= 0) {
1177 *progress = 1;
1178 if (r == 0)
1179 *closed = 1;
1180 return 0;
1181 } else {
1182 assert(r == -1);
1183 if (errno == EAGAIN || errno == EWOULDBLOCK) {
1184 *select = 1;
1185 return 0;
1186 } else if (errno == EPIPE) {
1187 *progress = 1;
1188 *closed = 1;
1189 return 0;
1190 } else
1191 return -1;
1192 }
1193}
1194
1195static int write_attempt(int fd, struct tunnelbuf *buf, int *select, int *closed, int *progress)
1196{
1197 int n, r;
1198
1199 DEBUG_MSG("write_attempt");
1200 n = write(fd, buf->buf + buf->offset, buf->len);
1201 DEBUG_MSG2("write",n);
1202 r = get_error(n, select, closed, progress);
1203 if (n > 0) {
1204 buf->len -= n;
1205 assert(buf->len >= 0);
1206 if (buf->len == 0)
1207 buf->offset = 0;
1208 else
1209 buf->offset += n;
1210 }
1211 if (r == -1)
1212 tls_errprintf(1, tls_child_apparg, "write error: %s\n", strerror(errno));
1213 return r;
1214}
1215
1216static int
1217read_attempt(int fd, struct tunnelbuf *buf, int *select, int *closed, int *progress)
1218{
1219 int n, r;
1220 size_t total;
1221
1222 DEBUG_MSG("read_attempt");
1223 total = buf->offset + buf->len;
1224 assert(total < sizeof buf->buf);
1225 n = read(fd, buf->buf + total, (sizeof buf->buf) - total);
1226 DEBUG_MSG2("read",n);
1227 r = get_error(n, select, closed, progress);
1228 if (n > 0) {
1229 buf->len += n;
1230 assert(buf->offset + buf->len <= sizeof buf->buf);
1231 }
1232 if (r == -1)
1233 tls_errprintf(1, tls_child_apparg, "read error: %s\n", strerror(errno));
1234 return r;
1235}
diff --git a/src/lib/libssl/src/demos/easy_tls/easy-tls.h b/src/lib/libssl/src/demos/easy_tls/easy-tls.h
new file mode 100644
index 0000000000..0cfbd8fe7b
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/easy-tls.h
@@ -0,0 +1,57 @@
1/* -*- Mode: C; c-file-style: "bsd" -*- */
2/*
3 * easy-tls.h -- generic TLS proxy.
4 * $Id: easy-tls.h,v 1.1 2002/05/15 02:29:18 beck Exp $
5 */
6/*
7 * (c) Copyright 1999 Bodo Moeller. All rights reserved.
8 */
9
10#ifndef HEADER_TLS_H
11#define HEADER_TLS_H
12
13#ifndef HEADER_SSL_H
14typedef struct ssl_ctx_st SSL_CTX;
15#endif
16
17#define TLS_INFO_SIZE 512 /* max. # of bytes written to infofd */
18
19void tls_set_dhe1024(int i, void* apparg);
20/* Generate DHE parameters:
21 * i >= 0 deterministic (i selects seed), i < 0 random (may take a while).
22 * tls_create_ctx calls this with random non-negative i if the application
23 * has never called it.*/
24
25void tls_rand_seed(void);
26int tls_rand_seed_from_file(const char *filename, size_t n, void *apparg);
27void tls_rand_seed_from_memory(const void *buf, size_t n);
28
29struct tls_create_ctx_args
30{
31 int client_p;
32 const char *certificate_file;
33 const char *key_file;
34 const char *ca_file;
35 int verify_depth;
36 int fail_unless_verified;
37 int export_p;
38};
39struct tls_create_ctx_args tls_create_ctx_defaultargs(void);
40/* struct tls_create_ctx_args is similar to a conventional argument list,
41 * but it can provide default values and allows for future extension. */
42SSL_CTX *tls_create_ctx(struct tls_create_ctx_args, void *apparg);
43
44struct tls_start_proxy_args
45{
46 int fd;
47 int client_p;
48 SSL_CTX *ctx;
49 pid_t *pid;
50 int *infofd;
51};
52struct tls_start_proxy_args tls_start_proxy_defaultargs(void);
53/* tls_start_proxy return value *MUST* be checked!
54 * 0 means ok, otherwise we've probably run out of some resources. */
55int tls_start_proxy(struct tls_start_proxy_args, void *apparg);
56
57#endif
diff --git a/src/lib/libssl/src/demos/easy_tls/test.c b/src/lib/libssl/src/demos/easy_tls/test.c
new file mode 100644
index 0000000000..4ce676ca93
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/test.c
@@ -0,0 +1,244 @@
1/* test.c */
2/* $Id: test.c,v 1.1 2002/05/15 02:29:18 beck Exp $ */
3
4#define L_PORT 9999
5#define C_PORT 443
6
7#include <arpa/inet.h>
8#include <assert.h>
9#include <errno.h>
10#include <fcntl.h>
11#include <netinet/in.h>
12#include <netinet/tcp.h>
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <sys/select.h>
17#include <sys/socket.h>
18#include <unistd.h>
19
20#include "test.h"
21#include "easy-tls.h"
22
23void
24test_process_init(int fd, int client_p, void *apparg)
25{
26 fprintf(stderr, "test_process_init(fd = %d, client_p = %d, apparg = %p)\n", fd, client_p, apparg);
27}
28
29void
30test_errflush(int child_p, char *errbuf, size_t num, void *apparg)
31{
32 fputs(errbuf, stderr);
33}
34
35
36int
37main(int argc, char *argv[])
38{
39 int s, fd, r;
40 FILE *conn_in;
41 FILE *conn_out;
42 char buf[256];
43 SSL_CTX *ctx;
44 int client_p = 0;
45 int port;
46 int tls = 0;
47 char infobuf[TLS_INFO_SIZE + 1];
48
49 if (argc > 1 && argv[1][0] == '-') {
50 fputs("Usage: test [port] -- server\n"
51 " test num.num.num.num [port] -- client\n",
52 stderr);
53 exit(1);
54 }
55
56 if (argc > 1) {
57 if (strchr(argv[1], '.')) {
58 client_p = 1;
59 }
60 }
61
62 fputs(client_p ? "Client\n" : "Server\n", stderr);
63
64 {
65 struct tls_create_ctx_args a = tls_create_ctx_defaultargs();
66 a.client_p = client_p;
67 a.certificate_file = "cert.pem";
68 a.key_file = "cert.pem";
69 a.ca_file = "cacerts.pem";
70
71 ctx = tls_create_ctx(a, NULL);
72 if (ctx == NULL)
73 exit(1);
74 }
75
76 s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
77 if (s == -1) {
78 perror("socket");
79 exit(1);
80 }
81
82 if (client_p) {
83 struct sockaddr_in addr;
84 size_t addr_len = sizeof addr;
85
86 addr.sin_family = AF_INET;
87 assert(argc > 1);
88 if (argc > 2)
89 sscanf(argv[2], "%d", &port);
90 else
91 port = C_PORT;
92 addr.sin_port = htons(port);
93 addr.sin_addr.s_addr = inet_addr(argv[1]);
94
95 r = connect(s, &addr, addr_len);
96 if (r != 0) {
97 perror("connect");
98 exit(1);
99 }
100 fd = s;
101 fprintf(stderr, "Connect (fd = %d).\n", fd);
102 } else {
103 /* server */
104 {
105 int i = 1;
106
107 r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *) &i, sizeof i);
108 if (r == -1) {
109 perror("setsockopt");
110 exit(1);
111 }
112 }
113
114 {
115 struct sockaddr_in addr;
116 size_t addr_len = sizeof addr;
117
118 if (argc > 1)
119 sscanf(argv[1], "%d", &port);
120 else
121 port = L_PORT;
122 addr.sin_family = AF_INET;
123 addr.sin_port = htons(port);
124 addr.sin_addr.s_addr = INADDR_ANY;
125
126 r = bind(s, &addr, addr_len);
127 if (r != 0) {
128 perror("bind");
129 exit(1);
130 }
131 }
132
133 r = listen(s, 1);
134 if (r == -1) {
135 perror("listen");
136 exit(1);
137 }
138
139 fprintf(stderr, "Listening at port %i.\n", port);
140
141 fd = accept(s, NULL, 0);
142 if (fd == -1) {
143 perror("accept");
144 exit(1);
145 }
146
147 fprintf(stderr, "Accept (fd = %d).\n", fd);
148 }
149
150 conn_in = fdopen(fd, "r");
151 if (conn_in == NULL) {
152 perror("fdopen");
153 exit(1);
154 }
155 conn_out = fdopen(fd, "w");
156 if (conn_out == NULL) {
157 perror("fdopen");
158 exit(1);
159 }
160
161 setvbuf(conn_in, NULL, _IOLBF, 256);
162 setvbuf(conn_out, NULL, _IOLBF, 256);
163
164 while (fgets(buf, sizeof buf, stdin) != NULL) {
165 if (buf[0] == 'W') {
166 fprintf(conn_out, "%.*s\r\n", (int)(strlen(buf + 1) - 1), buf + 1);
167 fprintf(stderr, ">>> %.*s\n", (int)(strlen(buf + 1) - 1), buf + 1);
168 } else if (buf[0] == 'C') {
169 fprintf(stderr, "Closing.\n");
170 fclose(conn_in);
171 fclose(conn_out);
172 exit(0);
173 } else if (buf[0] == 'R') {
174 int lines = 0;
175
176 sscanf(buf + 1, "%d", &lines);
177 do {
178 if (fgets(buf, sizeof buf, conn_in) == NULL) {
179 if (ferror(conn_in)) {
180 fprintf(stderr, "ERROR\n");
181 exit(1);
182 }
183 fprintf(stderr, "CLOSED\n");
184 return 0;
185 }
186 fprintf(stderr, "<<< %s", buf);
187 } while (--lines > 0);
188 } else if (buf[0] == 'T') {
189 int infofd;
190
191 tls++;
192 {
193 struct tls_start_proxy_args a = tls_start_proxy_defaultargs();
194 a.fd = fd;
195 a.client_p = client_p;
196 a.ctx = ctx;
197 a.infofd = &infofd;
198 r = tls_start_proxy(a, NULL);
199 }
200 assert(r != 1);
201 if (r != 0) {
202 fprintf(stderr, "tls_start_proxy failed: %d\n", r);
203 switch (r) {
204 case -1:
205 fputs("socketpair", stderr); break;
206 case 2:
207 fputs("FD_SETSIZE exceeded", stderr); break;
208 case -3:
209 fputs("pipe", stderr); break;
210 case -4:
211 fputs("fork", stderr); break;
212 case -5:
213 fputs("dup2", stderr); break;
214 default:
215 fputs("?", stderr);
216 }
217 if (r < 0)
218 perror("");
219 else
220 fputc('\n', stderr);
221 exit(1);
222 }
223
224 r = read(infofd, infobuf, sizeof infobuf - 1);
225 if (r > 0) {
226 const char *info = infobuf;
227 const char *eol;
228
229 infobuf[r] = '\0';
230 while ((eol = strchr(info, '\n')) != NULL) {
231 fprintf(stderr, "+++ `%.*s'\n", eol - info, info);
232 info = eol+1;
233 }
234 close (infofd);
235 }
236 } else {
237 fprintf(stderr, "W... write line to network\n"
238 "R[n] read line (n lines) from network\n"
239 "C close\n"
240 "T start %sTLS proxy\n", tls ? "another " : "");
241 }
242 }
243 return 0;
244}
diff --git a/src/lib/libssl/src/demos/easy_tls/test.h b/src/lib/libssl/src/demos/easy_tls/test.h
new file mode 100644
index 0000000000..c580169464
--- /dev/null
+++ b/src/lib/libssl/src/demos/easy_tls/test.h
@@ -0,0 +1,11 @@
1/* test.h */
2/* $Id: test.h,v 1.1 2002/05/15 02:29:18 beck Exp $ */
3
4
5void test_process_init(int fd, int client_p, void *apparg);
6#define TLS_APP_PROCESS_INIT test_process_init
7
8#undef TLS_CUMULATE_ERRORS
9
10void test_errflush(int child_p, char *errbuf, size_t num, void *apparg);
11#define TLS_APP_ERRFLUSH test_errflush
diff --git a/src/lib/libssl/src/demos/eay/Makefile b/src/lib/libssl/src/demos/eay/Makefile
new file mode 100644
index 0000000000..2d22eaca56
--- /dev/null
+++ b/src/lib/libssl/src/demos/eay/Makefile
@@ -0,0 +1,24 @@
1CC=cc
2CFLAGS= -g -I../../include
3#LIBS= -L../.. -lcrypto -lssl
4LIBS= -L../.. ../../libssl.a ../../libcrypto.a
5
6# the file conn.c requires a file "proxy.h" which I couldn't find...
7#EXAMPLES=base64 conn loadrsa
8EXAMPLES=base64 loadrsa
9
10all: $(EXAMPLES)
11
12base64: base64.o
13 $(CC) -o base64 base64.o $(LIBS)
14#
15# sorry... can't find "proxy.h"
16#conn: conn.o
17# $(CC) -o conn conn.o $(LIBS)
18
19loadrsa: loadrsa.o
20 $(CC) -o loadrsa loadrsa.o $(LIBS)
21
22clean:
23 rm -f $(EXAMPLES) *.o
24
diff --git a/src/lib/libssl/src/demos/eay/base64.c b/src/lib/libssl/src/demos/eay/base64.c
new file mode 100644
index 0000000000..4b8b0627d1
--- /dev/null
+++ b/src/lib/libssl/src/demos/eay/base64.c
@@ -0,0 +1,49 @@
1/* This is a simple example of using the base64 BIO to a memory BIO and then
2 * getting the data.
3 */
4#include <stdio.h>
5#include <openssl/bio.h>
6#include <openssl/evp.h>
7
8main()
9 {
10 int i;
11 BIO *mbio,*b64bio,*bio;
12 char buf[512];
13 char *p;
14
15 mbio=BIO_new(BIO_s_mem());
16 b64bio=BIO_new(BIO_f_base64());
17
18 bio=BIO_push(b64bio,mbio);
19 /* We now have bio pointing at b64->mem, the base64 bio encodes on
20 * write and decodes on read */
21
22 for (;;)
23 {
24 i=fread(buf,1,512,stdin);
25 if (i <= 0) break;
26 BIO_write(bio,buf,i);
27 }
28 /* We need to 'flush' things to push out the encoding of the
29 * last few bytes. There is special encoding if it is not a
30 * multiple of 3
31 */
32 BIO_flush(bio);
33
34 printf("We have %d bytes available\n",BIO_pending(mbio));
35
36 /* We will now get a pointer to the data and the number of elements. */
37 /* hmm... this one was not defined by a macro in bio.h, it will be for
38 * 0.9.1. The other option is too just read from the memory bio.
39 */
40 i=(int)BIO_ctrl(mbio,BIO_CTRL_INFO,0,(char *)&p);
41
42 printf("%d\n",i);
43 fwrite("---\n",1,4,stdout);
44 fwrite(p,1,i,stdout);
45 fwrite("---\n",1,4,stdout);
46
47 /* This call will walk the chain freeing all the BIOs */
48 BIO_free_all(bio);
49 }
diff --git a/src/lib/libssl/src/demos/eay/conn.c b/src/lib/libssl/src/demos/eay/conn.c
new file mode 100644
index 0000000000..c4b8f5163e
--- /dev/null
+++ b/src/lib/libssl/src/demos/eay/conn.c
@@ -0,0 +1,105 @@
1/* NOCW */
2/* demos/eay/conn.c */
3
4/* A minimal program to connect to a port using the sock4a protocol.
5 *
6 * cc -I../../include conn.c -L../.. -lcrypto
7 */
8#include <stdio.h>
9#include <stdlib.h>
10#include <openssl/err.h>
11#include <openssl/bio.h>
12/* #include "proxy.h" */
13
14extern int errno;
15
16int main(argc,argv)
17int argc;
18char *argv[];
19 {
20 PROXY *pxy;
21 char *host;
22 char buf[1024*10],*p;
23 BIO *bio;
24 int i,len,off,ret=1;
25
26 if (argc <= 1)
27 host="localhost:4433";
28 else
29 host=argv[1];
30
31 /* Lets get nice error messages */
32 ERR_load_crypto_strings();
33
34 /* First, configure proxy settings */
35 pxy=PROXY_new();
36 PROXY_add_server(pxy,PROXY_PROTOCOL_SOCKS,"gromit:1080");
37
38 bio=BIO_new(BIO_s_socks4a_connect());
39
40 BIO_set_conn_hostname(bio,host);
41 BIO_set_proxies(bio,pxy);
42 BIO_set_socks_userid(bio,"eay");
43 BIO_set_nbio(bio,1);
44
45 p="GET / HTTP/1.0\r\n\r\n";
46 len=strlen(p);
47
48 off=0;
49 for (;;)
50 {
51 i=BIO_write(bio,&(p[off]),len);
52 if (i <= 0)
53 {
54 if (BIO_should_retry(bio))
55 {
56 fprintf(stderr,"write DELAY\n");
57 sleep(1);
58 continue;
59 }
60 else
61 {
62 goto err;
63 }
64 }
65 off+=i;
66 len-=i;
67 if (len <= 0) break;
68 }
69
70 for (;;)
71 {
72 i=BIO_read(bio,buf,sizeof(buf));
73 if (i == 0) break;
74 if (i < 0)
75 {
76 if (BIO_should_retry(bio))
77 {
78 fprintf(stderr,"read DELAY\n");
79 sleep(1);
80 continue;
81 }
82 goto err;
83 }
84 fwrite(buf,1,i,stdout);
85 }
86
87 ret=1;
88
89 if (0)
90 {
91err:
92 if (ERR_peek_error() == 0) /* system call error */
93 {
94 fprintf(stderr,"errno=%d ",errno);
95 perror("error");
96 }
97 else
98 ERR_print_errors_fp(stderr);
99 }
100 BIO_free_all(bio);
101 if (pxy != NULL) PROXY_free(pxy);
102 exit(!ret);
103 return(ret);
104 }
105
diff --git a/src/lib/libssl/src/demos/eay/loadrsa.c b/src/lib/libssl/src/demos/eay/loadrsa.c
new file mode 100644
index 0000000000..79f1885ca4
--- /dev/null
+++ b/src/lib/libssl/src/demos/eay/loadrsa.c
@@ -0,0 +1,53 @@
1#include <stdio.h>
2#include <openssl/rsa.h>
3
4/* This is a simple program to generate an RSA private key. It then
5 * saves both the public and private key into a char array, then
6 * re-reads them. It saves them as DER encoded binary data.
7 */
8
9void callback(stage,count,arg)
10int stage,count;
11char *arg;
12 {
13 FILE *out;
14
15 out=(FILE *)arg;
16 fprintf(out,"%d",stage);
17 if (stage == 3)
18 fprintf(out,"\n");
19 fflush(out);
20 }
21
22main()
23 {
24 RSA *rsa,*pub_rsa,*priv_rsa;
25 int len;
26 unsigned char buf[1024],*p;
27
28 rsa=RSA_generate_key(512,RSA_F4,callback,(char *)stdout);
29
30 p=buf;
31
32 /* Save the public key into buffer, we know it will be big enough
33 * but we should really check how much space we need by calling the
34 * i2d functions with a NULL second parameter */
35 len=i2d_RSAPublicKey(rsa,&p);
36 len+=i2d_RSAPrivateKey(rsa,&p);
37
38 printf("The public and private key are now both in a char array\n");
39 printf("and are taking up %d bytes\n",len);
40
41 RSA_free(rsa);
42
43 p=buf;
44 pub_rsa=d2i_RSAPublicKey(NULL,&p,(long)len);
45 len-=(p-buf);
46 priv_rsa=d2i_RSAPrivateKey(NULL,&p,(long)len);
47
48 if ((pub_rsa == NULL) || (priv_rsa == NULL))
49 ERR_print_errors_fp(stderr);
50
51 RSA_free(pub_rsa);
52 RSA_free(priv_rsa);
53 }
diff --git a/src/lib/libssl/src/demos/pkcs12/README b/src/lib/libssl/src/demos/pkcs12/README
new file mode 100644
index 0000000000..c87434b04f
--- /dev/null
+++ b/src/lib/libssl/src/demos/pkcs12/README
@@ -0,0 +1,3 @@
1PKCS#12 demo applications
2
3Written by Steve Henson.
diff --git a/src/lib/libssl/src/demos/pkcs12/pkread.c b/src/lib/libssl/src/demos/pkcs12/pkread.c
new file mode 100644
index 0000000000..8e1b686312
--- /dev/null
+++ b/src/lib/libssl/src/demos/pkcs12/pkread.c
@@ -0,0 +1,61 @@
1/* pkread.c */
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <openssl/pem.h>
6#include <openssl/err.h>
7#include <openssl/pkcs12.h>
8
9/* Simple PKCS#12 file reader */
10
11int main(int argc, char **argv)
12{
13 FILE *fp;
14 EVP_PKEY *pkey;
15 X509 *cert;
16 STACK_OF(X509) *ca = NULL;
17 PKCS12 *p12;
18 int i;
19 if (argc != 4) {
20 fprintf(stderr, "Usage: pkread p12file password opfile\n");
21 exit (1);
22 }
23 SSLeay_add_all_algorithms();
24 ERR_load_crypto_strings();
25 if (!(fp = fopen(argv[1], "rb"))) {
26 fprintf(stderr, "Error opening file %s\n", argv[1]);
27 exit(1);
28 }
29 p12 = d2i_PKCS12_fp(fp, NULL);
30 fclose (fp);
31 if (!p12) {
32 fprintf(stderr, "Error reading PKCS#12 file\n");
33 ERR_print_errors_fp(stderr);
34 exit (1);
35 }
36 if (!PKCS12_parse(p12, argv[2], &pkey, &cert, &ca)) {
37 fprintf(stderr, "Error parsing PKCS#12 file\n");
38 ERR_print_errors_fp(stderr);
39 exit (1);
40 }
41 PKCS12_free(p12);
42 if (!(fp = fopen(argv[3], "w"))) {
43 fprintf(stderr, "Error opening file %s\n", argv[1]);
44 exit(1);
45 }
46 if (pkey) {
47 fprintf(fp, "***Private Key***\n");
48 PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
49 }
50 if (cert) {
51 fprintf(fp, "***User Certificate***\n");
52 PEM_write_X509_AUX(fp, cert);
53 }
54 if (ca && sk_num(ca)) {
55 fprintf(fp, "***Other Certificates***\n");
56 for (i = 0; i < sk_X509_num(ca); i++)
57 PEM_write_X509_AUX(fp, sk_X509_value(ca, i));
58 }
59 fclose(fp);
60 return 0;
61}
diff --git a/src/lib/libssl/src/demos/pkcs12/pkwrite.c b/src/lib/libssl/src/demos/pkcs12/pkwrite.c
new file mode 100644
index 0000000000..15f839d1eb
--- /dev/null
+++ b/src/lib/libssl/src/demos/pkcs12/pkwrite.c
@@ -0,0 +1,46 @@
1/* pkwrite.c */
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <openssl/pem.h>
6#include <openssl/err.h>
7#include <openssl/pkcs12.h>
8
9/* Simple PKCS#12 file creator */
10
11int main(int argc, char **argv)
12{
13 FILE *fp;
14 EVP_PKEY *pkey;
15 X509 *cert;
16 PKCS12 *p12;
17 if (argc != 5) {
18 fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
19 exit(1);
20 }
21 SSLeay_add_all_algorithms();
22 ERR_load_crypto_strings();
23 if (!(fp = fopen(argv[1], "r"))) {
24 fprintf(stderr, "Error opening file %s\n", argv[1]);
25 exit(1);
26 }
27 cert = PEM_read_X509(fp, NULL, NULL, NULL);
28 rewind(fp);
29 pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
30 fclose(fp);
31 p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0,0,0,0,0);
32 if(!p12) {
33 fprintf(stderr, "Error creating PKCS#12 structure\n");
34 ERR_print_errors_fp(stderr);
35 exit(1);
36 }
37 if (!(fp = fopen(argv[4], "wb"))) {
38 fprintf(stderr, "Error opening file %s\n", argv[1]);
39 ERR_print_errors_fp(stderr);
40 exit(1);
41 }
42 i2d_PKCS12_fp(fp, p12);
43 PKCS12_free(p12);
44 fclose(fp);
45 return 0;
46}
diff --git a/src/lib/libssl/src/demos/prime/Makefile b/src/lib/libssl/src/demos/prime/Makefile
new file mode 100644
index 0000000000..0166cd46fe
--- /dev/null
+++ b/src/lib/libssl/src/demos/prime/Makefile
@@ -0,0 +1,20 @@
1CC=cc
2CFLAGS= -g -I../../include -Wall
3LIBS= -L../.. -lcrypto
4EXAMPLES=prime
5
6all: $(EXAMPLES)
7
8prime: prime.o
9 $(CC) -o prime prime.o $(LIBS)
10
11clean:
12 rm -f $(EXAMPLES) *.o
13
14test: all
15 @echo Test creating a 128-bit prime
16 ./prime 128
17 @echo Test creating a 256-bit prime
18 ./prime 256
19 @echo Test creating a 512-bit prime
20 ./prime 512
diff --git a/src/lib/libssl/src/demos/sign/Makefile b/src/lib/libssl/src/demos/sign/Makefile
new file mode 100644
index 0000000000..e6d391e4ad
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/Makefile
@@ -0,0 +1,15 @@
1CC=cc
2CFLAGS= -g -I../../include -Wall
3LIBS= -L../.. -lcrypto
4EXAMPLES=sign
5
6all: $(EXAMPLES)
7
8sign: sign.o
9 $(CC) -o sign sign.o $(LIBS)
10
11clean:
12 rm -f $(EXAMPLES) *.o
13
14test: all
15 ./sign
diff --git a/src/lib/libssl/src/demos/state_machine/Makefile b/src/lib/libssl/src/demos/state_machine/Makefile
new file mode 100644
index 0000000000..c7a114540d
--- /dev/null
+++ b/src/lib/libssl/src/demos/state_machine/Makefile
@@ -0,0 +1,9 @@
1CFLAGS=-I../../include -Wall -Werror -g
2
3all: state_machine
4
5state_machine: state_machine.o
6 $(CC) -o state_machine state_machine.o -L../.. -lssl -lcrypto
7
8test: state_machine
9 ./state_machine 10000 ../../apps/server.pem ../../apps/server.pem
diff --git a/src/lib/libssl/src/demos/state_machine/state_machine.c b/src/lib/libssl/src/demos/state_machine/state_machine.c
new file mode 100644
index 0000000000..fef3f3e3d1
--- /dev/null
+++ b/src/lib/libssl/src/demos/state_machine/state_machine.c
@@ -0,0 +1,416 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * Nuron, a leader in hardware encryption technology, generously
57 * sponsored the development of this demo by Ben Laurie.
58 *
59 * See http://www.nuron.com/.
60 */
61
62/*
63 * the aim of this demo is to provide a fully working state-machine
64 * style SSL implementation, i.e. one where the main loop acquires
65 * some data, then converts it from or to SSL by feeding it into the
66 * SSL state machine. It then does any I/O required by the state machine
67 * and loops.
68 *
69 * In order to keep things as simple as possible, this implementation
70 * listens on a TCP socket, which it expects to get an SSL connection
71 * on (for example, from s_client) and from then on writes decrypted
72 * data to stdout and encrypts anything arriving on stdin. Verbose
73 * commentary is written to stderr.
74 *
75 * This implementation acts as a server, but it can also be done for a client. */
76
77#include <openssl/ssl.h>
78#include <assert.h>
79#include <unistd.h>
80#include <string.h>
81#include <openssl/err.h>
82#include <sys/types.h>
83#include <sys/socket.h>
84#include <netinet/in.h>
85
86/* die_unless is intended to work like assert, except that it happens
87 always, even if NDEBUG is defined. Use assert as a stopgap. */
88
89#define die_unless(x) assert(x)
90
91typedef struct
92 {
93 SSL_CTX *pCtx;
94 BIO *pbioRead;
95 BIO *pbioWrite;
96 SSL *pSSL;
97 } SSLStateMachine;
98
99void SSLStateMachine_print_error(SSLStateMachine *pMachine,const char *szErr)
100 {
101 unsigned long l;
102
103 fprintf(stderr,"%s\n",szErr);
104 while((l=ERR_get_error()))
105 {
106 char buf[1024];
107
108 ERR_error_string_n(l,buf,sizeof buf);
109 fprintf(stderr,"Error %lx: %s\n",l,buf);
110 }
111 }
112
113SSLStateMachine *SSLStateMachine_new(const char *szCertificateFile,
114 const char *szKeyFile)
115 {
116 SSLStateMachine *pMachine=malloc(sizeof *pMachine);
117 int n;
118
119 die_unless(pMachine);
120
121 pMachine->pCtx=SSL_CTX_new(SSLv23_server_method());
122 die_unless(pMachine->pCtx);
123
124 n=SSL_CTX_use_certificate_file(pMachine->pCtx,szCertificateFile,
125 SSL_FILETYPE_PEM);
126 die_unless(n > 0);
127
128 n=SSL_CTX_use_PrivateKey_file(pMachine->pCtx,szKeyFile,SSL_FILETYPE_PEM);
129 die_unless(n > 0);
130
131 pMachine->pSSL=SSL_new(pMachine->pCtx);
132 die_unless(pMachine->pSSL);
133
134 pMachine->pbioRead=BIO_new(BIO_s_mem());
135
136 pMachine->pbioWrite=BIO_new(BIO_s_mem());
137
138 SSL_set_bio(pMachine->pSSL,pMachine->pbioRead,pMachine->pbioWrite);
139
140 SSL_set_accept_state(pMachine->pSSL);
141
142 return pMachine;
143 }
144
145void SSLStateMachine_read_inject(SSLStateMachine *pMachine,
146 const unsigned char *aucBuf,int nBuf)
147 {
148 int n=BIO_write(pMachine->pbioRead,aucBuf,nBuf);
149 /* If it turns out this assert fails, then buffer the data here
150 * and just feed it in in churn instead. Seems to me that it
151 * should be guaranteed to succeed, though.
152 */
153 assert(n == nBuf);
154 fprintf(stderr,"%d bytes of encrypted data fed to state machine\n",n);
155 }
156
157int SSLStateMachine_read_extract(SSLStateMachine *pMachine,
158 unsigned char *aucBuf,int nBuf)
159 {
160 int n;
161
162 if(!SSL_is_init_finished(pMachine->pSSL))
163 {
164 fprintf(stderr,"Doing SSL_accept\n");
165 n=SSL_accept(pMachine->pSSL);
166 if(n == 0)
167 fprintf(stderr,"SSL_accept returned zero\n");
168 if(n < 0)
169 {
170 int err;
171
172 if((err=SSL_get_error(pMachine->pSSL,n)) == SSL_ERROR_WANT_READ)
173 {
174 fprintf(stderr,"SSL_accept wants more data\n");
175 return 0;
176 }
177
178 SSLStateMachine_print_error(pMachine,"SSL_accept error");
179 exit(7);
180 }
181 return 0;
182 }
183
184 n=SSL_read(pMachine->pSSL,aucBuf,nBuf);
185 if(n < 0)
186 {
187 int err=SSL_get_error(pMachine->pSSL,n);
188
189 if(err == SSL_ERROR_WANT_READ)
190 {
191 fprintf(stderr,"SSL_read wants more data\n");
192 return 0;
193 }
194
195 SSLStateMachine_print_error(pMachine,"SSL_read error");
196 exit(8);
197 }
198
199 fprintf(stderr,"%d bytes of decrypted data read from state machine\n",n);
200 return n;
201 }
202
203int SSLStateMachine_write_can_extract(SSLStateMachine *pMachine)
204 {
205 int n=BIO_pending(pMachine->pbioWrite);
206 if(n)
207 fprintf(stderr,"There is encrypted data available to write\n");
208 else
209 fprintf(stderr,"There is no encrypted data available to write\n");
210
211 return n;
212 }
213
214int SSLStateMachine_write_extract(SSLStateMachine *pMachine,
215 unsigned char *aucBuf,int nBuf)
216 {
217 int n;
218
219 n=BIO_read(pMachine->pbioWrite,aucBuf,nBuf);
220 fprintf(stderr,"%d bytes of encrypted data read from state machine\n",n);
221 return n;
222 }
223
224void SSLStateMachine_write_inject(SSLStateMachine *pMachine,
225 const unsigned char *aucBuf,int nBuf)
226 {
227 int n=SSL_write(pMachine->pSSL,aucBuf,nBuf);
228 /* If it turns out this assert fails, then buffer the data here
229 * and just feed it in in churn instead. Seems to me that it
230 * should be guaranteed to succeed, though.
231 */
232 assert(n == nBuf);
233 fprintf(stderr,"%d bytes of unencrypted data fed to state machine\n",n);
234 }
235
236int OpenSocket(int nPort)
237 {
238 int nSocket;
239 struct sockaddr_in saServer;
240 struct sockaddr_in saClient;
241 int one=1;
242 int nSize;
243 int nFD;
244 int nLen;
245
246 nSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
247 if(nSocket < 0)
248 {
249 perror("socket");
250 exit(1);
251 }
252
253 if(setsockopt(nSocket,SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof one) < 0)
254 {
255 perror("setsockopt");
256 exit(2);
257 }
258
259 memset(&saServer,0,sizeof saServer);
260 saServer.sin_family=AF_INET;
261 saServer.sin_port=htons(nPort);
262 nSize=sizeof saServer;
263 if(bind(nSocket,(struct sockaddr *)&saServer,nSize) < 0)
264 {
265 perror("bind");
266 exit(3);
267 }
268
269 if(listen(nSocket,512) < 0)
270 {
271 perror("listen");
272 exit(4);
273 }
274
275 nLen=sizeof saClient;
276 nFD=accept(nSocket,(struct sockaddr *)&saClient,&nLen);
277 if(nFD < 0)
278 {
279 perror("accept");
280 exit(5);
281 }
282
283 fprintf(stderr,"Incoming accepted on port %d\n",nPort);
284
285 return nFD;
286 }
287
288int main(int argc,char **argv)
289 {
290 SSLStateMachine *pMachine;
291 int nPort;
292 int nFD;
293 const char *szCertificateFile;
294 const char *szKeyFile;
295 char rbuf[1];
296 int nrbuf=0;
297
298 if(argc != 4)
299 {
300 fprintf(stderr,"%s <port> <certificate file> <key file>\n",argv[0]);
301 exit(6);
302 }
303
304 nPort=atoi(argv[1]);
305 szCertificateFile=argv[2];
306 szKeyFile=argv[3];
307
308 SSL_library_init();
309 OpenSSL_add_ssl_algorithms();
310 SSL_load_error_strings();
311 ERR_load_crypto_strings();
312
313 nFD=OpenSocket(nPort);
314
315 pMachine=SSLStateMachine_new(szCertificateFile,szKeyFile);
316
317 for( ; ; )
318 {
319 fd_set rfds,wfds;
320 unsigned char buf[1024];
321 int n;
322
323 FD_ZERO(&rfds);
324 FD_ZERO(&wfds);
325
326 /* Select socket for input */
327 FD_SET(nFD,&rfds);
328
329 /* check whether there's decrypted data */
330 if(!nrbuf)
331 nrbuf=SSLStateMachine_read_extract(pMachine,rbuf,1);
332
333 /* if there's decrypted data, check whether we can write it */
334 if(nrbuf)
335 FD_SET(1,&wfds);
336
337 /* Select socket for output */
338 if(SSLStateMachine_write_can_extract(pMachine))
339 FD_SET(nFD,&wfds);
340
341 /* Select stdin for input */
342 FD_SET(0,&rfds);
343
344 /* Wait for something to do something */
345 n=select(nFD+1,&rfds,&wfds,NULL,NULL);
346 assert(n > 0);
347
348 /* Socket is ready for input */
349 if(FD_ISSET(nFD,&rfds))
350 {
351 n=read(nFD,buf,sizeof buf);
352 if(n == 0)
353 {
354 fprintf(stderr,"Got EOF on socket\n");
355 exit(0);
356 }
357 assert(n > 0);
358
359 SSLStateMachine_read_inject(pMachine,buf,n);
360 }
361
362 /* stdout is ready for output (and hence we have some to send it) */
363 if(FD_ISSET(1,&wfds))
364 {
365 assert(nrbuf == 1);
366 buf[0]=rbuf[0];
367 nrbuf=0;
368
369 n=SSLStateMachine_read_extract(pMachine,buf+1,sizeof buf-1);
370 if(n < 0)
371 {
372 SSLStateMachine_print_error(pMachine,"read extract failed");
373 break;
374 }
375 assert(n >= 0);
376 ++n;
377 if(n > 0) /* FIXME: has to be true now */
378 {
379 int w;
380
381 w=write(1,buf,n);
382 /* FIXME: we should push back any unwritten data */
383 assert(w == n);
384 }
385 }
386
387 /* Socket is ready for output (and therefore we have output to send) */
388 if(FD_ISSET(nFD,&wfds))
389 {
390 int w;
391
392 n=SSLStateMachine_write_extract(pMachine,buf,sizeof buf);
393 assert(n > 0);
394
395 w=write(nFD,buf,n);
396 /* FIXME: we should push back any unwritten data */
397 assert(w == n);
398 }
399
400 /* Stdin is ready for input */
401 if(FD_ISSET(0,&rfds))
402 {
403 n=read(0,buf,sizeof buf);
404 if(n == 0)
405 {
406 fprintf(stderr,"Got EOF on stdin\n");
407 exit(0);
408 }
409 assert(n > 0);
410
411 SSLStateMachine_write_inject(pMachine,buf,n);
412 }
413 }
414 /* not reached */
415 return 0;
416 }
diff --git a/src/lib/libssl/src/demos/tunala/A-client.pem b/src/lib/libssl/src/demos/tunala/A-client.pem
new file mode 100644
index 0000000000..a4caf6ef8a
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/A-client.pem
@@ -0,0 +1,84 @@
1Certificate:
2 Data:
3 Version: 3 (0x2)
4 Serial Number: 2 (0x2)
5 Signature Algorithm: md5WithRSAEncryption
6 Issuer: C=NZ, L=Wellington, O=Really Irresponsible Authorisation Authority (RIAA), OU=Cert-stamping, CN=Jackov al-Trades/Email=none@fake.domain
7 Validity
8 Not Before: Jan 16 05:19:30 2002 GMT
9 Not After : Jan 14 05:19:30 2012 GMT
10 Subject: C=NZ, L=Auckland, O=Mordor, OU=SSL grunt things, CN=tunala-client/Email=client@fake.domain
11 Subject Public Key Info:
12 Public Key Algorithm: rsaEncryption
13 RSA Public Key: (1024 bit)
14 Modulus (1024 bit):
15 00:b0:d3:56:5c:c8:7f:fb:f4:95:9d:04:84:4f:82:
16 b7:a2:75:5c:81:48:8c:56:5d:52:ee:38:e1:5c:c8:
17 9a:70:8e:72:f2:00:1c:17:ef:df:b7:06:59:82:04:
18 f1:f6:49:11:12:a6:4d:cb:1e:ed:ac:59:1c:4a:d0:
19 3d:de:e6:f2:8d:cd:39:c2:0f:e0:46:2f:db:cb:9f:
20 47:f7:56:e7:f8:16:5f:68:71:fb:3a:e3:ab:d2:e5:
21 05:b7:da:65:61:fe:6d:30:e4:12:a8:b5:c1:71:24:
22 6b:aa:80:05:41:17:a0:8b:6e:8b:e6:04:cf:85:7b:
23 2a:ac:a1:79:7d:f4:96:6e:77
24 Exponent: 65537 (0x10001)
25 X509v3 extensions:
26 X509v3 Basic Constraints:
27 CA:FALSE
28 Netscape Comment:
29 OpenSSL Generated Certificate
30 X509v3 Subject Key Identifier:
31 F8:43:CB:4F:4D:4F:BC:6E:52:1A:FD:F9:7B:E1:12:3F:A7:A3:BA:93
32 X509v3 Authority Key Identifier:
33 keyid:49:FB:45:72:12:C4:CC:E1:45:A1:D3:08:9E:95:C4:2C:6D:55:3F:17
34 DirName:/C=NZ/L=Wellington/O=Really Irresponsible Authorisation Authority (RIAA)/OU=Cert-stamping/CN=Jackov al-Trades/Email=none@fake.domain
35 serial:00
36
37 Signature Algorithm: md5WithRSAEncryption
38 8f:5f:0e:43:da:9d:61:43:7e:03:38:9a:e6:50:9d:42:e8:95:
39 34:49:75:ec:04:8d:5c:85:99:94:70:a0:e7:1f:1e:a0:8b:0f:
40 d6:e2:cb:f7:35:d9:96:72:bd:a6:e9:8d:4e:b1:e2:ac:97:7f:
41 2f:70:01:9d:aa:04:bc:d4:01:2b:63:77:a5:de:63:3c:a8:f5:
42 f2:72:af:ec:11:12:c0:d4:70:cf:71:a6:fb:e9:1d:b3:27:07:
43 aa:f2:b1:f3:87:d6:ab:8b:ce:c2:08:1b:3c:f9:ba:ff:77:71:
44 86:09:ef:9e:4e:04:06:63:44:e9:93:20:90:c7:2d:50:c6:50:
45 f8:66
46-----BEGIN CERTIFICATE-----
47MIID9TCCA16gAwIBAgIBAjANBgkqhkiG9w0BAQQFADCBtDELMAkGA1UEBhMCTlox
48EzARBgNVBAcTCldlbGxpbmd0b24xPDA6BgNVBAoTM1JlYWxseSBJcnJlc3BvbnNp
49YmxlIEF1dGhvcmlzYXRpb24gQXV0aG9yaXR5IChSSUFBKTEWMBQGA1UECxMNQ2Vy
50dC1zdGFtcGluZzEZMBcGA1UEAxMQSmFja292IGFsLVRyYWRlczEfMB0GCSqGSIb3
51DQEJARYQbm9uZUBmYWtlLmRvbWFpbjAeFw0wMjAxMTYwNTE5MzBaFw0xMjAxMTQw
52NTE5MzBaMIGHMQswCQYDVQQGEwJOWjERMA8GA1UEBxMIQXVja2xhbmQxDzANBgNV
53BAoTBk1vcmRvcjEZMBcGA1UECxMQU1NMIGdydW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H2SRESpk3LHu2sWRxK0D3e5vKNzTnCD+BGL9vLn0f3Vuf4Fl9ocfs6
7346vS5QW32mVh/m0w5BKotcFxJGuqgAVBF6CLbovmBM+FeyqsoXl99JZudwIDAQAB
74AoGAU4chbqbPvkclPYzaq2yGLlneHrwUft+KwzlfS6L/QVgo+CQRIUWQmjaHpaGM
75YtjVFcg1S1QK1bUqZjTEZT0XKhfbYmqW8yYTfbcDEbnY7esoYlvIlW8qRlPRlTBE
76utKrtZafmVhLgoNawYGD0aLZofPqpYjbGUlrC7nrem2vNJECQQDVLD3Qb+OlEMET
7773ApnJhYsK3e+G2LTrtjrS8y5zS4+Xv61XUqvdV7ogzRl0tpvSAmMOItVyoYadkB
78S3xSIWX9AkEA1Fm1FhkQSZwGG5rf4c6gMN71jJ6JE3/kocdVa0sUjRevIupo4XQ2
79Vkykxi84MRP8cfHqyjewq7Ozv3op2MGWgwJBAKemsb66IJjzAkaBav7u70nhOf0/
80+Dc1Zl7QF2y7NVW8sGrnccx5m+ot2lMD4AV6/kvK6jaqdKrapBZGnbGiHqkCQQDI
81T1r33mqz1R8Z2S2Jtzz6/McKf930a/dC+GLGVEutkILf39lRmytKmv/wB0jtWtoO
82rlJ5sLDSNzC+1cE1u997AkEAu3IrtGmLKiuS6kDj6W47m+iiTIsuSJtTJb1SbUaK
83fIoBNFxbvJYW6rUU9+PxpMRaEhzh5s24/jBOE+mlb17mRQ==
84-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/tunala/A-server.pem b/src/lib/libssl/src/demos/tunala/A-server.pem
new file mode 100644
index 0000000000..e9f37b1895
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/A-server.pem
@@ -0,0 +1,84 @@
1Certificate:
2 Data:
3 Version: 3 (0x2)
4 Serial Number: 1 (0x1)
5 Signature Algorithm: md5WithRSAEncryption
6 Issuer: C=NZ, L=Wellington, O=Really Irresponsible Authorisation Authority (RIAA), OU=Cert-stamping, CN=Jackov al-Trades/Email=none@fake.domain
7 Validity
8 Not Before: Jan 16 05:14:06 2002 GMT
9 Not After : Jan 14 05:14:06 2012 GMT
10 Subject: C=NZ, L=Wellington, O=Middle Earth, OU=SSL dev things, CN=tunala-server/Email=server@fake.domain
11 Subject Public Key Info:
12 Public Key Algorithm: rsaEncryption
13 RSA Public Key: (1024 bit)
14 Modulus (1024 bit):
15 00:a9:3e:62:87:97:13:6b:de:8f:bc:1d:0a:3f:65:
16 0c:f9:76:a3:53:ce:97:30:27:0d:c6:df:72:1f:8d:
17 5a:ce:58:23:6a:65:e5:e3:72:1a:8d:7f:fe:90:01:
18 ea:42:f1:9f:6e:7b:0a:bd:eb:52:15:7b:f4:3d:9c:
19 4e:db:74:29:2b:d1:81:9d:b9:9e:18:2b:87:e1:da:
20 50:20:3c:59:6c:c9:83:3e:2c:11:0b:78:1e:03:f4:
21 56:3a:db:95:6a:75:33:85:a9:7b:cc:3c:4a:67:96:
22 f2:24:b2:a0:cb:2e:cc:52:18:16:6f:44:d9:29:64:
23 07:2e:fb:56:cc:7c:dc:a2:d7
24 Exponent: 65537 (0x10001)
25 X509v3 extensions:
26 X509v3 Basic Constraints:
27 CA:FALSE
28 Netscape Comment:
29 OpenSSL Generated Certificate
30 X509v3 Subject Key Identifier:
31 70:AC:7A:B5:6E:97:C2:82:AF:11:9E:32:CB:8D:48:49:93:B7:DC:22
32 X509v3 Authority Key Identifier:
33 keyid:49:FB:45:72:12:C4:CC:E1:45:A1:D3:08:9E:95:C4:2C:6D:55:3F:17
34 DirName:/C=NZ/L=Wellington/O=Really Irresponsible Authorisation Authority (RIAA)/OU=Cert-stamping/CN=Jackov al-Trades/Email=none@fake.domain
35 serial:00
36
37 Signature Algorithm: md5WithRSAEncryption
38 2e:cb:a3:cd:6d:a8:9d:d1:dc:e5:f0:e0:27:7e:4b:5a:90:a8:
39 85:43:f0:05:f7:04:43:d7:5f:d1:a5:8f:5c:58:eb:fc:da:c6:
40 7c:e0:0b:2b:98:72:95:f6:79:48:96:7a:fa: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l/6Q2uyU49cCN+2aYULZCAfs
78taNvxBspAkEAw0alNub+xj2AVQvaxOB1sGfKzsJjHCzKIxUXn/tJi3j0+2asmkBZ
79Umx1MWr9jKQBnCMciCRUbnMEZiElOxCN/wJAfAeQl6Z19gx206lJzzzEo3dOye54
80k02DSxijT8q9pBzf9bN3ZK987BybtiZr8p+bZiYVsSOF1wViSLURdD1QYQJAIaMU
81qH1n24wShBPTrmAfxbBLTgxL+Dl65Eoo1KT7iSvfv0JzbuqwuDL4iPeuD0DdCiE+
82M/FWHeRwGIuTFzaFzwJBANKwx0jZS/h093w9g0Clw6UzeA1P5VcAt9y+qMC9hO3c
834KXwIxQAt9yRaFLpiIR9do5bjjKNnMguf3aO/XRSDQM=
84-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/tunala/CA.pem b/src/lib/libssl/src/demos/tunala/CA.pem
new file mode 100644
index 0000000000..7a55b5463e
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/CA.pem
@@ -0,0 +1,24 @@
1-----BEGIN CERTIFICATE-----
2MIID9zCCA2CgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBtDELMAkGA1UEBhMCTlox
3EzARBgNVBAcTCldlbGxpbmd0b24xPDA6BgNVBAoTM1JlYWxseSBJcnJlc3BvbnNp
4YmxlIEF1dGhvcmlzYXRpb24gQXV0aG9yaXR5IChSSUFBKTEWMBQGA1UECxMNQ2Vy
5dC1zdGFtcGluZzEZMBcGA1UEAxMQSmFja292IGFsLVRyYWRlczEfMB0GCSqGSIb3
6DQEJARYQbm9uZUBmYWtlLmRvbWFpbjAeFw0wMjAxMTYwNTA5NTlaFw0xMjAxMTQw
7NTA5NTlaMIG0MQswCQYDVQQGEwJOWjETMBEGA1UEBxMKV2VsbGluZ3RvbjE8MDoG
8A1UEChMzUmVhbGx5IElycmVzcG9uc2libGUgQXV0aG9yaXNhdGlvbiBBdXRob3Jp
9dHkgKFJJQUEpMRYwFAYDVQQLEw1DZXJ0LXN0YW1waW5nMRkwFwYDVQQDExBKYWNr
10b3YgYWwtVHJhZGVzMR8wHQYJKoZIhvcNAQkBFhBub25lQGZha2UuZG9tYWluMIGf
11MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7QdDfFIrJn3X24hKmpkyk3TG0Ivxd
12K2wWmDPXq1wjr8lUTwrA6hM5Ba9N36jLieWpXhviLOWu9DBza5GmtgCuXloATKTC
1394xOdKHlciTVujG3wDlLDB5e710Kar84nnj6VueL1RyZ0bmP5PANa4mbGW9Tqc7J
14CkBTTW2y9d0SgQIDAQABo4IBFTCCAREwHQYDVR0OBBYEFEn7RXISxMzhRaHTCJ6V
15xCxtVT8XMIHhBgNVHSMEgdkwgdaAFEn7RXISxMzhRaHTCJ6VxCxtVT8XoYG6pIG3
16MIG0MQswCQYDVQQGEwJOWjETMBEGA1UEBxMKV2VsbGluZ3RvbjE8MDoGA1UEChMz
17UmVhbGx5IElycmVzcG9uc2libGUgQXV0aG9yaXNhdGlvbiBBdXRob3JpdHkgKFJJ
18QUEpMRYwFAYDVQQLEw1DZXJ0LXN0YW1waW5nMRkwFwYDVQQDExBKYWNrb3YgYWwt
19VHJhZGVzMR8wHQYJKoZIhvcNAQkBFhBub25lQGZha2UuZG9tYWluggEAMAwGA1Ud
20EwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAYQo95V/NY+eKxYxkhibZiUQygph+
21gTfgbDG20MsnH6+8//w5ArHauFCgDrf0P2VyACgq+N4pBTWFGaAaLwbjKy9HCe2E
22j9C91tO1CqDS4MJkDB5AP13FTkK6fP1ZCiTQranOAp3DlGWTTWsFVyW5kVfQ9diS
23ZOyJZ9Fit5XM2X0=
24-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/demos/tunala/INSTALL b/src/lib/libssl/src/demos/tunala/INSTALL
new file mode 100644
index 0000000000..a65bbeb8d1
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/INSTALL
@@ -0,0 +1,107 @@
1There are two ways to build this code;
2
3(1) Manually
4
5(2) Using all-singing all-dancing (all-confusing) autotools, ie. autoconf,
6automake, and their little friends (autoheader, etc).
7
8=================
9Building Manually
10=================
11
12There is a basic "Makefile" in this directory that gets moved out of the way and
13ignored when building with autoconf et al. This Makefile is suitable for
14building tunala on Linux using gcc. Any other platform probably requires some
15tweaking. Here are the various bits you might need to do if you want to build
16this way and the default Makefile isn't sufficient;
17
18* Compiler: Edit the "CC" definition in Makefile
19
20* Headers, features: tunala.h controls what happens in the non-autoconf world.
21 It, by default, assumes the system has *everything* (except autoconf's
22 "config.h") so if a target system is missing something it must define the
23 appropriate "NO_***" symbols in CFLAGS. These include;
24
25 - NO_HAVE_UNISTD_H, NO_HAVE_FCNTL_H, NO_HAVE_LIMITS_H
26 Indicates the compiling system doesn't have (or need) these header files.
27 - NO_HAVE_STRSTR, NO_HAVE_STRTOUL
28 Indicates the compiling system doesn't have these functions. Replacements
29 are compiled and used in breakage.c
30 - NO_HAVE_SELECT, NO_HAVE_SOCKET
31 Pointless symbols - these indicate select() and/or socket() are missing in
32 which case the program won't compile anyway.
33
34 If you want to specify any of these, add them with "-D" prefixed to each in
35 the CFLAGS definition in Makefile.
36
37* Compilation flags: edit DEBUG_FLAGS and/or CFLAGS directly to control the
38 flags passed to the compiler. This can also be used to change the degree of
39 optimisation.
40
41* Linker flags: some systems (eg. Solaris) require extra linker flags such as;
42 -ldl, -lsocket, -lnsl, etc. If unsure, bring up the man page for whichever
43 function is "undefined" when the linker fails - that usually indicates what
44 you need to add. Make changes to the LINK_FLAGS symbol.
45
46* Linker command: if a different linker syntax or even a different program is
47 required to link, edit the linker line directly in the "tunala:" target
48 definition - it currently assumes the "CC" (compiler) program is used to link.
49
50======================
51Building Automagically
52======================
53
54Automagic building is handled courtesy of autoconf, automake, etc. There are in
55fact two steps required to build, and only the first has to be done on a system
56with these tools installed (and if I was prepared to bloat out the CVS
57repository, I could store these extra files, but I'm not).
58
59First step: "autogunk.sh"
60-------------------------
61
62The "./autogunk.sh" script will call all the necessary autotool commands to
63create missing files and run automake and autoconf. The result is that a
64"./configure" script should be generated and a "Makefile.in" generated from the
65supplied "Makefile.am". NB: This script also moves the "manual" Makefile (see
66above) out of the way and calls it "Makefile.plain" - the "ungunk" script
67reverses this to leave the directory it was previously.
68
69Once "ungunk" has been run, the resulting directory should be able to build on
70other systems without autoconf, automake, or libtool. Which is what the second
71step describes;
72
73Second step: "./configure"
74--------------------------
75
76The second step is to run the generated "./configure" script to create a
77config.h header for your system and to generate a "Makefile" (generated from
78"Makefile.in") tweaked to compile on your system. This is the standard sort of
79thing you see in GNU packages, for example, and the standard tricks also work.
80Eg. to override "configure"'s choice of compiler, set the CC environment
81variable prior to running configure, eg.
82
83 CC=gcc ./configure
84
85would cause "gcc" to be used even if there is an otherwise preferable (to
86autoconf) native compiler on your system.
87
88After this run "make" and it should build the "tunala" executable.
89
90Notes
91-----
92
93- Some versions of autoconf (or automake?) generate a Makefile syntax that gives
94 trouble to some "make" programs on some systems (eg. OpenBSD). If this
95 happens, either build 'Manually' (see above) or use "gmake" instead of "make".
96 I don't like this either but like even less the idea of sifting into all the
97 script magic crud that's involved.
98
99- On a solaris system I tried, the "configure" script specified some broken
100 compiler flags in the resulting Makefile that don't even get echoed to
101 stdout/err when the error happens (evil!). If this happens, go into the
102 generated Makefile, find the two affected targets ("%.o:" and "%.lo"), and
103 remove the offending hidden option in the $(COMPILE) line all the sludge after
104 the two first lines of script (ie. after the "echo" and the "COMPILE" lines).
105 NB: This will probably only function if "--disable-shared" was used, otherwise
106 who knows what would result ...
107
diff --git a/src/lib/libssl/src/demos/tunala/Makefile b/src/lib/libssl/src/demos/tunala/Makefile
new file mode 100644
index 0000000000..bef1704a3c
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/Makefile
@@ -0,0 +1,41 @@
1# Edit these to suit
2#
3# Oh yeah, and please read the README too.
4
5
6SSL_HOMEDIR=../..
7SSL_INCLUDEDIR=$(SSL_HOMEDIR)/include
8SSL_LIBDIR=$(SSL_HOMEDIR)
9
10RM=rm -f
11CC=gcc
12DEBUG_FLAGS=-g -ggdb3 -Wall -Wshadow
13INCLUDE_FLAGS=-I$(SSL_INCLUDEDIR)
14CFLAGS=$(DEBUG_FLAGS) $(INCLUDE_FLAGS) -DNO_CONFIG_H
15COMPILE=$(CC) $(CFLAGS) -c
16
17# Edit, particularly the "-ldl" if not building with "dlfcn" support
18LINK_FLAGS=-L$(SSL_LIBDIR) -lssl -lcrypto -ldl
19
20SRCS=buffer.c cb.c ip.c sm.c tunala.c breakage.c
21OBJS=buffer.o cb.o ip.o sm.o tunala.o breakage.o
22
23TARGETS=tunala
24
25default: $(TARGETS)
26
27clean:
28 $(RM) $(OBJS) $(TARGETS) *.bak core
29
30.c.o:
31 $(COMPILE) $<
32
33tunala: $(OBJS)
34 $(CC) -o tunala $(OBJS) $(LINK_FLAGS)
35
36# Extra dependencies, should really use makedepend
37buffer.o: buffer.c tunala.h
38cb.o: cb.c tunala.h
39ip.o: ip.c tunala.h
40sm.o: sm.c tunala.h
41tunala.o: tunala.c tunala.h
diff --git a/src/lib/libssl/src/demos/tunala/Makefile.am b/src/lib/libssl/src/demos/tunala/Makefile.am
new file mode 100644
index 0000000000..706c7806c9
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/Makefile.am
@@ -0,0 +1,7 @@
1# Our includes come from the OpenSSL build-tree we're in
2INCLUDES = -I$(top_builddir)/../../include
3
4bin_PROGRAMS = tunala
5
6tunala_SOURCES = tunala.c buffer.c cb.c ip.c sm.c breakage.c
7tunala_LDADD = -L$(top_builddir)/../.. -lssl -lcrypto
diff --git a/src/lib/libssl/src/demos/tunala/README b/src/lib/libssl/src/demos/tunala/README
new file mode 100644
index 0000000000..15690088f3
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/README
@@ -0,0 +1,233 @@
1This is intended to be an example of a state-machine driven SSL application. It
2acts as an SSL tunneler (functioning as either the server or client half,
3depending on command-line arguments). *PLEASE* read the comments in tunala.h
4before you treat this stuff as anything more than a curiosity - YOU HAVE BEEN
5WARNED!! There, that's the draconian bit out of the way ...
6
7
8Why "tunala"??
9--------------
10
11I thought I asked you to read tunala.h?? :-)
12
13
14Show me
15-------
16
17If you want to simply see it running, skip to the end and see some example
18command-line arguments to demonstrate with.
19
20
21Where to look and what to do?
22-----------------------------
23
24The code is split up roughly coinciding with the detaching of an "abstract" SSL
25state machine (which is the purpose of all this) and its surrounding application
26specifics. This is primarily to make it possible for me to know when I could cut
27corners and when I needed to be rigorous (or at least maintain the pretense as
28such :-).
29
30Network stuff:
31
32Basically, the network part of all this is what is supposed to be abstracted out
33of the way. The intention is to illustrate one way to stick OpenSSL's mechanisms
34inside a little memory-driven sandbox and operate it like a pure state-machine.
35So, the network code is inside both ip.c (general utility functions and gory
36IPv4 details) and tunala.c itself, which takes care of application specifics
37like the main select() loop. The connectivity between the specifics of this
38application (TCP/IP tunneling and the associated network code) and the
39underlying abstract SSL state machine stuff is through the use of the "buffer_t"
40type, declared in tunala.h and implemented in buffer.c.
41
42State machine:
43
44Which leaves us, generally speaking, with the abstract "state machine" code left
45over and this is sitting inside sm.c, with declarations inside tunala.h. As can
46be seen by the definition of the state_machine_t structure and the associated
47functions to manipulate it, there are the 3 OpenSSL "handles" plus 4 buffer_t
48structures dealing with IO on both the encrypted and unencrypted sides ("dirty"
49and "clean" respectively). The "SSL" handle is what facilitates the reading and
50writing of the unencrypted (tunneled) data. The two "BIO" handles act as the
51read and write channels for encrypted tunnel traffic - in other applications
52these are often socket BIOs so that the OpenSSL framework operates with the
53network layer directly. In this example, those two BIOs are memory BIOs
54(BIO_s_mem()) so that the sending and receiving of the tunnel traffic stays
55within the state-machine, and we can handle where this gets send to (or read
56from) ourselves.
57
58
59Why?
60----
61
62If you take a look at the "state_machine_t" section of tunala.h and the code in
63sm.c, you will notice that nothing related to the concept of 'transport' is
64involved. The binding to TCP/IP networking occurs in tunala.c, specifically
65within the "tunala_item_t" structure that associates a state_machine_t object
66with 4 file-descriptors. The way to best see where the bridge between the
67outside world (TCP/IP reads, writes, select()s, file-descriptors, etc) and the
68state machine is, is to examine the "tunala_item_io()" function in tunala.c.
69This is currently around lines 641-732 but of course could be subject to change.
70
71
72And...?
73-------
74
75Well, although that function is around 90 lines of code, it could easily have
76been a lot less only I was trying to address an easily missed "gotcha" (item (2)
77below). The main() code that drives the select/accept/IO loop initialises new
78tunala_item_t structures when connections arrive, and works out which
79file-descriptors go where depending on whether we're an SSL client or server
80(client --> accepted connection is clean and proxied is dirty, server -->
81accepted connection is dirty and proxied is clean). What that tunala_item_io()
82function is attempting to do is 2 things;
83
84 (1) Perform all reads and writes on the network directly into the
85 state_machine_t's buffers (based on a previous select() result), and only
86 then allow the abstact state_machine_t to "churn()" using those buffers.
87 This will cause the SSL machine to consume as much input data from the two
88 "IN" buffers as possible, and generate as much output data into the two
89 "OUT" buffers as possible. Back up in the main() function, the next main
90 loop loop will examine these output buffers and select() for writability
91 on the corresponding sockets if the buffers are non-empty.
92
93 (2) Handle the complicated tunneling-specific issue of cascading "close"s.
94 This is the reason for most of the complexity in the logic - if one side
95 of the tunnel is closed, you can't simply close the other side and throw
96 away the whole thing - (a) there may still be outgoing data on the other
97 side of the tunnel that hasn't been sent yet, (b) the close (or things
98 happening during the close) may cause more data to be generated that needs
99 sending on the other side. Of course, this logic is complicated yet futher
100 by the fact that it's different depending on which side closes first :-)
101 state_machine_close_clean() will indicate to the state machine that the
102 unencrypted side of the tunnel has closed, so any existing outgoing data
103 needs to be flushed, and the SSL stream needs to be closed down using the
104 appropriate shutdown sequence. state_machine_close_dirty() is simpler
105 because it indicates that the SSL stream has been disconnected, so all
106 that remains before closing the other side is to flush out anything that
107 remains and wait for it to all be sent.
108
109Anyway, with those things in mind, the code should be a little easier to follow
110in terms of "what is *this* bit supposed to achieve??!!".
111
112
113How might this help?
114--------------------
115
116Well, the reason I wrote this is that there seemed to be rather a flood of
117questions of late on the openssl-dev and openssl-users lists about getting this
118whole IO logic thing sorted out, particularly by those who were trying to either
119use non-blocking IO, or wanted SSL in an environment where "something else" was
120handling the network already and they needed to operate in memory only. This
121code is loosely based on some other stuff I've been working on, although that
122stuff is far more complete, far more dependant on a whole slew of other
123network/framework code I don't want to incorporate here, and far harder to look
124at for 5 minutes and follow where everything is going. I will be trying over
125time to suck in a few things from that into this demo in the hopes it might be
126more useful, and maybe to even make this demo usable as a utility of its own.
127Possible things include:
128
129 * controlling multiple processes/threads - this can be used to combat
130 latencies and get passed file-descriptor limits on some systems, and it uses
131 a "controller" process/thread that maintains IPC links with the
132 processes/threads doing the real work.
133
134 * cert verification rules - having some say over which certs get in or out :-)
135
136 * control over SSL protocols and cipher suites
137
138 * A few other things you can already do in s_client and s_server :-)
139
140 * Support (and control over) session resuming, particularly when functioning
141 as an SSL client.
142
143If you have a particular environment where this model might work to let you "do
144SSL" without having OpenSSL be aware of the transport, then you should find you
145could use the state_machine_t structure (or your own variant thereof) and hook
146it up to your transport stuff in much the way tunala.c matches it up with those
1474 file-descriptors. The state_machine_churn(), state_machine_close_clean(), and
148state_machine_close_dirty() functions are the main things to understand - after
149that's done, you just have to ensure you're feeding and bleeding the 4
150state_machine buffers in a logical fashion. This state_machine loop handles not
151only handshakes and normal streaming, but also renegotiates - there's no special
152handling required beyond keeping an eye on those 4 buffers and keeping them in
153sync with your outer "loop" logic. Ie. if one of the OUT buffers is not empty,
154you need to find an opportunity to try and forward its data on. If one of the IN
155buffers is not full, you should keep an eye out for data arriving that should be
156placed there.
157
158This approach could hopefully also allow you to run the SSL protocol in very
159different environments. As an example, you could support encrypted event-driven
160IPC where threads/processes pass messages to each other inside an SSL layer;
161each IPC-message's payload would be in fact the "dirty" content, and the "clean"
162payload coming out of the tunnel at each end would be the real intended message.
163Likewise, this could *easily* be made to work across unix domain sockets, or
164even entirely different network/comms protocols.
165
166This is also a quick and easy way to do VPN if you (and the remote network's
167gateway) support virtual network devices that are encapsulted in a single
168network connection, perhaps PPP going through an SSL tunnel?
169
170
171Suggestions
172-----------
173
174Please let me know if you find this useful, or if there's anything wrong or
175simply too confusing about it. Patches are also welcome, but please attach a
176description of what it changes and why, and "diff -urN" format is preferred.
177Mail to geoff@openssl.org should do the trick.
178
179
180Example
181-------
182
183Here is an example of how to use "tunala" ...
184
185First, it's assumed that OpenSSL has already built, and that you are building
186inside the ./demos/tunala/ directory. If not - please correct the paths and
187flags inside the Makefile. Likewise, if you want to tweak the building, it's
188best to try and do so in the makefile (eg. removing the debug flags and adding
189optimisation flags).
190
191Secondly, this code has mostly only been tested on Linux. However, some
192autoconf/etc support has been added and the code has been compiled on openbsd
193and solaris using that.
194
195Thirdly, if you are Win32, you probably need to do some *major* rewriting of
196ip.c to stand a hope in hell. Good luck, and please mail me the diff if you do
197this, otherwise I will take a look at another time. It can certainly be done,
198but it's very non-POSIXy.
199
200See the INSTALL document for details on building.
201
202Now, if you don't have an executable "tunala" compiled, go back to "First,...".
203Rinse and repeat.
204
205Inside one console, try typing;
206
207(i) ./tunala -listen localhost:8080 -proxy localhost:8081 -cacert CA.pem \
208 -cert A-client.pem -out_totals -v_peer -v_strict
209
210In another console, type;
211
212(ii) ./tunala -listen localhost:8081 -proxy localhost:23 -cacert CA.pem \
213 -cert A-server.pem -server 1 -out_totals -v_peer -v_strict
214
215Now if you open another console and "telnet localhost 8080", you should be
216tunneled through to the telnet service on your local machine (if it's running -
217you could change it to port "22" and tunnel ssh instead if you so desired). When
218you logout of the telnet session, the tunnel should cleanly shutdown and show
219you some traffic stats in both consoles. Feel free to experiment. :-)
220
221Notes:
222
223 - the format for the "-listen" argument can skip the host part (eg. "-listen
224 8080" is fine). If you do, the listening socket will listen on all interfaces
225 so you can connect from other machines for example. Using the "localhost"
226 form listens only on 127.0.0.1 so you can only connect locally (unless, of
227 course, you've set up weird stuff with your networking in which case probably
228 none of the above applies).
229
230 - ./tunala -? gives you a list of other command-line options, but tunala.c is
231 also a good place to look :-)
232
233
diff --git a/src/lib/libssl/src/demos/tunala/autogunk.sh b/src/lib/libssl/src/demos/tunala/autogunk.sh
new file mode 100644
index 0000000000..c9783c6261
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/autogunk.sh
@@ -0,0 +1,25 @@
1#!/bin/sh
2
3# This script tries to follow the "GNU way" w.r.t. the autobits.
4# This does of course generate a number of irritating files.
5# Try to get over it (I am getting there myself).
6
7# This should generate any missing crud, and then run autoconf which should turn
8# configure.in into a "./configure" script and "Makefile.am" into a
9# "Makefile.in". Then running "./configure" should turn "Makefile.in" into
10# "Makefile" and should generate the config.h containing your systems various
11# settings. I know ... what a hassle ...
12
13# Also, sometimes these autobits things generate bizarre output (looking like
14# errors). So I direct everything "elsewhere" ...
15
16(aclocal
17autoheader
18libtoolize --copy --force
19automake --foreign --add-missing --copy
20autoconf) 1> /dev/null 2>&1
21
22# Move the "no-autotools" Makefile out of the way
23if test ! -f Makefile.plain; then
24 mv Makefile Makefile.plain
25fi
diff --git a/src/lib/libssl/src/demos/tunala/autoungunk.sh b/src/lib/libssl/src/demos/tunala/autoungunk.sh
new file mode 100644
index 0000000000..14d10790fd
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/autoungunk.sh
@@ -0,0 +1,18 @@
1#!/bin/sh
2
3# This script tries to clean up as much as is possible from whatever diabolical
4# mess has been left in the directory thanks to autoconf, automake, and their
5# friends.
6
7if test -f Makefile; then
8 make distclean
9 rm -f Makefile
10fi
11
12if test -f Makefile.plain; then
13 mv Makefile.plain Makefile
14fi
15
16rm -f aclocal.m4 config.* configure install-sh \
17 missing mkinstalldirs stamp-h.* Makefile.in \
18 ltconfig ltmain.sh
diff --git a/src/lib/libssl/src/demos/tunala/breakage.c b/src/lib/libssl/src/demos/tunala/breakage.c
new file mode 100644
index 0000000000..dcdd64b0ef
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/breakage.c
@@ -0,0 +1,66 @@
1#include "tunala.h"
2
3int int_strtoul(const char *str, unsigned long *val)
4{
5#ifdef HAVE_STRTOUL
6 char *tmp;
7 unsigned long ret = strtoul(str, &tmp, 10);
8 if((str == tmp) || (*tmp != '\0'))
9 /* The value didn't parse cleanly */
10 return 0;
11 if(ret == ULONG_MAX)
12 /* We hit a limit */
13 return 0;
14 *val = ret;
15 return 1;
16#else
17 char buf[2];
18 unsigned long ret = 0;
19 buf[1] = '\0';
20 if(str == '\0')
21 /* An empty string ... */
22 return 0;
23 while(*str != '\0') {
24 /* We have to multiply 'ret' by 10 before absorbing the next
25 * digit. If this will overflow, catch it now. */
26 if(ret && (((ULONG_MAX + 10) / ret) < 10))
27 return 0;
28 ret *= 10;
29 if(!isdigit(*str))
30 return 0;
31 buf[0] = *str;
32 ret += atoi(buf);
33 str++;
34 }
35 *val = ret;
36 return 1;
37#endif
38}
39
40#ifndef HAVE_STRSTR
41char *int_strstr(const char *haystack, const char *needle)
42{
43 const char *sub_haystack = haystack, *sub_needle = needle;
44 unsigned int offset = 0;
45 if(!needle)
46 return haystack;
47 if(!haystack)
48 return NULL;
49 while((*sub_haystack != '\0') && (*sub_needle != '\0')) {
50 if(sub_haystack[offset] == sub_needle) {
51 /* sub_haystack is still a candidate */
52 offset++;
53 sub_needle++;
54 } else {
55 /* sub_haystack is no longer a possibility */
56 sub_haystack++;
57 offset = 0;
58 sub_needle = needle;
59 }
60 }
61 if(*sub_haystack == '\0')
62 /* Found nothing */
63 return NULL;
64 return sub_haystack;
65}
66#endif
diff --git a/src/lib/libssl/src/demos/tunala/buffer.c b/src/lib/libssl/src/demos/tunala/buffer.c
new file mode 100644
index 0000000000..c5cd004209
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/buffer.c
@@ -0,0 +1,205 @@
1#include "tunala.h"
2
3#ifndef NO_BUFFER
4
5void buffer_init(buffer_t *buf)
6{
7 buf->used = 0;
8 buf->total_in = buf->total_out = 0;
9}
10
11void buffer_close(buffer_t *buf)
12{
13 /* Our data is static - nothing needs "release", just reset it */
14 buf->used = 0;
15}
16
17/* Code these simple ones in compact form */
18unsigned int buffer_used(buffer_t *buf) {
19 return buf->used; }
20unsigned int buffer_unused(buffer_t *buf) {
21 return (MAX_DATA_SIZE - buf->used); }
22int buffer_full(buffer_t *buf) {
23 return (buf->used == MAX_DATA_SIZE ? 1 : 0); }
24int buffer_notfull(buffer_t *buf) {
25 return (buf->used < MAX_DATA_SIZE ? 1 : 0); }
26int buffer_empty(buffer_t *buf) {
27 return (buf->used == 0 ? 1 : 0); }
28int buffer_notempty(buffer_t *buf) {
29 return (buf->used > 0 ? 1 : 0); }
30unsigned long buffer_total_in(buffer_t *buf) {
31 return buf->total_in; }
32unsigned long buffer_total_out(buffer_t *buf) {
33 return buf->total_out; }
34
35/* These 3 static (internal) functions don't adjust the "total" variables as
36 * it's not sure when they're called how it should be interpreted. Only the
37 * higher-level "buffer_[to|from]_[fd|SSL|BIO]" functions should alter these
38 * values. */
39#if 0 /* To avoid "unused" warnings */
40static unsigned int buffer_adddata(buffer_t *buf, const unsigned char *ptr,
41 unsigned int size)
42{
43 unsigned int added = MAX_DATA_SIZE - buf->used;
44 if(added > size)
45 added = size;
46 if(added == 0)
47 return 0;
48 memcpy(buf->data + buf->used, ptr, added);
49 buf->used += added;
50 buf->total_in += added;
51 return added;
52}
53
54static unsigned int buffer_tobuffer(buffer_t *to, buffer_t *from, int cap)
55{
56 unsigned int moved, tomove = from->used;
57 if((int)tomove > cap)
58 tomove = cap;
59 if(tomove == 0)
60 return 0;
61 moved = buffer_adddata(to, from->data, tomove);
62 if(moved == 0)
63 return 0;
64 buffer_takedata(from, NULL, moved);
65 return moved;
66}
67#endif
68
69static unsigned int buffer_takedata(buffer_t *buf, unsigned char *ptr,
70 unsigned int size)
71{
72 unsigned int taken = buf->used;
73 if(taken > size)
74 taken = size;
75 if(taken == 0)
76 return 0;
77 if(ptr)
78 memcpy(ptr, buf->data, taken);
79 buf->used -= taken;
80 /* Do we have to scroll? */
81 if(buf->used > 0)
82 memmove(buf->data, buf->data + taken, buf->used);
83 return taken;
84}
85
86#ifndef NO_IP
87
88int buffer_from_fd(buffer_t *buf, int fd)
89{
90 int toread = buffer_unused(buf);
91 if(toread == 0)
92 /* Shouldn't be called in this case! */
93 abort();
94 toread = read(fd, buf->data + buf->used, toread);
95 if(toread > 0) {
96 buf->used += toread;
97 buf->total_in += toread;
98 }
99 return toread;
100}
101
102int buffer_to_fd(buffer_t *buf, int fd)
103{
104 int towrite = buffer_used(buf);
105 if(towrite == 0)
106 /* Shouldn't be called in this case! */
107 abort();
108 towrite = write(fd, buf->data, towrite);
109 if(towrite > 0) {
110 buffer_takedata(buf, NULL, towrite);
111 buf->total_out += towrite;
112 }
113 return towrite;
114}
115
116#endif /* !defined(NO_IP) */
117
118#ifndef NO_OPENSSL
119
120static void int_ssl_check(SSL *s, int ret)
121{
122 int e = SSL_get_error(s, ret);
123 switch(e) {
124 /* These seem to be harmless and already "dealt with" by our
125 * non-blocking environment. NB: "ZERO_RETURN" is the clean
126 * "error" indicating a successfully closed SSL tunnel. We let
127 * this happen because our IO loop should not appear to have
128 * broken on this condition - and outside the IO loop, the
129 * "shutdown" state is checked. */
130 case SSL_ERROR_NONE:
131 case SSL_ERROR_WANT_READ:
132 case SSL_ERROR_WANT_WRITE:
133 case SSL_ERROR_WANT_X509_LOOKUP:
134 case SSL_ERROR_ZERO_RETURN:
135 return;
136 /* These seem to be indications of a genuine error that should
137 * result in the SSL tunnel being regarded as "dead". */
138 case SSL_ERROR_SYSCALL:
139 case SSL_ERROR_SSL:
140 SSL_set_app_data(s, (char *)1);
141 return;
142 default:
143 break;
144 }
145 /* For any other errors that (a) exist, and (b) crop up - we need to
146 * interpret what to do with them - so "politely inform" the caller that
147 * the code needs updating here. */
148 abort();
149}
150
151void buffer_from_SSL(buffer_t *buf, SSL *ssl)
152{
153 int ret;
154 if(!ssl || buffer_full(buf))
155 return;
156 ret = SSL_read(ssl, buf->data + buf->used, buffer_unused(buf));
157 if(ret > 0) {
158 buf->used += ret;
159 buf->total_in += ret;
160 }
161 if(ret < 0)
162 int_ssl_check(ssl, ret);
163}
164
165void buffer_to_SSL(buffer_t *buf, SSL *ssl)
166{
167 int ret;
168 if(!ssl || buffer_empty(buf))
169 return;
170 ret = SSL_write(ssl, buf->data, buf->used);
171 if(ret > 0) {
172 buffer_takedata(buf, NULL, ret);
173 buf->total_out += ret;
174 }
175 if(ret < 0)
176 int_ssl_check(ssl, ret);
177}
178
179void buffer_from_BIO(buffer_t *buf, BIO *bio)
180{
181 int ret;
182 if(!bio || buffer_full(buf))
183 return;
184 ret = BIO_read(bio, buf->data + buf->used, buffer_unused(buf));
185 if(ret > 0) {
186 buf->used += ret;
187 buf->total_in += ret;
188 }
189}
190
191void buffer_to_BIO(buffer_t *buf, BIO *bio)
192{
193 int ret;
194 if(!bio || buffer_empty(buf))
195 return;
196 ret = BIO_write(bio, buf->data, buf->used);
197 if(ret > 0) {
198 buffer_takedata(buf, NULL, ret);
199 buf->total_out += ret;
200 }
201}
202
203#endif /* !defined(NO_OPENSSL) */
204
205#endif /* !defined(NO_BUFFER) */
diff --git a/src/lib/libssl/src/demos/tunala/cb.c b/src/lib/libssl/src/demos/tunala/cb.c
new file mode 100644
index 0000000000..cd32f74c70
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/cb.c
@@ -0,0 +1,133 @@
1#include "tunala.h"
2
3#ifndef NO_OPENSSL
4
5/* For callbacks generating output, here are their file-descriptors. */
6static FILE *fp_cb_ssl_info = NULL;
7static FILE *fp_cb_ssl_verify = NULL;
8/* Output level:
9 * 0 = nothing,
10 * 1 = minimal, just errors,
11 * 2 = minimal, all steps,
12 * 3 = detail, all steps */
13static unsigned int cb_ssl_verify_level = 1;
14
15/* Other static rubbish (to mirror s_cb.c where required) */
16static int int_verify_depth = 10;
17
18/* This function is largely borrowed from the one used in OpenSSL's "s_client"
19 * and "s_server" utilities. */
20void cb_ssl_info(const SSL *s, int where, int ret)
21{
22 const char *str1, *str2;
23 int w;
24
25 if(!fp_cb_ssl_info)
26 return;
27
28 w = where & ~SSL_ST_MASK;
29 str1 = (w & SSL_ST_CONNECT ? "SSL_connect" : (w & SSL_ST_ACCEPT ?
30 "SSL_accept" : "undefined")),
31 str2 = SSL_state_string_long(s);
32
33 if (where & SSL_CB_LOOP)
34 fprintf(fp_cb_ssl_info, "(%s) %s\n", str1, str2);
35 else if (where & SSL_CB_EXIT) {
36 if (ret == 0)
37 fprintf(fp_cb_ssl_info, "(%s) failed in %s\n", str1, str2);
38/* In a non-blocking model, we get a few of these "error"s simply because we're
39 * calling "reads" and "writes" on the state-machine that are virtual NOPs
40 * simply to avoid wasting the time seeing if we *should* call them. Removing
41 * this case makes the "-out_state" output a lot easier on the eye. */
42#if 0
43 else if (ret < 0)
44 fprintf(fp_cb_ssl_info, "%s:error in %s\n", str1, str2);
45#endif
46 }
47}
48
49void cb_ssl_info_set_output(FILE *fp)
50{
51 fp_cb_ssl_info = fp;
52}
53
54static const char *int_reason_no_issuer = "X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT";
55static const char *int_reason_not_yet = "X509_V_ERR_CERT_NOT_YET_VALID";
56static const char *int_reason_before = "X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD";
57static const char *int_reason_expired = "X509_V_ERR_CERT_HAS_EXPIRED";
58static const char *int_reason_after = "X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD";
59
60/* Stolen wholesale from apps/s_cb.c :-) And since then, mutilated ... */
61int cb_ssl_verify(int ok, X509_STORE_CTX *ctx)
62{
63 char buf1[256]; /* Used for the subject name */
64 char buf2[256]; /* Used for the issuer name */
65 const char *reason = NULL; /* Error reason (if any) */
66 X509 *err_cert;
67 int err, depth;
68
69 if(!fp_cb_ssl_verify || (cb_ssl_verify_level == 0))
70 return ok;
71 err_cert = X509_STORE_CTX_get_current_cert(ctx);
72 err = X509_STORE_CTX_get_error(ctx);
73 depth = X509_STORE_CTX_get_error_depth(ctx);
74
75 buf1[0] = buf2[0] = '\0';
76 /* Fill buf1 */
77 X509_NAME_oneline(X509_get_subject_name(err_cert), buf1, 256);
78 /* Fill buf2 */
79 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf2, 256);
80 switch (ctx->error) {
81 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
82 reason = int_reason_no_issuer;
83 break;
84 case X509_V_ERR_CERT_NOT_YET_VALID:
85 reason = int_reason_not_yet;
86 break;
87 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
88 reason = int_reason_before;
89 break;
90 case X509_V_ERR_CERT_HAS_EXPIRED:
91 reason = int_reason_expired;
92 break;
93 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
94 reason = int_reason_after;
95 break;
96 }
97
98 if((cb_ssl_verify_level == 1) && ok)
99 return ok;
100 fprintf(fp_cb_ssl_verify, "chain-depth=%d, ", depth);
101 if(reason)
102 fprintf(fp_cb_ssl_verify, "error=%s\n", reason);
103 else
104 fprintf(fp_cb_ssl_verify, "error=%d\n", err);
105 if(cb_ssl_verify_level < 3)
106 return ok;
107 fprintf(fp_cb_ssl_verify, "--> subject = %s\n", buf1);
108 fprintf(fp_cb_ssl_verify, "--> issuer = %s\n", buf2);
109 if(!ok)
110 fprintf(fp_cb_ssl_verify,"--> verify error:num=%d:%s\n",err,
111 X509_verify_cert_error_string(err));
112 fprintf(fp_cb_ssl_verify, "--> verify return:%d\n",ok);
113 return ok;
114}
115
116void cb_ssl_verify_set_output(FILE *fp)
117{
118 fp_cb_ssl_verify = fp;
119}
120
121void cb_ssl_verify_set_depth(unsigned int verify_depth)
122{
123 int_verify_depth = verify_depth;
124}
125
126void cb_ssl_verify_set_level(unsigned int level)
127{
128 if(level < 4)
129 cb_ssl_verify_level = level;
130}
131
132#endif /* !defined(NO_OPENSSL) */
133
diff --git a/src/lib/libssl/src/demos/tunala/configure.in b/src/lib/libssl/src/demos/tunala/configure.in
new file mode 100644
index 0000000000..b2a6ffc756
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/configure.in
@@ -0,0 +1,28 @@
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(tunala.c)
3AM_CONFIG_HEADER(config.h)
4AM_INIT_AUTOMAKE(tunala, 0.0.1-dev)
5
6dnl Checks for programs. (Though skip libtool)
7AC_PROG_CC
8dnl AC_PROG_LIBTOOL
9dnl AM_PROG_LIBTOOL
10
11dnl Checks for libraries.
12AC_CHECK_LIB(dl, dlopen)
13AC_CHECK_LIB(socket, socket)
14AC_CHECK_LIB(nsl, gethostbyname)
15
16dnl Checks for header files.
17AC_HEADER_STDC
18AC_CHECK_HEADERS(fcntl.h limits.h unistd.h)
19
20dnl Checks for typedefs, structures, and compiler characteristics.
21AC_C_CONST
22
23dnl Checks for library functions.
24AC_CHECK_FUNCS(strstr strtoul)
25AC_CHECK_FUNCS(select socket)
26AC_CHECK_FUNCS(dlopen)
27
28AC_OUTPUT(Makefile)
diff --git a/src/lib/libssl/src/demos/tunala/ip.c b/src/lib/libssl/src/demos/tunala/ip.c
new file mode 100644
index 0000000000..96ef4e6536
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/ip.c
@@ -0,0 +1,146 @@
1#include "tunala.h"
2
3#ifndef NO_IP
4
5#define IP_LISTENER_BACKLOG 511 /* So if it gets masked by 256 or some other
6 such value it'll still be respectable */
7
8/* Any IP-related initialisations. For now, this means blocking SIGPIPE */
9int ip_initialise(void)
10{
11 struct sigaction sa;
12
13 sa.sa_handler = SIG_IGN;
14 sa.sa_flags = 0;
15 sigemptyset(&sa.sa_mask);
16 if(sigaction(SIGPIPE, &sa, NULL) != 0)
17 return 0;
18 return 1;
19}
20
21int ip_create_listener_split(const char *ip, unsigned short port)
22{
23 struct sockaddr_in in_addr;
24 int fd = -1;
25 int reuseVal = 1;
26
27 /* Create the socket */
28 if((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
29 goto err;
30 /* Set the SO_REUSEADDR flag - servers act weird without it */
31 if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)(&reuseVal),
32 sizeof(reuseVal)) != 0)
33 goto err;
34 /* Prepare the listen address stuff */
35 in_addr.sin_family = AF_INET;
36 memcpy(&in_addr.sin_addr.s_addr, ip, 4);
37 in_addr.sin_port = htons(port);
38 /* Bind to the required port/address/interface */
39 if(bind(fd, (struct sockaddr *)&in_addr, sizeof(struct sockaddr_in)) != 0)
40 goto err;
41 /* Start "listening" */
42 if(listen(fd, IP_LISTENER_BACKLOG) != 0)
43 goto err;
44 return fd;
45err:
46 if(fd != -1)
47 close(fd);
48 return -1;
49}
50
51int ip_create_connection_split(const char *ip, unsigned short port)
52{
53 struct sockaddr_in in_addr;
54 int flags, fd = -1;
55
56 /* Create the socket */
57 if((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
58 goto err;
59 /* Make it non-blocking */
60 if(((flags = fcntl(fd, F_GETFL, 0)) < 0) ||
61 (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0))
62 goto err;
63 /* Prepare the connection address stuff */
64 in_addr.sin_family = AF_INET;
65 memcpy(&in_addr.sin_addr.s_addr, ip, 4);
66 in_addr.sin_port = htons(port);
67 /* Start a connect (non-blocking, in all likelihood) */
68 if((connect(fd, (struct sockaddr *)&in_addr,
69 sizeof(struct sockaddr_in)) != 0) &&
70 (errno != EINPROGRESS))
71 goto err;
72 return fd;
73err:
74 if(fd != -1)
75 close(fd);
76 return -1;
77}
78
79static char all_local_ip[] = {0x00,0x00,0x00,0x00};
80
81int ip_parse_address(const char *address, const char **parsed_ip,
82 unsigned short *parsed_port, int accept_all_ip)
83{
84 char buf[256];
85 struct hostent *lookup;
86 unsigned long port;
87 const char *ptr = strstr(address, ":");
88 const char *ip = all_local_ip;
89
90 if(!ptr) {
91 /* We assume we're listening on all local interfaces and have
92 * only specified a port. */
93 if(!accept_all_ip)
94 return 0;
95 ptr = address;
96 goto determine_port;
97 }
98 if((ptr - address) > 255)
99 return 0;
100 memset(buf, 0, 256);
101 memcpy(buf, address, ptr - address);
102 ptr++;
103 if((lookup = gethostbyname(buf)) == NULL) {
104 /* Spit a message to differentiate between lookup failures and
105 * bad strings. */
106 fprintf(stderr, "hostname lookup for '%s' failed\n", buf);
107 return 0;
108 }
109 ip = lookup->h_addr_list[0];
110determine_port:
111 if(strlen(ptr) < 1)
112 return 0;
113 if(!int_strtoul(ptr, &port) || (port > 65535))
114 return 0;
115 *parsed_ip = ip;
116 *parsed_port = (unsigned short)port;
117 return 1;
118}
119
120int ip_create_listener(const char *address)
121{
122 const char *ip;
123 unsigned short port;
124
125 if(!ip_parse_address(address, &ip, &port, 1))
126 return -1;
127 return ip_create_listener_split(ip, port);
128}
129
130int ip_create_connection(const char *address)
131{
132 const char *ip;
133 unsigned short port;
134
135 if(!ip_parse_address(address, &ip, &port, 0))
136 return -1;
137 return ip_create_connection_split(ip, port);
138}
139
140int ip_accept_connection(int listen_fd)
141{
142 return accept(listen_fd, NULL, NULL);
143}
144
145#endif /* !defined(NO_IP) */
146
diff --git a/src/lib/libssl/src/demos/tunala/sm.c b/src/lib/libssl/src/demos/tunala/sm.c
new file mode 100644
index 0000000000..25359e67ef
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/sm.c
@@ -0,0 +1,151 @@
1#include "tunala.h"
2
3#ifndef NO_TUNALA
4
5void state_machine_init(state_machine_t *machine)
6{
7 machine->ssl = NULL;
8 machine->bio_intossl = machine->bio_fromssl = NULL;
9 buffer_init(&machine->clean_in);
10 buffer_init(&machine->clean_out);
11 buffer_init(&machine->dirty_in);
12 buffer_init(&machine->dirty_out);
13}
14
15void state_machine_close(state_machine_t *machine)
16{
17 if(machine->ssl)
18 SSL_free(machine->ssl);
19/* SSL_free seems to decrement the reference counts already so doing this goes
20 * kaboom. */
21#if 0
22 if(machine->bio_intossl)
23 BIO_free(machine->bio_intossl);
24 if(machine->bio_fromssl)
25 BIO_free(machine->bio_fromssl);
26#endif
27 buffer_close(&machine->clean_in);
28 buffer_close(&machine->clean_out);
29 buffer_close(&machine->dirty_in);
30 buffer_close(&machine->dirty_out);
31 state_machine_init(machine);
32}
33
34buffer_t *state_machine_get_buffer(state_machine_t *machine, sm_buffer_t type)
35{
36 switch(type) {
37 case SM_CLEAN_IN:
38 return &machine->clean_in;
39 case SM_CLEAN_OUT:
40 return &machine->clean_out;
41 case SM_DIRTY_IN:
42 return &machine->dirty_in;
43 case SM_DIRTY_OUT:
44 return &machine->dirty_out;
45 default:
46 break;
47 }
48 /* Should never get here */
49 abort();
50 return NULL;
51}
52
53SSL *state_machine_get_SSL(state_machine_t *machine)
54{
55 return machine->ssl;
56}
57
58int state_machine_set_SSL(state_machine_t *machine, SSL *ssl, int is_server)
59{
60 if(machine->ssl)
61 /* Shouldn't ever be set twice */
62 abort();
63 machine->ssl = ssl;
64 /* Create the BIOs to handle the dirty side of the SSL */
65 if((machine->bio_intossl = BIO_new(BIO_s_mem())) == NULL)
66 abort();
67 if((machine->bio_fromssl = BIO_new(BIO_s_mem())) == NULL)
68 abort();
69 /* Hook up the BIOs on the dirty side of the SSL */
70 SSL_set_bio(machine->ssl, machine->bio_intossl, machine->bio_fromssl);
71 if(is_server)
72 SSL_set_accept_state(machine->ssl);
73 else
74 SSL_set_connect_state(machine->ssl);
75 /* If we're the first one to generate traffic - do it now otherwise we
76 * go into the next select empty-handed and our peer will not send data
77 * but will similarly wait for us. */
78 return state_machine_churn(machine);
79}
80
81/* Performs the data-IO loop and returns zero if the machine should close */
82int state_machine_churn(state_machine_t *machine)
83{
84 unsigned int loop;
85 if(machine->ssl == NULL) {
86 if(buffer_empty(&machine->clean_out))
87 /* Time to close this state-machine altogether */
88 return 0;
89 else
90 /* Still buffered data on the clean side to go out */
91 return 1;
92 }
93 /* Do this loop twice to cover any dependencies about which precise
94 * order of reads and writes is required. */
95 for(loop = 0; loop < 2; loop++) {
96 buffer_to_SSL(&machine->clean_in, machine->ssl);
97 buffer_to_BIO(&machine->dirty_in, machine->bio_intossl);
98 buffer_from_SSL(&machine->clean_out, machine->ssl);
99 buffer_from_BIO(&machine->dirty_out, machine->bio_fromssl);
100 }
101 /* We close on the SSL side if the info callback noticed some problems
102 * or an SSL shutdown was underway and shutdown traffic had all been
103 * sent. */
104 if(SSL_get_app_data(machine->ssl) || (SSL_get_shutdown(machine->ssl) &&
105 buffer_empty(&machine->dirty_out))) {
106 /* Great, we can seal off the dirty side completely */
107 if(!state_machine_close_dirty(machine))
108 return 0;
109 }
110 /* Either the SSL is alive and well, or the closing process still has
111 * outgoing data waiting to be sent */
112 return 1;
113}
114
115/* Called when the clean side of the SSL has lost its connection */
116int state_machine_close_clean(state_machine_t *machine)
117{
118 /* Well, first thing to do is null out the clean-side buffers - they're
119 * no use any more. */
120 buffer_close(&machine->clean_in);
121 buffer_close(&machine->clean_out);
122 /* And start an SSL shutdown */
123 if(machine->ssl)
124 SSL_shutdown(machine->ssl);
125 /* This is an "event", so flush the SSL of any generated traffic */
126 state_machine_churn(machine);
127 if(buffer_empty(&machine->dirty_in) &&
128 buffer_empty(&machine->dirty_out))
129 return 0;
130 return 1;
131}
132
133/* Called when the dirty side of the SSL has lost its connection. This is pretty
134 * terminal as all that can be left to do is send any buffered output on the
135 * clean side - after that, we're done. */
136int state_machine_close_dirty(state_machine_t *machine)
137{
138 buffer_close(&machine->dirty_in);
139 buffer_close(&machine->dirty_out);
140 buffer_close(&machine->clean_in);
141 if(machine->ssl)
142 SSL_free(machine->ssl);
143 machine->ssl = NULL;
144 machine->bio_intossl = machine->bio_fromssl = NULL;
145 if(buffer_empty(&machine->clean_out))
146 return 0;
147 return 1;
148}
149
150#endif /* !defined(NO_TUNALA) */
151
diff --git a/src/lib/libssl/src/demos/tunala/tunala.c b/src/lib/libssl/src/demos/tunala/tunala.c
new file mode 100644
index 0000000000..e802a6209f
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/tunala.c
@@ -0,0 +1,1093 @@
1#if defined(NO_BUFFER) || defined(NO_IP) || defined(NO_OPENSSL)
2#error "Badness, NO_BUFFER, NO_IP or NO_OPENSSL is defined, turn them *off*"
3#endif
4
5/* Include our bits'n'pieces */
6#include "tunala.h"
7
8
9/********************************************/
10/* Our local types that specify our "world" */
11/********************************************/
12
13/* These represent running "tunnels". Eg. if you wanted to do SSL in a
14 * "message-passing" scanario, the "int" file-descriptors might be replaced by
15 * thread or process IDs, and the "select" code might be replaced by message
16 * handling code. Whatever. */
17typedef struct _tunala_item_t {
18 /* The underlying SSL state machine. This is a data-only processing unit
19 * and we communicate with it by talking to its four "buffers". */
20 state_machine_t sm;
21 /* The file-descriptors for the "dirty" (encrypted) side of the SSL
22 * setup. In actuality, this is typically a socket and both values are
23 * identical. */
24 int dirty_read, dirty_send;
25 /* The file-descriptors for the "clean" (unencrypted) side of the SSL
26 * setup. These could be stdin/stdout, a socket (both values the same),
27 * or whatever you like. */
28 int clean_read, clean_send;
29} tunala_item_t;
30
31/* This structure is used as the data for running the main loop. Namely, in a
32 * network format such as this, it is stuff for select() - but as pointed out,
33 * when moving the real-world to somewhere else, this might be replaced by
34 * something entirely different. It's basically the stuff that controls when
35 * it's time to do some "work". */
36typedef struct _select_sets_t {
37 int max; /* As required as the first argument to select() */
38 fd_set reads, sends, excepts; /* As passed to select() */
39} select_sets_t;
40typedef struct _tunala_selector_t {
41 select_sets_t last_selected; /* Results of the last select() */
42 select_sets_t next_select; /* What we'll next select on */
43} tunala_selector_t;
44
45/* This structure is *everything*. We do it to avoid the use of globals so that,
46 * for example, it would be easier to shift things around between async-IO,
47 * thread-based, or multi-fork()ed (or combinations thereof). */
48typedef struct _tunala_world_t {
49 /* The file-descriptor we "listen" on for new connections */
50 int listen_fd;
51 /* The array of tunnels */
52 tunala_item_t *tunnels;
53 /* the number of tunnels in use and allocated, respectively */
54 unsigned int tunnels_used, tunnels_size;
55 /* Our outside "loop" context stuff */
56 tunala_selector_t selector;
57 /* Our SSL_CTX, which is configured as the SSL client or server and has
58 * the various cert-settings and callbacks configured. */
59 SSL_CTX *ssl_ctx;
60 /* Simple flag with complex logic :-) Indicates whether we're an SSL
61 * server or an SSL client. */
62 int server_mode;
63} tunala_world_t;
64
65/*****************************/
66/* Internal static functions */
67/*****************************/
68
69static SSL_CTX *initialise_ssl_ctx(int server_mode, const char *engine_id,
70 const char *CAfile, const char *cert, const char *key,
71 const char *dcert, const char *dkey, const char *cipher_list,
72 const char *dh_file, const char *dh_special, int ctx_options,
73 int out_state, int out_verify, int verify_mode,
74 unsigned int verify_depth);
75static void selector_init(tunala_selector_t *selector);
76static void selector_add_listener(tunala_selector_t *selector, int fd);
77static void selector_add_tunala(tunala_selector_t *selector, tunala_item_t *t);
78static int selector_select(tunala_selector_t *selector);
79/* This returns -1 for error, 0 for no new connections, or 1 for success, in
80 * which case *newfd is populated. */
81static int selector_get_listener(tunala_selector_t *selector, int fd, int *newfd);
82static int tunala_world_new_item(tunala_world_t *world, int fd,
83 const char *ip, unsigned short port, int flipped);
84static void tunala_world_del_item(tunala_world_t *world, unsigned int idx);
85static int tunala_item_io(tunala_selector_t *selector, tunala_item_t *item);
86
87/*********************************************/
88/* MAIN FUNCTION (and its utility functions) */
89/*********************************************/
90
91static const char *def_proxyhost = "127.0.0.1:443";
92static const char *def_listenhost = "127.0.0.1:8080";
93static int def_max_tunnels = 50;
94static const char *def_cacert = NULL;
95static const char *def_cert = NULL;
96static const char *def_key = NULL;
97static const char *def_dcert = NULL;
98static const char *def_dkey = NULL;
99static const char *def_engine_id = NULL;
100static int def_server_mode = 0;
101static int def_flipped = 0;
102static const char *def_cipher_list = NULL;
103static const char *def_dh_file = NULL;
104static const char *def_dh_special = NULL;
105static int def_ctx_options = 0;
106static int def_verify_mode = 0;
107static unsigned int def_verify_depth = 10;
108static int def_out_state = 0;
109static unsigned int def_out_verify = 0;
110static int def_out_totals = 0;
111static int def_out_conns = 0;
112
113static const char *helpstring =
114"\n'Tunala' (A tunneler with a New Zealand accent)\n"
115"Usage: tunala [options], where options are from;\n"
116" -listen [host:]<port> (default = 127.0.0.1:8080)\n"
117" -proxy <host>:<port> (default = 127.0.0.1:443)\n"
118" -maxtunnels <num> (default = 50)\n"
119" -cacert <path|NULL> (default = NULL)\n"
120" -cert <path|NULL> (default = NULL)\n"
121" -key <path|NULL> (default = whatever '-cert' is)\n"
122" -dcert <path|NULL> (usually for DSA, default = NULL)\n"
123" -dkey <path|NULL> (usually for DSA, default = whatever '-dcert' is)\n"
124" -engine <id|NULL> (default = NULL)\n"
125" -server <0|1> (default = 0, ie. an SSL client)\n"
126" -flipped <0|1> (makes SSL servers be network clients, and vice versa)\n"
127" -cipher <list> (specifies cipher list to use)\n"
128" -dh_file <path> (a PEM file containing DH parameters to use)\n"
129" -dh_special <NULL|generate|standard> (see below: def=NULL)\n"
130" -no_ssl2 (disable SSLv2)\n"
131" -no_ssl3 (disable SSLv3)\n"
132" -no_tls1 (disable TLSv1)\n"
133" -v_peer (verify the peer certificate)\n"
134" -v_strict (do not continue if peer doesn't authenticate)\n"
135" -v_once (no verification in renegotiates)\n"
136" -v_depth <num> (limit certificate chain depth, default = 10)\n"
137" -out_conns (prints client connections and disconnections)\n"
138" -out_state (prints SSL handshake states)\n"
139" -out_verify <0|1|2|3> (prints certificate verification states: def=1)\n"
140" -out_totals (prints out byte-totals when a tunnel closes)\n"
141" -<h|help|?> (displays this help screen)\n"
142"Notes:\n"
143"(1) It is recommended to specify a cert+key when operating as an SSL server.\n"
144" If you only specify '-cert', the same file must contain a matching\n"
145" private key.\n"
146"(2) Either dh_file or dh_special can be used to specify where DH parameters\n"
147" will be obtained from (or '-dh_special NULL' for the default choice) but\n"
148" you cannot specify both. For dh_special, 'generate' will create new DH\n"
149" parameters on startup, and 'standard' will use embedded parameters\n"
150" instead.\n"
151"(3) Normally an ssl client connects to an ssl server - so that an 'ssl client\n"
152" tunala' listens for 'clean' client connections and proxies ssl, and an\n"
153" 'ssl server tunala' listens for ssl connections and proxies 'clean'. With\n"
154" '-flipped 1', this behaviour is reversed so that an 'ssl server tunala'\n"
155" listens for clean client connections and proxies ssl (but participating\n"
156" as an ssl *server* in the SSL/TLS protocol), and an 'ssl client tunala'\n"
157" listens for ssl connections (participating as an ssl *client* in the\n"
158" SSL/TLS protocol) and proxies 'clean' to the end destination. This can\n"
159" be useful for allowing network access to 'servers' where only the server\n"
160" needs to authenticate the client (ie. the other way is not required).\n"
161" Even with client and server authentication, this 'technique' mitigates\n"
162" some DoS (denial-of-service) potential as it will be the network client\n"
163" having to perform the first private key operation rather than the other\n"
164" way round.\n"
165"(4) The 'technique' used by setting '-flipped 1' is probably compatible with\n"
166" absolutely nothing except another complimentary instance of 'tunala'\n"
167" running with '-flipped 1'. :-)\n";
168
169/* Default DH parameters for use with "-dh_special standard" ... stolen striaght
170 * from s_server. */
171static unsigned char dh512_p[]={
172 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
173 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
174 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
175 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
176 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
177 0x47,0x74,0xE8,0x33,
178 };
179static unsigned char dh512_g[]={
180 0x02,
181 };
182
183/* And the function that parses the above "standard" parameters, again, straight
184 * out of s_server. */
185static DH *get_dh512(void)
186 {
187 DH *dh=NULL;
188
189 if ((dh=DH_new()) == NULL) return(NULL);
190 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
191 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
192 if ((dh->p == NULL) || (dh->g == NULL))
193 return(NULL);
194 return(dh);
195 }
196
197/* Various help/error messages used by main() */
198static int usage(const char *errstr, int isunknownarg)
199{
200 if(isunknownarg)
201 fprintf(stderr, "Error: unknown argument '%s'\n", errstr);
202 else
203 fprintf(stderr, "Error: %s\n", errstr);
204 fprintf(stderr, "%s\n", helpstring);
205 return 1;
206}
207
208static int err_str0(const char *str0)
209{
210 fprintf(stderr, "%s\n", str0);
211 return 1;
212}
213
214static int err_str1(const char *fmt, const char *str1)
215{
216 fprintf(stderr, fmt, str1);
217 fprintf(stderr, "\n");
218 return 1;
219}
220
221static int parse_max_tunnels(const char *s, unsigned int *maxtunnels)
222{
223 unsigned long l;
224 if(!int_strtoul(s, &l) || (l < 1) || (l > 1024)) {
225 fprintf(stderr, "Error, '%s' is an invalid value for "
226 "maxtunnels\n", s);
227 return 0;
228 }
229 *maxtunnels = (unsigned int)l;
230 return 1;
231}
232
233static int parse_server_mode(const char *s, int *servermode)
234{
235 unsigned long l;
236 if(!int_strtoul(s, &l) || (l > 1)) {
237 fprintf(stderr, "Error, '%s' is an invalid value for the "
238 "server mode\n", s);
239 return 0;
240 }
241 *servermode = (int)l;
242 return 1;
243}
244
245static int parse_dh_special(const char *s, const char **dh_special)
246{
247 if((strcmp(s, "NULL") == 0) || (strcmp(s, "generate") == 0) ||
248 (strcmp(s, "standard") == 0)) {
249 *dh_special = s;
250 return 1;
251 }
252 fprintf(stderr, "Error, '%s' is an invalid value for 'dh_special'\n", s);
253 return 0;
254}
255
256static int parse_verify_level(const char *s, unsigned int *verify_level)
257{
258 unsigned long l;
259 if(!int_strtoul(s, &l) || (l > 3)) {
260 fprintf(stderr, "Error, '%s' is an invalid value for "
261 "out_verify\n", s);
262 return 0;
263 }
264 *verify_level = (unsigned int)l;
265 return 1;
266}
267
268static int parse_verify_depth(const char *s, unsigned int *verify_depth)
269{
270 unsigned long l;
271 if(!int_strtoul(s, &l) || (l < 1) || (l > 50)) {
272 fprintf(stderr, "Error, '%s' is an invalid value for "
273 "verify_depth\n", s);
274 return 0;
275 }
276 *verify_depth = (unsigned int)l;
277 return 1;
278}
279
280/* Some fprintf format strings used when tunnels close */
281static const char *io_stats_dirty =
282" SSL traffic; %8lu bytes in, %8lu bytes out\n";
283static const char *io_stats_clean =
284" clear traffic; %8lu bytes in, %8lu bytes out\n";
285
286int main(int argc, char *argv[])
287{
288 unsigned int loop;
289 int newfd;
290 tunala_world_t world;
291 tunala_item_t *t_item;
292 const char *proxy_ip;
293 unsigned short proxy_port;
294 /* Overridables */
295 const char *proxyhost = def_proxyhost;
296 const char *listenhost = def_listenhost;
297 unsigned int max_tunnels = def_max_tunnels;
298 const char *cacert = def_cacert;
299 const char *cert = def_cert;
300 const char *key = def_key;
301 const char *dcert = def_dcert;
302 const char *dkey = def_dkey;
303 const char *engine_id = def_engine_id;
304 int server_mode = def_server_mode;
305 int flipped = def_flipped;
306 const char *cipher_list = def_cipher_list;
307 const char *dh_file = def_dh_file;
308 const char *dh_special = def_dh_special;
309 int ctx_options = def_ctx_options;
310 int verify_mode = def_verify_mode;
311 unsigned int verify_depth = def_verify_depth;
312 int out_state = def_out_state;
313 unsigned int out_verify = def_out_verify;
314 int out_totals = def_out_totals;
315 int out_conns = def_out_conns;
316
317/* Parse command-line arguments */
318next_arg:
319 argc--; argv++;
320 if(argc > 0) {
321 if(strcmp(*argv, "-listen") == 0) {
322 if(argc < 2)
323 return usage("-listen requires an argument", 0);
324 argc--; argv++;
325 listenhost = *argv;
326 goto next_arg;
327 } else if(strcmp(*argv, "-proxy") == 0) {
328 if(argc < 2)
329 return usage("-proxy requires an argument", 0);
330 argc--; argv++;
331 proxyhost = *argv;
332 goto next_arg;
333 } else if(strcmp(*argv, "-maxtunnels") == 0) {
334 if(argc < 2)
335 return usage("-maxtunnels requires an argument", 0);
336 argc--; argv++;
337 if(!parse_max_tunnels(*argv, &max_tunnels))
338 return 1;
339 goto next_arg;
340 } else if(strcmp(*argv, "-cacert") == 0) {
341 if(argc < 2)
342 return usage("-cacert requires an argument", 0);
343 argc--; argv++;
344 if(strcmp(*argv, "NULL") == 0)
345 cacert = NULL;
346 else
347 cacert = *argv;
348 goto next_arg;
349 } else if(strcmp(*argv, "-cert") == 0) {
350 if(argc < 2)
351 return usage("-cert requires an argument", 0);
352 argc--; argv++;
353 if(strcmp(*argv, "NULL") == 0)
354 cert = NULL;
355 else
356 cert = *argv;
357 goto next_arg;
358 } else if(strcmp(*argv, "-key") == 0) {
359 if(argc < 2)
360 return usage("-key requires an argument", 0);
361 argc--; argv++;
362 if(strcmp(*argv, "NULL") == 0)
363 key = NULL;
364 else
365 key = *argv;
366 goto next_arg;
367 } else if(strcmp(*argv, "-dcert") == 0) {
368 if(argc < 2)
369 return usage("-dcert requires an argument", 0);
370 argc--; argv++;
371 if(strcmp(*argv, "NULL") == 0)
372 dcert = NULL;
373 else
374 dcert = *argv;
375 goto next_arg;
376 } else if(strcmp(*argv, "-dkey") == 0) {
377 if(argc < 2)
378 return usage("-dkey requires an argument", 0);
379 argc--; argv++;
380 if(strcmp(*argv, "NULL") == 0)
381 dkey = NULL;
382 else
383 dkey = *argv;
384 goto next_arg;
385 } else if(strcmp(*argv, "-engine") == 0) {
386 if(argc < 2)
387 return usage("-engine requires an argument", 0);
388 argc--; argv++;
389 engine_id = *argv;
390 goto next_arg;
391 } else if(strcmp(*argv, "-server") == 0) {
392 if(argc < 2)
393 return usage("-server requires an argument", 0);
394 argc--; argv++;
395 if(!parse_server_mode(*argv, &server_mode))
396 return 1;
397 goto next_arg;
398 } else if(strcmp(*argv, "-flipped") == 0) {
399 if(argc < 2)
400 return usage("-flipped requires an argument", 0);
401 argc--; argv++;
402 if(!parse_server_mode(*argv, &flipped))
403 return 1;
404 goto next_arg;
405 } else if(strcmp(*argv, "-cipher") == 0) {
406 if(argc < 2)
407 return usage("-cipher requires an argument", 0);
408 argc--; argv++;
409 cipher_list = *argv;
410 goto next_arg;
411 } else if(strcmp(*argv, "-dh_file") == 0) {
412 if(argc < 2)
413 return usage("-dh_file requires an argument", 0);
414 if(dh_special)
415 return usage("cannot mix -dh_file with "
416 "-dh_special", 0);
417 argc--; argv++;
418 dh_file = *argv;
419 goto next_arg;
420 } else if(strcmp(*argv, "-dh_special") == 0) {
421 if(argc < 2)
422 return usage("-dh_special requires an argument", 0);
423 if(dh_file)
424 return usage("cannot mix -dh_file with "
425 "-dh_special", 0);
426 argc--; argv++;
427 if(!parse_dh_special(*argv, &dh_special))
428 return 1;
429 goto next_arg;
430 } else if(strcmp(*argv, "-no_ssl2") == 0) {
431 ctx_options |= SSL_OP_NO_SSLv2;
432 goto next_arg;
433 } else if(strcmp(*argv, "-no_ssl3") == 0) {
434 ctx_options |= SSL_OP_NO_SSLv3;
435 goto next_arg;
436 } else if(strcmp(*argv, "-no_tls1") == 0) {
437 ctx_options |= SSL_OP_NO_TLSv1;
438 goto next_arg;
439 } else if(strcmp(*argv, "-v_peer") == 0) {
440 verify_mode |= SSL_VERIFY_PEER;
441 goto next_arg;
442 } else if(strcmp(*argv, "-v_strict") == 0) {
443 verify_mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
444 goto next_arg;
445 } else if(strcmp(*argv, "-v_once") == 0) {
446 verify_mode |= SSL_VERIFY_CLIENT_ONCE;
447 goto next_arg;
448 } else if(strcmp(*argv, "-v_depth") == 0) {
449 if(argc < 2)
450 return usage("-v_depth requires an argument", 0);
451 argc--; argv++;
452 if(!parse_verify_depth(*argv, &verify_depth))
453 return 1;
454 goto next_arg;
455 } else if(strcmp(*argv, "-out_state") == 0) {
456 out_state = 1;
457 goto next_arg;
458 } else if(strcmp(*argv, "-out_verify") == 0) {
459 if(argc < 2)
460 return usage("-out_verify requires an argument", 0);
461 argc--; argv++;
462 if(!parse_verify_level(*argv, &out_verify))
463 return 1;
464 goto next_arg;
465 } else if(strcmp(*argv, "-out_totals") == 0) {
466 out_totals = 1;
467 goto next_arg;
468 } else if(strcmp(*argv, "-out_conns") == 0) {
469 out_conns = 1;
470 goto next_arg;
471 } else if((strcmp(*argv, "-h") == 0) ||
472 (strcmp(*argv, "-help") == 0) ||
473 (strcmp(*argv, "-?") == 0)) {
474 fprintf(stderr, "%s\n", helpstring);
475 return 0;
476 } else
477 return usage(*argv, 1);
478 }
479 /* Run any sanity checks we want here */
480 if(!cert && !dcert && server_mode)
481 fprintf(stderr, "WARNING: you are running an SSL server without "
482 "a certificate - this may not work!\n");
483
484 /* Initialise network stuff */
485 if(!ip_initialise())
486 return err_str0("ip_initialise failed");
487 /* Create the SSL_CTX */
488 if((world.ssl_ctx = initialise_ssl_ctx(server_mode, engine_id,
489 cacert, cert, key, dcert, dkey, cipher_list, dh_file,
490 dh_special, ctx_options, out_state, out_verify,
491 verify_mode, verify_depth)) == NULL)
492 return err_str1("initialise_ssl_ctx(engine_id=%s) failed",
493 (engine_id == NULL) ? "NULL" : engine_id);
494 if(engine_id)
495 fprintf(stderr, "Info, engine '%s' initialised\n", engine_id);
496 /* Create the listener */
497 if((world.listen_fd = ip_create_listener(listenhost)) == -1)
498 return err_str1("ip_create_listener(%s) failed", listenhost);
499 fprintf(stderr, "Info, listening on '%s'\n", listenhost);
500 if(!ip_parse_address(proxyhost, &proxy_ip, &proxy_port, 0))
501 return err_str1("ip_parse_address(%s) failed", proxyhost);
502 fprintf(stderr, "Info, proxying to '%s' (%d.%d.%d.%d:%d)\n", proxyhost,
503 (int)proxy_ip[0], (int)proxy_ip[1],
504 (int)proxy_ip[2], (int)proxy_ip[3], (int)proxy_port);
505 fprintf(stderr, "Info, set maxtunnels to %d\n", (int)max_tunnels);
506 fprintf(stderr, "Info, set to operate as an SSL %s\n",
507 (server_mode ? "server" : "client"));
508 /* Initialise the rest of the stuff */
509 world.tunnels_used = world.tunnels_size = 0;
510 world.tunnels = NULL;
511 world.server_mode = server_mode;
512 selector_init(&world.selector);
513
514/* We're ready to loop */
515main_loop:
516 /* Should we listen for *new* tunnels? */
517 if(world.tunnels_used < max_tunnels)
518 selector_add_listener(&world.selector, world.listen_fd);
519 /* We should add in our existing tunnels */
520 for(loop = 0; loop < world.tunnels_used; loop++)
521 selector_add_tunala(&world.selector, world.tunnels + loop);
522 /* Now do the select */
523 switch(selector_select(&world.selector)) {
524 case -1:
525 fprintf(stderr, "selector_select returned a badness error.\n");
526 goto shouldnt_happen;
527 case 0:
528 fprintf(stderr, "Warn, selector_select returned 0 - signal?""?\n");
529 goto main_loop;
530 default:
531 break;
532 }
533 /* Accept new connection if we should and can */
534 if((world.tunnels_used < max_tunnels) && (selector_get_listener(
535 &world.selector, world.listen_fd,
536 &newfd) == 1)) {
537 /* We have a new connection */
538 if(!tunala_world_new_item(&world, newfd, proxy_ip,
539 proxy_port, flipped))
540 fprintf(stderr, "tunala_world_new_item failed\n");
541 else if(out_conns)
542 fprintf(stderr, "Info, new tunnel opened, now up to "
543 "%d\n", world.tunnels_used);
544 }
545 /* Give each tunnel its moment, note the while loop is because it makes
546 * the logic easier than with "for" to deal with an array that may shift
547 * because of deletes. */
548 loop = 0;
549 t_item = world.tunnels;
550 while(loop < world.tunnels_used) {
551 if(!tunala_item_io(&world.selector, t_item)) {
552 /* We're closing whether for reasons of an error or a
553 * natural close. Don't increment loop or t_item because
554 * the next item is moving to us! */
555 if(!out_totals)
556 goto skip_totals;
557 fprintf(stderr, "Tunnel closing, traffic stats follow\n");
558 /* Display the encrypted (over the network) stats */
559 fprintf(stderr, io_stats_dirty,
560 buffer_total_in(state_machine_get_buffer(
561 &t_item->sm,SM_DIRTY_IN)),
562 buffer_total_out(state_machine_get_buffer(
563 &t_item->sm,SM_DIRTY_OUT)));
564 /* Display the local (tunnelled) stats. NB: Data we
565 * *receive* is data sent *out* of the state_machine on
566 * its 'clean' side. Hence the apparent back-to-front
567 * OUT/IN mixup here :-) */
568 fprintf(stderr, io_stats_clean,
569 buffer_total_out(state_machine_get_buffer(
570 &t_item->sm,SM_CLEAN_OUT)),
571 buffer_total_in(state_machine_get_buffer(
572 &t_item->sm,SM_CLEAN_IN)));
573skip_totals:
574 tunala_world_del_item(&world, loop);
575 if(out_conns)
576 fprintf(stderr, "Info, tunnel closed, down to %d\n",
577 world.tunnels_used);
578 }
579 else {
580 /* Move to the next item */
581 loop++;
582 t_item++;
583 }
584 }
585 goto main_loop;
586 /* Should never get here */
587shouldnt_happen:
588 abort();
589 return 1;
590}
591
592/****************/
593/* OpenSSL bits */
594/****************/
595
596static int ctx_set_cert(SSL_CTX *ctx, const char *cert, const char *key)
597{
598 FILE *fp = NULL;
599 X509 *x509 = NULL;
600 EVP_PKEY *pkey = NULL;
601 int toret = 0; /* Assume an error */
602
603 /* cert */
604 if(cert) {
605 if((fp = fopen(cert, "r")) == NULL) {
606 fprintf(stderr, "Error opening cert file '%s'\n", cert);
607 goto err;
608 }
609 if(!PEM_read_X509(fp, &x509, NULL, NULL)) {
610 fprintf(stderr, "Error reading PEM cert from '%s'\n",
611 cert);
612 goto err;
613 }
614 if(!SSL_CTX_use_certificate(ctx, x509)) {
615 fprintf(stderr, "Error, cert in '%s' can not be used\n",
616 cert);
617 goto err;
618 }
619 /* Clear the FILE* for reuse in the "key" code */
620 fclose(fp);
621 fp = NULL;
622 fprintf(stderr, "Info, operating with cert in '%s'\n", cert);
623 /* If a cert was given without matching key, we assume the same
624 * file contains the required key. */
625 if(!key)
626 key = cert;
627 } else {
628 if(key)
629 fprintf(stderr, "Error, can't specify a key without a "
630 "corresponding certificate\n");
631 else
632 fprintf(stderr, "Error, ctx_set_cert called with "
633 "NULLs!\n");
634 goto err;
635 }
636 /* key */
637 if(key) {
638 if((fp = fopen(key, "r")) == NULL) {
639 fprintf(stderr, "Error opening key file '%s'\n", key);
640 goto err;
641 }
642 if(!PEM_read_PrivateKey(fp, &pkey, NULL, NULL)) {
643 fprintf(stderr, "Error reading PEM key from '%s'\n",
644 key);
645 goto err;
646 }
647 if(!SSL_CTX_use_PrivateKey(ctx, pkey)) {
648 fprintf(stderr, "Error, key in '%s' can not be used\n",
649 key);
650 goto err;
651 }
652 fprintf(stderr, "Info, operating with key in '%s'\n", key);
653 } else
654 fprintf(stderr, "Info, operating without a cert or key\n");
655 /* Success */
656 toret = 1; err:
657 if(x509)
658 X509_free(x509);
659 if(pkey)
660 EVP_PKEY_free(pkey);
661 if(fp)
662 fclose(fp);
663 return toret;
664}
665
666static int ctx_set_dh(SSL_CTX *ctx, const char *dh_file, const char *dh_special)
667{
668 DH *dh = NULL;
669 FILE *fp = NULL;
670
671 if(dh_special) {
672 if(strcmp(dh_special, "NULL") == 0)
673 return 1;
674 if(strcmp(dh_special, "standard") == 0) {
675 if((dh = get_dh512()) == NULL) {
676 fprintf(stderr, "Error, can't parse 'standard'"
677 " DH parameters\n");
678 return 0;
679 }
680 fprintf(stderr, "Info, using 'standard' DH parameters\n");
681 goto do_it;
682 }
683 if(strcmp(dh_special, "generate") != 0)
684 /* This shouldn't happen - screening values is handled
685 * in main(). */
686 abort();
687 fprintf(stderr, "Info, generating DH parameters ... ");
688 fflush(stderr);
689 if((dh = DH_generate_parameters(512, DH_GENERATOR_5,
690 NULL, NULL)) == NULL) {
691 fprintf(stderr, "error!\n");
692 return 0;
693 }
694 fprintf(stderr, "complete\n");
695 goto do_it;
696 }
697 /* So, we're loading dh_file */
698 if((fp = fopen(dh_file, "r")) == NULL) {
699 fprintf(stderr, "Error, couldn't open '%s' for DH parameters\n",
700 dh_file);
701 return 0;
702 }
703 dh = PEM_read_DHparams(fp, NULL, NULL, NULL);
704 fclose(fp);
705 if(dh == NULL) {
706 fprintf(stderr, "Error, could not parse DH parameters from '%s'\n",
707 dh_file);
708 return 0;
709 }
710 fprintf(stderr, "Info, using DH parameters from file '%s'\n", dh_file);
711do_it:
712 SSL_CTX_set_tmp_dh(ctx, dh);
713 DH_free(dh);
714 return 1;
715}
716
717static SSL_CTX *initialise_ssl_ctx(int server_mode, const char *engine_id,
718 const char *CAfile, const char *cert, const char *key,
719 const char *dcert, const char *dkey, const char *cipher_list,
720 const char *dh_file, const char *dh_special, int ctx_options,
721 int out_state, int out_verify, int verify_mode,
722 unsigned int verify_depth)
723{
724 SSL_CTX *ctx = NULL, *ret = NULL;
725 SSL_METHOD *meth;
726 ENGINE *e = NULL;
727
728 OpenSSL_add_ssl_algorithms();
729 SSL_load_error_strings();
730
731 meth = (server_mode ? SSLv23_server_method() : SSLv23_client_method());
732 if(meth == NULL)
733 goto err;
734 if(engine_id) {
735 ENGINE_load_builtin_engines();
736 if((e = ENGINE_by_id(engine_id)) == NULL) {
737 fprintf(stderr, "Error obtaining '%s' engine, openssl "
738 "errors follow\n", engine_id);
739 goto err;
740 }
741 if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
742 fprintf(stderr, "Error assigning '%s' engine, openssl "
743 "errors follow\n", engine_id);
744 goto err;
745 }
746 ENGINE_free(e);
747 }
748 if((ctx = SSL_CTX_new(meth)) == NULL)
749 goto err;
750 /* cacert */
751 if(CAfile) {
752 if(!X509_STORE_load_locations(SSL_CTX_get_cert_store(ctx),
753 CAfile, NULL)) {
754 fprintf(stderr, "Error loading CA cert(s) in '%s'\n",
755 CAfile);
756 goto err;
757 }
758 fprintf(stderr, "Info, operating with CA cert(s) in '%s'\n",
759 CAfile);
760 } else
761 fprintf(stderr, "Info, operating without a CA cert(-list)\n");
762 if(!SSL_CTX_set_default_verify_paths(ctx)) {
763 fprintf(stderr, "Error setting default verify paths\n");
764 goto err;
765 }
766
767 /* cert and key */
768 if((cert || key) && !ctx_set_cert(ctx, cert, key))
769 goto err;
770 /* dcert and dkey */
771 if((dcert || dkey) && !ctx_set_cert(ctx, dcert, dkey))
772 goto err;
773
774 /* cipher_list */
775 if(cipher_list) {
776 if(!SSL_CTX_set_cipher_list(ctx, cipher_list)) {
777 fprintf(stderr, "Error setting cipher list '%s'\n",
778 cipher_list);
779 goto err;
780 }
781 fprintf(stderr, "Info, set cipher list '%s'\n", cipher_list);
782 } else
783 fprintf(stderr, "Info, operating with default cipher list\n");
784
785 /* dh_file & dh_special */
786 if((dh_file || dh_special) && !ctx_set_dh(ctx, dh_file, dh_special))
787 goto err;
788
789 /* ctx_options */
790 SSL_CTX_set_options(ctx, ctx_options);
791
792 /* out_state (output of SSL handshake states to screen). */
793 if(out_state)
794 cb_ssl_info_set_output(stderr);
795
796 /* out_verify */
797 if(out_verify > 0) {
798 cb_ssl_verify_set_output(stderr);
799 cb_ssl_verify_set_level(out_verify);
800 }
801
802 /* verify_depth */
803 cb_ssl_verify_set_depth(verify_depth);
804
805 /* Success! (includes setting verify_mode) */
806 SSL_CTX_set_info_callback(ctx, cb_ssl_info);
807 SSL_CTX_set_verify(ctx, verify_mode, cb_ssl_verify);
808 ret = ctx;
809err:
810 if(!ret) {
811 ERR_print_errors_fp(stderr);
812 if(ctx)
813 SSL_CTX_free(ctx);
814 }
815 return ret;
816}
817
818/*****************/
819/* Selector bits */
820/*****************/
821
822static void selector_sets_init(select_sets_t *s)
823{
824 s->max = 0;
825 FD_ZERO(&s->reads);
826 FD_ZERO(&s->sends);
827 FD_ZERO(&s->excepts);
828}
829static void selector_init(tunala_selector_t *selector)
830{
831 selector_sets_init(&selector->last_selected);
832 selector_sets_init(&selector->next_select);
833}
834
835#define SEL_EXCEPTS 0x00
836#define SEL_READS 0x01
837#define SEL_SENDS 0x02
838static void selector_add_raw_fd(tunala_selector_t *s, int fd, int flags)
839{
840 FD_SET(fd, &s->next_select.excepts);
841 if(flags & SEL_READS)
842 FD_SET(fd, &s->next_select.reads);
843 if(flags & SEL_SENDS)
844 FD_SET(fd, &s->next_select.sends);
845 /* Adjust "max" */
846 if(s->next_select.max < (fd + 1))
847 s->next_select.max = fd + 1;
848}
849
850static void selector_add_listener(tunala_selector_t *selector, int fd)
851{
852 selector_add_raw_fd(selector, fd, SEL_READS);
853}
854
855static void selector_add_tunala(tunala_selector_t *s, tunala_item_t *t)
856{
857 /* Set clean read if sm.clean_in is not full */
858 if(t->clean_read != -1) {
859 selector_add_raw_fd(s, t->clean_read,
860 (buffer_full(state_machine_get_buffer(&t->sm,
861 SM_CLEAN_IN)) ? SEL_EXCEPTS : SEL_READS));
862 }
863 /* Set clean send if sm.clean_out is not empty */
864 if(t->clean_send != -1) {
865 selector_add_raw_fd(s, t->clean_send,
866 (buffer_empty(state_machine_get_buffer(&t->sm,
867 SM_CLEAN_OUT)) ? SEL_EXCEPTS : SEL_SENDS));
868 }
869 /* Set dirty read if sm.dirty_in is not full */
870 if(t->dirty_read != -1) {
871 selector_add_raw_fd(s, t->dirty_read,
872 (buffer_full(state_machine_get_buffer(&t->sm,
873 SM_DIRTY_IN)) ? SEL_EXCEPTS : SEL_READS));
874 }
875 /* Set dirty send if sm.dirty_out is not empty */
876 if(t->dirty_send != -1) {
877 selector_add_raw_fd(s, t->dirty_send,
878 (buffer_empty(state_machine_get_buffer(&t->sm,
879 SM_DIRTY_OUT)) ? SEL_EXCEPTS : SEL_SENDS));
880 }
881}
882
883static int selector_select(tunala_selector_t *selector)
884{
885 memcpy(&selector->last_selected, &selector->next_select,
886 sizeof(select_sets_t));
887 selector_sets_init(&selector->next_select);
888 return select(selector->last_selected.max,
889 &selector->last_selected.reads,
890 &selector->last_selected.sends,
891 &selector->last_selected.excepts, NULL);
892}
893
894/* This returns -1 for error, 0 for no new connections, or 1 for success, in
895 * which case *newfd is populated. */
896static int selector_get_listener(tunala_selector_t *selector, int fd, int *newfd)
897{
898 if(FD_ISSET(fd, &selector->last_selected.excepts))
899 return -1;
900 if(!FD_ISSET(fd, &selector->last_selected.reads))
901 return 0;
902 if((*newfd = ip_accept_connection(fd)) == -1)
903 return -1;
904 return 1;
905}
906
907/************************/
908/* "Tunala" world stuff */
909/************************/
910
911static int tunala_world_make_room(tunala_world_t *world)
912{
913 unsigned int newsize;
914 tunala_item_t *newarray;
915
916 if(world->tunnels_used < world->tunnels_size)
917 return 1;
918 newsize = (world->tunnels_size == 0 ? 16 :
919 ((world->tunnels_size * 3) / 2));
920 if((newarray = malloc(newsize * sizeof(tunala_item_t))) == NULL)
921 return 0;
922 memset(newarray, 0, newsize * sizeof(tunala_item_t));
923 if(world->tunnels_used > 0)
924 memcpy(newarray, world->tunnels,
925 world->tunnels_used * sizeof(tunala_item_t));
926 if(world->tunnels_size > 0)
927 free(world->tunnels);
928 /* migrate */
929 world->tunnels = newarray;
930 world->tunnels_size = newsize;
931 return 1;
932}
933
934static int tunala_world_new_item(tunala_world_t *world, int fd,
935 const char *ip, unsigned short port, int flipped)
936{
937 tunala_item_t *item;
938 int newfd;
939 SSL *new_ssl = NULL;
940
941 if(!tunala_world_make_room(world))
942 return 0;
943 if((new_ssl = SSL_new(world->ssl_ctx)) == NULL) {
944 fprintf(stderr, "Error creating new SSL\n");
945 ERR_print_errors_fp(stderr);
946 return 0;
947 }
948 item = world->tunnels + (world->tunnels_used++);
949 state_machine_init(&item->sm);
950 item->clean_read = item->clean_send =
951 item->dirty_read = item->dirty_send = -1;
952 if((newfd = ip_create_connection_split(ip, port)) == -1)
953 goto err;
954 /* Which way round? If we're a server, "fd" is the dirty side and the
955 * connection we open is the clean one. For a client, it's the other way
956 * around. Unless, of course, we're "flipped" in which case everything
957 * gets reversed. :-) */
958 if((world->server_mode && !flipped) ||
959 (!world->server_mode && flipped)) {
960 item->dirty_read = item->dirty_send = fd;
961 item->clean_read = item->clean_send = newfd;
962 } else {
963 item->clean_read = item->clean_send = fd;
964 item->dirty_read = item->dirty_send = newfd;
965 }
966 /* We use the SSL's "app_data" to indicate a call-back induced "kill" */
967 SSL_set_app_data(new_ssl, NULL);
968 if(!state_machine_set_SSL(&item->sm, new_ssl, world->server_mode))
969 goto err;
970 return 1;
971err:
972 tunala_world_del_item(world, world->tunnels_used - 1);
973 return 0;
974
975}
976
977static void tunala_world_del_item(tunala_world_t *world, unsigned int idx)
978{
979 tunala_item_t *item = world->tunnels + idx;
980 if(item->clean_read != -1)
981 close(item->clean_read);
982 if(item->clean_send != item->clean_read)
983 close(item->clean_send);
984 item->clean_read = item->clean_send = -1;
985 if(item->dirty_read != -1)
986 close(item->dirty_read);
987 if(item->dirty_send != item->dirty_read)
988 close(item->dirty_send);
989 item->dirty_read = item->dirty_send = -1;
990 state_machine_close(&item->sm);
991 /* OK, now we fix the item array */
992 if(idx + 1 < world->tunnels_used)
993 /* We need to scroll entries to the left */
994 memmove(world->tunnels + idx,
995 world->tunnels + (idx + 1),
996 (world->tunnels_used - (idx + 1)) *
997 sizeof(tunala_item_t));
998 world->tunnels_used--;
999}
1000
1001static int tunala_item_io(tunala_selector_t *selector, tunala_item_t *item)
1002{
1003 int c_r, c_s, d_r, d_s; /* Four boolean flags */
1004
1005 /* Take ourselves out of the gene-pool if there was an except */
1006 if((item->clean_read != -1) && FD_ISSET(item->clean_read,
1007 &selector->last_selected.excepts))
1008 return 0;
1009 if((item->clean_send != -1) && FD_ISSET(item->clean_send,
1010 &selector->last_selected.excepts))
1011 return 0;
1012 if((item->dirty_read != -1) && FD_ISSET(item->dirty_read,
1013 &selector->last_selected.excepts))
1014 return 0;
1015 if((item->dirty_send != -1) && FD_ISSET(item->dirty_send,
1016 &selector->last_selected.excepts))
1017 return 0;
1018 /* Grab our 4 IO flags */
1019 c_r = c_s = d_r = d_s = 0;
1020 if(item->clean_read != -1)
1021 c_r = FD_ISSET(item->clean_read, &selector->last_selected.reads);
1022 if(item->clean_send != -1)
1023 c_s = FD_ISSET(item->clean_send, &selector->last_selected.sends);
1024 if(item->dirty_read != -1)
1025 d_r = FD_ISSET(item->dirty_read, &selector->last_selected.reads);
1026 if(item->dirty_send != -1)
1027 d_s = FD_ISSET(item->dirty_send, &selector->last_selected.sends);
1028 /* If no IO has happened for us, skip needless data looping */
1029 if(!c_r && !c_s && !d_r && !d_s)
1030 return 1;
1031 if(c_r)
1032 c_r = (buffer_from_fd(state_machine_get_buffer(&item->sm,
1033 SM_CLEAN_IN), item->clean_read) <= 0);
1034 if(c_s)
1035 c_s = (buffer_to_fd(state_machine_get_buffer(&item->sm,
1036 SM_CLEAN_OUT), item->clean_send) <= 0);
1037 if(d_r)
1038 d_r = (buffer_from_fd(state_machine_get_buffer(&item->sm,
1039 SM_DIRTY_IN), item->dirty_read) <= 0);
1040 if(d_s)
1041 d_s = (buffer_to_fd(state_machine_get_buffer(&item->sm,
1042 SM_DIRTY_OUT), item->dirty_send) <= 0);
1043 /* If any of the flags is non-zero, that means they need closing */
1044 if(c_r) {
1045 close(item->clean_read);
1046 if(item->clean_send == item->clean_read)
1047 item->clean_send = -1;
1048 item->clean_read = -1;
1049 }
1050 if(c_s && (item->clean_send != -1)) {
1051 close(item->clean_send);
1052 if(item->clean_send == item->clean_read)
1053 item->clean_read = -1;
1054 item->clean_send = -1;
1055 }
1056 if(d_r) {
1057 close(item->dirty_read);
1058 if(item->dirty_send == item->dirty_read)
1059 item->dirty_send = -1;
1060 item->dirty_read = -1;
1061 }
1062 if(d_s && (item->dirty_send != -1)) {
1063 close(item->dirty_send);
1064 if(item->dirty_send == item->dirty_read)
1065 item->dirty_read = -1;
1066 item->dirty_send = -1;
1067 }
1068 /* This function name is attributed to the term donated by David
1069 * Schwartz on openssl-dev, message-ID:
1070 * <NCBBLIEPOCNJOAEKBEAKEEDGLIAA.davids@webmaster.com>. :-) */
1071 if(!state_machine_churn(&item->sm))
1072 /* If the SSL closes, it will also zero-out the _in buffers
1073 * and will in future process just outgoing data. As and
1074 * when the outgoing data has gone, it will return zero
1075 * here to tell us to bail out. */
1076 return 0;
1077 /* Otherwise, we return zero if both sides are dead. */
1078 if(((item->clean_read == -1) || (item->clean_send == -1)) &&
1079 ((item->dirty_read == -1) || (item->dirty_send == -1)))
1080 return 0;
1081 /* If only one side closed, notify the SSL of this so it can take
1082 * appropriate action. */
1083 if((item->clean_read == -1) || (item->clean_send == -1)) {
1084 if(!state_machine_close_clean(&item->sm))
1085 return 0;
1086 }
1087 if((item->dirty_read == -1) || (item->dirty_send == -1)) {
1088 if(!state_machine_close_dirty(&item->sm))
1089 return 0;
1090 }
1091 return 1;
1092}
1093
diff --git a/src/lib/libssl/src/demos/tunala/tunala.h b/src/lib/libssl/src/demos/tunala/tunala.h
new file mode 100644
index 0000000000..b4c8ec78d8
--- /dev/null
+++ b/src/lib/libssl/src/demos/tunala/tunala.h
@@ -0,0 +1,214 @@
1/* Tunala ("Tunneler with a New Zealand accent")
2 *
3 * Written by Geoff Thorpe, but endorsed/supported by noone. Please use this is
4 * if it's useful or informative to you, but it's only here as a scratchpad for
5 * ideas about how you might (or might not) program with OpenSSL. If you deploy
6 * this is in a mission-critical environment, and have not read, understood,
7 * audited, and modified this code to your satisfaction, and the result is that
8 * all hell breaks loose and you are looking for a new employer, then it proves
9 * nothing except perhaps that Darwinism is alive and well. Let's just say, *I*
10 * don't use this in a mission-critical environment, so it would be stupid for
11 * anyone to assume that it is solid and/or tested enough when even its author
12 * doesn't place that much trust in it. You have been warned.
13 *
14 * With thanks to Cryptographic Appliances, Inc.
15 */
16
17#ifndef _TUNALA_H
18#define _TUNALA_H
19
20/* pull in autoconf fluff */
21#ifndef NO_CONFIG_H
22#include "config.h"
23#else
24/* We don't have autoconf, we have to set all of these unless a tweaked Makefile
25 * tells us not to ... */
26/* headers */
27#ifndef NO_HAVE_SELECT
28#define HAVE_SELECT
29#endif
30#ifndef NO_HAVE_SOCKET
31#define HAVE_SOCKET
32#endif
33#ifndef NO_HAVE_UNISTD_H
34#define HAVE_UNISTD_H
35#endif
36#ifndef NO_HAVE_FCNTL_H
37#define HAVE_FCNTL_H
38#endif
39#ifndef NO_HAVE_LIMITS_H
40#define HAVE_LIMITS_H
41#endif
42/* features */
43#ifndef NO_HAVE_STRSTR
44#define HAVE_STRSTR
45#endif
46#ifndef NO_HAVE_STRTOUL
47#define HAVE_STRTOUL
48#endif
49#endif
50
51#if !defined(HAVE_SELECT) || !defined(HAVE_SOCKET)
52#error "can't build without some network basics like select() and socket()"
53#endif
54
55#include <stdlib.h>
56#ifndef NO_SYSTEM_H
57#include <string.h>
58#ifdef HAVE_UNISTD_H
59#include <unistd.h>
60#endif
61#ifdef HAVE_FCNTL_H
62#include <fcntl.h>
63#endif
64#ifdef HAVE_LIMITS_H
65#include <limits.h>
66#endif
67#include <netdb.h>
68#include <signal.h>
69#include <sys/socket.h>
70#include <sys/types.h>
71#include <netinet/in.h>
72#endif /* !defined(NO_SYSTEM_H) */
73
74#ifndef NO_OPENSSL
75#include <openssl/err.h>
76#include <openssl/engine.h>
77#include <openssl/ssl.h>
78#endif /* !defined(NO_OPENSSL) */
79
80#ifndef OPENSSL_NO_BUFFER
81/* This is the generic "buffer" type that is used when feeding the
82 * state-machine. It's basically a FIFO with respect to the "adddata" &
83 * "takedata" type functions that operate on it. */
84#define MAX_DATA_SIZE 16384
85typedef struct _buffer_t {
86 unsigned char data[MAX_DATA_SIZE];
87 unsigned int used;
88 /* Statistical values - counts the total number of bytes read in and
89 * read out (respectively) since "buffer_init()" */
90 unsigned long total_in, total_out;
91} buffer_t;
92
93/* Initialise a buffer structure before use */
94void buffer_init(buffer_t *buf);
95/* Cleanup a buffer structure - presently not needed, but if buffer_t is
96 * converted to using dynamic allocation, this would be required - so should be
97 * called to protect against an explosion of memory leaks later if the change is
98 * made. */
99void buffer_close(buffer_t *buf);
100
101/* Basic functions to manipulate buffers */
102
103unsigned int buffer_used(buffer_t *buf); /* How much data in the buffer */
104unsigned int buffer_unused(buffer_t *buf); /* How much space in the buffer */
105int buffer_full(buffer_t *buf); /* Boolean, is it full? */
106int buffer_notfull(buffer_t *buf); /* Boolean, is it not full? */
107int buffer_empty(buffer_t *buf); /* Boolean, is it empty? */
108int buffer_notempty(buffer_t *buf); /* Boolean, is it not empty? */
109unsigned long buffer_total_in(buffer_t *buf); /* Total bytes written to buffer */
110unsigned long buffer_total_out(buffer_t *buf); /* Total bytes read from buffer */
111
112#if 0 /* Currently used only within buffer.c - better to expose only
113 * higher-level functions anyway */
114/* Add data to the tail of the buffer, returns the amount that was actually
115 * added (so, you need to check if return value is less than size) */
116unsigned int buffer_adddata(buffer_t *buf, const unsigned char *ptr,
117 unsigned int size);
118
119/* Take data from the front of the buffer (and scroll the rest forward). If
120 * "ptr" is NULL, this just removes data off the front of the buffer. Return
121 * value is the amount actually removed (can be less than size if the buffer has
122 * too little data). */
123unsigned int buffer_takedata(buffer_t *buf, unsigned char *ptr,
124 unsigned int size);
125
126/* Flushes as much data as possible out of the "from" buffer into the "to"
127 * buffer. Return value is the amount moved. The amount moved can be restricted
128 * to a maximum by specifying "cap" - setting it to -1 means no limit. */
129unsigned int buffer_tobuffer(buffer_t *to, buffer_t *from, int cap);
130#endif
131
132#ifndef NO_IP
133/* Read or write between a file-descriptor and a buffer */
134int buffer_from_fd(buffer_t *buf, int fd);
135int buffer_to_fd(buffer_t *buf, int fd);
136#endif /* !defined(NO_IP) */
137
138#ifndef NO_OPENSSL
139/* Read or write between an SSL or BIO and a buffer */
140void buffer_from_SSL(buffer_t *buf, SSL *ssl);
141void buffer_to_SSL(buffer_t *buf, SSL *ssl);
142void buffer_from_BIO(buffer_t *buf, BIO *bio);
143void buffer_to_BIO(buffer_t *buf, BIO *bio);
144
145/* Callbacks */
146void cb_ssl_info(const SSL *s, int where, int ret);
147void cb_ssl_info_set_output(FILE *fp); /* Called if output should be sent too */
148int cb_ssl_verify(int ok, X509_STORE_CTX *ctx);
149void cb_ssl_verify_set_output(FILE *fp);
150void cb_ssl_verify_set_depth(unsigned int verify_depth);
151void cb_ssl_verify_set_level(unsigned int level);
152#endif /* !defined(NO_OPENSSL) */
153#endif /* !defined(OPENSSL_NO_BUFFER) */
154
155#ifndef NO_TUNALA
156#ifdef OPENSSL_NO_BUFFER
157#error "TUNALA section of tunala.h requires BUFFER support"
158#endif
159typedef struct _state_machine_t {
160 SSL *ssl;
161 BIO *bio_intossl;
162 BIO *bio_fromssl;
163 buffer_t clean_in, clean_out;
164 buffer_t dirty_in, dirty_out;
165} state_machine_t;
166typedef enum {
167 SM_CLEAN_IN, SM_CLEAN_OUT,
168 SM_DIRTY_IN, SM_DIRTY_OUT
169} sm_buffer_t;
170void state_machine_init(state_machine_t *machine);
171void state_machine_close(state_machine_t *machine);
172buffer_t *state_machine_get_buffer(state_machine_t *machine, sm_buffer_t type);
173SSL *state_machine_get_SSL(state_machine_t *machine);
174int state_machine_set_SSL(state_machine_t *machine, SSL *ssl, int is_server);
175/* Performs the data-IO loop and returns zero if the machine should close */
176int state_machine_churn(state_machine_t *machine);
177/* Is used to handle closing conditions - namely when one side of the tunnel has
178 * closed but the other should finish flushing. */
179int state_machine_close_clean(state_machine_t *machine);
180int state_machine_close_dirty(state_machine_t *machine);
181#endif /* !defined(NO_TUNALA) */
182
183#ifndef NO_IP
184/* Initialise anything related to the networking. This includes blocking pesky
185 * SIGPIPE signals. */
186int ip_initialise(void);
187/* ip is the 4-byte ip address (eg. 127.0.0.1 is {0x7F,0x00,0x00,0x01}), port is
188 * the port to listen on (host byte order), and the return value is the
189 * file-descriptor or -1 on error. */
190int ip_create_listener_split(const char *ip, unsigned short port);
191/* Same semantics as above. */
192int ip_create_connection_split(const char *ip, unsigned short port);
193/* Converts a string into the ip/port before calling the above */
194int ip_create_listener(const char *address);
195int ip_create_connection(const char *address);
196/* Just does a string conversion on its own. NB: If accept_all_ip is non-zero,
197 * then the address string could be just a port. Ie. it's suitable for a
198 * listening address but not a connecting address. */
199int ip_parse_address(const char *address, const char **parsed_ip,
200 unsigned short *port, int accept_all_ip);
201/* Accepts an incoming connection through the listener. Assumes selects and
202 * what-not have deemed it an appropriate thing to do. */
203int ip_accept_connection(int listen_fd);
204#endif /* !defined(NO_IP) */
205
206/* These functions wrap up things that can be portability hassles. */
207int int_strtoul(const char *str, unsigned long *val);
208#ifdef HAVE_STRSTR
209#define int_strstr strstr
210#else
211char *int_strstr(const char *haystack, const char *needle);
212#endif
213
214#endif /* !defined(_TUNALA_H) */
diff --git a/src/lib/libssl/src/demos/x509/README b/src/lib/libssl/src/demos/x509/README
new file mode 100644
index 0000000000..88f9d6c46e
--- /dev/null
+++ b/src/lib/libssl/src/demos/x509/README
@@ -0,0 +1,3 @@
1This directory contains examples of how to contruct
2various X509 structures. Certificates, certificate requests
3and CRLs.
diff --git a/src/lib/libssl/src/demos/x509/mkcert.c b/src/lib/libssl/src/demos/x509/mkcert.c
new file mode 100644
index 0000000000..4709e18e7c
--- /dev/null
+++ b/src/lib/libssl/src/demos/x509/mkcert.c
@@ -0,0 +1,168 @@
1/* Certificate creation. Demonstrates some certificate related
2 * operations.
3 */
4
5
6#include <stdio.h>
7#include <stdlib.h>
8
9#include <openssl/pem.h>
10#include <openssl/conf.h>
11#include <openssl/x509v3.h>
12#include <openssl/engine.h>
13
14int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
15int add_ext(X509 *cert, int nid, char *value);
16
17int main(int argc, char **argv)
18 {
19 BIO *bio_err;
20 X509 *x509=NULL;
21 EVP_PKEY *pkey=NULL;
22
23 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
24
25 bio_err=BIO_new_fp(stderr, BIO_NOCLOSE);
26
27 mkcert(&x509,&pkey,512,0,365);
28
29 RSA_print_fp(stdout,pkey->pkey.rsa,0);
30 X509_print_fp(stdout,x509);
31
32 PEM_write_PrivateKey(stdout,pkey,NULL,NULL,0,NULL, NULL);
33 PEM_write_X509(stdout,x509);
34
35 X509_free(x509);
36 EVP_PKEY_free(pkey);
37
38 ENGINE_cleanup();
39 CRYPTO_cleanup_all_ex_data();
40
41 CRYPTO_mem_leaks(bio_err);
42 BIO_free(bio_err);
43 return(0);
44 }
45
46static void callback(int p, int n, void *arg)
47 {
48 char c='B';
49
50 if (p == 0) c='.';
51 if (p == 1) c='+';
52 if (p == 2) c='*';
53 if (p == 3) c='\n';
54 fputc(c,stderr);
55 }
56
57int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
58 {
59 X509 *x;
60 EVP_PKEY *pk;
61 RSA *rsa;
62 X509_NAME *name=NULL;
63
64 if ((pkeyp == NULL) || (*pkeyp == NULL))
65 {
66 if ((pk=EVP_PKEY_new()) == NULL)
67 {
68 abort();
69 return(0);
70 }
71 }
72 else
73 pk= *pkeyp;
74
75 if ((x509p == NULL) || (*x509p == NULL))
76 {
77 if ((x=X509_new()) == NULL)
78 goto err;
79 }
80 else
81 x= *x509p;
82
83 rsa=RSA_generate_key(bits,RSA_F4,callback,NULL);
84 if (!EVP_PKEY_assign_RSA(pk,rsa))
85 {
86 abort();
87 goto err;
88 }
89 rsa=NULL;
90
91 X509_set_version(x,3);
92 ASN1_INTEGER_set(X509_get_serialNumber(x),serial);
93 X509_gmtime_adj(X509_get_notBefore(x),0);
94 X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);
95 X509_set_pubkey(x,pk);
96
97 name=X509_get_subject_name(x);
98
99 /* This function creates and adds the entry, working out the
100 * correct string type and performing checks on its length.
101 * Normally we'd check the return value for errors...
102 */
103 X509_NAME_add_entry_by_txt(name,"C",
104 MBSTRING_ASC, "UK", -1, -1, 0);
105 X509_NAME_add_entry_by_txt(name,"CN",
106 MBSTRING_ASC, "OpenSSL Group", -1, -1, 0);
107
108 /* Its self signed so set the issuer name to be the same as the
109 * subject.
110 */
111 X509_set_issuer_name(x,name);
112
113 /* Add various extensions: standard extensions */
114 add_ext(x, NID_basic_constraints, "critical,CA:TRUE");
115 add_ext(x, NID_key_usage, "critical,keyCertSign,cRLSign");
116
117 add_ext(x, NID_subject_key_identifier, "hash");
118
119 /* Some Netscape specific extensions */
120 add_ext(x, NID_netscape_cert_type, "sslCA");
121
122 add_ext(x, NID_netscape_comment, "example comment extension");
123
124
125#ifdef CUSTOM_EXT
126 /* Maybe even add our own extension based on existing */
127 {
128 int nid;
129 nid = OBJ_create("1.2.3.4", "MyAlias", "My Test Alias Extension");
130 X509V3_EXT_add_alias(nid, NID_netscape_comment);
131 add_ext(x, nid, "example comment alias");
132 }
133#endif
134
135 if (!X509_sign(x,pk,EVP_md5()))
136 goto err;
137
138 *x509p=x;
139 *pkeyp=pk;
140 return(1);
141err:
142 return(0);
143 }
144
145/* Add extension using V3 code: we can set the config file as NULL
146 * because we wont reference any other sections.
147 */
148
149int add_ext(X509 *cert, int nid, char *value)
150 {
151 X509_EXTENSION *ex;
152 X509V3_CTX ctx;
153 /* This sets the 'context' of the extensions. */
154 /* No configuration database */
155 X509V3_set_ctx_nodb(&ctx);
156 /* Issuer and subject certs: both the target since it is self signed,
157 * no request and no CRL
158 */
159 X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
160 ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, value);
161 if (!ex)
162 return 0;
163
164 X509_add_ext(cert,ex,-1);
165 X509_EXTENSION_free(ex);
166 return 1;
167 }
168
diff --git a/src/lib/libssl/src/demos/x509/mkreq.c b/src/lib/libssl/src/demos/x509/mkreq.c
new file mode 100644
index 0000000000..d69dcc392b
--- /dev/null
+++ b/src/lib/libssl/src/demos/x509/mkreq.c
@@ -0,0 +1,157 @@
1/* Certificate request creation. Demonstrates some request related
2 * operations.
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7
8#include <openssl/pem.h>
9#include <openssl/conf.h>
10#include <openssl/x509v3.h>
11#include <openssl/engine.h>
12
13int mkreq(X509_REQ **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
14int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value);
15
16int main(int argc, char **argv)
17 {
18 BIO *bio_err;
19 X509_REQ *req=NULL;
20 EVP_PKEY *pkey=NULL;
21
22 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
23
24 bio_err=BIO_new_fp(stderr, BIO_NOCLOSE);
25
26 mkreq(&req,&pkey,512,0,365);
27
28 RSA_print_fp(stdout,pkey->pkey.rsa,0);
29 X509_REQ_print_fp(stdout,req);
30
31 PEM_write_X509_REQ(stdout,req);
32
33 X509_REQ_free(req);
34 EVP_PKEY_free(pkey);
35
36 ENGINE_cleanup();
37 CRYPTO_cleanup_all_ex_data();
38
39 CRYPTO_mem_leaks(bio_err);
40 BIO_free(bio_err);
41 return(0);
42 }
43
44static void callback(int p, int n, void *arg)
45 {
46 char c='B';
47
48 if (p == 0) c='.';
49 if (p == 1) c='+';
50 if (p == 2) c='*';
51 if (p == 3) c='\n';
52 fputc(c,stderr);
53 }
54
55int mkreq(X509_REQ **req, EVP_PKEY **pkeyp, int bits, int serial, int days)
56 {
57 X509_REQ *x;
58 EVP_PKEY *pk;
59 RSA *rsa;
60 X509_NAME *name=NULL;
61 STACK_OF(X509_EXTENSION) *exts = NULL;
62
63 if ((pk=EVP_PKEY_new()) == NULL)
64 goto err;
65
66 if ((x=X509_REQ_new()) == NULL)
67 goto err;
68
69 rsa=RSA_generate_key(bits,RSA_F4,callback,NULL);
70 if (!EVP_PKEY_assign_RSA(pk,rsa))
71 goto err;
72
73 rsa=NULL;
74
75 X509_REQ_set_pubkey(x,pk);
76
77 name=X509_REQ_get_subject_name(x);
78
79 /* This function creates and adds the entry, working out the
80 * correct string type and performing checks on its length.
81 * Normally we'd check the return value for errors...
82 */
83 X509_NAME_add_entry_by_txt(name,"C",
84 MBSTRING_ASC, "UK", -1, -1, 0);
85 X509_NAME_add_entry_by_txt(name,"CN",
86 MBSTRING_ASC, "OpenSSL Group", -1, -1, 0);
87
88#ifdef REQUEST_EXTENSIONS
89 /* Certificate requests can contain extensions, which can be used
90 * to indicate the extensions the requestor would like added to
91 * their certificate. CAs might ignore them however or even choke
92 * if they are present.
93 */
94
95 /* For request extensions they are all packed in a single attribute.
96 * We save them in a STACK and add them all at once later...
97 */
98
99 exts = sk_X509_EXTENSION_new_null();
100 /* Standard extenions */
101
102 add_ext(exts, NID_key_usage, "critical,digitalSignature,keyEncipherment");
103
104 /* This is a typical use for request extensions: requesting a value for
105 * subject alternative name.
106 */
107
108 add_ext(exts, NID_subject_alt_name, "email:steve@openssl.org");
109
110 /* Some Netscape specific extensions */
111 add_ext(exts, NID_netscape_cert_type, "client,email");
112
113
114
115#ifdef CUSTOM_EXT
116 /* Maybe even add our own extension based on existing */
117 {
118 int nid;
119 nid = OBJ_create("1.2.3.4", "MyAlias", "My Test Alias Extension");
120 X509V3_EXT_add_alias(nid, NID_netscape_comment);
121 add_ext(x, nid, "example comment alias");
122 }
123#endif
124
125 /* Now we've created the extensions we add them to the request */
126
127 X509_REQ_add_extensions(x, exts);
128
129 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
130
131#endif
132
133 if (!X509_REQ_sign(x,pk,EVP_md5()))
134 goto err;
135
136 *req=x;
137 *pkeyp=pk;
138 return(1);
139err:
140 return(0);
141 }
142
143/* Add extension using V3 code: we can set the config file as NULL
144 * because we wont reference any other sections.
145 */
146
147int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value)
148 {
149 X509_EXTENSION *ex;
150 ex = X509V3_EXT_conf_nid(NULL, NULL, nid, value);
151 if (!ex)
152 return 0;
153 sk_X509_EXTENSION_push(sk, ex);
154
155 return 1;
156 }
157
diff --git a/src/lib/libssl/src/doc/HOWTO/certificates.txt b/src/lib/libssl/src/doc/HOWTO/certificates.txt
new file mode 100644
index 0000000000..88048645db
--- /dev/null
+++ b/src/lib/libssl/src/doc/HOWTO/certificates.txt
@@ -0,0 +1,85 @@
1<DRAFT!>
2 HOWTO certificates
3
4How you handle certificates depend a great deal on what your role is.
5Your role can be one or several of:
6
7 - User of some client software
8 - User of some server software
9 - Certificate authority
10
11This file is for users who wish to get a certificate of their own.
12Certificate authorities should read ca.txt.
13
14In all the cases shown below, the standard configuration file, as
15compiled into openssl, will be used. You may find it in /etc/,
16/usr/local/ssr/ or somewhere else. The name is openssl.cnf, and
17is better described in another HOWTO <config.txt?>. If you want to
18use a different configuration file, use the argument '-config {file}'
19with the command shown below.
20
21
22Certificates are related to public key cryptography by containing a
23public key. To be useful, there must be a corresponding private key
24somewhere. With OpenSSL, public keys are easily derived from private
25keys, so before you create a certificate or a certificate request, you
26need to create a private key.
27
28Private keys are generated with 'openssl genrsa' if you want a RSA
29private key, or 'openssl gendsa' if you want a DSA private key. More
30info on how to handle these commands are found in the manual pages for
31those commands or by running them with the argument '-h'. For the
32sake of the description in this file, let's assume that the private
33key ended up in the file privkey.pem (which is the default in some
34cases).
35
36
37Let's start with the most normal way of getting a certificate. Most
38often, you want or need to get a certificate from a certificate
39authority. To handle that, the certificate authority needs a
40certificate request (or, as some certificate authorities like to put
41it, "certificate signing request", since that's exactly what they do,
42they sign it and give you the result back, thus making it authentic
43according to their policies) from you. To generate a request, use the
44command 'openssl req' like this:
45
46 openssl req -new -key privkey.pem -out cert.csr
47
48Now, cert.csr can be sent to the certificate authority, if they can
49handle files in PEM format. If not, use the extra argument '-outform'
50followed by the keyword for the format to use (see another HOWTO
51<formats.txt?>). In some cases, that isn't sufficient and you will
52have to be more creative.
53
54When the certificate authority has then done the checks the need to
55do (and probably gotten payment from you), they will hand over your
56new certificate to you.
57
58
59[fill in on how to create a self-signed certificate]
60
61
62If you created everything yourself, or if the certificate authority
63was kind enough, your certificate is a raw DER thing in PEM format.
64Your key most definitely is if you have followed the examples above.
65However, some (most?) certificate authorities will encode them with
66things like PKCS7 or PKCS12, or something else. Depending on your
67applications, this may be perfectly OK, it all depends on what they
68know how to decode. If not, There are a number of OpenSSL tools to
69convert between some (most?) formats.
70
71So, depending on your application, you may have to convert your
72certificate and your key to various formats, most often also putting
73them together into one file. The ways to do this is described in
74another HOWTO <formats.txt?>, I will just mention the simplest case.
75In the case of a raw DER thing in PEM format, and assuming that's all
76right for yor applications, simply concatenating the certificate and
77the key into a new file and using that one should be enough. With
78some applications, you don't even have to do that.
79
80
81By now, you have your cetificate and your private key and can start
82using the software that depend on it.
83
84--
85Richard Levitte
diff --git a/src/lib/libssl/src/doc/README b/src/lib/libssl/src/doc/README
new file mode 100644
index 0000000000..a9a588262a
--- /dev/null
+++ b/src/lib/libssl/src/doc/README
@@ -0,0 +1,10 @@
1
2 openssl.pod ..... Documentation of OpenSSL `openssl' command
3 crypto.pod ...... Documentation of OpenSSL crypto.h+libcrypto.a
4 ssl.pod ......... Documentation of OpenSSL ssl.h+libssl.a
5 ssleay.txt ...... Assembled documentation files of ancestor SSLeay [obsolete]
6 openssl.txt ..... Assembled documentation files for OpenSSL [not final]
7
8 An archive of HTML documents for the SSLeay library is available from
9 http://www.columbia.edu/~ariel/ssleay/
10
diff --git a/src/lib/libssl/src/doc/apps/CA.pl.pod b/src/lib/libssl/src/doc/apps/CA.pl.pod
new file mode 100644
index 0000000000..83e4c0af81
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/CA.pl.pod
@@ -0,0 +1,138 @@
1
2=pod
3
4=head1 NAME
5
6CA.pl - friendlier interface for OpenSSL certificate programs
7
8=head1 SYNOPSIS
9
10B<CA.pl>
11[B<-?>]
12[B<-h>]
13[B<-help>]
14[B<-newcert>]
15[B<-newreq>]
16[B<-newca>]
17[B<-xsign>]
18[B<-sign>]
19[B<-signreq>]
20[B<-signcert>]
21[B<-verify>]
22[B<files>]
23
24=head1 DESCRIPTION
25
26The B<CA.pl> script is a perl script that supplies the relevant command line
27arguments to the B<openssl> command for some common certificate operations.
28It is intended to simplify the process of certificate creation and management
29by the use of some simple options.
30
31=head1 COMMAND OPTIONS
32
33=over 4
34
35=item B<?>, B<-h>, B<-help>
36
37prints a usage message.
38
39=item B<-newcert>
40
41creates a new self signed certificate. The private key and certificate are
42written to the file "newreq.pem".
43
44=item B<-newreq>
45
46creates a new certificate request. The private key and request are
47written to the file "newreq.pem".
48
49=item B<-newca>
50
51creates a new CA hierarchy for use with the B<ca> program (or the B<-signcert>
52and B<-xsign> options). The user is prompted to enter the filename of the CA
53certificates (which should also contain the private key) or by hitting ENTER
54details of the CA will be prompted for. The relevant files and directories
55are created in a directory called "demoCA" in the current directory.
56
57=item B<-pkcs12>
58
59create a PKCS#12 file containing the user certificate, private key and CA
60certificate. It expects the user certificate and private key to be in the
61file "newcert.pem" and the CA certificate to be in the file demoCA/cacert.pem,
62it creates a file "newcert.p12". This command can thus be called after the
63B<-sign> option. The PKCS#12 file can be imported directly into a browser.
64If there is an additional argument on the command line it will be used as the
65"friendly name" for the certificate (which is typically displayed in the browser
66list box), otherwise the name "My Certificate" is used.
67
68=item B<-sign>, B<-signreq>, B<-xsign>
69
70calls the B<ca> program to sign a certificate request. It expects the request
71to be in the file "newreq.pem". The new certificate is written to the file
72"newcert.pem" except in the case of the B<-xcert> option when it is written
73to standard output.
74
75=item B<-signcert>
76
77this option is the same as B<-sign> except it expects a self signed certificate
78to be present in the file "newreq.pem".
79
80=item B<-verify>
81
82verifies certificates against the CA certificate for "demoCA". If no certificates
83are specified on the command line it tries to verify the file "newcert.pem".
84
85=item B<files>
86
87one or more optional certificate file names for use with the B<-verify> command.
88
89=back
90
91=head1 EXAMPLES
92
93Create a CA hierarchy:
94
95 CA.pl -newca
96
97Complete certificate creation example: create a CA, create a request, sign
98the request and finally create a PKCS#12 file containing it.
99
100 CA.pl -newca
101 CA.pl -newreq
102 CA.pl -signreq
103 CA.pl -pkcs12 "My Test Certificate"
104
105=head1 NOTES
106
107Most of the filenames mentioned can be modified by editing the B<CA.pl> script.
108
109If the demoCA directory already exists then the B<-newca> command will not
110overwrite it and will do nothing. This can happen if a previous call using
111the B<-newca> option terminated abnormally. To get the correct behaviour
112delete the demoCA directory if it already exists.
113
114Under some environments it may not be possible to run the B<CA.pl> script
115directly (for example Win32) and the default configuration file location may
116be wrong. In this case the command:
117
118 perl -S CA.pl
119
120can be used and the B<OPENSSL_CONF> environment variable changed to point to
121the correct path of the configuration file "openssl.cnf".
122
123The script is intended as a simple front end for the B<openssl> program for use
124by a beginner. Its behaviour isn't always what is wanted. For more control over the
125behaviour of the certificate commands call the B<openssl> command directly.
126
127=head1 ENVIRONMENT VARIABLES
128
129The variable B<OPENSSL_CONF> if defined allows an alternative configuration
130file location to be specified, it should contain the full path to the
131configuration file, not just its directory.
132
133=head1 SEE ALSO
134
135L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<req(1)|req(1)>, L<pkcs12(1)|pkcs12(1)>,
136L<config(5)|config(5)>
137
138=cut
diff --git a/src/lib/libssl/src/doc/apps/asn1parse.pod b/src/lib/libssl/src/doc/apps/asn1parse.pod
new file mode 100644
index 0000000000..e76e9813ab
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/asn1parse.pod
@@ -0,0 +1,129 @@
1=pod
2
3=head1 NAME
4
5asn1parse - ASN.1 parsing tool
6
7=head1 SYNOPSIS
8
9B<openssl> B<asn1parse>
10[B<-inform PEM|DER>]
11[B<-in filename>]
12[B<-out filename>]
13[B<-noout>]
14[B<-offset number>]
15[B<-length number>]
16[B<-i>]
17[B<-oid filename>]
18[B<-strparse offset>]
19
20=head1 DESCRIPTION
21
22The B<asn1parse> command is a diagnostic utility that can parse ASN.1
23structures. It can also be used to extract data from ASN.1 formatted data.
24
25=head1 OPTIONS
26
27=over 4
28
29=item B<-inform> B<DER|PEM>
30
31the input format. B<DER> is binary format and B<PEM> (the default) is base64
32encoded.
33
34=item B<-in filename>
35
36the input file, default is standard input
37
38=item B<-out filename>
39
40output file to place the DER encoded data into. If this
41option is not present then no data will be output. This is most useful when
42combined with the B<-strparse> option.
43
44=item B<-noout>
45
46don't output the parsed version of the input file.
47
48=item B<-offset number>
49
50starting offset to begin parsing, default is start of file.
51
52=item B<-length number>
53
54number of bytes to parse, default is until end of file.
55
56=item B<-i>
57
58indents the output according to the "depth" of the structures.
59
60=item B<-oid filename>
61
62a file containing additional OBJECT IDENTIFIERs (OIDs). The format of this
63file is described in the NOTES section below.
64
65=item B<-strparse offset>
66
67parse the contents octets of the ASN.1 object starting at B<offset>. This
68option can be used multiple times to "drill down" into a nested structure.
69
70
71=back
72
73=head2 OUTPUT
74
75The output will typically contain lines like this:
76
77 0:d=0 hl=4 l= 681 cons: SEQUENCE
78
79.....
80
81 229:d=3 hl=3 l= 141 prim: BIT STRING
82 373:d=2 hl=3 l= 162 cons: cont [ 3 ]
83 376:d=3 hl=3 l= 159 cons: SEQUENCE
84 379:d=4 hl=2 l= 29 cons: SEQUENCE
85 381:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Key Identifier
86 386:d=5 hl=2 l= 22 prim: OCTET STRING
87 410:d=4 hl=2 l= 112 cons: SEQUENCE
88 412:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Authority Key Identifier
89 417:d=5 hl=2 l= 105 prim: OCTET STRING
90 524:d=4 hl=2 l= 12 cons: SEQUENCE
91
92.....
93
94This example is part of a self signed certificate. Each line starts with the
95offset in decimal. B<d=XX> specifies the current depth. The depth is increased
96within the scope of any SET or SEQUENCE. B<hl=XX> gives the header length
97(tag and length octets) of the current type. B<l=XX> gives the length of
98the contents octets.
99
100The B<-i> option can be used to make the output more readable.
101
102Some knowledge of the ASN.1 structure is needed to interpret the output.
103
104In this example the BIT STRING at offset 229 is the certificate public key.
105The contents octets of this will contain the public key information. This can
106be examined using the option B<-strparse 229> to yield:
107
108 0:d=0 hl=3 l= 137 cons: SEQUENCE
109 3:d=1 hl=3 l= 129 prim: INTEGER :E5D21E1F5C8D208EA7A2166C7FAF9F6BDF2059669C60876DDB70840F1A5AAFA59699FE471F379F1DD6A487E7D5409AB6A88D4A9746E24B91D8CF55DB3521015460C8EDE44EE8A4189F7A7BE77D6CD3A9AF2696F486855CF58BF0EDF2B4068058C7A947F52548DDF7E15E96B385F86422BEA9064A3EE9E1158A56E4A6F47E5897
110 135:d=1 hl=2 l= 3 prim: INTEGER :010001
111
112=head1 NOTES
113
114If an OID is not part of OpenSSL's internal table it will be represented in
115numerical form (for example 1.2.3.4). The file passed to the B<-oid> option
116allows additional OIDs to be included. Each line consists of three columns,
117the first column is the OID in numerical format and should be followed by white
118space. The second column is the "short name" which is a single word followed
119by white space. The final column is the rest of the line and is the
120"long name". B<asn1parse> displays the long name. Example:
121
122C<1.2.3.4 shortName A long name>
123
124=head1 BUGS
125
126There should be options to change the format of input lines. The output of some
127ASN.1 types is not well handled (if at all).
128
129=cut
diff --git a/src/lib/libssl/src/doc/apps/ca.pod b/src/lib/libssl/src/doc/apps/ca.pod
new file mode 100644
index 0000000000..03209aa6b1
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/ca.pod
@@ -0,0 +1,479 @@
1
2=pod
3
4=head1 NAME
5
6ca - sample minimal CA application
7
8=head1 SYNOPSIS
9
10B<openssl> B<ca>
11[B<-verbose>]
12[B<-config filename>]
13[B<-name section>]
14[B<-gencrl>]
15[B<-revoke file>]
16[B<-crldays days>]
17[B<-crlhours hours>]
18[B<-crlexts section>]
19[B<-startdate date>]
20[B<-enddate date>]
21[B<-days arg>]
22[B<-md arg>]
23[B<-policy arg>]
24[B<-keyfile arg>]
25[B<-key arg>]
26[B<-cert file>]
27[B<-in file>]
28[B<-out file>]
29[B<-notext>]
30[B<-outdir dir>]
31[B<-infiles>]
32[B<-spkac file>]
33[B<-ss_cert file>]
34[B<-preserveDN>]
35[B<-batch>]
36[B<-msie_hack>]
37[B<-extensions section>]
38
39=head1 DESCRIPTION
40
41The B<ca> command is a minimal CA application. It can be used
42to sign certificate requests in a variety of forms and generate
43CRLs it also maintains a text database of issued certificates
44and their status.
45
46The options descriptions will be divided into each purpose.
47
48=head1 CA OPTIONS
49
50=over 4
51
52=item B<-config filename>
53
54specifies the configuration file to use.
55
56=item B<-in filename>
57
58an input filename containing a single certificate request to be
59signed by the CA.
60
61=item B<-ss_cert filename>
62
63a single self signed certificate to be signed by the CA.
64
65=item B<-spkac filename>
66
67a file containing a single Netscape signed public key and challenge
68and additional field values to be signed by the CA. See the B<NOTES>
69section for information on the required format.
70
71=item B<-infiles>
72
73if present this should be the last option, all subsequent arguments
74are assumed to the the names of files containing certificate requests.
75
76=item B<-out filename>
77
78the output file to output certificates to. The default is standard
79output. The certificate details will also be printed out to this
80file.
81
82=item B<-outdir directory>
83
84the directory to output certificates to. The certificate will be
85written to a filename consisting of the serial number in hex with
86".pem" appended.
87
88=item B<-cert>
89
90the CA certificate file.
91
92=item B<-keyfile filename>
93
94the private key to sign requests with.
95
96=item B<-key password>
97
98the password used to encrypt the private key. Since on some
99systems the command line arguments are visible (e.g. Unix with
100the 'ps' utility) this option should be used with caution.
101
102=item B<-verbose>
103
104this prints extra details about the operations being performed.
105
106=item B<-notext>
107
108don't output the text form of a certificate to the output file.
109
110=item B<-startdate date>
111
112this allows the start date to be explicitly set. The format of the
113date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
114
115=item B<-enddate date>
116
117this allows the expiry date to be explicitly set. The format of the
118date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
119
120=item B<-days arg>
121
122the number of days to certify the certificate for.
123
124=item B<-md alg>
125
126the message digest to use. Possible values include md5, sha1 and mdc2.
127This option also applies to CRLs.
128
129=item B<-policy arg>
130
131this option defines the CA "policy" to use. This is a section in
132the configuration file which decides which fields should be mandatory
133or match the CA certificate. Check out the B<POLICY FORMAT> section
134for more information.
135
136=item B<-msie_hack>
137
138this is a legacy option to make B<ca> work with very old versions of
139the IE certificate enrollment control "certenr3". It used UniversalStrings
140for almost everything. Since the old control has various security bugs
141its use is strongly discouraged. The newer control "Xenroll" does not
142need this option.
143
144=item B<-preserveDN>
145
146Normally the DN order of a certificate is the same as the order of the
147fields in the relevant policy section. When this option is set the order
148is the same as the request. This is largely for compatibility with the
149older IE enrollment control which would only accept certificates if their
150DNs match the order of the request. This is not needed for Xenroll.
151
152=item B<-batch>
153
154this sets the batch mode. In this mode no questions will be asked
155and all certificates will be certified automatically.
156
157=item B<-extensions section>
158
159the section of the configuration file containing certificate extensions
160to be added when a certificate is issued. If no extension section is
161present then a V1 certificate is created. If the extension section
162is present (even if it is empty) then a V3 certificate is created.
163
164=back
165
166=head1 CRL OPTIONS
167
168=over 4
169
170=item B<-gencrl>
171
172this option generates a CRL based on information in the index file.
173
174=item B<-crldays num>
175
176the number of days before the next CRL is due. That is the days from
177now to place in the CRL nextUpdate field.
178
179=item B<-crlhours num>
180
181the number of hours before the next CRL is due.
182
183=item B<-revoke filename>
184
185a filename containing a certificate to revoke.
186
187=item B<-crlexts section>
188
189the section of the configuration file containing CRL extensions to
190include. If no CRL extension section is present then a V1 CRL is
191created, if the CRL extension section is present (even if it is
192empty) then a V2 CRL is created. The CRL extensions specified are
193CRL extensions and B<not> CRL entry extensions. It should be noted
194that some software (for example Netscape) can't handle V2 CRLs.
195
196=back
197
198=head1 CONFIGURATION FILE OPTIONS
199
200The options for B<ca> are contained in the B<ca> section of the
201configuration file. Many of these are identical to command line
202options. Where the option is present in the configuration file
203and the command line the command line value is used. Where an
204option is described as mandatory then it must be present in
205the configuration file or the command line equivalent (if
206any) used.
207
208=over 4
209
210=item B<oid_file>
211
212This specifies a file containing additional B<OBJECT IDENTIFIERS>.
213Each line of the file should consist of the numerical form of the
214object identifier followed by white space then the short name followed
215by white space and finally the long name.
216
217=item B<oid_section>
218
219This specifies a section in the configuration file containing extra
220object identifiers. Each line should consist of the short name of the
221object identifier followed by B<=> and the numerical form. The short
222and long names are the same when this option is used.
223
224=item B<new_certs_dir>
225
226the same as the B<-outdir> command line option. It specifies
227the directory where new certificates will be placed. Mandatory.
228
229=item B<certificate>
230
231the same as B<-cert>. It gives the file containing the CA
232certificate. Mandatory.
233
234=item B<private_key>
235
236same as the B<-keyfile> option. The file containing the
237CA private key. Mandatory.
238
239=item B<RANDFILE>
240
241a file used to read and write random number seed information, or
242an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
243
244=item B<default_days>
245
246the same as the B<-days> option. The number of days to certify
247a certificate for.
248
249=item B<default_startdate>
250
251the same as the B<-startdate> option. The start date to certify
252a certificate for. If not set the current time is used.
253
254=item B<default_enddate>
255
256the same as the B<-enddate> option. Either this option or
257B<default_days> (or the command line equivalents) must be
258present.
259
260=item B<default_crl_hours default_crl_days>
261
262the same as the B<-crlhours> and the B<-crldays> options. These
263will only be used if neither command line option is present. At
264least one of these must be present to generate a CRL.
265
266=item B<default_md>
267
268the same as the B<-md> option. The message digest to use. Mandatory.
269
270=item B<database>
271
272the text database file to use. Mandatory. This file must be present
273though initially it will be empty.
274
275=item B<serialfile>
276
277a text file containing the next serial number to use in hex. Mandatory.
278This file must be present and contain a valid serial number.
279
280=item B<x509_extensions>
281
282the same as B<-extensions>.
283
284=item B<crl_extensions>
285
286the same as B<-crlexts>.
287
288=item B<preserve>
289
290the same as B<-preserveDN>
291
292=item B<msie_hack>
293
294the same as B<-msie_hack>
295
296=item B<policy>
297
298the same as B<-policy>. Mandatory. See the B<POLICY FORMAT> section
299for more information.
300
301=back
302
303=head1 POLICY FORMAT
304
305The policy section consists of a set of variables corresponding to
306certificate DN fields. If the value is "match" then the field value
307must match the same field in the CA certificate. If the value is
308"supplied" then it must be present. If the value is "optional" then
309it may be present. Any fields not mentioned in the policy section
310are silently deleted, unless the B<-preserveDN> option is set but
311this can be regarded more of a quirk than intended behaviour.
312
313=head1 SPKAC FORMAT
314
315The input to the B<-spkac> command line option is a Netscape
316signed public key and challenge. This will usually come from
317the B<KEYGEN> tag in an HTML form to create a new private key.
318It is however possible to create SPKACs using the B<spkac> utility.
319
320The file should contain the variable SPKAC set to the value of
321the SPKAC and also the required DN components as name value pairs.
322If you need to include the same component twice then it can be
323preceded by a number and a '.'.
324
325=head1 EXAMPLES
326
327Note: these examples assume that the B<ca> directory structure is
328already set up and the relevant files already exist. This usually
329involves creating a CA certificate and private key with B<req>, a
330serial number file and an empty index file and placing them in
331the relevant directories.
332
333To use the sample configuration file below the directories demoCA,
334demoCA/private and demoCA/newcerts would be created. The CA
335certificate would be copied to demoCA/cacert.pem and its private
336key to demoCA/private/cakey.pem. A file demoCA/serial would be
337created containing for example "01" and the empty index file
338demoCA/index.txt.
339
340
341Sign a certificate request:
342
343 openssl ca -in req.pem -out newcert.pem
344
345Generate a CRL
346
347 openssl ca -gencrl -out crl.pem
348
349Sign several requests:
350
351 openssl ca -infiles req1.pem req2.pem req3.pem
352
353Certify a Netscape SPKAC:
354
355 openssl ca -spkac spkac.txt
356
357A sample SPKAC file (the SPKAC line has been truncated for clarity):
358
359 SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK2A5
360 CN=Steve Test
361 emailAddress=steve@openssl.org
362 0.OU=OpenSSL Group
363 1.OU=Another Group
364
365A sample configuration file with the relevant sections for B<ca>:
366
367 [ ca ]
368 default_ca = CA_default # The default ca section
369
370 [ CA_default ]
371
372 dir = ./demoCA # top dir
373 database = $dir/index.txt # index file.
374 new_certs_dir = $dir/newcerts # new certs dir
375
376 certificate = $dir/cacert.pem # The CA cert
377 serial = $dir/serial # serial no file
378 private_key = $dir/private/cakey.pem# CA private key
379 RANDFILE = $dir/private/.rand # random number file
380
381 default_days = 365 # how long to certify for
382 default_crl_days= 30 # how long before next CRL
383 default_md = md5 # md to use
384
385 policy = policy_any # default policy
386
387 [ policy_any ]
388 countryName = supplied
389 stateOrProvinceName = optional
390 organizationName = optional
391 organizationalUnitName = optional
392 commonName = supplied
393 emailAddress = optional
394
395=head1 WARNINGS
396
397The B<ca> command is quirky and at times downright unfriendly.
398
399The B<ca> utility was originally meant as an example of how to do things
400in a CA. It was not supposed be be used as a full blown CA itself:
401nevertheless some people are using it for this purpose.
402
403The B<ca> command is effectively a single user command: no locking is
404done on the various files and attempts to run more than one B<ca> command
405on the same database can have unpredictable results.
406
407=head1 FILES
408
409Note: the location of all files can change either by compile time options,
410configuration file entries, environment variables or command line options.
411The values below reflect the default values.
412
413 /usr/local/ssl/lib/openssl.cnf - master configuration file
414 ./demoCA - main CA directory
415 ./demoCA/cacert.pem - CA certificate
416 ./demoCA/private/cakey.pem - CA private key
417 ./demoCA/serial - CA serial number file
418 ./demoCA/serial.old - CA serial number backup file
419 ./demoCA/index.txt - CA text database file
420 ./demoCA/index.txt.old - CA text database backup file
421 ./demoCA/certs - certificate output file
422 ./demoCA/.rnd - CA random seed information
423
424=head1 ENVIRONMENT VARIABLES
425
426B<OPENSSL_CONF> reflects the location of master configuration file it can
427be overridden by the B<-config> command line option.
428
429=head1 RESTRICTIONS
430
431The text database index file is a critical part of the process and
432if corrupted it can be difficult to fix. It is theoretically possible
433to rebuild the index file from all the issued certificates and a current
434CRL: however there is no option to do this.
435
436CRL entry extensions cannot currently be created: only CRL extensions
437can be added.
438
439V2 CRL features like delta CRL support and CRL numbers are not currently
440supported.
441
442Although several requests can be input and handled at once it is only
443possible to include one SPKAC or self signed certificate.
444
445=head1 BUGS
446
447The use of an in memory text database can cause problems when large
448numbers of certificates are present because, as the name implies
449the database has to be kept in memory.
450
451Certificate request extensions are ignored: some kind of "policy" should
452be included to use certain static extensions and certain extensions
453from the request.
454
455It is not possible to certify two certificates with the same DN: this
456is a side effect of how the text database is indexed and it cannot easily
457be fixed without introducing other problems. Some S/MIME clients can use
458two certificates with the same DN for separate signing and encryption
459keys.
460
461The B<ca> command really needs rewriting or the required functionality
462exposed at either a command or interface level so a more friendly utility
463(perl script or GUI) can handle things properly. The scripts B<CA.sh> and
464B<CA.pl> help a little but not very much.
465
466Any fields in a request that are not present in a policy are silently
467deleted. This does not happen if the B<-preserveDN> option is used but
468the extra fields are not displayed when the user is asked to certify
469a request. The behaviour should be more friendly and configurable.
470
471Cancelling some commands by refusing to certify a certificate can
472create an empty file.
473
474=head1 SEE ALSO
475
476L<req(1)|req(1)>, L<spkac(1)|spkac(1)>, L<x509(1)|x509(1)>, L<CA.pl(1)|CA.pl(1)>,
477L<config(5)|config(5)>
478
479=cut
diff --git a/src/lib/libssl/src/doc/apps/ciphers.pod b/src/lib/libssl/src/doc/apps/ciphers.pod
new file mode 100644
index 0000000000..2301e28251
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/ciphers.pod
@@ -0,0 +1,342 @@
1=pod
2
3=head1 NAME
4
5ciphers - SSL cipher display and cipher list tool.
6
7=head1 SYNOPSIS
8
9B<openssl> B<ciphers>
10[B<-v>]
11[B<-ssl2>]
12[B<-ssl3>]
13[B<-tls1>]
14[B<cipherlist>]
15
16=head1 DESCRIPTION
17
18The B<cipherlist> command converts OpenSSL cipher lists into ordered
19SSL cipher preference lists. It can be used as a test tool to determine
20the appropriate cipherlist.
21
22=head1 COMMAND OPTIONS
23
24=over 4
25
26=item B<-v>
27
28verbose option. List ciphers with a complete description of the authentication,
29key exchange, encryption and mac algorithms used along with any key size
30restrictions and whether the algorithm is classed as an "export" cipher.
31
32=item B<-ssl3>
33
34only include SSL v3 ciphers.
35
36=item B<-ssl2>
37
38only include SSL v2 ciphers.
39
40=item B<-tls1>
41
42only include TLS v1 ciphers.
43
44=item B<-h>, B<-?>
45
46print a brief usage message.
47
48=item B<cipherlist>
49
50a cipher list to convert to a cipher preference list. If it is not included
51then the default cipher list will be used. The format is described below.
52
53=back
54
55=head1 CIPHER LIST FORMAT
56
57The cipher list consists of one or more I<cipher strings> separated by colons.
58Commas or spaces are also acceptable separators but colons are normally used.
59
60The actual cipher string can take several different forms.
61
62It can consist of a single cipher suite such as B<RC4-SHA>.
63
64It can represent a list of cipher suites containing a certain algorithm, or
65cipher suites of a certain type. For example B<SHA1> represents all ciphers
66suites using the digest algorithm SHA1 and B<SSLv3> represents all SSL v3
67algorithms.
68
69Lists of cipher suites can be combined in a single cipher string using the
70B<+> character. This is used as a logical B<and> operation. For example
71B<SHA1+DES> represents all cipher suites containing the SHA1 B<and> the DES
72algorithms.
73
74Each cipher string can be optionally preceded by the characters B<!>,
75B<-> or B<+>.
76
77If B<!> is used then the ciphers are permanently deleted from the list.
78The ciphers deleted can never reappear in the list even if they are
79explicitly stated.
80
81If B<-> is used then the ciphers are deleted from the list, but some or
82all of the ciphers can be added again by later options.
83
84If B<+> is used then the ciphers are moved to the end of the list. This
85option doesn't add any new ciphers it just moves matching existing ones.
86
87If none of these characters is present then the string is just interpreted
88as a list of ciphers to be appended to the current preference list. If the
89list includes any ciphers already present they will be ignored: that is they
90will not moved to the end of the list.
91
92Additionally the cipher string B<@STRENGTH> can be used at any point to sort
93the current cipher list in order of encryption algorithm key length.
94
95=head1 CIPHER STRINGS
96
97The following is a list of all permitted cipher strings and their meanings.
98
99=over 4
100
101=item B<DEFAULT>
102
103the default cipher list. This is determined at compile time and is normally
104B<ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH>. This must be the first cipher string
105specified.
106
107=item B<ALL>
108
109all ciphers suites except the B<eNULL> ciphers which must be explicitly enabled.
110
111=item B<HIGH>
112
113"high" encryption cipher suites. This currently means those with key lengths larger
114than 128 bits.
115
116=item B<MEDIUM>
117
118"medium" encryption cipher suites, currently those using 128 bit encryption.
119
120=item B<LOW>
121
122"low" encryption cipher suites, currently those using 64 or 56 bit encryption algorithms
123but excluding export cipher suites.
124
125=item B<EXP>, B<EXPORT>
126
127export encryption algorithms. Including 40 and 56 bits algorithms.
128
129=item B<EXPORT40>
130
13140 bit export encryption algorithms
132
133=item B<EXPORT56>
134
13556 bit export encryption algorithms.
136
137=item B<eNULL>, B<NULL>
138
139the "NULL" ciphers that is those offering no encryption. Because these offer no
140encryption at all and are a security risk they are disabled unless explicitly
141included.
142
143=item B<aNULL>
144
145the cipher suites offering no authentication. This is currently the anonymous
146DH algorithms. These cipher suites are vulnerable to a "man in the middle"
147attack and so their use is normally discouraged.
148
149=item B<kRSA>, B<RSA>
150
151cipher suites using RSA key exchange.
152
153=item B<kEDH>
154
155cipher suites using ephemeral DH key agreement.
156
157=item B<kDHr>, B<kDHd>
158
159cipher suites using DH key agreement and DH certificates signed by CAs with RSA
160and DSS keys respectively. Not implemented.
161
162=item B<aRSA>
163
164cipher suites using RSA authentication, i.e. the certificates carry RSA keys.
165
166=item B<aDSS>, B<DSS>
167
168cipher suites using DSS authentication, i.e. the certificates carry DSS keys.
169
170=item B<aDH>
171
172cipher suites effectively using DH authentication, i.e. the certificates carry
173DH keys. Not implemented.
174
175=item B<kFZA>, B<aFZA>, B<eFZA>, B<FZA>
176
177ciphers suites using FORTEZZA key exchange, authentication, encryption or all
178FORTEZZA algorithms. Not implemented.
179
180=item B<TLSv1>, B<SSLv3>, B<SSLv2>
181
182TLS v1.0, SSL v3.0 or SSL v2.0 cipher suites respectively.
183
184=item B<DH>
185
186cipher suites using DH, including anonymous DH.
187
188=item B<ADH>
189
190anonymous DH cipher suites.
191
192=item B<3DES>
193
194cipher suites using triple DES.
195
196=item B<DES>
197
198cipher suites using DES (not triple DES).
199
200=item B<RC4>
201
202cipher suites using RC4.
203
204=item B<RC2>
205
206cipher suites using RC2.
207
208=item B<IDEA>
209
210cipher suites using IDEA.
211
212=item B<MD5>
213
214cipher suites using MD5.
215
216=item B<SHA1>, B<SHA>
217
218cipher suites using SHA1.
219
220=back
221
222=head1 CIPHER SUITE NAMES
223
224The following lists give the SSL or TLS cipher suites names from the
225relevant specification and their OpenSSL equivalents.
226
227=head2 SSL v3.0 cipher suites.
228
229 SSL_RSA_WITH_NULL_MD5 NULL-MD5
230 SSL_RSA_WITH_NULL_SHA NULL-SHA
231 SSL_RSA_EXPORT_WITH_RC4_40_MD5 EXP-RC4-MD5
232 SSL_RSA_WITH_RC4_128_MD5 RC4-MD5
233 SSL_RSA_WITH_RC4_128_SHA RC4-SHA
234 SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5 EXP-RC2-CBC-MD5
235 SSL_RSA_WITH_IDEA_CBC_SHA IDEA-CBC-SHA
236 SSL_RSA_EXPORT_WITH_DES40_CBC_SHA EXP-DES-CBC-SHA
237 SSL_RSA_WITH_DES_CBC_SHA DES-CBC-SHA
238 SSL_RSA_WITH_3DES_EDE_CBC_SHA DES-CBC3-SHA
239
240 SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA Not implemented.
241 SSL_DH_DSS_WITH_DES_CBC_SHA Not implemented.
242 SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA Not implemented.
243 SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA Not implemented.
244 SSL_DH_RSA_WITH_DES_CBC_SHA Not implemented.
245 SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA Not implemented.
246 SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA EXP-EDH-DSS-DES-CBC-SHA
247 SSL_DHE_DSS_WITH_DES_CBC_SHA EDH-DSS-CBC-SHA
248 SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA EDH-DSS-DES-CBC3-SHA
249 SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA EXP-EDH-RSA-DES-CBC-SHA
250 SSL_DHE_RSA_WITH_DES_CBC_SHA EDH-RSA-DES-CBC-SHA
251 SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA EDH-RSA-DES-CBC3-SHA
252
253 SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 EXP-ADH-RC4-MD5
254 SSL_DH_anon_WITH_RC4_128_MD5 ADH-RC4-MD5
255 SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA EXP-ADH-DES-CBC-SHA
256 SSL_DH_anon_WITH_DES_CBC_SHA ADH-DES-CBC-SHA
257 SSL_DH_anon_WITH_3DES_EDE_CBC_SHA ADH-DES-CBC3-SHA
258
259 SSL_FORTEZZA_KEA_WITH_NULL_SHA Not implemented.
260 SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA Not implemented.
261 SSL_FORTEZZA_KEA_WITH_RC4_128_SHA Not implemented.
262
263=head2 TLS v1.0 cipher suites.
264
265 TLS_RSA_WITH_NULL_MD5 NULL-MD5
266 TLS_RSA_WITH_NULL_SHA NULL-SHA
267 TLS_RSA_EXPORT_WITH_RC4_40_MD5 EXP-RC4-MD5
268 TLS_RSA_WITH_RC4_128_MD5 RC4-MD5
269 TLS_RSA_WITH_RC4_128_SHA RC4-SHA
270 TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 EXP-RC2-CBC-MD5
271 TLS_RSA_WITH_IDEA_CBC_SHA IDEA-CBC-SHA
272 TLS_RSA_EXPORT_WITH_DES40_CBC_SHA EXP-DES-CBC-SHA
273 TLS_RSA_WITH_DES_CBC_SHA DES-CBC-SHA
274 TLS_RSA_WITH_3DES_EDE_CBC_SHA DES-CBC3-SHA
275
276 TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA Not implemented.
277 TLS_DH_DSS_WITH_DES_CBC_SHA Not implemented.
278 TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA Not implemented.
279 TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA Not implemented.
280 TLS_DH_RSA_WITH_DES_CBC_SHA Not implemented.
281 TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA Not implemented.
282 TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA EXP-EDH-DSS-DES-CBC-SHA
283 TLS_DHE_DSS_WITH_DES_CBC_SHA EDH-DSS-CBC-SHA
284 TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA EDH-DSS-DES-CBC3-SHA
285 TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA EXP-EDH-RSA-DES-CBC-SHA
286 TLS_DHE_RSA_WITH_DES_CBC_SHA EDH-RSA-DES-CBC-SHA
287 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA EDH-RSA-DES-CBC3-SHA
288
289 TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 EXP-ADH-RC4-MD5
290 TLS_DH_anon_WITH_RC4_128_MD5 ADH-RC4-MD5
291 TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA EXP-ADH-DES-CBC-SHA
292 TLS_DH_anon_WITH_DES_CBC_SHA ADH-DES-CBC-SHA
293 TLS_DH_anon_WITH_3DES_EDE_CBC_SHA ADH-DES-CBC3-SHA
294
295=head2 Additional Export 1024 and other cipher suites
296
297Note: these ciphers can also be used in SSL v3.
298
299 TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA EXP1024-DES-CBC-SHA
300 TLS_RSA_EXPORT1024_WITH_RC4_56_SHA EXP1024-RC4-SHA
301 TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA EXP1024-DHE-DSS-DES-CBC-SHA
302 TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA EXP1024-DHE-DSS-RC4-SHA
303 TLS_DHE_DSS_WITH_RC4_128_SHA DHE-DSS-RC4-SHA
304
305=head2 SSL v2.0 cipher suites.
306
307 SSL_CK_RC4_128_WITH_MD5 RC4-MD5
308 SSL_CK_RC4_128_EXPORT40_WITH_MD5 EXP-RC4-MD5
309 SSL_CK_RC2_128_CBC_WITH_MD5 RC2-MD5
310 SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5 EXP-RC2-MD5
311 SSL_CK_IDEA_128_CBC_WITH_MD5 IDEA-CBC-MD5
312 SSL_CK_DES_64_CBC_WITH_MD5 DES-CBC-MD5
313 SSL_CK_DES_192_EDE3_CBC_WITH_MD5 DES-CBC3-MD5
314
315=head1 NOTES
316
317The non-ephemeral DH modes are currently unimplemented in OpenSSL
318because there is no support for DH certificates.
319
320Some compiled versions of OpenSSL may not include all the ciphers
321listed here because some ciphers were excluded at compile time.
322
323=head1 EXAMPLES
324
325Verbose listing of all OpenSSL ciphers including NULL ciphers:
326
327 openssl ciphers -v 'ALL:eNULL'
328
329Include all ciphers except NULL and anonymous DH then sort by
330strength:
331
332 openssl ciphers -v 'ALL:!ADH:@STRENGTH'
333
334Include only 3DES ciphers and then place RSA ciphers last:
335
336 openssl ciphers -v '3DES:+RSA'
337
338=head1 SEE ALSO
339
340L<s_client(1)|s_client(1)>, L<s_server(1)|s_server(1)>, L<ssl(3)|ssl(3)>
341
342=cut
diff --git a/src/lib/libssl/src/doc/apps/config.pod b/src/lib/libssl/src/doc/apps/config.pod
new file mode 100644
index 0000000000..ce874a42ce
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/config.pod
@@ -0,0 +1,138 @@
1
2=pod
3
4=head1 NAME
5
6config - OpenSSL CONF library configuration files
7
8=head1 DESCRIPTION
9
10The OpenSSL CONF library can be used to read configuration files.
11It is used for the OpenSSL master configuration file B<openssl.cnf>
12and in a few other places like B<SPKAC> files and certificate extension
13files for the B<x509> utility.
14
15A configuration file is divided into a number of sections. Each section
16starts with a line B<[ section_name ]> and ends when a new section is
17started or end of file is reached. A section name can consist of
18alphanumeric characters and underscores.
19
20The first section of a configuration file is special and is referred
21to as the B<default> section this is usually unnamed and is from the
22start of file until the first named section. When a name is being looked up
23it is first looked up in a named section (if any) and then the
24default section.
25
26The environment is mapped onto a section called B<ENV>.
27
28Comments can be included by preceding them with the B<#> character
29
30Each section in a configuration file consists of a number of name and
31value pairs of the form B<name=value>
32
33The B<name> string can contain any alphanumeric characters as well as
34a few punctuation symbols such as B<.> B<,> B<;> and B<_>.
35
36The B<value> string consists of the string following the B<=> character
37until end of line with any leading and trailing white space removed.
38
39The value string undergoes variable expansion. This can be done by
40including the form B<$var> or B<${var}>: this will substitute the value
41of the named variable in the current section. It is also possible to
42substitute a value from another section using the syntax B<$section::name>
43or B<${section::name}>. By using the form B<$ENV::name> environment
44variables can be substituted. It is also possible to assign values to
45environment variables by using the name B<ENV::name>, this will work
46if the program looks up environment variables using the B<CONF> library
47instead of calling B<getenv()> directly.
48
49It is possible to escape certain characters by using any kind of quote
50or the B<\> character. By making the last character of a line a B<\>
51a B<value> string can be spread across multiple lines. In addition
52the sequences B<\n>, B<\r>, B<\b> and B<\t> are recognized.
53
54=head1 NOTES
55
56If a configuration file attempts to expand a variable that doesn't exist
57then an error is flagged and the file will not load. This can happen
58if an attempt is made to expand an environment variable that doesn't
59exist. For example the default OpenSSL master configuration file used
60the value of B<HOME> which may not be defined on non Unix systems.
61
62This can be worked around by including a B<default> section to provide
63a default value: then if the environment lookup fails the default value
64will be used instead. For this to work properly the default value must
65be defined earlier in the configuration file than the expansion. See
66the B<EXAMPLES> section for an example of how to do this.
67
68If the same variable exists in the same section then all but the last
69value will be silently ignored. In certain circumstances such as with
70DNs the same field may occur multiple times. This is usually worked
71around by ignoring any characters before an initial B<.> e.g.
72
73 1.OU="My first OU"
74 2.OU="My Second OU"
75
76=head1 EXAMPLES
77
78Here is a sample configuration file using some of the features
79mentioned above.
80
81 # This is the default section.
82
83 HOME=/temp
84 RANDFILE= ${ENV::HOME}/.rnd
85 configdir=$ENV::HOME/config
86
87 [ section_one ]
88
89 # We are now in section one.
90
91 # Quotes permit leading and trailing whitespace
92 any = " any variable name "
93
94 other = A string that can \
95 cover several lines \
96 by including \\ characters
97
98 message = Hello World\n
99
100 [ section_two ]
101
102 greeting = $section_one::message
103
104This next example shows how to expand environment variables safely.
105
106Suppose you want a variable called B<tmpfile> to refer to a
107temporary filename. The directory it is placed in can determined by
108the the B<TEMP> or B<TMP> environment variables but they may not be
109set to any value at all. If you just include the environment variable
110names and the variable doesn't exist then this will cause an error when
111an attempt is made to load the configuration file. By making use of the
112default section both values can be looked up with B<TEMP> taking
113priority and B</tmp> used if neither is defined:
114
115 TMP=/tmp
116 # The above value is used if TMP isn't in the environment
117 TEMP=$ENV::TMP
118 # The above value is used if TEMP isn't in the environment
119 tmpfile=${ENV::TEMP}/tmp.filename
120
121=head1 BUGS
122
123Currently there is no way to include characters using the octal B<\nnn>
124form. Strings are all null terminated so nulls cannot form part of
125the value.
126
127The escaping isn't quite right: if you want to use sequences like B<\n>
128you can't use any quote escaping on the same line.
129
130Files are loaded in a single pass. This means that an variable expansion
131will only work if the variables referenced are defined earlier in the
132file.
133
134=head1 SEE ALSO
135
136L<x509(1)|x509(1)>, L<req(1)|req(1)>, L<ca(1)|ca(1)>
137
138=cut
diff --git a/src/lib/libssl/src/doc/apps/crl.pod b/src/lib/libssl/src/doc/apps/crl.pod
new file mode 100644
index 0000000000..a40c873b95
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/crl.pod
@@ -0,0 +1,117 @@
1=pod
2
3=head1 NAME
4
5crl - CRL utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<crl>
10[B<-inform PEM|DER>]
11[B<-outform PEM|DER>]
12[B<-text>]
13[B<-in filename>]
14[B<-out filename>]
15[B<-noout>]
16[B<-hash>]
17[B<-issuer>]
18[B<-lastupdate>]
19[B<-nextupdate>]
20[B<-CAfile file>]
21[B<-CApath dir>]
22
23=head1 DESCRIPTION
24
25The B<crl> command processes CRL files in DER or PEM format.
26
27=head1 COMMAND OPTIONS
28
29=over 4
30
31=item B<-inform DER|PEM>
32
33This specifies the input format. B<DER> format is DER encoded CRL
34structure. B<PEM> (the default) is a base64 encoded version of
35the DER form with header and footer lines.
36
37=item B<-outform DER|PEM>
38
39This specifies the output format, the options have the same meaning as the
40B<-inform> option.
41
42=item B<-in filename>
43
44This specifies the input filename to read from or standard input if this
45option is not specified.
46
47=item B<-out filename>
48
49specifies the output filename to write to or standard output by
50default.
51
52=item B<-text>
53
54print out the CRL in text form.
55
56=item B<-noout>
57
58don't output the encoded version of the CRL.
59
60=item B<-hash>
61
62output a hash of the issuer name. This can be use to lookup CRLs in
63a directory by issuer name.
64
65=item B<-issuer>
66
67output the issuer name.
68
69=item B<-lastupdate>
70
71output the lastUpdate field.
72
73=item B<-nextupdate>
74
75output the nextUpdate field.
76
77=item B<-CAfile file>
78
79verify the signature on a CRL by looking up the issuing certificate in
80B<file>
81
82=item B<-CApath dir>
83
84verify the signature on a CRL by looking up the issuing certificate in
85B<dir>. This directory must be a standard certificate directory: that
86is a hash of each subject name (using B<x509 -hash>) should be linked
87to each certificate.
88
89=back
90
91=head1 NOTES
92
93The PEM CRL format uses the header and footer lines:
94
95 -----BEGIN X509 CRL-----
96 -----END X509 CRL-----
97
98=head1 EXAMPLES
99
100Convert a CRL file from PEM to DER:
101
102 openssl crl -in crl.pem -outform DER -out crl.der
103
104Output the text form of a DER encoded certificate:
105
106 openssl crl -in crl.der -text -noout
107
108=head1 BUGS
109
110Ideally it should be possible to create a CRL using appropriate options
111and files too.
112
113=head1 SEE ALSO
114
115L<crl2pkcs7(1)|crl2pkcs7(1)>, L<ca(1)|ca(1)>, L<x509(1)|x509(1)>
116
117=cut
diff --git a/src/lib/libssl/src/doc/apps/crl2pkcs7.pod b/src/lib/libssl/src/doc/apps/crl2pkcs7.pod
new file mode 100644
index 0000000000..da199b044a
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/crl2pkcs7.pod
@@ -0,0 +1,90 @@
1=pod
2
3=head1 NAME
4
5crl2pkcs7 - Create a PKCS#7 structure from a CRL and certificates.
6
7=head1 SYNOPSIS
8
9B<openssl> B<pkcs7>
10[B<-inform PEM|DER>]
11[B<-outform PEM|DER>]
12[B<-in filename>]
13[B<-out filename>]
14[B<-print_certs>]
15
16=head1 DESCRIPTION
17
18The B<crl2pkcs7> command takes an optional CRL and one or more
19certificates and converts them into a PKCS#7 degenerate "certificates
20only" structure.
21
22=head1 COMMAND OPTIONS
23
24=over 4
25
26=item B<-inform DER|PEM>
27
28This specifies the CRL input format. B<DER> format is DER encoded CRL
29structure.B<PEM> (the default) is a base64 encoded version of
30the DER form with header and footer lines.
31
32=item B<-outform DER|PEM>
33
34This specifies the PKCS#7 structure output format. B<DER> format is DER
35encoded PKCS#7 structure.B<PEM> (the default) is a base64 encoded version of
36the DER form with header and footer lines.
37
38=item B<-in filename>
39
40This specifies the input filename to read a CRL from or standard input if this
41option is not specified.
42
43=item B<-out filename>
44
45specifies the output filename to write the PKCS#7 structure to or standard
46output by default.
47
48=item B<-certfile filename>
49
50specifies a filename containing one or more certificates in B<PEM> format.
51All certificates in the file will be added to the PKCS#7 structure. This
52option can be used more than once to read certificates form multiple
53files.
54
55=item B<-nocrl>
56
57normally a CRL is included in the output file. With this option no CRL is
58included in the output file and a CRL is not read from the input file.
59
60=back
61
62=head1 EXAMPLES
63
64Create a PKCS#7 structure from a certificate and CRL:
65
66 openssl crl2pkcs7 -in crl.pem -certfile cert.pem -out p7.pem
67
68Creates a PKCS#7 structure in DER format with no CRL from several
69different certificates:
70
71 openssl crl2pkcs7 -nocrl -certfile newcert.pem
72 -certfile demoCA/cacert.pem -outform DER -out p7.der
73
74=head1 NOTES
75
76The output file is a PKCS#7 signed data structure containing no signers and
77just certificates and an optional CRL.
78
79This utility can be used to send certificates and CAs to Netscape as part of
80the certificate enrollment process. This involves sending the DER encoded output
81as MIME type application/x-x509-user-cert.
82
83The B<PEM> encoded form with the header and footer lines removed can be used to
84install user certificates and CAs in MSIE using the Xenroll control.
85
86=head1 SEE ALSO
87
88L<pkcs7(1)|pkcs7(1)>
89
90=cut
diff --git a/src/lib/libssl/src/doc/apps/dgst.pod b/src/lib/libssl/src/doc/apps/dgst.pod
new file mode 100644
index 0000000000..cbf2cc529a
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/dgst.pod
@@ -0,0 +1,49 @@
1=pod
2
3=head1 NAME
4
5dgst, md5, md2, sha1, sha, mdc2, ripemd160 - message digests
6
7=head1 SYNOPSIS
8
9[B<dgst>]
10[B<-md5|-md2|-sha1|-sha|mdc2|-ripemd160>]
11[B<-c>]
12[B<-d>]
13[B<file...>]
14
15[B<md5|md2|sha1|sha|mdc2|ripemd160>]
16[B<-c>]
17[B<-d>]
18[B<file...>]
19
20=head1 DESCRIPTION
21
22The digest functions print out the message digest of a supplied file or files
23in hexadecimal form.
24
25=head1 OPTIONS
26
27=over 4
28
29=item B<-c>
30
31print out the digest in two digit groups separated by colons.
32
33=item B<-d>
34
35print out BIO debugging information.
36
37=item B<file...>
38
39file or files to digest. If no files are specified then standard input is
40used.
41
42=back
43
44=head1 NOTES
45
46The digest of choice for all new applications is SHA1. Other digests are
47however still widely used.
48
49=cut
diff --git a/src/lib/libssl/src/doc/apps/dhparam.pod b/src/lib/libssl/src/doc/apps/dhparam.pod
new file mode 100644
index 0000000000..6b237ec05a
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/dhparam.pod
@@ -0,0 +1,115 @@
1=pod
2
3=head1 NAME
4
5dhparam - DH parameter manipulation and generation
6
7=head1 SYNOPSIS
8
9B<openssl dh>
10[B<-inform DER|PEM>]
11[B<-outform DER|PEM>]
12[B<-in filename>]
13[B<-out filename>]
14[B<-noout>]
15[B<-text>]
16[B<-C>]
17[B<-2>]
18[B<-5>]
19[B<-rand file(s)>]
20[numbits]
21
22=head1 DESCRIPTION
23
24This command is used to manipulate DH parameter files.
25
26=head1 OPTIONS
27
28=over 4
29
30=item B<-inform DER|PEM>
31
32This specifies the input format. The B<DER> option uses an ASN1 DER encoded
33form compatible with the PKCS#3 DHparameter structure. The PEM form is the
34default format: it consists of the B<DER> format base64 encoded with
35additional header and footer lines.
36
37=item B<-outform DER|PEM>
38
39This specifies the output format, the options have the same meaning as the
40B<-inform> option.
41
42=item B<-in filename>
43
44This specifies the input filename to read parameters from or standard input if
45this option is not specified.
46
47=item B<-out filename>
48
49This specifies the output filename parameters to. Standard output is used
50if this option is not present. The output filename should B<not> be the same
51as the input filename.
52
53=item B<-2>, B<-5>
54
55The generator to use, either 2 or 5. 2 is the default. If present then the
56input file is ignored and parameters are generated instead.
57
58=item B<-rand file(s)>
59
60a file or files containing random data used to seed the random number
61generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
62Multiple files can be specified separated by a OS-dependent character.
63The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
64all others.
65
66=item B<numbits>
67
68this option specifies that a parameter set should be generated of size
69B<numbits>. It must be the last option. If not present then a value of 512
70is used. If this option is present then the input file is ignored and
71parameters are generated instead.
72
73=item B<-noout>
74
75this option inhibits the output of the encoded version of the parameters.
76
77=item B<-text>
78
79this option prints out the DH parameters in human readable form.
80
81=item B<-C>
82
83this option converts the parameters into C code. The parameters can then
84be loaded by calling the B<get_dhXXX()> function.
85
86=back
87
88=head1 WARNINGS
89
90The program B<dhparam> combines the functionality of the programs B<dh> and
91B<gendh> in previous versions of OpenSSL and SSLeay. The B<dh> and B<gendh>
92programs are retained for now but may have different purposes in future
93versions of OpenSSL.
94
95=head1 NOTES
96
97PEM format DH parameters use the header and footer lines:
98
99 -----BEGIN DH PARAMETERS-----
100 -----END DH PARAMETERS-----
101
102OpenSSL currently only supports the older PKCS#3 DH, not the newer X9.42
103DH.
104
105This program manipulates DH parameters not keys.
106
107=head1 BUGS
108
109There should be a way to generate and manipulate DH keys.
110
111=head1 SEE ALSO
112
113L<dsaparam(1)|dsaparam(1)>
114
115=cut
diff --git a/src/lib/libssl/src/doc/apps/dsa.pod b/src/lib/libssl/src/doc/apps/dsa.pod
new file mode 100644
index 0000000000..28e534bb95
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/dsa.pod
@@ -0,0 +1,150 @@
1=pod
2
3=head1 NAME
4
5dsa - DSA key processing
6
7=head1 SYNOPSIS
8
9B<openssl> B<dsa>
10[B<-inform PEM|DER>]
11[B<-outform PEM|DER>]
12[B<-in filename>]
13[B<-passin arg>]
14[B<-out filename>]
15[B<-passout arg>]
16[B<-des>]
17[B<-des3>]
18[B<-idea>]
19[B<-text>]
20[B<-noout>]
21[B<-modulus>]
22[B<-pubin>]
23[B<-pubout>]
24
25=head1 DESCRIPTION
26
27The B<dsa> command processes DSA keys. They can be converted between various
28forms and their components printed out. B<Note> This command uses the
29traditional SSLeay compatible format for private key encryption: newer
30applications should use the more secure PKCS#8 format using the B<pkcs8>
31
32=head1 COMMAND OPTIONS
33
34=over 4
35
36=item B<-inform DER|PEM>
37
38This specifies the input format. The B<DER> option with a private key uses
39an ASN1 DER encoded form of an ASN.1 SEQUENCE consisting of the values of
40version (currently zero), p, q, g, the public and private key components
41respectively as ASN.1 INTEGERs. When used with a public key it uses a
42SubjectPublicKeyInfo structure: it is an error if the key is not DSA.
43
44The B<PEM> form is the default format: it consists of the B<DER> format base64
45encoded with additional header and footer lines. In the case of a private key
46PKCS#8 format is also accepted.
47
48=item B<-outform DER|PEM>
49
50This specifies the output format, the options have the same meaning as the
51B<-inform> option.
52
53=item B<-in filename>
54
55This specifies the input filename to read a key from or standard input if this
56option is not specified. If the key is encrypted a pass phrase will be
57prompted for.
58
59=item B<-passin arg>
60
61the input file password source. For more information about the format of B<arg>
62see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
63
64=item B<-out filename>
65
66This specifies the output filename to write a key to or standard output by
67is not specified. If any encryption options are set then a pass phrase will be
68prompted for. The output filename should B<not> be the same as the input
69filename.
70
71=item B<-passout arg>
72
73the output file password source. For more information about the format of B<arg>
74see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
75
76=item B<-des|-des3|-idea>
77
78These options encrypt the private key with the DES, triple DES, or the
79IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
80If none of these options is specified the key is written in plain text. This
81means that using the B<dsa> utility to read in an encrypted key with no
82encryption option can be used to remove the pass phrase from a key, or by
83setting the encryption options it can be use to add or change the pass phrase.
84These options can only be used with PEM format output files.
85
86=item B<-text>
87
88prints out the public, private key components and parameters.
89
90=item B<-noout>
91
92this option prevents output of the encoded version of the key.
93
94=item B<-modulus>
95
96this option prints out the value of the public key component of the key.
97
98=item B<-pubin>
99
100by default a private key is read from the input file: with this option a
101public key is read instead.
102
103=item B<-pubout>
104
105by default a private key is output. With this option a public
106key will be output instead. This option is automatically set if the input is
107a public key.
108
109=back
110
111=head1 NOTES
112
113The PEM private key format uses the header and footer lines:
114
115 -----BEGIN DSA PRIVATE KEY-----
116 -----END DSA PRIVATE KEY-----
117
118The PEM public key format uses the header and footer lines:
119
120 -----BEGIN PUBLIC KEY-----
121 -----END PUBLIC KEY-----
122
123=head1 EXAMPLES
124
125To remove the pass phrase on a DSA private key:
126
127 openssl dsa -in key.pem -out keyout.pem
128
129To encrypt a private key using triple DES:
130
131 openssl dsa -in key.pem -des3 -out keyout.pem
132
133To convert a private key from PEM to DER format:
134
135 openssl dsa -in key.pem -outform DER -out keyout.der
136
137To print out the components of a private key to standard output:
138
139 openssl dsa -in key.pem -text -noout
140
141To just output the public part of a private key:
142
143 openssl dsa -in key.pem -pubout -out pubkey.pem
144
145=head1 SEE ALSO
146
147L<dsaparam(1)|dsaparam(1)>, L<gendsa(1)|gendsa(1)>, L<rsa(1)|rsa(1)>,
148L<genrsa(1)|genrsa(1)>
149
150=cut
diff --git a/src/lib/libssl/src/doc/apps/dsaparam.pod b/src/lib/libssl/src/doc/apps/dsaparam.pod
new file mode 100644
index 0000000000..8647f34698
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/dsaparam.pod
@@ -0,0 +1,102 @@
1=pod
2
3=head1 NAME
4
5dsaparam - DSA parameter manipulation and generation
6
7=head1 SYNOPSIS
8
9B<openssl dsaparam>
10[B<-inform DER|PEM>]
11[B<-outform DER|PEM>]
12[B<-in filename>]
13[B<-out filename>]
14[B<-noout>]
15[B<-text>]
16[B<-C>]
17[B<-rand file(s)>]
18[B<-genkey>]
19[B<numbits>]
20
21=head1 DESCRIPTION
22
23This command is used to manipulate or generate DSA parameter files.
24
25=head1 OPTIONS
26
27=over 4
28
29=item B<-inform DER|PEM>
30
31This specifies the input format. The B<DER> option uses an ASN1 DER encoded
32form compatible with RFC2459 (PKIX) DSS-Parms that is a SEQUENCE consisting
33of p, q and g respectively. The PEM form is the default format: it consists
34of the B<DER> format base64 encoded with additional header and footer lines.
35
36=item B<-outform DER|PEM>
37
38This specifies the output format, the options have the same meaning as the
39B<-inform> option.
40
41=item B<-in filename>
42
43This specifies the input filename to read parameters from or standard input if
44this option is not specified. If the B<numbits> parameter is included then
45this option will be ignored.
46
47=item B<-out filename>
48
49This specifies the output filename parameters to. Standard output is used
50if this option is not present. The output filename should B<not> be the same
51as the input filename.
52
53=item B<-noout>
54
55this option inhibits the output of the encoded version of the parameters.
56
57=item B<-text>
58
59this option prints out the DSA parameters in human readable form.
60
61=item B<-C>
62
63this option converts the parameters into C code. The parameters can then
64be loaded by calling the B<get_dsaXXX()> function.
65
66=item B<-genkey>
67
68this option will generate a DSA either using the specified or generated
69parameters.
70
71=item B<-rand file(s)>
72
73a file or files containing random data used to seed the random number
74generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
75Multiple files can be specified separated by a OS-dependent character.
76The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
77all others.
78
79=item B<numbits>
80
81this option specifies that a parameter set should be generated of size
82B<numbits>. It must be the last option. If this option is included then
83the input file (if any) is ignored.
84
85=back
86
87=head1 NOTES
88
89PEM format DSA parameters use the header and footer lines:
90
91 -----BEGIN DSA PARAMETERS-----
92 -----END DSA PARAMETERS-----
93
94DSA parameter generation is a slow process and as a result the same set of
95DSA parameters is often used to generate several distinct keys.
96
97=head1 SEE ALSO
98
99L<gendsa(1)|gendsa(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
100L<rsa(1)|rsa(1)>
101
102=cut
diff --git a/src/lib/libssl/src/doc/apps/enc.pod b/src/lib/libssl/src/doc/apps/enc.pod
new file mode 100644
index 0000000000..e436ccc37e
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/enc.pod
@@ -0,0 +1,257 @@
1=pod
2
3=head1 NAME
4
5enc - symmetric cipher routines
6
7=head1 SYNOPSIS
8
9B<openssl enc -ciphername>
10[B<-in filename>]
11[B<-out filename>]
12[B<-pass arg>]
13[B<-e>]
14[B<-d>]
15[B<-a>]
16[B<-A>]
17[B<-k password>]
18[B<-kfile filename>]
19[B<-K key>]
20[B<-iv IV>]
21[B<-p>]
22[B<-P>]
23[B<-bufsize number>]
24[B<-debug>]
25
26=head1 DESCRIPTION
27
28The symmetric cipher commands allow data to be encrypted or decrypted
29using various block and stream ciphers using keys based on passwords
30or explicitly provided. Base64 encoding or decoding can also be performed
31either by itself or in addition to the encryption or decryption.
32
33=head1 OPTIONS
34
35=over 4
36
37=item B<-in filename>
38
39the input filename, standard input by default.
40
41=item B<-out filename>
42
43the output filename, standard output by default.
44
45=item B<-pass arg>
46
47the password source. For more information about the format of B<arg>
48see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
49
50=item B<-salt>
51
52use a salt in the key derivation routines. This option should B<ALWAYS>
53be used unless compatibility with previous versions of OpenSSL or SSLeay
54is required. This option is only present on OpenSSL versions 0.9.5 or
55above.
56
57=item B<-nosalt>
58
59don't use a salt in the key derivation routines. This is the default for
60compatibility with previous versions of OpenSSL and SSLeay.
61
62=item B<-e>
63
64encrypt the input data: this is the default.
65
66=item B<-d>
67
68decrypt the input data.
69
70=item B<-a>
71
72base64 process the data. This means that if encryption is taking place
73the data is base64 encoded after encryption. If decryption is set then
74the input data is base64 decoded before being decrypted.
75
76=item B<-A>
77
78if the B<-a> option is set then base64 process the data on one line.
79
80=item B<-k password>
81
82the password to derive the key from. This is for compatibility with previous
83versions of OpenSSL. Superseded by the B<-pass> argument.
84
85=item B<-kfile filename>
86
87read the password to derive the key from the first line of B<filename>.
88This is for computability with previous versions of OpenSSL. Superseded by
89the B<-pass> argument.
90
91=item B<-S salt>
92
93the actual salt to use: this must be represented as a string comprised only
94of hex digits.
95
96=item B<-K key>
97
98the actual key to use: this must be represented as a string comprised only
99of hex digits.
100
101=item B<-iv IV>
102
103the actual IV to use: this must be represented as a string comprised only
104of hex digits.
105
106=item B<-p>
107
108print out the key and IV used.
109
110=item B<-P>
111
112print out the key and IV used then immediately exit: don't do any encryption
113or decryption.
114
115=item B<-bufsize number>
116
117set the buffer size for I/O
118
119=item B<-debug>
120
121debug the BIOs used for I/O.
122
123=back
124
125=head1 NOTES
126
127The program can be called either as B<openssl ciphername> or
128B<openssl enc -ciphername>.
129
130A password will be prompted for to derive the key and IV if necessary.
131
132The B<-salt> option should B<ALWAYS> be used if the key is being derived
133from a password unless you want compatibility with previous versions of
134OpenSSL and SSLeay.
135
136Without the B<-salt> option it is possible to perform efficient dictionary
137attacks on the password and to attack stream cipher encrypted data. The reason
138for this is that without the salt the same password always generates the same
139encryption key. When the salt is being used the first eight bytes of the
140encrypted data are reserved for the salt: it is generated at random when
141encrypting a file and read from the encrypted file when it is decrypted.
142
143Some of the ciphers do not have large keys and others have security
144implications if not used correctly. A beginner is advised to just use
145a strong block cipher in CBC mode such as bf or des3.
146
147All the block ciphers use PKCS#5 padding also known as standard block
148padding: this allows a rudimentary integrity or password check to be
149performed. However since the chance of random data passing the test is
150better than 1 in 256 it isn't a very good test.
151
152All RC2 ciphers have the same key and effective key length.
153
154Blowfish and RC5 algorithms use a 128 bit key.
155
156=head1 SUPPORTED CIPHERS
157
158 base64 Base 64
159
160 bf-cbc Blowfish in CBC mode
161 bf Alias for bf-cbc
162 bf-cfb Blowfish in CFB mode
163 bf-ecb Blowfish in ECB mode
164 bf-ofb Blowfish in OFB mode
165
166 cast-cbc CAST in CBC mode
167 cast Alias for cast-cbc
168 cast5-cbc CAST5 in CBC mode
169 cast5-cfb CAST5 in CFB mode
170 cast5-ecb CAST5 in ECB mode
171 cast5-ofb CAST5 in OFB mode
172
173 des-cbc DES in CBC mode
174 des Alias for des-cbc
175 des-cfb DES in CBC mode
176 des-ofb DES in OFB mode
177 des-ecb DES in ECB mode
178
179 des-ede-cbc Two key triple DES EDE in CBC mode
180 des-ede Alias for des-ede
181 des-ede-cfb Two key triple DES EDE in CFB mode
182 des-ede-ofb Two key triple DES EDE in OFB mode
183
184 des-ede3-cbc Three key triple DES EDE in CBC mode
185 des-ede3 Alias for des-ede3-cbc
186 des3 Alias for des-ede3-cbc
187 des-ede3-cfb Three key triple DES EDE CFB mode
188 des-ede3-ofb Three key triple DES EDE in OFB mode
189
190 desx DESX algorithm.
191
192 idea-cbc IDEA algorithm in CBC mode
193 idea same as idea-cbc
194 idea-cfb IDEA in CFB mode
195 idea-ecb IDEA in ECB mode
196 idea-ofb IDEA in OFB mode
197
198 rc2-cbc 128 bit RC2 in CBC mode
199 rc2 Alias for rc2-cbc
200 rc2-cfb 128 bit RC2 in CBC mode
201 rc2-ecb 128 bit RC2 in CBC mode
202 rc2-ofb 128 bit RC2 in CBC mode
203 rc2-64-cbc 64 bit RC2 in CBC mode
204 rc2-40-cbc 40 bit RC2 in CBC mode
205
206 rc4 128 bit RC4
207 rc4-64 64 bit RC4
208 rc4-40 40 bit RC4
209
210 rc5-cbc RC5 cipher in CBC mode
211 rc5 Alias for rc5-cbc
212 rc5-cfb RC5 cipher in CBC mode
213 rc5-ecb RC5 cipher in CBC mode
214 rc5-ofb RC5 cipher in CBC mode
215
216=head1 EXAMPLES
217
218Just base64 encode a binary file:
219
220 openssl base64 -in file.bin -out file.b64
221
222Decode the same file
223
224 openssl base64 -d -in file.b64 -out file.bin
225
226Encrypt a file using triple DES in CBC mode using a prompted password:
227
228 openssl des3 -salt -in file.txt -out file.des3
229
230Decrypt a file using a supplied password:
231
232 openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword
233
234Encrypt a file then base64 encode it (so it can be sent via mail for example)
235using Blowfish in CBC mode:
236
237 openssl bf -a -salt -in file.txt -out file.bf
238
239Base64 decode a file then decrypt it:
240
241 openssl bf -d -salt -a -in file.bf -out file.txt
242
243Decrypt some data using a supplied 40 bit RC4 key:
244
245 openssl rc4-40 -in file.rc4 -out file.txt -K 0102030405
246
247=head1 BUGS
248
249The B<-A> option when used with large files doesn't work properly.
250
251There should be an option to allow an iteration count to be included.
252
253Like the EVP library the B<enc> program only supports a fixed number of
254algorithms with certain parameters. So if, for example, you want to use RC2
255with a 76 bit key or RC4 with an 84 bit key you can't use this program.
256
257=cut
diff --git a/src/lib/libssl/src/doc/apps/gendsa.pod b/src/lib/libssl/src/doc/apps/gendsa.pod
new file mode 100644
index 0000000000..3314ace517
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/gendsa.pod
@@ -0,0 +1,58 @@
1=pod
2
3=head1 NAME
4
5gendsa - generate a DSA private key from a set of parameters
6
7=head1 SYNOPSIS
8
9B<openssl> B<gendsa>
10[B<-out filename>]
11[B<-des>]
12[B<-des3>]
13[B<-idea>]
14[B<-rand file(s)>]
15[B<paramfile>]
16
17=head1 DESCRIPTION
18
19The B<gendsa> command generates a DSA private key from a DSA parameter file
20(which will be typically generated by the B<openssl dsaparam> command).
21
22=head1 OPTIONS
23
24=over 4
25
26=item B<-des|-des3|-idea>
27
28These options encrypt the private key with the DES, triple DES, or the
29IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
30If none of these options is specified no encryption is used.
31
32=item B<-rand file(s)>
33
34a file or files containing random data used to seed the random number
35generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
36Multiple files can be specified separated by a OS-dependent character.
37The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
38all others.
39
40=item B<paramfile>
41
42This option specifies the DSA parameter file to use. The parameters in this
43file determine the size of the private key. DSA parameters can be generated
44and examined using the B<openssl dsaparam> command.
45
46=back
47
48=head1 NOTES
49
50DSA key generation is little more than random number generation so it is
51much quicker that RSA key generation for example.
52
53=head1 SEE ALSO
54
55L<dsaparam(1)|dsaparam(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
56L<rsa(1)|rsa(1)>
57
58=cut
diff --git a/src/lib/libssl/src/doc/apps/genrsa.pod b/src/lib/libssl/src/doc/apps/genrsa.pod
new file mode 100644
index 0000000000..a2d878410b
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/genrsa.pod
@@ -0,0 +1,85 @@
1=pod
2
3=head1 NAME
4
5genrsa - generate an RSA private key
6
7=head1 SYNOPSIS
8
9B<openssl> B<genrsa>
10[B<-out filename>]
11[B<-passout arg>]
12[B<-des>]
13[B<-des3>]
14[B<-idea>]
15[B<-f4>]
16[B<-3>]
17[B<-rand file(s)>]
18[B<numbits>]
19
20=head1 DESCRIPTION
21
22The B<genrsa> command generates an RSA private key.
23
24=head1 OPTIONS
25
26=over 4
27
28=item B<-out filename>
29
30the output filename. If this argument is not specified then standard output is
31used.
32
33=item B<-passout arg>
34
35the output file password source. For more information about the format of B<arg>
36see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
37
38=item B<-des|-des3|-idea>
39
40These options encrypt the private key with the DES, triple DES, or the
41IDEA ciphers respectively before outputting it. If none of these options is
42specified no encryption is used. If encryption is used a pass phrase is prompted
43for if it is not supplied via the B<-passout> argument.
44
45=item B<-F4|-3>
46
47the public exponent to use, either 65537 or 3. The default is 65537.
48
49=item B<-rand file(s)>
50
51a file or files containing random data used to seed the random number
52generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
53Multiple files can be specified separated by a OS-dependent character.
54The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
55all others.
56
57=item B<numbits>
58
59the size of the private key to generate in bits. This must be the last option
60specified. The default is 512.
61
62=back
63
64=head1 NOTES
65
66RSA private key generation essentially involves the generation of two prime
67numbers. When generating a private key various symbols will be output to
68indicate the progress of the generation. A B<.> represents each number which
69has passed an initial sieve test, B<+> means a number has passed a single
70round of the Miller-Rabin primality test. A newline means that the number has
71passed all the prime tests (the actual number depends on the key size).
72
73Because key generation is a random process the time taken to generate a key
74may vary somewhat.
75
76=head1 BUGS
77
78A quirk of the prime generation algorithm is that it cannot generate small
79primes. Therefore the number of bits should not be less that 64. For typical
80private keys this will not matter because for security reasons they will
81be much larger (typically 1024 bits).
82
83=head1 SEE ALSO
84
85L<gendsa(1)|gendsa(1)>
diff --git a/src/lib/libssl/src/doc/apps/nseq.pod b/src/lib/libssl/src/doc/apps/nseq.pod
new file mode 100644
index 0000000000..989c3108fb
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/nseq.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5nseq - create or examine a netscape certificate sequence
6
7=head1 SYNOPSIS
8
9B<openssl> B<nseq>
10[B<-in filename>]
11[B<-out filename>]
12[B<-toseq>]
13
14=head1 DESCRIPTION
15
16The B<nseq> command takes a file containing a Netscape certificate
17sequence and prints out the certificates contained in it or takes a
18file of certificates and converts it into a Netscape certificate
19sequence.
20
21=head1 COMMAND OPTIONS
22
23=over 4
24
25=item B<-in filename>
26
27This specifies the input filename to read or standard input if this
28option is not specified.
29
30=item B<-out filename>
31
32specifies the output filename or standard output by default.
33
34=item B<-toseq>
35
36normally a Netscape certificate sequence will be input and the output
37is the certificates contained in it. With the B<-toseq> option the
38situation is reversed: a Netscape certificate sequence is created from
39a file of certificates.
40
41=back
42
43=head1 EXAMPLES
44
45Output the certificates in a Netscape certificate sequence
46
47 openssl nseq -in nseq.pem -out certs.pem
48
49Create a Netscape certificate sequence
50
51 openssl nseq -in certs.pem -toseq -out nseq.pem
52
53=head1 NOTES
54
55The B<PEM> encoded form uses the same headers and footers as a certificate:
56
57 -----BEGIN CERTIFICATE-----
58 -----END CERTIFICATE-----
59
60A Netscape certificate sequence is a Netscape specific form that can be sent
61to browsers as an alternative to the standard PKCS#7 format when several
62certificates are sent to the browser: for example during certificate enrollment.
63It is used by Netscape certificate server for example.
64
65=head1 BUGS
66
67This program needs a few more options: like allowing DER or PEM input and
68output files and allowing multiple certificate files to be used.
69
70=cut
diff --git a/src/lib/libssl/src/doc/apps/ocsp.pod b/src/lib/libssl/src/doc/apps/ocsp.pod
new file mode 100644
index 0000000000..da201b95e6
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/ocsp.pod
@@ -0,0 +1,348 @@
1=pod
2
3=head1 NAME
4
5ocsp - Online Certificate Status Protocol utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<ocsp>
10[B<-out file>]
11[B<-issuer file>]
12[B<-cert file>]
13[B<-serial n>]
14[B<-req_text>]
15[B<-resp_text>]
16[B<-text>]
17[B<-reqout file>]
18[B<-respout file>]
19[B<-reqin file>]
20[B<-respin file>]
21[B<-nonce>]
22[B<-no_nonce>]
23[B<-url responder_url>]
24[B<-host host:n>]
25[B<-path>]
26[B<-CApath file>]
27[B<-CAfile file>]
28[B<-VAfile file>]
29[B<-verify_certs file>]
30[B<-noverify>]
31[B<-trust_other>]
32[B<-no_intern>]
33[B<-no_sig_verify>]
34[B<-no_cert_verify>]
35[B<-no_chain>]
36[B<-no_cert_checks>]
37[B<-validity_period nsec>]
38[B<-status_age nsec>]
39
40=head1 DESCRIPTION
41
42B<WARNING: this documentation is preliminary and subject to change.>
43
44The Online Certificate Status Protocol (OCSP) enables applications to
45determine the (revocation) state of an identified certificate (RFC 2560).
46
47The B<ocsp> command performs many common OCSP tasks. It can be used
48to print out requests and responses, create requests and send queries
49to an OCSP responder and behave like a mini OCSP server itself.
50
51=head1 OCSP CLIENT OPTIONS
52
53=over 4
54
55=item B<-out filename>
56
57specify output filename, default is standard output.
58
59=item B<-issuer filename>
60
61This specifies the current issuer certificate. This option can be used
62multiple times. The certificate specified in B<filename> must be in
63PEM format.
64
65=item B<-cert filename>
66
67Add the certificate B<filename> to the request. The issuer certificate
68is taken from the previous B<issuer> option, or an error occurs if no
69issuer certificate is specified.
70
71=item B<-serial num>
72
73Same as the B<cert> option except the certificate with serial number
74B<num> is added to the request. The serial number is interpreted as a
75decimal integer unless preceded by B<0x>. Negative integers can also
76be specified by preceding the value by a B<-> sign.
77
78=item B<-signer filename>, B<-signkey filename>
79
80Sign the OCSP request using the certificate specified in the B<signer>
81option and the private key specified by the B<signkey> option. If
82the B<signkey> option is not present then the private key is read
83from the same file as the certificate. If neither option is specified then
84the OCSP request is not signed.
85
86=item B<-nonce>, B<-no_nonce>
87
88Add an OCSP nonce extension to a request or disable OCSP nonce addition.
89Normally if an OCSP request is input using the B<respin> option no
90nonce is added: using the B<nonce> option will force addition of a nonce.
91If an OCSP request is being created (using B<cert> and B<serial> options)
92a nonce is automatically added specifying B<no_nonce> overrides this.
93
94=item B<-req_text>, B<-resp_text>, B<-text>
95
96print out the text form of the OCSP request, response or both respectively.
97
98=item B<-reqout file>, B<-respout file>
99
100write out the DER encoded certificate request or response to B<file>.
101
102=item B<-reqin file>, B<-respin file>
103
104read OCSP request or response file from B<file>. These option are ignored
105if OCSP request or response creation is implied by other options (for example
106with B<serial>, B<cert> and B<host> options).
107
108=item B<-url responder_url>
109
110specify the responder URL. Both HTTP and HTTPS (SSL/TLS) URLs can be specified.
111
112=item B<-host hostname:port>, B<-path pathname>
113
114if the B<host> option is present then the OCSP request is sent to the host
115B<hostname> on port B<port>. B<path> specifies the HTTP path name to use
116or "/" by default.
117
118=item B<-CAfile file>, B<-CApath pathname>
119
120file or pathname containing trusted CA certificates. These are used to verify
121the signature on the OCSP response.
122
123=item B<-verify_certs file>
124
125file containing additional certificates to search when attempting to locate
126the OCSP response signing certificate. Some responders omit the actual signer's
127certificate from the response: this option can be used to supply the necessary
128certificate in such cases.
129
130=item B<-trust_other>
131
132the certificates specified by the B<-verify_certs> option should be explicitly
133trusted and no additional checks will be performed on them. This is useful
134when the complete responder certificate chain is not available or trusting a
135root CA is not appropriate.
136
137=item B<-VAfile file>
138
139file containing explicitly trusted responder certificates. Equivalent to the
140B<-verify_certs> and B<-trust_other> options.
141
142=item B<-noverify>
143
144don't attempt to verify the OCSP response signature or the nonce values. This
145option will normally only be used for debugging since it disables all verification
146of the responders certificate.
147
148=item B<-no_intern>
149
150ignore certificates contained in the OCSP response when searching for the
151signers certificate. With this option the signers certificate must be specified
152with either the B<-verify_certs> or B<-VAfile> options.
153
154=item B<-no_sig_verify>
155
156don't check the signature on the OCSP response. Since this option tolerates invalid
157signatures on OCSP responses it will normally only be used for testing purposes.
158
159=item B<-no_cert_verify>
160
161don't verify the OCSP response signers certificate at all. Since this option allows
162the OCSP response to be signed by any certificate it should only be used for
163testing purposes.
164
165=item B<-no_chain>
166
167do not use certificates in the response as additional untrusted CA
168certificates.
169
170=item B<-no_cert_checks>
171
172don't perform any additional checks on the OCSP response signers certificate.
173That is do not make any checks to see if the signers certificate is authorised
174to provide the necessary status information: as a result this option should
175only be used for testing purposes.
176
177=item B<-validity_period nsec>, B<-status_age age>
178
179these options specify the range of times, in seconds, which will be tolerated
180in an OCSP response. Each certificate status response includes a B<notBefore> time and
181an optional B<notAfter> time. The current time should fall between these two values, but
182the interval between the two times may be only a few seconds. In practice the OCSP
183responder and clients clocks may not be precisely synchronised and so such a check
184may fail. To avoid this the B<-validity_period> option can be used to specify an
185acceptable error range in seconds, the default value is 5 minutes.
186
187If the B<notAfter> time is omitted from a response then this means that new status
188information is immediately available. In this case the age of the B<notBefore> field
189is checked to see it is not older than B<age> seconds old. By default this additional
190check is not performed.
191
192=back
193
194=head1 OCSP SERVER OPTIONS
195
196=over 4
197
198=item B<-index indexfile>
199
200B<indexfile> is a text index file in B<ca> format containing certificate revocation
201information.
202
203If the B<index> option is specified the B<ocsp> utility is in responder mode, otherwise
204it is in client mode. The request(s) the responder processes can be either specified on
205the command line (using B<issuer> and B<serial> options), supplied in a file (using the
206B<respin> option) or via external OCSP clients (if B<port> or B<url> is specified).
207
208If the B<index> option is present then the B<CA> and B<rsigner> options must also be
209present.
210
211=item B<-CA file>
212
213CA certificate corresponding to the revocation information in B<indexfile>.
214
215=item B<-rsigner file>
216
217The certificate to sign OCSP responses with.
218
219=item B<-rother file>
220
221Additional certificates to include in the OCSP response.
222
223=item B<-resp_no_certs>
224
225Don't include any certificates in the OCSP response.
226
227=item B<-resp_key_id>
228
229Identify the signer certificate using the key ID, default is to use the subject name.
230
231=item B<-rkey file>
232
233The private key to sign OCSP responses with: if not present the file specified in the
234B<rsigner> option is used.
235
236=item B<-port portnum>
237
238Port to listen for OCSP requests on. The port may also be specified using the B<url>
239option.
240
241=item B<-nrequest number>
242
243The OCSP server will exit after receiving B<number> requests, default unlimited.
244
245=item B<-nmin minutes>, B<-ndays days>
246
247Number of minutes or days when fresh revocation information is available: used in the
248B<nextUpdate> field. If neither option is present then the B<nextUpdate> field is
249omitted meaning fresh revocation information is immediately available.
250
251=back
252
253=head1 OCSP Response verification.
254
255OCSP Response follows the rules specified in RFC2560.
256
257Initially the OCSP responder certificate is located and the signature on
258the OCSP request checked using the responder certificate's public key.
259
260Then a normal certificate verify is performed on the OCSP responder certificate
261building up a certificate chain in the process. The locations of the trusted
262certificates used to build the chain can be specified by the B<CAfile>
263and B<CApath> options or they will be looked for in the standard OpenSSL
264certificates directory.
265
266If the initial verify fails then the OCSP verify process halts with an
267error.
268
269Otherwise the issuing CA certificate in the request is compared to the OCSP
270responder certificate: if there is a match then the OCSP verify succeeds.
271
272Otherwise the OCSP responder certificate's CA is checked against the issuing
273CA certificate in the request. If there is a match and the OCSPSigning
274extended key usage is present in the OCSP responder certificate then the
275OCSP verify succeeds.
276
277Otherwise the root CA of the OCSP responders CA is checked to see if it
278is trusted for OCSP signing. If it is the OCSP verify succeeds.
279
280If none of these checks is successful then the OCSP verify fails.
281
282What this effectively means if that if the OCSP responder certificate is
283authorised directly by the CA it is issuing revocation information about
284(and it is correctly configured) then verification will succeed.
285
286If the OCSP responder is a "global responder" which can give details about
287multiple CAs and has its own separate certificate chain then its root
288CA can be trusted for OCSP signing. For example:
289
290 openssl x509 -in ocspCA.pem -addtrust OCSPSigning -out trustedCA.pem
291
292Alternatively the responder certificate itself can be explicitly trusted
293with the B<-VAfile> option.
294
295=head1 NOTES
296
297As noted, most of the verify options are for testing or debugging purposes.
298Normally only the B<-CApath>, B<-CAfile> and (if the responder is a 'global
299VA') B<-VAfile> options need to be used.
300
301The OCSP server is only useful for test and demonstration purposes: it is
302not really usable as a full OCSP responder. It contains only a very
303simple HTTP request handling and can only handle the POST form of OCSP
304queries. It also handles requests serially meaning it cannot respond to
305new requests until it has processed the current one. The text index file
306format of revocation is also inefficient for large quantities of revocation
307data.
308
309It is possible to run the B<ocsp> application in responder mode via a CGI
310script using the B<respin> and B<respout> options.
311
312=head1 EXAMPLES
313
314Create an OCSP request and write it to a file:
315
316 openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem -reqout req.der
317
318Send a query to an OCSP responder with URL http://ocsp.myhost.com/ save the
319response to a file and print it out in text form
320
321 openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem \
322 -url http://ocsp.myhost.com/ -resp_text -respout resp.der
323
324Read in an OCSP response and print out text form:
325
326 openssl ocsp -respin resp.der -text
327
328OCSP server on port 8888 using a standard B<ca> configuration, and a separate
329responder certificate. All requests and responses are printed to a file.
330
331 openssl ocsp -index demoCA/index.txt -port 8888 -rsigner rcert.pem -CA demoCA/cacert.pem
332 -text -out log.txt
333
334As above but exit after processing one request:
335
336 openssl ocsp -index demoCA/index.txt -port 8888 -rsigner rcert.pem -CA demoCA/cacert.pem
337 -nrequest 1
338
339Query status information using internally generated request:
340
341 openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA demoCA/cacert.pem
342 -issuer demoCA/cacert.pem -serial 1
343
344Query status information using request read from a file, write response to a
345second file.
346
347 openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA demoCA/cacert.pem
348 -reqin req.der -respout resp.der
diff --git a/src/lib/libssl/src/doc/apps/openssl.pod b/src/lib/libssl/src/doc/apps/openssl.pod
new file mode 100644
index 0000000000..9b1320606b
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/openssl.pod
@@ -0,0 +1,298 @@
1
2=pod
3
4=head1 NAME
5
6openssl - OpenSSL command line tool
7
8=head1 SYNOPSIS
9
10B<openssl>
11I<command>
12[ I<command_opts> ]
13[ I<command_args> ]
14
15=head1 DESCRIPTION
16
17OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL
18v2/v3) and Transport Layer Security (TLS v1) network protocols and related
19cryptography standards required by them.
20
21The B<openssl> program is a command line tool for using the various
22cryptography functions of OpenSSL's B<crypto> library from the shell.
23It can be used for
24
25 o Creation of RSA, DH and DSA key parameters
26 o Creation of X.509 certificates, CSRs and CRLs
27 o Calculation of Message Digests
28 o Encryption and Decryption with Ciphers
29 o SSL/TLS Client and Server Tests
30 o Handling of S/MIME signed or encrypted mail
31
32=head1 COMMAND SUMMARY
33
34The B<openssl> program provides a rich variety of commands (I<command> in the
35SYNOPSIS above), each of which often has a wealth of options and arguments
36(I<command_opts> and I<command_args> in the SYNOPSIS).
37
38=head2 STANDARD COMMANDS
39
40=over 10
41
42=item L<B<asn1parse>|asn1parse(1)>
43
44Parse an ASN.1 sequence.
45
46=item L<B<ca>|ca(1)>
47
48Certificate Authority (CA) Management.
49
50=item L<B<ciphers>|ciphers(1)>
51
52Cipher Suite Description Determination.
53
54=item L<B<crl>|crl(1)>
55
56Certificate Revocation List (CRL) Management.
57
58=item L<B<crl2pkcs7>|crl2pkcs7(1)>
59
60CRL to PKCS#7 Conversion.
61
62=item L<B<dgst>|dgst(1)>
63
64Message Digest Calculation.
65
66=item L<B<dh>|dh(1)>
67
68Diffie-Hellman Data Management.
69
70=item L<B<dsa>|dsa(1)>
71
72DSA Data Management.
73
74=item L<B<dsaparam>|dsaparam(1)>
75
76DSA Parameter Generation.
77
78=item L<B<enc>|enc(1)>
79
80Encoding with Ciphers.
81
82=item L<B<errstr>|errstr(1)>
83
84Error Number to Error String Conversion.
85
86=item L<B<gendh>|gendh(1)>
87
88Generation of Diffie-Hellman Parameters.
89
90=item L<B<gendsa>|gendsa(1)>
91
92Generation of DSA Parameters.
93
94=item L<B<genrsa>|genrsa(1)>
95
96Generation of RSA Parameters.
97
98=item L<B<passwd>|passwd(1)>
99
100Generation of hashed passwords.
101
102=item L<B<pkcs7>|pkcs7(1)>
103
104PKCS#7 Data Management.
105
106=item L<B<req>|req(1)>
107
108X.509 Certificate Signing Request (CSR) Management.
109
110=item L<B<rsa>|rsa(1)>
111
112RSA Data Management.
113
114=item L<B<s_client>|s_client(1)>
115
116This implements a generic SSL/TLS client which can establish a transparent
117connection to a remote server speaking SSL/TLS. It's intended for testing
118purposes only and provides only rudimentary interface functionality but
119internally uses mostly all functionality of the OpenSSL B<ssl> library.
120
121=item L<B<s_server>|s_server(1)>
122
123This implements a generic SSL/TLS server which accepts connections from remote
124clients speaking SSL/TLS. It's intended for testing purposes only and provides
125only rudimentary interface functionality but internally uses mostly all
126functionality of the OpenSSL B<ssl> library. It provides both an own command
127line oriented protocol for testing SSL functions and a simple HTTP response
128facility to emulate an SSL/TLS-aware webserver.
129
130=item L<B<s_time>|s_time(1)>
131
132SSL Connection Timer.
133
134=item L<B<sess_id>|sess_id(1)>
135
136SSL Session Data Management.
137
138=item L<B<smime>|smime(1)>
139
140S/MIME mail processing.
141
142=item L<B<speed>|speed(1)>
143
144Algorithm Speed Measurement.
145
146=item L<B<verify>|verify(1)>
147
148X.509 Certificate Verification.
149
150=item L<B<version>|version(1)>
151
152OpenSSL Version Information.
153
154=item L<B<x509>|x509(1)>
155
156X.509 Certificate Data Management.
157
158=back
159
160=head2 MESSAGE DIGEST COMMANDS
161
162=over 10
163
164=item B<md2>
165
166MD2 Digest
167
168=item B<md5>
169
170MD5 Digest
171
172=item B<mdc2>
173
174MDC2 Digest
175
176=item B<rmd160>
177
178RMD-160 Digest
179
180=item B<sha>
181
182SHA Digest
183
184=item B<sha1>
185
186SHA-1 Digest
187
188=back
189
190=head2 ENCODING AND CIPHER COMMANDS
191
192=over 10
193
194=item B<base64>
195
196Base64 Encoding
197
198=item B<bf bf-cbc bf-cfb bf-ecb bf-ofb>
199
200Blowfish Cipher
201
202=item B<cast cast-cbc>
203
204CAST Cipher
205
206=item B<cast5-cbc cast5-cfb cast5-ecb cast5-ofb>
207
208CAST5 Cipher
209
210=item B<des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ofb>
211
212DES Cipher
213
214=item B<des3 desx des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb>
215
216Triple-DES Cipher
217
218=item B<idea idea-cbc idea-cfb idea-ecb idea-ofb>
219
220IDEA Cipher
221
222=item B<rc2 rc2-cbc rc2-cfb rc2-ecb rc2-ofb>
223
224RC2 Cipher
225
226=item B<rc4>
227
228RC4 Cipher
229
230=item B<rc5 rc5-cbc rc5-cfb rc5-ecb rc5-ofb>
231
232RC5 Cipher
233
234=back
235
236=head1 PASS PHRASE ARGUMENTS
237
238Several commands accept password arguments, typically using B<-passin>
239and B<-passout> for input and output passwords respectively. These allow
240the password to be obtained from a variety of sources. Both of these
241options take a single argument whose format is described below. If no
242password argument is given and a password is required then the user is
243prompted to enter one: this will typically be read from the current
244terminal with echoing turned off.
245
246=over 10
247
248=item B<pass:password>
249
250the actual password is B<password>. Since the password is visible
251to utilities (like 'ps' under Unix) this form should only be used
252where security is not important.
253
254=item B<env:var>
255
256obtain the password from the environment variable B<var>. Since
257the environment of other processes is visible on certain platforms
258(e.g. ps under certain Unix OSes) this option should be used with caution.
259
260=item B<file:pathname>
261
262the first line of B<pathname> is the password. If the same B<pathname>
263argument is supplied to B<-passin> and B<-passout> arguments then the first
264line will be used for the input password and the next line for the output
265password. B<pathname> need not refer to a regular file: it could for example
266refer to a device or named pipe.
267
268=item B<fd:number>
269
270read the password from the file descriptor B<number>. This can be used to
271send the data via a pipe for example.
272
273=item B<stdin>
274
275read the password from standard input.
276
277=back
278
279=head1 SEE ALSO
280
281L<asn1parse(1)|asn1parse(1)>, L<ca(1)|ca(1)>, L<config(5)|config(5)>,
282L<crl(1)|crl(1)>, L<crl2pkcs7(1)|crl2pkcs7(1)>, L<dgst(1)|dgst(1)>,
283L<dhparam(1)|dhparam(1)>, L<dsa(1)|dsa(1)>, L<dsaparam(1)|dsaparam(1)>,
284L<enc(1)|enc(1)>, L<gendsa(1)|gendsa(1)>,
285L<genrsa(1)|genrsa(1)>, L<nseq(1)|nseq(1)>, L<openssl(1)|openssl(1)>,
286L<passwd(1)|passwd(1)>,
287L<pkcs12(1)|pkcs12(1)>, L<pkcs7(1)|pkcs7(1)>, L<pkcs8(1)|pkcs8(1)>,
288L<req(1)|req(1)>, L<rsa(1)|rsa(1)>, L<s_client(1)|s_client(1)>,
289L<s_server(1)|s_server(1)>, L<smime(1)|smime(1)>, L<spkac(1)|spkac(1)>,
290L<verify(1)|verify(1)>, L<version(1)|version(1)>, L<x509(1)|x509(1)>,
291L<crypto(3)|crypto(3)>, L<ssl(3)|ssl(3)>
292
293=head1 HISTORY
294
295The openssl(1) document appeared in OpenSSL 0.9.2
296
297=cut
298
diff --git a/src/lib/libssl/src/doc/apps/passwd.pod b/src/lib/libssl/src/doc/apps/passwd.pod
new file mode 100644
index 0000000000..cee6a2f172
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/passwd.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5passwd - compute password hashes
6
7=head1 SYNOPSIS
8
9B<openssl passwd>
10[B<-crypt>]
11[B<-apr1>]
12[B<-salt> I<string>]
13[B<-in> I<file>]
14[B<-stdin>]
15[B<-quiet>]
16[B<-table>]
17{I<password>}
18
19=head1 DESCRIPTION
20
21The B<passwd> command computes the hash of a password typed at
22run-time or the hash of each password in a list. The password list is
23taken from the named file for option B<-in file>, from stdin for
24option B<-stdin>, and from the command line otherwise.
25The Unix standard algorithm B<crypt> and the MD5-based B<apr1> algorithm
26are available.
27
28=head1 OPTIONS
29
30=over 4
31
32=item B<-crypt>
33
34Use the B<crypt> algorithm (default).
35
36=item B<-apr1>
37
38Use the B<apr1> algorithm.
39
40=item B<-salt> I<string>
41
42Use the specified salt.
43
44=item B<-in> I<file>
45
46Read passwords from I<file>.
47
48=item B<-stdin>
49
50Read passwords from B<stdin>.
51
52=item B<-quiet>
53
54Don't output warnings when passwords given at the command line are truncated.
55
56=item B<-table>
57
58In the output list, prepend the cleartext password and a TAB character
59to each password hash.
60
61=back
62
63=head1 EXAMPLES
64
65B<openssl passwd -crypt -salt xx password> prints B<xxj31ZMTZzkVA>.
66
67B<openssl passwd -apr1 -salt xxxxxxxx password> prints B<$apr1$xxxxxxxx$dxHfLAsjHkDRmG83UXe8K0>.
68
69=cut
diff --git a/src/lib/libssl/src/doc/apps/pkcs12.pod b/src/lib/libssl/src/doc/apps/pkcs12.pod
new file mode 100644
index 0000000000..241f9c4a8b
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/pkcs12.pod
@@ -0,0 +1,310 @@
1
2=pod
3
4=head1 NAME
5
6pkcs12 - PKCS#12 file utility
7
8=head1 SYNOPSIS
9
10B<openssl> B<pkcs12>
11[B<-export>]
12[B<-chain>]
13[B<-inkey filename>]
14[B<-certfile filename>]
15[B<-name name>]
16[B<-caname name>]
17[B<-in filename>]
18[B<-out filename>]
19[B<-noout>]
20[B<-nomacver>]
21[B<-nocerts>]
22[B<-clcerts>]
23[B<-cacerts>]
24[B<-nokeys>]
25[B<-info>]
26[B<-des>]
27[B<-des3>]
28[B<-idea>]
29[B<-nodes>]
30[B<-noiter>]
31[B<-maciter>]
32[B<-twopass>]
33[B<-descert>]
34[B<-certpbe>]
35[B<-keypbe>]
36[B<-keyex>]
37[B<-keysig>]
38[B<-password arg>]
39[B<-passin arg>]
40[B<-passout arg>]
41[B<-rand file(s)>]
42
43=head1 DESCRIPTION
44
45The B<pkcs12> command allows PKCS#12 files (sometimes referred to as
46PFX files) to be created and parsed. PKCS#12 files are used by several
47programs including Netscape, MSIE and MS Outlook.
48
49=head1 COMMAND OPTIONS
50
51There are a lot of options the meaning of some depends of whether a PKCS#12 file
52is being created or parsed. By default a PKCS#12 file is parsed a PKCS#12
53file can be created by using the B<-export> option (see below).
54
55=head1 PARSING OPTIONS
56
57=over 4
58
59=item B<-in filename>
60
61This specifies filename of the PKCS#12 file to be parsed. Standard input is used
62by default.
63
64=item B<-out filename>
65
66The filename to write certificates and private keys to, standard output by default.
67They are all written in PEM format.
68
69=item B<-pass arg>, B<-passin arg>
70
71the PKCS#12 file (i.e. input file) password source. For more information about the
72format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
73L<openssl(1)|openssl(1)>.
74
75=item B<-passout arg>
76
77pass phrase source to encrypt any outputed private keys with. For more information
78about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
79L<openssl(1)|openssl(1)>.
80
81=item B<-noout>
82
83this option inhibits output of the keys and certificates to the output file version
84of the PKCS#12 file.
85
86=item B<-clcerts>
87
88only output client certificates (not CA certificates).
89
90=item B<-cacerts>
91
92only output CA certificates (not client certificates).
93
94=item B<-nocerts>
95
96no certificates at all will be output.
97
98=item B<-nokeys>
99
100no private keys will be output.
101
102=item B<-info>
103
104output additional information about the PKCS#12 file structure, algorithms used and
105iteration counts.
106
107=item B<-des>
108
109use DES to encrypt private keys before outputting.
110
111=item B<-des3>
112
113use triple DES to encrypt private keys before outputting, this is the default.
114
115=item B<-idea>
116
117use IDEA to encrypt private keys before outputting.
118
119=item B<-nodes>
120
121don't encrypt the private keys at all.
122
123=item B<-nomacver>
124
125don't attempt to verify the integrity MAC before reading the file.
126
127=item B<-twopass>
128
129prompt for separate integrity and encryption passwords: most software
130always assumes these are the same so this option will render such
131PKCS#12 files unreadable.
132
133=back
134
135=head1 FILE CREATION OPTIONS
136
137=over 4
138
139=item B<-export>
140
141This option specifies that a PKCS#12 file will be created rather than
142parsed.
143
144=item B<-out filename>
145
146This specifies filename to write the PKCS#12 file to. Standard output is used
147by default.
148
149=item B<-in filename>
150
151The filename to read certificates and private keys from, standard input by default.
152They must all be in PEM format. The order doesn't matter but one private key and
153its corresponding certificate should be present. If additional certificates are
154present they will also be included in the PKCS#12 file.
155
156=item B<-inkey filename>
157
158file to read private key from. If not present then a private key must be present
159in the input file.
160
161=item B<-name friendlyname>
162
163This specifies the "friendly name" for the certificate and private key. This name
164is typically displayed in list boxes by software importing the file.
165
166=item B<-certfile filename>
167
168A filename to read additional certificates from.
169
170=item B<-caname friendlyname>
171
172This specifies the "friendly name" for other certificates. This option may be
173used multiple times to specify names for all certificates in the order they
174appear. Netscape ignores friendly names on other certificates whereas MSIE
175displays them.
176
177=item B<-pass arg>, B<-passout arg>
178
179the PKCS#12 file (i.e. output file) password source. For more information about
180the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
181L<openssl(1)|openssl(1)>.
182
183=item B<-passin password>
184
185pass phrase source to decrypt any input private keys with. For more information
186about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
187L<openssl(1)|openssl(1)>.
188
189=item B<-chain>
190
191if this option is present then an attempt is made to include the entire
192certificate chain of the user certificate. The standard CA store is used
193for this search. If the search fails it is considered a fatal error.
194
195=item B<-descert>
196
197encrypt the certificate using triple DES, this may render the PKCS#12
198file unreadable by some "export grade" software. By default the private
199key is encrypted using triple DES and the certificate using 40 bit RC2.
200
201=item B<-keypbe alg>, B<-certpbe alg>
202
203these options allow the algorithm used to encrypt the private key and
204certificates to be selected. Although any PKCS#5 v1.5 or PKCS#12 algorithms
205can be selected it is advisable only to use PKCS#12 algorithms. See the list
206in the B<NOTES> section for more information.
207
208=item B<-keyex|-keysig>
209
210specifies that the private key is to be used for key exchange or just signing.
211This option is only interpreted by MSIE and similar MS software. Normally
212"export grade" software will only allow 512 bit RSA keys to be used for
213encryption purposes but arbitrary length keys for signing. The B<-keysig>
214option marks the key for signing only. Signing only keys can be used for
215S/MIME signing, authenticode (ActiveX control signing) and SSL client
216authentication, however due to a bug only MSIE 5.0 and later support
217the use of signing only keys for SSL client authentication.
218
219=item B<-nomaciter>, B<-noiter>
220
221these options affect the iteration counts on the MAC and key algorithms.
222Unless you wish to produce files compatible with MSIE 4.0 you should leave
223these options alone.
224
225To discourage attacks by using large dictionaries of common passwords the
226algorithm that derives keys from passwords can have an iteration count applied
227to it: this causes a certain part of the algorithm to be repeated and slows it
228down. The MAC is used to check the file integrity but since it will normally
229have the same password as the keys and certificates it could also be attacked.
230By default both MAC and encryption iteration counts are set to 2048, using
231these options the MAC and encryption iteration counts can be set to 1, since
232this reduces the file security you should not use these options unless you
233really have to. Most software supports both MAC and key iteration counts.
234MSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter>
235option.
236
237=item B<-maciter>
238
239This option is included for compatibility with previous versions, it used
240to be needed to use MAC iterations counts but they are now used by default.
241
242=item B<-rand file(s)>
243
244a file or files containing random data used to seed the random number
245generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
246Multiple files can be specified separated by a OS-dependent character.
247The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
248all others.
249
250=back
251
252=head1 NOTES
253
254Although there are a large number of options most of them are very rarely
255used. For PKCS#12 file parsing only B<-in> and B<-out> need to be used
256for PKCS#12 file creation B<-export> and B<-name> are also used.
257
258If none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present
259then all certificates will be output in the order they appear in the input
260PKCS#12 files. There is no guarantee that the first certificate present is
261the one corresponding to the private key. Certain software which requires
262a private key and certificate and assumes the first certificate in the
263file is the one corresponding to the private key: this may not always
264be the case. Using the B<-clcerts> option will solve this problem by only
265outputing the certificate corresponding to the private key. If the CA
266certificates are required then they can be output to a separate file using
267the B<-nokeys -cacerts> options to just output CA certificates.
268
269The B<-keypbe> and B<-certpbe> algorithms allow the precise encryption
270algorithms for private keys and certificates to be specified. Normally
271the defaults are fine but occasionally software can't handle triple DES
272encrypted private keys, then the option B<-keypbe PBE-SHA1-RC2-40> can
273be used to reduce the private key encryption to 40 bit RC2. A complete
274description of all algorithms is contained in the B<pkcs8> manual page.
275
276=head1 EXAMPLES
277
278Parse a PKCS#12 file and output it to a file:
279
280 openssl pkcs12 -in file.p12 -out file.pem
281
282Output only client certificates to a file:
283
284 openssl pkcs12 -in file.p12 -clcerts -out file.pem
285
286Don't encrypt the private key:
287
288 openssl pkcs12 -in file.p12 -out file.pem -nodes
289
290Print some info about a PKCS#12 file:
291
292 openssl pkcs12 -in file.p12 -info -noout
293
294Create a PKCS#12 file:
295
296 openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate"
297
298Include some extra certificates:
299
300 openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" \
301 -certfile othercerts.pem
302
303=head1 BUGS
304
305Some would argue that the PKCS#12 standard is one big bug :-)
306
307=head1 SEE ALSO
308
309L<pkcs8(1)|pkcs8(1)>
310
diff --git a/src/lib/libssl/src/doc/apps/pkcs7.pod b/src/lib/libssl/src/doc/apps/pkcs7.pod
new file mode 100644
index 0000000000..4e9bd6e46b
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/pkcs7.pod
@@ -0,0 +1,97 @@
1=pod
2
3=head1 NAME
4
5pkcs7 - PKCS#7 utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<pkcs7>
10[B<-inform PEM|DER>]
11[B<-outform PEM|DER>]
12[B<-in filename>]
13[B<-out filename>]
14[B<-print_certs>]
15[B<-text>]
16[B<-noout>]
17
18=head1 DESCRIPTION
19
20The B<pkcs7> command processes PKCS#7 files in DER or PEM format.
21
22=head1 COMMAND OPTIONS
23
24=over 4
25
26=item B<-inform DER|PEM>
27
28This specifies the input format. B<DER> format is DER encoded PKCS#7
29v1.5 structure.B<PEM> (the default) is a base64 encoded version of
30the DER form with header and footer lines.
31
32=item B<-outform DER|PEM>
33
34This specifies the output format, the options have the same meaning as the
35B<-inform> option.
36
37=item B<-in filename>
38
39This specifies the input filename to read from or standard input if this
40option is not specified.
41
42=item B<-out filename>
43
44specifies the output filename to write to or standard output by
45default.
46
47=item B<-print_certs>
48
49prints out any certificates or CRLs contained in the file. They are
50preceded by their subject and issuer names in one line format.
51
52=item B<-text>
53
54prints out certificates details in full rather than just subject and
55issuer names.
56
57=item B<-noout>
58
59don't output the encoded version of the PKCS#7 structure (or certificates
60is B<-print_certs> is set).
61
62=back
63
64=head1 EXAMPLES
65
66Convert a PKCS#7 file from PEM to DER:
67
68 openssl pkcs7 -in file.pem -outform DER -out file.der
69
70Output all certificates in a file:
71
72 openssl pkcs7 -in file.pem -print_certs -out certs.pem
73
74=head1 NOTES
75
76The PEM PKCS#7 format uses the header and footer lines:
77
78 -----BEGIN PKCS7-----
79 -----END PKCS7-----
80
81For compatability with some CAs it will also accept:
82
83 -----BEGIN CERTIFICATE-----
84 -----END CERTIFICATE-----
85
86=head1 RESTRICTIONS
87
88There is no option to print out all the fields of a PKCS#7 file.
89
90This PKCS#7 routines only understand PKCS#7 v 1.5 as specified in RFC2315 they
91cannot currently parse, for example, the new CMS as described in RFC2630.
92
93=head1 SEE ALSO
94
95L<crl2pkcs7(1)|crl2pkcs7(1)>
96
97=cut
diff --git a/src/lib/libssl/src/doc/apps/pkcs8.pod b/src/lib/libssl/src/doc/apps/pkcs8.pod
new file mode 100644
index 0000000000..a56b2dd002
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/pkcs8.pod
@@ -0,0 +1,235 @@
1=pod
2
3=head1 NAME
4
5pkcs8 - PKCS#8 format private key conversion tool
6
7=head1 SYNOPSIS
8
9B<openssl> B<pkcs8>
10[B<-topk8>]
11[B<-inform PEM|DER>]
12[B<-outform PEM|DER>]
13[B<-in filename>]
14[B<-passin arg>]
15[B<-out filename>]
16[B<-passout arg>]
17[B<-noiter>]
18[B<-nocrypt>]
19[B<-nooct>]
20[B<-embed>]
21[B<-nsdb>]
22[B<-v2 alg>]
23[B<-v1 alg>]
24
25=head1 DESCRIPTION
26
27The B<pkcs8> command processes private keys in PKCS#8 format. It can handle
28both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPrivateKeyInfo
29format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12 algorithms.
30
31=head1 COMMAND OPTIONS
32
33=over 4
34
35=item B<-topk8>
36
37Normally a PKCS#8 private key is expected on input and a traditional format
38private key will be written. With the B<-topk8> option the situation is
39reversed: it reads a traditional format private key and writes a PKCS#8
40format key.
41
42=item B<-inform DER|PEM>
43
44This specifies the input format. If a PKCS#8 format key is expected on input
45then either a B<DER> or B<PEM> encoded version of a PKCS#8 key will be
46expected. Otherwise the B<DER> or B<PEM> format of the traditional format
47private key is used.
48
49=item B<-outform DER|PEM>
50
51This specifies the output format, the options have the same meaning as the
52B<-inform> option.
53
54=item B<-in filename>
55
56This specifies the input filename to read a key from or standard input if this
57option is not specified. If the key is encrypted a pass phrase will be
58prompted for.
59
60=item B<-passin arg>
61
62the input file password source. For more information about the format of B<arg>
63see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
64
65=item B<-out filename>
66
67This specifies the output filename to write a key to or standard output by
68default. If any encryption options are set then a pass phrase will be
69prompted for. The output filename should B<not> be the same as the input
70filename.
71
72=item B<-passout arg>
73
74the output file password source. For more information about the format of B<arg>
75see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
76
77=item B<-nocrypt>
78
79PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo
80structures using an appropriate password based encryption algorithm. With
81this option an unencrypted PrivateKeyInfo structure is expected or output.
82This option does not encrypt private keys at all and should only be used
83when absolutely necessary. Certain software such as some versions of Java
84code signing software used unencrypted private keys.
85
86=item B<-nooct>
87
88This option generates RSA private keys in a broken format that some software
89uses. Specifically the private key should be enclosed in a OCTET STRING
90but some software just includes the structure itself without the
91surrounding OCTET STRING.
92
93=item B<-embed>
94
95This option generates DSA keys in a broken format. The DSA parameters are
96embedded inside the PrivateKey structure. In this form the OCTET STRING
97contains an ASN1 SEQUENCE consisting of two structures: a SEQUENCE containing
98the parameters and an ASN1 INTEGER containing the private key.
99
100=item B<-nsdb>
101
102This option generates DSA keys in a broken format compatible with Netscape
103private key databases. The PrivateKey contains a SEQUENCE consisting of
104the public and private keys respectively.
105
106=item B<-v2 alg>
107
108This option enables the use of PKCS#5 v2.0 algorithms. Normally PKCS#8
109private keys are encrypted with the password based encryption algorithm
110called B<pbeWithMD5AndDES-CBC> this uses 56 bit DES encryption but it
111was the strongest encryption algorithm supported in PKCS#5 v1.5. Using
112the B<-v2> option PKCS#5 v2.0 algorithms are used which can use any
113encryption algorithm such as 168 bit triple DES or 128 bit RC2 however
114not many implementations support PKCS#5 v2.0 yet. If you are just using
115private keys with OpenSSL then this doesn't matter.
116
117The B<alg> argument is the encryption algorithm to use, valid values include
118B<des>, B<des3> and B<rc2>. It is recommended that B<des3> is used.
119
120=item B<-v1 alg>
121
122This option specifies a PKCS#5 v1.5 or PKCS#12 algorithm to use. A complete
123list of possible algorithms is included below.
124
125=back
126
127=head1 NOTES
128
129The encrypted form of a PEM encode PKCS#8 files uses the following
130headers and footers:
131
132 -----BEGIN ENCRYPTED PRIVATE KEY-----
133 -----END ENCRYPTED PRIVATE KEY-----
134
135The unencrypted form uses:
136
137 -----BEGIN PRIVATE KEY-----
138 -----END PRIVATE KEY-----
139
140Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration
141counts are more secure that those encrypted using the traditional
142SSLeay compatible formats. So if additional security is considered
143important the keys should be converted.
144
145The default encryption is only 56 bits because this is the encryption
146that most current implementations of PKCS#8 will support.
147
148Some software may use PKCS#12 password based encryption algorithms
149with PKCS#8 format private keys: these are handled automatically
150but there is no option to produce them.
151
152It is possible to write out DER encoded encrypted private keys in
153PKCS#8 format because the encryption details are included at an ASN1
154level whereas the traditional format includes them at a PEM level.
155
156=head1 PKCS#5 v1.5 and PKCS#12 algorithms.
157
158Various algorithms can be used with the B<-v1> command line option,
159including PKCS#5 v1.5 and PKCS#12. These are described in more detail
160below.
161
162=over 4
163
164=item B<PBE-MD2-DES PBE-MD5-DES>
165
166These algorithms were included in the original PKCS#5 v1.5 specification.
167They only offer 56 bits of protection since they both use DES.
168
169=item B<PBE-SHA1-RC2-64 PBE-MD2-RC2-64 PBE-MD5-RC2-64 PBE-SHA1-DES>
170
171These algorithms are not mentioned in the original PKCS#5 v1.5 specification
172but they use the same key derivation algorithm and are supported by some
173software. They are mentioned in PKCS#5 v2.0. They use either 64 bit RC2 or
17456 bit DES.
175
176=item B<PBE-SHA1-RC4-128 PBE-SHA1-RC4-40 PBE-SHA1-3DES PBE-SHA1-2DES PBE-SHA1-RC2-128 PBE-SHA1-RC2-40>
177
178These algorithms use the PKCS#12 password based encryption algorithm and
179allow strong encryption algorithms like triple DES or 128 bit RC2 to be used.
180
181=back
182
183=head1 EXAMPLES
184
185Convert a private from traditional to PKCS#5 v2.0 format using triple
186DES:
187
188 openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem
189
190Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm
191(DES):
192
193 openssl pkcs8 -in key.pem -topk8 -out enckey.pem
194
195Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm
196(3DES):
197
198 openssl pkcs8 -in key.pem -topk8 -out enckey.pem -v1 PBE-SHA1-3DES
199
200Read a DER unencrypted PKCS#8 format private key:
201
202 openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem
203
204Convert a private key from any PKCS#8 format to traditional format:
205
206 openssl pkcs8 -in pk8.pem -out key.pem
207
208=head1 STANDARDS
209
210Test vectors from this PKCS#5 v2.0 implementation were posted to the
211pkcs-tng mailing list using triple DES, DES and RC2 with high iteration
212counts, several people confirmed that they could decrypt the private
213keys produced and Therefore it can be assumed that the PKCS#5 v2.0
214implementation is reasonably accurate at least as far as these
215algorithms are concerned.
216
217The format of PKCS#8 DSA (and other) private keys is not well documented:
218it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's default DSA
219PKCS#8 private key format complies with this standard.
220
221=head1 BUGS
222
223There should be an option that prints out the encryption algorithm
224in use and other details such as the iteration count.
225
226PKCS#8 using triple DES and PKCS#5 v2.0 should be the default private
227key format for OpenSSL: for compatibility several of the utilities use
228the old format at present.
229
230=head1 SEE ALSO
231
232L<dsa(1)|dsa(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>,
233L<gendsa(1)|gendsa(1)>
234
235=cut
diff --git a/src/lib/libssl/src/doc/apps/rand.pod b/src/lib/libssl/src/doc/apps/rand.pod
new file mode 100644
index 0000000000..f81eab0457
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/rand.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5rand - generate pseudo-random bytes
6
7=head1 SYNOPSIS
8
9B<openssl rand>
10[B<-out> I<file>]
11[B<-rand> I<file(s)>]
12[B<-base64>]
13I<num>
14
15=head1 DESCRIPTION
16
17The B<rand> command outputs I<num> pseudo-random bytes after seeding
18the random number generater once. As in other B<openssl> command
19line tools, PRNG seeding uses the file I<$HOME/>B<.rnd> or B<.rnd>
20in addition to the files given in the B<-rand> option. A new
21I<$HOME>/B<.rnd> or B<.rnd> file will be written back if enough
22seeding was obtained from these sources.
23
24=head1 OPTIONS
25
26=over 4
27
28=item B<-out> I<file>
29
30Write to I<file> instead of standard output.
31
32=item B<-rand> I<file(s)>
33
34Use specified file or files or EGD socket (see L<RAND_egd(3)|RAND_egd(3)>)
35for seeding the random number generator.
36Multiple files can be specified separated by a OS-dependent character.
37The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
38all others.
39
40=item B<-base64>
41
42Perform base64 encoding on the output.
43
44=back
45
46=head1 SEE ALSO
47
48L<RAND_bytes(3)|RAND_bytes(3)>
49
50=cut
diff --git a/src/lib/libssl/src/doc/apps/req.pod b/src/lib/libssl/src/doc/apps/req.pod
new file mode 100644
index 0000000000..fde6ff2e9f
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/req.pod
@@ -0,0 +1,528 @@
1
2=pod
3
4=head1 NAME
5
6req - PKCS#10 certificate and certificate generating utility.
7
8=head1 SYNOPSIS
9
10B<openssl> B<req>
11[B<-inform PEM|DER>]
12[B<-outform PEM|DER>]
13[B<-in filename>]
14[B<-passin arg>]
15[B<-out filename>]
16[B<-passout arg>]
17[B<-text>]
18[B<-noout>]
19[B<-verify>]
20[B<-modulus>]
21[B<-new>]
22[B<-newkey rsa:bits>]
23[B<-newkey dsa:file>]
24[B<-nodes>]
25[B<-key filename>]
26[B<-keyform PEM|DER>]
27[B<-keyout filename>]
28[B<-[md5|sha1|md2|mdc2]>]
29[B<-config filename>]
30[B<-x509>]
31[B<-days n>]
32[B<-asn1-kludge>]
33[B<-newhdr>]
34[B<-extensions section>]
35[B<-reqexts section>]
36
37=head1 DESCRIPTION
38
39The B<req> command primarily creates and processes certificate requests
40in PKCS#10 format. It can additionally create self signed certificates
41for use as root CAs for example.
42
43=head1 COMMAND OPTIONS
44
45=over 4
46
47=item B<-inform DER|PEM>
48
49This specifies the input format. The B<DER> option uses an ASN1 DER encoded
50form compatible with the PKCS#10. The B<PEM> form is the default format: it
51consists of the B<DER> format base64 encoded with additional header and
52footer lines.
53
54=item B<-outform DER|PEM>
55
56This specifies the output format, the options have the same meaning as the
57B<-inform> option.
58
59=item B<-in filename>
60
61This specifies the input filename to read a request from or standard input
62if this option is not specified. A request is only read if the creation
63options (B<-new> and B<-newkey>) are not specified.
64
65=item B<-passin arg>
66
67the input file password source. For more information about the format of B<arg>
68see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
69
70=item B<-out filename>
71
72This specifies the output filename to write to or standard output by
73default.
74
75=item B<-passout arg>
76
77the output file password source. For more information about the format of B<arg>
78see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
79
80=item B<-text>
81
82prints out the certificate request in text form.
83
84=item B<-noout>
85
86this option prevents output of the encoded version of the request.
87
88=item B<-modulus>
89
90this option prints out the value of the modulus of the public key
91contained in the request.
92
93=item B<-verify>
94
95verifies the signature on the request.
96
97=item B<-new>
98
99this option generates a new certificate request. It will prompt
100the user for the relevant field values. The actual fields
101prompted for and their maximum and minimum sizes are specified
102in the configuration file and any requested extensions.
103
104If the B<-key> option is not used it will generate a new RSA private
105key using information specified in the configuration file.
106
107=item B<-newkey arg>
108
109this option creates a new certificate request and a new private
110key. The argument takes one of two forms. B<rsa:nbits>, where
111B<nbits> is the number of bits, generates an RSA key B<nbits>
112in size. B<dsa:filename> generates a DSA key using the parameters
113in the file B<filename>.
114
115=item B<-key filename>
116
117This specifies the file to read the private key from. It also
118accepts PKCS#8 format private keys for PEM format files.
119
120=item B<-keyform PEM|DER>
121
122the format of the private key file specified in the B<-key>
123argument. PEM is the default.
124
125=item B<-keyout filename>
126
127this gives the filename to write the newly created private key to.
128If this option is not specified then the filename present in the
129configuration file is used.
130
131=item B<-nodes>
132
133if this option is specified then if a private key is created it
134will not be encrypted.
135
136=item B<-[md5|sha1|md2|mdc2]>
137
138this specifies the message digest to sign the request with. This
139overrides the digest algorithm specified in the configuration file.
140This option is ignored for DSA requests: they always use SHA1.
141
142=item B<-config filename>
143
144this allows an alternative configuration file to be specified,
145this overrides the compile time filename or any specified in
146the B<OPENSSL_CONF> environment variable.
147
148=item B<-x509>
149
150this option outputs a self signed certificate instead of a certificate
151request. This is typically used to generate a test certificate or
152a self signed root CA. The extensions added to the certificate
153(if any) are specified in the configuration file.
154
155=item B<-days n>
156
157when the B<-x509> option is being used this specifies the number of
158days to certify the certificate for. The default is 30 days.
159
160=item B<-extensions section>
161=item B<-reqexts section>
162
163these options specify alternative sections to include certificate
164extensions (if the B<-x509> option is present) or certificate
165request extensions. This allows several different sections to
166be used in the same configuration file to specify requests for
167a variety of purposes.
168
169=item B<-asn1-kludge>
170
171by default the B<req> command outputs certificate requests containing
172no attributes in the correct PKCS#10 format. However certain CAs will only
173accept requests containing no attributes in an invalid form: this
174option produces this invalid format.
175
176More precisely the B<Attributes> in a PKCS#10 certificate request
177are defined as a B<SET OF Attribute>. They are B<not OPTIONAL> so
178if no attributes are present then they should be encoded as an
179empty B<SET OF>. The invalid form does not include the empty
180B<SET OF> whereas the correct form does.
181
182It should be noted that very few CAs still require the use of this option.
183
184=item B<-newhdr>
185
186Adds the word B<NEW> to the PEM file header and footer lines on the outputed
187request. Some software (Netscape certificate server) and some CAs need this.
188
189=back
190
191=head1 CONFIGURATION FILE FORMAT
192
193The configuration options are specified in the B<req> section of
194the configuration file. As with all configuration files if no
195value is specified in the specific section (i.e. B<req>) then
196the initial unnamed or B<default> section is searched too.
197
198The options available are described in detail below.
199
200=over 4
201
202=item B<input_password output_password>
203
204The passwords for the input private key file (if present) and
205the output private key file (if one will be created). The
206command line options B<passin> and B<passout> override the
207configuration file values.
208
209=item B<default_bits>
210
211This specifies the default key size in bits. If not specified then
212512 is used. It is used if the B<-new> option is used. It can be
213overridden by using the B<-newkey> option.
214
215=item B<default_keyfile>
216
217This is the default filename to write a private key to. If not
218specified the key is written to standard output. This can be
219overridden by the B<-keyout> option.
220
221=item B<oid_file>
222
223This specifies a file containing additional B<OBJECT IDENTIFIERS>.
224Each line of the file should consist of the numerical form of the
225object identifier followed by white space then the short name followed
226by white space and finally the long name.
227
228=item B<oid_section>
229
230This specifies a section in the configuration file containing extra
231object identifiers. Each line should consist of the short name of the
232object identifier followed by B<=> and the numerical form. The short
233and long names are the same when this option is used.
234
235=item B<RANDFILE>
236
237This specifies a filename in which random number seed information is
238placed and read from, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
239It is used for private key generation.
240
241=item B<encrypt_key>
242
243If this is set to B<no> then if a private key is generated it is
244B<not> encrypted. This is equivalent to the B<-nodes> command line
245option. For compatibility B<encrypt_rsa_key> is an equivalent option.
246
247=item B<default_md>
248
249This option specifies the digest algorithm to use. Possible values
250include B<md5 sha1 mdc2>. If not present then MD5 is used. This
251option can be overridden on the command line.
252
253=item B<string_mask>
254
255This option masks out the use of certain string types in certain
256fields. Most users will not need to change this option.
257
258It can be set to several values B<default> which is also the default
259option uses PrintableStrings, T61Strings and BMPStrings if the
260B<pkix> value is used then only PrintableStrings and BMPStrings will
261be used. This follows the PKIX recommendation in RFC2459. If the
262B<utf8only> option is used then only UTF8Strings will be used: this
263is the PKIX recommendation in RFC2459 after 2003. Finally the B<nombstr>
264option just uses PrintableStrings and T61Strings: certain software has
265problems with BMPStrings and UTF8Strings: in particular Netscape.
266
267=item B<req_extensions>
268
269this specifies the configuration file section containing a list of
270extensions to add to the certificate request. It can be overridden
271by the B<-reqexts> command line switch.
272
273=item B<x509_extensions>
274
275this specifies the configuration file section containing a list of
276extensions to add to certificate generated when the B<-x509> switch
277is used. It can be overridden by the B<-extensions> command line switch.
278
279=item B<prompt>
280
281if set to the value B<no> this disables prompting of certificate fields
282and just takes values from the config file directly. It also changes the
283expected format of the B<distinguished_name> and B<attributes> sections.
284
285=item B<attributes>
286
287this specifies the section containing any request attributes: its format
288is the same as B<distinguished_name>. Typically these may contain the
289challengePassword or unstructuredName types. They are currently ignored
290by OpenSSL's request signing utilities but some CAs might want them.
291
292=item B<distinguished_name>
293
294This specifies the section containing the distinguished name fields to
295prompt for when generating a certificate or certificate request. The format
296is described in the next section.
297
298=back
299
300=head1 DISTINGUISHED NAME AND ATTRIBUTE SECTION FORMAT
301
302There are two separate formats for the distinguished name and attribute
303sections. If the B<prompt> option is set to B<no> then these sections
304just consist of field names and values: for example,
305
306 CN=My Name
307 OU=My Organization
308 emailAddress=someone@somewhere.org
309
310This allows external programs (e.g. GUI based) to generate a template file
311with all the field names and values and just pass it to B<req>. An example
312of this kind of configuration file is contained in the B<EXAMPLES> section.
313
314Alternatively if the B<prompt> option is absent or not set to B<no> then the
315file contains field prompting information. It consists of lines of the form:
316
317 fieldName="prompt"
318 fieldName_default="default field value"
319 fieldName_min= 2
320 fieldName_max= 4
321
322"fieldName" is the field name being used, for example commonName (or CN).
323The "prompt" string is used to ask the user to enter the relevant
324details. If the user enters nothing then the default value is used if no
325default value is present then the field is omitted. A field can
326still be omitted if a default value is present if the user just
327enters the '.' character.
328
329The number of characters entered must be between the fieldName_min and
330fieldName_max limits: there may be additional restrictions based
331on the field being used (for example countryName can only ever be
332two characters long and must fit in a PrintableString).
333
334Some fields (such as organizationName) can be used more than once
335in a DN. This presents a problem because configuration files will
336not recognize the same name occurring twice. To avoid this problem
337if the fieldName contains some characters followed by a full stop
338they will be ignored. So for example a second organizationName can
339be input by calling it "1.organizationName".
340
341The actual permitted field names are any object identifier short or
342long names. These are compiled into OpenSSL and include the usual
343values such as commonName, countryName, localityName, organizationName,
344organizationUnitName, stateOrPrivinceName. Additionally emailAddress
345is include as well as name, surname, givenName initials and dnQualifier.
346
347Additional object identifiers can be defined with the B<oid_file> or
348B<oid_section> options in the configuration file. Any additional fields
349will be treated as though they were a DirectoryString.
350
351
352=head1 EXAMPLES
353
354Examine and verify certificate request:
355
356 openssl req -in req.pem -text -verify -noout
357
358Create a private key and then generate a certificate request from it:
359
360 openssl genrsa -out key.pem 1024
361 openssl req -new -key key.pem -out req.pem
362
363The same but just using req:
364
365 openssl req -newkey rsa:1024 -keyout key.pem -out req.pem
366
367Generate a self signed root certificate:
368
369 openssl req -x509 -newkey rsa:1024 -keyout key.pem -out req.pem
370
371Example of a file pointed to by the B<oid_file> option:
372
373 1.2.3.4 shortName A longer Name
374 1.2.3.6 otherName Other longer Name
375
376Example of a section pointed to by B<oid_section> making use of variable
377expansion:
378
379 testoid1=1.2.3.5
380 testoid2=${testoid1}.6
381
382Sample configuration file prompting for field values:
383
384 [ req ]
385 default_bits = 1024
386 default_keyfile = privkey.pem
387 distinguished_name = req_distinguished_name
388 attributes = req_attributes
389 x509_extensions = v3_ca
390
391 dirstring_type = nobmp
392
393 [ req_distinguished_name ]
394 countryName = Country Name (2 letter code)
395 countryName_default = AU
396 countryName_min = 2
397 countryName_max = 2
398
399 localityName = Locality Name (eg, city)
400
401 organizationalUnitName = Organizational Unit Name (eg, section)
402
403 commonName = Common Name (eg, YOUR name)
404 commonName_max = 64
405
406 emailAddress = Email Address
407 emailAddress_max = 40
408
409 [ req_attributes ]
410 challengePassword = A challenge password
411 challengePassword_min = 4
412 challengePassword_max = 20
413
414 [ v3_ca ]
415
416 subjectKeyIdentifier=hash
417 authorityKeyIdentifier=keyid:always,issuer:always
418 basicConstraints = CA:true
419
420Sample configuration containing all field values:
421
422
423 RANDFILE = $ENV::HOME/.rnd
424
425 [ req ]
426 default_bits = 1024
427 default_keyfile = keyfile.pem
428 distinguished_name = req_distinguished_name
429 attributes = req_attributes
430 prompt = no
431 output_password = mypass
432
433 [ req_distinguished_name ]
434 C = GB
435 ST = Test State or Province
436 L = Test Locality
437 O = Organization Name
438 OU = Organizational Unit Name
439 CN = Common Name
440 emailAddress = test@email.address
441
442 [ req_attributes ]
443 challengePassword = A challenge password
444
445
446=head1 NOTES
447
448The header and footer lines in the B<PEM> format are normally:
449
450 -----BEGIN CERTIFICATE REQUEST----
451 -----END CERTIFICATE REQUEST----
452
453some software (some versions of Netscape certificate server) instead needs:
454
455 -----BEGIN NEW CERTIFICATE REQUEST----
456 -----END NEW CERTIFICATE REQUEST----
457
458which is produced with the B<-newhdr> option but is otherwise compatible.
459Either form is accepted transparently on input.
460
461The certificate requests generated by B<Xenroll> with MSIE have extensions
462added. It includes the B<keyUsage> extension which determines the type of
463key (signature only or general purpose) and any additional OIDs entered
464by the script in an extendedKeyUsage extension.
465
466=head1 DIAGNOSTICS
467
468The following messages are frequently asked about:
469
470 Using configuration from /some/path/openssl.cnf
471 Unable to load config info
472
473This is followed some time later by...
474
475 unable to find 'distinguished_name' in config
476 problems making Certificate Request
477
478The first error message is the clue: it can't find the configuration
479file! Certain operations (like examining a certificate request) don't
480need a configuration file so its use isn't enforced. Generation of
481certificates or requests however does need a configuration file. This
482could be regarded as a bug.
483
484Another puzzling message is this:
485
486 Attributes:
487 a0:00
488
489this is displayed when no attributes are present and the request includes
490the correct empty B<SET OF> structure (the DER encoding of which is 0xa0
4910x00). If you just see:
492
493 Attributes:
494
495then the B<SET OF> is missing and the encoding is technically invalid (but
496it is tolerated). See the description of the command line option B<-asn1-kludge>
497for more information.
498
499=head1 ENVIRONMENT VARIABLES
500
501The variable B<OPENSSL_CONF> if defined allows an alternative configuration
502file location to be specified, it will be overridden by the B<-config> command
503line switch if it is present. For compatibility reasons the B<SSLEAY_CONF>
504environment variable serves the same purpose but its use is discouraged.
505
506=head1 BUGS
507
508OpenSSL's handling of T61Strings (aka TeletexStrings) is broken: it effectively
509treats them as ISO-8859-1 (Latin 1), Netscape and MSIE have similar behaviour.
510This can cause problems if you need characters that aren't available in
511PrintableStrings and you don't want to or can't use BMPStrings.
512
513As a consequence of the T61String handling the only correct way to represent
514accented characters in OpenSSL is to use a BMPString: unfortunately Netscape
515currently chokes on these. If you have to use accented characters with Netscape
516and MSIE then you currently need to use the invalid T61String form.
517
518The current prompting is not very friendly. It doesn't allow you to confirm what
519you've just entered. Other things like extensions in certificate requests are
520statically defined in the configuration file. Some of these: like an email
521address in subjectAltName should be input by the user.
522
523=head1 SEE ALSO
524
525L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>,
526L<gendsa(1)|gendsa(1)>, L<config(5)|config(5)>
527
528=cut
diff --git a/src/lib/libssl/src/doc/apps/rsa.pod b/src/lib/libssl/src/doc/apps/rsa.pod
new file mode 100644
index 0000000000..62ad62e23d
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/rsa.pod
@@ -0,0 +1,156 @@
1
2=pod
3
4=head1 NAME
5
6rsa - RSA key processing tool
7
8=head1 SYNOPSIS
9
10B<openssl> B<rsa>
11[B<-inform PEM|NET|DER>]
12[B<-outform PEM|NET|DER>]
13[B<-in filename>]
14[B<-passin arg>]
15[B<-out filename>]
16[B<-passout arg>]
17[B<-des>]
18[B<-des3>]
19[B<-idea>]
20[B<-text>]
21[B<-noout>]
22[B<-modulus>]
23[B<-check>]
24[B<-pubin>]
25[B<-pubout>]
26
27=head1 DESCRIPTION
28
29The B<rsa> command processes RSA keys. They can be converted between various
30forms and their components printed out. B<Note> this command uses the
31traditional SSLeay compatible format for private key encryption: newer
32applications should use the more secure PKCS#8 format using the B<pkcs8>
33utility.
34
35=head1 COMMAND OPTIONS
36
37=over 4
38
39=item B<-inform DER|NET|PEM>
40
41This specifies the input format. The B<DER> option uses an ASN1 DER encoded
42form compatible with the PKCS#1 RSAPrivateKey or SubjectPublicKeyInfo format.
43The B<PEM> form is the default format: it consists of the B<DER> format base64
44encoded with additional header and footer lines. On input PKCS#8 format private
45keys are also accepted. The B<NET> form is a format compatible with older Netscape
46servers and MS IIS, this uses unsalted RC4 for its encryption. It is not very
47secure and so should only be used when necessary.
48
49=item B<-outform DER|NET|PEM>
50
51This specifies the output format, the options have the same meaning as the
52B<-inform> option.
53
54=item B<-in filename>
55
56This specifies the input filename to read a key from or standard input if this
57option is not specified. If the key is encrypted a pass phrase will be
58prompted for.
59
60=item B<-passin arg>
61
62the input file password source. For more information about the format of B<arg>
63see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
64
65=item B<-out filename>
66
67This specifies the output filename to write a key to or standard output if this
68option is not specified. If any encryption options are set then a pass phrase
69will be prompted for. The output filename should B<not> be the same as the input
70filename.
71
72=item B<-passout password>
73
74the output file password source. For more information about the format of B<arg>
75see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
76
77=item B<-des|-des3|-idea>
78
79These options encrypt the private key with the DES, triple DES, or the
80IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
81If none of these options is specified the key is written in plain text. This
82means that using the B<rsa> utility to read in an encrypted key with no
83encryption option can be used to remove the pass phrase from a key, or by
84setting the encryption options it can be use to add or change the pass phrase.
85These options can only be used with PEM format output files.
86
87=item B<-text>
88
89prints out the various public or private key components in
90plain text in addition to the encoded version.
91
92=item B<-noout>
93
94this option prevents output of the encoded version of the key.
95
96=item B<-modulus>
97
98this option prints out the value of the modulus of the key.
99
100=item B<-check>
101
102this option checks the consistency of an RSA private key.
103
104=item B<-pubin>
105
106by default a private key is read from the input file: with this
107option a public key is read instead.
108
109=item B<-pubout>
110
111by default a private key is output: with this option a public
112key will be output instead. This option is automatically set if
113the input is a public key.
114
115=back
116
117=head1 NOTES
118
119The PEM private key format uses the header and footer lines:
120
121 -----BEGIN RSA PRIVATE KEY-----
122 -----END RSA PRIVATE KEY-----
123
124The PEM public key format uses the header and footer lines:
125
126 -----BEGIN PUBLIC KEY-----
127 -----END PUBLIC KEY-----
128
129=head1 EXAMPLES
130
131To remove the pass phrase on an RSA private key:
132
133 openssl rsa -in key.pem -out keyout.pem
134
135To encrypt a private key using triple DES:
136
137 openssl rsa -in key.pem -des3 -out keyout.pem
138
139To convert a private key from PEM to DER format:
140
141 openssl rsa -in key.pem -outform DER -out keyout.der
142
143To print out the components of a private key to standard output:
144
145 openssl rsa -in key.pem -text -noout
146
147To just output the public part of a private key:
148
149 openssl rsa -in key.pem -pubout -out pubkey.pem
150
151=head1 SEE ALSO
152
153L<pkcs8(1)|pkcs8(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
154L<gendsa(1)|gendsa(1)>
155
156=cut
diff --git a/src/lib/libssl/src/doc/apps/rsautl.pod b/src/lib/libssl/src/doc/apps/rsautl.pod
new file mode 100644
index 0000000000..7a334bc8d6
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/rsautl.pod
@@ -0,0 +1,183 @@
1=pod
2
3=head1 NAME
4
5rsautl - RSA utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<rsautl>
10[B<-in file>]
11[B<-out file>]
12[B<-inkey file>]
13[B<-pubin>]
14[B<-certin>]
15[B<-sign>]
16[B<-verify>]
17[B<-encrypt>]
18[B<-decrypt>]
19[B<-pkcs>]
20[B<-ssl>]
21[B<-raw>]
22[B<-hexdump>]
23[B<-asn1parse>]
24
25=head1 DESCRIPTION
26
27The B<rsautl> command can be used to sign, verify, encrypt and decrypt
28data using the RSA algorithm.
29
30=head1 COMMAND OPTIONS
31
32=over 4
33
34=item B<-in filename>
35
36This specifies the input filename to read data from or standard input
37if this option is not specified.
38
39=item B<-out filename>
40
41specifies the output filename to write to or standard output by
42default.
43
44=item B<-inkey file>
45
46the input key file, by default it should be an RSA private key.
47
48=item B<-pubin>
49
50the input file is an RSA public key.
51
52=item B<-certin>
53
54the input is a certificate containing an RSA public key.
55
56=item B<-sign>
57
58sign the input data and output the signed result. This requires
59and RSA private key.
60
61=item B<-verify>
62
63verify the input data and output the recovered data.
64
65=item B<-encrypt>
66
67encrypt the input data using an RSA public key.
68
69=item B<-decrypt>
70
71decrypt the input data using an RSA private key.
72
73=item B<-pkcs, -oaep, -ssl, -raw>
74
75the padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
76special padding used in SSL v2 backwards compatible handshakes,
77or no padding, respectively.
78For signatures, only B<-pkcs> and B<-raw> can be used.
79
80=item B<-hexdump>
81
82hex dump the output data.
83
84=item B<-asn1parse>
85
86asn1parse the output data, this is useful when combined with the
87B<-verify> option.
88
89=back
90
91=head1 NOTES
92
93B<rsautl> because it uses the RSA algorithm directly can only be
94used to sign or verify small pieces of data.
95
96=head1 EXAMPLES
97
98Sign some data using a private key:
99
100 openssl rsautl -sign -in file -inkey key.pem -out sig
101
102Recover the signed data
103
104 openssl rsautl -sign -in sig -inkey key.pem
105
106Examine the raw signed data:
107
108 openssl rsautl -sign -in file -inkey key.pem -raw -hexdump
109
110 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
111 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
112 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
113 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
114 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
115 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
116 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
117 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world
118
119The PKCS#1 block formatting is evident from this. If this was done using
120encrypt and decrypt the block would have been of type 2 (the second byte)
121and random padding data visible instead of the 0xff bytes.
122
123It is possible to analyse the signature of certificates using this
124utility in conjunction with B<asn1parse>. Consider the self signed
125example in certs/pca-cert.pem . Running B<asn1parse> as follows yields:
126
127 openssl asn1parse -in pca-cert.pem
128
129 0:d=0 hl=4 l= 742 cons: SEQUENCE
130 4:d=1 hl=4 l= 591 cons: SEQUENCE
131 8:d=2 hl=2 l= 3 cons: cont [ 0 ]
132 10:d=3 hl=2 l= 1 prim: INTEGER :02
133 13:d=2 hl=2 l= 1 prim: INTEGER :00
134 16:d=2 hl=2 l= 13 cons: SEQUENCE
135 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
136 29:d=3 hl=2 l= 0 prim: NULL
137 31:d=2 hl=2 l= 92 cons: SEQUENCE
138 33:d=3 hl=2 l= 11 cons: SET
139 35:d=4 hl=2 l= 9 cons: SEQUENCE
140 37:d=5 hl=2 l= 3 prim: OBJECT :countryName
141 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU
142 ....
143 599:d=1 hl=2 l= 13 cons: SEQUENCE
144 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
145 612:d=2 hl=2 l= 0 prim: NULL
146 614:d=1 hl=3 l= 129 prim: BIT STRING
147
148
149The final BIT STRING contains the actual signature. It can be extracted with:
150
151 openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
152
153The certificate public key can be extracted with:
154
155 openssl x509 -in test/testx509.pem -pubout -noout >pubkey.pem
156
157The signature can be analysed with:
158
159 openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
160
161 0:d=0 hl=2 l= 32 cons: SEQUENCE
162 2:d=1 hl=2 l= 12 cons: SEQUENCE
163 4:d=2 hl=2 l= 8 prim: OBJECT :md5
164 14:d=2 hl=2 l= 0 prim: NULL
165 16:d=1 hl=2 l= 16 prim: OCTET STRING
166 0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
167
168This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
169the digest used was md5. The actual part of the certificate that was signed can
170be extracted with:
171
172 openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
173
174and its digest computed with:
175
176 openssl md5 -c tbs
177 MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
178
179which it can be seen agrees with the recovered value above.
180
181=head1 SEE ALSO
182
183L<dgst(1)|dgst(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>
diff --git a/src/lib/libssl/src/doc/apps/s_client.pod b/src/lib/libssl/src/doc/apps/s_client.pod
new file mode 100644
index 0000000000..3ede134164
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/s_client.pod
@@ -0,0 +1,213 @@
1
2=pod
3
4=head1 NAME
5
6s_client - SSL/TLS client program
7
8=head1 SYNOPSIS
9
10B<openssl> B<s_client>
11[B<-connect> host:port>]
12[B<-verify depth>]
13[B<-cert filename>]
14[B<-key filename>]
15[B<-CApath directory>]
16[B<-CAfile filename>]
17[B<-reconnect>]
18[B<-pause>]
19[B<-showcerts>]
20[B<-debug>]
21[B<-nbio_test>]
22[B<-state>]
23[B<-nbio>]
24[B<-crlf>]
25[B<-quiet>]
26[B<-ssl2>]
27[B<-ssl3>]
28[B<-tls1>]
29[B<-no_ssl2>]
30[B<-no_ssl3>]
31[B<-no_tls1>]
32[B<-bugs>]
33[B<-cipher cipherlist>]
34
35=head1 DESCRIPTION
36
37The B<s_client> command implements a generic SSL/TLS client which connects
38to a remote host using SSL/TLS. It is a I<very> useful diagnostic tool for
39SSL servers.
40
41=head1 OPTIONS
42
43=over 4
44
45=item B<-connect host:port>
46
47This specifies the host and optional port to connect to. If not specified
48then an attempt is made to connect to the local host on port 4433.
49
50=item B<-cert certname>
51
52The certificate to use, if one is requested by the server. The default is
53not to use a certificate.
54
55=item B<-key keyfile>
56
57The private key to use. If not specified then the certificate file will
58be used.
59
60=item B<-verify depth>
61
62The verify depth to use. This specifies the maximum length of the
63server certificate chain and turns on server certificate verification.
64Currently the verify operation continues after errors so all the problems
65with a certificate chain can be seen. As a side effect the connection
66will never fail due to a server certificate verify failure.
67
68=item B<-CApath directory>
69
70The directory to use for server certificate verification. This directory
71must be in "hash format", see B<verify> for more information. These are
72also used when building the client certificate chain.
73
74=item B<-CAfile file>
75
76A file containing trusted certificates to use during server authentication
77and to use when attempting to build the client certificate chain.
78
79=item B<-reconnect>
80
81reconnects to the same server 5 times using the same session ID, this can
82be used as a test that session caching is working.
83
84=item B<-pause>
85
86pauses 1 second between each read and write call.
87
88=item B<-showcerts>
89
90display the whole server certificate chain: normally only the server
91certificate itself is displayed.
92
93=item B<-prexit>
94
95print session information when the program exits. This will always attempt
96to print out information even if the connection fails. Normally information
97will only be printed out once if the connection succeeds. This option is useful
98because the cipher in use may be renegotiated or the connection may fail
99because a client certificate is required or is requested only after an
100attempt is made to access a certain URL. Note: the output produced by this
101option is not always accurate because a connection might never have been
102established.
103
104=item B<-state>
105
106prints out the SSL session states.
107
108=item B<-debug>
109
110print extensive debugging information including a hex dump of all traffic.
111
112=item B<-nbio_test>
113
114tests non-blocking I/O
115
116=item B<-nbio>
117
118turns on non-blocking I/O
119
120=item B<-crlf>
121
122this option translated a line feed from the terminal into CR+LF as required
123by some servers.
124
125=item B<-quiet>
126
127inhibit printing of session and certificate information.
128
129=item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>
130
131these options disable the use of certain SSL or TLS protocols. By default
132the initial handshake uses a method which should be compatible with all
133servers and permit them to use SSL v3, SSL v2 or TLS as appropriate.
134
135Unfortunately there are a lot of ancient and broken servers in use which
136cannot handle this technique and will fail to connect. Some servers only
137work if TLS is turned off with the B<-no_tls> option others will only
138support SSL v2 and may need the B<-ssl2> option.
139
140=item B<-bugs>
141
142there are several known bug in SSL and TLS implementations. Adding this
143option enables various workarounds.
144
145=item B<-cipher cipherlist>
146
147this allows the cipher list sent by the client to be modified. Although
148the server determines which cipher suite is used it should take the first
149supported cipher in the list sent by the client. See the B<ciphers>
150command for more information.
151
152=back
153
154=head1 CONNECTED COMMANDS
155
156If a connection is established with an SSL server then any data received
157from the server is displayed and any key presses will be sent to the
158server. If the line begins with an B<R> then the session will be
159renegotiated. If the line begins with a B<Q> the connection will be closed
160down.
161
162=head1 NOTES
163
164B<s_client> can be used to debug SSL servers. To connect to an SSL HTTP
165server the command:
166
167 openssl s_client -connect servername:443
168
169would typically be used (https uses port 443). If the connection succeeds
170then an HTTP command can be given such as "GET /" to retrieve a web page.
171
172If the handshake fails then there are several possible causes, if it is
173nothing obvious like no client certificate then the B<-bugs>, B<-ssl2>,
174B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1> can be tried
175in case it is a buggy server. In particular you should play with these
176options B<before> submitting a bug report to an OpenSSL mailing list.
177
178A frequent problem when attempting to get client certificates working
179is that a web client complains it has no certificates or gives an empty
180list to choose from. This is normally because the server is not sending
181the clients certificate authority in its "acceptable CA list" when it
182requests a certificate. By using B<s_client> the CA list can be viewed
183and checked. However some servers only request client authentication
184after a specific URL is requested. To obtain the list in this case it
185is necessary to use the B<-prexit> command and send an HTTP request
186for an appropriate page.
187
188If a certificate is specified on the command line using the B<-cert>
189option it will not be used unless the server specifically requests
190a client certificate. Therefor merely including a client certificate
191on the command line is no guarantee that the certificate works.
192
193If there are problems verifying a server certificate then the
194B<-showcerts> option can be used to show the whole chain.
195
196=head1 BUGS
197
198Because this program has a lot of options and also because some of
199the techniques used are rather old, the C source of s_client is rather
200hard to read and not a model of how things should be done. A typical
201SSL client program would be much simpler.
202
203The B<-verify> option should really exit if the server verification
204fails.
205
206The B<-prexit> option is a bit of a hack. We should really report
207information whenever a session is renegotiated.
208
209=head1 SEE ALSO
210
211L<sess_id(1)|sess_id(1)>, L<s_server(1)|s_server(1)>, L<ciphers(1)|ciphers(1)>
212
213=cut
diff --git a/src/lib/libssl/src/doc/apps/s_server.pod b/src/lib/libssl/src/doc/apps/s_server.pod
new file mode 100644
index 0000000000..0f29c361d9
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/s_server.pod
@@ -0,0 +1,265 @@
1
2=pod
3
4=head1 NAME
5
6s_server - SSL/TLS server program
7
8=head1 SYNOPSIS
9
10B<openssl> B<s_client>
11[B<-accept port>]
12[B<-context id>]
13[B<-verify depth>]
14[B<-Verify depth>]
15[B<-cert filename>]
16[B<-key keyfile>]
17[B<-dcert filename>]
18[B<-dkey keyfile>]
19[B<-dhparam filename>]
20[B<-nbio>]
21[B<-nbio_test>]
22[B<-crlf>]
23[B<-debug>]
24[B<-state>]
25[B<-CApath directory>]
26[B<-CAfile filename>]
27[B<-nocert>]
28[B<-cipher cipherlist>]
29[B<-quiet>]
30[B<-no_tmp_rsa>]
31[B<-ssl2>]
32[B<-ssl3>]
33[B<-tls1>]
34[B<-no_ssl2>]
35[B<-no_ssl3>]
36[B<-no_tls1>]
37[B<-no_dhe>]
38[B<-bugs>]
39[B<-hack>]
40[B<-www>]
41[B<-WWW>]
42
43=head1 DESCRIPTION
44
45The B<s_server> command implements a generic SSL/TLS server which listens
46for connections on a given port using SSL/TLS.
47
48=head1 OPTIONS
49
50=over 4
51
52=item B<-accept port>
53
54the TCP port to listen on for connections. If not specified 4433 is used.
55
56=item B<-context id>
57
58sets the SSL context id. It can be given any string value. If this option
59is not present a default value will be used.
60
61=item B<-cert certname>
62
63The certificate to use, most servers cipher suites require the use of a
64certificate and some require a certificate with a certain public key type:
65for example the DSS cipher suites require a certificate containing a DSS
66(DSA) key. If not specified then the filename "server.pem" will be used.
67
68=item B<-key keyfile>
69
70The private key to use. If not specified then the certificate file will
71be used.
72
73=item B<-dcert filename>, B<-dkey keyname>
74
75specify an additional certificate and private key, these behave in the
76same manner as the B<-cert> and B<-key> options except there is no default
77if they are not specified (no additional certificate and key is used). As
78noted above some cipher suites require a certificate containing a key of
79a certain type. Some cipher suites need a certificate carrying an RSA key
80and some a DSS (DSA) key. By using RSA and DSS certificates and keys
81a server can support clients which only support RSA or DSS cipher suites
82by using an appropriate certificate.
83
84=item B<-nocert>
85
86if this option is set then no certificate is used. This restricts the
87cipher suites available to the anonymous ones (currently just anonymous
88DH).
89
90=item B<-dhparam filename>
91
92the DH parameter file to use. The ephemeral DH cipher suites generate keys
93using a set of DH parameters. If not specified then an attempt is made to
94load the parameters from the server certificate file. If this fails then
95a static set of parameters hard coded into the s_server program will be used.
96
97=item B<-nodhe>
98
99if this option is set then no DH parameters will be loaded effectively
100disabling the ephemeral DH cipher suites.
101
102=item B<-no_tmp_rsa>
103
104certain export cipher suites sometimes use a temporary RSA key, this option
105disables temporary RSA key generation.
106
107=item B<-verify depth>, B<-Verify depth>
108
109The verify depth to use. This specifies the maximum length of the
110client certificate chain and makes the server request a certificate from
111the client. With the B<-verify> option a certificate is requested but the
112client does not have to send one, with the B<-Verify> option the client
113must supply a certificate or an error occurs.
114
115=item B<-CApath directory>
116
117The directory to use for client certificate verification. This directory
118must be in "hash format", see B<verify> for more information. These are
119also used when building the server certificate chain.
120
121=item B<-CAfile file>
122
123A file containing trusted certificates to use during client authentication
124and to use when attempting to build the server certificate chain. The list
125is also used in the list of acceptable client CAs passed to the client when
126a certificate is requested.
127
128=item B<-state>
129
130prints out the SSL session states.
131
132=item B<-debug>
133
134print extensive debugging information including a hex dump of all traffic.
135
136=item B<-nbio_test>
137
138tests non blocking I/O
139
140=item B<-nbio>
141
142turns on non blocking I/O
143
144=item B<-crlf>
145
146this option translated a line feed from the terminal into CR+LF.
147
148=item B<-quiet>
149
150inhibit printing of session and certificate information.
151
152=item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>
153
154these options disable the use of certain SSL or TLS protocols. By default
155the initial handshake uses a method which should be compatible with all
156servers and permit them to use SSL v3, SSL v2 or TLS as appropriate.
157
158=item B<-bugs>
159
160there are several known bug in SSL and TLS implementations. Adding this
161option enables various workarounds.
162
163=item B<-hack>
164
165this option enables a further workaround for some some early Netscape
166SSL code (?).
167
168=item B<-cipher cipherlist>
169
170this allows the cipher list used by the server to be modified. When
171the client sends a list of supported ciphers the first client cipher
172also included in the server list is used. Because the client specifies
173the preference order, the order of the server cipherlist irrelevant. See
174the B<ciphers> command for more information.
175
176=item B<-www>
177
178sends a status message back to the client when it connects. This includes
179lots of information about the ciphers used and various session parameters.
180The output is in HTML format so this option will normally be used with a
181web browser.
182
183=item B<-WWW>
184
185emulates a simple web server. Pages will be resolved relative to the
186current directory, for example if the URL https://myhost/page.html is
187requested the file ./page.html will be loaded.
188
189=back
190
191=head1 CONNECTED COMMANDS
192
193If a connection request is established with an SSL client and neither the
194B<-www> nor the B<-WWW> option has been used then normally any data received
195from the client is displayed and any key presses will be sent to the client.
196
197Certain single letter commands are also recognized which perform special
198operations: these are listed below.
199
200=over 4
201
202=item B<q>
203
204end the current SSL connection but still accept new connections.
205
206=item B<Q>
207
208end the current SSL connection and exit.
209
210=item B<r>
211
212renegotiate the SSL session.
213
214=item B<R>
215
216renegotiate the SSL session and request a client certificate.
217
218=item B<P>
219
220send some plain text down the underlying TCP connection: this should
221cause the client to disconnect due to a protocol violation.
222
223=item B<S>
224
225print out some session cache status information.
226
227=back
228
229=head1 NOTES
230
231B<s_server> can be used to debug SSL clients. To accept connections from
232a web browser the command:
233
234 openssl s_server -accept 443 -www
235
236can be used for example.
237
238Most web browsers (in particular Netscape and MSIE) only support RSA cipher
239suites, so they cannot connect to servers which don't use a certificate
240carrying an RSA key or a version of OpenSSL with RSA disabled.
241
242Although specifying an empty list of CAs when requesting a client certificate
243is strictly speaking a protocol violation, some SSL clients interpret this to
244mean any CA is acceptable. This is useful for debugging purposes.
245
246The session parameters can printed out using the B<sess_id> program.
247
248=head1 BUGS
249
250Because this program has a lot of options and also because some of
251the techniques used are rather old, the C source of s_server is rather
252hard to read and not a model of how things should be done. A typical
253SSL server program would be much simpler.
254
255The output of common ciphers is wrong: it just gives the list of ciphers that
256OpenSSL recognizes and the client supports.
257
258There should be a way for the B<s_server> program to print out details of any
259unknown cipher suites a client says it supports.
260
261=head1 SEE ALSO
262
263L<sess_id(1)|sess_id(1)>, L<s_client(1)|s_client(1)>, L<ciphers(1)|ciphers(1)>
264
265=cut
diff --git a/src/lib/libssl/src/doc/apps/sess_id.pod b/src/lib/libssl/src/doc/apps/sess_id.pod
new file mode 100644
index 0000000000..9988d2cd3d
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/sess_id.pod
@@ -0,0 +1,151 @@
1
2=pod
3
4=head1 NAME
5
6sess_id - SSL/TLS session handling utility
7
8=head1 SYNOPSIS
9
10B<openssl> B<sess_id>
11[B<-inform PEM|DER>]
12[B<-outform PEM|DER>]
13[B<-in filename>]
14[B<-out filename>]
15[B<-text>]
16[B<-noout>]
17[B<-context ID>]
18
19=head1 DESCRIPTION
20
21The B<sess_id> process the encoded version of the SSL session structure
22and optionally prints out SSL session details (for example the SSL session
23master key) in human readable format. Since this is a diagnostic tool that
24needs some knowledge of the SSL protocol to use properly, most users will
25not need to use it.
26
27=over 4
28
29=item B<-inform DER|PEM>
30
31This specifies the input format. The B<DER> option uses an ASN1 DER encoded
32format containing session details. The precise format can vary from one version
33to the next. The B<PEM> form is the default format: it consists of the B<DER>
34format base64 encoded with additional header and footer lines.
35
36=item B<-outform DER|PEM>
37
38This specifies the output format, the options have the same meaning as the
39B<-inform> option.
40
41=item B<-in filename>
42
43This specifies the input filename to read session information from or standard
44input by default.
45
46=item B<-out filename>
47
48This specifies the output filename to write session information to or standard
49output if this option is not specified.
50
51=item B<-text>
52
53prints out the various public or private key components in
54plain text in addition to the encoded version.
55
56=item B<-cert>
57
58if a certificate is present in the session it will be output using this option,
59if the B<-text> option is also present then it will be printed out in text form.
60
61=item B<-noout>
62
63this option prevents output of the encoded version of the session.
64
65=item B<-context ID>
66
67this option can set the session id so the output session information uses the
68supplied ID. The ID can be any string of characters. This option wont normally
69be used.
70
71=back
72
73=head1 OUTPUT
74
75Typical output:
76
77 SSL-Session:
78 Protocol : TLSv1
79 Cipher : 0016
80 Session-ID: 871E62626C554CE95488823752CBD5F3673A3EF3DCE9C67BD916C809914B40ED
81 Session-ID-ctx: 01000000
82 Master-Key: A7CEFC571974BE02CAC305269DC59F76EA9F0B180CB6642697A68251F2D2BB57E51DBBB4C7885573192AE9AEE220FACD
83 Key-Arg : None
84 Start Time: 948459261
85 Timeout : 300 (sec)
86 Verify return code 0 (ok)
87
88Theses are described below in more detail.
89
90=over 4
91
92=item B<Protocol>
93
94this is the protocol in use TLSv1, SSLv3 or SSLv2.
95
96=item B<Cipher>
97
98the cipher used this is the actual raw SSL or TLS cipher code, see the SSL
99or TLS specifications for more information.
100
101=item B<Session-ID>
102
103the SSL session ID in hex format.
104
105=item B<Session-ID-ctx>
106
107the session ID context in hex format.
108
109=item B<Master-Key>
110
111this is the SSL session master key.
112
113=item B<Key-Arg>
114
115the key argument, this is only used in SSL v2.
116
117=item B<Start Time>
118
119this is the session start time represented as an integer in standard Unix format.
120
121=item B<Timeout>
122
123the timeout in seconds.
124
125=item B<Verify return code>
126
127this is the return code when an SSL client certificate is verified.
128
129=back
130
131=head1 NOTES
132
133The PEM encoded session format uses the header and footer lines:
134
135 -----BEGIN SSL SESSION PARAMETERS-----
136 -----END SSL SESSION PARAMETERS-----
137
138Since the SSL session output contains the master key it is possible to read the contents
139of an encrypted session using this information. Therefore appropriate security precautions
140should be taken if the information is being output by a "real" application. This is
141however strongly discouraged and should only be used for debugging purposes.
142
143=head1 BUGS
144
145The cipher and start time should be printed out in human readable form.
146
147=head1 SEE ALSO
148
149L<ciphers(1)|ciphers(1)>, L<s_server(1)|s_server(1)>
150
151=cut
diff --git a/src/lib/libssl/src/doc/apps/smime.pod b/src/lib/libssl/src/doc/apps/smime.pod
new file mode 100644
index 0000000000..631ecdc241
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/smime.pod
@@ -0,0 +1,325 @@
1=pod
2
3=head1 NAME
4
5smime - S/MIME utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<smime>
10[B<-encrypt>]
11[B<-decrypt>]
12[B<-sign>]
13[B<-verify>]
14[B<-pk7out>]
15[B<-des>]
16[B<-des3>]
17[B<-rc2-40>]
18[B<-rc2-64>]
19[B<-rc2-128>]
20[B<-in file>]
21[B<-certfile file>]
22[B<-signer file>]
23[B<-recip file>]
24[B<-in file>]
25[B<-inkey file>]
26[B<-out file>]
27[B<-to addr>]
28[B<-from ad>]
29[B<-subject s>]
30[B<-text>]
31[B<-rand file(s)>]
32[cert.pem]...
33
34=head1 DESCRIPTION
35
36The B<smime> command handles S/MIME mail. It can encrypt, decrypt, sign and
37verify S/MIME messages.
38
39=head1 COMMAND OPTIONS
40
41There are five operation options that set the type of operation to be performed.
42The meaning of the other options varies according to the operation type.
43
44=over 4
45
46=item B<-encrypt>
47
48encrypt mail for the given recipient certificates. Input file is the message
49to be encrypted. The output file is the encrypted mail in MIME format.
50
51=item B<-decrypt>
52
53decrypt mail using the supplied certificate and private key. Expects an
54encrypted mail message in MIME format for the input file. The decrypted mail
55is written to the output file.
56
57=item B<-sign>
58
59sign mail using the supplied certificate and private key. Input file is
60the message to be signed. The signed message in MIME format is written
61to the output file.
62
63=item B<-verify>
64
65verify signed mail. Expects a signed mail message on input and outputs
66the signed data. Both clear text and opaque signing is supported.
67
68=item B<-pk7out>
69
70takes an input message and writes out a PEM encoded PKCS#7 structure.
71
72=item B<-in filename>
73
74the input message to be encrypted or signed or the MIME message to
75be decrypted or verified.
76
77=item B<-out filename>
78
79the message text that has been decrypted or verified or the output MIME
80format message that has been signed or verified.
81
82=item B<-text>
83
84this option adds plain text (text/plain) MIME headers to the supplied
85message if encrypting or signing. If decrypting or verifying it strips
86off text headers: if the decrypted or verified message is not of MIME
87type text/plain then an error occurs.
88
89=item B<-CAfile file>
90
91a file containing trusted CA certificates, only used with B<-verify>.
92
93=item B<-CApath dir>
94
95a directory containing trusted CA certificates, only used with
96B<-verify>. This directory must be a standard certificate directory: that
97is a hash of each subject name (using B<x509 -hash>) should be linked
98to each certificate.
99
100=item B<-des -des3 -rc2-40 -rc2-64 -rc2-128>
101
102the encryption algorithm to use. DES (56 bits), triple DES (168 bits)
103or 40, 64 or 128 bit RC2 respectively if not specified 40 bit RC2 is
104used. Only used with B<-encrypt>.
105
106=item B<-nointern>
107
108when verifying a message normally certificates (if any) included in
109the message are searched for the signing certificate. With this option
110only the certificates specified in the B<-certfile> option are used.
111The supplied certificates can still be used as untrusted CAs however.
112
113=item B<-noverify>
114
115do not verify the signers certificate of a signed message.
116
117=item B<-nochain>
118
119do not do chain verification of signers certificates: that is don't
120use the certificates in the signed message as untrusted CAs.
121
122=item B<-nosigs>
123
124don't try to verify the signatures on the message.
125
126=item B<-nocerts>
127
128when signing a message the signer's certificate is normally included
129with this option it is excluded. This will reduce the size of the
130signed message but the verifier must have a copy of the signers certificate
131available locally (passed using the B<-certfile> option for example).
132
133=item B<-noattr>
134
135normally when a message is signed a set of attributes are included which
136include the signing time and supported symmetric algorithms. With this
137option they are not included.
138
139=item B<-binary>
140
141normally the input message is converted to "canonical" format which is
142effectively using CR and LF as end of line: as required by the S/MIME
143specification. When this option is present no translation occurs. This
144is useful when handling binary data which may not be in MIME format.
145
146=item B<-nodetach>
147
148when signing a message use opaque signing: this form is more resistant
149to translation by mail relays but it cannot be read by mail agents that
150do not support S/MIME. Without this option cleartext signing with
151the MIME type multipart/signed is used.
152
153=item B<-certfile file>
154
155allows additional certificates to be specified. When signing these will
156be included with the message. When verifying these will be searched for
157the signers certificates. The certificates should be in PEM format.
158
159=item B<-signer file>
160
161the signers certificate when signing a message. If a message is
162being verified then the signers certificates will be written to this
163file if the verification was successful.
164
165=item B<-recip file>
166
167the recipients certificate when decrypting a message. This certificate
168must match one of the recipients of the message or an error occurs.
169
170=item B<-inkey file>
171
172the private key to use when signing or decrypting. This must match the
173corresponding certificate. If this option is not specified then the
174private key must be included in the certificate file specified with
175the B<-recip> or B<-signer> file.
176
177=item B<-rand file(s)>
178
179a file or files containing random data used to seed the random number
180generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
181Multiple files can be specified separated by a OS-dependent character.
182The separator is B<;> for MS-Windows, B<,> for OpenVSM, and B<:> for
183all others.
184
185=item B<cert.pem...>
186
187one or more certificates of message recipients: used when encrypting
188a message.
189
190=item B<-to, -from, -subject>
191
192the relevant mail headers. These are included outside the signed
193portion of a message so they may be included manually. If signing
194then many S/MIME mail clients check the signers certificate's email
195address matches that specified in the From: address.
196
197=back
198
199=head1 NOTES
200
201The MIME message must be sent without any blank lines between the
202headers and the output. Some mail programs will automatically add
203a blank line. Piping the mail directly to sendmail is one way to
204achieve the correct format.
205
206The supplied message to be signed or encrypted must include the
207necessary MIME headers: or many S/MIME clients wont display it
208properly (if at all). You can use the B<-text> option to automatically
209add plain text headers.
210
211A "signed and encrypted" message is one where a signed message is
212then encrypted. This can be produced by encrypting an already signed
213message: see the examples section.
214
215This version of the program only allows one signer per message but it
216will verify multiple signers on received messages. Some S/MIME clients
217choke if a message contains multiple signers. It is possible to sign
218messages "in parallel" by signing an already signed message.
219
220The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
221clients. Strictly speaking these process PKCS#7 enveloped data: PKCS#7
222encrypted data is used for other purposes.
223
224=head1 EXIT CODES
225
226=over 4
227
228=item 0
229
230the operation was completely successfully.
231
232=item 1
233
234an error occurred parsing the command options.
235
236=item 2
237
238one of the input files could not be read.
239
240=item 3
241
242an error occurred creating the PKCS#7 file or when reading the MIME
243message.
244
245=item 4
246
247an error occurred decrypting or verifying the message.
248
249=item 5
250
251the message was verified correctly but an error occurred writing out
252the signers certificates.
253
254=back
255
256=head1 EXAMPLES
257
258Create a cleartext signed message:
259
260 openssl smime -sign -in message.txt -text -out mail.msg \
261 -signer mycert.pem
262
263Create and opaque signed message
264
265 openssl smime -sign -in message.txt -text -out mail.msg -nodetach \
266 -signer mycert.pem
267
268Create a signed message, include some additional certificates and
269read the private key from another file:
270
271 openssl smime -sign -in in.txt -text -out mail.msg \
272 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
273
274Send a signed message under Unix directly to sendmail, including headers:
275
276 openssl smime -sign -in in.txt -text -signer mycert.pem \
277 -from steve@openssl.org -to someone@somewhere \
278 -subject "Signed message" | sendmail someone@somewhere
279
280Verify a message and extract the signer's certificate if successful:
281
282 openssl smime -verify -in mail.msg -signer user.pem -out signedtext.txt
283
284Send encrypted mail using triple DES:
285
286 openssl smime -encrypt -in in.txt -from steve@openssl.org \
287 -to someone@somewhere -subject "Encrypted message" \
288 -des3 user.pem -out mail.msg
289
290Sign and encrypt mail:
291
292 openssl smime -sign -in ml.txt -signer my.pem -text \
293 | openssl -encrypt -out mail.msg \
294 -from steve@openssl.org -to someone@somewhere \
295 -subject "Signed and Encrypted message" -des3 user.pem
296
297Note: the encryption command does not include the B<-text> option because the message
298being encrypted already has MIME headers.
299
300Decrypt mail:
301
302 openssl smime -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
303
304=head1 BUGS
305
306The MIME parser isn't very clever: it seems to handle most messages that I've thrown
307at it but it may choke on others.
308
309The code currently will only write out the signer's certificate to a file: if the
310signer has a separate encryption certificate this must be manually extracted. There
311should be some heuristic that determines the correct encryption certificate.
312
313Ideally a database should be maintained of a certificates for each email address.
314
315The code doesn't currently take note of the permitted symmetric encryption
316algorithms as supplied in the SMIMECapabilities signed attribute. this means the
317user has to manually include the correct encryption algorithm. It should store
318the list of permitted ciphers in a database and only use those.
319
320No revocation checking is done on the signer's certificate.
321
322The current code can only handle S/MIME v2 messages, the more complex S/MIME v3
323structures may cause parsing errors.
324
325=cut
diff --git a/src/lib/libssl/src/doc/apps/speed.pod b/src/lib/libssl/src/doc/apps/speed.pod
new file mode 100644
index 0000000000..fecd9a994d
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/speed.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5speed - test library performance
6
7=head1 SYNOPSIS
8
9B<openssl speed>
10[B<md2>]
11[B<mdc2>]
12[B<md5>]
13[B<hmac>]
14[B<sha1>]
15[B<rmd160>]
16[B<idea-cbc>]
17[B<rc2-cbc>]
18[B<rc5-cbc>]
19[B<bf-cbc>]
20[B<des-cbc>]
21[B<des-ede3>]
22[B<rc4>]
23[B<rsa512>]
24[B<rsa1024>]
25[B<rsa2048>]
26[B<rsa4096>]
27[B<dsa512>]
28[B<dsa1024>]
29[B<dsa2048>]
30[B<idea>]
31[B<rc2>]
32[B<des>]
33[B<rsa>]
34[B<blowfish>]
35
36=head1 DESCRIPTION
37
38This command is used to test the performance of cryptographic algorithms.
39
40=head1 OPTIONS
41
42If an option is given, B<speed> test that algorithm, otherwise all of
43the above are tested.
44
45=cut
diff --git a/src/lib/libssl/src/doc/apps/spkac.pod b/src/lib/libssl/src/doc/apps/spkac.pod
new file mode 100644
index 0000000000..bb84dfbe33
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/spkac.pod
@@ -0,0 +1,127 @@
1=pod
2
3=head1 NAME
4
5spkac - SPKAC printing and generating utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<spkac>
10[B<-in filename>]
11[B<-out filename>]
12[B<-key keyfile>]
13[B<-passin arg>]
14[B<-challenge string>]
15[B<-pubkey>]
16[B<-spkac spkacname>]
17[B<-spksect section>]
18[B<-noout>]
19[B<-verify>]
20
21
22=head1 DESCRIPTION
23
24The B<spkac> command processes Netscape signed public key and challenge
25(SPKAC) files. It can print out their contents, verify the signature and
26produce its own SPKACs from a supplied private key.
27
28=head1 COMMAND OPTIONS
29
30=over 4
31
32=item B<-in filename>
33
34This specifies the input filename to read from or standard input if this
35option is not specified. Ignored if the B<-key> option is used.
36
37=item B<-out filename>
38
39specifies the output filename to write to or standard output by
40default.
41
42=item B<-key keyfile>
43
44create an SPKAC file using the private key in B<keyfile>. The
45B<-in>, B<-noout>, B<-spksect> and B<-verify> options are ignored if
46present.
47
48=item B<-passin password>
49
50the input file password source. For more information about the format of B<arg>
51see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
52
53=item B<-challenge string>
54
55specifies the challenge string if an SPKAC is being created.
56
57=item B<-spkac spkacname>
58
59allows an alternative name form the variable containing the
60SPKAC. The default is "SPKAC". This option affects both
61generated and input SPKAC files.
62
63=item B<-spksect section>
64
65allows an alternative name form the section containing the
66SPKAC. The default is the default section.
67
68=item B<-noout>
69
70don't output the text version of the SPKAC (not used if an
71SPKAC is being created).
72
73=item B<-pubkey>
74
75output the public key of an SPKAC (not used if an SPKAC is
76being created).
77
78=item B<-verify>
79
80verifies the digital signature on the supplied SPKAC.
81
82
83=back
84
85=head1 EXAMPLES
86
87Print out the contents of an SPKAC:
88
89 openssl spkac -in spkac.cnf
90
91Verify the signature of an SPKAC:
92
93 openssl spkac -in spkac.cnf -noout -verify
94
95Create an SPKAC using the challenge string "hello":
96
97 openssl spkac -key key.pem -challenge hello -out spkac.cnf
98
99Example of an SPKAC, (long lines split up for clarity):
100
101 SPKAC=MIG5MGUwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1cCoq2Wa3Ixs47uI7F\
102 PVwHVIPDx5yso105Y6zpozam135a8R0CpoRvkkigIyXfcCjiVi5oWk+6FfPaD03u\
103 PFoQIDAQABFgVoZWxsbzANBgkqhkiG9w0BAQQFAANBAFpQtY/FojdwkJh1bEIYuc\
104 2EeM2KHTWPEepWYeawvHD0gQ3DngSC75YCWnnDdq+NQ3F+X4deMx9AaEglZtULwV\
105 4=
106
107=head1 NOTES
108
109A created SPKAC with suitable DN components appended can be fed into
110the B<ca> utility.
111
112SPKACs are typically generated by Netscape when a form is submitted
113containing the B<KEYGEN> tag as part of the certificate enrollment
114process.
115
116The challenge string permits a primitive form of proof of possession
117of private key. By checking the SPKAC signature and a random challenge
118string some guarantee is given that the user knows the private key
119corresponding to the public key being certified. This is important in
120some applications. Without this it is possible for a previous SPKAC
121to be used in a "replay attack".
122
123=head1 SEE ALSO
124
125L<ca(1)|ca(1)>
126
127=cut
diff --git a/src/lib/libssl/src/doc/apps/verify.pod b/src/lib/libssl/src/doc/apps/verify.pod
new file mode 100644
index 0000000000..4a6572d3b8
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/verify.pod
@@ -0,0 +1,273 @@
1=pod
2
3=head1 NAME
4
5pkcs7 - PKCS#7 utility
6
7=head1 SYNOPSIS
8
9B<openssl> B<verify>
10[B<-CApath directory>]
11[B<-CAfile file>]
12[B<-purpose purpose>]
13[B<-untrusted file>]
14[B<-help>]
15[B<-verbose>]
16[B<->]
17[certificates]
18
19
20=head1 DESCRIPTION
21
22The B<verify> command verifies certificate chains.
23
24=head1 COMMAND OPTIONS
25
26=over 4
27
28=item B<-CApath directory>
29
30A directory of trusted certificates. The certificates should have names
31of the form: hash.0 or have symbolic links to them of this
32form ("hash" is the hashed certificate subject name: see the B<-hash> option
33of the B<x509> utility). Under Unix the B<c_rehash> script will automatically
34create symbolic links to a directory of certificates.
35
36=item B<-CAfile file>
37
38A file of trusted certificates. The file should contain multiple certificates
39in PEM format concatenated together.
40
41=item B<-untrusted file>
42
43A file of untrusted certificates. The file should contain multiple certificates
44
45=item B<-purpose purpose>
46
47the intended use for the certificate. Without this option no chain verification
48will be done. Currently accepted uses are B<sslclient>, B<sslserver>,
49B<nssslserver>, B<smimesign>, B<smimeencrypt>. See the B<VERIFY OPERATION>
50section for more information.
51
52=item B<-help>
53
54prints out a usage message.
55
56=item B<-verbose>
57
58print extra information about the operations being performed.
59
60=item B<->
61
62marks the last option. All arguments following this are assumed to be
63certificate files. This is useful if the first certificate filename begins
64with a B<->.
65
66=item B<certificates>
67
68one or more certificates to verify. If no certificate filenames are included
69then an attempt is made to read a certificate from standard input. They should
70all be in PEM format.
71
72
73=back
74
75=head1 VERIFY OPERATION
76
77The B<verify> program uses the same functions as the internal SSL and S/MIME
78verification, therefore this description applies to these verify operations
79too.
80
81There is one crucial difference between the verify operations performed
82by the B<verify> program: wherever possible an attempt is made to continue
83after an error whereas normally the verify operation would halt on the
84first error. This allows all the problems with a certificate chain to be
85determined.
86
87The verify operation consists of a number of separate steps.
88
89Firstly a certificate chain is built up starting from the supplied certificate
90and ending in the root CA. It is an error if the whole chain cannot be built
91up. The chain is built up by looking up a certificate whose subject name
92matches the issuer name of the current certificate. If a certificate is found
93whose subject and issuer names are identical it is assumed to be the root CA.
94The lookup first looks in the list of untrusted certificates and if no match
95is found the remaining lookups are from the trusted certificates. The root CA
96is always looked up in the trusted certificate list: if the certificate to
97verify is a root certificate then an exact match must be found in the trusted
98list.
99
100The second operation is to check every untrusted certificate's extensions for
101consistency with the supplied purpose. If the B<-purpose> option is not included
102then no checks are done. The supplied or "leaf" certificate must have extensions
103compatible with the supplied purpose and all other certificates must also be valid
104CA certificates. The precise extensions required are described in more detail in
105the B<CERTIFICATE EXTENSIONS> section of the B<x509> utility.
106
107The third operation is to check the trust settings on the root CA. The root
108CA should be trusted for the supplied purpose. For compatibility with previous
109versions of SSLeay and OpenSSL a certificate with no trust settings is considered
110to be valid for all purposes.
111
112The final operation is to check the validity of the certificate chain. The validity
113period is checked against the current system time and the notBefore and notAfter
114dates in the certificate. The certificate signatures are also checked at this
115point.
116
117If all operations complete successfully then certificate is considered valid. If
118any operation fails then the certificate is not valid.
119
120=head1 DIAGNOSTICS
121
122When a verify operation fails the output messages can be somewhat cryptic. The
123general form of the error message is:
124
125 server.pem: /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
126 error 24 at 1 depth lookup:invalid CA certificate
127
128The first line contains the name of the certificate being verified followed by
129the subject name of the certificate. The second line contains the error number
130and the depth. The depth is number of the certificate being verified when a
131problem was detected starting with zero for the certificate being verified itself
132then 1 for the CA that signed the certificate and so on. Finally a text version
133of the error number is presented.
134
135An exhaustive list of the error codes and messages is shown below, this also
136includes the name of the error code as defined in the header file x509_vfy.h
137Some of the error codes are defined but never returned: these are described
138as "unused".
139
140=over 4
141
142=item B<0 X509_V_OK: ok>
143
144the operation was successful.
145
146=item B<2 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate>
147
148the issuer certificate could not be found: this occurs if the issuer certificate
149of an untrusted certificate cannot be found.
150
151=item B<3 X509_V_ERR_UNABLE_TO_GET_CRL unable to get certificate CRL>
152
153the CRL of a certificate could not be found. Unused.
154
155=item B<4 X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature>
156
157the certificate signature could not be decrypted. This means that the actual signature value
158could not be determined rather than it not matching the expected value, this is only
159meaningful for RSA keys.
160
161=item B<5 X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature>
162
163the CRL signature could not be decrypted: this means that the actual signature value
164could not be determined rather than it not matching the expected value. Unused.
165
166=item B<6 X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key>
167
168the public key in the certificate SubjectPublicKeyInfo could not be read.
169
170=item B<7 X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure>
171
172the signature of the certificate is invalid.
173
174=item B<8 X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure>
175
176the signature of the certificate is invalid. Unused.
177
178=item B<9 X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid>
179
180the certificate is not yet valid: the notBefore date is after the current time.
181
182=item B<10 X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid>
183
184the CRL is not yet valid. Unused.
185
186=item B<11 X509_V_ERR_CERT_HAS_EXPIRED: Certificate has expired>
187
188the certificate has expired: that is the notAfter date is before the current time.
189
190=item B<12 X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired>
191
192the CRL has expired. Unused.
193
194=item B<13 X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field>
195
196the certificate notBefore field contains an invalid time.
197
198=item B<14 X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field>
199
200the certificate notAfter field contains an invalid time.
201
202=item B<15 X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field>
203
204the CRL lastUpdate field contains an invalid time. Unused.
205
206=item B<16 X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field>
207
208the CRL nextUpdate field contains an invalid time. Unused.
209
210=item B<17 X509_V_ERR_OUT_OF_MEM: out of memory>
211
212an error occurred trying to allocate memory. This should never happen.
213
214=item B<18 X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate>
215
216the passed certificate is self signed and the same certificate cannot be found in the list of
217trusted certificates.
218
219=item B<19 X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain>
220
221the certificate chain could be built up using the untrusted certificates but the root could not
222be found locally.
223
224=item B<20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate>
225
226the issuer certificate of a locally looked up certificate could not be found. This normally means
227the list of trusted certificates is not complete.
228
229=item B<21 X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate>
230
231no signatures could be verified because the chain contains only one certificate and it is not
232self signed.
233
234=item B<22 X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long>
235
236the certificate chain length is greater than the supplied maximum depth. Unused.
237
238=item B<23 X509_V_ERR_CERT_REVOKED: certificate revoked>
239
240the certificate has been revoked. Unused.
241
242=item B<24 X509_V_ERR_INVALID_CA: invalid CA certificate>
243
244a CA certificate is invalid. Either it is not a CA or its extensions are not consistent
245with the supplied purpose.
246
247=item B<25 X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded>
248
249the basicConstraints pathlength parameter has been exceeded.
250
251=item B<26 X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose>
252
253the supplied certificate cannot be used for the specified purpose.
254
255=item B<27 X509_V_ERR_CERT_UNTRUSTED: certificate not trusted>
256
257the root CA is not marked as trusted for the specified purpose.
258
259=item B<28 X509_V_ERR_CERT_REJECTED: certificate rejected>
260
261the root CA is marked to reject the specified purpose.
262
263=item B<50 X509_V_ERR_APPLICATION_VERIFICATION: application verification failure>
264
265an application specific error. Unused.
266
267=back
268
269=head1 SEE ALSO
270
271L<x509(1)|x509(1)>
272
273=cut
diff --git a/src/lib/libssl/src/doc/apps/version.pod b/src/lib/libssl/src/doc/apps/version.pod
new file mode 100644
index 0000000000..5d261a6405
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/version.pod
@@ -0,0 +1,56 @@
1=pod
2
3=head1 NAME
4
5version - print OpenSSL version information
6
7=head1 SYNOPSIS
8
9B<openssl version>
10[B<-a>]
11[B<-v>]
12[B<-b>]
13[B<-o>]
14[B<-f>]
15[B<-p>]
16
17=head1 DESCRIPTION
18
19This command is used to print out version information about OpenSSL.
20
21=head1 OPTIONS
22
23=over 4
24
25=item B<-a>
26
27all information, this is the same as setting all the other flags.
28
29=item B<-v>
30
31the current OpenSSL version.
32
33=item B<-b>
34
35the date the current version of OpenSSL was built.
36
37=item B<-o>
38
39option information: various options set when the library was built.
40
41=item B<-c>
42
43compilation flags.
44
45=item B<-p>
46
47platform setting.
48
49=back
50
51=head1 NOTES
52
53The output of B<openssl version -a> would typically be used when sending
54in a bug report.
55
56=cut
diff --git a/src/lib/libssl/src/doc/apps/x509.pod b/src/lib/libssl/src/doc/apps/x509.pod
new file mode 100644
index 0000000000..b127182bbb
--- /dev/null
+++ b/src/lib/libssl/src/doc/apps/x509.pod
@@ -0,0 +1,543 @@
1
2=pod
3
4=head1 NAME
5
6x509 - Certificate display and signing utility
7
8=head1 SYNOPSIS
9
10B<openssl> B<x509>
11[B<-inform DER|PEM|NET>]
12[B<-outform DER|PEM|NET>]
13[B<-keyform DER|PEM>]
14[B<-CAform DER|PEM>]
15[B<-CAkeyform DER|PEM>]
16[B<-in filename>]
17[B<-out filename>]
18[B<-serial>]
19[B<-hash>]
20[B<-subject>]
21[B<-issuer>]
22[B<-startdate>]
23[B<-enddate>]
24[B<-purpose>]
25[B<-dates>]
26[B<-modulus>]
27[B<-fingerprint>]
28[B<-alias>]
29[B<-noout>]
30[B<-trustout>]
31[B<-clrtrust>]
32[B<-clrreject>]
33[B<-addtrust arg>]
34[B<-addreject arg>]
35[B<-setalias arg>]
36[B<-days arg>]
37[B<-signkey filename>]
38[B<-x509toreq>]
39[B<-req>]
40[B<-CA filename>]
41[B<-CAkey filename>]
42[B<-CAcreateserial>]
43[B<-CAserial filename>]
44[B<-text>]
45[B<-C>]
46[B<-md2|-md5|-sha1|-mdc2>]
47[B<-clrext>]
48[B<-extfile filename>]
49[B<-extensions section>]
50
51=head1 DESCRIPTION
52
53The B<x509> command is a multi purpose certificate utility. It can be
54used to display certificate information, convert certificates to
55various forms, sign certificate requests like a "mini CA" or edit
56certificate trust settings.
57
58Since there are a large number of options they will split up into
59various sections.
60
61
62=head1 INPUT, OUTPUT AND GENERAL PURPOSE OPTIONS
63
64=over 4
65
66=item B<-inform DER|PEM|NET>
67
68This specifies the input format normally the command will expect an X509
69certificate but this can change if other options such as B<-req> are
70present. The DER format is the DER encoding of the certificate and PEM
71is the base64 encoding of the DER encoding with header and footer lines
72added. The NET option is an obscure Netscape server format that is now
73obsolete.
74
75=item B<-outform DER|PEM|NET>
76
77This specifies the output format, the options have the same meaning as the
78B<-inform> option.
79
80=item B<-in filename>
81
82This specifies the input filename to read a certificate from or standard input
83if this option is not specified.
84
85=item B<-out filename>
86
87This specifies the output filename to write to or standard output by
88default.
89
90=item B<-md2|-md5|-sha1|-mdc2>
91
92the digest to use. This affects any signing or display option that uses a message
93digest, such as the B<-fingerprint>, B<-signkey> and B<-CA> options. If not
94specified then MD5 is used. If the key being used to sign with is a DSA key then
95this option has no effect: SHA1 is always used with DSA keys.
96
97
98=back
99
100=head1 DISPLAY OPTIONS
101
102Note: the B<-alias> and B<-purpose> options are also display options
103but are described in the B<TRUST OPTIONS> section.
104
105=over 4
106
107=item B<-text>
108
109prints out the certificate in text form. Full details are output including the
110public key, signature algorithms, issuer and subject names, serial number
111any extensions present and any trust settings.
112
113=item B<-noout>
114
115this option prevents output of the encoded version of the request.
116
117=item B<-modulus>
118
119this option prints out the value of the modulus of the public key
120contained in the certificate.
121
122=item B<-serial>
123
124outputs the certificate serial number.
125
126=item B<-hash>
127
128outputs the "hash" of the certificate subject name. This is used in OpenSSL to
129form an index to allow certificates in a directory to be looked up by subject
130name.
131
132=item B<-subject>
133
134outputs the subject name.
135
136=item B<-issuer>
137
138outputs the issuer name.
139
140=item B<-startdate>
141
142prints out the start date of the certificate, that is the notBefore date.
143
144=item B<-enddate>
145
146prints out the expiry date of the certificate, that is the notAfter date.
147
148=item B<-dates>
149
150prints out the start and expiry dates of a certificate.
151
152=item B<-fingerprint>
153
154prints out the digest of the DER encoded version of the whole certificate.
155
156=item B<-C>
157
158this outputs the certificate in the form of a C source file.
159
160=back
161
162=head1 TRUST SETTINGS
163
164Please note these options are currently experimental and may well change.
165
166A B<trusted certificate> is an ordinary certificate which has several
167additional pieces of information attached to it such as the permitted
168and prohibited uses of the certificate and an "alias".
169
170Normally when a certificate is being verified at least one certificate
171must be "trusted". By default a trusted certificate must be stored
172locally and must be a root CA: any certificate chain ending in this CA
173is then usable for any purpose.
174
175Trust settings currently are only used with a root CA. They allow a finer
176control over the purposes the root CA can be used for. For example a CA
177may be trusted for SSL client but not SSL server use.
178
179See the description of the B<verify> utility for more information on the
180meaning of trust settings.
181
182Future versions of OpenSSL will recognize trust settings on any
183certificate: not just root CAs.
184
185
186=over 4
187
188=item B<-trustout>
189
190this causes B<x509> to output a B<trusted> certificate. An ordinary
191or trusted certificate can be input but by default an ordinary
192certificate is output and any trust settings are discarded. With the
193B<-trustout> option a trusted certificate is output. A trusted
194certificate is automatically output if any trust settings are modified.
195
196=item B<-setalias arg>
197
198sets the alias of the certificate. This will allow the certificate
199to be referred to using a nickname for example "Steve's Certificate".
200
201=item B<-alias>
202
203outputs the certificate alias, if any.
204
205=item B<-clrtrust>
206
207clears all the permitted or trusted uses of the certificate.
208
209=item B<-clrreject>
210
211clears all the prohibited or rejected uses of the certificate.
212
213=item B<-addtrust arg>
214
215adds a trusted certificate use. Currently acceptable values
216are B<all> (any purpose), B<sslclient> (SSL client use), B<sslserver>
217(SSL server use) B<email> (S/MIME email) and B<objsign> (Object signing).
218
219=item B<-addreject arg>
220
221adds a prohibited use. It accepts the same values as the B<-addtrust>
222option.
223
224=item B<-purpose>
225
226this option performs tests on the certificate extensions and outputs
227the results. For a more complete description see the B<CERTIFICATE
228EXTENSIONS> section.
229
230=back
231
232=head1 SIGNING OPTIONS
233
234The B<x509> utility can be used to sign certificates and requests: it
235can thus behave like a "mini CA".
236
237=over 4
238
239=item B<-signkey filename>
240
241this option causes the input file to be self signed using the supplied
242private key.
243
244If the input file is a certificate it sets the issuer name to the
245subject name (i.e. makes it self signed) changes the public key to the
246supplied value and changes the start and end dates. The start date is
247set to the current time and the end date is set to a value determined
248by the B<-days> option. Any certificate extensions are retained unless
249the B<-clrext> option is supplied.
250
251If the input is a certificate request then a self signed certificate
252is created using the supplied private key using the subject name in
253the request.
254
255=item B<-clrext>
256
257delete any extensions from a certificate. This option is used when a
258certificate is being created from another certificate (for example with
259the B<-signkey> or the B<-CA> options). Normally all extensions are
260retained.
261
262=item B<-keyform PEM|DER>
263
264specifies the format (DER or PEM) of the private key file used in the
265B<-signkey> option.
266
267=item B<-days arg>
268
269specifies the number of days to make a certificate valid for. The default
270is 30 days.
271
272=item B<-x509toreq>
273
274converts a certificate into a certificate request. The B<-signkey> option
275is used to pass the required private key.
276
277=item B<-req>
278
279by default a certificate is expected on input. With this option a
280certificate request is expected instead.
281
282=item B<-CA filename>
283
284specifies the CA certificate to be used for signing. When this option is
285present B<x509> behaves like a "mini CA". The input file is signed by this
286CA using this option: that is its issuer name is set to the subject name
287of the CA and it is digitally signed using the CAs private key.
288
289This option is normally combined with the B<-req> option. Without the
290B<-req> option the input is a certificate which must be self signed.
291
292=item B<-CAkey filename>
293
294sets the CA private key to sign a certificate with. If this option is
295not specified then it is assumed that the CA private key is present in
296the CA certificate file.
297
298=item B<-CAserial filename>
299
300sets the CA serial number file to use.
301
302When the B<-CA> option is used to sign a certificate it uses a serial
303number specified in a file. This file consist of one line containing
304an even number of hex digits with the serial number to use. After each
305use the serial number is incremented and written out to the file again.
306
307The default filename consists of the CA certificate file base name with
308".srl" appended. For example if the CA certificate file is called
309"mycacert.pem" it expects to find a serial number file called "mycacert.srl".
310
311=item B<-CAcreateserial filename>
312
313with this option the CA serial number file is created if it does not exist:
314it will contain the serial number "02" and the certificate being signed will
315have the 1 as its serial number. Normally if the B<-CA> option is specified
316and the serial number file does not exist it is an error.
317
318=item B<-extfile filename>
319
320file containing certificate extensions to use. If not specified then
321no extensions are added to the certificate.
322
323=item B<-extensions section>
324
325the section to add certificate extensions from. If this option is not
326specified then the extensions should either be contained in the unnamed
327(default) section or the default section should contain a variable called
328"extensions" which contains the section to use.
329
330=back
331
332=head1 EXAMPLES
333
334Note: in these examples the '\' means the example should be all on one
335line.
336
337Display the contents of a certificate:
338
339 openssl x509 -in cert.pem -noout -text
340
341Display the certificate serial number:
342
343 openssl x509 -in cert.pem -noout -serial
344
345Display the certificate MD5 fingerprint:
346
347 openssl x509 -in cert.pem -noout -fingerprint
348
349Display the certificate SHA1 fingerprint:
350
351 openssl x509 -sha1 -in cert.pem -noout -fingerprint
352
353Convert a certificate from PEM to DER format:
354
355 openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
356
357Convert a certificate to a certificate request:
358
359 openssl x509 -x509toreq -in cert.pem -out req.pem -signkey key.pem
360
361Convert a certificate request into a self signed certificate using
362extensions for a CA:
363
364 openssl x509 -req -in careq.pem -config openssl.cnf -extensions v3_ca \
365 -signkey key.pem -out cacert.pem
366
367Sign a certificate request using the CA certificate above and add user
368certificate extensions:
369
370 openssl x509 -req -in req.pem -config openssl.cnf -extensions v3_usr \
371 -CA cacert.pem -CAkey key.pem -CAcreateserial
372
373
374Set a certificate to be trusted for SSL client use and change set its alias to
375"Steve's Class 1 CA"
376
377 openssl x509 -in cert.pem -addtrust sslclient \
378 -alias "Steve's Class 1 CA" -out trust.pem
379
380=head1 NOTES
381
382The PEM format uses the header and footer lines:
383
384 -----BEGIN CERTIFICATE----
385 -----END CERTIFICATE----
386
387it will also handle files containing:
388
389 -----BEGIN X509 CERTIFICATE----
390 -----END X509 CERTIFICATE----
391
392Trusted certificates have the lines
393
394 -----BEGIN TRUSTED CERTIFICATE----
395 -----END TRUSTED CERTIFICATE----
396
397The B<-fingerprint> option takes the digest of the DER encoded certificate.
398This is commonly called a "fingerprint". Because of the nature of message
399digests the fingerprint of a certificate is unique to that certificate and
400two certificates with the same fingerprint can be considered to be the same.
401
402The Netscape fingerprint uses MD5 whereas MSIE uses SHA1.
403
404=head1 CERTIFICATE EXTENSIONS
405
406The B<-purpose> option checks the certificate extensions and determines
407what the certificate can be used for. The actual checks done are rather
408complex and include various hacks and workarounds to handle broken
409certificates and software.
410
411The same code is used when verifying untrusted certificates in chains
412so this section is useful if a chain is rejected by the verify code.
413
414The basicConstraints extension CA flag is used to determine whether the
415certificate can be used as a CA. If the CA flag is true then it is a CA,
416if the CA flag is false then it is not a CA. B<All> CAs should have the
417CA flag set to true.
418
419If the basicConstraints extension is absent then the certificate is
420considered to be a "possible CA" other extensions are checked according
421to the intended use of the certificate. A warning is given in this case
422because the certificate should really not be regarded as a CA: however
423it is allowed to be a CA to work around some broken software.
424
425If the certificate is a V1 certificate (and thus has no extensions) and
426it is self signed it is also assumed to be a CA but a warning is again
427given: this is to work around the problem of Verisign roots which are V1
428self signed certificates.
429
430If the keyUsage extension is present then additional restraints are
431made on the uses of the certificate. A CA certificate B<must> have the
432keyCertSign bit set if the keyUsage extension is present.
433
434The extended key usage extension places additional restrictions on the
435certificate uses. If this extension is present (whether critical or not)
436the key can only be used for the purposes specified.
437
438A complete description of each test is given below. The comments about
439basicConstraints and keyUsage and V1 certificates above apply to B<all>
440CA certificates.
441
442
443=over 4
444
445=item B<SSL Client>
446
447The extended key usage extension must be absent or include the "web client
448authentication" OID. keyUsage must be absent or it must have the
449digitalSignature bit set. Netscape certificate type must be absent or it must
450have the SSL client bit set.
451
452=item B<SSL Client CA>
453
454The extended key usage extension must be absent or include the "web client
455authentication" OID. Netscape certificate type must be absent or it must have
456the SSL CA bit set: this is used as a work around if the basicConstraints
457extension is absent.
458
459=item B<SSL Server>
460
461The extended key usage extension must be absent or include the "web server
462authentication" and/or one of the SGC OIDs. keyUsage must be absent or it
463must have the digitalSignature, the keyEncipherment set or both bits set.
464Netscape certificate type must be absent or have the SSL server bit set.
465
466=item B<SSL Server CA>
467
468The extended key usage extension must be absent or include the "web server
469authentication" and/or one of the SGC OIDs. Netscape certificate type must
470be absent or the SSL CA bit must be set: this is used as a work around if the
471basicConstraints extension is absent.
472
473=item B<Netscape SSL Server>
474
475For Netscape SSL clients to connect to an SSL server it must have the
476keyEncipherment bit set if the keyUsage extension is present. This isn't
477always valid because some cipher suites use the key for digital signing.
478Otherwise it is the same as a normal SSL server.
479
480=item B<Common S/MIME Client Tests>
481
482The extended key usage extension must be absent or include the "email
483protection" OID. Netscape certificate type must be absent or should have the
484S/MIME bit set. If the S/MIME bit is not set in netscape certificate type
485then the SSL client bit is tolerated as an alternative but a warning is shown:
486this is because some Verisign certificates don't set the S/MIME bit.
487
488=item B<S/MIME Signing>
489
490In addition to the common S/MIME client tests the digitalSignature bit must
491be set if the keyUsage extension is present.
492
493=item B<S/MIME Encryption>
494
495In addition to the common S/MIME tests the keyEncipherment bit must be set
496if the keyUsage extension is present.
497
498=item B<S/MIME CA>
499
500The extended key usage extension must be absent or include the "email
501protection" OID. Netscape certificate type must be absent or must have the
502S/MIME CA bit set: this is used as a work around if the basicConstraints
503extension is absent.
504
505=item B<CRL Signing>
506
507The keyUsage extension must be absent or it must have the CRL signing bit
508set.
509
510=item B<CRL Signing CA>
511
512The normal CA tests apply. Except in this case the basicConstraints extension
513must be present.
514
515=back
516
517=head1 BUGS
518
519The way DNs are printed is in a "historical SSLeay" format which doesn't
520follow any published standard. It should follow some standard like RFC2253
521or RFC1779 with options to make the stuff more readable.
522
523Extensions in certificates are not transferred to certificate requests and
524vice versa.
525
526It is possible to produce invalid certificates or requests by specifying the
527wrong private key or using inconsistent options in some cases: these should
528be checked.
529
530There should be options to explicitly set such things as start and end
531dates rather than an offset from the current time.
532
533The code to implement the verify behaviour described in the B<TRUST SETTINGS>
534is currently being developed. It thus describes the intended behavior rather
535than the current behaviour. It is hoped that it will represent reality in
536OpenSSL 0.9.5 and later.
537
538=head1 SEE ALSO
539
540L<req(1)|req(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>,
541L<gendsa(1)|gendsa(1)>, L<verify(1)|verify(1)>
542
543=cut
diff --git a/src/lib/libssl/src/doc/c-indentation.el b/src/lib/libssl/src/doc/c-indentation.el
new file mode 100644
index 0000000000..9a4a0be598
--- /dev/null
+++ b/src/lib/libssl/src/doc/c-indentation.el
@@ -0,0 +1,36 @@
1; This Emacs Lisp file defines a C indentation style that closely
2; follows most aspects of the one that is used throughout SSLeay,
3; and hence in OpenSSL.
4;
5; This definition is for the "CC mode" package, which is the default
6; mode for editing C source files in Emacs 20, not for the older
7; c-mode.el (which was the default in less recent releaes of Emacs 19).
8;
9; Copy the definition in your .emacs file or use M-x eval-buffer.
10; To activate this indentation style, visit a C file, type
11; M-x c-set-style <RET> (or C-c . for short), and enter "eay".
12; To toggle the auto-newline feature of CC mode, type C-c C-a.
13;
14; Apparently statement blocks that are not introduced by a statement
15; such as "if" and that are not the body of a function cannot
16; be handled too well by CC mode with this indentation style.
17; The style defined below does not indent them at all.
18; To insert tabs manually, prefix them with ^Q (the "quoted-insert"
19; command of Emacs). If you know a solution to this problem
20; or find other problems with this indentation style definition,
21; please send e-mail to bodo@openssl.org.
22
23(c-add-style "eay"
24 '((c-basic-offset . 8)
25 (c-comment-only-line-offset . 0)
26 (c-hanging-braces-alist)
27 (c-offsets-alist . ((defun-open . +)
28 (defun-block-intro . 0)
29 (block-open . 0)
30 (substatement-open . +)
31 (statement-block-intro . 0)
32 (statement-case-open . +)
33 (statement-case-intro . +)
34 (case-label . -)
35 (label . -)
36 (arglist-cont-nonempty . +)))))
diff --git a/src/lib/libssl/src/doc/crypto/BIO_ctrl.pod b/src/lib/libssl/src/doc/crypto/BIO_ctrl.pod
new file mode 100644
index 0000000000..722e8b8f46
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_ctrl.pod
@@ -0,0 +1,128 @@
1=pod
2
3=head1 NAME
4
5BIO_ctrl, BIO_callback_ctrl, BIO_ptr_ctrl, BIO_int_ctrl, BIO_reset,
6BIO_seek, BIO_tell, BIO_flush, BIO_eof, BIO_set_close, BIO_get_close,
7BIO_pending, BIO_wpending, BIO_ctrl_pending, BIO_ctrl_wpending,
8BIO_get_info_callback, BIO_set_info_callback - BIO control operations
9
10=head1 SYNOPSIS
11
12 #include <openssl/bio.h>
13
14 long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
15 long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
16 char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
17 long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
18
19 int BIO_reset(BIO *b);
20 int BIO_seek(BIO *b, int ofs);
21 int BIO_tell(BIO *b);
22 int BIO_flush(BIO *b);
23 int BIO_eof(BIO *b);
24 int BIO_set_close(BIO *b,long flag);
25 int BIO_get_close(BIO *b);
26 int BIO_pending(BIO *b);
27 int BIO_wpending(BIO *b);
28 size_t BIO_ctrl_pending(BIO *b);
29 size_t BIO_ctrl_wpending(BIO *b);
30
31 int BIO_get_info_callback(BIO *b,bio_info_cb **cbp);
32 int BIO_set_info_callback(BIO *b,bio_info_cb *cb);
33
34 typedef void bio_info_cb(BIO *b, int oper, const char *ptr, int arg1, long arg2, long arg3);
35
36=head1 DESCRIPTION
37
38BIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl() and BIO_int_ctrl()
39are BIO "control" operations taking arguments of various types.
40These functions are not normally called directly, various macros
41are used instead. The standard macros are described below, macros
42specific to a particular type of BIO are described in the specific
43BIOs manual page as well as any special features of the standard
44calls.
45
46BIO_reset() typically resets a BIO to some initial state, in the case
47of file related BIOs for example it rewinds the file pointer to the
48start of the file.
49
50BIO_seek() resets a file related BIO's (that is file descriptor and
51FILE BIOs) file position pointer to B<ofs> bytes from start of file.
52
53BIO_tell() returns the current file position of a file related BIO.
54
55BIO_flush() normally writes out any internally buffered data, in some
56cases it is used to signal EOF and that no more data will be written.
57
58BIO_eof() returns 1 if the BIO has read EOF, the precise meaning of
59"EOF" varies according to the BIO type.
60
61BIO_set_close() sets the BIO B<b> close flag to B<flag>. B<flag> can
62take the value BIO_CLOSE or BIO_NOCLOSE. Typically BIO_CLOSE is used
63in a source/sink BIO to indicate that the underlying I/O stream should
64be closed when the BIO is freed.
65
66BIO_get_close() returns the BIOs close flag.
67
68BIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
69return the number of pending characters in the BIOs read and write buffers.
70Not all BIOs support these calls. BIO_ctrl_pending() and BIO_ctrl_wpending()
71return a size_t type and are functions, BIO_pending() and BIO_wpending() are
72macros which call BIO_ctrl().
73
74=head1 RETURN VALUES
75
76BIO_reset() normally returns 1 for success and 0 or -1 for failure. File
77BIOs are an exception, they return 0 for success and -1 for failure.
78
79BIO_seek() and BIO_tell() both return the current file position on success
80and -1 for failure, except file BIOs which for BIO_seek() always return 0
81for success and -1 for failure.
82
83BIO_flush() returns 1 for success and 0 or -1 for failure.
84
85BIO_eof() returns 1 if EOF has been reached 0 otherwise.
86
87BIO_set_close() always returns 1.
88
89BIO_get_close() returns the close flag value: BIO_CLOSE or BIO_NOCLOSE.
90
91BIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
92return the amount of pending data.
93
94=head1 NOTES
95
96BIO_flush(), because it can write data may return 0 or -1 indicating
97that the call should be retried later in a similar manner to BIO_write().
98The BIO_should_retry() call should be used and appropriate action taken
99is the call fails.
100
101The return values of BIO_pending() and BIO_wpending() may not reliably
102determine the amount of pending data in all cases. For example in the
103case of a file BIO some data may be available in the FILE structures
104internal buffers but it is not possible to determine this in a
105portably way. For other types of BIO they may not be supported.
106
107Filter BIOs if they do not internally handle a particular BIO_ctrl()
108operation usually pass the operation to the next BIO in the chain.
109This often means there is no need to locate the required BIO for
110a particular operation, it can be called on a chain and it will
111be automatically passed to the relevant BIO. However this can cause
112unexpected results: for example no current filter BIOs implement
113BIO_seek(), but this may still succeed if the chain ends in a FILE
114or file descriptor BIO.
115
116Source/sink BIOs return an 0 if they do not recognize the BIO_ctrl()
117operation.
118
119=head1 BUGS
120
121Some of the return values are ambiguous and care should be taken. In
122particular a return value of 0 can be returned if an operation is not
123supported, if an error occurred, if EOF has not been reached and in
124the case of BIO_seek() on a file BIO for a successful operation.
125
126=head1 SEE ALSO
127
128TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_base64.pod b/src/lib/libssl/src/doc/crypto/BIO_f_base64.pod
new file mode 100644
index 0000000000..fdb603b38e
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_base64.pod
@@ -0,0 +1,82 @@
1=pod
2
3=head1 NAME
4
5BIO_f_base64 - base64 BIO filter
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10 #include <openssl/evp.h>
11
12 BIO_METHOD * BIO_f_base64(void);
13
14=head1 DESCRIPTION
15
16BIO_f_base64() returns the base64 BIO method. This is a filter
17BIO that base64 encodes any data written through it and decodes
18any data read through it.
19
20Base64 BIOs do not support BIO_gets() or BIO_puts().
21
22BIO_flush() on a base64 BIO that is being written through is
23used to signal that no more data is to be encoded: this is used
24to flush the final block through the BIO.
25
26The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags()
27to encode the data all on one line or expect the data to be all
28on one line.
29
30=head1 NOTES
31
32Because of the format of base64 encoding the end of the encoded
33block cannot always be reliably determined.
34
35=head1 RETURN VALUES
36
37BIO_f_base64() returns the base64 BIO method.
38
39=head1 EXAMPLES
40
41Base64 encode the string "Hello World\n" and write the result
42to standard output:
43
44 BIO *bio, *b64;
45 char message[] = "Hello World \n";
46
47 b64 = BIO_new(BIO_f_base64());
48 bio = BIO_new_fp(stdout, BIO_NOCLOSE);
49 bio = BIO_push(b64, bio);
50 BIO_write(bio, message, strlen(message));
51 BIO_flush(bio);
52
53 BIO_free_all(bio);
54
55Read Base64 encoded data from standard input and write the decoded
56data to standard output:
57
58 BIO *bio, *b64, bio_out;
59 char inbuf[512];
60 int inlen;
61 char message[] = "Hello World \n";
62
63 b64 = BIO_new(BIO_f_base64());
64 bio = BIO_new_fp(stdin, BIO_NOCLOSE);
65 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
66 bio = BIO_push(b64, bio);
67 while((inlen = BIO_read(bio, inbuf, strlen(message))) > 0)
68 BIO_write(bio_out, inbuf, inlen);
69
70 BIO_free_all(bio);
71
72=head1 BUGS
73
74The ambiguity of EOF in base64 encoded data can cause additional
75data following the base64 encoded block to be misinterpreted.
76
77There should be some way of specifying a test that the BIO can perform
78to reliably determine EOF (for example a MIME boundary).
79
80=head1 SEE ALSO
81
82TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_buffer.pod b/src/lib/libssl/src/doc/crypto/BIO_f_buffer.pod
new file mode 100644
index 0000000000..c9093c6a57
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_buffer.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5BIO_f_buffer - buffering BIO
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO_METHOD * BIO_f_buffer(void);
12
13 #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
14 #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
15 #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
16 #define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
17 #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
18
19=head1 DESCRIPTION
20
21BIO_f_buffer() returns the buffering BIO method.
22
23Data written to a buffering BIO is buffered and periodically written
24to the next BIO in the chain. Data read from a buffering BIO comes from
25an internal buffer which is filled from the next BIO in the chain.
26Both BIO_gets() and BIO_puts() are supported.
27
28Calling BIO_reset() on a buffering BIO clears any buffered data.
29
30BIO_get_buffer_num_lines() returns the number of lines currently buffered.
31
32BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size()
33set the read, write or both read and write buffer sizes to B<size>. The initial
34buffer size is DEFAULT_BUFFER_SIZE, currently 1024. Any attempt to reduce the
35buffer size below DEFAULT_BUFFER_SIZE is ignored. Any buffered data is cleared
36when the buffer is resized.
37
38BIO_set_buffer_read_data() clears the read buffer and fills it with B<num>
39bytes of B<buf>. If B<num> is larger than the current buffer size the buffer
40is expanded.
41
42=head1 NOTES
43
44Buffering BIOs implement BIO_gets() by using BIO_read() operations on the
45next BIO in the chain. By prepending a buffering BIO to a chain it is therefore
46possible to provide BIO_gets() functionality if the following BIOs do not
47support it (for example SSL BIOs).
48
49Data is only written to the next BIO in the chain when the write buffer fills
50or when BIO_flush() is called. It is therefore important to call BIO_flush()
51whenever any pending data should be written such as when removing a buffering
52BIO using BIO_pop(). BIO_flush() may need to be retried if the ultimate
53source/sink BIO is non blocking.
54
55=head1 RETURN VALUES
56
57BIO_f_buffer() returns the buffering BIO method.
58
59BIO_get_buffer_num_lines() returns the number of lines buffered (may be 0).
60
61BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size()
62return 1 if the buffer was successfully resized or 0 for failure.
63
64BIO_set_buffer_read_data() returns 1 if the data was set correctly or 0 if
65there was an error.
66
67=head1 SEE ALSO
68
69TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_cipher.pod b/src/lib/libssl/src/doc/crypto/BIO_f_cipher.pod
new file mode 100644
index 0000000000..4182f2c309
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_cipher.pod
@@ -0,0 +1,76 @@
1=pod
2
3=head1 NAME
4
5BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx - cipher BIO filter
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10 #include <openssl/evp.h>
11
12 BIO_METHOD * BIO_f_cipher(void);
13 void BIO_set_cipher(BIO *b,const EVP_CIPHER *cipher,
14 unsigned char *key, unsigned char *iv, int enc);
15 int BIO_get_cipher_status(BIO *b)
16 int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx)
17
18=head1 DESCRIPTION
19
20BIO_f_cipher() returns the cipher BIO method. This is a filter
21BIO that encrypts any data written through it, and decrypts any data
22read from it. It is a BIO wrapper for the cipher routines
23EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal().
24
25Cipher BIOs do not support BIO_gets() or BIO_puts().
26
27BIO_flush() on an encryption BIO that is being written through is
28used to signal that no more data is to be encrypted: this is used
29to flush and possibly pad the final block through the BIO.
30
31BIO_set_cipher() sets the cipher of BIO <b> to B<cipher> using key B<key>
32and IV B<iv>. B<enc> should be set to 1 for encryption and zero for
33decryption.
34
35When reading from an encryption BIO the final block is automatically
36decrypted and checked when EOF is detected. BIO_get_cipher_status()
37is a BIO_ctrl() macro which can be called to determine whether the
38decryption operation was successful.
39
40BIO_get_cipher_ctx() is a BIO_ctrl() macro which retrieves the internal
41BIO cipher context. The retrieved context can be used in conjunction
42with the standard cipher routines to set it up. This is useful when
43BIO_set_cipher() is not flexible enough for the applications needs.
44
45=head1 NOTES
46
47When encrypting BIO_flush() B<must> be called to flush the final block
48through the BIO. If it is not then the final block will fail a subsequent
49decrypt.
50
51When decrypting an error on the final block is signalled by a zero
52return value from the read operation. A successful decrypt followed
53by EOF will also return zero for the final read. BIO_get_cipher_status()
54should be called to determine if the decrypt was successful.
55
56As always, if BIO_gets() or BIO_puts() support is needed then it can
57be achieved by preceding the cipher BIO with a buffering BIO.
58
59=head1 RETURN VALUES
60
61BIO_f_cipher() returns the cipher BIO method.
62
63BIO_set_cipher() does not return a value.
64
65BIO_get_cipher_status() returns 1 for a successful decrypt and 0
66for failure.
67
68BIO_get_cipher_ctx() currently always returns 1.
69
70=head1 EXAMPLES
71
72TBA
73
74=head1 SEE ALSO
75
76TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_md.pod b/src/lib/libssl/src/doc/crypto/BIO_f_md.pod
new file mode 100644
index 0000000000..c32504dfb1
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_md.pod
@@ -0,0 +1,138 @@
1=pod
2
3=head1 NAME
4
5BIO_f_md, BIO_set_md, BIO_get_md, BIO_get_md_ctx - message digest BIO filter
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10 #include <openssl/evp.h>
11
12 BIO_METHOD * BIO_f_md(void);
13 int BIO_set_md(BIO *b,EVP_MD *md);
14 int BIO_get_md(BIO *b,EVP_MD **mdp);
15 int BIO_get_md_ctx(BIO *b,EVP_MD_CTX **mdcp);
16
17=head1 DESCRIPTION
18
19BIO_f_md() returns the message digest BIO method. This is a filter
20BIO that digests any data passed through it, it is a BIO wrapper
21for the digest routines EVP_DigestInit(), EVP_DigestUpdate()
22and EVP_DigestFinal().
23
24Any data written or read through a digest BIO using BIO_read() and
25BIO_write() is digested.
26
27BIO_gets(), if its B<size> parameter is large enough finishes the
28digest calculation and returns the digest value. BIO_puts() is
29not supported.
30
31BIO_reset() reinitializes a digest BIO.
32
33BIO_set_md() sets the message digest of BIO B<b> to B<md>: this
34must be called to initialize a digest BIO before any data is
35passed through it. It is a BIO_ctrl() macro.
36
37BIO_get_md() places the a pointer to the digest BIOs digest method
38in B<mdp>, it is a BIO_ctrl() macro.
39
40BIO_get_md_ctx() returns the digest BIOs context into B<mdcp>.
41
42=head1 NOTES
43
44The context returned by BIO_get_md_ctx() can be used in calls
45to EVP_DigestFinal() and also the signature routines EVP_SignFinal()
46and EVP_VerifyFinal().
47
48The context returned by BIO_get_md_ctx() is an internal context
49structure. Changes made to this context will affect the digest
50BIO itself and the context pointer will become invalid when the digest
51BIO is freed.
52
53After the digest has been retrieved from a digest BIO it must be
54reinitialized by calling BIO_reset(), or BIO_set_md() before any more
55data is passed through it.
56
57If an application needs to call BIO_gets() or BIO_puts() through
58a chain containing digest BIOs then this can be done by prepending
59a buffering BIO.
60
61=head1 RETURN VALUES
62
63BIO_f_md() returns the digest BIO method.
64
65BIO_set_md(), BIO_get_md() and BIO_md_ctx() return 1 for success and
660 for failure.
67
68=head1 EXAMPLES
69
70The following example creates a BIO chain containing an SHA1 and MD5
71digest BIO and passes the string "Hello World" through it. Error
72checking has been omitted for clarity.
73
74 BIO *bio, *mdtmp;
75 char message[] = "Hello World";
76 bio = BIO_new(BIO_s_null());
77 mdtmp = BIO_new(BIO_f_md());
78 BIO_set_md(mdtmp, EVP_sha1());
79 /* For BIO_push() we want to append the sink BIO and keep a note of
80 * the start of the chain.
81 */
82 bio = BIO_push(mdtmp, bio);
83 mdtmp = BIO_new(BIO_f_md());
84 BIO_set_md(mdtmp, EVP_md5());
85 bio = BIO_push(mdtmp, bio);
86 /* Note: mdtmp can now be discarded */
87 BIO_write(bio, message, strlen(message));
88
89The next example digests data by reading through a chain instead:
90
91 BIO *bio, *mdtmp;
92 char buf[1024];
93 int rdlen;
94 bio = BIO_new_file(file, "rb");
95 mdtmp = BIO_new(BIO_f_md());
96 BIO_set_md(mdtmp, EVP_sha1());
97 bio = BIO_push(mdtmp, bio);
98 mdtmp = BIO_new(BIO_f_md());
99 BIO_set_md(mdtmp, EVP_md5());
100 bio = BIO_push(mdtmp, bio);
101 do {
102 rdlen = BIO_read(bio, buf, sizeof(buf));
103 /* Might want to do something with the data here */
104 } while(rdlen > 0);
105
106This next example retrieves the message digests from a BIO chain and
107outputs them. This could be used with the examples above.
108
109 BIO *mdtmp;
110 unsigned char mdbuf[EVP_MAX_MD_SIZE];
111 int mdlen;
112 int i;
113 mdtmp = bio; /* Assume bio has previously been set up */
114 do {
115 EVP_MD *md;
116 mdtmp = BIO_find_type(mdtmp, BIO_TYPE_MD);
117 if(!mdtmp) break;
118 BIO_get_md(mdtmp, &md);
119 printf("%s digest", OBJ_nid2sn(EVP_MD_type(md)));
120 mdlen = BIO_gets(mdtmp, mdbuf, EVP_MAX_MD_SIZE);
121 for(i = 0; i < mdlen; i++) printf(":%02X", mdbuf[i]);
122 printf("\n");
123 mdtmp = BIO_next(mdtmp);
124 } while(mdtmp);
125
126 BIO_free_all(bio);
127
128=head1 BUGS
129
130The lack of support for BIO_puts() and the non standard behaviour of
131BIO_gets() could be regarded as anomalous. It could be argued that BIO_gets()
132and BIO_puts() should be passed to the next BIO in the chain and digest
133the data passed through and that digests should be retrieved using a
134separate BIO_ctrl() call.
135
136=head1 SEE ALSO
137
138TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_null.pod b/src/lib/libssl/src/doc/crypto/BIO_f_null.pod
new file mode 100644
index 0000000000..b057c18408
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_null.pod
@@ -0,0 +1,32 @@
1=pod
2
3=head1 NAME
4
5BIO_f_null - null filter
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO_METHOD * BIO_f_null(void);
12
13=head1 DESCRIPTION
14
15BIO_f_null() returns the null filter BIO method. This is a filter BIO
16that does nothing.
17
18All requests to a null filter BIO are passed through to the next BIO in
19the chain: this means that a BIO chain containing a null filter BIO
20behaves just as though the BIO was not there.
21
22=head1 NOTES
23
24As may be apparent a null filter BIO is not particularly useful.
25
26=head1 RETURN VALUES
27
28BIO_f_null() returns the null filter BIO method.
29
30=head1 SEE ALSO
31
32TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_ssl.pod b/src/lib/libssl/src/doc/crypto/BIO_f_ssl.pod
new file mode 100644
index 0000000000..a56ee2b92f
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_f_ssl.pod
@@ -0,0 +1,313 @@
1=pod
2
3=head1 NAME
4
5BIO_f_ssl, BIO_set_ssl, BIO_get_ssl, BIO_set_ssl_mode, BIO_set_ssl_renegotiate_bytes,
6BIO_get_num_renegotiates, BIO_set_ssl_renegotiate_timeout, BIO_new_ssl,
7BIO_new_ssl_connect, BIO_new_buffer_ssl_connect, BIO_ssl_copy_session_id,
8BIO_ssl_shutdown - SSL BIO
9
10=head1 SYNOPSIS
11
12 #include <openssl/bio.h>
13 #include <openssl/ssl.h>
14
15 BIO_METHOD *BIO_f_ssl(void);
16
17 #define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
18 #define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
19 #define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
20 #define BIO_set_ssl_renegotiate_bytes(b,num) \
21 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
22 #define BIO_set_ssl_renegotiate_timeout(b,seconds) \
23 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
24 #define BIO_get_num_renegotiates(b) \
25 BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL);
26
27 BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
28 BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
29 BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
30 int BIO_ssl_copy_session_id(BIO *to,BIO *from);
31 void BIO_ssl_shutdown(BIO *bio);
32
33 #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
34
35=head1 DESCRIPTION
36
37BIO_f_ssl() returns the SSL BIO method. This is a filter BIO which
38is a wrapper round the OpenSSL SSL routines adding a BIO "flavour" to
39SSL I/O.
40
41I/O performed on an SSL BIO communicates using the SSL protocol with
42the SSLs read and write BIOs. If an SSL connection is not established
43then an attempt is made to establish one on the first I/O call.
44
45If a BIO is appended to an SSL BIO using BIO_push() it is automatically
46used as the SSL BIOs read and write BIOs.
47
48Calling BIO_reset() on an SSL BIO closes down any current SSL connection
49by calling SSL_shutdown(). BIO_reset() is then sent to the next BIO in
50the chain: this will typically disconnect the underlying transport.
51The SSL BIO is then reset to the initial accept or connect state.
52
53If the close flag is set when an SSL BIO is freed then the internal
54SSL structure is also freed using SSL_free().
55
56BIO_set_ssl() sets the internal SSL pointer of BIO B<b> to B<ssl> using
57the close flag B<c>.
58
59BIO_get_ssl() retrieves the SSL pointer of BIO B<b>, it can then be
60manipulated using the standard SSL library functions.
61
62BIO_set_ssl_mode() sets the SSL BIO mode to B<client>. If B<client>
63is 1 client mode is set. If B<client> is 0 server mode is set.
64
65BIO_set_ssl_renegotiate_bytes() sets the renegotiate byte count
66to B<num>. When set after every B<num> bytes of I/O (read and write)
67the SSL session is automatically renegotiated. B<num> must be at
68least 512 bytes.
69
70BIO_set_ssl_renegotiate_timeout() sets the renegotiate timeout to
71B<seconds>. When the renegotiate timeout elapses the session is
72automatically renegotiated.
73
74BIO_get_num_renegotiates() returns the total number of session
75renegotiations due to I/O or timeout.
76
77BIO_new_ssl() allocates an SSL BIO using SSL_CTX B<ctx> and using
78client mode if B<client> is non zero.
79
80BIO_new_ssl_connect() creates a new BIO chain consisting of an
81SSL BIO (using B<ctx>) followed by a connect BIO.
82
83BIO_new_buffer_ssl_connect() creates a new BIO chain consisting
84of a buffering BIO, an SSL BIO (using B<ctx>) and a connect
85BIO.
86
87BIO_ssl_copy_session_id() copies an SSL session id between
88BIO chains B<from> and B<to>. It does this by locating the
89SSL BIOs in each chain and calling SSL_copy_session_id() on
90the internal SSL pointer.
91
92BIO_ssl_shutdown() closes down an SSL connection on BIO
93chain B<bio>. It does this by locating the SSL BIO in the
94chain and calling SSL_shutdown() on its internal SSL
95pointer.
96
97BIO_do_handshake() attempts to complete an SSL handshake on the
98supplied BIO and establish the SSL connection. It returns 1
99if the connection was established successfully. A zero or negative
100value is returned if the connection could not be established, the
101call BIO_should_retry() should be used for non blocking connect BIOs
102to determine if the call should be retried. If an SSL connection has
103already been established this call has no effect.
104
105=head1 NOTES
106
107SSL BIOs are exceptional in that if the underlying transport
108is non blocking they can still request a retry in exceptional
109circumstances. Specifically this will happen if a session
110renegotiation takes place during a BIO_read() operation, one
111case where this happens is when SGC or step up occurs.
112
113In OpenSSL 0.9.6 and later the SSL flag SSL_AUTO_RETRY can be
114set to disable this behaviour. That is when this flag is set
115an SSL BIO using a blocking transport will never request a
116retry.
117
118Since unknown BIO_ctrl() operations are sent through filter
119BIOs the servers name and port can be set using BIO_set_host()
120on the BIO returned by BIO_new_ssl_connect() without having
121to locate the connect BIO first.
122
123Applications do not have to call BIO_do_handshake() but may wish
124to do so to separate the handshake process from other I/O
125processing.
126
127=head1 RETURN VALUES
128
129TBA
130
131=head1 EXAMPLE
132
133This SSL/TLS client example, attempts to retrieve a page from an
134SSL/TLS web server. The I/O routines are identical to those of the
135unencrypted example in L<BIO_s_connect(3)|BIO_s_connect(3)>.
136
137 BIO *sbio, *out;
138 int len;
139 char tmpbuf[1024];
140 SSL_CTX *ctx;
141 SSL *ssl;
142
143 ERR_load_crypto_strings();
144 ERR_load_SSL_strings();
145 OpenSSL_add_all_algorithms();
146
147 /* We would seed the PRNG here if the platform didn't
148 * do it automatically
149 */
150
151 ctx = SSL_CTX_new(SSLv23_client_method());
152
153 /* We'd normally set some stuff like the verify paths and
154 * mode here because as things stand this will connect to
155 * any server whose certificate is signed by any CA.
156 */
157
158 sbio = BIO_new_ssl_connect(ctx);
159
160 BIO_get_ssl(sbio, &ssl);
161
162 if(!ssl) {
163 fprintf(stderr, "Can't locate SSL pointer\n");
164 /* whatever ... */
165 }
166
167 /* Don't want any retries */
168 SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
169
170 /* We might want to do other things with ssl here */
171
172 BIO_set_conn_hostname(sbio, "localhost:https");
173
174 out = BIO_new_fp(stdout, BIO_NOCLOSE);
175 if(BIO_do_connect(sbio) <= 0) {
176 fprintf(stderr, "Error connecting to server\n");
177 ERR_print_errors_fp(stderr);
178 /* whatever ... */
179 }
180
181 if(BIO_do_handshake(sbio) <= 0) {
182 fprintf(stderr, "Error establishing SSL connection\n");
183 ERR_print_errors_fp(stderr);
184 /* whatever ... */
185 }
186
187 /* Could examine ssl here to get connection info */
188
189 BIO_puts(sbio, "GET / HTTP/1.0\n\n");
190 for(;;) {
191 len = BIO_read(sbio, tmpbuf, 1024);
192 if(len <= 0) break;
193 BIO_write(out, tmpbuf, len);
194 }
195 BIO_free_all(sbio);
196 BIO_free(out);
197
198Here is a simple server example. It makes use of a buffering
199BIO to allow lines to be read from the SSL BIO using BIO_gets.
200It creates a pseudo web page containing the actual request from
201a client and also echoes the request to standard output.
202
203 BIO *sbio, *bbio, *acpt, *out;
204 int len;
205 char tmpbuf[1024];
206 SSL_CTX *ctx;
207 SSL *ssl;
208
209 ERR_load_crypto_strings();
210 ERR_load_SSL_strings();
211 OpenSSL_add_all_algorithms();
212
213 /* Might seed PRNG here */
214
215 ctx = SSL_CTX_new(SSLv23_server_method());
216
217 if (!SSL_CTX_use_certificate_file(ctx,"server.pem",SSL_FILETYPE_PEM)
218 || !SSL_CTX_use_PrivateKey_file(ctx,"server.pem",SSL_FILETYPE_PEM)
219 || !SSL_CTX_check_private_key(ctx)) {
220
221 fprintf(stderr, "Error setting up SSL_CTX\n");
222 ERR_print_errors_fp(stderr);
223 return 0;
224 }
225
226 /* Might do other things here like setting verify locations and
227 * DH and/or RSA temporary key callbacks
228 */
229
230 /* New SSL BIO setup as server */
231 sbio=BIO_new_ssl(ctx,0);
232
233 BIO_get_ssl(sbio, &ssl);
234
235 if(!ssl) {
236 fprintf(stderr, "Can't locate SSL pointer\n");
237 /* whatever ... */
238 }
239
240 /* Don't want any retries */
241 SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
242
243 /* Create the buffering BIO */
244
245 bbio = BIO_new(BIO_f_buffer());
246
247 /* Add to chain */
248 sbio = BIO_push(bbio, sbio);
249
250 acpt=BIO_new_accept("4433");
251
252 /* By doing this when a new connection is established
253 * we automatically have sbio inserted into it. The
254 * BIO chain is now 'swallowed' by the accept BIO and
255 * will be freed when the accept BIO is freed.
256 */
257
258 BIO_set_accept_bios(acpt,sbio);
259
260 out = BIO_new_fp(stdout, BIO_NOCLOSE);
261
262 /* Setup accept BIO */
263 if(BIO_do_accept(acpt) <= 0) {
264 fprintf(stderr, "Error setting up accept BIO\n");
265 ERR_print_errors_fp(stderr);
266 return 0;
267 }
268
269 /* Now wait for incoming connection */
270 if(BIO_do_accept(acpt) <= 0) {
271 fprintf(stderr, "Error in connection\n");
272 ERR_print_errors_fp(stderr);
273 return 0;
274 }
275
276 /* We only want one connection so remove and free
277 * accept BIO
278 */
279
280 sbio = BIO_pop(acpt);
281
282 BIO_free_all(acpt);
283
284 if(BIO_do_handshake(sbio) <= 0) {
285 fprintf(stderr, "Error in SSL handshake\n");
286 ERR_print_errors_fp(stderr);
287 return 0;
288 }
289
290 BIO_puts(sbio, "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n");
291 BIO_puts(sbio, "<pre>\r\nConnection Established\r\nRequest headers:\r\n");
292 BIO_puts(sbio, "--------------------------------------------------\r\n");
293
294 for(;;) {
295 len = BIO_gets(sbio, tmpbuf, 1024);
296 if(len <= 0) break;
297 BIO_write(sbio, tmpbuf, len);
298 BIO_write(out, tmpbuf, len);
299 /* Look for blank line signifying end of headers*/
300 if((tmpbuf[0] == '\r') || (tmpbuf[0] == '\n')) break;
301 }
302
303 BIO_puts(sbio, "--------------------------------------------------\r\n");
304 BIO_puts(sbio, "</pre>\r\n");
305
306 /* Since there is a buffering BIO present we had better flush it */
307 BIO_flush(sbio);
308
309 BIO_free_all(sbio);
310
311=head1 SEE ALSO
312
313TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_find_type.pod b/src/lib/libssl/src/doc/crypto/BIO_find_type.pod
new file mode 100644
index 0000000000..bd3b256196
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_find_type.pod
@@ -0,0 +1,98 @@
1=pod
2
3=head1 NAME
4
5BIO_find_type, BIO_next - BIO chain traversal
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO * BIO_find_type(BIO *b,int bio_type);
12 BIO * BIO_next(BIO *b);
13
14 #define BIO_method_type(b) ((b)->method->type)
15
16 #define BIO_TYPE_NONE 0
17 #define BIO_TYPE_MEM (1|0x0400)
18 #define BIO_TYPE_FILE (2|0x0400)
19
20 #define BIO_TYPE_FD (4|0x0400|0x0100)
21 #define BIO_TYPE_SOCKET (5|0x0400|0x0100)
22 #define BIO_TYPE_NULL (6|0x0400)
23 #define BIO_TYPE_SSL (7|0x0200)
24 #define BIO_TYPE_MD (8|0x0200)
25 #define BIO_TYPE_BUFFER (9|0x0200)
26 #define BIO_TYPE_CIPHER (10|0x0200)
27 #define BIO_TYPE_BASE64 (11|0x0200)
28 #define BIO_TYPE_CONNECT (12|0x0400|0x0100)
29 #define BIO_TYPE_ACCEPT (13|0x0400|0x0100)
30 #define BIO_TYPE_PROXY_CLIENT (14|0x0200)
31 #define BIO_TYPE_PROXY_SERVER (15|0x0200)
32 #define BIO_TYPE_NBIO_TEST (16|0x0200)
33 #define BIO_TYPE_NULL_FILTER (17|0x0200)
34 #define BIO_TYPE_BER (18|0x0200)
35 #define BIO_TYPE_BIO (19|0x0400)
36
37 #define BIO_TYPE_DESCRIPTOR 0x0100
38 #define BIO_TYPE_FILTER 0x0200
39 #define BIO_TYPE_SOURCE_SINK 0x0400
40
41=head1 DESCRIPTION
42
43The BIO_find_type() searches for a BIO of a given type in a chain, starting
44at BIO B<b>. If B<type> is a specific type (such as BIO_TYPE_MEM) then a search
45is made for a BIO of that type. If B<type> is a general type (such as
46B<BIO_TYPE_SOURCE_SINK>) then the next matching BIO of the given general type is
47searched for. BIO_find_type() returns the next matching BIO or NULL if none is
48found.
49
50Note: not all the B<BIO_TYPE_*> types above have corresponding BIO implementations.
51
52BIO_next() returns the next BIO in a chain. It can be used to traverse all BIOs
53in a chain or used in conjunction with BIO_find_type() to find all BIOs of a
54certain type.
55
56BIO_method_type() returns the type of a BIO.
57
58=head1 RETURN VALUES
59
60BIO_find_type() returns a matching BIO or NULL for no match.
61
62BIO_next() returns the next BIO in a chain.
63
64BIO_method_type() returns the type of the BIO B<b>.
65
66=head1 NOTES
67
68BIO_next() was added to OpenSSL 0.9.6 to provide a 'clean' way to traverse a BIO
69chain or find multiple matches using BIO_find_type(). Previous versions had to
70use:
71
72 next = bio->next_bio;
73
74=head1 BUGS
75
76BIO_find_type() in OpenSSL 0.9.5a and earlier could not be safely passed a
77NULL pointer for the B<b> argument.
78
79=head1 EXAMPLE
80
81Traverse a chain looking for digest BIOs:
82
83 BIO *btmp;
84 btmp = in_bio; /* in_bio is chain to search through */
85
86 do {
87 btmp = BIO_find_type(btmp, BIO_TYPE_MD);
88 if(btmp == NULL) break; /* Not found */
89 /* btmp is a digest BIO, do something with it ...*/
90 ...
91
92 btmp = BIO_next(btmp);
93 } while(btmp);
94
95
96=head1 SEE ALSO
97
98TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_new.pod b/src/lib/libssl/src/doc/crypto/BIO_new.pod
new file mode 100644
index 0000000000..2a245fc8de
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_new.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5BIO_new, BIO_set, BIO_free, BIO_vfree, BIO_free_all - BIO allocation and freeing functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO * BIO_new(BIO_METHOD *type);
12 int BIO_set(BIO *a,BIO_METHOD *type);
13 int BIO_free(BIO *a);
14 void BIO_vfree(BIO *a);
15 void BIO_free_all(BIO *a);
16
17=head1 DESCRIPTION
18
19The BIO_new() function returns a new BIO using method B<type>.
20
21BIO_set() sets the method of an already existing BIO.
22
23BIO_free() frees up a single BIO, BIO_vfree() also frees up a single BIO
24but it does not return a value. Calling BIO_free() may also have some effect
25on the underlying I/O structure, for example it may close the file being
26referred to under certain circumstances. For more details see the individual
27BIO_METHOD descriptions.
28
29BIO_free_all() frees up an entire BIO chain, it does not halt if an error
30occurs freeing up an individual BIO in the chain.
31
32=head1 RETURN VALUES
33
34BIO_new() returns a newly created BIO or NULL if the call fails.
35
36BIO_set(), BIO_free() return 1 for success and 0 for failure.
37
38BIO_free_all() and BIO_vfree() do not return values.
39
40=head1 NOTES
41
42Some BIOs (such as memory BIOs) can be used immediately after calling
43BIO_new(). Others (such as file BIOs) need some additional initialization,
44and frequently a utility function exists to create and initialize such BIOs.
45
46If BIO_free() is called on a BIO chain it will only free one BIO resulting
47in a memory leak.
48
49Calling BIO_free_all() a single BIO has the same effect as calling BIO_free()
50on it other than the discarded return value.
51
52Normally the B<type> argument is supplied by a function which returns a
53pointer to a BIO_METHOD. There is a naming convention for such functions:
54a source/sink BIO is normally called BIO_s_*() and a filter BIO
55BIO_f_*();
56
57=head1 EXAMPLE
58
59Create a memory BIO:
60
61 BIO *mem = BIO_new(BIO_s_mem());
62
63=head1 SEE ALSO
64
65TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_push.pod b/src/lib/libssl/src/doc/crypto/BIO_push.pod
new file mode 100644
index 0000000000..8af1d3c097
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_push.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5BIO_push, BIO_pop - add and remove BIOs from a chain.
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO * BIO_push(BIO *b,BIO *append);
12 BIO * BIO_pop(BIO *b);
13
14=head1 DESCRIPTION
15
16The BIO_push() function appends the BIO B<append> to B<b>, it returns
17B<b>.
18
19BIO_pop() removes the BIO B<b> from a chain and returns the next BIO
20in the chain, or NULL if there is no next BIO. The removed BIO then
21becomes a single BIO with no association with the original chain,
22it can thus be freed or attached to a different chain.
23
24=head1 NOTES
25
26The names of these functions are perhaps a little misleading. BIO_push()
27joins two BIO chains whereas BIO_pop() deletes a single BIO from a chain,
28the deleted BIO does not need to be at the end of a chain.
29
30The process of calling BIO_push() and BIO_pop() on a BIO may have additional
31consequences (a control call is made to the affected BIOs) any effects will
32be noted in the descriptions of individual BIOs.
33
34=head1 EXAMPLES
35
36For these examples suppose B<md1> and B<md2> are digest BIOs, B<b64> is
37a base64 BIO and B<f> is a file BIO.
38
39If the call:
40
41 BIO_push(b64, f);
42
43is made then the new chain will be B<b64-chain>. After making the calls
44
45 BIO_push(md2, b64);
46 BIO_push(md1, md2);
47
48the new chain is B<md1-md2-b64-f>. Data written to B<md1> will be digested
49by B<md1> and B<md2>, B<base64> encoded and written to B<f>.
50
51It should be noted that reading causes data to pass in the reverse
52direction, that is data is read from B<f>, base64 B<decoded> and digested
53by B<md1> and B<md2>. If the call:
54
55 BIO_pop(md2);
56
57The call will return B<b64> and the new chain will be B<md1-b64-f> data can
58be written to B<md1> as before.
59
60=head1 RETURN VALUES
61
62BIO_push() returns the end of the chain, B<b>.
63
64BIO_pop() returns the next BIO in the chain, or NULL if there is no next
65BIO.
66
67=head1 SEE ALSO
68
69TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_read.pod b/src/lib/libssl/src/doc/crypto/BIO_read.pod
new file mode 100644
index 0000000000..b34528104d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_read.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5BIO_read, BIO_write, BIO_gets, BIO_puts - BIO I/O functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 int BIO_read(BIO *b, void *buf, int len);
12 int BIO_gets(BIO *b,char *buf, int size);
13 int BIO_write(BIO *b, const void *buf, int len);
14 int BIO_puts(BIO *b,const char *buf);
15
16=head1 DESCRIPTION
17
18BIO_read() attempts to read B<len> bytes from BIO B<b> and places
19the data in B<buf>.
20
21BIO_gets() performs the BIOs "gets" operation and places the data
22in B<buf>. Usually this operation will attempt to read a line of data
23from the BIO of maximum length B<len>. There are exceptions to this
24however, for example BIO_gets() on a digest BIO will calculate and
25return the digest and other BIOs may not support BIO_gets() at all.
26
27BIO_write() attempts to write B<len> bytes from B<buf> to BIO B<b>.
28
29BIO_puts() attempts to write a null terminated string B<buf> to BIO B<b>
30
31=head1 RETURN VALUES
32
33All these functions return either the amount of data successfully read or
34written (if the return value is positive) or that no data was successfully
35read or written if the result is 0 or -1. If the return value is -2 then
36the operation is not implemented in the specific BIO type.
37
38=head1 NOTES
39
40A 0 or -1 return is not necessarily an indication of an error. In
41particular when the source/sink is non-blocking or of a certain type
42it may merely be an indication that no data is currently available and that
43the application should retry the operation later.
44
45One technique sometimes used with blocking sockets is to use a system call
46(such as select(), poll() or equivalent) to determine when data is available
47and then call read() to read the data. The equivalent with BIOs (that is call
48select() on the underlying I/O structure and then call BIO_read() to
49read the data) should B<not> be used because a single call to BIO_read()
50can cause several reads (and writes in the case of SSL BIOs) on the underlying
51I/O structure and may block as a result. Instead select() (or equivalent)
52should be combined with non blocking I/O so successive reads will request
53a retry instead of blocking.
54
55See L<BIO_should_retry(3)|BIO_should_retry(3)> for details of how to
56determine the cause of a retry and other I/O issues.
57
58If the BIO_gets() function is not supported by a BIO then it possible to
59work around this by adding a buffering BIO L<BIO_f_buffer(3)|BIO_f_buffer(3)>
60to the chain.
61
62=head1 SEE ALSO
63
64L<BIO_should_retry(3)|BIO_should_retry(3)>
65
66TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod b/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod
new file mode 100644
index 0000000000..c49da7fb02
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod
@@ -0,0 +1,184 @@
1=pod
2
3=head1 NAME
4
5BIO_s_accept, BIO_set_nbio, BIO_set_accept_port, BIO_get_accept_port,
6BIO_set_nbio_accept, BIO_set_accept_bios, BIO_set_bind_mode,
7BIO_get_bind_mode, BIO_do_accept - accept BIO
8
9=head1 SYNOPSIS
10
11 #include <openssl/bio.h>
12
13 BIO_METHOD * BIO_s_accept(void);
14
15 #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
16 #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
17
18 BIO *BIO_new_accept(char *host_port);
19
20 #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
21 #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
22
23 #define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
24 #define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
25
26 #define BIO_BIND_NORMAL 0
27 #define BIO_BIND_REUSEADDR_IF_UNUSED 1
28 #define BIO_BIND_REUSEADDR 2
29
30 #define BIO_do_accept(b) BIO_do_handshake(b)
31
32=head1 DESCRIPTION
33
34BIO_s_accept() returns the accept BIO method. This is a wrapper
35round the platform's TCP/IP socket accept routines.
36
37Using accept BIOs TCP/IP connections can be accepted and data
38transferred using only BIO routines. In this way any platform
39specific operations are hidden by the BIO abstraction.
40
41Read and write operations on an accept BIO will perform I/O
42on the underlying connection. If no connection is established
43and the port (see below) is set up properly then the BIO
44waits for an incoming connection.
45
46Accept BIOs support BIO_puts() but not BIO_gets().
47
48If the close flag is set on an accept BIO then any active
49connection on that chain is shutdown and the socket closed when
50the BIO is freed.
51
52Calling BIO_reset() on a accept BIO will close any active
53connection and reset the BIO into a state where it awaits another
54incoming connection.
55
56BIO_get_fd() and BIO_set_fd() can be called to retrieve or set
57the accept socket. See L<BIO_s_fd(3)|BIO_s_fd(3)>
58
59BIO_set_accept_port() uses the string B<name> to set the accept
60port. The port is represented as a string of the form "host:port",
61where "host" is the interface to use and "port" is the port.
62Either or both values can be "*" which is interpreted as meaning
63any interface or port respectively. "port" has the same syntax
64as the port specified in BIO_set_conn_port() for connect BIOs,
65that is it can be a numerical port string or a string to lookup
66using getservbyname() and a string table.
67
68BIO_new_accept() combines BIO_new() and BIO_set_accept_port() into
69a single call: that is it creates a new accept BIO with port
70B<host_port>.
71
72BIO_set_nbio_accept() sets the accept socket to blocking mode
73(the default) if B<n> is 0 or non blocking mode if B<n> is 1.
74
75BIO_set_accept_bios() can be used to set a chain of BIOs which
76will be duplicated and prepended to the chain when an incoming
77connection is received. This is useful if, for example, a
78buffering or SSL BIO is required for each connection. The
79chain of BIOs must not be freed after this call, they will
80be automatically freed when the accept BIO is freed.
81
82BIO_set_bind_mode() and BIO_get_bind_mode() set and retrieve
83the current bind mode. If BIO_BIND_NORMAL (the default) is set
84then another socket cannot be bound to the same port. If
85BIO_BIND_REUSEADDR is set then other sockets can bind to the
86same port. If BIO_BIND_REUSEADDR_IF_UNUSED is set then and
87attempt is first made to use BIO_BIN_NORMAL, if this fails
88and the port is not in use then a second attempt is made
89using BIO_BIND_REUSEADDR.
90
91BIO_do_accept() serves two functions. When it is first
92called, after the accept BIO has been setup, it will attempt
93to create the accept socket and bind an address to it. Second
94and subsequent calls to BIO_do_accept() will await an incoming
95connection.
96
97=head1 NOTES
98
99When an accept BIO is at the end of a chain it will await an
100incoming connection before processing I/O calls. When an accept
101BIO is not at then end of a chain it passes I/O calls to the next
102BIO in the chain.
103
104When a connection is established a new socket BIO is created for
105the connection and appended to the chain. That is the chain is now
106accept->socket. This effectively means that attempting I/O on
107an initial accept socket will await an incoming connection then
108perform I/O on it.
109
110If any additional BIOs have been set using BIO_set_accept_bios()
111then they are placed between the socket and the accept BIO,
112that is the chain will be accept->otherbios->socket.
113
114If a server wishes to process multiple connections (as is normally
115the case) then the accept BIO must be made available for further
116incoming connections. This can be done by waiting for a connection and
117then calling:
118
119 connection = BIO_pop(accept);
120
121After this call B<connection> will contain a BIO for the recently
122established connection and B<accept> will now be a single BIO
123again which can be used to await further incoming connections.
124If no further connections will be accepted the B<accept> can
125be freed using BIO_free().
126
127If only a single connection will be processed it is possible to
128perform I/O using the accept BIO itself. This is often undesirable
129however because the accept BIO will still accept additional incoming
130connections. This can be resolved by using BIO_pop() (see above)
131and freeing up the accept BIO after the initial connection.
132
133=head1 RETURN VALUES
134
135TBA
136
137=head1 EXAMPLE
138
139This example accepts two connections on port 4444, sends messages
140down each and finally closes both down.
141
142 BIO *abio, *cbio, *cbio2;
143 ERR_load_crypto_strings();
144 abio = BIO_new_accept("4444");
145
146 /* First call to BIO_accept() sets up accept BIO */
147 if(BIO_do_accept(abio) <= 0) {
148 fprintf(stderr, "Error setting up accept\n");
149 ERR_print_errors_fp(stderr);
150 exit(0);
151 }
152
153 /* Wait for incoming connection */
154 if(BIO_do_accept(abio) <= 0) {
155 fprintf(stderr, "Error accepting connection\n");
156 ERR_print_errors_fp(stderr);
157 exit(0);
158 }
159 fprintf(stderr, "Connection 1 established\n");
160 /* Retrieve BIO for connection */
161 cbio = BIO_pop(abio);
162 BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n");
163 fprintf(stderr, "Sent out data on connection 1\n");
164 /* Wait for another connection */
165 if(BIO_do_accept(abio) <= 0) {
166 fprintf(stderr, "Error accepting connection\n");
167 ERR_print_errors_fp(stderr);
168 exit(0);
169 }
170 fprintf(stderr, "Connection 2 established\n");
171 /* Close accept BIO to refuse further connections */
172 cbio2 = BIO_pop(abio);
173 BIO_free(abio);
174 BIO_puts(cbio2, "Connection 2: Sending out Data on second\n");
175 fprintf(stderr, "Sent out data on connection 2\n");
176
177 BIO_puts(cbio, "Connection 1: Second connection established\n");
178 /* Close the two established connections */
179 BIO_free(cbio);
180 BIO_free(cbio2);
181
182=head1 SEE ALSO
183
184TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_bio.pod b/src/lib/libssl/src/doc/crypto/BIO_s_bio.pod
new file mode 100644
index 0000000000..95ae802e47
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_bio.pod
@@ -0,0 +1,130 @@
1=pod
2
3=head1 NAME
4
5BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr,
6BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
7BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
8BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request - BIO pair BIO
9
10=head1 SYNOPSIS
11
12 #include <openssl/bio.h>
13
14 BIO_METHOD *BIO_s_bio(void);
15
16 #define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
17 #define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
18
19 #define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
20
21 #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
22 #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
23
24 int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2);
25
26 #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
27 size_t BIO_ctrl_get_write_guarantee(BIO *b);
28
29 #define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
30 size_t BIO_ctrl_get_read_request(BIO *b);
31
32 int BIO_ctrl_reset_read_request(BIO *b);
33
34=head1 DESCRIPTION
35
36BIO_s_bio() returns the method for a BIO pair. A BIO pair is a pair of source/sink
37BIOs where data written to either half of the pair is buffered and can be read from
38the other half. Both halves must usually by handled by the same application thread
39since no locking is done on the internal data structures.
40
41Since BIO chains typically end in a source/sink BIO it is possible to make this
42one half of a BIO pair and have all the data processed by the chain under application
43control.
44
45One typical use of BIO pairs is to place TLS/SSL I/O under application control, this
46can be used when the application wishes to use a non standard transport for
47TLS/SSL or the normal socket routines are inappropriate.
48
49Calls to BIO_read() will read data from the buffer or request a retry if no
50data is available.
51
52Calls to BIO_write() will place data in the buffer or request a retry if the
53buffer is full.
54
55The standard calls BIO_ctrl_pending() and BIO_ctrl_wpending() can be used to
56determine the amount of pending data in the read or write buffer.
57
58BIO_reset() clears any data in the write buffer.
59
60BIO_make_bio_pair() joins two separate BIOs into a connected pair.
61
62BIO_destroy_pair() destroys the association between two connected BIOs. Freeing
63up any half of the pair will automatically destroy the association.
64
65BIO_shutdown_wr() is used to close down a BIO B<b>. After this call no further
66writes on BIO B<b> are allowed (they will return an error). Reads on the other
67half of the pair will return any pending data or EOF when all pending data has
68been read.
69
70BIO_set_write_buf_size() sets the write buffer size of BIO B<b> to B<size>.
71If the size is not initialized a default value is used. This is currently
7217K, sufficient for a maximum size TLS record.
73
74BIO_get_write_buf_size() returns the size of the write buffer.
75
76BIO_new_bio_pair() combines the calls to BIO_new(), BIO_make_bio_pair() and
77BIO_set_write_buf_size() to create a connected pair of BIOs B<bio1>, B<bio2>
78with write buffer sizes B<writebuf1> and B<writebuf2>. If either size is
79zero then the default size is used.
80
81BIO_get_write_guarantee() and BIO_ctrl_get_write_guarantee() return the maximum
82length of data that can be currently written to the BIO. Writes larger than this
83value will return a value from BIO_write() less than the amount requested or if the
84buffer is full request a retry. BIO_ctrl_get_write_guarantee() is a function
85whereas BIO_get_write_guarantee() is a macro.
86
87BIO_get_read_request() and BIO_ctrl_get_read_request() return the
88amount of data requested, or the buffer size if it is less, if the
89last read attempt at the other half of the BIO pair failed due to an
90empty buffer. This can be used to determine how much data should be
91written to the BIO so the next read will succeed: this is most useful
92in TLS/SSL applications where the amount of data read is usually
93meaningful rather than just a buffer size. After a successful read
94this call will return zero. It also will return zero once new data
95has been written satisfying the read request or part of it.
96Note that BIO_get_read_request() never returns an amount larger
97than that returned by BIO_get_write_guarantee().
98
99BIO_ctrl_reset_read_request() can also be used to reset the value returned by
100BIO_get_read_request() to zero.
101
102=head1 NOTES
103
104Both halves of a BIO pair should be freed. That is even if one half is implicit
105freed due to a BIO_free_all() or SSL_free() call the other half needs to be freed.
106
107When used in bidirectional applications (such as TLS/SSL) care should be taken to
108flush any data in the write buffer. This can be done by calling BIO_pending()
109on the other half of the pair and, if any data is pending, reading it and sending
110it to the underlying transport. This must be done before any normal processing
111(such as calling select() ) due to a request and BIO_should_read() being true.
112
113To see why this is important consider a case where a request is sent using
114BIO_write() and a response read with BIO_read(), this can occur during an
115TLS/SSL handshake for example. BIO_write() will succeed and place data in the write
116buffer. BIO_read() will initially fail and BIO_should_read() will be true. If
117the application then waits for data to be available on the underlying transport
118before flushing the write buffer it will never succeed because the request was
119never sent!
120
121=head1 EXAMPLE
122
123TBA
124
125=head1 SEE ALSO
126
127L<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
128L<BIO_should_retry(3)|BIO_should_retry(3)>, L<BIO_read(3)|BIO_read(3)>
129
130=cut
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod b/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod
new file mode 100644
index 0000000000..fe1aa679d4
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod
@@ -0,0 +1,182 @@
1=pod
2
3=head1 NAME
4
5BIO_s_connect, BIO_set_conn_hostname, BIO_set_conn_port,
6BIO_set_conn_ip, BIO_set_conn_int_port, BIO_get_conn_hostname,
7BIO_get_conn_port, BIO_get_conn_ip, BIO_get_conn_int_port,
8BIO_set_nbio, BIO_do_connect - connect BIO
9
10=head1 SYNOPSIS
11
12 #include <openssl/bio.h>
13
14 BIO_METHOD * BIO_s_connect(void);
15
16 #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
17 #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
18 #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
19 #define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
20 #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
21 #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
22 #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2)
23 #define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port)
24
25 #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
26
27 #define BIO_do_connect(b) BIO_do_handshake(b)
28
29=head1 DESCRIPTION
30
31BIO_s_connect() returns the connect BIO method. This is a wrapper
32round the platform's TCP/IP socket connection routines.
33
34Using connect BIOs TCP/IP connections can be made and data
35transferred using only BIO routines. In this way any platform
36specific operations are hidden by the BIO abstraction.
37
38Read and write operations on a connect BIO will perform I/O
39on the underlying connection. If no connection is established
40and the port and hostname (see below) is set up properly then
41a connection is established first.
42
43Connect BIOs support BIO_puts() but not BIO_gets().
44
45If the close flag is set on a connect BIO then any active
46connection is shutdown and the socket closed when the BIO
47is freed.
48
49Calling BIO_reset() on a connect BIO will close any active
50connection and reset the BIO into a state where it can connect
51to the same host again.
52
53BIO_get_fd() places the underlying socket in B<c> if it is not NULL,
54it also returns the socket . If B<c> is not NULL it should be of
55type (int *).
56
57BIO_set_conn_hostname() uses the string B<name> to set the hostname
58The hostname can be an IP address. The hostname can also include the
59port in the form hostname:port . It is also acceptable to use the
60form "hostname/any/other/path" or "hostname:port/any/other/path".
61
62BIO_set_conn_port() sets the port to B<port>. B<port> can be the
63numerical form or a string such as "http". A string will be looked
64up first using getservbyname() on the host platform but if that
65fails a standard table of port names will be used. Currently the
66list is http, telnet, socks, https, ssl, ftp, gopher and wais.
67
68BIO_set_conn_ip() sets the IP address to B<ip> using binary form,
69that is four bytes specifying the IP address in big-endian form.
70
71BIO_set_conn_int_port() sets the port using B<port>. B<port> should
72be of type (int *).
73
74BIO_get_conn_hostname() returns the hostname of the connect BIO or
75NULL if the BIO is initialized but no hostname is set.
76This return value is an internal pointer which should not be modified.
77
78BIO_get_conn_port() returns the port as a string.
79
80BIO_get_conn_ip() returns the IP address in binary form.
81
82BIO_get_conn_int_port() returns the port as an int.
83
84BIO_set_nbio() sets the non blocking I/O flag to B<n>. If B<n> is
85zero then blocking I/O is set. If B<n> is 1 then non blocking I/O
86is set. Blocking I/O is the default. The call to BIO_set_nbio()
87should be made before the connection is established because
88non blocking I/O is set during the connect process.
89
90BIO_do_connect() attempts to connect the supplied BIO. It returns 1
91if the connection was established successfully. A zero or negative
92value is returned if the connection could not be established, the
93call BIO_should_retry() should be used for non blocking connect BIOs
94to determine if the call should be retried.
95
96=head1 NOTES
97
98If blocking I/O is set then a non positive return value from any
99I/O call is caused by an error condition, although a zero return
100will normally mean that the connection was closed.
101
102If the port name is supplied as part of the host name then this will
103override any value set with BIO_set_conn_port(). This may be undesirable
104if the application does not wish to allow connection to arbitrary
105ports. This can be avoided by checking for the presence of the ':'
106character in the passed hostname and either indicating an error or
107truncating the string at that point.
108
109The values returned by BIO_get_conn_hostname(), BIO_get_conn_port(),
110BIO_get_conn_ip() and BIO_get_conn_int_port() are updated when a
111connection attempt is made. Before any connection attempt the values
112returned are those set by the application itself.
113
114Applications do not have to call BIO_do_connect() but may wish to do
115so to separate the connection process from other I/O processing.
116
117If non blocking I/O is set then retries will be requested as appropriate.
118
119It addition to BIO_should_read() and BIO_should_write() it is also
120possible for BIO_should_io_special() to be true during the initial
121connection process with the reason BIO_RR_CONNECT. If this is returned
122then this is an indication that a connection attempt would block,
123the application should then take appropriate action to wait until
124the underlying socket has connected and retry the call.
125
126=head1 RETURN VALUES
127
128BIO_s_connect() returns the connect BIO method.
129
130BIO_get_fd() returns the socket or -1 if the BIO has not
131been initialized.
132
133BIO_set_conn_hostname(), BIO_set_conn_port(), BIO_set_conn_ip() and
134BIO_set_conn_int_port() always return 1.
135
136BIO_get_conn_hostname() returns the connected hostname or NULL is
137none was set.
138
139BIO_get_conn_port() returns a string representing the connected
140port or NULL if not set.
141
142BIO_get_conn_ip() returns a pointer to the connected IP address in
143binary form or all zeros if not set.
144
145BIO_get_conn_int_port() returns the connected port or 0 if none was
146set.
147
148BIO_set_nbio() always returns 1.
149
150BIO_do_connect() returns 1 if the connection was successfully
151established and 0 or -1 if the connection failed.
152
153=head1 EXAMPLE
154
155This is example connects to a webserver on the local host and attempts
156to retrieve a page and copy the result to standard output.
157
158
159 BIO *cbio, *out;
160 int len;
161 char tmpbuf[1024];
162 ERR_load_crypto_strings();
163 cbio = BIO_new_connect("localhost:http");
164 out = BIO_new_fp(stdout, BIO_NOCLOSE);
165 if(BIO_do_connect(cbio) <= 0) {
166 fprintf(stderr, "Error connecting to server\n");
167 ERR_print_errors_fp(stderr);
168 /* whatever ... */
169 }
170 BIO_puts(cbio, "GET / HTTP/1.0\n\n");
171 for(;;) {
172 len = BIO_read(cbio, tmpbuf, 1024);
173 if(len <= 0) break;
174 BIO_write(out, tmpbuf, len);
175 }
176 BIO_free(cbio);
177 BIO_free(out);
178
179
180=head1 SEE ALSO
181
182TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_fd.pod b/src/lib/libssl/src/doc/crypto/BIO_s_fd.pod
new file mode 100644
index 0000000000..b1de1d1015
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_fd.pod
@@ -0,0 +1,89 @@
1=pod
2
3=head1 NAME
4
5BIO_s_fd, BIO_set_fd, BIO_get_fd, BIO_new_fd - file descriptor BIO
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO_METHOD * BIO_s_fd(void);
12
13 #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
14 #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
15
16 BIO *BIO_new_fd(int fd, int close_flag);
17
18=head1 DESCRIPTION
19
20BIO_s_fd() returns the file descriptor BIO method. This is a wrapper
21round the platforms file descriptor routines such as read() and write().
22
23BIO_read() and BIO_write() read or write the underlying descriptor.
24BIO_puts() is supported but BIO_gets() is not.
25
26If the close flag is set then then close() is called on the underlying
27file descriptor when the BIO is freed.
28
29BIO_reset() attempts to change the file pointer to the start of file
30using lseek(fd, 0, 0).
31
32BIO_seek() sets the file pointer to position B<ofs> from start of file
33using lseek(fd, ofs, 0).
34
35BIO_tell() returns the current file position by calling lseek(fd, 0, 1).
36
37BIO_set_fd() sets the file descriptor of BIO B<b> to B<fd> and the close
38flag to B<c>.
39
40BIO_get_fd() places the file descriptor in B<c> if it is not NULL, it also
41returns the file descriptor. If B<c> is not NULL it should be of type
42(int *).
43
44BIO_new_fd() returns a file descriptor BIO using B<fd> and B<close_flag>.
45
46=head1 NOTES
47
48The behaviour of BIO_read() and BIO_write() depends on the behavior of the
49platforms read() and write() calls on the descriptor. If the underlying
50file descriptor is in a non blocking mode then the BIO will behave in the
51manner described in the L<BIO_read(3)|BIO_read(3)> and L<BIO_should_retry(3)|BIO_should_retry(3)>
52manual pages.
53
54File descriptor BIOs should not be used for socket I/O. Use socket BIOs
55instead.
56
57=head1 RETURN VALUES
58
59BIO_s_fd() returns the file descriptor BIO method.
60
61BIO_reset() returns zero for success and -1 if an error occurred.
62BIO_seek() and BIO_tell() return the current file position or -1
63is an error occurred. These values reflect the underlying lseek()
64behaviour.
65
66BIO_set_fd() always returns 1.
67
68BIO_get_fd() returns the file descriptor or -1 if the BIO has not
69been initialized.
70
71BIO_new_fd() returns the newly allocated BIO or NULL is an error
72occurred.
73
74=head1 EXAMPLE
75
76This is a file descriptor BIO version of "Hello World":
77
78 BIO *out;
79 out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
80 BIO_printf(out, "Hello World\n");
81 BIO_free(out);
82
83=head1 SEE ALSO
84
85L<BIO_seek(3)|BIO_seek(3)>, L<BIO_tell(3)|BIO_tell(3)>,
86L<BIO_reset(3)|BIO_reset(3)>, L<BIO_read(3)|BIO_read(3)>,
87L<BIO_write(3)|BIO_write(3)>, L<BIO_puts(3)|BIO_puts(3)>,
88L<BIO_gets(3)|BIO_gets(3)>, L<BIO_printf(3)|BIO_printf(3)>,
89L<BIO_set_close(3)|BIO_set_close(3)>, L<BIO_get_close(3)|BIO_get_close(3)>
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_file.pod b/src/lib/libssl/src/doc/crypto/BIO_s_file.pod
new file mode 100644
index 0000000000..b2a29263f4
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_file.pod
@@ -0,0 +1,144 @@
1=pod
2
3=head1 NAME
4
5BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp,
6BIO_read_filename, BIO_write_filename, BIO_append_filename,
7BIO_rw_filename - FILE bio
8
9=head1 SYNOPSIS
10
11 #include <openssl/bio.h>
12
13 BIO_METHOD * BIO_s_file(void);
14 BIO *BIO_new_file(const char *filename, const char *mode);
15 BIO *BIO_new_fp(FILE *stream, int flags);
16
17 BIO_set_fp(BIO *b,FILE *fp, int flags);
18 BIO_get_fp(BIO *b,FILE **fpp);
19
20 int BIO_read_filename(BIO *b, char *name)
21 int BIO_write_filename(BIO *b, char *name)
22 int BIO_append_filename(BIO *b, char *name)
23 int BIO_rw_filename(BIO *b, char *name)
24
25=head1 DESCRIPTION
26
27BIO_s_file() returns the BIO file method. As its name implies it
28is a wrapper round the stdio FILE structure and it is a
29source/sink BIO.
30
31Calls to BIO_read() and BIO_write() read and write data to the
32underlying stream. BIO_gets() and BIO_puts() are supported on file BIOs.
33
34BIO_flush() on a file BIO calls the fflush() function on the wrapped
35stream.
36
37BIO_reset() attempts to change the file pointer to the start of file
38using fseek(stream, 0, 0).
39
40BIO_seek() sets the file pointer to position B<ofs> from start of file
41using fseek(stream, ofs, 0).
42
43BIO_eof() calls feof().
44
45Setting the BIO_CLOSE flag calls fclose() on the stream when the BIO
46is freed.
47
48BIO_new_file() creates a new file BIO with mode B<mode> the meaning
49of B<mode> is the same as the stdio function fopen(). The BIO_CLOSE
50flag is set on the returned BIO.
51
52BIO_new_fp() creates a file BIO wrapping B<stream>. Flags can be:
53BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying
54stream to text mode, default is binary: this only has any effect under
55Win32).
56
57BIO_set_fp() set the fp of a file BIO to B<fp>. B<flags> has the same
58meaning as in BIO_new_fp(), it is a macro.
59
60BIO_get_fp() retrieves the fp of a file BIO, it is a macro.
61
62BIO_seek() is a macro that sets the position pointer to B<offset> bytes
63from the start of file.
64
65BIO_tell() returns the value of the position pointer.
66
67BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
68BIO_rw_filename() set the file BIO B<b> to use file B<name> for
69reading, writing, append or read write respectively.
70
71=head1 NOTES
72
73When wrapping stdout, stdin or stderr the underlying stream should not
74normally be closed so the BIO_NOCLOSE flag should be set.
75
76Because the file BIO calls the underlying stdio functions any quirks
77in stdio behaviour will be mirrored by the corresponding BIO.
78
79=head1 EXAMPLES
80
81File BIO "hello world":
82
83 BIO *bio_out;
84 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
85 BIO_printf(bio_out, "Hello World\n");
86
87Alternative technique:
88
89 BIO *bio_out;
90 bio_out = BIO_new(BIO_s_file());
91 if(bio_out == NULL) /* Error ... */
92 if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
93 BIO_printf(bio_out, "Hello World\n");
94
95Write to a file:
96
97 BIO *out;
98 out = BIO_new_file("filename.txt", "w");
99 if(!out) /* Error occurred */
100 BIO_printf(out, "Hello World\n");
101 BIO_free(out);
102
103Alternative technique:
104
105 BIO *out;
106 out = BIO_new(BIO_s_file());
107 if(out == NULL) /* Error ... */
108 if(!BIO_write_filename(out, "filename.txt")) /* Error ... */
109 BIO_printf(out, "Hello World\n");
110 BIO_free(out);
111
112=head1 RETURN VALUES
113
114BIO_s_file() returns the file BIO method.
115
116BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
117occurred.
118
119BIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure
120(although the current implementation never return 0).
121
122BIO_seek() returns the same value as the underlying fseek() function:
1230 for success or -1 for failure.
124
125BIO_tell() returns the current file position.
126
127BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
128BIO_rw_filename() return 1 for success or 0 for failure.
129
130=head1 BUGS
131
132BIO_reset() and BIO_seek() are implemented using fseek() on the underlying
133stream. The return value for fseek() is 0 for success or -1 if an error
134occurred this differs from other types of BIO which will typically return
1351 for success and a non positive value if an error occurred.
136
137=head1 SEE ALSO
138
139L<BIO_seek(3)|BIO_seek(3)>, L<BIO_tell(3)|BIO_tell(3)>,
140L<BIO_reset(3)|BIO_reset(3)>, L<BIO_flush(3)|BIO_flush(3)>,
141L<BIO_read(3)|BIO_read(3)>,
142L<BIO_write(3)|BIO_write(3)>, L<BIO_puts(3)|BIO_puts(3)>,
143L<BIO_gets(3)|BIO_gets(3)>, L<BIO_printf(3)|BIO_printf(3)>,
144L<BIO_set_close(3)|BIO_set_close(3)>, L<BIO_get_close(3)|BIO_get_close(3)>
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_mem.pod b/src/lib/libssl/src/doc/crypto/BIO_s_mem.pod
new file mode 100644
index 0000000000..19648acfae
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_mem.pod
@@ -0,0 +1,115 @@
1=pod
2
3=head1 NAME
4
5BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data, BIO_set_mem_buf,
6BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO
7
8=head1 SYNOPSIS
9
10 #include <openssl/bio.h>
11
12 BIO_METHOD * BIO_s_mem(void);
13
14 BIO_set_mem_eof_return(BIO *b,int v)
15 long BIO_get_mem_data(BIO *b, char **pp)
16 BIO_set_mem_buf(BIO *b,BUF_MEM *bm,int c)
17 BIO_get_mem_ptr(BIO *b,BUF_MEM **pp)
18
19 BIO *BIO_new_mem_buf(void *buf, int len);
20
21=head1 DESCRIPTION
22
23BIO_s_mem() return the memory BIO method function.
24
25A memory BIO is a source/sink BIO which uses memory for its I/O. Data
26written to a memory BIO is stored in a BUF_MEM structure which is extended
27as appropriate to accommodate the stored data.
28
29Any data written to a memory BIO can be recalled by reading from it.
30Unless the memory BIO is read only any data read from it is deleted from
31the BIO.
32
33Memory BIOs support BIO_gets() and BIO_puts().
34
35If the BIO_CLOSE flag is set when a memory BIO is freed then the underlying
36BUF_MEM structure is also freed.
37
38Calling BIO_reset() on a read write memory BIO clears any data in it. On a
39read only BIO it restores the BIO to its original state and the read only
40data can be read again.
41
42BIO_eof() is true if no data is in the BIO.
43
44BIO_ctrl_pending() returns the number of bytes currently stored.
45
46BIO_set_mem_eof_return() sets the behaviour of memory BIO B<b> when it is
47empty. If the B<v> is zero then an empty memory BIO will return EOF (that is
48it will return zero and BIO_should_retry(b) will be false. If B<v> is non
49zero then it will return B<v> when it is empty and it will set the read retry
50flag (that is BIO_read_retry(b) is true). To avoid ambiguity with a normal
51positive return value B<v> should be set to a negative value, typically -1.
52
53BIO_get_mem_data() sets B<pp> to a pointer to the start of the memory BIOs data
54and returns the total amount of data available. It is implemented as a macro.
55
56BIO_set_mem_buf() sets the internal BUF_MEM structure to B<bm> and sets the
57close flag to B<c>, that is B<c> should be either BIO_CLOSE or BIO_NOCLOSE.
58It is a macro.
59
60BIO_get_mem_ptr() places the underlying BUF_MEM structure in B<pp>. It is
61a macro.
62
63BIO_new_mem_buf() creates a memory BIO using B<len> bytes of data at B<buf>,
64if B<len> is -1 then the B<buf> is assumed to be null terminated and its
65length is determined by B<strlen>. The BIO is set to a read only state and
66as a result cannot be written to. This is useful when some data needs to be
67made available from a static area of memory in the form of a BIO. The
68supplied data is read directly from the supplied buffer: it is B<not> copied
69first, so the supplied area of memory must be unchanged until the BIO is freed.
70
71=head1 NOTES
72
73Writes to memory BIOs will always succeed if memory is available: that is
74their size can grow indefinitely.
75
76Every read from a read write memory BIO will remove the data just read with
77an internal copy operation, if a BIO contains a lots of data and it is
78read in small chunks the operation can be very slow. The use of a read only
79memory BIO avoids this problem. If the BIO must be read write then adding
80a buffering BIO to the chain will speed up the process.
81
82=head1 BUGS
83
84There should be an option to set the maximum size of a memory BIO.
85
86There should be a way to "rewind" a read write BIO without destroying
87its contents.
88
89The copying operation should not occur after every small read of a large BIO
90to improve efficiency.
91
92=head1 EXAMPLE
93
94Create a memory BIO and write some data to it:
95
96 BIO *mem = BIO_new(BIO_s_mem());
97 BIO_puts(mem, "Hello World\n");
98
99Create a read only memory BIO:
100
101 char data[] = "Hello World";
102 BIO *mem;
103 mem = BIO_new_mem_buf(data, -1);
104
105Extract the BUF_MEM structure from a memory BIO and then free up the BIO:
106
107 BUF_MEM *bptr;
108 BIO_get_mem_ptr(mem, &bptr);
109 BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */
110 BIO_free(mem);
111
112
113=head1 SEE ALSO
114
115TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_null.pod b/src/lib/libssl/src/doc/crypto/BIO_s_null.pod
new file mode 100644
index 0000000000..e5514f7238
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_null.pod
@@ -0,0 +1,37 @@
1=pod
2
3=head1 NAME
4
5BIO_s_null - null data sink
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO_METHOD * BIO_s_null(void);
12
13=head1 DESCRIPTION
14
15BIO_s_null() returns the null sink BIO method. Data written to
16the null sink is discarded, reads return EOF.
17
18=head1 NOTES
19
20A null sink BIO behaves in a similar manner to the Unix /dev/null
21device.
22
23A null bio can be placed on the end of a chain to discard any data
24passed through it.
25
26A null sink is useful if, for example, an application wishes to digest some
27data by writing through a digest bio but not send the digested data anywhere.
28Since a BIO chain must normally include a source/sink BIO this can be achieved
29by adding a null sink BIO to the end of the chain
30
31=head1 RETURN VALUES
32
33BIO_s_null() returns the null sink BIO method.
34
35=head1 SEE ALSO
36
37TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_socket.pod b/src/lib/libssl/src/doc/crypto/BIO_s_socket.pod
new file mode 100644
index 0000000000..253185185c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_s_socket.pod
@@ -0,0 +1,61 @@
1=pod
2
3=head1 NAME
4
5BIO_s_socket, BIO_new_socket - socket BIO
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO_METHOD * BIO_s_socket(void);
12
13 #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
14 #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
15
16 BIO *BIO_new_socket(int sock, int close_flag);
17
18=head1 DESCRIPTION
19
20BIO_s_socket() returns the socket BIO method. This is a wrapper
21round the platform's socket routines.
22
23BIO_read() and BIO_write() read or write the underlying socket.
24BIO_puts() is supported but BIO_gets() is not.
25
26If the close flag is set then the socket is shut down and closed
27when the BIO is freed.
28
29BIO_set_fd() sets the socket of BIO B<b> to B<fd> and the close
30flag to B<c>.
31
32BIO_get_fd() places the socket in B<c> if it is not NULL, it also
33returns the socket . If B<c> is not NULL it should be of type (int *).
34
35BIO_new_socket() returns a socket BIO using B<sock> and B<close_flag>.
36
37=head1 NOTES
38
39Socket BIOs also support any relevant functionality of file descriptor
40BIOs.
41
42The reason for having separate file descriptor and socket BIOs is that on some
43platforms sockets are not file descriptors and use distinct I/O routines,
44Windows is one such platform. Any code mixing the two will not work on
45all platforms.
46
47=head1 RETURN VALUES
48
49BIO_s_socket() returns the socket BIO method.
50
51BIO_set_fd() always returns 1.
52
53BIO_get_fd() returns the socket or -1 if the BIO has not been
54initialized.
55
56BIO_new_socket() returns the newly allocated BIO or NULL is an error
57occurred.
58
59=head1 SEE ALSO
60
61TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_set_callback.pod b/src/lib/libssl/src/doc/crypto/BIO_set_callback.pod
new file mode 100644
index 0000000000..9b6961ca8d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_set_callback.pod
@@ -0,0 +1,108 @@
1=pod
2
3=head1 NAME
4
5BIO_set_callback, BIO_get_callback, BIO_set_callback_arg, BIO_get_callback_arg,
6BIO_debug_callback - BIO callback functions
7
8=head1 SYNOPSIS
9
10 #include <openssl/bio.h>
11
12 #define BIO_set_callback(b,cb) ((b)->callback=(cb))
13 #define BIO_get_callback(b) ((b)->callback)
14 #define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
15 #define BIO_get_callback_arg(b) ((b)->cb_arg)
16
17 long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
18 long argl,long ret);
19
20 typedef long callback(BIO *b, int oper, const char *argp,
21 int argi, long argl, long retvalue);
22
23=head1 DESCRIPTION
24
25BIO_set_callback() and BIO_get_callback() set and retrieve the BIO callback,
26they are both macros. The callback is called during most high level BIO
27operations. It can be used for debugging purposes to trace operations on
28a BIO or to modify its operation.
29
30BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be
31used to set and retrieve an argument for use in the callback.
32
33BIO_debug_callback() is a standard debugging callback which prints
34out information relating to each BIO operation. If the callback
35argument is set if is interpreted as a BIO to send the information
36to, otherwise stderr is used.
37
38callback() is the callback function itself. The meaning of each
39argument is described below.
40
41The BIO the callback is attached to is passed in B<b>.
42
43B<oper> is set to the operation being performed. For some operations
44the callback is called twice, once before and once after the actual
45operation, the latter case has B<oper> or'ed with BIO_CB_RETURN.
46
47The meaning of the arguments B<argp>, B<argi> and B<argl> depends on
48the value of B<oper>, that is the operation being performed.
49
50B<retvalue> is the return value that would be returned to the
51application if no callback were present. The actual value returned
52is the return value of the callback itself. In the case of callbacks
53called before the actual BIO operation 1 is placed in retvalue, if
54the return value is not positive it will be immediately returned to
55the application and the BIO operation will not be performed.
56
57The callback should normally simply return B<retvalue> when it has
58finished processing, unless if specifically wishes to modify the
59value returned to the application.
60
61=head1 CALLBACK OPERATIONS
62
63=over 4
64
65=item B<BIO_free(b)>
66
67callback(b, BIO_CB_FREE, NULL, 0L, 0L, 1L) is called before the
68free operation.
69
70=item B<BIO_read(b, out, outl)>
71
72callback(b, BIO_CB_READ, out, outl, 0L, 1L) is called before
73the read and callback(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, 0L, retvalue)
74after.
75
76=item B<BIO_write(b, in, inl)>
77
78callback(b, BIO_CB_WRITE, in, inl, 0L, 1L) is called before
79the write and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, 0L, retvalue)
80after.
81
82=item B<BIO_gets(b, out, outl)>
83
84callback(b, BIO_CB_GETS, out, outl, 0L, 1L) is called before
85the operation and callback(b, BIO_CB_GETS|BIO_CB_RETURN, out, outl, 0L, retvalue)
86after.
87
88=item B<BIO_puts(b, in)>
89
90callback(b, BIO_CB_WRITE, in, 0, 0L, 1L) is called before
91the operation and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, 0, 0L, retvalue)
92after.
93
94=item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)>
95
96callback(b,BIO_CB_CTRL,parg,cmd,larg,1L) is called before the call and
97callback(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, larg,ret) after.
98
99=back
100
101=head1 EXAMPLE
102
103The BIO_debug_callback() function is a good example, its source is
104in crypto/bio/bio_cb.c
105
106=head1 SEE ALSO
107
108TBA
diff --git a/src/lib/libssl/src/doc/crypto/BIO_should_retry.pod b/src/lib/libssl/src/doc/crypto/BIO_should_retry.pod
new file mode 100644
index 0000000000..539c391272
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BIO_should_retry.pod
@@ -0,0 +1,114 @@
1=pod
2
3=head1 NAME
4
5BIO_should_retry, BIO_should_read, BIO_should_write,
6BIO_should_io_special, BIO_retry_type, BIO_should_retry,
7BIO_get_retry_BIO, BIO_get_retry_reason - BIO retry functions
8
9=head1 SYNOPSIS
10
11 #include <openssl/bio.h>
12
13 #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
14 #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
15 #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
16 #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
17 #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
18
19 #define BIO_FLAGS_READ 0x01
20 #define BIO_FLAGS_WRITE 0x02
21 #define BIO_FLAGS_IO_SPECIAL 0x04
22 #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
23 #define BIO_FLAGS_SHOULD_RETRY 0x08
24
25 BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
26 int BIO_get_retry_reason(BIO *bio);
27
28=head1 DESCRIPTION
29
30These functions determine why a BIO is not able to read or write data.
31They will typically be called after a failed BIO_read() or BIO_write()
32call.
33
34BIO_should_retry() is true if the call that produced this condition
35should then be retried at a later time.
36
37If BIO_should_retry() is false then the cause is an error condition.
38
39BIO_should_read() is true if the cause of the condition is that a BIO
40needs to read data.
41
42BIO_should_write() is true if the cause of the condition is that a BIO
43needs to read data.
44
45BIO_should_io_special() is true if some "special" condition, that is a
46reason other than reading or writing is the cause of the condition.
47
48BIO_get_retry_reason() returns a mask of the cause of a retry condition
49consisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
50B<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
51these.
52
53BIO_get_retry_BIO() determines the precise reason for the special
54condition, it returns the BIO that caused this condition and if
55B<reason> is not NULL it contains the reason code. The meaning of
56the reason code and the action that should be taken depends on
57the type of BIO that resulted in this condition.
58
59BIO_get_retry_reason() returns the reason for a special condition if
60passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
61
62=head1 NOTES
63
64If BIO_should_retry() returns false then the precise "error condition"
65depends on the BIO type that caused it and the return code of the BIO
66operation. For example if a call to BIO_read() on a socket BIO returns
670 and BIO_should_retry() is false then the cause will be that the
68connection closed. A similar condition on a file BIO will mean that it
69has reached EOF. Some BIO types may place additional information on
70the error queue. For more details see the individual BIO type manual
71pages.
72
73If the underlying I/O structure is in a blocking mode almost all current
74BIO types will not request a retry, because the underlying I/O
75calls will not. If the application knows that the BIO type will never
76signal a retry then it need not call BIO_should_retry() after a failed
77BIO I/O call. This is typically done with file BIOs.
78
79SSL BIOs are the only current exception to this rule: they can request a
80retry even if the underlying I/O structure is blocking, if a handshake
81occurs during a call to BIO_read(). An application can retry the failed
82call immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
83on the underlying SSL structure.
84
85While an application may retry a failed non blocking call immediately
86this is likely to be very inefficient because the call will fail
87repeatedly until data can be processed or is available. An application
88will normally wait until the necessary condition is satisfied. How
89this is done depends on the underlying I/O structure.
90
91For example if the cause is ultimately a socket and BIO_should_read()
92is true then a call to select() may be made to wait until data is
93available and then retry the BIO operation. By combining the retry
94conditions of several non blocking BIOs in a single select() call
95it is possible to service several BIOs in a single thread, though
96the performance may be poor if SSL BIOs are present because long delays
97can occur during the initial handshake process.
98
99It is possible for a BIO to block indefinitely if the underlying I/O
100structure cannot process or return any data. This depends on the behaviour of
101the platforms I/O functions. This is often not desirable: one solution
102is to use non blocking I/O and use a timeout on the select() (or
103equivalent) call.
104
105=head1 BUGS
106
107The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
108that is they cannot retry after a partial read or write. This is usually
109worked around by only passing the relevant data to ASN1 functions when
110the entire structure can be read or written.
111
112=head1 SEE ALSO
113
114TBA
diff --git a/src/lib/libssl/src/doc/crypto/BN_CTX_new.pod b/src/lib/libssl/src/doc/crypto/BN_CTX_new.pod
new file mode 100644
index 0000000000..c94d8c610d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_CTX_new.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5BN_CTX_new, BN_CTX_init, BN_CTX_free - allocate and free BN_CTX structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BN_CTX *BN_CTX_new(void);
12
13 void BN_CTX_init(BN_CTX *c);
14
15 void BN_CTX_free(BN_CTX *c);
16
17=head1 DESCRIPTION
18
19A B<BN_CTX> is a structure that holds B<BIGNUM> temporary variables used by
20library functions. Since dynamic memory allocation to create B<BIGNUM>s
21is rather expensive when used in conjunction with repeated subroutine
22calls, the B<BN_CTX> structure is used.
23
24BN_CTX_new() allocates and initializes a B<BN_CTX>
25structure. BN_CTX_init() initializes an existing uninitialized
26B<BN_CTX>.
27
28BN_CTX_free() frees the components of the B<BN_CTX>, and if it was
29created by BN_CTX_new(), also the structure itself.
30If L<BN_CTX_start(3)|BN_CTX_start(3)> has been used on the B<BN_CTX>,
31L<BN_CTX_end(3)|BN_CTX_end(3)> must be called before the B<BN_CTX>
32may be freed by BN_CTX_free().
33
34
35=head1 RETURN VALUES
36
37BN_CTX_new() returns a pointer to the B<BN_CTX>. If the allocation fails,
38it returns B<NULL> and sets an error code that can be obtained by
39L<ERR_get_error(3)|ERR_get_error(3)>.
40
41BN_CTX_init() and BN_CTX_free() have no return values.
42
43=head1 SEE ALSO
44
45L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
46L<BN_CTX_start(3)|BN_CTX_start(3)>
47
48=head1 HISTORY
49
50BN_CTX_new() and BN_CTX_free() are available in all versions on SSLeay
51and OpenSSL. BN_CTX_init() was added in SSLeay 0.9.1b.
52
53=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_CTX_start.pod b/src/lib/libssl/src/doc/crypto/BN_CTX_start.pod
new file mode 100644
index 0000000000..c30552b122
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_CTX_start.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5BN_CTX_start, BN_CTX_get, BN_CTX_end - use temporary BIGNUM variables
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 void BN_CTX_start(BN_CTX *ctx);
12
13 BIGNUM *BN_CTX_get(BN_CTX *ctx);
14
15 void BN_CTX_end(BN_CTX *ctx);
16
17=head1 DESCRIPTION
18
19These functions are used to obtain temporary B<BIGNUM> variables from
20a B<BN_CTX> in order to save the overhead of repeatedly creating and
21freeing B<BIGNUM>s in functions that are called from inside a loop.
22
23A function must call BN_CTX_start() first. Then, BN_CTX_get() may be
24called repeatedly to obtain temporary B<BIGNUM>s. All BN_CTX_get()
25calls must be made before calling any other functions that use the
26B<ctx> as an argument.
27
28Finally, BN_CTX_end() must be called before returning from the function.
29When BN_CTX_end() is called, the B<BIGNUM> pointers obtained from
30BN_CTX_get() become invalid.
31
32=head1 RETURN VALUES
33
34BN_CTX_start() and BN_CTX_end() return no values.
35
36BN_CTX_get() returns a pointer to the B<BIGNUM>, or B<NULL> on error.
37Once BN_CTX_get() has failed, the subsequent calls will return B<NULL>
38as well, so it is sufficient to check the return value of the last
39BN_CTX_get() call. In case of an error, an error code is set, which
40can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
41
42
43=head1 SEE ALSO
44
45L<BN_CTX_new(3)|BN_CTX_new(3)>
46
47=head1 HISTORY
48
49BN_CTX_start(), BN_CTX_get() and BN_CTX_end() were added in OpenSSL 0.9.5.
50
51=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_add.pod b/src/lib/libssl/src/doc/crypto/BN_add.pod
new file mode 100644
index 0000000000..0541d45643
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_add.pod
@@ -0,0 +1,99 @@
1=pod
2
3=head1 NAME
4
5BN_add, BN_sub, BN_mul, BN_div, BN_sqr, BN_mod, BN_mod_mul, BN_exp,
6BN_mod_exp, BN_gcd - arithmetic operations on BIGNUMs
7
8=head1 SYNOPSIS
9
10 #include <openssl/bn.h>
11
12 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
13
14 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
15
16 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
17
18 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
19 BN_CTX *ctx);
20
21 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
22
23 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
24
25 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
26 BN_CTX *ctx);
27
28 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
29
30 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
31 const BIGNUM *m, BN_CTX *ctx);
32
33 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
34
35=head1 DESCRIPTION
36
37BN_add() adds B<a> and B<b> and places the result in B<r> (C<r=a+b>).
38B<r> may be the same B<BIGNUM> as B<a> or B<b>.
39
40BN_sub() subtracts B<b> from B<a> and places the result in B<r> (C<r=a-b>).
41
42BN_mul() multiplies B<a> and B<b> and places the result in B<r> (C<r=a*b>).
43B<r> may be the same B<BIGNUM> as B<a> or B<b>.
44For multiplication by powers of 2, use L<BN_lshift(3)|BN_lshift(3)>.
45
46BN_div() divides B<a> by B<d> and places the result in B<dv> and the
47remainder in B<rem> (C<dv=a/d, rem=a%d>). Either of B<dv> and B<rem> may
48be NULL, in which case the respective value is not returned.
49For division by powers of 2, use BN_rshift(3).
50
51BN_sqr() takes the square of B<a> and places the result in B<r>
52(C<r=a^2>). B<r> and B<a> may be the same B<BIGNUM>.
53This function is faster than BN_mul(r,a,a).
54
55BN_mod() find the remainder of B<a> divided by B<m> and places it in
56B<rem> (C<rem=a%m>).
57
58BN_mod_mul() multiplies B<a> by B<b> and finds the remainder when
59divided by B<m> (C<r=(a*b)%m>). B<r> may be the same B<BIGNUM> as B<a>
60or B<b>. For a more efficient algorithm, see
61L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>; for repeated
62computations using the same modulus, see L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>.
63
64BN_exp() raises B<a> to the B<p>-th power and places the result in B<r>
65(C<r=a^p>). This function is faster than repeated applications of
66BN_mul().
67
68BN_mod_exp() computes B<a> to the B<p>-th power modulo B<m> (C<r=a^p %
69m>). This function uses less time and space than BN_exp().
70
71BN_gcd() computes the greatest common divisor of B<a> and B<b> and
72places the result in B<r>. B<r> may be the same B<BIGNUM> as B<a> or
73B<b>.
74
75For all functions, B<ctx> is a previously allocated B<BN_CTX> used for
76temporary variables; see L<BN_CTX_new(3)|BN_CTX_new(3)>.
77
78Unless noted otherwise, the result B<BIGNUM> must be different from
79the arguments.
80
81=head1 RETURN VALUES
82
83For all functions, 1 is returned for success, 0 on error. The return
84value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
85The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87=head1 SEE ALSO
88
89L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
90L<BN_add_word(3)|BN_add_word(3)>, L<BN_set_bit(3)|BN_set_bit(3)>
91
92=head1 HISTORY
93
94BN_add(), BN_sub(), BN_div(), BN_sqr(), BN_mod(), BN_mod_mul(),
95BN_mod_exp() and BN_gcd() are available in all versions of SSLeay and
96OpenSSL. The B<ctx> argument to BN_mul() was added in SSLeay
970.9.1b. BN_exp() appeared in SSLeay 0.9.0.
98
99=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_add_word.pod b/src/lib/libssl/src/doc/crypto/BN_add_word.pod
new file mode 100644
index 0000000000..66bedfb924
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_add_word.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5BN_add_word, BN_sub_word, BN_mul_word, BN_div_word, BN_mod_word - arithmetic
6functions on BIGNUMs with integers
7
8=head1 SYNOPSIS
9
10 #include <openssl/bn.h>
11
12 int BN_add_word(BIGNUM *a, BN_ULONG w);
13
14 int BN_sub_word(BIGNUM *a, BN_ULONG w);
15
16 int BN_mul_word(BIGNUM *a, BN_ULONG w);
17
18 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
19
20 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
21
22=head1 DESCRIPTION
23
24These functions perform arithmetic operations on BIGNUMs with unsigned
25integers. They are much more efficient than the normal BIGNUM
26arithmetic operations.
27
28BN_add_word() adds B<w> to B<a> (C<a+=w>).
29
30BN_sub_word() subtracts B<w> from B<a> (C<a-=w>).
31
32BN_mul_word() multiplies B<a> and B<w> (C<a*=b>).
33
34BN_div_word() divides B<a> by B<w> (C<a/=w>) and returns the remainder.
35
36BN_mod_word() returns the remainder of B<a> divided by B<w> (C<a%m>).
37
38For BN_div_word() and BN_mod_word(), B<w> must not be 0.
39
40=head1 RETURN VALUES
41
42BN_add_word(), BN_sub_word() and BN_mul_word() return 1 for success, 0
43on error. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
44
45BN_mod_word() and BN_div_word() return B<a>%B<w>.
46
47=head1 SEE ALSO
48
49L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>
50
51=head1 HISTORY
52
53BN_add_word() and BN_mod_word() are available in all versions of
54SSLeay and OpenSSL. BN_div_word() was added in SSLeay 0.8, and
55BN_sub_word() and BN_mul_word() in SSLeay 0.9.0.
56
57=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_bn2bin.pod b/src/lib/libssl/src/doc/crypto/BN_bn2bin.pod
new file mode 100644
index 0000000000..05f9e628cc
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_bn2bin.pod
@@ -0,0 +1,95 @@
1=pod
2
3=head1 NAME
4
5BN_bn2bin, BN_bin2bn, BN_bn2hex, BN_bn2dec, BN_hex2bn, BN_dec2bn,
6BN_print, BN_print_fp, BN_bn2mpi, BN_mpi2bn - format conversions
7
8=head1 SYNOPSIS
9
10 #include <openssl/bn.h>
11
12 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
13 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
14
15 char *BN_bn2hex(const BIGNUM *a);
16 char *BN_bn2dec(const BIGNUM *a);
17 int BN_hex2bn(BIGNUM **a, const char *str);
18 int BN_dec2bn(BIGNUM **a, const char *str);
19
20 int BN_print(BIO *fp, const BIGNUM *a);
21 int BN_print_fp(FILE *fp, const BIGNUM *a);
22
23 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
24 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
25
26=head1 DESCRIPTION
27
28BN_bn2bin() converts the absolute value of B<a> into big-endian form
29and stores it at B<to>. B<to> must point to BN_num_bytes(B<a>) bytes of
30memory.
31
32BN_bin2bn() converts the positive integer in big-endian form of length
33B<len> at B<s> into a B<BIGNUM> and places it in B<ret>. If B<ret> is
34NULL, a new B<BIGNUM> is created.
35
36BN_bn2hex() and BN_bn2dec() return printable strings containing the
37hexadecimal and decimal encoding of B<a> respectively. For negative
38numbers, the string is prefaced with a leading '-'. The string must be
39Free()d later.
40
41BN_hex2bn() converts the string B<str> containing a hexadecimal number
42to a B<BIGNUM> and stores it in **B<bn>. If *B<bn> is NULL, a new
43B<BIGNUM> is created. If B<bn> is NULL, it only computes the number's
44length in hexadecimal digits. If the string starts with '-', the
45number is negative. BN_dec2bn() is the same using the decimal system.
46
47BN_print() and BN_print_fp() write the hexadecimal encoding of B<a>,
48with a leading '-' for negative numbers, to the B<BIO> or B<FILE>
49B<fp>.
50
51BN_bn2mpi() and BN_mpi2bn() convert B<BIGNUM>s from and to a format
52that consists of the number's length in bytes represented as a 3-byte
53big-endian number, and the number itself in big-endian format, where
54the most significant bit signals a negative number (the representation
55of numbers with the MSB set is prefixed with null byte).
56
57BN_bn2mpi() stores the representation of B<a> at B<to>, where B<to>
58must be large enough to hold the result. The size can be determined by
59calling BN_bn2mpi(B<a>, NULL).
60
61BN_mpi2bn() converts the B<len> bytes long representation at B<s> to
62a B<BIGNUM> and stores it at B<ret>, or in a newly allocated B<BIGNUM>
63if B<ret> is NULL.
64
65=head1 RETURN VALUES
66
67BN_bn2bin() returns the length of the big-endian number placed at B<to>.
68BN_bin2bn() returns the B<BIGNUM>, NULL on error.
69
70BN_bn2hex() and BN_bn2dec() return a null-terminated string, or NULL
71on error. BN_hex2bn() and BN_dec2bn() return the number's length in
72hexadecimal or decimal digits, and 0 on error.
73
74BN_print_fp() and BN_print() return 1 on success, 0 on write errors.
75
76BN_bn2mpi() returns the length of the representation. BN_mpi2bn()
77returns the B<BIGNUM>, and NULL on error.
78
79The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
80
81=head1 SEE ALSO
82
83L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_zero(3)|BN_zero(3)>,
84L<ASN1_INTEGER_to_BN(3)|ASN1_INTEGER_to_BN(3)>,
85L<BN_num_bytes(3)|BN_num_bytes(3)>
86
87=head1 HISTORY
88
89BN_bn2bin(), BN_bin2bn(), BN_print_fp() and BN_print() are available
90in all versions of SSLeay and OpenSSL.
91
92BN_bn2hex(), BN_bn2dec(), BN_hex2bn(), BN_dec2bn(), BN_bn2mpi() and
93BN_mpi2bn() were added in SSLeay 0.9.0.
94
95=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_cmp.pod b/src/lib/libssl/src/doc/crypto/BN_cmp.pod
new file mode 100644
index 0000000000..23e9ed0b4f
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_cmp.pod
@@ -0,0 +1,48 @@
1=pod
2
3=head1 NAME
4
5BN_cmp, BN_ucmp, BN_is_zero, BN_is_one, BN_is_word, BN_is_odd - BIGNUM comparison and test functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 int BN_cmp(BIGNUM *a, BIGNUM *b);
12 int BN_ucmp(BIGNUM *a, BIGNUM *b);
13
14 int BN_is_zero(BIGNUM *a);
15 int BN_is_one(BIGNUM *a);
16 int BN_is_word(BIGNUM *a, BN_ULONG w);
17 int BN_is_odd(BIGNUM *a);
18
19=head1 DESCRIPTION
20
21BN_cmp() compares the numbers B<a> and B<b>. BN_ucmp() compares their
22absolute values.
23
24BN_is_zero(), BN_is_one() and BN_is_word() test if B<a> equals 0, 1,
25or B<w> respectively. BN_is_odd() tests if a is odd.
26
27BN_is_zero(), BN_is_one(), BN_is_word() and BN_is_odd() are macros.
28
29=head1 RETURN VALUES
30
31BN_cmp() returns -1 if B<a> E<lt> B<b>, 0 if B<a> == B<b> and 1 if
32B<a> E<gt> B<b>. BN_ucmp() is the same using the absolute values
33of B<a> and B<b>.
34
35BN_is_zero(), BN_is_one() BN_is_word() and BN_is_odd() return 1 if
36the condition is true, 0 otherwise.
37
38=head1 SEE ALSO
39
40L<bn(3)|bn(3)>
41
42=head1 HISTORY
43
44BN_cmp(), BN_ucmp(), BN_is_zero(), BN_is_one() and BN_is_word() are
45available in all versions of SSLeay and OpenSSL.
46BN_is_odd() was added in SSLeay 0.8.
47
48=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_copy.pod b/src/lib/libssl/src/doc/crypto/BN_copy.pod
new file mode 100644
index 0000000000..8ad25e7834
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_copy.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5BN_copy, BN_dup - copy BIGNUMs
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_copy(BIGNUM *to, const BIGNUM *from);
12
13 BIGNUM *BN_dup(const BIGNUM *from);
14
15=head1 DESCRIPTION
16
17BN_copy() copies B<from> to B<to>. BN_dup() creates a new B<BIGNUM>
18containing the value B<from>.
19
20=head1 RETURN VALUES
21
22BN_copy() returns B<to> on success, NULL on error. BN_dup() returns
23the new B<BIGNUM>, and NULL on error. The error codes can be obtained
24by L<ERR_get_error(3)|ERR_get_error(3)>.
25
26=head1 SEE ALSO
27
28L<bn(3)|bn(3)>, L<err(3)|err(3)>
29
30=head1 HISTORY
31
32BN_copy() and BN_dup() are available in all versions of SSLeay and OpenSSL.
33
34=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_generate_prime.pod b/src/lib/libssl/src/doc/crypto/BN_generate_prime.pod
new file mode 100644
index 0000000000..638f6514ee
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_generate_prime.pod
@@ -0,0 +1,102 @@
1=pod
2
3=head1 NAME
4
5BN_generate_prime, BN_is_prime, BN_is_prime_fasttest - generate primes and test for primality
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add,
12 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
13
14 int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int,
15 void *), BN_CTX *ctx, void *cb_arg);
16
17 int BN_is_prime_fasttest(const BIGNUM *a, int checks,
18 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg,
19 int do_trial_division);
20
21=head1 DESCRIPTION
22
23BN_generate_prime() generates a pseudo-random prime number of B<num>
24bits.
25If B<ret> is not B<NULL>, it will be used to store the number.
26
27If B<callback> is not B<NULL>, it is called as follows:
28
29=over 4
30
31=item *
32
33B<callback(0, i, cb_arg)> is called after generating the i-th
34potential prime number.
35
36=item *
37
38While the number is being tested for primality, B<callback(1, j,
39cb_arg)> is called as described below.
40
41=item *
42
43When a prime has been found, B<callback(2, i, cb_arg)> is called.
44
45=back
46
47The prime may have to fulfill additional requirements for use in
48Diffie-Hellman key exchange:
49
50If B<add> is not B<NULL>, the prime will fulfill the condition p % B<add>
51== B<rem> (p % B<add> == 1 if B<rem> == B<NULL>) in order to suit a given
52generator.
53
54If B<safe> is true, it will be a safe prime (i.e. a prime p so
55that (p-1)/2 is also prime).
56
57The PRNG must be seeded prior to calling BN_generate_prime().
58The prime number generation has a negligible error probability.
59
60BN_is_prime() and BN_is_prime_fasttest() test if the number B<a> is
61prime. The following tests are performed until one of them shows that
62B<a> is composite; if B<a> passes all these tests, it is considered
63prime.
64
65BN_is_prime_fasttest(), when called with B<do_trial_division == 1>,
66first attempts trial division by a number of small primes;
67if no divisors are found by this test and B<callback> is not B<NULL>,
68B<callback(1, -1, cb_arg)> is called.
69If B<do_trial_division == 0>, this test is skipped.
70
71Both BN_is_prime() and BN_is_prime_fasttest() perform a Miller-Rabin
72probabilistic primality test with B<checks> iterations. If
73B<checks == BN_prime_check>, a number of iterations is used that
74yields a false positive rate of at most 2^-80 for random input.
75
76If B<callback> is not B<NULL>, B<callback(1, j, cb_arg)> is called
77after the j-th iteration (j = 0, 1, ...). B<ctx> is a
78pre-allocated B<BN_CTX> (to save the overhead of allocating and
79freeing the structure in a loop), or B<NULL>.
80
81=head1 RETURN VALUES
82
83BN_generate_prime() returns the prime number on success, B<NULL> otherwise.
84
85BN_is_prime() returns 0 if the number is composite, 1 if it is
86prime with an error probability of less than 0.25^B<checks>, and
87-1 on error.
88
89The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
90
91=head1 SEE ALSO
92
93L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>
94
95=head1 HISTORY
96
97The B<cb_arg> arguments to BN_generate_prime() and to BN_is_prime()
98were added in SSLeay 0.9.0. The B<ret> argument to BN_generate_prime()
99was added in SSLeay 0.9.1.
100BN_is_prime_fasttest() was added in OpenSSL 0.9.5.
101
102=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_mod_inverse.pod b/src/lib/libssl/src/doc/crypto/BN_mod_inverse.pod
new file mode 100644
index 0000000000..49e62daf9f
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_mod_inverse.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5BN_mod_inverse - compute inverse modulo n
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
12 BN_CTX *ctx);
13
14=head1 DESCRIPTION
15
16BN_mod_inverse() computes the inverse of B<a> modulo B<n>
17places the result in B<r> (C<(a*r)%n==1>). If B<r> is NULL,
18a new B<BIGNUM> is created.
19
20B<ctx> is a previously allocated B<BN_CTX> used for temporary
21variables. B<r> may be the same B<BIGNUM> as B<a> or B<n>.
22
23=head1 RETURN VALUES
24
25BN_mod_inverse() returns the B<BIGNUM> containing the inverse, and
26NULL on error. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
27
28=head1 SEE ALSO
29
30L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>
31
32=head1 HISTORY
33
34BN_mod_inverse() is available in all versions of SSLeay and OpenSSL.
35
36=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_mod_mul_montgomery.pod b/src/lib/libssl/src/doc/crypto/BN_mod_mul_montgomery.pod
new file mode 100644
index 0000000000..0f0c1375af
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_mod_mul_montgomery.pod
@@ -0,0 +1,95 @@
1=pod
2
3=head1 NAME
4
5BN_mod_mul_montgomery, BN_MONT_CTX_new, BN_MONT_CTX_init,
6BN_MONT_CTX_free, BN_MONT_CTX_set, BN_MONT_CTX_copy,
7BN_from_montgomery, BN_to_montgomery - Montgomery multiplication
8
9=head1 SYNOPSIS
10
11 #include <openssl/bn.h>
12
13 BN_MONT_CTX *BN_MONT_CTX_new(void);
14 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
15 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
16
17 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
18 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
19
20 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
21 BN_MONT_CTX *mont, BN_CTX *ctx);
22
23 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
24 BN_CTX *ctx);
25
26 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
27 BN_CTX *ctx);
28
29=head1 DESCRIPTION
30
31These functions implement Montgomery multiplication. They are used
32automatically when L<BN_mod_exp(3)|BN_mod_exp(3)> is called with suitable input,
33but they may be useful when several operations are to be performed
34using the same modulus.
35
36BN_MONT_CTX_new() allocates and initializes a B<BN_MONT_CTX> structure.
37BN_MONT_CTX_init() initializes an existing uninitialized B<BN_MONT_CTX>.
38
39BN_MONT_CTX_set() sets up the B<mont> structure from the modulus B<m>
40by precomputing its inverse and a value R.
41
42BN_MONT_CTX_copy() copies the B<N_MONT_CTX> B<from> to B<to>.
43
44BN_MONT_CTX_free() frees the components of the B<BN_MONT_CTX>, and, if
45it was created by BN_MONT_CTX_new(), also the structure itself.
46
47BN_mod_mul_montgomery() computes Mont(B<a>,B<b>):=B<a>*B<b>*R^-1 and places
48the result in B<r>.
49
50BN_from_montgomery() performs the Montgomery reduction B<r> = B<a>*R^-1.
51
52BN_to_montgomery() computes Mont(B<a>,R^2).
53
54For all functions, B<ctx> is a previously allocated B<BN_CTX> used for
55temporary variables.
56
57The B<BN_MONT_CTX> structure is defined as follows:
58
59 typedef struct bn_mont_ctx_st
60 {
61 int ri; /* number of bits in R */
62 BIGNUM RR; /* R^2 (used to convert to Montgomery form) */
63 BIGNUM N; /* The modulus */
64 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
65 * (Ni is only stored for bignum algorithm) */
66 BN_ULONG n0; /* least significant word of Ni */
67 int flags;
68 } BN_MONT_CTX;
69
70BN_to_montgomery() is a macro.
71
72=head1 RETURN VALUES
73
74BN_MONT_CTX_new() returns the newly allocated B<BN_MONT_CTX>, and NULL
75on error.
76
77BN_MONT_CTX_init() and BN_MONT_CTX_free() have no return values.
78
79For the other functions, 1 is returned for success, 0 on error.
80The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
81
82=head1 SEE ALSO
83
84L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
85L<BN_CTX_new(3)|BN_CTX_new(3)>
86
87=head1 HISTORY
88
89BN_MONT_CTX_new(), BN_MONT_CTX_free(), BN_MONT_CTX_set(),
90BN_mod_mul_montgomery(), BN_from_montgomery() and BN_to_montgomery()
91are available in all versions of SSLeay and OpenSSL.
92
93BN_MONT_CTX_init() and BN_MONT_CTX_copy() were added in SSLeay 0.9.1b.
94
95=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_mod_mul_reciprocal.pod b/src/lib/libssl/src/doc/crypto/BN_mod_mul_reciprocal.pod
new file mode 100644
index 0000000000..32432ce4e6
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_mod_mul_reciprocal.pod
@@ -0,0 +1,81 @@
1=pod
2
3=head1 NAME
4
5BN_mod_mul_reciprocal, BN_RECP_CTX_new, BN_RECP_CTX_init,
6BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using
7reciprocal
8
9=head1 SYNOPSIS
10
11 #include <openssl/bn.h>
12
13 BN_RECP_CTX *BN_RECP_CTX_new(void);
14 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
15 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
16
17 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
18
19 int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
20 BN_CTX *ctx);
21
22 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
23 BN_RECP_CTX *recp, BN_CTX *ctx);
24
25=head1 DESCRIPTION
26
27BN_mod_mul_reciprocal() can be used to perform an efficient
28L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed
29repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
30using B<recp>=1/B<m>, which is set as described below. B<ctx> is a
31previously allocated B<BN_CTX> used for temporary variables.
32
33BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
34BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
35
36BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
37was created by BN_RECP_CTX_new(), also the structure itself.
38
39BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
401/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
41integer. The result and the number of bits it was shifted left will
42later be stored in B<recp>.
43
44BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient
45in B<dv> and the remainder in B<rem>.
46
47The B<BN_RECP_CTX> structure is defined as follows:
48
49 typedef struct bn_recp_ctx_st
50 {
51 BIGNUM N; /* the divisor */
52 BIGNUM Nr; /* the reciprocal */
53 int num_bits;
54 int shift;
55 int flags;
56 } BN_RECP_CTX;
57
58It cannot be shared between threads.
59
60=head1 RETURN VALUES
61
62BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
63on error.
64
65BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
66
67For the other functions, 1 is returned for success, 0 on error.
68The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
69
70=head1 SEE ALSO
71
72L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
73L<BN_CTX_new(3)|BN_CTX_new(3)>
74
75=head1 HISTORY
76
77B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function
78BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
79arguments were different.
80
81=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_new.pod b/src/lib/libssl/src/doc/crypto/BN_new.pod
new file mode 100644
index 0000000000..c1394ff2a3
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_new.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5BN_new, BN_init, BN_clear, BN_free, BN_clear_free - allocate and free BIGNUMs
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_new(void);
12
13 void BN_init(BIGNUM *);
14
15 void BN_clear(BIGNUM *a);
16
17 void BN_free(BIGNUM *a);
18
19 void BN_clear_free(BIGNUM *a);
20
21=head1 DESCRIPTION
22
23BN_new() allocated and initializes a B<BIGNUM> structure. BN_init()
24initializes an existing uninitialized B<BIGNUM>.
25
26BN_clear() is used to destroy sensitive data such as keys when they
27are no longer needed. It erases the memory used by B<a> and sets it
28to the value 0.
29
30BN_free() frees the components of the B<BIGNUM>, and if it was created
31by BN_new(), also the structure itself. BN_clear_free() additionally
32overwrites the data before the memory is returned to the system.
33
34=head1 RETURN VALUES
35
36BN_new() returns a pointer to the B<BIGNUM>. If the allocation fails,
37it returns B<NULL> and sets an error code that can be obtained
38by L<ERR_get_error(3)|ERR_get_error(3)>.
39
40BN_init(), BN_clear(), BN_free() and BN_clear_free() have no return
41values.
42
43=head1 SEE ALSO
44
45L<bn(3)|bn(3)>, L<err(3)|err(3)>
46
47=head1 HISTORY
48
49BN_new(), BN_clear(), BN_free() and BN_clear_free() are available in
50all versions on SSLeay and OpenSSL. BN_init() was added in SSLeay
510.9.1b.
52
53=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_num_bytes.pod b/src/lib/libssl/src/doc/crypto/BN_num_bytes.pod
new file mode 100644
index 0000000000..61589fb9ac
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_num_bytes.pod
@@ -0,0 +1,37 @@
1=pod
2
3=head1 NAME
4
5BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 int BN_num_bytes(const BIGNUM *a);
12
13 int BN_num_bits(const BIGNUM *a);
14
15 int BN_num_bits_word(BN_ULONG w);
16
17=head1 DESCRIPTION
18
19These functions return the size of a B<BIGNUM> in bytes or bits,
20and the size of an unsigned integer in bits.
21
22BN_num_bytes() is a macro.
23
24=head1 RETURN VALUES
25
26The size.
27
28=head1 SEE ALSO
29
30L<bn(3)|bn(3)>
31
32=head1 HISTORY
33
34BN_num_bytes(), BN_num_bits() and BN_num_bits_word() are available in
35all versions of SSLeay and OpenSSL.
36
37=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_rand.pod b/src/lib/libssl/src/doc/crypto/BN_rand.pod
new file mode 100644
index 0000000000..33363c981f
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_rand.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5BN_rand, BN_pseudo_rand - generate pseudo-random number
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
12
13 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
14
15=head1 DESCRIPTION
16
17BN_rand() generates a cryptographically strong pseudo-random number of
18B<bits> bits in length and stores it in B<rnd>. If B<top> is true, the
19two most significant bits of the number will be set to 1, so that the
20product of two such random numbers will always have 2*B<bits> length.
21If B<bottom> is true, the number will be odd.
22
23BN_pseudo_rand() does the same, but pseudo-random numbers generated by
24this function are not necessarily unpredictable. They can be used for
25non-cryptographic purposes and for certain purposes in cryptographic
26protocols, but usually not for key generation etc.
27
28The PRNG must be seeded prior to calling BN_rand().
29
30=head1 RETURN VALUES
31
32BN_rand() and BN_pseudo_rand() return 1 on success, 0 on error.
33The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
34
35=head1 SEE ALSO
36
37L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
38L<RAND_add(3)|RAND_add(3)>, L<RAND_bytes(3)|RAND_bytes(3)>
39
40=head1 HISTORY
41
42BN_rand() is available in all versions of SSLeay and OpenSSL.
43BN_pseudo_rand() was added in OpenSSL 0.9.5.
44
45=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_set_bit.pod b/src/lib/libssl/src/doc/crypto/BN_set_bit.pod
new file mode 100644
index 0000000000..b7c47b9b01
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_set_bit.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5BN_set_bit, BN_clear_bit, BN_is_bit_set, BN_mask_bits, BN_lshift,
6BN_lshift1, BN_rshift, BN_rshift1 - bit operations on BIGNUMs
7
8=head1 SYNOPSIS
9
10 #include <openssl/bn.h>
11
12 int BN_set_bit(BIGNUM *a, int n);
13 int BN_clear_bit(BIGNUM *a, int n);
14
15 int BN_is_bit_set(const BIGNUM *a, int n);
16
17 int BN_mask_bits(BIGNUM *a, int n);
18
19 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
20 int BN_lshift1(BIGNUM *r, BIGNUM *a);
21
22 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
23 int BN_rshift1(BIGNUM *r, BIGNUM *a);
24
25=head1 DESCRIPTION
26
27BN_set_bit() sets bit B<n> in B<a> to 1 (C<a|=(1E<lt>E<lt>n)>). The
28number is expanded if necessary.
29
30BN_clear_bit() sets bit B<n> in B<a> to 0 (C<a&=~(1E<lt>E<lt>n)>). An
31error occurs if B<a> is shorter than B<n> bits.
32
33BN_is_bit_set() tests if bit B<n> in B<a> is set.
34
35BN_mask_bits() truncates B<a> to an B<n> bit number
36(C<a&=~((~0)E<gt>E<gt>n)>). An error occurs if B<a> already is
37shorter than B<n> bits.
38
39BN_lshift() shifts B<a> left by B<n> bits and places the result in
40B<r> (C<r=a*2^n>). BN_lshift1() shifts B<a> left by one and places
41the result in B<r> (C<r=2*a>).
42
43BN_rshift() shifts B<a> right by B<n> bits and places the result in
44B<r> (C<r=a/2^n>). BN_rshift1() shifts B<a> right by one and places
45the result in B<r> (C<r=a/2>).
46
47For the shift functions, B<r> and B<a> may be the same variable.
48
49=head1 RETURN VALUES
50
51BN_is_bit_set() returns 1 if the bit is set, 0 otherwise.
52
53All other functions return 1 for success, 0 on error. The error codes
54can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
55
56=head1 SEE ALSO
57
58L<bn(3)|bn(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>, L<BN_add(3)|BN_add(3)>
59
60=head1 HISTORY
61
62BN_set_bit(), BN_clear_bit(), BN_is_bit_set(), BN_mask_bits(),
63BN_lshift(), BN_lshift1(), BN_rshift(), and BN_rshift1() are available
64in all versions of SSLeay and OpenSSL.
65
66=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_swap.pod b/src/lib/libssl/src/doc/crypto/BN_swap.pod
new file mode 100644
index 0000000000..79efaa1446
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_swap.pod
@@ -0,0 +1,23 @@
1=pod
2
3=head1 NAME
4
5BN_swap - exchange BIGNUMs
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 void BN_swap(BIGNUM *a, BIGNUM *b);
12
13=head1 DESCRIPTION
14
15BN_swap() exchanges the values of I<a> and I<b>.
16
17L<bn(3)|bn(3)>
18
19=head1 HISTORY
20
21BN_swap was added in OpenSSL 0.9.7.
22
23=cut
diff --git a/src/lib/libssl/src/doc/crypto/BN_zero.pod b/src/lib/libssl/src/doc/crypto/BN_zero.pod
new file mode 100644
index 0000000000..165fd9a228
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/BN_zero.pod
@@ -0,0 +1,55 @@
1=pod
2
3=head1 NAME
4
5BN_zero, BN_one, BN_set_word, BN_get_word - BIGNUM assignment operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 int BN_zero(BIGNUM *a);
12 int BN_one(BIGNUM *a);
13
14 BIGNUM *BN_value_one(void);
15
16 int BN_set_word(BIGNUM *a, unsigned long w);
17 unsigned long BN_get_word(BIGNUM *a);
18
19=head1 DESCRIPTION
20
21BN_zero(), BN_one() and BN_set_word() set B<a> to the values 0, 1 and
22B<w> respectively. BN_zero() and BN_one() are macros.
23
24BN_value_one() returns a B<BIGNUM> constant of value 1. This constant
25is useful for use in comparisons and assignment.
26
27BN_get_word() returns B<a>, if it can be represented as an unsigned
28long.
29
30=head1 RETURN VALUES
31
32BN_get_word() returns the value B<a>, and 0xffffffffL if B<a> cannot
33be represented as an unsigned long.
34
35BN_zero(), BN_one() and BN_set_word() return 1 on success, 0 otherwise.
36BN_value_one() returns the constant.
37
38=head1 BUGS
39
40Someone might change the constant.
41
42If a B<BIGNUM> is equal to 0xffffffffL it can be represented as an
43unsigned long but this value is also returned on error.
44
45=head1 SEE ALSO
46
47L<bn(3)|bn(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
48
49=head1 HISTORY
50
51BN_zero(), BN_one() and BN_set_word() are available in all versions of
52SSLeay and OpenSSL. BN_value_one() and BN_get_word() were added in
53SSLeay 0.8.
54
55=cut
diff --git a/src/lib/libssl/src/doc/crypto/CRYPTO_set_ex_data.pod b/src/lib/libssl/src/doc/crypto/CRYPTO_set_ex_data.pod
new file mode 100644
index 0000000000..1bd5bed67d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/CRYPTO_set_ex_data.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5CRYPTO_set_ex_data, CRYPTO_get_ex_data - internal application specific data functions
6
7=head1 SYNOPSIS
8
9 int CRYPTO_set_ex_data(CRYPTO_EX_DATA *r, int idx, void *arg);
10
11 void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *r, int idx);
12
13=head1 DESCRIPTION
14
15Several OpenSSL structures can have application specific data attached to them.
16These functions are used internally by OpenSSL to manipulate application
17specific data attached to a specific structure.
18
19These functions should only be used by applications to manipulate
20B<CRYPTO_EX_DATA> structures passed to the B<new_func()>, B<free_func()> and
21B<dup_func()> callbacks: as passed to B<RSA_get_ex_new_index()> for example.
22
23B<CRYPTO_set_ex_data()> is used to set application specific data, the data is
24supplied in the B<arg> parameter and its precise meaning is up to the
25application.
26
27B<CRYPTO_get_ex_data()> is used to retrieve application specific data. The data
28is returned to the application, this will be the same value as supplied to
29a previous B<CRYPTO_set_ex_data()> call.
30
31=head1 RETURN VALUES
32
33B<CRYPTO_set_ex_data()> returns 1 on success or 0 on failure.
34
35B<CRYPTO_get_ex_data()> returns the application data or 0 on failure. 0 may also
36be valid application data but currently it can only fail if given an invalid B<idx>
37parameter.
38
39On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 SEE ALSO
42
43L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
44L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
45L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>
46
47=head1 HISTORY
48
49CRYPTO_set_ex_data() and CRYPTO_get_ex_data() have been available since SSLeay 0.9.0.
50
51=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_generate_key.pod b/src/lib/libssl/src/doc/crypto/DH_generate_key.pod
new file mode 100644
index 0000000000..920995b2e5
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_generate_key.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_generate_key(DH *dh);
12
13 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
14
15=head1 DESCRIPTION
16
17DH_generate_key() performs the first step of a Diffie-Hellman key
18exchange by generating private and public DH values. By calling
19DH_compute_key(), these are combined with the other party's public
20value to compute the shared key.
21
22DH_generate_key() expects B<dh> to contain the shared parameters
23B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
24unless B<dh-E<gt>priv_key> is already set, and computes the
25corresponding public value B<dh-E<gt>pub_key>, which can then be
26published.
27
28DH_compute_key() computes the shared secret from the private DH value
29in B<dh> and the other party's public value in B<pub_key> and stores
30it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
31
32=head1 RETURN VALUES
33
34DH_generate_key() returns 1 on success, 0 otherwise.
35
36DH_compute_key() returns the size of the shared secret on success, -1
37on error.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 SEE ALSO
42
43L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)>
44
45=head1 HISTORY
46
47DH_generate_key() and DH_compute_key() are available in all versions
48of SSLeay and OpenSSL.
49
50=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_generate_parameters.pod b/src/lib/libssl/src/doc/crypto/DH_generate_parameters.pod
new file mode 100644
index 0000000000..a7d0c75f0c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_generate_parameters.pod
@@ -0,0 +1,72 @@
1=pod
2
3=head1 NAME
4
5DH_generate_parameters, DH_check - generate and check Diffie-Hellman parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *DH_generate_parameters(int prime_len, int generator,
12 void (*callback)(int, int, void *), void *cb_arg);
13
14 int DH_check(DH *dh, int *codes);
15
16=head1 DESCRIPTION
17
18DH_generate_parameters() generates Diffie-Hellman parameters that can
19be shared among a group of users, and returns them in a newly
20allocated B<DH> structure. The pseudo-random number generator must be
21seeded prior to calling DH_generate_parameters().
22
23B<prime_len> is the length in bits of the safe prime to be generated.
24B<generator> is a small number E<gt> 1, typically 2 or 5.
25
26A callback function may be used to provide feedback about the progress
27of the key generation. If B<callback> is not B<NULL>, it will be
28called as described in L<BN_generate_prime(3)|BN_generate_prime(3)> while a random prime
29number is generated, and when a prime has been found, B<callback(3,
300, cb_arg)> is called.
31
32DH_check() validates Diffie-Hellman parameters. It checks that B<p> is
33a safe prime, and that B<g> is a suitable generator. In the case of an
34error, the bit flags DH_CHECK_P_NOT_SAFE_PRIME or
35DH_NOT_SUITABLE_GENERATOR are set in B<*codes>.
36DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be
37checked, i.e. it does not equal 2 or 5.
38
39=head1 RETURN VALUES
40
41DH_generate_parameters() returns a pointer to the DH structure, or
42NULL if the parameter generation fails. The error codes can be
43obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
44
45DH_check() returns 1 if the check could be performed, 0 otherwise.
46
47=head1 NOTES
48
49DH_generate_parameters() may run for several hours before finding a
50suitable prime.
51
52The parameters generated by DH_generate_parameters() are not to be
53used in signature schemes.
54
55=head1 BUGS
56
57If B<generator> is not 2 or 5, B<dh-E<gt>g>=B<generator> is not
58a usable generator.
59
60=head1 SEE ALSO
61
62L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_free(3)|DH_free(3)>
63
64=head1 HISTORY
65
66DH_check() is available in all versions of SSLeay and OpenSSL.
67The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
68
69In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
70instead of DH_CHECK_P_NOT_SAFE_PRIME.
71
72=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_get_ex_new_index.pod b/src/lib/libssl/src/doc/crypto/DH_get_ex_new_index.pod
new file mode 100644
index 0000000000..82e2548bcd
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data - add application specific data to DH structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DH_set_ex_data(DH *d, int idx, void *arg);
17
18 char *DH_get_ex_data(DH *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DH
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index()|RSA_get_ex_new_index()>, L<dh(3)|dh(3)>
30
31=head1 HISTORY
32
33DH_get_ex_new_index(), DH_set_ex_data() and DH_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_new.pod b/src/lib/libssl/src/doc/crypto/DH_new.pod
new file mode 100644
index 0000000000..64624b9d15
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_new.pod
@@ -0,0 +1,40 @@
1=pod
2
3=head1 NAME
4
5DH_new, DH_free - allocate and free DH objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH* DH_new(void);
12
13 void DH_free(DH *dh);
14
15=head1 DESCRIPTION
16
17DH_new() allocates and initializes a B<DH> structure.
18
19DH_free() frees the B<DH> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DH_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28DH_free() returns no value.
29
30=head1 SEE ALSO
31
32L<dh(3)|dh(3)>, L<err(3)|err(3)>,
33L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
34L<DH_generate_key(3)|DH_generate_key(3)>
35
36=head1 HISTORY
37
38DH_new() and DH_free() are available in all versions of SSLeay and OpenSSL.
39
40=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_set_method.pod b/src/lib/libssl/src/doc/crypto/DH_set_method.pod
new file mode 100644
index 0000000000..dca41d8dbc
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_set_method.pod
@@ -0,0 +1,99 @@
1=pod
2
3=head1 NAME
4
5DH_set_default_method, DH_get_default_method, DH_set_method,
6DH_new_method, DH_OpenSSL - select DH method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11
12 void DH_set_default_method(DH_METHOD *meth);
13
14 DH_METHOD *DH_get_default_method(void);
15
16 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
17
18 DH *DH_new_method(DH_METHOD *meth);
19
20 DH_METHOD *DH_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DH_OpenSSL() returns a pointer to that method.
30
31DH_set_default_method() makes B<meth> the default method for all B<DH>
32structures created later.
33
34DH_get_default_method() returns a pointer to the current default
35method.
36
37DH_set_method() selects B<meth> for all operations using the structure B<dh>.
38
39DH_get_method() returns a pointer to the method currently selected
40for B<dh>.
41
42DH_new_method() allocates and initializes a B<DH> structure so that
43B<method> will be used for the DH operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DH_METHOD STRUCTURE
47
48 typedef struct dh_meth_st
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* generate private and public DH values for key agreement */
54 int (*generate_key)(DH *dh);
55
56 /* compute shared secret */
57 int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
58
59 /* compute r = a ^ p mod m. May be NULL */
60 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
61 const BIGNUM *m, BN_CTX *ctx,
62 BN_MONT_CTX *m_ctx);
63
64 /* called at DH_new */
65 int (*init)(DH *dh);
66
67 /* called at DH_free */
68 int (*finish)(DH *dh);
69
70 int flags;
71
72 char *app_data; /* ?? */
73
74 } DH_METHOD;
75
76=head1 RETURN VALUES
77
78DH_OpenSSL(), DH_get_default_method() and DH_get_method() return
79pointers to the respective B<DH_METHOD>s.
80
81DH_set_default_method() returns no value.
82
83DH_set_method() returns a pointer to the B<DH_METHOD> previously
84associated with B<dh>.
85
86DH_new_method() returns B<NULL> and sets an error code that can be
87obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
88returns a pointer to the newly allocated structure.
89
90=head1 SEE ALSO
91
92L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
93
94=head1 HISTORY
95
96DH_set_default_method(), DH_get_default_method(), DH_set_method(),
97DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
98
99=cut
diff --git a/src/lib/libssl/src/doc/crypto/DH_size.pod b/src/lib/libssl/src/doc/crypto/DH_size.pod
new file mode 100644
index 0000000000..97f26fda78
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DH_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DH_size - get Diffie-Hellman prime size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_size(DH *dh);
12
13=head1 DESCRIPTION
14
15This function returns the Diffie-Hellman size in bytes. It can be used
16to determine how much memory must be allocated for the shared secret
17computed by DH_compute_key().
18
19B<dh-E<gt>p> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dh(3)|dh(3)>, L<DH_generate_key(3)|DH_generate_key(3)>
28
29=head1 HISTORY
30
31DH_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_SIG_new.pod b/src/lib/libssl/src/doc/crypto/DSA_SIG_new.pod
new file mode 100644
index 0000000000..671655554a
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_SIG_new.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5DSA_SIG_new, DSA_SIG_free - allocate and free DSA signature objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_SIG_new(void);
12
13 void DSA_SIG_free(DSA_SIG *a);
14
15=head1 DESCRIPTION
16
17DSA_SIG_new() allocates and initializes a B<DSA_SIG> structure.
18
19DSA_SIG_free() frees the B<DSA_SIG> structure and its components. The
20values are erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_SIG_new() returns B<NULL> and sets an
25error code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_SIG_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<DSA_do_sign(3)|DSA_do_sign(3)>
34
35=head1 HISTORY
36
37DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
38
39=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_do_sign.pod b/src/lib/libssl/src/doc/crypto/DSA_do_sign.pod
new file mode 100644
index 0000000000..a24fd5714e
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_do_sign.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5DSA_do_sign, DSA_do_verify - raw DSA signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
12
13 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
14 DSA_SIG *sig, DSA *dsa);
15
16=head1 DESCRIPTION
17
18DSA_do_sign() computes a digital signature on the B<len> byte message
19digest B<dgst> using the private key B<dsa> and returns it in a
20newly allocated B<DSA_SIG> structure.
21
22L<DSA_sign_setup(3)|DSA_sign_setup(3)> may be used to precompute part
23of the signing operation in case signature generation is
24time-critical.
25
26DSA_do_verify() verifies that the signature B<sig> matches a given
27message digest B<dgst> of size B<len>. B<dsa> is the signer's public
28key.
29
30=head1 RETURN VALUES
31
32DSA_do_sign() returns the signature, NULL on error. DSA_do_verify()
33returns 1 for a valid signature, 0 for an incorrect signature and -1
34on error. The error codes can be obtained by
35L<ERR_get_error(3)|ERR_get_error(3)>.
36
37=head1 SEE ALSO
38
39L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
40L<DSA_SIG_new(3)|DSA_SIG_new(3)>,
41L<DSA_sign(3)|DSA_sign(3)>
42
43=head1 HISTORY
44
45DSA_do_sign() and DSA_do_verify() were added in OpenSSL 0.9.3.
46
47=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_dup_DH.pod b/src/lib/libssl/src/doc/crypto/DSA_dup_DH.pod
new file mode 100644
index 0000000000..29cb1075d1
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_dup_DH.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_dup_DH - create a DH structure out of DSA structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DH * DSA_dup_DH(DSA *r);
12
13=head1 DESCRIPTION
14
15DSA_dup_DH() duplicates DSA parameters/keys as DH parameters/keys. q
16is lost during that conversion, but the resulting DH parameters
17contain its length.
18
19=head1 RETURN VALUE
20
21DSA_dup_DH() returns the new B<DH> structure, and NULL on error. The
22error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
23
24=head1 NOTE
25
26Be careful to avoid small subgroup attacks when using this.
27
28=head1 SEE ALSO
29
30L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>
31
32=head1 HISTORY
33
34DSA_dup_DH() was added in OpenSSL 0.9.4.
35
36=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_generate_key.pod b/src/lib/libssl/src/doc/crypto/DSA_generate_key.pod
new file mode 100644
index 0000000000..52890db5be
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_generate_key.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_key - generate DSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_generate_key(DSA *a);
12
13=head1 DESCRIPTION
14
15DSA_generate_key() expects B<a> to contain DSA parameters. It generates
16a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
17
18The PRNG must be seeded prior to calling DSA_generate_key().
19
20=head1 RETURN VALUE
21
22DSA_generate_key() returns 1 on success, 0 otherwise.
23The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
28
29=head1 HISTORY
30
31DSA_generate_key() is available since SSLeay 0.8.
32
33=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_generate_parameters.pod b/src/lib/libssl/src/doc/crypto/DSA_generate_parameters.pod
new file mode 100644
index 0000000000..43f60b0eb9
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_generate_parameters.pod
@@ -0,0 +1,105 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_parameters - generate DSA parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA *DSA_generate_parameters(int bits, unsigned char *seed,
12 int seed_len, int *counter_ret, unsigned long *h_ret,
13 void (*callback)(int, int, void *), void *cb_arg);
14
15=head1 DESCRIPTION
16
17DSA_generate_parameters() generates primes p and q and a generator g
18for use in the DSA.
19
20B<bits> is the length of the prime to be generated; the DSS allows a
21maximum of 1024 bits.
22
23If B<seed> is B<NULL> or B<seed_len> E<lt> 20, the primes will be
24generated at random. Otherwise, the seed is used to generate
25them. If the given seed does not yield a prime q, a new random
26seed is chosen and placed at B<seed>.
27
28DSA_generate_parameters() places the iteration count in
29*B<counter_ret> and a counter used for finding a generator in
30*B<h_ret>, unless these are B<NULL>.
31
32A callback function may be used to provide feedback about the progress
33of the key generation. If B<callback> is not B<NULL>, it will be
34called as follows:
35
36=over 4
37
38=item *
39
40When a candidate for q is generated, B<callback(0, m++, cb_arg)> is called
41(m is 0 for the first candidate).
42
43=item *
44
45When a candidate for q has passed a test by trial division,
46B<callback(1, -1, cb_arg)> is called.
47While a candidate for q is tested by Miller-Rabin primality tests,
48B<callback(1, i, cb_arg)> is called in the outer loop
49(once for each witness that confirms that the candidate may be prime);
50i is the loop counter (starting at 0).
51
52=item *
53
54When a prime q has been found, B<callback(2, 0, cb_arg)> and
55B<callback(3, 0, cb_arg)> are called.
56
57=item *
58
59Before a candidate for p (other than the first) is generated and tested,
60B<callback(0, counter, cb_arg)> is called.
61
62=item *
63
64When a candidate for p has passed the test by trial division,
65B<callback(1, -1, cb_arg)> is called.
66While it is tested by the Miller-Rabin primality test,
67B<callback(1, i, cb_arg)> is called in the outer loop
68(once for each witness that confirms that the candidate may be prime).
69i is the loop counter (starting at 0).
70
71=item *
72
73When p has been found, B<callback(2, 1, cb_arg)> is called.
74
75=item *
76
77When the generator has been found, B<callback(3, 1, cb_arg)> is called.
78
79=back
80
81=head1 RETURN VALUE
82
83DSA_generate_parameters() returns a pointer to the DSA structure, or
84B<NULL> if the parameter generation fails. The error codes can be
85obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87=head1 BUGS
88
89Seed lengths E<gt> 20 are not supported.
90
91=head1 SEE ALSO
92
93L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
94L<DSA_free(3)|DSA_free(3)>
95
96=head1 HISTORY
97
98DSA_generate_parameters() appeared in SSLeay 0.8. The B<cb_arg>
99argument was added in SSLeay 0.9.0.
100In versions up to OpenSSL 0.9.4, B<callback(1, ...)> was called
101in the inner loop of the Miller-Rabin test whenever it reached the
102squaring step (the parameters to B<callback> did not reveal how many
103witnesses had been tested); since OpenSSL 0.9.5, B<callback(1, ...)>
104is called as in BN_is_prime(3), i.e. once for each witness.
105=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_get_ex_new_index.pod b/src/lib/libssl/src/doc/crypto/DSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..4612e708ec
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data - add application specific data to DSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/DSA.h>
10
11 int DSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DSA_set_ex_data(DSA *d, int idx, void *arg);
17
18 char *DSA_get_ex_data(DSA *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DSA
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dsa(3)|dsa(3)>
30
31=head1 HISTORY
32
33DSA_get_ex_new_index(), DSA_set_ex_data() and DSA_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_new.pod b/src/lib/libssl/src/doc/crypto/DSA_new.pod
new file mode 100644
index 0000000000..7dde54445b
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_new.pod
@@ -0,0 +1,41 @@
1=pod
2
3=head1 NAME
4
5DSA_new, DSA_free - allocate and free DSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA* DSA_new(void);
12
13 void DSA_free(DSA *dsa);
14
15=head1 DESCRIPTION
16
17DSA_new() allocates and initializes a B<DSA> structure.
18
19DSA_free() frees the B<DSA> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_new() returns B<NULL> and sets an error
25code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
34L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
35L<DSA_generate_key(3)|DSA_generate_key(3)>
36
37=head1 HISTORY
38
39DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
40
41=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_set_method.pod b/src/lib/libssl/src/doc/crypto/DSA_set_method.pod
new file mode 100644
index 0000000000..0b13ec9237
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_set_method.pod
@@ -0,0 +1,111 @@
1=pod
2
3=head1 NAME
4
5DSA_set_default_method, DSA_get_default_method, DSA_set_method,
6DSA_new_method, DSA_OpenSSL - select RSA method
7
8=head1 SYNOPSIS
9
10 #include <openssl/DSA.h>
11
12 void DSA_set_default_method(DSA_METHOD *meth);
13
14 DSA_METHOD *DSA_get_default_method(void);
15
16 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
17
18 DSA *DSA_new_method(DSA_METHOD *meth);
19
20 DSA_METHOD *DSA_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DSA_OpenSSL() returns a pointer to that method.
30
31DSA_set_default_method() makes B<meth> the default method for all B<DSA>
32structures created later.
33
34DSA_get_default_method() returns a pointer to the current default
35method.
36
37DSA_set_method() selects B<meth> for all operations using the structure B<DSA>.
38
39DSA_get_method() returns a pointer to the method currently selected
40for B<DSA>.
41
42DSA_new_method() allocates and initializes a B<DSA> structure so that
43B<method> will be used for the DSA operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DSA_METHOD STRUCTURE
47
48struct
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* sign */
54 DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
55 DSA *dsa);
56
57 /* pre-compute k^-1 and r */
58 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
59 BIGNUM **rp);
60
61 /* verify */
62 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
63 DSA_SIG *sig, DSA *dsa);
64
65 /* compute rr = a1^p1 * a2^p2 mod m. May be NULL */
66 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
67 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
68 BN_CTX *ctx, BN_MONT_CTX *in_mont);
69
70 /* compute r = a ^ p mod m. May be NULL */
71 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
72 const BIGNUM *p, const BIGNUM *m,
73 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
74
75 /* called at DSA_new */
76 int (*init)(DSA *DSA);
77
78 /* called at DSA_free */
79 int (*finish)(DSA *DSA);
80
81 int flags;
82
83 char *app_data; /* ?? */
84
85 } DSA_METHOD;
86
87=head1 RETURN VALUES
88
89DSA_OpenSSL(), DSA_get_default_method() and DSA_get_method() return
90pointers to the respective B<DSA_METHOD>s.
91
92DSA_set_default_method() returns no value.
93
94DSA_set_method() returns a pointer to the B<DSA_METHOD> previously
95associated with B<dsa>.
96
97DSA_new_method() returns B<NULL> and sets an error code that can be
98obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
99fails. Otherwise it returns a pointer to the newly allocated
100structure.
101
102=head1 SEE ALSO
103
104L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
105
106=head1 HISTORY
107
108DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
109DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
110
111=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_sign.pod b/src/lib/libssl/src/doc/crypto/DSA_sign.pod
new file mode 100644
index 0000000000..f6e60a8ca3
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_sign.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5DSA_sign, DSA_sign_setup, DSA_verify - DSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_sign(int type, const unsigned char *dgst, int len,
12 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
13
14 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
15 BIGNUM **rp);
16
17 int DSA_verify(int type, const unsigned char *dgst, int len,
18 unsigned char *sigbuf, int siglen, DSA *dsa);
19
20=head1 DESCRIPTION
21
22DSA_sign() computes a digital signature on the B<len> byte message
23digest B<dgst> using the private key B<dsa> and places its ASN.1 DER
24encoding at B<sigret>. The length of the signature is places in
25*B<siglen>. B<sigret> must point to DSA_size(B<dsa>) bytes of memory.
26
27DSA_sign_setup() may be used to precompute part of the signing
28operation in case signature generation is time-critical. It expects
29B<dsa> to contain DSA parameters. It places the precomputed values
30in newly allocated B<BIGNUM>s at *B<kinvp> and *B<rp>, after freeing
31the old ones unless *B<kinvp> and *B<rp> are NULL. These values may
32be passed to DSA_sign() in B<dsa-E<gt>kinv> and B<dsa-E<gt>r>.
33B<ctx> is a pre-allocated B<BN_CTX> or NULL.
34
35DSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
36matches a given message digest B<dgst> of size B<len>.
37B<dsa> is the signer's public key.
38
39The B<type> parameter is ignored.
40
41The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
42is called.
43
44=head1 RETURN VALUES
45
46DSA_sign() and DSA_sign_setup() return 1 on success, 0 on error.
47DSA_verify() returns 1 for a valid signature, 0 for an incorrect
48signature and -1 on error. The error codes can be obtained by
49L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 CONFORMING TO
52
53US Federal Information Processing Standard FIPS 186 (Digital Signature
54Standard, DSS), ANSI X9.30
55
56=head1 SEE ALSO
57
58L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
59L<DSA_do_sign(3)|DSA_do_sign(3)>
60
61=head1 HISTORY
62
63DSA_sign() and DSA_verify() are available in all versions of SSLeay.
64DSA_sign_setup() was added in SSLeay 0.8.
65
66=cut
diff --git a/src/lib/libssl/src/doc/crypto/DSA_size.pod b/src/lib/libssl/src/doc/crypto/DSA_size.pod
new file mode 100644
index 0000000000..23b6320a4d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/DSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DSA_size - get DSA signature size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_size(DSA *dsa);
12
13=head1 DESCRIPTION
14
15This function returns the size of an ASN.1 encoded DSA signature in
16bytes. It can be used to determine how much memory must be allocated
17for a DSA signature.
18
19B<dsa-E<gt>q> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<DSA_sign(3)|DSA_sign(3)>
28
29=head1 HISTORY
30
31DSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_GET_LIB.pod b/src/lib/libssl/src/doc/crypto/ERR_GET_LIB.pod
new file mode 100644
index 0000000000..2a129da036
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_GET_LIB.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_GET_LIB, ERR_GET_FUNC, ERR_GET_REASON - get library, function and
6reason code
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 int ERR_GET_LIB(unsigned long e);
13
14 int ERR_GET_FUNC(unsigned long e);
15
16 int ERR_GET_REASON(unsigned long e);
17
18=head1 DESCRIPTION
19
20The error code returned by ERR_get_error() consists of a library
21number, function code and reason code. ERR_GET_LIB(), ERR_GET_FUNC()
22and ERR_GET_REASON() can be used to extract these.
23
24The library number and function code describe where the error
25occurred, the reason code is the information about what went wrong.
26
27Each sub-library of OpenSSL has a unique library number; function and
28reason codes are unique within each sub-library. Note that different
29libraries may use the same value to signal different functions and
30reasons.
31
32B<ERR_R_...> reason codes such as B<ERR_R_MALLOC_FAILURE> are globally
33unique. However, when checking for sub-library specific reason codes,
34be sure to also compare the library number.
35
36ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are macros.
37
38=head1 RETURN VALUES
39
40The library number, function code and reason code respectively.
41
42=head1 SEE ALSO
43
44L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
45
46=head1 HISTORY
47
48ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are available in
49all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_clear_error.pod b/src/lib/libssl/src/doc/crypto/ERR_clear_error.pod
new file mode 100644
index 0000000000..566e1f4e31
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_clear_error.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5ERR_clear_error - clear the error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_clear_error(void);
12
13=head1 DESCRIPTION
14
15ERR_clear_error() empties the current thread's error queue.
16
17=head1 RETURN VALUES
18
19ERR_clear_error() has no return value.
20
21=head1 SEE ALSO
22
23L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
24
25=head1 HISTORY
26
27ERR_clear_error() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_error_string.pod b/src/lib/libssl/src/doc/crypto/ERR_error_string.pod
new file mode 100644
index 0000000000..0d2417599c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_error_string.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5ERR_error_string - obtain human-readable error message
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 char *ERR_error_string(unsigned long e, char *buf);
12
13 const char *ERR_lib_error_string(unsigned long e);
14 const char *ERR_func_error_string(unsigned long e);
15 const char *ERR_reason_error_string(unsigned long e);
16
17=head1 DESCRIPTION
18
19ERR_error_string() generates a human-readable string representing the
20error code B<e>, and places it at B<buf>. B<buf> must be at least 120
21bytes long. If B<buf> is B<NULL>, the error string is placed in a
22static buffer.
23
24The string will have the following format:
25
26 error:[error code]:[library name]:[function name]:[reason string]
27
28I<error code> is an 8 digit hexadecimal number, I<library name>,
29I<function name> and I<reason string> are ASCII text.
30
31ERR_lib_error_string(), ERR_func_error_string() and
32ERR_reason_error_string() return the library name, function
33name and reason string respectively.
34
35The OpenSSL error strings should be loaded by calling
36L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
37applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
38first.
39If there is no text string registered for the given error code,
40the error string will contain the numeric code.
41
42L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
43all error codes currently in the queue.
44
45=head1 RETURN VALUES
46
47ERR_error_string() returns a pointer to a static buffer containing the
48string if B<buf == NULL>, B<buf> otherwise.
49
50ERR_lib_error_string(), ERR_func_error_string() and
51ERR_reason_error_string() return the strings, and B<NULL> if
52none is registered for the error code.
53
54=head1 SEE ALSO
55
56L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
57L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
58L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
59L<ERR_print_errors(3)|ERR_print_errors(3)>
60
61=head1 HISTORY
62
63ERR_error_string() is available in all versions of SSLeay and OpenSSL.
64
65=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_get_error.pod b/src/lib/libssl/src/doc/crypto/ERR_get_error.pod
new file mode 100644
index 0000000000..75ece00d97
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_get_error.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5ERR_get_error, ERR_peek_error - obtain error code
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13
14 unsigned long ERR_get_error_line(const char **file, int *line);
15 unsigned long ERR_peek_error_line(const char **file, int *line);
16
17 unsigned long ERR_get_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19 unsigned long ERR_peek_error_line_data(const char **file, int *line,
20 const char **data, int *flags);
21
22=head1 DESCRIPTION
23
24ERR_get_error() returns the last error code from the thread's error
25queue and removes the entry. This function can be called repeatedly
26until there are no more error codes to return.
27
28ERR_peek_error() returns the last error code from the thread's
29error queue without modifying it.
30
31See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
32location and reason of the error, and
33L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
34messages.
35
36ERR_get_error_line() and ERR_peek_error_line() are the same as the
37above, but they additionally store the file name and line number where
38the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
39
40ERR_get_error_line_data() and ERR_peek_error_line_data() store
41additional data and flags associated with the error code in *B<data>
42and *B<flags>, unless these are B<NULL>. *B<data> contains a string
43if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by Malloc(),
44*B<flags>&B<ERR_TXT_MALLOCED> is true.
45
46=head1 RETURN VALUES
47
48The error code, or 0 if there is no error in the queue.
49
50=head1 SEE ALSO
51
52L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
53L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
54
55=head1 HISTORY
56
57ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
58ERR_peek_error_line() are available in all versions of SSLeay and
59OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
60were added in SSLeay 0.9.0.
61
62=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_load_crypto_strings.pod b/src/lib/libssl/src/doc/crypto/ERR_load_crypto_strings.pod
new file mode 100644
index 0000000000..9bdec75a46
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_load_crypto_strings.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5ERR_load_crypto_strings, SSL_load_error_strings, ERR_free_strings -
6load and free error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_crypto_strings(void);
13 void ERR_free_strings(void);
14
15 #include <openssl/ssl.h>
16
17 void SSL_load_error_strings(void);
18
19=head1 DESCRIPTION
20
21ERR_load_crypto_strings() registers the error strings for all
22B<libcrypto> functions. SSL_load_error_strings() does the same,
23but also registers the B<libssl> error strings.
24
25One of these functions should be called before generating
26textual error messages. However, this is not required when memory
27usage is an issue.
28
29ERR_free_strings() frees all previously loaded error strings.
30
31=head1 RETURN VALUES
32
33ERR_load_crypto_strings(), SSL_load_error_strings() and
34ERR_free_strings() return no values.
35
36=head1 SEE ALSO
37
38L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>
39
40=head1 HISTORY
41
42ERR_load_error_strings(), SSL_load_error_strings() and
43ERR_free_strings() are available in all versions of SSLeay and
44OpenSSL.
45
46=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_load_strings.pod b/src/lib/libssl/src/doc/crypto/ERR_load_strings.pod
new file mode 100644
index 0000000000..5acdd0edbc
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_load_strings.pod
@@ -0,0 +1,54 @@
1=pod
2
3=head1 NAME
4
5ERR_load_strings, ERR_PACK, ERR_get_next_error_library - load
6arbitrary error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
13
14 int ERR_get_next_error_library(void);
15
16 unsigned long ERR_PACK(int lib, int func, int reason);
17
18=head1 DESCRIPTION
19
20ERR_load_strings() registers error strings for library number B<lib>.
21
22B<str> is an array of error string data:
23
24 typedef struct ERR_string_data_st
25 {
26 unsigned long error;
27 char *string;
28 } ERR_STRING_DATA;
29
30The error code is generated from the library number and a function and
31reason code: B<error> = ERR_PACK(B<lib>, B<func>, B<reason>).
32ERR_PACK() is a macro.
33
34The last entry in the array is {0,0}.
35
36ERR_get_next_error_library() can be used to assign library numbers
37to user libraries at runtime.
38
39=head1 RETURN VALUE
40
41ERR_load_strings() returns no value. ERR_PACK() return the error code.
42ERR_get_next_error_library() returns a new library number.
43
44=head1 SEE ALSO
45
46L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
47
48=head1 HISTORY
49
50ERR_load_error_strings() and ERR_PACK() are available in all versions
51of SSLeay and OpenSSL. ERR_get_next_error_library() was added in
52SSLeay 0.9.0.
53
54=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_print_errors.pod b/src/lib/libssl/src/doc/crypto/ERR_print_errors.pod
new file mode 100644
index 0000000000..b100a5fa2b
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_print_errors.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_print_errors, ERR_print_errors_fp - print error messages
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_print_errors(BIO *bp);
12 void ERR_print_errors_fp(FILE *fp);
13
14=head1 DESCRIPTION
15
16ERR_print_errors() is a convenience function that prints the error
17strings for all errors that OpenSSL has recorded to B<bp>, thus
18emptying the error queue.
19
20ERR_print_errors_fp() is the same, except that the output goes to a
21B<FILE>.
22
23
24The error strings will have the following format:
25
26 [pid]:error:[error code]:[library name]:[function name]:[reason string]:[file name]:[line]:[optional text message]
27
28I<error code> is an 8 digit hexadecimal number. I<library name>,
29I<function name> and I<reason string> are ASCII text, as is I<optional
30text message> if one was set for the respective error code.
31
32If there is no text string registered for the given error code,
33the error string will contain the numeric code.
34
35=head1 RETURN VALUES
36
37ERR_print_errors() and ERR_print_errors_fp() return no values.
38
39=head1 SEE ALSO
40
41L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
42L<ERR_get_error(3)|ERR_get_error(3)>,
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
44L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45
46=head1 HISTORY
47
48ERR_print_errors() and ERR_print_errors_fp()
49are available in all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_put_error.pod b/src/lib/libssl/src/doc/crypto/ERR_put_error.pod
new file mode 100644
index 0000000000..acd241fbe4
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_put_error.pod
@@ -0,0 +1,44 @@
1=pod
2
3=head1 NAME
4
5ERR_put_error, ERR_add_error_data - record an error
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_put_error(int lib, int func, int reason, const char *file,
12 int line);
13
14 void ERR_add_error_data(int num, ...);
15
16=head1 DESCRIPTION
17
18ERR_put_error() adds an error code to the thread's error queue. It
19signals that the error of reason code B<reason> occurred in function
20B<func> of library B<lib>, in line number B<line> of B<file>.
21This function is usually called by a macro.
22
23ERR_add_error_data() associates the concatenation of its B<num> string
24arguments with the error code added last.
25
26L<ERR_load_strings(3)|ERR_load_strings(3)> can be used to register
27error strings so that the application can a generate human-readable
28error messages for the error code.
29
30=head1 RETURN VALUES
31
32ERR_put_error() and ERR_add_error_data() return
33no values.
34
35=head1 SEE ALSO
36
37L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
38
39=head1 HISTORY
40
41ERR_put_error() is available in all versions of SSLeay and OpenSSL.
42ERR_add_error_data() was added in SSLeay 0.9.0.
43
44=cut
diff --git a/src/lib/libssl/src/doc/crypto/ERR_remove_state.pod b/src/lib/libssl/src/doc/crypto/ERR_remove_state.pod
new file mode 100644
index 0000000000..ebcdc0f5a5
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ERR_remove_state.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5ERR_remove_state - free a thread's error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_remove_state(unsigned long pid);
12
13=head1 DESCRIPTION
14
15ERR_remove_state() frees the error queue associated with thread B<pid>.
16If B<pid> == 0, the current thread will have its error queue removed.
17
18Since error queue data structures are allocated automatically for new
19threads, they must be freed when threads are terminated in oder to
20avoid memory leaks.
21
22=head1 RETURN VALUE
23
24ERR_remove_state() returns no value.
25
26=head1 SEE ALSO
27
28L<err(3)|err(3)>
29
30=head1 HISTORY
31
32ERR_remove_state() is available in all versions of SSLeay and OpenSSL.
33
34=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_BytesToKey.pod b/src/lib/libssl/src/doc/crypto/EVP_BytesToKey.pod
new file mode 100644
index 0000000000..5ce4add082
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_BytesToKey.pod
@@ -0,0 +1,67 @@
1=pod
2
3=head1 NAME
4
5 EVP_BytesToKey - password based encryption routine
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
12 const unsigned char *salt,
13 const unsigned char *data, int datal, int count,
14 unsigned char *key,unsigned char *iv);
15
16=head1 DESCRIPTION
17
18EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
19the cipher to derive the key and IV for. B<md> is the message digest to use.
20The B<salt> paramter is used as a salt in the derivation: it should point to
21an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
22B<datal> bytes which is used to derive the keying data. B<count> is the
23iteration count to use. The derived key and IV will be written to B<key>
24and B<iv> respectively.
25
26=head1 NOTES
27
28A typical application of this function is to derive keying material for an
29encryption algorithm from a password in the B<data> parameter.
30
31Increasing the B<count> parameter slows down the algorithm which makes it
32harder for an attacker to peform a brute force attack using a large number
33of candidate passwords.
34
35If the total key and IV length is less than the digest length and
36B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
37otherwise a non standard extension is used to derive the extra data.
38
39Newer applications should use more standard algorithms such as PKCS#5
40v2.0 for key derivation.
41
42=head1 KEY DERIVATION ALGORITHM
43
44The key and IV is derived by concatenating D_1, D_2, etc until
45enough data is available for the key and IV. D_i is defined as:
46
47 D_i = HASH^count(D_(i-1) || data || salt)
48
49where || denotes concatentaion, D_0 is empty, HASH is the digest
50algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
51is HASH(HASH(data)) and so on.
52
53The initial bytes are used for the key and the subsequent bytes for
54the IV.
55
56=head1 RETURN VALUES
57
58EVP_BytesToKey() returns the size of the derived key in bytes.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
64
65=head1 HISTORY
66
67=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod b/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod
new file mode 100644
index 0000000000..345b1ddfa7
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod
@@ -0,0 +1,197 @@
1=pod
2
3=head1 NAME
4
5EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
14 unsigned int *s);
15
16 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
17
18 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
19
20 #define EVP_MD_type(e) ((e)->type)
21 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
22 #define EVP_MD_size(e) ((e)->md_size)
23 #define EVP_MD_block_size(e) ((e)->block_size)
24
25 #define EVP_MD_CTX_md(e) (e)->digest)
26 #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
27 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
28 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
29
30 EVP_MD *EVP_md_null(void);
31 EVP_MD *EVP_md2(void);
32 EVP_MD *EVP_md5(void);
33 EVP_MD *EVP_sha(void);
34 EVP_MD *EVP_sha1(void);
35 EVP_MD *EVP_dss(void);
36 EVP_MD *EVP_dss1(void);
37 EVP_MD *EVP_mdc2(void);
38 EVP_MD *EVP_ripemd160(void);
39
40 const EVP_MD *EVP_get_digestbyname(const char *name);
41 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
42 #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
43
44=head1 DESCRIPTION
45
46The EVP digest routines are a high level interface to message digests.
47
48EVP_DigestInit() initialises a digest context B<ctx> to use a digest
49B<type>: this will typically be supplied by a function such as
50EVP_sha1().
51
52EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
53digest context B<ctx>. This funtion can be called several times on the
54same B<ctx> to hash additional data.
55
56EVP_DigestFinal() retrieves the digest value from B<ctx> and places
57it in B<md>. If the B<s> parameter is not NULL then the number of
58bytes of data written (i.e. the length of the digest) will be written
59to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
60After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate()
61can be made, but EVP_DigestInit() can be called to initialiase a new
62digest operation.
63
64EVP_MD_CTX_copy() can be used to copy the message digest state from
65B<in> to B<out>. This is useful if large amounts of data are to be
66hashed which only differ in the last few bytes.
67
68EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
69when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
70hash.
71
72EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
73message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
74
75EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
76representing the given message digest when passed an B<EVP_MD> structure.
77For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
78normally used when setting ASN1 OIDs.
79
80EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
81B<EVP_MD_CTX>.
82
83EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
84with this digest. For example EVP_sha1() is associated with RSA so this will
85return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
86algorithms may not be retained in future versions of OpenSSL.
87
88EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
89return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
90algorithms respectively. The associated signature algorithm is RSA in each case.
91
92EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
93algorithms but using DSS (DSA) for the signature algorithm.
94
95EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
96returns is of zero length.
97
98EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
99return an B<EVP_MD> structure when passed a digest name, a digest NID or
100an ASN1_OBJECT structure respectively. The digest table must be initialised
101using, for example, OpenSSL_add_all_digests() for these functions to work.
102
103=head1 RETURN VALUES
104
105EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() do not return values.
106
107EVP_MD_CTX_copy() returns 1 if successful or 0 for failure.
108
109EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
110corresponding OBJECT IDENTIFIER or NID_undef if none exists.
111
112EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
113EVP_MD_CTX_block_size() and EVP_MD_block_size() return the digest or block
114size in bytes.
115
116EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
117EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
118corresponding EVP_MD structures.
119
120EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
121return either an B<EVP_MD> structure or NULL if an error occurs.
122
123=head1 NOTES
124
125The B<EVP> interface to message digests should almost always be used in
126preference to the low level interfaces. This is because the code then becomes
127transparent to the digest used and much more flexible.
128
129SHA1 is the digest of choice for new applications. The other digest algorithms
130are still in common use.
131
132=head1 EXAMPLE
133
134This example digests the data "Test Message\n" and "Hello World\n", using the
135digest name passed on the command line.
136
137 #include <stdio.h>
138 #include <openssl/evp.h>
139
140 main(int argc, char *argv[])
141 {
142 EVP_MD_CTX mdctx;
143 const EVP_MD *md;
144 char mess1[] = "Test Message\n";
145 char mess2[] = "Hello World\n";
146 unsigned char md_value[EVP_MAX_MD_SIZE];
147 int md_len, i;
148
149 OpenSSL_add_all_digests();
150
151 if(!argv[1]) {
152 printf("Usage: mdtest digestname\n");
153 exit(1);
154 }
155
156 md = EVP_get_digestbyname(argv[1]);
157
158 if(!md) {
159 printf("Unknown message digest %s\n", argv[1]);
160 exit(1);
161 }
162
163 EVP_DigestInit(&mdctx, md);
164 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
165 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
166 EVP_DigestFinal(&mdctx, md_value, &md_len);
167
168 printf("Digest is: ");
169 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
170 printf("\n");
171 }
172
173=head1 BUGS
174
175Several of the functions do not return values: maybe they should. Although the
176internal digest operations will never fail some future hardware based operations
177might.
178
179The link between digests and signing algorithms results in a situation where
180EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
181even though they are identical digests.
182
183The size of an B<EVP_MD_CTX> structure is determined at compile time: this results
184in code that must be recompiled if the size of B<EVP_MD_CTX> increases.
185
186=head1 SEE ALSO
187
188L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
189L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
190L<sha(3)|sha(3)>, L<digest(1)|digest(1)>
191
192=head1 HISTORY
193
194EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
195available in all versions of SSLeay and OpenSSL.
196
197=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod b/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod
new file mode 100644
index 0000000000..77ed4ccdba
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod
@@ -0,0 +1,224 @@
1=pod
2
3=head1 NAME
4
5EVP_EncryptInit, EVP_EncryptUpdate, EVP_EncryptFinal - EVP cipher routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12 unsigned char *key, unsigned char *iv);
13 void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18 void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
19 unsigned char *key, unsigned char *iv);
20 void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
21 int *outl, unsigned char *in, int inl);
22 int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
23 int *outl);
24
25 void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
26 unsigned char *key, unsigned char *iv, int enc);
27 void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
28 int *outl, unsigned char *in, int inl);
29 int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
30 int *outl);
31
32 void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
33
34 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
35 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
36 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
37
38 #define EVP_CIPHER_nid(e) ((e)->nid)
39 #define EVP_CIPHER_block_size(e) ((e)->block_size)
40 #define EVP_CIPHER_key_length(e) ((e)->key_len)
41 #define EVP_CIPHER_iv_length(e) ((e)->iv_len)
42
43 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
44 #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
45 #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
46 #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
47 #define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
48 #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
49 #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
50
51 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
52 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
53
54=head1 DESCRIPTION
55
56The EVP cipher routines are a high level interface to certain
57symmetric ciphers.
58
59EVP_EncryptInit() initialises a cipher context B<ctx> for encryption
60with cipher B<type>. B<type> is normally supplied by a function such
61as EVP_des_cbc() . B<key> is the symmetric key to use and B<iv> is the
62IV to use (if necessary), the actual number of bytes used for the
63key and IV depends on the cipher. It is possible to set all parameters
64to NULL except B<type> in an initial call and supply the remaining
65parameters in subsequent calls. This is normally done when the
66EVP_CIPHER_asn1_to_param() function is called to set the cipher
67parameters from an ASN1 AlgorithmIdentifier and the key from a
68different source.
69
70EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
71writes the encrypted version to B<out>. This function can be called
72multiple times to encrypt successive blocks of data. The amount
73of data written depends on the block alignment of the encrypted data:
74as a result the amount of data written may be anything from zero bytes
75to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
76room. The actual number of bytes written is placed in B<outl>.
77
78EVP_EncryptFinal() encrypts the "final" data, that is any data that
79remains in a partial block. It uses L<standard block padding|/NOTES> (aka PKCS
80padding). The encrypted final data is written to B<out> which should
81have sufficient space for one cipher block. The number of bytes written
82is placed in B<outl>. After this function is called the encryption operation
83is finished and no further calls to EVP_EncryptUpdate() should be made.
84
85EVP_DecryptInit(), EVP_DecryptUpdate() and EVP_DecryptFinal() are the
86corresponding decryption operations. EVP_DecryptFinal() will return an
87error code if the final block is not correctly formatted. The parameters
88and restrictions are identical to the encryption operations except that
89the decrypted data buffer B<out> passed to EVP_DecryptUpdate() should
90have sufficient room for (B<inl> + cipher_block_size) bytes unless the
91cipher block size is 1 in which case B<inl> bytes is sufficient.
92
93EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal() are functions
94that can be used for decryption or encryption. The operation performed
95depends on the value of the B<enc> parameter. It should be set to 1 for
96encryption and 0 for decryption.
97
98EVP_CIPHER_CTX_cleanup() clears all information from a cipher context.
99It should be called after all operations using a cipher are complete
100so sensitive information does not remain in memory.
101
102EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
103return an EVP_CIPHER structure when passed a cipher name, a NID or an
104ASN1_OBJECT structure.
105
106EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
107passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID
108value is an internal value which may not have a corresponding OBJECT
109IDENTIFIER.
110
111EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
112length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
113structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
114for all ciphers.
115
116EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
117length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
118It will return zero if the cipher does not use an IV. The constant
119B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
120
121EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
122size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
123structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
124length for all ciphers.
125
126EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
127cipher or context. This "type" is the actual NID of the cipher OBJECT
128IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
129128 bit RC2 have the same NID. If the cipher does not have an object
130identifier or does not have ASN1 support this function will return
131B<NID_undef>.
132
133EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
134an B<EVP_CIPHER_CTX> structure.
135
136EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
137on the passed cipher. This will typically include any parameters and an
138IV. The cipher IV (if any) must be set when this call is made. This call
139should be made before the cipher is actually "used" (before any
140EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
141may fail if the cipher does not have any ASN1 support.
142
143EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
144AlgorithmIdentifier "parameter". The precise effect depends on the cipher
145In the case of RC2, for example, it will set the IV and effective key length.
146This function should be called after the base cipher type is set but before
147the key is set. For example EVP_CipherInit() will be called with the IV and
148key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
149EVP_CipherInit() again with all parameters except the key set to NULL. It is
150possible for this function to fail if the cipher does not have any ASN1 support
151or the parameters cannot be set (for example the RC2 effective key length
152does not have an B<EVP_CIPHER> structure).
153
154=head1 RETURN VALUES
155
156EVP_EncryptInit(), EVP_EncryptUpdate() and EVP_EncryptFinal() do not return
157values.
158
159EVP_DecryptInit() and EVP_DecryptUpdate() do not return values.
160EVP_DecryptFinal() returns 0 if the decrypt failed or 1 for success.
161
162EVP_CipherInit() and EVP_CipherUpdate() do not return values.
163EVP_CipherFinal() returns 1 for a decryption failure or 1 for success, if
164the operation is encryption then it always returns 1.
165
166EVP_CIPHER_CTX_cleanup() does not return a value.
167
168EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
169return an B<EVP_CIPHER> structure or NULL on error.
170
171EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
172
173EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
174size.
175
176EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
177length.
178
179EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
180length or zero if the cipher does not use an IV.
181
182EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
183OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
184
185EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
186
187EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for
188success or zero for failure.
189
190=head1 NOTES
191
192Where possible the B<EVP> interface to symmetric ciphers should be used in
193preference to the low level interfaces. This is because the code then becomes
194transparent to the cipher used and much more flexible.
195
196PKCS padding works by adding B<n> padding bytes of value B<n> to make the total
197length of the encrypted data a multiple of the block size. Padding is always
198added so if the data is already a multiple of the block size B<n> will equal
199the block size. For example if the block size is 8 and 11 bytes are to be
200encrypted then 5 padding bytes of value 5 will be added.
201
202When decrypting the final block is checked to see if it has the correct form.
203
204Although the decryption operation can produce an error, it is not a strong
205test that the input data or key is correct. A random block has better than
2061 in 256 chance of being of the correct format and problems with the
207input data earlier on will not produce a final decrypt error.
208
209=head1 BUGS
210
211The current B<EVP> cipher interface is not as flexible as it should be. Only
212certain "spot" encryption algorithms can be used for ciphers which have various
213parameters associated with them (RC2, RC5 for example) this is inadequate.
214
215Several of the functions do not return error codes because the software versions
216can never fail. This is not true of hardware versions.
217
218=head1 SEE ALSO
219
220L<evp(3)|evp(3)>
221
222=head1 HISTORY
223
224=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_OpenInit.pod b/src/lib/libssl/src/doc/crypto/EVP_OpenInit.pod
new file mode 100644
index 0000000000..9707a4b399
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_OpenInit.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5EVP_OpenInit, EVP_OpenUpdate, EVP_OpenFinal - EVP envelope decryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
12 int ekl,unsigned char *iv,EVP_PKEY *priv);
13 void EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21decryption. They decrypt a public key encrypted symmetric key and
22then decrypt data using it.
23
24EVP_OpenInit() initialises a cipher context B<ctx> for decryption
25with cipher B<type>. It decrypts the encrypted symmetric key of length
26B<ekl> bytes passed in the B<ek> parameter using the private key B<priv>.
27The IV is supplied in the B<iv> parameter.
28
29EVP_OpenUpdate() and EVP_OpenFinal() have exactly the same properties
30as the EVP_DecryptUpdate() and EVP_DecryptFinal() routines, as
31documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
32page.
33
34=head1 RETURN VALUES
35
36EVP_OpenInit() returns -1 on error or an non zero integer (actually the
37recovered secret key size) if successful.
38
39EVP_SealUpdate() does not return a value.
40
41EVP_SealFinal() returns 0 if the decrypt failed or 1 for success.
42
43=head1 SEE ALSO
44
45L<evp(3)|evp(3)>,L<rand(3)|rand(3)>
46L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
47L<EVP_SealInit(3)|EVP_SealInit(3)>
48
49=head1 HISTORY
50
51=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_SealInit.pod b/src/lib/libssl/src/doc/crypto/EVP_SealInit.pod
new file mode 100644
index 0000000000..1579d110fa
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_SealInit.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
12 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
13 void EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21encryption. They generate a random key and then "envelope" it by
22using public key encryption. Data can then be encrypted using this
23key.
24
25EVP_SealInit() initialises a cipher context B<ctx> for encryption
26with cipher B<type> using a random secret key and IV supplied in
27the B<iv> parameter. B<type> is normally supplied by a function such
28as EVP_des_cbc(). The secret key is encrypted using one or more public
29keys, this allows the same encrypted data to be decrypted using any
30of the corresponding private keys. B<ek> is an array of buffers where
31the public key encrypted secret key will be written, each buffer must
32contain enough room for the corresponding encrypted key: that is
33B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual
34size of each encrypted secret key is written to the array B<ekl>. B<pubk> is
35an array of B<npubk> public keys.
36
37EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
38as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as
39documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
40page.
41
42=head1 RETURN VALUES
43
44EVP_SealInit() returns -1 on error or B<npubk> if successful.
45
46EVP_SealUpdate() and EVP_SealFinal() do not return values.
47
48=head1 NOTES
49
50Because a random secret key is generated the random number generator
51must be seeded before calling EVP_SealInit().
52
53The public key must be RSA because it is the only OpenSSL public key
54algorithm that supports key transport.
55
56Envelope encryption is the usual method of using public key encryption
57on large amounts of data, this is because public key encryption is slow
58but symmetric encryption is fast. So symmetric encryption is used for
59bulk encryption and the small random symmetric key used is transferred
60using public key encryption.
61
62=head1 SEE ALSO
63
64L<evp(3)|evp(3)>,L<rand(3)|rand(3)>
65L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
66L<EVP_OpenInit(3)|EVP_OpenInit(3)>
67
68=head1 HISTORY
69
70=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_SignInit.pod b/src/lib/libssl/src/doc/crypto/EVP_SignInit.pod
new file mode 100644
index 0000000000..bbc9203c9c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_SignInit.pod
@@ -0,0 +1,85 @@
1=pod
2
3=head1 NAME
4
5EVP_SignInit, EVP_SignUpdate, EVP_SignFinal - EVP signing functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
14
15 int EVP_PKEY_size(EVP_PKEY *pkey);
16
17=head1 DESCRIPTION
18
19The EVP signature routines are a high level interface to digital
20signatures.
21
22EVP_SignInit() initialises a signing context B<ctx> to using digest
23B<type>: this will typically be supplied by a function such as
24EVP_sha1().
25
26EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
27signature context B<ctx>. This funtion can be called several times on the
28same B<ctx> to include additional data.
29
30EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey>
31and places the signature in B<sig>. If the B<s> parameter is not NULL
32then the number of bytes of data written (i.e. the length of the signature)
33will be written to the integer at B<s>, at most EVP_PKEY_size(pkey) bytes
34will be written. After calling EVP_SignFinal() no additional calls to
35EVP_SignUpdate() can be made, but EVP_SignInit() can be called to initialiase
36a new signature operation.
37
38EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
39signature returned by EVP_SignFinal() may be smaller.
40
41=head1 RETURN VALUES
42
43EVP_SignInit() and EVP_SignUpdate() do not return values.
44
45EVP_SignFinal() returns 1 for success and 0 for failure.
46
47EVP_PKEY_size() returns the maximum size of a signature in bytes.
48
49The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 NOTES
52
53The B<EVP> interface to digital signatures should almost always be used in
54preference to the low level interfaces. This is because the code then becomes
55transparent to the algorithm used and much more flexible.
56
57Due to the link between message digests and public key algorithms the correct
58digest algorithm must be used with the correct public key type. A list of
59algorithms and associated public key algorithms appears in
60L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
61
62When signing with DSA private keys the random number generator must be seeded
63or the operation will fail. The random number generator does not need to be
64seeded for RSA signatures.
65
66=head1 BUGS
67
68Several of the functions do not return values: maybe they should. Although the
69internal digest operations will never fail some future hardware based operations
70might.
71
72=head1 SEE ALSO
73
74L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
75L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
76L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
77L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
78L<sha(3)|sha(3)>, L<digest(1)|digest(1)>
79
80=head1 HISTORY
81
82EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
83available in all versions of SSLeay and OpenSSL.
84
85=cut
diff --git a/src/lib/libssl/src/doc/crypto/EVP_VerifyInit.pod b/src/lib/libssl/src/doc/crypto/EVP_VerifyInit.pod
new file mode 100644
index 0000000000..3b5e07f4ad
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/EVP_VerifyInit.pod
@@ -0,0 +1,71 @@
1=pod
2
3=head1 NAME
4
5EVP_VerifyInit, EVP_VerifyUpdate, EVP_VerifyFinal - EVP signature verification functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey);
14
15=head1 DESCRIPTION
16
17The EVP signature verification routines are a high level interface to digital
18signatures.
19
20EVP_VerifyInit() initialises a verification context B<ctx> to using digest
21B<type>: this will typically be supplied by a function such as EVP_sha1().
22
23EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
24verification context B<ctx>. This funtion can be called several times on the
25same B<ctx> to include additional data.
26
27EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey>
28and against the B<siglen> bytes at B<sigbuf>. After calling EVP_VerifyFinal()
29no additional calls to EVP_VerifyUpdate() can be made, but EVP_VerifyInit()
30can be called to initialiase a new verification operation.
31
32=head1 RETURN VALUES
33
34EVP_VerifyInit() and EVP_VerifyUpdate() do not return values.
35
36EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if some
37other error occurred.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 NOTES
42
43The B<EVP> interface to digital signatures should almost always be used in
44preference to the low level interfaces. This is because the code then becomes
45transparent to the algorithm used and much more flexible.
46
47Due to the link between message digests and public key algorithms the correct
48digest algorithm must be used with the correct public key type. A list of
49algorithms and associated public key algorithms appears in
50L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
51
52=head1 BUGS
53
54Several of the functions do not return values: maybe they should. Although the
55internal digest operations will never fail some future hardware based operations
56might.
57
58=head1 SEE ALSO
59
60L<EVP_SignInit(3)|EVP_SignInit(3)>,
61L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
62L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
63L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
64L<sha(3)|sha(3)>, L<digest(1)|digest(1)>
65
66=head1 HISTORY
67
68EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are
69available in all versions of SSLeay and OpenSSL.
70
71=cut
diff --git a/src/lib/libssl/src/doc/crypto/OPENSSL_VERSION_NUMBER.pod b/src/lib/libssl/src/doc/crypto/OPENSSL_VERSION_NUMBER.pod
new file mode 100644
index 0000000000..b0b1058d19
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/OPENSSL_VERSION_NUMBER.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_VERSION_NUMBER, SSLeay - get OpenSSL version number
6
7=head1 SYNOPSIS
8
9 #include <openssl/opensslv.h>
10 #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnnL
11
12 #include <openssl/crypto.h>
13 long SSLeay(void);
14
15=head1 DESCRIPTION
16
17OPENSSL_VERSION_NUMBER is a numeric release version identifier:
18
19 MMNNFFRBB major minor fix final beta/patch
20
21for example
22
23 0x000904100 == 0.9.4 release
24 0x000905000 == 0.9.5 dev
25
26Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
27For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
28
29SSLeay() returns this number. The return value can be compared to the
30macro to make sure that the correct version of the library has been
31loaded, especially when using DLLs on Windows systems.
32
33=head1 RETURN VALUE
34
35The version number.
36
37=head1 SEE ALSO
38
39L<crypto(3)|crypto(3)>
40
41=head1 HISTORY
42
43SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
44OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
45
46=cut
diff --git a/src/lib/libssl/src/doc/crypto/OpenSSL_add_all_algorithms.pod b/src/lib/libssl/src/doc/crypto/OpenSSL_add_all_algorithms.pod
new file mode 100644
index 0000000000..1300fe190c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/OpenSSL_add_all_algorithms.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5OpenSSL_add_all_algorithms() - add algorithms to internal table
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void OpenSSL_add_all_algorithms(void);
12 void OpenSSL_add_all_ciphers(void);
13 void OpenSSL_add_all_digests(void);
14
15 void EVP_cleanup(void);
16
17=head1 DESCRIPTION
18
19OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
20this table to lookup ciphers via functions such as EVP_get_cipher_byname().
21
22OpenSSL_add_all_digests() adds all digest algorithms to the table.
23
24OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
25ciphers).
26
27OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
28password based encryption algorithms.
29
30EVP_cleanup() removes all ciphers and digests from the table.
31
32=head1 RETURN VALUES
33
34None of the functions return a value.
35
36=head1 NOTES
37
38A typical application will will call OpenSSL_add_all_algorithms() initially and
39EVP_cleanup() before exiting.
40
41An application does not need to add algorithms to use them explicitly, for example
42by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
43needs to lookup algorithms.
44
45The cipher and digest lookup functions are used in many parts of the library. If
46the table is not initialised several functions will misbehave and complain they
47cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
48This is a common query in the OpenSSL mailing lists.
49
50Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
51statically linked executable can be quite large. If this is important it is possible
52to just add the required ciphers and digests.
53
54=head1 BUGS
55
56Although the functions do not return error codes it is possible for them to fail.
57This will only happen as a result of a memory allocation failure so this is not
58too much of a problem in practice.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
64
65=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_add.pod b/src/lib/libssl/src/doc/crypto/RAND_add.pod
new file mode 100644
index 0000000000..0a13ec2a92
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_add.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5RAND_add, RAND_seed, RAND_screen - add entropy to the PRNG
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_seed(const void *buf, int num);
12
13 void RAND_add(const void *buf, int num, double entropy);
14
15 int RAND_status(void);
16
17 void RAND_screen(void);
18
19=head1 DESCRIPTION
20
21RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state. Thus,
22if the data at B<buf> are unpredictable to an adversary, this
23increases the uncertainty about the state and makes the PRNG output
24less predictable. Suitable input comes from user interaction (random
25key presses, mouse movements) and certain hardware events. The
26B<entropy> argument is (the lower bound of) an estimate of how much
27randomness is contained in B<buf>, measured in bytes. Details about
28sources of randomness and how to estimate their entropy can be found
29in the literature, e.g. RFC 1750.
30
31RAND_add() may be called with sensitive data such as user entered
32passwords. The seed values cannot be recovered from the PRNG output.
33
34OpenSSL makes sure that the PRNG state is unique for each thread. On
35systems that provide C</dev/urandom>, the randomness device is used
36to seed the PRNG transparently. However, on all other systems, the
37application is responsible for seeding the PRNG by calling RAND_add(),
38L<RAND_egd(3)|RAND_egd(3)>
39or L<RAND_load_file(3)|RAND_load_file(3)>.
40
41RAND_seed() is equivalent to RAND_add() when B<num == entropy>.
42
43The RAND_screen() function is available for the convenience of Windows
44programmers. It adds the current contents of the screen to the PRNG.
45For applications that can catch Windows events, seeding the PRNG with
46the parameters of B<WM_MOUSEMOVE> events is a significantly better
47source of randomness. It should be noted that both methods cannot be
48used on servers that run without user interaction.
49
50=head1 RETURN VALUES
51
52RAND_status() returns 1 if the PRNG has been seeded with enough data,
530 otherwise.
54
55The other functions do not return values.
56
57=head1 SEE ALSO
58
59L<rand(3)|rand(3)>, L<RAND_egd(3)|RAND_egd(3)>,
60L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
61
62=head1 HISTORY
63
64RAND_seed() and RAND_screen() are available in all versions of SSLeay
65and OpenSSL. RAND_add() and RAND_status() have been added in OpenSSL
660.9.5.
67
68=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_bytes.pod b/src/lib/libssl/src/doc/crypto/RAND_bytes.pod
new file mode 100644
index 0000000000..b6ebd50527
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_bytes.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5RAND_bytes, RAND_pseudo_bytes - generate random data
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_bytes(unsigned char *buf, int num);
12
13 int RAND_pseudo_bytes(unsigned char *buf, int num);
14
15=head1 DESCRIPTION
16
17RAND_bytes() puts B<num> cryptographically strong pseudo-random bytes
18into B<buf>. An error occurs if the PRNG has not been seeded with
19enough randomness to ensure an unpredictable byte sequence.
20
21RAND_pseudo_bytes() puts B<num> pseudo-random bytes into B<buf>.
22Pseudo-random byte sequences generated by RAND_pseudo_bytes() will be
23unique if they are of sufficient length, but are not necessarily
24unpredictable. They can be used for non-cryptographic purposes and for
25certain purposes in cryptographic protocols, but usually not for key
26generation etc.
27
28=head1 RETURN VALUES
29
30RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
31obtained by L<ERR_get_error(3)|ERR_get_error(3)>. RAND_pseudo_bytes() returns 1 if the
32bytes generated are cryptographically strong, 0 otherwise. Both
33functions return -1 if they are not supported by the current RAND
34method.
35
36=head1 SEE ALSO
37
38L<rand(3)|rand(3)>, L<err(3)|err(3)>, L<RAND_add(3)|RAND_add(3)>
39
40=head1 HISTORY
41
42RAND_bytes() is available in all versions of SSLeay and OpenSSL. It
43has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
44in OpenSSL 0.9.5.
45
46=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_cleanup.pod b/src/lib/libssl/src/doc/crypto/RAND_cleanup.pod
new file mode 100644
index 0000000000..3a8f0749a8
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_cleanup.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5RAND_cleanup - erase the PRNG state
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_cleanup(void);
12
13=head1 DESCRIPTION
14
15RAND_cleanup() erases the memory used by the PRNG.
16
17=head1 RETURN VALUE
18
19RAND_cleanup() returns no value.
20
21=head1 SEE ALSO
22
23L<rand(3)|rand(3)>
24
25=head1 HISTORY
26
27RAND_cleanup() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_egd.pod b/src/lib/libssl/src/doc/crypto/RAND_egd.pod
new file mode 100644
index 0000000000..a40bd96198
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_egd.pod
@@ -0,0 +1,38 @@
1=pod
2
3=head1 NAME
4
5RAND_egd - query entropy gathering daemon
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_egd(const char *path);
12
13=head1 DESCRIPTION
14
15RAND_egd() queries the entropy gathering daemon EGD on socket B<path>.
16
17EGD is available from http://www.lothar.com/tech/crypto/ (C<perl
18Makefile.PL; make; make install> to install). It is run as B<egd>
19I<path>, where I<path> is an absolute path designating a socket. When
20RAND_egd() is called with that path as an argument, it tries to read
21random bytes that EGD has collected. The read is performed in
22non-blocking mode.
23
24=head1 RETURN VALUE
25
26RAND_egd() returns the number of bytes read from the daemon on
27success, and -1 if the connection failed or the daemon did not return
28enough data to fully seed the PRNG.
29
30=head1 SEE ALSO
31
32L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
33
34=head1 HISTORY
35
36RAND_egd() is available since OpenSSL 0.9.5.
37
38=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_load_file.pod b/src/lib/libssl/src/doc/crypto/RAND_load_file.pod
new file mode 100644
index 0000000000..8dd700ca3d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_load_file.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 const char *RAND_file_name(char *buf, int num);
12
13 int RAND_load_file(const char *filename, long max_bytes);
14
15 int RAND_write_file(const char *filename);
16
17=head1 DESCRIPTION
18
19RAND_file_name() generates a default path for the random seed
20file. B<buf> points to a buffer of size B<num> in which to store the
21filename. The seed file is $RANDFILE if that environment variable is
22set, $HOME/.rnd otherwise. If $HOME is not set either, or B<num> is
23too small for the path name, an error occurs.
24
25RAND_load_file() reads a number of bytes from file B<filename> and
26adds them to the PRNG. If B<max_bytes> is non-negative,
27up to to B<max_bytes> are read; starting with OpenSSL 0.9.5,
28if B<max_bytes> is -1, the complete file is read.
29
30RAND_write_file() writes a number of random bytes (currently 1024) to
31file B<filename> which can be used to initialize the PRNG by calling
32RAND_load_file() in a later session.
33
34=head1 RETURN VALUES
35
36RAND_load_file() returns the number of bytes read.
37
38RAND_write_file() returns the number of bytes written, and -1 if the
39bytes written were generated without appropriate seed.
40
41RAND_file_name() returns a pointer to B<buf> on success, and NULL on
42error.
43
44=head1 SEE ALSO
45
46L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
47
48=head1 HISTORY
49
50RAND_load_file(), RAND_write_file() and RAND_file_name() are available in
51all versions of SSLeay and OpenSSL.
52
53=cut
diff --git a/src/lib/libssl/src/doc/crypto/RAND_set_rand_method.pod b/src/lib/libssl/src/doc/crypto/RAND_set_rand_method.pod
new file mode 100644
index 0000000000..466e9b8767
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RAND_set_rand_method.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_set_rand_method(RAND_METHOD *meth);
12
13 RAND_METHOD *RAND_get_rand_method(void);
14
15 RAND_METHOD *RAND_SSLeay(void);
16
17=head1 DESCRIPTION
18
19A B<RAND_METHOD> specifies the functions that OpenSSL uses for random
20number generation. By modifying the method, alternative
21implementations such as hardware RNGs may be used. Initially, the
22default is to use the OpenSSL internal implementation. RAND_SSLeay()
23returns a pointer to that method.
24
25RAND_set_rand_method() sets the RAND method to B<meth>.
26RAND_get_rand_method() returns a pointer to the current method.
27
28=head1 THE RAND_METHOD STRUCTURE
29
30 typedef struct rand_meth_st
31 {
32 void (*seed)(const void *buf, int num);
33 int (*bytes)(unsigned char *buf, int num);
34 void (*cleanup)(void);
35 void (*add)(const void *buf, int num, int entropy);
36 int (*pseudorand)(unsigned char *buf, int num);
37 } RAND_METHOD;
38
39The components point to the implementation of RAND_seed(),
40RAND_bytes(), RAND_cleanup(), RAND_add() and RAND_pseudo_rand().
41Each component may be NULL if the function is not implemented.
42
43=head1 RETURN VALUES
44
45RAND_set_rand_method() returns no value. RAND_get_rand_method() and
46RAND_SSLeay() return pointers to the respective methods.
47
48=head1 SEE ALSO
49
50L<rand(3)|rand(3)>
51
52=head1 HISTORY
53
54RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
55available in all versions of OpenSSL.
56
57=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_blinding_on.pod b/src/lib/libssl/src/doc/crypto/RSA_blinding_on.pod
new file mode 100644
index 0000000000..fd2c69abd8
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_blinding_on.pod
@@ -0,0 +1,43 @@
1=pod
2
3=head1 NAME
4
5RSA_blinding_on, RSA_blinding_off - protect the RSA operation from timing attacks
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
12
13 void RSA_blinding_off(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA is vulnerable to timing attacks. In a setup where attackers can
18measure the time of RSA decryption or signature operations, blinding
19must be used to protect the RSA operation from that attack.
20
21RSA_blinding_on() turns blinding on for key B<rsa> and generates a
22random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
23initialized B<BN_CTX>. The random number generator must be seeded
24prior to calling RSA_blinding_on().
25
26RSA_blinding_off() turns blinding off and frees the memory used for
27the blinding factor.
28
29=head1 RETURN VALUES
30
31RSA_blinding_on() returns 1 on success, and 0 if an error occurred.
32
33RSA_blinding_off() returns no value.
34
35=head1 SEE ALSO
36
37L<rsa(3)|rsa(3)>, L<rand(3)|rand(3)>
38
39=head1 HISTORY
40
41RSA_blinding_on() and RSA_blinding_off() appeared in SSLeay 0.9.0.
42
43=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_check_key.pod b/src/lib/libssl/src/doc/crypto/RSA_check_key.pod
new file mode 100644
index 0000000000..79fed753ad
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_check_key.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5RSA_check_key - validate private RSA keys
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_check_key(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function validates RSA keys. It checks that B<p> and B<q> are
16in fact prime, and that B<n = p*q>.
17
18It also checks that B<d*e = 1 mod (p-1*q-1)>,
19and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
20
21The key's public components may not be B<NULL>.
22
23=head1 RETURN VALUE
24
25RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
26-1 is returned if an error occurs while checking the key.
27
28If the key is invalid or an error occurred, the reason code can be
29obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
30
31=head1 SEE ALSO
32
33L<rsa(3)|rsa(3)>, L<err(3)|err(3)>
34
35=head1 HISTORY
36
37RSA_check() appeared in OpenSSL 0.9.4.
38
39=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_generate_key.pod b/src/lib/libssl/src/doc/crypto/RSA_generate_key.pod
new file mode 100644
index 0000000000..fdaddbcb13
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_generate_key.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5RSA_generate_key - generate RSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA *RSA_generate_key(int num, unsigned long e,
12 void (*callback)(int,int,void *), void *cb_arg);
13
14=head1 DESCRIPTION
15
16RSA_generate_key() generates a key pair and returns it in a newly
17allocated B<RSA> structure. The pseudo-random number generator must
18be seeded prior to calling RSA_generate_key().
19
20The modulus size will be B<num> bits, and the public exponent will be
21B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22The exponent is an odd number, typically 3 or 65535.
23
24A callback function may be used to provide feedback about the
25progress of the key generation. If B<callback> is not B<NULL>, it
26will be called as follows:
27
28=over 4
29
30=item *
31
32While a random prime number is generated, it is called as
33described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
34
35=item *
36
37When the n-th randomly generated prime is rejected as not
38suitable for the key, B<callback(2, n, cb_arg)> is called.
39
40=item *
41
42When a random p has been found with p-1 relatively prime to B<e>,
43it is called as B<callback(3, 0, cb_arg)>.
44
45=back
46
47The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
48
49=head1 RETURN VALUE
50
51If key generation fails, RSA_generate_key() returns B<NULL>; the
52error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
53
54=head1 BUGS
55
56B<callback(2, x, cb_arg)> is used with two different meanings.
57
58RSA_generate_key() goes into an infinite loop for illegal input values.
59
60=head1 SEE ALSO
61
62L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_free(3)|RSA_free(3)>
63
64=head1 HISTORY
65
66The B<cb_arg> argument was added in SSLeay 0.9.0.
67
68=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_get_ex_new_index.pod b/src/lib/libssl/src/doc/crypto/RSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..920dc76325
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_get_ex_new_index.pod
@@ -0,0 +1,122 @@
1=pod
2
3=head1 NAME
4
5RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specific data to RSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int RSA_set_ex_data(RSA *r, int idx, void *arg);
17
18 void *RSA_get_ex_data(RSA *r, int idx);
19
20 int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22
23 void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
24 int idx, long argl, void *argp);
25
26 int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
27 int idx, long argl, void *argp);
28
29=head1 DESCRIPTION
30
31Several OpenSSL structures can have application specific data attached to them.
32This has several potential uses, it can be used to cache data associated with
33a structure (for example the hash of some part of the structure) or some
34additional data (for example a handle to the data in an external library).
35
36Since the application data can be anything at all it is passed and retrieved
37as a B<void *> type.
38
39The B<RSA_get_ex_new_index()> function is initially called to "register" some
40new application specific data. It takes three optional function pointers which
41are called when the parent structure (in this case an RSA structure) is
42initially created, when it is copied and when it is freed up. If any or all of
43these function pointer arguments are not used they should be set to NULL. The
44precise manner in which these function pointers are called is described in more
45detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
46parameters which will be passed to the supplied functions but which otherwise
47have no special meaning. It returns an B<index> which should be stored
48(typically in a static variable) and passed used in the B<idx> parameter in
49the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
50will return an index greater than any previously returned, this is important
51because the optional functions are called in order of increasing index value.
52
53B<RSA_set_ex_data()> is used to set application specific data, the data is
54supplied in the B<arg> parameter and its precise meaning is up to the
55application.
56
57B<RSA_get_ex_data()> is used to retrieve application specific data. The data
58is returned to the application, this will be the same value as supplied to
59a previous B<RSA_set_ex_data()> call.
60
61B<new_func()> is called when a structure is initially allocated (for example
62with B<RSA_new()>. The parent structure members will not have any meaningful
63values at this point. This function will typically be used to allocate any
64application specific structure.
65
66B<free_func()> is called when a structure is being freed up. The dynamic parent
67structure members should not be accessed because they will be freed up when
68this function is called.
69
70B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
71pointer to the parent RSA structure. B<ptr> is a the application specific data
72(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
73B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
74B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
75it. The B<idx> parameter is the index: this will be the same value returned by
76B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
77the B<argl> and B<argp> parameters are the values originally passed to the same
78corresponding parameters when B<RSA_get_ex_new_index()> was called.
79
80B<dup_func()> is called when a structure is being copied. Pointers to the
81destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
82B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
83the source application data when the function is called, when the function returns
84the value is copied to the destination: the application can thus modify the data
85pointed to by B<from_d> and have different values in the source and destination.
86The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
87and B<free_func()>.
88
89=head1 RETURN VALUES
90
91B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
92index value).
93
94B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
95
96B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
97be valid application data but currently it can only fail if given an invalid B<idx>
98parameter.
99
100B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
101
102On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
103
104=head1 BUGS
105
106B<dup_func()> is currently never called.
107
108The return value of B<new_func()> is ignored.
109
110The B<new_func()> function isn't very useful because no meaningful values are
111present in the parent RSA structure when it is called.
112
113=head1 SEE ALSO
114
115L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
116
117=head1 HISTORY
118
119RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
120available since SSLeay 0.9.0.
121
122=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_new.pod b/src/lib/libssl/src/doc/crypto/RSA_new.pod
new file mode 100644
index 0000000000..f16490ea6a
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_new.pod
@@ -0,0 +1,38 @@
1=pod
2
3=head1 NAME
4
5RSA_new, RSA_free - allocate and free RSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12
13 void RSA_free(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA_new() allocates and initializes an B<RSA> structure.
18
19RSA_free() frees the B<RSA> structure and its components. The key is
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, RSA_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28RSA_free() returns no value.
29
30=head1 SEE ALSO
31
32L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_generate_key(3)|RSA_generate_key(3)>
33
34=head1 HISTORY
35
36RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
37
38=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_padding_add_PKCS1_type_1.pod b/src/lib/libssl/src/doc/crypto/RSA_padding_add_PKCS1_type_1.pod
new file mode 100644
index 0000000000..b8f678fe72
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_padding_add_PKCS1_type_1.pod
@@ -0,0 +1,124 @@
1=pod
2
3=head1 NAME
4
5RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
6RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
7RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
8RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
9RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
10padding
11
12=head1 SYNOPSIS
13
14 #include <openssl/rsa.h>
15
16 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
17 unsigned char *f, int fl);
18
19 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
20 unsigned char *f, int fl, int rsa_len);
21
22 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
23 unsigned char *f, int fl);
24
25 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
26 unsigned char *f, int fl, int rsa_len);
27
28 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
29 unsigned char *f, int fl, unsigned char *p, int pl);
30
31 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
32 unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
33
34 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
35 unsigned char *f, int fl);
36
37 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
38 unsigned char *f, int fl, int rsa_len);
39
40 int RSA_padding_add_none(unsigned char *to, int tlen,
41 unsigned char *f, int fl);
42
43 int RSA_padding_check_none(unsigned char *to, int tlen,
44 unsigned char *f, int fl, int rsa_len);
45
46=head1 DESCRIPTION
47
48The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
49decrypt, sign and verify functions. Normally they should not be called
50from application programs.
51
52However, they can also be called directly to implement padding for other
53asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
54RSA_padding_check_PKCS1_OAEP() may be used in an application combined
55with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
56parameter.
57
58RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
59B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
60does not meet the size requirements of the encoding method.
61
62The following encoding methods are implemented:
63
64=over 4
65
66=item PKCS1_type_1
67
68PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
69
70=item PKCS1_type_2
71
72PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
73
74=item PKCS1_OAEP
75
76PKCS #1 v2.0 EME-OAEP
77
78=item SSLv23
79
80PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
81
82=item none
83
84simply copy the data
85
86=back
87
88The random number generator must be seeded prior to calling
89RSA_padding_add_xxx().
90
91RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
92a valid encoding for a B<rsa_len> byte RSA key in the respective
93encoding method and stores the recovered data of at most B<tlen> bytes
94(for B<RSA_NO_PADDING>: of size B<tlen>)
95at B<to>.
96
97For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
98of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
99
100=head1 RETURN VALUES
101
102The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
103The RSA_padding_check_xxx() functions return the length of the
104recovered data, -1 on error. Error codes can be obtained by calling
105L<ERR_get_error(3)|ERR_get_error(3)>.
106
107=head1 SEE ALSO
108
109L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
110L<RSA_private_decrypt(3)|RSA_private_decrypt(3)>,
111L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
112
113=head1 HISTORY
114
115RSA_padding_add_PKCS1_type_1(), RSA_padding_check_PKCS1_type_1(),
116RSA_padding_add_PKCS1_type_2(), RSA_padding_check_PKCS1_type_2(),
117RSA_padding_add_SSLv23(), RSA_padding_check_SSLv23(),
118RSA_padding_add_none() and RSA_padding_check_none() appeared in
119SSLeay 0.9.0.
120
121RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP() were
122added in OpenSSL 0.9.2b.
123
124=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_print.pod b/src/lib/libssl/src/doc/crypto/RSA_print.pod
new file mode 100644
index 0000000000..dd968a5274
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_print.pod
@@ -0,0 +1,48 @@
1=pod
2
3=head1 NAME
4
5RSA_print, RSA_print_fp, DHparams_print, DHparams_print_fp - print
6cryptographic parameters
7
8=head1 SYNOPSIS
9
10 #include <openssl/rsa.h>
11
12 int RSA_print(BIO *bp, RSA *x, int offset);
13 int RSA_print_fp(FILE *fp, RSA *x, int offset);
14
15 #include <openssl/dsa.h>
16
17 int DSAparams_print(BIO *bp, DSA *x);
18 int DSAparams_print_fp(FILE *fp, DSA *x);
19 int DSA_print(BIO *bp, DSA *x, int offset);
20 int DSA_print_fp(FILE *fp, DSA *x, int offset);
21
22 #include <openssl/dh.h>
23
24 int DHparams_print(BIO *bp, DH *x);
25 int DHparams_print_fp(FILE *fp, DH *x);
26
27=head1 DESCRIPTION
28
29A human-readable hexadecimal output of the components of the RSA
30key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
31
32The output lines are indented by B<offset> spaces.
33
34=head1 RETURN VALUES
35
36These functions return 1 on success, 0 on error.
37
38=head1 SEE ALSO
39
40L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
41
42=head1 HISTORY
43
44RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
45DH_print_fp() are available in all versions of SSLeay and OpenSSL.
46DSAparams_print() and DSAparams_print_pf() were added in SSLeay 0.8.
47
48=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_private_encrypt.pod b/src/lib/libssl/src/doc/crypto/RSA_private_encrypt.pod
new file mode 100644
index 0000000000..6861a98a10
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_private_encrypt.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5RSA_private_encrypt, RSA_public_decrypt - low level signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_private_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_public_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19These functions handle RSA signatures at a low level.
20
21RSA_private_encrypt() signs the B<flen> bytes at B<from> (usually a
22message digest with an algorithm identifier) using the private key
23B<rsa> and stores the signature in B<to>. B<to> must point to
24B<RSA_size(rsa)> bytes of memory.
25
26B<padding> denotes one of the following modes:
27
28=over 4
29
30=item RSA_PKCS1_PADDING
31
32PKCS #1 v1.5 padding. This function does not handle the
33B<algorithmIdentifier> specified in PKCS #1. When generating or
34verifying PKCS #1 signatures, L<RSA_sign(3)|RSA_sign(3)> and L<RSA_verify(3)|RSA_verify(3)> should be
35used.
36
37=item RSA_NO_PADDING
38
39Raw RSA signature. This mode should I<only> be used to implement
40cryptographically sound padding modes in the application code.
41Signing user data directly with RSA is insecure.
42
43=back
44
45RSA_public_decrypt() recovers the message digest from the B<flen>
46bytes long signature at B<from> using the signer's public key
47B<rsa>. B<to> must point to a memory section large enough to hold the
48message digest (which is smaller than B<RSA_size(rsa) -
4911>). B<padding> is the padding mode that was used to sign the data.
50
51=head1 RETURN VALUES
52
53RSA_private_encrypt() returns the size of the signature (i.e.,
54RSA_size(rsa)). RSA_public_decrypt() returns the size of the
55recovered message digest.
56
57On error, -1 is returned; the error codes can be
58obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
59
60=head1 SEE ALSO
61
62L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
63
64=head1 HISTORY
65
66The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
67available since SSLeay 0.9.0.
68
69=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_public_encrypt.pod b/src/lib/libssl/src/doc/crypto/RSA_public_encrypt.pod
new file mode 100644
index 0000000000..910c4752b8
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_public_encrypt.pod
@@ -0,0 +1,86 @@
1=pod
2
3=head1 NAME
4
5RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_public_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_private_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
20session key) using the public key B<rsa> and stores the ciphertext in
21B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
22
23B<padding> denotes one of the following modes:
24
25=over 4
26
27=item RSA_PKCS1_PADDING
28
29PKCS #1 v1.5 padding. This currently is the most widely used mode.
30
31=item RSA_PKCS1_OAEP_PADDING
32
33EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
34encoding parameter. This mode is recommended for all new applications.
35
36=item RSA_SSLV23_PADDING
37
38PKCS #1 v1.5 padding with an SSL-specific modification that denotes
39that the server is SSL3 capable.
40
41=item RSA_NO_PADDING
42
43Raw RSA encryption. This mode should I<only> be used to implement
44cryptographically sound padding modes in the application code.
45Encrypting user data directly with RSA is insecure.
46
47=back
48
49B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
50based padding modes, and less than RSA_size(B<rsa>) - 21 for
51RSA_PKCS1_OAEP_PADDING. The random number generator must be seeded
52prior to calling RSA_public_encrypt().
53
54RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
55private key B<rsa> and stores the plaintext in B<to>. B<to> must point
56to a memory section large enough to hold the decrypted data (which is
57smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
58was used to encrypt the data.
59
60=head1 RETURN VALUES
61
62RSA_public_encrypt() returns the size of the encrypted data (i.e.,
63RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
64recovered plaintext.
65
66On error, -1 is returned; the error codes can be
67obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
68
69=head1 CONFORMING TO
70
71SSL, PKCS #1 v2.0
72
73=head1 SEE ALSO
74
75L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_size(3)|RSA_size(3)>
76
77=head1 NOTES
78
79The L<RSA_PKCS1_RSAref(3)|RSA_PKCS1_RSAref(3)> method supports only the RSA_PKCS1_PADDING mode.
80
81=head1 HISTORY
82
83The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
84available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
85
86=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_set_method.pod b/src/lib/libssl/src/doc/crypto/RSA_set_method.pod
new file mode 100644
index 0000000000..deb1183a23
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_set_method.pod
@@ -0,0 +1,153 @@
1=pod
2
3=head1 NAME
4
5RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6RSA_get_method, RSA_PKCS1_SSLeay, RSA_PKCS1_RSAref,
7RSA_PKCS1_null_method, RSA_flags, RSA_new_method - select RSA method
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 void RSA_set_default_method(RSA_METHOD *meth);
14
15 RSA_METHOD *RSA_get_default_method(void);
16
17 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
18
19 RSA_METHOD *RSA_get_method(RSA *rsa);
20
21 RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23 RSA_METHOD *RSA_PKCS1_RSAref(void);
24
25 RSA_METHOD *RSA_null_method(void);
26
27 int RSA_flags(RSA *rsa);
28
29 RSA *RSA_new_method(RSA_METHOD *method);
30
31=head1 DESCRIPTION
32
33An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
34operations. By modifying the method, alternative implementations
35such as hardware accelerators may be used.
36
37Initially, the default is to use the OpenSSL internal implementation,
38unless OpenSSL was configured with the C<rsaref> or C<-DRSA_NULL>
39options. RSA_PKCS1_SSLeay() returns a pointer to that method.
40
41RSA_PKCS1_RSAref() returns a pointer to a method that uses the RSAref
42library. This is the default method in the C<rsaref> configuration;
43the function is not available in other configurations.
44RSA_null_method() returns a pointer to a method that does not support
45the RSA transformation. It is the default if OpenSSL is compiled with
46C<-DRSA_NULL>. These methods may be useful in the USA because of a
47patent on the RSA cryptosystem.
48
49RSA_set_default_method() makes B<meth> the default method for all B<RSA>
50structures created later.
51
52RSA_get_default_method() returns a pointer to the current default
53method.
54
55RSA_set_method() selects B<meth> for all operations using the key
56B<rsa>.
57
58RSA_get_method() returns a pointer to the method currently selected
59for B<rsa>.
60
61RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
62
63RSA_new_method() allocates and initializes an B<RSA> structure so that
64B<method> will be used for the RSA operations. If B<method> is B<NULL>,
65the default method is used.
66
67=head1 THE RSA_METHOD STRUCTURE
68
69 typedef struct rsa_meth_st
70 {
71 /* name of the implementation */
72 const char *name;
73
74 /* encrypt */
75 int (*rsa_pub_enc)(int flen, unsigned char *from,
76 unsigned char *to, RSA *rsa, int padding);
77
78 /* verify arbitrary data */
79 int (*rsa_pub_dec)(int flen, unsigned char *from,
80 unsigned char *to, RSA *rsa, int padding);
81
82 /* sign arbitrary data */
83 int (*rsa_priv_enc)(int flen, unsigned char *from,
84 unsigned char *to, RSA *rsa, int padding);
85
86 /* decrypt */
87 int (*rsa_priv_dec)(int flen, unsigned char *from,
88 unsigned char *to, RSA *rsa, int padding);
89
90 /* compute r0 = r0 ^ I mod rsa->n. May be NULL */
91 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
92
93 /* compute r = a ^ p mod m. May be NULL */
94 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
95 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
96
97 /* called at RSA_new */
98 int (*init)(RSA *rsa);
99
100 /* called at RSA_free */
101 int (*finish)(RSA *rsa);
102
103 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
104 * operations, even if p,q,dmp1,dmq1,iqmp
105 * are NULL
106 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
107 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
108 */
109 int flags;
110
111 char *app_data; /* ?? */
112
113 /* sign. For backward compatibility, this is used only
114 * if (flags & RSA_FLAG_SIGN_VER)
115 */
116 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
117 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
118
119 /* verify. For backward compatibility, this is used only
120 * if (flags & RSA_FLAG_SIGN_VER)
121 */
122 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
123 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
124
125 } RSA_METHOD;
126
127=head1 RETURN VALUES
128
129RSA_PKCS1_SSLeay(), RSA_PKCS1_RSAref(), RSA_PKCS1_null_method(),
130RSA_get_default_method() and RSA_get_method() return pointers to the
131respective B<RSA_METHOD>s.
132
133RSA_set_default_method() returns no value.
134
135RSA_set_method() returns a pointer to the B<RSA_METHOD> previously
136associated with B<rsa>.
137
138RSA_new_method() returns B<NULL> and sets an error code that can be
139obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
140returns a pointer to the newly allocated structure.
141
142=head1 SEE ALSO
143
144L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
145
146=head1 HISTORY
147
148RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
149RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
150well as the rsa_sign and rsa_verify components of RSA_METHOD were
151added in OpenSSL 0.9.4.
152
153=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_sign.pod b/src/lib/libssl/src/doc/crypto/RSA_sign.pod
new file mode 100644
index 0000000000..f0bf6eea1b
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_sign.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5RSA_sign, RSA_verify - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
12 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
13
14 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
16
17=head1 DESCRIPTION
18
19RSA_sign() signs the message digest B<m> of size B<m_len> using the
20private key B<rsa> as specified in PKCS #1 v2.0. It stores the
21signature in B<sigret> and the signature size in B<siglen>. B<sigret>
22must point to RSA_size(B<rsa>) bytes of memory.
23
24B<type> denotes the message digest algorithm that was used to generate
25B<m>. It usually is one of B<NID_sha1>, B<NID_ripemd160> and B<NID_md5>;
26see L<objects(3)|objects(3)> for details. If B<type> is B<NID_md5_sha1>,
27an SSL signature (MD5 and SHA1 message digests with PKCS #1 padding
28and no algorithm identifier) is created.
29
30RSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
31matches a given message digest B<m> of size B<m_len>. B<type> denotes
32the message digest algorithm that was used to generate the signature.
33B<rsa> is the signer's public key.
34
35=head1 RETURN VALUES
36
37RSA_sign() returns 1 on success, 0 otherwise. RSA_verify() returns 1
38on successful verification, 0 otherwise.
39
40The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
41
42=head1 BUGS
43
44Certain signatures with an improper algorithm identifier are accepted
45for compatibility with SSLeay 0.4.5 :-)
46
47=head1 CONFORMING TO
48
49SSL, PKCS #1 v2.0
50
51=head1 SEE ALSO
52
53L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rsa(3)|rsa(3)>,
54L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
55L<RSA_public_decrypt(3)|RSA_public_decrypt(3)>
56
57=head1 HISTORY
58
59RSA_sign() and RSA_verify() are available in all versions of SSLeay
60and OpenSSL.
61
62=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod b/src/lib/libssl/src/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod
new file mode 100644
index 0000000000..df9ceb339a
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
12 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
13 RSA *rsa);
14
15 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
16 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
17 RSA *rsa);
18
19=head1 DESCRIPTION
20
21RSA_sign_ASN1_OCTET_STRING() signs the octet string B<m> of size
22B<m_len> using the private key B<rsa> represented in DER using PKCS #1
23padding. It stores the signature in B<sigret> and the signature size
24in B<siglen>. B<sigret> must point to B<RSA_size(rsa)> bytes of
25memory.
26
27B<dummy> is ignored.
28
29The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
30
31RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
32of size B<siglen> is the DER representation of a given octet string
33B<m> of size B<m_len>. B<dummy> is ignored. B<rsa> is the signer's
34public key.
35
36=head1 RETURN VALUES
37
38RSA_sign_ASN1_OCTET_STRING() returns 1 on success, 0 otherwise.
39RSA_verify_ASN1_OCTET_STRING() returns 1 on successful verification, 0
40otherwise.
41
42The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
43
44=head1 BUGS
45
46These functions serve no recognizable purpose.
47
48=head1 SEE ALSO
49
50L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rand(3)|rand(3)>,
51L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
52L<RSA_verify(3)|RSA_verify(3)>
53
54=head1 HISTORY
55
56RSA_sign_ASN1_OCTET_STRING() and RSA_verify_ASN1_OCTET_STRING() were
57added in SSLeay 0.8.
58
59=cut
diff --git a/src/lib/libssl/src/doc/crypto/RSA_size.pod b/src/lib/libssl/src/doc/crypto/RSA_size.pod
new file mode 100644
index 0000000000..b36b4d58d5
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/RSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5RSA_size - get RSA modulus size
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_size(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function returns the RSA modulus size in bytes. It can be used to
16determine how much memory must be allocated for an RSA encrypted
17value.
18
19B<rsa-E<gt>n> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<rsa(3)|rsa(3)>
28
29=head1 HISTORY
30
31RSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libssl/src/doc/crypto/bio.pod b/src/lib/libssl/src/doc/crypto/bio.pod
new file mode 100644
index 0000000000..24f61dfb56
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/bio.pod
@@ -0,0 +1,54 @@
1=pod
2
3=head1 NAME
4
5bio - I/O abstraction
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11TBA
12
13
14=head1 DESCRIPTION
15
16A BIO is an I/O abstraction, it hides many of the underlying I/O
17details from an application. If an application uses a BIO for its
18I/O it can transparently handle SSL connections, unencrypted network
19connections and file I/O.
20
21There are two type of BIO, a source/sink BIO and a filter BIO.
22
23As its name implies a source/sink BIO is a source and/or sink of data,
24examples include a socket BIO and a file BIO.
25
26A filter BIO takes data from one BIO and passes it through to
27another, or the application. The data may be left unmodified (for
28example a message digest BIO) or translated (for example an
29encryption BIO). The effect of a filter BIO may change according
30to the I/O operation it is performing: for example an encryption
31BIO will encrypt data if it is being written to and decrypt data
32if it is being read from.
33
34BIOs can be joined together to form a chain (a single BIO is a chain
35with one component). A chain normally consist of one source/sink
36BIO and one or more filter BIOs. Data read from or written to the
37first BIO then traverses the chain to the end (normally a source/sink
38BIO).
39
40=head1 SEE ALSO
41
42L<BIO_ctrl(3)|BIO_ctrl(3)>,
43L<BIO_f_base64(3)|BIO_f_base64(3)>,
44L<BIO_f_cipher(3)|BIO_f_cipher(3)>, L<BIO_f_md(3)|BIO_f_md(3)>,
45L<BIO_f_null(3)|BIO_f_null(3)>, L<BIO_f_ssl(3)|BIO_f_ssl(3)>,
46L<BIO_find_type(3)|BIO_find_type(3)>, L<BIO_new(3)|BIO_new(3)>,
47L<BIO_new_bio_pair(3)|BIO_new_bio_pair(3)>,
48L<BIO_push(3)|BIO_push(3)>, L<BIO_read(3)|BIO_read(3)>,
49L<BIO_s_accept(3)|BIO_s_accept(3)>, L<BIO_s_bio(3)|BIO_s_bio(3)>,
50L<BIO_s_connect(3)|BIO_s_connect(3)>, L<BIO_s_fd(3)|BIO_s_fd(3)>,
51L<BIO_s_file(3)|BIO_s_file(3)>, L<BIO_s_mem(3)|BIO_s_mem(3)>,
52L<BIO_s_null(3)|BIO_s_null(3)>, L<BIO_s_socket(3)|BIO_s_socket(3)>,
53L<BIO_set_callback(3)|BIO_set_callback(3)>,
54L<BIO_should_retry(3)|BIO_should_retry(3)>
diff --git a/src/lib/libssl/src/doc/crypto/blowfish.pod b/src/lib/libssl/src/doc/crypto/blowfish.pod
new file mode 100644
index 0000000000..e8c7114311
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/blowfish.pod
@@ -0,0 +1,106 @@
1=pod
2
3=head1 NAME
4
5blowfish, BF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt,
6BF_cfb64_encrypt, BF_ofb64_encrypt, BF_options - Blowfish encryption
7
8=head1 SYNOPSIS
9
10 #include <openssl/blowfish.h>
11
12 void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
13
14 void BF_encrypt(BF_LONG *data,const BF_KEY *key);
15 void BF_decrypt(BF_LONG *data,const BF_KEY *key);
16
17 void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
18 BF_KEY *key, int enc);
19 void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
20 long length, BF_KEY *schedule, unsigned char *ivec, int enc);
21 void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
22 long length, BF_KEY *schedule, unsigned char *ivec, int *num,
23 int enc);
24 void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
25 long length, BF_KEY *schedule, unsigned char *ivec, int *num);
26 const char *BF_options(void);
27
28=head1 DESCRIPTION
29
30This library implements the Blowfish cipher, which is invented and described
31by Counterpane (see http://www.counterpane.com/blowfish/ ).
32
33Blowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
34It uses a variable size key, but typically, 128 bit (16 byte) keys are
35a considered good for strong encryption. Blowfish can be used in the same
36modes as DES (see L<des_modes(7)|des_modes(7)>). Blowfish is currently one
37of the faster block ciphers. It is quite a bit faster than DES, and much
38faster than IDEA or RC2.
39
40Blowfish consists of a key setup phase and the actual encryption or decryption
41phase.
42
43BF_set_key() sets up the B<BF_KEY> B<key> using the B<len> bytes long key
44at B<data>.
45
46BF_encrypt() and BF_decrypt() are the lowest level functions for Blowfish
47encryption. They encrypt/decrypt the first 64 bits of the vector pointed by
48B<data>, using the key B<key>. These functions should not be used unless you
49implement 'modes' of Blowfish.
50
51BF_ecb_encrypt() is the basic Blowfish encryption and decryption function.
52It encrypts or decrypts the first 64 bits of B<in> using the key B<key>,
53putting the result in B<out>. B<enc> decides if encryption (B<BF_ENCRYPT>)
54or decryption (B<BF_DECRYPT>) shall be performed. The vector pointed at by
55B<in> and B<out> must be 64 bits in length, no less. If they are larger,
56everything after the first 64 bits is ignored.
57
58The mode functions BF_cbc_encrypt(), BF_cfb64_encrypt() and BF_ofb64_encrypt()
59all operate on variable length data. They all take an initialisation vector
60B<ivec> which must be initially filled with zeros, but then just need to be
61passed along into the next call of the same function for the same message.
62BF_cbc_encrypt() operates of data that is a multiple of 8 bytes long, while
63BF_cfb64_encrypt() and BF_ofb64_encrypt() are used to encrypt an variable
64number of bytes (the amount does not have to be an exact multiple of 8). The
65purpose of the latter two is to simulate stream ciphers, and therefore, they
66need the parameter B<num>, which is a pointer to an integer where the current
67offset in B<ivec> is stored between calls. This integer must be initialised
68to zero when B<ivec> is filled with zeros.
69
70BF_cbc_encrypt() is the Cipher Block Chaining function for Blowfish. It
71encrypts or decrypts the 64 bits chunks of B<in> using the key B<schedule>,
72putting the result in B<out>. B<enc> decides if encryption (BF_ENCRYPT) or
73decryption (BF_DECRYPT) shall be performed. B<ivec> must point at an 8 byte
74long initialisation vector, which must be initially filled with zeros.
75
76BF_cfb64_encrypt() is the CFB mode for Blowfish with 64 bit feedback.
77It encrypts or decrypts the bytes in B<in> using the key B<schedule>,
78putting the result in B<out>. B<enc> decides if encryption (B<BF_ENCRYPT>)
79or decryption (B<BF_DECRYPT>) shall be performed. B<ivec> must point at an
808 byte long initialisation vector, which must be initially filled with zeros.
81B<num> must point at an integer which must be initially zero.
82
83BF_ofb64_encrypt() is the OFB mode for Blowfish with 64 bit feedback.
84It uses the same parameters as BF_cfb64_encrypt(), which must be initialised
85the same way.
86
87=head1 RETURN VALUES
88
89None of the functions presented here return any value.
90
91=head1 NOTE
92
93Applications should use the higher level functions
94L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> etc. instead of calling the
95blowfish functions directly.
96
97=head1 SEE ALSO
98
99L<des_modes(7)|des_modes(7)>
100
101=head1 HISTORY
102
103The Blowfish functions are available in all versions of SSLeay and OpenSSL.
104
105=cut
106
diff --git a/src/lib/libssl/src/doc/crypto/bn.pod b/src/lib/libssl/src/doc/crypto/bn.pod
new file mode 100644
index 0000000000..1504a1c92d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/bn.pod
@@ -0,0 +1,148 @@
1=pod
2
3=head1 NAME
4
5bn - multiprecision integer arithmetics
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_new(void);
12 void BN_free(BIGNUM *a);
13 void BN_init(BIGNUM *);
14 void BN_clear(BIGNUM *a);
15 void BN_clear_free(BIGNUM *a);
16
17 BN_CTX *BN_CTX_new(void);
18 void BN_CTX_init(BN_CTX *c);
19 void BN_CTX_free(BN_CTX *c);
20
21 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
22 BIGNUM *BN_dup(const BIGNUM *a);
23
24 int BN_num_bytes(const BIGNUM *a);
25 int BN_num_bits(const BIGNUM *a);
26 int BN_num_bits_word(BN_ULONG w);
27
28 int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
29 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
30 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
31 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
32 BN_CTX *ctx);
33 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
34 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
35 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
36 BN_CTX *ctx);
37 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
38 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
39 const BIGNUM *m, BN_CTX *ctx);
40 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
41
42 int BN_add_word(BIGNUM *a, BN_ULONG w);
43 int BN_sub_word(BIGNUM *a, BN_ULONG w);
44 int BN_mul_word(BIGNUM *a, BN_ULONG w);
45 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
46 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
47
48 int BN_cmp(BIGNUM *a, BIGNUM *b);
49 int BN_ucmp(BIGNUM *a, BIGNUM *b);
50 int BN_is_zero(BIGNUM *a);
51 int BN_is_one(BIGNUM *a);
52 int BN_is_word(BIGNUM *a, BN_ULONG w);
53 int BN_is_odd(BIGNUM *a);
54
55 int BN_zero(BIGNUM *a);
56 int BN_one(BIGNUM *a);
57 BIGNUM *BN_value_one(void);
58 int BN_set_word(BIGNUM *a, unsigned long w);
59 unsigned long BN_get_word(BIGNUM *a);
60
61 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
62 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
63
64 BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
65 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
66 int BN_is_prime(const BIGNUM *p, int nchecks,
67 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
68
69 int BN_set_bit(BIGNUM *a, int n);
70 int BN_clear_bit(BIGNUM *a, int n);
71 int BN_is_bit_set(const BIGNUM *a, int n);
72 int BN_mask_bits(BIGNUM *a, int n);
73 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
74 int BN_lshift1(BIGNUM *r, BIGNUM *a);
75 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
76 int BN_rshift1(BIGNUM *r, BIGNUM *a);
77
78 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
79 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
80 char *BN_bn2hex(const BIGNUM *a);
81 char *BN_bn2dec(const BIGNUM *a);
82 int BN_hex2bn(BIGNUM **a, const char *str);
83 int BN_dec2bn(BIGNUM **a, const char *str);
84 int BN_print(BIO *fp, const BIGNUM *a);
85 int BN_print_fp(FILE *fp, const BIGNUM *a);
86 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
87 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
88
89 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
90 BN_CTX *ctx);
91
92 BN_RECP_CTX *BN_RECP_CTX_new(void);
93 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
94 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
95 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
96 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
97 BN_RECP_CTX *recp, BN_CTX *ctx);
98
99 BN_MONT_CTX *BN_MONT_CTX_new(void);
100 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
101 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
102 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
103 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
104 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
105 BN_MONT_CTX *mont, BN_CTX *ctx);
106 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
107 BN_CTX *ctx);
108 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
109 BN_CTX *ctx);
110
111
112=head1 DESCRIPTION
113
114This library performs arithmetic operations on integers of arbitrary
115size. It was written for use in public key cryptography, such as RSA
116and Diffie-Hellman.
117
118It uses dynamic memory allocation for storing its data structures.
119That means that there is no limit on the size of the numbers
120manipulated by these functions, but return values must always be
121checked in case a memory allocation error has occurred.
122
123The basic object in this library is a B<BIGNUM>. It is used to hold a
124single large integer. This type should be considered opaque and fields
125should not be modified or accessed directly.
126
127The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
128L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
129Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
130describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
131random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
132numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
133of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
134
135=head1 SEE ALSO
136
137L<bn_internal(3)|bn_internal(3)>,
138L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
139L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
140L<BN_copy(3)|BN_copy(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
141L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
142L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
143L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
144L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
145L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
146L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
147
148=cut
diff --git a/src/lib/libssl/src/doc/crypto/bn_internal.pod b/src/lib/libssl/src/doc/crypto/bn_internal.pod
new file mode 100644
index 0000000000..5af0c791c8
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/bn_internal.pod
@@ -0,0 +1,225 @@
1=pod
2
3=head1 NAME
4
5bn_mul_words, bn_mul_add_words, bn_sqr_words, bn_div_words,
6bn_add_words, bn_sub_words, bn_mul_comba4, bn_mul_comba8,
7bn_sqr_comba4, bn_sqr_comba8, bn_cmp_words, bn_mul_normal,
8bn_mul_low_normal, bn_mul_recursive, bn_mul_part_recursive,
9bn_mul_low_recursive, bn_mul_high, bn_sqr_normal, bn_sqr_recursive,
10bn_expand, bn_wexpand, bn_expand2, bn_fix_top, bn_check_top,
11bn_print, bn_dump, bn_set_max, bn_set_high, bn_set_low - BIGNUM
12library internal functions
13
14=head1 SYNOPSIS
15
16 BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
17 BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num,
18 BN_ULONG w);
19 void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
20 BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
21 BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,
22 int num);
23 BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,
24 int num);
25
26 void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
27 void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
28 void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a);
29 void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a);
30
31 int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n);
32
33 void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b,
34 int nb);
35 void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n);
36 void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
37 BN_ULONG *tmp);
38 void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b,
39 int tn, int n, BN_ULONG *tmp);
40 void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b,
41 int n2, BN_ULONG *tmp);
42 void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l,
43 int n2, BN_ULONG *tmp);
44
45 void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp);
46 void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *tmp);
47
48 void mul(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c);
49 void mul_add(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c);
50 void sqr(BN_ULONG r0, BN_ULONG r1, BN_ULONG a);
51
52 BIGNUM *bn_expand(BIGNUM *a, int bits);
53 BIGNUM *bn_wexpand(BIGNUM *a, int n);
54 BIGNUM *bn_expand2(BIGNUM *a, int n);
55 void bn_fix_top(BIGNUM *a);
56
57 void bn_check_top(BIGNUM *a);
58 void bn_print(BIGNUM *a);
59 void bn_dump(BN_ULONG *d, int n);
60 void bn_set_max(BIGNUM *a);
61 void bn_set_high(BIGNUM *r, BIGNUM *a, int n);
62 void bn_set_low(BIGNUM *r, BIGNUM *a, int n);
63
64=head1 DESCRIPTION
65
66This page documents the internal functions used by the OpenSSL
67B<BIGNUM> implementation. They are described here to facilitate
68debugging and extending the library. They are I<not> to be used by
69applications.
70
71=head2 The BIGNUM structure
72
73 typedef struct bignum_st
74 {
75 int top; /* index of last used d (most significant word) */
76 BN_ULONG *d; /* pointer to an array of 'BITS2' bit chunks */
77 int max; /* size of the d array */
78 int neg; /* sign */
79 } BIGNUM;
80
81The big number is stored in B<d>, a malloc()ed array of B<BN_ULONG>s,
82least significant first. A B<BN_ULONG> can be either 16, 32 or 64 bits
83in size (B<BITS2>), depending on the 'number of bits' specified in
84C<openssl/bn.h>.
85
86B<max> is the size of the B<d> array that has been allocated. B<top>
87is the 'last' entry being used, so for a value of 4, bn.d[0]=4 and
88bn.top=1. B<neg> is 1 if the number is negative. When a B<BIGNUM> is
89B<0>, the B<d> field can be B<NULL> and B<top> == B<0>.
90
91Various routines in this library require the use of temporary
92B<BIGNUM> variables during their execution. Since dynamic memory
93allocation to create B<BIGNUM>s is rather expensive when used in
94conjunction with repeated subroutine calls, the B<BN_CTX> structure is
95used. This structure contains B<BN_CTX_NUM> B<BIGNUM>s, see
96L<BN_CTX_start(3)|BN_CTX_start(3)>.
97
98=head2 Low-level arithmetic operations
99
100These functions are implemented in C and for several platforms in
101assembly language:
102
103bn_mul_words(B<rp>, B<ap>, B<num>, B<w>) operates on the B<num> word
104arrays B<rp> and B<ap>. It computes B<ap> * B<w>, places the result
105in B<rp>, and returns the high word (carry).
106
107bn_mul_add_words(B<rp>, B<ap>, B<num>, B<w>) operates on the B<num>
108word arrays B<rp> and B<ap>. It computes B<ap> * B<w> + B<rp>, places
109the result in B<rp>, and returns the high word (carry).
110
111bn_sqr_words(B<rp>, B<ap>, B<n>) operates on the B<num> word array
112B<ap> and the 2*B<num> word array B<ap>. It computes B<ap> * B<ap>
113word-wise, and places the low and high bytes of the result in B<rp>.
114
115bn_div_words(B<h>, B<l>, B<d>) divides the two word number (B<h>,B<l>)
116by B<d> and returns the result.
117
118bn_add_words(B<rp>, B<ap>, B<bp>, B<num>) operates on the B<num> word
119arrays B<ap>, B<bp> and B<rp>. It computes B<ap> + B<bp>, places the
120result in B<rp>, and returns the high word (carry).
121
122bn_sub_words(B<rp>, B<ap>, B<bp>, B<num>) operates on the B<num> word
123arrays B<ap>, B<bp> and B<rp>. It computes B<ap> - B<bp>, places the
124result in B<rp>, and returns the carry (1 if B<bp> E<gt> B<ap>, 0
125otherwise).
126
127bn_mul_comba4(B<r>, B<a>, B<b>) operates on the 4 word arrays B<a> and
128B<b> and the 8 word array B<r>. It computes B<a>*B<b> and places the
129result in B<r>.
130
131bn_mul_comba8(B<r>, B<a>, B<b>) operates on the 8 word arrays B<a> and
132B<b> and the 16 word array B<r>. It computes B<a>*B<b> and places the
133result in B<r>.
134
135bn_sqr_comba4(B<r>, B<a>, B<b>) operates on the 4 word arrays B<a> and
136B<b> and the 8 word array B<r>.
137
138bn_sqr_comba8(B<r>, B<a>, B<b>) operates on the 8 word arrays B<a> and
139B<b> and the 16 word array B<r>.
140
141The following functions are implemented in C:
142
143bn_cmp_words(B<a>, B<b>, B<n>) operates on the B<n> word arrays B<a>
144and B<b>. It returns 1, 0 and -1 if B<a> is greater than, equal and
145less than B<b>.
146
147bn_mul_normal(B<r>, B<a>, B<na>, B<b>, B<nb>) operates on the B<na>
148word array B<a>, the B<nb> word array B<b> and the B<na>+B<nb> word
149array B<r>. It computes B<a>*B<b> and places the result in B<r>.
150
151bn_mul_low_normal(B<r>, B<a>, B<b>, B<n>) operates on the B<n> word
152arrays B<r>, B<a> und B<b>. It computes the B<n> low words of
153B<a>*B<b> and places the result in B<r>.
154
155bn_mul_recursive(B<r>, B<a>, B<b>, B<n2>, B<t>) operates on the B<n2>
156word arrays B<a> and B<b> and the 2*B<n2> word arrays B<r> and B<t>.
157B<n2> must be a power of 2. It computes B<a>*B<b> and places the
158result in B<r>.
159
160bn_mul_part_recursive(B<r>, B<a>, B<b>, B<tn>, B<n>, B<tmp>) operates
161on the B<n>+B<tn> word arrays B<a> and B<b> and the 4*B<n> word arrays
162B<r> and B<tmp>.
163
164bn_mul_low_recursive(B<r>, B<a>, B<b>, B<n2>, B<tmp>) operates on the
165B<n2> word arrays B<r> and B<tmp> and the B<n2>/2 word arrays B<a>
166and B<b>.
167
168bn_mul_high(B<r>, B<a>, B<b>, B<l>, B<n2>, B<tmp>) operates on the
169B<n2> word arrays B<r>, B<a>, B<b> and B<l> (?) and the 3*B<n2> word
170array B<tmp>.
171
172BN_mul() calls bn_mul_normal(), or an optimized implementation if the
173factors have the same size: bn_mul_comba8() is used if they are 8
174words long, bn_mul_recursive() if they are larger than
175B<BN_MULL_SIZE_NORMAL> and the size is an exact multiple of the word
176size, and bn_mul_part_recursive() for others that are larger than
177B<BN_MULL_SIZE_NORMAL>.
178
179bn_sqr_normal(B<r>, B<a>, B<n>, B<tmp>) operates on the B<n> word array
180B<a> and the 2*B<n> word arrays B<tmp> and B<r>.
181
182The implementations use the following macros which, depending on the
183architecture, may use "long long" C operations or inline assembler.
184They are defined in C<bn_lcl.h>.
185
186mul(B<r>, B<a>, B<w>, B<c>) computes B<w>*B<a>+B<c> and places the
187low word of the result in B<r> and the high word in B<c>.
188
189mul_add(B<r>, B<a>, B<w>, B<c>) computes B<w>*B<a>+B<r>+B<c> and
190places the low word of the result in B<r> and the high word in B<c>.
191
192sqr(B<r0>, B<r1>, B<a>) computes B<a>*B<a> and places the low word
193of the result in B<r0> and the high word in B<r1>.
194
195=head2 Size changes
196
197bn_expand() ensures that B<b> has enough space for a B<bits> bit
198number. bn_wexpand() ensures that B<b> has enough space for an
199B<n> word number. If the number has to be expanded, both macros
200call bn_expand2(), which allocates a new B<d> array and copies the
201data. They return B<NULL> on error, B<b> otherwise.
202
203The bn_fix_top() macro reduces B<a-E<gt>top> to point to the most
204significant non-zero word when B<a> has shrunk.
205
206=head2 Debugging
207
208bn_check_top() verifies that C<((a)-E<gt>top E<gt>= 0 && (a)-E<gt>top
209E<lt>= (a)-E<gt>max)>. A violation will cause the program to abort.
210
211bn_print() prints B<a> to stderr. bn_dump() prints B<n> words at B<d>
212(in reverse order, i.e. most significant word first) to stderr.
213
214bn_set_max() makes B<a> a static number with a B<max> of its current size.
215This is used by bn_set_low() and bn_set_high() to make B<r> a read-only
216B<BIGNUM> that contains the B<n> low or high words of B<a>.
217
218If B<BN_DEBUG> is not defined, bn_check_top(), bn_print(), bn_dump()
219and bn_set_max() are defined as empty macros.
220
221=head1 SEE ALSO
222
223L<bn(3)|bn(3)>
224
225=cut
diff --git a/src/lib/libssl/src/doc/crypto/buffer.pod b/src/lib/libssl/src/doc/crypto/buffer.pod
new file mode 100644
index 0000000000..7088f51bc4
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/buffer.pod
@@ -0,0 +1,73 @@
1=pod
2
3=head1 NAME
4
5BUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple
6character arrays structure
7
8=head1 SYNOPSIS
9
10 #include <openssl/buffer.h>
11
12 BUF_MEM *BUF_MEM_new(void);
13
14 void BUF_MEM_free(BUF_MEM *a);
15
16 int BUF_MEM_grow(BUF_MEM *str, int len);
17
18 char * BUF_strdup(const char *str);
19
20=head1 DESCRIPTION
21
22The buffer library handles simple character arrays. Buffers are used for
23various purposes in the library, most notably memory BIOs.
24
25The library uses the BUF_MEM structure defined in buffer.h:
26
27 typedef struct buf_mem_st
28 {
29 int length; /* current number of bytes */
30 char *data;
31 int max; /* size of buffer */
32 } BUF_MEM;
33
34B<length> is the current size of the buffer in bytes, B<max> is the amount of
35memory allocated to the buffer. There are three functions which handle these
36and one "miscellaneous" function.
37
38BUF_MEM_new() allocates a new buffer of zero size.
39
40BUF_MEM_free() frees up an already existing buffer. The data is zeroed
41before freeing up in case the buffer contains sensitive data.
42
43BUF_MEM_grow() changes the size of an already existing buffer to
44B<len>. Any data already in the buffer is preserved if it increases in
45size.
46
47BUF_strdup() copies a null terminated string into a block of allocated
48memory and returns a pointer to the allocated block.
49Unlike the standard C library strdup() this function uses Malloc() and so
50should be used in preference to the standard library strdup() because it can
51be used for memory leak checking or replacing the malloc() function.
52
53The memory allocated from BUF_strdup() should be freed up using the Free()
54function.
55
56=head1 RETURN VALUES
57
58BUF_MEM_new() returns the buffer or NULL on error.
59
60BUF_MEM_free() has no return value.
61
62BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
63
64=head1 SEE ALSO
65
66L<bio(3)|bio(3)>
67
68=head1 HISTORY
69
70BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
71versions of SSLeay and OpenSSL. BUF_strdup() was addded in SSLeay 0.8.
72
73=cut
diff --git a/src/lib/libssl/src/doc/crypto/crypto.pod b/src/lib/libssl/src/doc/crypto/crypto.pod
new file mode 100644
index 0000000000..4b9ceacd91
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/crypto.pod
@@ -0,0 +1,67 @@
1=pod
2
3=head1 NAME
4
5crypto - OpenSSL cryptographic library
6
7=head1 SYNOPSIS
8
9=head1 DESCRIPTION
10
11The OpenSSL B<crypto> library implements a wide range of cryptographic
12algorithms used in various Internet standards. The services provided
13by this library are used by the OpenSSL implementations of SSL, TLS
14and S/MIME, and they have also been used to implement SSH, OpenPGP, and
15other cryptographic standards.
16
17=head1 OVERVIEW
18
19B<libcrypto> consists of a number of sub-libraries that implement the
20individual algorithms.
21
22The functionality includes symmetric encryption, public key
23cryptography and key agreement, certificate handling, cryptographic
24hash functions and a cryptographic pseudo-random number generator.
25
26=over 4
27
28=item SYMMETRIC CIPHERS
29
30L<blowfish(3)|blowfish(3)>, L<cast(3)|cast(3)>, L<des(3)|des(3)>,
31L<idea(3)|idea(3)>, L<rc2(3)|rc2(3)>, L<rc4(3)|rc4(3)>, L<rc5(3)|rc5(3)>
32
33=item PUBLIC KEY CRYPTOGRAPHY AND KEY AGREEMENT
34
35L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rsa(3)|rsa(3)>
36
37=item CERTIFICATES
38
39L<x509(3)|x509(3)>, L<x509v3(3)|x509v3(3)>
40
41=item AUTHENTICATION CODES, HASH FUNCTIONS
42
43L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>,
44L<ripemd(3)|ripemd(3)>, L<sha(3)|sha(3)>
45
46=item AUXILIARY FUNCTIONS
47
48L<err(3)|err(3)>, L<threads(3)|threads(3)>, L<rand(3)|rand(3)>
49
50=item INPUT/OUTPUT, DATA ENCODING
51
52L<asn1(3)|asn1(3)>, L<bio(3)|bio(3)>, L<evp(3)|evp(3)>, L<pem(3)|pem(3)>,
53L<pkcs7(3)|pkcs7(3)>, L<pkcs12(3)|pkcs12(3)>
54
55=item INTERNAL FUNCTIONS
56
57L<bn(3)|bn(3)>, L<buffer(3)|buffer(3)>, L<lhash(3)|lhash(3)>,
58L<objects(3)|objects(3)>, L<stack(3)|stack(3)>,
59L<txt_db(3)|txt_db(3)>
60
61=back
62
63=head1 SEE ALSO
64
65L<openssl(1)|openssl(1)>, L<ssl(3)|ssl(3)>
66
67=cut
diff --git a/src/lib/libssl/src/doc/crypto/d2i_DHparams.pod b/src/lib/libssl/src/doc/crypto/d2i_DHparams.pod
new file mode 100644
index 0000000000..a6d1743d39
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/d2i_DHparams.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5d2i_DHparams, i2d_DHparams - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *d2i_DHparams(DH **a, unsigned char **pp, long length);
12 int i2d_DHparams(DH *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16...
17
18=head1 RETURN VALUES
19
20...
21
22=head1 SEE ALSO
23
24...
25
26=head1 HISTORY
27
28...
29
30=cut
diff --git a/src/lib/libssl/src/doc/crypto/d2i_RSAPublicKey.pod b/src/lib/libssl/src/doc/crypto/d2i_RSAPublicKey.pod
new file mode 100644
index 0000000000..ff4d0d57db
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/d2i_RSAPublicKey.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Netscape_RSA, d2i_Netscape_RSA - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
12
13 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
14
15 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
16
17 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
18
19 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
20
21 RSA * d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
22
23=head1 DESCRIPTION
24
25...
26
27=head1 RETURN VALUES
28
29...
30
31=head1 SEE ALSO
32
33...
34
35=head1 HISTORY
36
37...
38
39=cut
diff --git a/src/lib/libssl/src/doc/crypto/des.pod b/src/lib/libssl/src/doc/crypto/des.pod
new file mode 100644
index 0000000000..c553210ef2
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/des.pod
@@ -0,0 +1,376 @@
1=pod
2
3=head1 NAME
4
5des_random_key, des_set_key, des_key_sched, des_set_key_checked,
6des_set_key_unchecked, des_set_odd_parity, des_is_weak_key,
7des_ecb_encrypt, des_ecb2_encrypt, des_ecb3_encrypt, des_ncbc_encrypt,
8des_cfb_encrypt, des_ofb_encrypt, des_pcbc_encrypt, des_cfb64_encrypt,
9des_ofb64_encrypt, des_xcbc_encrypt, des_ede2_cbc_encrypt,
10des_ede2_cfb64_encrypt, des_ede2_ofb64_encrypt, des_ede3_cbc_encrypt,
11des_ede3_cbcm_encrypt, des_ede3_cfb64_encrypt, des_ede3_ofb64_encrypt,
12des_read_password, des_read_2passwords, des_read_pw_string,
13des_cbc_cksum, des_quad_cksum, des_string_to_key, des_string_to_2keys,
14des_fcrypt, des_crypt, des_enc_read, des_enc_write - DES encryption
15
16=head1 SYNOPSIS
17
18 #include <openssl/des.h>
19
20 void des_random_key(des_cblock *ret);
21
22 int des_set_key(const_des_cblock *key, des_key_schedule schedule);
23 int des_key_sched(const_des_cblock *key, des_key_schedule schedule);
24 int des_set_key_checked(const_des_cblock *key,
25 des_key_schedule schedule);
26 void des_set_key_unchecked(const_des_cblock *key,
27 des_key_schedule schedule);
28
29 void des_set_odd_parity(des_cblock *key);
30 int des_is_weak_key(const_des_cblock *key);
31
32 void des_ecb_encrypt(const_des_cblock *input, des_cblock *output,
33 des_key_schedule ks, int enc);
34 void des_ecb2_encrypt(const_des_cblock *input, des_cblock *output,
35 des_key_schedule ks1, des_key_schedule ks2, int enc);
36 void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
37 des_key_schedule ks1, des_key_schedule ks2,
38 des_key_schedule ks3, int enc);
39
40 void des_ncbc_encrypt(const unsigned char *input, unsigned char *output,
41 long length, des_key_schedule schedule, des_cblock *ivec,
42 int enc);
43 void des_cfb_encrypt(const unsigned char *in, unsigned char *out,
44 int numbits, long length, des_key_schedule schedule,
45 des_cblock *ivec, int enc);
46 void des_ofb_encrypt(const unsigned char *in, unsigned char *out,
47 int numbits, long length, des_key_schedule schedule,
48 des_cblock *ivec);
49 void des_pcbc_encrypt(const unsigned char *input, unsigned char *output,
50 long length, des_key_schedule schedule, des_cblock *ivec,
51 int enc);
52 void des_cfb64_encrypt(const unsigned char *in, unsigned char *out,
53 long length, des_key_schedule schedule, des_cblock *ivec,
54 int *num, int enc);
55 void des_ofb64_encrypt(const unsigned char *in, unsigned char *out,
56 long length, des_key_schedule schedule, des_cblock *ivec,
57 int *num);
58
59 void des_xcbc_encrypt(const unsigned char *input, unsigned char *output,
60 long length, des_key_schedule schedule, des_cblock *ivec,
61 const_des_cblock *inw, const_des_cblock *outw, int enc);
62
63 void des_ede2_cbc_encrypt(const unsigned char *input,
64 unsigned char *output, long length, des_key_schedule ks1,
65 des_key_schedule ks2, des_cblock *ivec, int enc);
66 void des_ede2_cfb64_encrypt(const unsigned char *in,
67 unsigned char *out, long length, des_key_schedule ks1,
68 des_key_schedule ks2, des_cblock *ivec, int *num, int enc);
69 void des_ede2_ofb64_encrypt(const unsigned char *in,
70 unsigned char *out, long length, des_key_schedule ks1,
71 des_key_schedule ks2, des_cblock *ivec, int *num);
72
73 void des_ede3_cbc_encrypt(const unsigned char *input,
74 unsigned char *output, long length, des_key_schedule ks1,
75 des_key_schedule ks2, des_key_schedule ks3, des_cblock *ivec,
76 int enc);
77 void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
78 long length, des_key_schedule ks1, des_key_schedule ks2,
79 des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2,
80 int enc);
81 void des_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
82 long length, des_key_schedule ks1, des_key_schedule ks2,
83 des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
84 void des_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
85 long length, des_key_schedule ks1,
86 des_key_schedule ks2, des_key_schedule ks3,
87 des_cblock *ivec, int *num);
88
89 int des_read_password(des_cblock *key, const char *prompt, int verify);
90 int des_read_2passwords(des_cblock *key1, des_cblock *key2,
91 const char *prompt, int verify);
92 int des_read_pw_string(char *buf, int length, const char *prompt,
93 int verify);
94
95 DES_LONG des_cbc_cksum(const unsigned char *input, des_cblock *output,
96 long length, des_key_schedule schedule,
97 const_des_cblock *ivec);
98 DES_LONG des_quad_cksum(const unsigned char *input, des_cblock output[],
99 long length, int out_count, des_cblock *seed);
100 void des_string_to_key(const char *str, des_cblock *key);
101 void des_string_to_2keys(const char *str, des_cblock *key1,
102 des_cblock *key2);
103
104 char *des_fcrypt(const char *buf, const char *salt, char *ret);
105 char *des_crypt(const char *buf, const char *salt);
106 char *crypt(const char *buf, const char *salt);
107
108 int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
109 des_cblock *iv);
110 int des_enc_write(int fd, const void *buf, int len,
111 des_key_schedule sched, des_cblock *iv);
112
113=head1 DESCRIPTION
114
115This library contains a fast implementation of the DES encryption
116algorithm.
117
118There are two phases to the use of DES encryption. The first is the
119generation of a I<des_key_schedule> from a key, the second is the
120actual encryption. A DES key is of type I<des_cblock>. This type is
121consists of 8 bytes with odd parity. The least significant bit in
122each byte is the parity bit. The key schedule is an expanded form of
123the key; it is used to speed the encryption process.
124
125des_random_key() generates a random key. The PRNG must be seeded
126prior to using this function (see L<rand(3)|rand(3)>; for backward
127compatibility the function des_random_seed() is available as well).
128If the PRNG could not generate a secure key, 0 is returned. In
129earlier versions of the library, des_random_key() did not generate
130secure keys.
131
132Before a DES key can be used, it must be converted into the
133architecture dependant I<des_key_schedule> via the
134des_set_key_checked() or des_set_key_unchecked() function.
135
136des_set_key_checked() will check that the key passed is of odd parity
137and is not a week or semi-weak key. If the parity is wrong, then -1
138is returned. If the key is a weak key, then -2 is returned. If an
139error is returned, the key schedule is not generated.
140
141des_set_key() (called des_key_sched() in the MIT library) works like
142des_set_key_checked() if the I<des_check_key> flag is non-zero,
143otherwise like des_set_key_unchecked(). These functions are available
144for compatibility; it is recommended to use a function that does not
145depend on a global variable.
146
147des_set_odd_parity() (called des_fixup_key_parity() in the MIT
148library) sets the parity of the passed I<key> to odd.
149
150des_is_weak_key() returns 1 is the passed key is a weak key, 0 if it
151is ok. The probability that a randomly generated key is weak is
1521/2^52, so it is not really worth checking for them.
153
154The following routines mostly operate on an input and output stream of
155I<des_cblock>s.
156
157des_ecb_encrypt() is the basic DES encryption routine that encrypts or
158decrypts a single 8-byte I<des_cblock> in I<electronic code book>
159(ECB) mode. It always transforms the input data, pointed to by
160I<input>, into the output data, pointed to by the I<output> argument.
161If the I<encrypt> argument is non-zero (DES_ENCRYPT), the I<input>
162(cleartext) is encrypted in to the I<output> (ciphertext) using the
163key_schedule specified by the I<schedule> argument, previously set via
164I<des_set_key>. If I<encrypt> is zero (DES_DECRYPT), the I<input> (now
165ciphertext) is decrypted into the I<output> (now cleartext). Input
166and output may overlap. des_ecb_encrypt() does not return a value.
167
168des_ecb3_encrypt() encrypts/decrypts the I<input> block by using
169three-key Triple-DES encryption in ECB mode. This involves encrypting
170the input with I<ks1>, decrypting with the key schedule I<ks2>, and
171then encrypting with I<ks3>. This routine greatly reduces the chances
172of brute force breaking of DES and has the advantage of if I<ks1>,
173I<ks2> and I<ks3> are the same, it is equivalent to just encryption
174using ECB mode and I<ks1> as the key.
175
176The macro des_ecb2_encrypt() is provided to perform two-key Triple-DES
177encryption by using I<ks1> for the final encryption.
178
179des_ncbc_encrypt() encrypts/decrypts using the I<cipher-block-chaining>
180(CBC) mode of DES. If the I<encrypt> argument is non-zero, the
181routine cipher-block-chain encrypts the cleartext data pointed to by
182the I<input> argument into the ciphertext pointed to by the I<output>
183argument, using the key schedule provided by the I<schedule> argument,
184and initialization vector provided by the I<ivec> argument. If the
185I<length> argument is not an integral multiple of eight bytes, the
186last block is copied to a temporary area and zero filled. The output
187is always an integral multiple of eight bytes.
188
189des_xcbc_encrypt() is RSA's DESX mode of DES. It uses I<inw> and
190I<outw> to 'whiten' the encryption. I<inw> and I<outw> are secret
191(unlike the iv) and are as such, part of the key. So the key is sort
192of 24 bytes. This is much better than CBC DES.
193
194des_ede3_cbc_encrypt() implements outer triple CBC DES encryption with
195three keys. This means that each DES operation inside the CBC mode is
196really an C<C=E(ks3,D(ks2,E(ks1,M)))>. This mode is used by SSL.
197
198The des_ede2_cbc_encrypt() macro implements two-key Triple-DES by
199reusing I<ks1> for the final encryption. C<C=E(ks1,D(ks2,E(ks1,M)))>.
200This form of Triple-DES is used by the RSAREF library.
201
202des_pcbc_encrypt() encrypt/decrypts using the propagating cipher block
203chaing mode used by Kerberos v4. Its parameters are the same as
204des_ncbc_encrypt().
205
206des_cfb_encrypt() encrypt/decrypts using cipher feedback mode. This
207method takes an array of characters as input and outputs and array of
208characters. It does not require any padding to 8 character groups.
209Note: the I<ivec> variable is changed and the new changed value needs to
210be passed to the next call to this function. Since this function runs
211a complete DES ECB encryption per I<numbits>, this function is only
212suggested for use when sending small numbers of characters.
213
214des_cfb64_encrypt()
215implements CFB mode of DES with 64bit feedback. Why is this
216useful you ask? Because this routine will allow you to encrypt an
217arbitrary number of bytes, no 8 byte padding. Each call to this
218routine will encrypt the input bytes to output and then update ivec
219and num. num contains 'how far' we are though ivec. If this does
220not make much sense, read more about cfb mode of DES :-).
221
222des_ede3_cfb64_encrypt() and des_ede2_cfb64_encrypt() is the same as
223des_cfb64_encrypt() except that Triple-DES is used.
224
225des_ofb_encrypt() encrypts using output feedback mode. This method
226takes an array of characters as input and outputs and array of
227characters. It does not require any padding to 8 character groups.
228Note: the I<ivec> variable is changed and the new changed value needs to
229be passed to the next call to this function. Since this function runs
230a complete DES ECB encryption per numbits, this function is only
231suggested for use when sending small numbers of characters.
232
233des_ofb64_encrypt() is the same as des_cfb64_encrypt() using Output
234Feed Back mode.
235
236des_ede3_ofb64_encrypt() and des_ede2_ofb64_encrypt() is the same as
237des_ofb64_encrypt(), using Triple-DES.
238
239The following functions are included in the DES library for
240compatibility with the MIT Kerberos library. des_read_pw_string()
241is also available under the name EVP_read_pw_string().
242
243des_read_pw_string() writes the string specified by I<prompt> to
244standarf output, turns echo off and reads in input string from the
245terminal. The string is returned in I<buf>, which must have space for
246at least I<length> bytes. If I<verify> is set, the user is asked for
247the password twice and unless the two copies match, an error is
248returned. A return code of -1 indicates a system error, 1 failure due
249to use interaction, and 0 is success.
250
251des_read_password() does the same and converts the password to a DES
252key by calling des_string_to_key(); des_read_2password() operates in
253the same way as des_read_password() except that it generates two keys
254by using the des_string_to_2key() function. des_string_to_key() is
255available for backward compatibility with the MIT library. New
256applications should use a cryptographic hash function. The same
257applies for des_string_to_2key().
258
259des_cbc_cksum() produces an 8 byte checksum based on the input stream
260(via CBC encryption). The last 4 bytes of the checksum are returned
261and the complete 8 bytes are placed in I<output>. This function is
262used by Kerberos v4. Other applications should use
263L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead.
264
265des_quad_cksum() is a Kerberos v4 function. It returns a 4 byte
266checksum from the input bytes. The algorithm can be iterated over the
267input, depending on I<out_count>, 1, 2, 3 or 4 times. If I<output> is
268non-NULL, the 8 bytes generated by each pass are written into
269I<output>.
270
271The following are DES-based tranformations:
272
273des_fcrypt() is a fast version of the unix crypt(3) function. This
274version takes only a small amount of space relative to other fast
275crypt() implementations. This is different to the normal crypt in
276that the third parameter is the buffer that the return value is
277written into. It needs to be at least 14 bytes long. This function
278is thread safe, unlike the normal crypt.
279
280des_crypt() is a faster replacement for the normal system crypt().
281This function calls des_fcrypt() with a static array passed as the
282third parameter. This emulates the normal non-thread safe semantics
283of crypt(3).
284
285des_enc_write() writes I<len> bytes to file descriptor I<fd> from
286buffer I<buf>. The data is encrypted via I<pcbc_encrypt> (default)
287using I<sched> for the key and I<iv> as a starting vector. The actual
288data send down I<fd> consists of 4 bytes (in network byte order)
289containing the length of the following encrypted data. The encrypted
290data then follows, padded with random data out to a multiple of 8
291bytes.
292
293des_enc_read() is used to read I<len> bytes from file descriptor
294I<fd> into buffer I<buf>. The data being read from I<fd> is assumed to
295have come from des_enc_write() and is decrypted using I<sched> for
296the key schedule and I<iv> for the initial vector.
297
298B<Warning:> The data format used by des_enc_write() and des_enc_read()
299has a cryptographic weakness: When asked to write more than MAXWRITE
300bytes, des_enc_write() will split the data into several chunks that
301are all encrypted using the same IV. So don't use these functions
302unless you are sure you know what you do (in which case you might not
303want to use them anyway). They cannot handle non-blocking sockets.
304des_enc_read() uses an internal state and thus cannot be used on
305multiple files.
306
307I<des_rw_mode> is used to specify the encryption mode to use with
308des_enc_read() and des_end_write(). If set to I<DES_PCBC_MODE> (the
309default), des_pcbc_encrypt is used. If set to I<DES_CBC_MODE>
310des_cbc_encrypt is used.
311
312=head1 NOTES
313
314Single-key DES is insecure due to its short key size. ECB mode is
315not suitable for most applications; see L<des_modes(7)|des_modes(7)>.
316
317The L<evp(3)|evp(3)> library provides higher-level encryption functions.
318
319=head1 BUGS
320
321des_3cbc_encrypt() is flawed and must not be used in applications.
322
323des_cbc_encrypt() does not modify B<ivec>; use des_ncbc_encrypt()
324instead.
325
326des_cfb_encrypt() and des_ofb_encrypt() operates on input of 8 bits.
327What this means is that if you set numbits to 12, and length to 2, the
328first 12 bits will come from the 1st input byte and the low half of
329the second input byte. The second 12 bits will have the low 8 bits
330taken from the 3rd input byte and the top 4 bits taken from the 4th
331input byte. The same holds for output. This function has been
332implemented this way because most people will be using a multiple of 8
333and because once you get into pulling bytes input bytes apart things
334get ugly!
335
336des_read_pw_string() is the most machine/OS dependent function and
337normally generates the most problems when porting this code.
338
339=head1 CONFORMING TO
340
341ANSI X3.106
342
343The B<des> library was written to be source code compatible with
344the MIT Kerberos library.
345
346=head1 SEE ALSO
347
348crypt(3), L<des_modes(3)|des_modes(3)>, L<evp(3)|evp(3)>, L<rand(3)|rand(3)>
349
350=head1 HISTORY
351
352des_cbc_cksum(), des_cbc_encrypt(), des_ecb_encrypt(),
353des_is_weak_key(), des_key_sched(), des_pcbc_encrypt(),
354des_quad_cksum(), des_random_key(), des_read_password() and
355des_string_to_key() are available in the MIT Kerberos library;
356des_check_key_parity(), des_fixup_key_parity() and des_is_weak_key()
357are available in newer versions of that library.
358
359des_set_key_checked() and des_set_key_unchecked() were added in
360OpenSSL 0.9.5.
361
362des_generate_random_block(), des_init_random_number_generator(),
363des_new_random_key(), des_set_random_generator_seed() and
364des_set_sequence_number() and des_rand_data() are used in newer
365versions of Kerberos but are not implemented here.
366
367des_random_key() generated cryptographically weak random data in
368SSLeay and in OpenSSL prior version 0.9.5, as well as in the original
369MIT library.
370
371=head1 AUTHOR
372
373Eric Young (eay@cryptsoft.com). Modified for the OpenSSL project
374(http://www.openssl.org).
375
376=cut
diff --git a/src/lib/libssl/src/doc/crypto/des_modes.pod b/src/lib/libssl/src/doc/crypto/des_modes.pod
new file mode 100644
index 0000000000..d8148c86fc
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/des_modes.pod
@@ -0,0 +1,250 @@
1=pod
2
3=head1 NAME
4
5Modes of DES - the variants of DES and other crypto algorithms of OpenSSL
6
7=head1 DESCRIPTION
8
9Several crypto algorithms fo OpenSSL can be used in a number of modes. Those
10are used for using block ciphers in a way similar to stream ciphers, among
11other things.
12
13=head1 OVERVIEW
14
15=head2 Electronic Codebook Mode (ECB)
16
17Normally, this is found as the function I<algorithm>_ecb_encrypt().
18
19=over 2
20
21=item *
22
2364 bits are enciphered at a time.
24
25=item *
26
27The order of the blocks can be rearranged without detection.
28
29=item *
30
31The same plaintext block always produces the same ciphertext block
32(for the same key) making it vulnerable to a 'dictionary attack'.
33
34=item *
35
36An error will only affect one ciphertext block.
37
38=back
39
40=head2 Cipher Block Chaining Mode (CBC)
41
42Normally, this is found as the function I<algorithm>_cbc_encrypt().
43Be aware that des_cbc_encrypt() is not really DES CBC (it does
44not update the IV); use des_ncbc_encrypt() instead.
45
46=over 2
47
48=item *
49
50a multiple of 64 bits are enciphered at a time.
51
52=item *
53
54The CBC mode produces the same ciphertext whenever the same
55plaintext is encrypted using the same key and starting variable.
56
57=item *
58
59The chaining operation makes the ciphertext blocks dependent on the
60current and all preceding plaintext blocks and therefore blocks can not
61be rearranged.
62
63=item *
64
65The use of different starting variables prevents the same plaintext
66enciphering to the same ciphertext.
67
68=item *
69
70An error will affect the current and the following ciphertext blocks.
71
72=back
73
74=head2 Cipher Feedback Mode (CFB)
75
76Normally, this is found as the function I<algorithm>_cfb_encrypt().
77
78=over 2
79
80=item *
81
82a number of bits (j) <= 64 are enciphered at a time.
83
84=item *
85
86The CFB mode produces the same ciphertext whenever the same
87plaintext is encrypted using the same key and starting variable.
88
89=item *
90
91The chaining operation makes the ciphertext variables dependent on the
92current and all preceding variables and therefore j-bit variables are
93chained together and can not be rearranged.
94
95=item *
96
97The use of different starting variables prevents the same plaintext
98enciphering to the same ciphertext.
99
100=item *
101
102The strength of the CFB mode depends on the size of k (maximal if
103j == k). In my implementation this is always the case.
104
105=item *
106
107Selection of a small value for j will require more cycles through
108the encipherment algorithm per unit of plaintext and thus cause
109greater processing overheads.
110
111=item *
112
113Only multiples of j bits can be enciphered.
114
115=item *
116
117An error will affect the current and the following ciphertext variables.
118
119=back
120
121=head2 Output Feedback Mode (OFB)
122
123Normally, this is found as the function I<algorithm>_ofb_encrypt().
124
125=over 2
126
127
128=item *
129
130a number of bits (j) <= 64 are enciphered at a time.
131
132=item *
133
134The OFB mode produces the same ciphertext whenever the same
135plaintext enciphered using the same key and starting variable. More
136over, in the OFB mode the same key stream is produced when the same
137key and start variable are used. Consequently, for security reasons
138a specific start variable should be used only once for a given key.
139
140=item *
141
142The absence of chaining makes the OFB more vulnerable to specific attacks.
143
144=item *
145
146The use of different start variables values prevents the same
147plaintext enciphering to the same ciphertext, by producing different
148key streams.
149
150=item *
151
152Selection of a small value for j will require more cycles through
153the encipherment algorithm per unit of plaintext and thus cause
154greater processing overheads.
155
156=item *
157
158Only multiples of j bits can be enciphered.
159
160=item *
161
162OFB mode of operation does not extend ciphertext errors in the
163resultant plaintext output. Every bit error in the ciphertext causes
164only one bit to be in error in the deciphered plaintext.
165
166=item *
167
168OFB mode is not self-synchronising. If the two operation of
169encipherment and decipherment get out of synchronism, the system needs
170to be re-initialised.
171
172=item *
173
174Each re-initialisation should use a value of the start variable
175different from the start variable values used before with the same
176key. The reason for this is that an identical bit stream would be
177produced each time from the same parameters. This would be
178susceptible to a 'known plaintext' attack.
179
180=back
181
182=head2 Triple ECB Mode
183
184Normally, this is found as the function I<algorithm>_ecb3_encrypt().
185
186=over 2
187
188=item *
189
190Encrypt with key1, decrypt with key2 and encrypt with key3 again.
191
192=item *
193
194As for ECB encryption but increases the key length to 168 bits.
195There are theoretic attacks that can be used that make the effective
196key length 112 bits, but this attack also requires 2^56 blocks of
197memory, not very likely, even for the NSA.
198
199=item *
200
201If both keys are the same it is equivalent to encrypting once with
202just one key.
203
204=item *
205
206If the first and last key are the same, the key length is 112 bits.
207There are attacks that could reduce the key space to 55 bit's but it
208requires 2^56 blocks of memory.
209
210=item *
211
212If all 3 keys are the same, this is effectively the same as normal
213ecb mode.
214
215=back
216
217=head2 Triple CBC Mode
218
219Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
220
221=over 2
222
223
224=item *
225
226Encrypt with key1, decrypt with key2 and then encrypt with key3.
227
228=item *
229
230As for CBC encryption but increases the key length to 168 bits with
231the same restrictions as for triple ecb mode.
232
233=back
234
235=head1 NOTES
236
237This text was been written in large parts by Eric Young in his original
238documentation for SSLeay, the predecessor of OpenSSL. In turn, he attributed
239it to:
240
241 AS 2805.5.2
242 Australian Standard
243 Electronic funds transfer - Requirements for interfaces,
244 Part 5.2: Modes of operation for an n-bit block cipher algorithm
245 Appendix A
246
247=head1 SEE ALSO
248
249L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<idea(3)|idea(3)>,
250L<rc2(3)|rc2(3)>
diff --git a/src/lib/libssl/src/doc/crypto/dh.pod b/src/lib/libssl/src/doc/crypto/dh.pod
new file mode 100644
index 0000000000..0a9b7c03a2
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/dh.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5dh - Diffie-Hellman key agreement
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH * DH_new(void);
12 void DH_free(DH *dh);
13
14 int DH_size(DH *dh);
15
16 DH * DH_generate_parameters(int prime_len, int generator,
17 void (*callback)(int, int, void *), void *cb_arg);
18 int DH_check(DH *dh, int *codes);
19
20 int DH_generate_key(DH *dh);
21 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
22
23 void DH_set_default_method(DH_METHOD *meth);
24 DH_METHOD *DH_get_default_method(void);
25 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
26 DH *DH_new_method(DH_METHOD *meth);
27 DH_METHOD *DH_OpenSSL(void);
28
29 int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
30 int (*dup_func)(), void (*free_func)());
31 int DH_set_ex_data(DH *d, int idx, char *arg);
32 char *DH_get_ex_data(DH *d, int idx);
33
34 DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
35 int i2d_DHparams(DH *a, unsigned char **pp);
36
37 int DHparams_print_fp(FILE *fp, DH *x);
38 int DHparams_print(BIO *bp, DH *x);
39
40=head1 DESCRIPTION
41
42These functions implement the Diffie-Hellman key agreement protocol.
43The generation of shared DH parameters is described in
44L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
45to perform a key agreement.
46
47The B<DH> structure consists of several BIGNUM components.
48
49 struct
50 {
51 BIGNUM *p; // prime number (shared)
52 BIGNUM *g; // generator of Z_p (shared)
53 BIGNUM *priv_key; // private DH value x
54 BIGNUM *pub_key; // public DH value g^x
55 // ...
56 };
57 DH
58
59=head1 SEE ALSO
60
61L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
62L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<DH_set_method(3)|DH_set_method(3)>,
63L<DH_new(3)|DH_new(3)>, L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
64L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
65L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
66L<RSA_print(3)|RSA_print(3)>
67
68=cut
diff --git a/src/lib/libssl/src/doc/crypto/dsa.pod b/src/lib/libssl/src/doc/crypto/dsa.pod
new file mode 100644
index 0000000000..2c09244899
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/dsa.pod
@@ -0,0 +1,104 @@
1=pod
2
3=head1 NAME
4
5dsa - Digital Signature Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA * DSA_new(void);
12 void DSA_free(DSA *dsa);
13
14 int DSA_size(DSA *dsa);
15
16 DSA * DSA_generate_parameters(int bits, unsigned char *seed,
17 int seed_len, int *counter_ret, unsigned long *h_ret,
18 void (*callback)(int, int, void *), void *cb_arg);
19
20 DH * DSA_dup_DH(DSA *r);
21
22 int DSA_generate_key(DSA *dsa);
23
24 int DSA_sign(int dummy, const unsigned char *dgst, int len,
25 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
26 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
27 BIGNUM **rp);
28 int DSA_verify(int dummy, const unsigned char *dgst, int len,
29 unsigned char *sigbuf, int siglen, DSA *dsa);
30
31 void DSA_set_default_method(DSA_METHOD *meth);
32 DSA_METHOD *DSA_get_default_method(void);
33 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
34 DSA *DSA_new_method(DSA_METHOD *meth);
35 DSA_METHOD *DSA_OpenSSL(void);
36
37 int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
38 int (*dup_func)(), void (*free_func)());
39 int DSA_set_ex_data(DSA *d, int idx, char *arg);
40 char *DSA_get_ex_data(DSA *d, int idx);
41
42 DSA_SIG *DSA_SIG_new(void);
43 void DSA_SIG_free(DSA_SIG *a);
44 int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
45 DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
46
47 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
48 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
49 DSA_SIG *sig, DSA *dsa);
50
51 DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
52 DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
53 DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
54 int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
55 int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
56 int i2d_DSAparams(DSA *a,unsigned char **pp);
57
58 int DSAparams_print(BIO *bp, DSA *x);
59 int DSAparams_print_fp(FILE *fp, DSA *x);
60 int DSA_print(BIO *bp, DSA *x, int off);
61 int DSA_print_fp(FILE *bp, DSA *x, int off);
62
63=head1 DESCRIPTION
64
65These functions implement the Digital Signature Algorithm (DSA). The
66generation of shared DSA parameters is described in
67L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
68L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
69generate a signature key. Signature generation and verification are
70described in L<DSA_sign(3)|DSA_sign(3)>.
71
72The B<DSA> structure consists of several BIGNUM components.
73
74 struct
75 {
76 BIGNUM *p; // prime number (public)
77 BIGNUM *q; // 160-bit subprime, q | p-1 (public)
78 BIGNUM *g; // generator of subgroup (public)
79 BIGNUM *priv_key; // private key x
80 BIGNUM *pub_key; // public key y = g^x
81 // ...
82 }
83 DSA;
84
85In public keys, B<priv_key> is NULL.
86
87=head1 CONFORMING TO
88
89US Federal Information Processing Standard FIPS 186 (Digital Signature
90Standard, DSS), ANSI X9.30
91
92=head1 SEE ALSO
93
94L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
95L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<DSA_new(3)|DSA_new(3)>,
96L<DSA_size(3)|DSA_size(3)>,
97L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
98L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
99L<DSA_generate_key(3)|DSA_generate_key(3)>,
100L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
101L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
102L<RSA_print(3)|RSA_print(3)>
103
104=cut
diff --git a/src/lib/libssl/src/doc/crypto/err.pod b/src/lib/libssl/src/doc/crypto/err.pod
new file mode 100644
index 0000000000..b824c92b57
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/err.pod
@@ -0,0 +1,187 @@
1=pod
2
3=head1 NAME
4
5err - error codes
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13 unsigned long ERR_get_error_line(const char **file, int *line);
14 unsigned long ERR_peek_error_line(const char **file, int *line);
15 unsigned long ERR_get_error_line_data(const char **file, int *line,
16 const char **data, int *flags);
17 unsigned long ERR_peek_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19
20 int ERR_GET_LIB(unsigned long e);
21 int ERR_GET_FUNC(unsigned long e);
22 int ERR_GET_REASON(unsigned long e);
23
24 void ERR_clear_error(void);
25
26 char *ERR_error_string(unsigned long e, char *buf);
27 const char *ERR_lib_error_string(unsigned long e);
28 const char *ERR_func_error_string(unsigned long e);
29 const char *ERR_reason_error_string(unsigned long e);
30
31 void ERR_print_errors(BIO *bp);
32 void ERR_print_errors_fp(FILE *fp);
33
34 void ERR_load_crypto_strings(void);
35 void ERR_free_strings(void);
36
37 void ERR_remove_state(unsigned long pid);
38
39 void ERR_put_error(int lib, int func, int reason, const char *file,
40 int line);
41 void ERR_add_error_data(int num, ...);
42
43 void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
44 unsigned long ERR_PACK(int lib, int func, int reason);
45 int ERR_get_next_error_library(void);
46
47=head1 DESCRIPTION
48
49When a call to the OpenSSL library fails, this is usually signalled
50by the return value, and an error code is stored in an error queue
51associated with the current thread. The B<err> library provides
52functions to obtain these error codes and textual error messages.
53
54The L<ERR_get_error(3)|ERR_get_error(3)> manpage describes how to
55access error codes.
56
57Error codes contain information about where the error occurred, and
58what went wrong. L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> describes how to
59extract this information. A method to obtain human-readable error
60messages is described in L<ERR_error_string(3)|ERR_error_string(3)>.
61
62L<ERR_clear_error(3)|ERR_clear_error(3)> can be used to clear the
63error queue.
64
65Note that L<ERR_remove_state(3)|ERR_remove_state(3)> should be used to
66avoid memory leaks when threads are terminated.
67
68=head1 ADDING NEW ERROR CODES TO OPENSSL
69
70See L<ERR_put_error(3)> if you want to record error codes in the
71OpenSSL error system from within your application.
72
73The remainder of this section is of interest only if you want to add
74new error codes to OpenSSL or add error codes from external libraries.
75
76=head2 Reporting errors
77
78Each sub-library has a specific macro XXXerr() that is used to report
79errors. Its first argument is a function code B<XXX_F_...>, the second
80argument is a reason code B<XXX_R_...>. Function codes are derived
81from the function names; reason codes consist of textual error
82descriptions. For example, the function ssl23_read() reports a
83"handshake failure" as follows:
84
85 SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
86
87Function and reason codes should consist of upper case characters,
88numbers and underscores only. The error file generation script translates
89function codes into function names by looking in the header files
90for an appropriate function name, if none is found it just uses
91the capitalized form such as "SSL23_READ" in the above example.
92
93The trailing section of a reason code (after the "_R_") is translated
94into lower case and underscores changed to spaces.
95
96When you are using new function or reason codes, run B<make errors>.
97The necessary B<#define>s will then automatically be added to the
98sub-library's header file.
99
100Although a library will normally report errors using its own specific
101XXXerr macro, another library's macro can be used. This is normally
102only done when a library wants to include ASN1 code which must use
103the ASN1err() macro.
104
105=head2 Adding new libraries
106
107When adding a new sub-library to OpenSSL, assign it a library number
108B<ERR_LIB_XXX>, define a macro XXXerr() (both in B<err.h>), add its
109name to B<ERR_str_libraries[]> (in B<crypto/err/err.c>), and add
110C<ERR_load_XXX_strings()> to the ERR_load_crypto_strings() function
111(in B<crypto/err/err_all.c>). Finally, add an entry
112
113 L XXX xxx.h xxx_err.c
114
115to B<crypto/err/openssl.ec>, and add B<xxx_err.c> to the Makefile.
116Running B<make errors> will then generate a file B<xxx_err.c>, and
117add all error codes used in the library to B<xxx.h>.
118
119Additionally the library include file must have a certain form.
120Typically it will initially look like this:
121
122 #ifndef HEADER_XXX_H
123 #define HEADER_XXX_H
124
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128
129 /* Include files */
130
131 #include <openssl/bio.h>
132 #include <openssl/x509.h>
133
134 /* Macros, structures and function prototypes */
135
136
137 /* BEGIN ERROR CODES */
138
139The B<BEGIN ERROR CODES> sequence is used by the error code
140generation script as the point to place new error codes, any text
141after this point will be overwritten when B<make errors> is run.
142The closing #endif etc will be automatically added by the script.
143
144The generated C error code file B<xxx_err.c> will load the header
145files B<stdio.h>, B<openssl/err.h> and B<openssl/xxx.h> so the
146header file must load any additional header files containg any
147definitions it uses.
148
149=head1 USING ERROR CODES IN EXTERNAL LIBRARIES
150
151It is also possible to use OpenSSL's error code scheme in external
152libraries. The library needs to load its own codes and call the OpenSSL
153error code insertion script B<mkerr.pl> explicitly to add codes to
154the header file and generate the C error code file. This will normally
155be done if the external library needs to generate new ASN1 structures
156but it can also be used to add more general purpose error code handling.
157
158TBA more details
159
160=head1 INTERNALS
161
162The error queues are stored in a hash table with one B<ERR_STATE>
163entry for each pid. ERR_get_state() returns the current thread's
164B<ERR_STATE>. An B<ERR_STATE> can hold up to B<ERR_NUM_ERRORS> error
165codes. When more error codes are added, the old ones are overwritten,
166on the assumption that the most recent errors are most important.
167
168Error strings are also stored in hash table. The hash tables can
169be obtained by calling ERR_get_err_state_table(void) and
170ERR_get_string_table(void) respectively.
171
172=head1 SEE ALSO
173
174L<CRYPTO_set_id_callback(3)|CRYPTO_set_id_callback(3)>,
175L<CRYPTO_set_locking_callback(3)|<CRYPTO_set_locking_callback(3)>,
176L<ERR_get_error(3)|ERR_get_error(3)>,
177L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>,
178L<ERR_clear_error(3)|ERR_clear_error(3)>,
179L<ERR_error_string(3)|ERR_error_string(3)>,
180L<ERR_print_errors(3)|ERR_print_errors(3)>,
181L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
182L<ERR_remove_state(3)|ERR_remove_state(3)>,
183L<ERR_put_error(3)|ERR_put_error(3)>,
184L<ERR_load_strings(3)|ERR_load_strings(3)>,
185L<SSL_get_error(3)|SSL_get_error(3)>
186
187=cut
diff --git a/src/lib/libssl/src/doc/crypto/evp.pod b/src/lib/libssl/src/doc/crypto/evp.pod
new file mode 100644
index 0000000000..f089dd49a2
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/evp.pod
@@ -0,0 +1,37 @@
1=pod
2
3=head1 NAME
4
5evp - high-level cryptographic functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11=head1 DESCRIPTION
12
13The EVP library provided a high-level interface to cryptographic
14functions.
15
16B<EVP_Seal>I<...> and B<EVP_Open>I<...> provide public key encryption
17and decryption to implement digital "envelopes".
18
19The B<EVP_Sign>I<...> and B<EVP_Verify>I<...> functions implement
20digital signatures.
21
22Symmetric encryption is available with the B<EVP_Encrypt>I<...>
23functions. The B<EVP_Digest>I<...> functions provide message digests.
24
25Algorithms are loaded with OpenSSL_add_all_algorithms(3).
26
27=head1 SEE ALSO
28
29L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
30L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
31L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
32L<EVP_SealInit(3)|EVP_SealInit(3)>,
33L<EVP_SignInit(3)|EVP_SignInit(3)>,
34L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
35L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>
36
37=cut
diff --git a/src/lib/libssl/src/doc/crypto/hmac.pod b/src/lib/libssl/src/doc/crypto/hmac.pod
new file mode 100644
index 0000000000..45b6108c39
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/hmac.pod
@@ -0,0 +1,75 @@
1=pod
2
3=head1 NAME
4
5HMAC, HMAC_Init, HMAC_Update, HMAC_Final - HMAC message authentication code
6
7=head1 SYNOPSIS
8
9 #include <openssl/hmac.h>
10
11 unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
12 int key_len, const unsigned char *d, int n,
13 unsigned char *md, unsigned int *md_len);
14
15 void HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
16 const EVP_MD *md);
17 void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
18 void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
19
20 void HMAC_cleanup(HMAC_CTX *ctx);
21
22=head1 DESCRIPTION
23
24HMAC is a MAC (message authentication code), i.e. a keyed hash
25function used for message authentication, which is based on a hash
26function.
27
28HMAC() computes the message authentication code of the B<n> bytes at
29B<d> using the hash function B<evp_md> and the key B<key> which is
30B<key_len> bytes long.
31
32It places the result in B<md> (which must have space for the output of
33the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
34If B<md> is NULL, the digest is placed in a static array. The size of
35the output is placed in B<md_len>, unless it is B<NULL>.
36
37B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
38B<key> and B<evp_md> may be B<NULL> if a key and hash function have
39been set in a previous call to HMAC_Init() for that B<HMAC_CTX>.
40
41HMAC_cleanup() erases the key and other data from the B<HMAC_CTX>.
42
43The following functions may be used if the message is not completely
44stored in memory:
45
46HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
47function B<evp_md> and the key B<key> which is B<key_len> bytes long.
48
49HMAC_Update() can be called repeatedly with chunks of the message to
50be authenticated (B<len> bytes at B<data>).
51
52HMAC_Final() places the message authentication code in B<md>, which
53must have space for the hash function output.
54
55=head1 RETURN VALUES
56
57HMAC() returns a pointer to the message authentication code.
58
59HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup() do not
60return values.
61
62=head1 CONFORMING TO
63
64RFC 2104
65
66=head1 SEE ALSO
67
68L<sha(3)|sha(3)>, L<evp(3)|evp(3)>
69
70=head1 HISTORY
71
72HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup()
73are available since SSLeay 0.9.0.
74
75=cut
diff --git a/src/lib/libssl/src/doc/crypto/lh_stats.pod b/src/lib/libssl/src/doc/crypto/lh_stats.pod
new file mode 100644
index 0000000000..3eeaa72e52
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/lh_stats.pod
@@ -0,0 +1,60 @@
1=pod
2
3=head1 NAME
4
5lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio,
6lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics
7
8=head1 SYNOPSIS
9
10 #include <openssl/lhash.h>
11
12 void lh_stats(LHASH *table, FILE *out);
13 void lh_node_stats(LHASH *table, FILE *out);
14 void lh_node_usage_stats(LHASH *table, FILE *out);
15
16 void lh_stats_bio(LHASH *table, BIO *out);
17 void lh_node_stats_bio(LHASH *table, BIO *out);
18 void lh_node_usage_stats_bio(LHASH *table, BIO *out);
19
20=head1 DESCRIPTION
21
22The B<LHASH> structure records statistics about most aspects of
23accessing the hash table. This is mostly a legacy of Eric Young
24writing this library for the reasons of implementing what looked like
25a nice algorithm rather than for a particular software product.
26
27lh_stats() prints out statistics on the size of the hash table, how
28many entries are in it, and the number and result of calls to the
29routines in this library.
30
31lh_node_stats() prints the number of entries for each 'bucket' in the
32hash table.
33
34lh_node_usage_stats() prints out a short summary of the state of the
35hash table. It prints the 'load' and the 'actual load'. The load is
36the average number of data items per 'bucket' in the hash table. The
37'actual load' is the average number of items per 'bucket', but only
38for buckets which contain entries. So the 'actual load' is the
39average number of searches that will need to find an item in the hash
40table, while the 'load' is the average number that will be done to
41record a miss.
42
43lh_stats_bio(), lh_node_stats_bio() and lh_node_usage_stats_bio()
44are the same as the above, except that the output goes to a B<BIO>.
45
46=head1 RETURN VALUES
47
48These functions do not return values.
49
50=head1 SEE ALSO
51
52L<bio(3)|bio(3)>, L<lhash(3)|lhash(3)>
53
54=head1 HISTORY
55
56These functions are available in all versions of SSLeay and OpenSSL.
57
58This manpage is derived from the SSLeay documentation.
59
60=cut
diff --git a/src/lib/libssl/src/doc/crypto/lhash.pod b/src/lib/libssl/src/doc/crypto/lhash.pod
new file mode 100644
index 0000000000..af2c9a7102
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/lhash.pod
@@ -0,0 +1,155 @@
1=pod
2
3=head1 NAME
4
5lh_new, lh_free, lh_insert, lh_delete, lh_retrieve, lh_doall,
6lh_doall_arg, lh_error - dynamic hash table
7
8=head1 SYNOPSIS
9
10 #include <openssl/lhash.h>
11
12 LHASH *lh_new(unsigned long (*hash)(/*void *a*/),
13 int (*compare)(/*void *a,void *b*/));
14 void lh_free(LHASH *table);
15
16 void *lh_insert(LHASH *table, void *data);
17 void *lh_delete(LHASH *table, void *data);
18 void *lh_retrieve(LHASH *table, void *data);
19
20 void lh_doall(LHASH *table, void (*func)(/*void *b*/));
21 void lh_doall_arg(LHASH *table, void (*func)(/*void *a,void *b*/),
22 void *arg);
23
24 int lh_error(LHASH *table);
25
26=head1 DESCRIPTION
27
28This library implements dynamic hash tables. The hash table entries
29can be arbitrary structures. Usually they consist of key and value
30fields.
31
32lh_new() creates a new B<LHASH> structure. B<hash> takes a pointer to
33the structure and returns an unsigned long hash value of its key
34field. The hash value is normally truncated to a power of 2, so make
35sure that your hash function returns well mixed low order
36bits. B<compare> takes two arguments, and returns 0 if their keys are
37equal, non-zero otherwise.
38
39lh_free() frees the B<LHASH> structure B<table>. Allocated hash table
40entries will not be freed; consider using lh_doall() to deallocate any
41remaining entries in the hash table.
42
43lh_insert() inserts the structure pointed to by B<data> into B<table>.
44If there already is an entry with the same key, the old value is
45replaced. Note that lh_insert() stores pointers, the data are not
46copied.
47
48lh_delete() deletes an entry from B<table>.
49
50lh_retrieve() looks up an entry in B<table>. Normally, B<data> is
51a structure with the key field(s) set; the function will return a
52pointer to a fully populated structure.
53
54lh_doall() will, for every entry in the hash table, call B<func> with
55the data item as parameters.
56This function can be quite useful when used as follows:
57 void cleanup(STUFF *a)
58 { STUFF_free(a); }
59 lh_doall(hash,cleanup);
60 lh_free(hash);
61This can be used to free all the entries. lh_free() then cleans up the
62'buckets' that point to nothing. When doing this, be careful if you
63delete entries from the hash table in B<func>: the table may decrease
64in size, moving item that you are currently on down lower in the hash
65table. This could cause some entries to be skipped. The best
66solution to this problem is to set hash-E<gt>down_load=0 before you
67start. This will stop the hash table ever being decreased in size.
68
69lh_doall_arg() is the same as lh_doall() except that B<func> will
70be called with B<arg> as the second argument.
71
72lh_error() can be used to determine if an error occurred in the last
73operation. lh_error() is a macro.
74
75=head1 RETURN VALUES
76
77lh_new() returns B<NULL> on error, otherwise a pointer to the new
78B<LHASH> structure.
79
80When a hash table entry is replaced, lh_insert() returns the value
81being replaced. B<NULL> is returned on normal operation and on error.
82
83lh_delete() returns the entry being deleted. B<NULL> is returned if
84there is no such value in the hash table.
85
86lh_retrieve() returns the hash table entry if it has been found,
87B<NULL> otherwise.
88
89lh_error() returns 1 if an error occurred in the last operation, 0
90otherwise.
91
92lh_free(), lh_doall() and lh_doall_arg() return no values.
93
94=head1 BUGS
95
96lh_insert() returns B<NULL> both for success and error.
97
98=head1 INTERNALS
99
100The following description is based on the SSLeay documentation:
101
102The B<lhash> library implements a hash table described in the
103I<Communications of the ACM> in 1991. What makes this hash table
104different is that as the table fills, the hash table is increased (or
105decreased) in size via Realloc(). When a 'resize' is done, instead of
106all hashes being redistributed over twice as many 'buckets', one
107bucket is split. So when an 'expand' is done, there is only a minimal
108cost to redistribute some values. Subsequent inserts will cause more
109single 'bucket' redistributions but there will never be a sudden large
110cost due to redistributing all the 'buckets'.
111
112The state for a particular hash table is kept in the B<LHASH> structure.
113The decision to increase or decrease the hash table size is made
114depending on the 'load' of the hash table. The load is the number of
115items in the hash table divided by the size of the hash table. The
116default values are as follows. If (hash->up_load E<lt> load) =E<gt>
117expand. if (hash-E<gt>down_load E<gt> load) =E<gt> contract. The
118B<up_load> has a default value of 1 and B<down_load> has a default value
119of 2. These numbers can be modified by the application by just
120playing with the B<up_load> and B<down_load> variables. The 'load' is
121kept in a form which is multiplied by 256. So
122hash-E<gt>up_load=8*256; will cause a load of 8 to be set.
123
124If you are interested in performance the field to watch is
125num_comp_calls. The hash library keeps track of the 'hash' value for
126each item so when a lookup is done, the 'hashes' are compared, if
127there is a match, then a full compare is done, and
128hash-E<gt>num_comp_calls is incremented. If num_comp_calls is not equal
129to num_delete plus num_retrieve it means that your hash function is
130generating hashes that are the same for different values. It is
131probably worth changing your hash function if this is the case because
132even if your hash table has 10 items in a 'bucket', it can be searched
133with 10 B<unsigned long> compares and 10 linked list traverses. This
134will be much less expensive that 10 calls to you compare function.
135
136lh_strhash() is a demo string hashing function:
137
138 unsigned long lh_strhash(const char *c);
139
140Since the B<LHASH> routines would normally be passed structures, this
141routine would not normally be passed to lh_new(), rather it would be
142used in the function passed to lh_new().
143
144=head1 SEE ALSO
145
146L<lh_stats(3)|lh_stats(3)>
147
148=head1 HISTORY
149
150The B<lhash> library is available in all versions of SSLeay and OpenSSL.
151lh_error() was added in SSLeay 0.9.1b.
152
153This manpage is derived from the SSLeay documentation.
154
155=cut
diff --git a/src/lib/libssl/src/doc/crypto/md5.pod b/src/lib/libssl/src/doc/crypto/md5.pod
new file mode 100644
index 0000000000..d7c120023d
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/md5.pod
@@ -0,0 +1,85 @@
1=pod
2
3=head1 NAME
4
5MD2, MD5, MD2_Init, MD2_Update, MD2_Final, MD5_Init, MD5_Update,
6MD5_Final - MD2 and MD5 hash functions
7
8=head1 SYNOPSIS
9
10 #include <openssl/md2.h>
11
12 unsigned char *MD2(const unsigned char *d, unsigned long n,
13 unsigned char *md);
14
15 void MD2_Init(MD2_CTX *c);
16 void MD2_Update(MD2_CTX *c, const unsigned char *data,
17 unsigned long len);
18 void MD2_Final(unsigned char *md, MD2_CTX *c);
19
20
21 #include <openssl/md5.h>
22
23 unsigned char *MD5(const unsigned char *d, unsigned long n,
24 unsigned char *md);
25
26 void MD5_Init(MD5_CTX *c);
27 void MD5_Update(MD5_CTX *c, const void *data,
28 unsigned long len);
29 void MD5_Final(unsigned char *md, MD5_CTX *c);
30
31=head1 DESCRIPTION
32
33MD2 and MD5 are cryptographic hash functions with a 128 bit output.
34
35MD2() and MD5() compute the MD2 and MD5 message digest of the B<n>
36bytes at B<d> and place it in B<md> (which must have space for
37MD2_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16 bytes of output). If
38B<md> is NULL, the digest is placed in a static array.
39
40The following functions may be used if the message is not completely
41stored in memory:
42
43MD2_Init() initializes a B<MD2_CTX> structure.
44
45MD2_Update() can be called repeatedly with chunks of the message to
46be hashed (B<len> bytes at B<data>).
47
48MD2_Final() places the message digest in B<md>, which must have space
49for MD2_DIGEST_LENGTH == 16 bytes of output, and erases the B<MD2_CTX>.
50
51MD5_Init(), MD5_Update() and MD5_Final() are analogous using an
52B<MD5_CTX> structure.
53
54Applications should use the higher level functions
55L<EVP_DigestInit(3)|EVP_DigestInit(3)>
56etc. instead of calling the hash functions directly.
57
58=head1 NOTE
59
60MD2 and MD5 are recommended only for compatibility with existing
61applications. In new applications, SHA-1 or RIPEMD-160 should be
62preferred.
63
64=head1 RETURN VALUES
65
66MD2() and MD5() return pointers to the hash value.
67
68MD2_Init(), MD2_Update() MD2_Final(), MD5_Init(), MD5_Update() and
69MD5_Final() do not return values.
70
71=head1 CONFORMING TO
72
73RFC 1319, RFC 1321
74
75=head1 SEE ALSO
76
77L<sha(3)|sha(3)>, L<ripemd(3)|ripemd(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
78
79=head1 HISTORY
80
81MD2(), MD2_Init(), MD2_Update() MD2_Final(), MD5(), MD5_Init(),
82MD5_Update() and MD5_Final() are available in all versions of SSLeay
83and OpenSSL.
84
85=cut
diff --git a/src/lib/libssl/src/doc/crypto/mdc2.pod b/src/lib/libssl/src/doc/crypto/mdc2.pod
new file mode 100644
index 0000000000..11dc303e04
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/mdc2.pod
@@ -0,0 +1,64 @@
1=pod
2
3=head1 NAME
4
5MDC2, MDC2_Init, MDC2_Update, MDC2_Final - MDC2 hash function
6
7=head1 SYNOPSIS
8
9 #include <openssl/mdc2.h>
10
11 unsigned char *MDC2(const unsigned char *d, unsigned long n,
12 unsigned char *md);
13
14 void MDC2_Init(MDC2_CTX *c);
15 void MDC2_Update(MDC2_CTX *c, const unsigned char *data,
16 unsigned long len);
17 void MDC2_Final(unsigned char *md, MDC2_CTX *c);
18
19=head1 DESCRIPTION
20
21MDC2 is a method to construct hash functions with 128 bit output from
22block ciphers. These functions are an implementation of MDC2 with
23DES.
24
25MDC2() computes the MDC2 message digest of the B<n>
26bytes at B<d> and places it in B<md> (which must have space for
27MDC2_DIGEST_LENGTH == 16 bytes of output). If B<md> is NULL, the digest
28is placed in a static array.
29
30The following functions may be used if the message is not completely
31stored in memory:
32
33MDC2_Init() initializes a B<MDC2_CTX> structure.
34
35MDC2_Update() can be called repeatedly with chunks of the message to
36be hashed (B<len> bytes at B<data>).
37
38MDC2_Final() places the message digest in B<md>, which must have space
39for MDC2_DIGEST_LENGTH == 16 bytes of output, and erases the B<MDC2_CTX>.
40
41Applications should use the higher level functions
42L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead of calling the
43hash functions directly.
44
45=head1 RETURN VALUES
46
47MDC2() returns a pointer to the hash value.
48
49MDC2_Init(), MDC2_Update() and MDC2_Final() do not return values.
50
51=head1 CONFORMING TO
52
53ISO/IEC 10118-2, with DES
54
55=head1 SEE ALSO
56
57L<sha(3)|sha(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
58
59=head1 HISTORY
60
61MDC2(), MDC2_Init(), MDC2_Update() and MDC2_Final() are available since
62SSLeay 0.8.
63
64=cut
diff --git a/src/lib/libssl/src/doc/crypto/pem.pod b/src/lib/libssl/src/doc/crypto/pem.pod
new file mode 100644
index 0000000000..a4f8cc3337
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/pem.pod
@@ -0,0 +1,476 @@
1=pod
2
3=head1 NAME
4
5PEM - PEM routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/pem.h>
10
11 EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
12 pem_password_cb *cb, void *u);
13
14 EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
15 pem_password_cb *cb, void *u);
16
17 int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
18 unsigned char *kstr, int klen,
19 pem_password_cb *cb, void *u);
20
21 int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
22 unsigned char *kstr, int klen,
23 pem_password_cb *cb, void *u);
24
25 int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
26 char *kstr, int klen,
27 pem_password_cb *cb, void *u);
28
29 int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
30 char *kstr, int klen,
31 pem_password_cb *cb, void *u);
32
33 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
34 char *kstr, int klen,
35 pem_password_cb *cb, void *u);
36
37 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
38 char *kstr, int klen,
39 pem_password_cb *cb, void *u);
40
41 EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
42 pem_password_cb *cb, void *u);
43
44 EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
45 pem_password_cb *cb, void *u);
46
47 int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
48 int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
49
50 RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
51 pem_password_cb *cb, void *u);
52
53 RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
54 pem_password_cb *cb, void *u);
55
56 int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
57 unsigned char *kstr, int klen,
58 pem_password_cb *cb, void *u);
59
60 int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
61 unsigned char *kstr, int klen,
62 pem_password_cb *cb, void *u);
63
64 RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
65 pem_password_cb *cb, void *u);
66
67 RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
68 pem_password_cb *cb, void *u);
69
70 int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
71
72 int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
73
74 RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
75 pem_password_cb *cb, void *u);
76
77 RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
78 pem_password_cb *cb, void *u);
79
80 int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
81
82 int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
83
84 DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
85 pem_password_cb *cb, void *u);
86
87 DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
88 pem_password_cb *cb, void *u);
89
90 int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
91 unsigned char *kstr, int klen,
92 pem_password_cb *cb, void *u);
93
94 int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
95 unsigned char *kstr, int klen,
96 pem_password_cb *cb, void *u);
97
98 DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
99 pem_password_cb *cb, void *u);
100
101 DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
102 pem_password_cb *cb, void *u);
103
104 int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
105
106 int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
107
108 DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
109
110 DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
111
112 int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
113
114 int PEM_write_DSAparams(FILE *fp, DSA *x);
115
116 DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
117
118 DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
119
120 int PEM_write_bio_DHparams(BIO *bp, DH *x);
121
122 int PEM_write_DHparams(FILE *fp, DH *x);
123
124 X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
125
126 X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
127
128 int PEM_write_bio_X509(BIO *bp, X509 *x);
129
130 int PEM_write_X509(FILE *fp, X509 *x);
131
132 X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
133
134 X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
135
136 int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
137
138 int PEM_write_X509_AUX(FILE *fp, X509 *x);
139
140 X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
141 pem_password_cb *cb, void *u);
142
143 X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
144 pem_password_cb *cb, void *u);
145
146 int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
147
148 int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
149
150 int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
151
152 int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
153
154 X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
155 pem_password_cb *cb, void *u);
156 X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
157 pem_password_cb *cb, void *u);
158 int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
159 int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
160
161 PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
162
163 PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
164
165 int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
166
167 int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
168
169 NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp,
170 NETSCAPE_CERT_SEQUENCE **x,
171 pem_password_cb *cb, void *u);
172
173 NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(FILE *fp,
174 NETSCAPE_CERT_SEQUENCE **x,
175 pem_password_cb *cb, void *u);
176
177 int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp, NETSCAPE_CERT_SEQUENCE *x);
178
179 int PEM_write_NETSCAPE_CERT_SEQUENCE(FILE *fp, NETSCAPE_CERT_SEQUENCE *x);
180
181=head1 DESCRIPTION
182
183The PEM functions read or write structures in PEM format. In
184this sense PEM format is simply base64 encoded data surrounded
185by header lines.
186
187For more details about the meaning of arguments see the
188B<PEM FUNCTION ARGUMENTS> section.
189
190Each operation has four functions associated with it. For
191clarity the term "B<foobar> functions" will be used to collectively
192refer to the PEM_read_bio_foobar(), PEM_read_foobar(),
193PEM_write_bio_foobar() and PEM_write_foobar() functions.
194
195The B<PrivateKey> functions read or write a private key in
196PEM format using an EVP_PKEY structure. The write routines use
197"traditional" private key format and can handle both RSA and DSA
198private keys. The read functions can additionally transparently
199handle PKCS#8 format encrypted and unencrypted keys too.
200
201PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey()
202write a private key in an EVP_PKEY structure in PKCS#8
203EncryptedPrivateKeyInfo format using PKCS#5 v2.0 password based encryption
204algorithms. The B<cipher> argument specifies the encryption algoritm to
205use: unlike all other PEM routines the encryption is applied at the
206PKCS#8 level and not in the PEM headers. If B<cipher> is NULL then no
207encryption is used and a PKCS#8 PrivateKeyInfo structure is used instead.
208
209PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid()
210also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
211it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
212to use is specified in the B<nid> parameter and should be the NID of the
213corresponding OBJECT IDENTIFIER (see NOTES section).
214
215The B<PUBKEY> functions process a public key using an EVP_PKEY
216structure. The public key is encoded as a SubjectPublicKeyInfo
217structure.
218
219The B<RSAPrivateKey> functions process an RSA private key using an
220RSA structure. It handles the same formats as the B<PrivateKey>
221functions but an error occurs if the private key is not RSA.
222
223The B<RSAPublicKey> functions process an RSA public key using an
224RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey
225structure.
226
227The B<RSA_PUBKEY> functions also process an RSA public key using
228an RSA structure. However the public key is encoded using a
229SubjectPublicKeyInfo structure and an error occurs if the public
230key is not RSA.
231
232The B<DSAPrivateKey> functions process a DSA private key using a
233DSA structure. It handles the same formats as the B<PrivateKey>
234functions but an error occurs if the private key is not DSA.
235
236The B<DSA_PUBKEY> functions process a DSA public key using
237a DSA structure. The public key is encoded using a
238SubjectPublicKeyInfo structure and an error occurs if the public
239key is not DSA.
240
241The B<DSAparams> functions process DSA parameters using a DSA
242structure. The parameters are encoded using a foobar structure.
243
244The B<DHparams> functions process DH parameters using a DH
245structure. The parameters are encoded using a PKCS#3 DHparameter
246structure.
247
248The B<X509> functions process an X509 certificate using an X509
249structure. They will also process a trusted X509 certificate but
250any trust settings are discarded.
251
252The B<X509_AUX> functions process a trusted X509 certificate using
253an X509 structure.
254
255The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10
256certificate request using an X509_REQ structure. The B<X509_REQ>
257write functions use B<CERTIFICATE REQUEST> in the header whereas
258the B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>
259(as required by some CAs). The B<X509_REQ> read functions will
260handle either form so there are no B<X509_REQ_NEW> read functions.
261
262The B<X509_CRL> functions process an X509 CRL using an X509_CRL
263structure.
264
265The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7
266structure.
267
268The B<NETSCAPE_CERT_SEQUENCE> functions process a Netscape Certificate
269Sequence using a NETSCAPE_CERT_SEQUENCE structure.
270
271=head1 PEM FUNCTION ARGUMENTS
272
273The PEM functions have many common arguments.
274
275The B<bp> BIO parameter (if present) specifies the BIO to read from
276or write to.
277
278The B<fp> FILE parameter (if present) specifies the FILE pointer to
279read from or write to.
280
281The PEM read functions all take an argument B<TYPE **x> and return
282a B<TYPE *> pointer. Where B<TYPE> is whatever structure the function
283uses. If B<x> is NULL then the parameter is ignored. If B<x> is not
284NULL but B<*x> is NULL then the structure returned will be written
285to B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is made
286to reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).
287Irrespective of the value of B<x> a pointer to the structure is always
288returned (or NULL if an error occurred).
289
290The PEM functions which write private keys take an B<enc> parameter
291which specifies the encryption algorithm to use, encryption is done
292at the PEM level. If this parameter is set to NULL then the private
293key is written in unencrypted form.
294
295The B<cb> argument is the callback to use when querying for the pass
296phrase used for encrypted PEM structures (normally only private keys).
297
298For the PEM write routines if the B<kstr> parameter is not NULL then
299B<klen> bytes at B<kstr> are used as the passphrase and B<cb> is
300ignored.
301
302If the B<cb> parameters is set to NULL and the B<u> parameter is not
303NULL then the B<u> parameter is interpreted as a null terminated string
304to use as the passphrase. If both B<cb> and B<u> are NULL then the
305default callback routine is used which will typically prompt for the
306passphrase on the current terminal with echoing turned off.
307
308The default passphrase callback is sometimes inappropriate (for example
309in a GUI application) so an alternative can be supplied. The callback
310routine has the following form:
311
312 int cb(char *buf, int size, int rwflag, void *u);
313
314B<buf> is the buffer to write the passphrase to. B<size> is the maximum
315length of the passphrase (i.e. the size of buf). B<rwflag> is a flag
316which is set to 0 when reading and 1 when writing. A typical routine
317will ask the user to verify the passphrase (for example by prompting
318for it twice) if B<rwflag> is 1. The B<u> parameter has the same
319value as the B<u> parameter passed to the PEM routine. It allows
320arbitrary data to be passed to the callback by the application
321(for example a window handle in a GUI application). The callback
322B<must> return the number of characters in the passphrase or 0 if
323an error occurred.
324
325=head1 EXAMPLES
326
327Although the PEM routines take several arguments in almost all applications
328most of them are set to 0 or NULL.
329
330Read a certificate in PEM format from a BIO:
331
332 X509 *x;
333 x = PEM_read_bio(bp, NULL, 0, NULL);
334 if (x == NULL)
335 {
336 /* Error */
337 }
338
339Alternative method:
340
341 X509 *x = NULL;
342 if (!PEM_read_bio_X509(bp, &x, 0, NULL))
343 {
344 /* Error */
345 }
346
347Write a certificate to a BIO:
348
349 if (!PEM_write_bio_X509(bp, x))
350 {
351 /* Error */
352 }
353
354Write an unencrypted private key to a FILE pointer:
355
356 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL))
357 {
358 /* Error */
359 }
360
361Write a private key (using traditional format) to a BIO using
362triple DES encryption, the pass phrase is prompted for:
363
364 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
365 {
366 /* Error */
367 }
368
369Write a private key (using PKCS#8 format) to a BIO using triple
370DES encryption, using the pass phrase "hello":
371
372 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello"))
373 {
374 /* Error */
375 }
376
377Read a private key from a BIO using the pass phrase "hello":
378
379 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
380 if (key == NULL)
381 {
382 /* Error */
383 }
384
385Read a private key from a BIO using a pass phrase callback:
386
387 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
388 if (key == NULL)
389 {
390 /* Error */
391 }
392
393Skeleton pass phrase callback:
394
395 int pass_cb(char *buf, int size, int rwflag, void *u);
396 {
397 int len;
398 char *tmp;
399 /* We'd probably do something else if 'rwflag' is 1 */
400 printf("Enter pass phrase for \"%s\"\n", u);
401
402 /* get pass phrase, length 'len' into 'tmp' */
403 tmp = "hello";
404 len = strlen(tmp);
405
406 if (len <= 0) return 0;
407 /* if too long, truncate */
408 if (len > size) len = size;
409 memcpy(buf, tmp, len);
410 return len;
411 }
412
413=head1 NOTES
414
415The old B<PrivateKey> write routines are retained for compatibility.
416New applications should write private keys using the
417PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines
418because they are more secure (they use an iteration count of 2048 whereas
419the traditional routines use a count of 1) unless compatibility with older
420versions of OpenSSL is important.
421
422The B<PrivateKey> read routines can be used in all applications because
423they handle all formats transparently.
424
425A frequent cause of problems is attempting to use the PEM routines like
426this:
427
428 X509 *x;
429 PEM_read_bio_X509(bp, &x, 0, NULL);
430
431this is a bug because an attempt will be made to reuse the data at B<x>
432which is an uninitialised pointer.
433
434=head1 PEM ENCRYPTION FORMAT
435
436This old B<PrivateKey> routines use a non standard technique for encryption.
437
438The private key (or other data) takes the following form:
439
440 -----BEGIN RSA PRIVATE KEY-----
441 Proc-Type: 4,ENCRYPTED
442 DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89
443
444 ...base64 encoded data...
445 -----END RSA PRIVATE KEY-----
446
447The line beginning DEK-Info contains two comma separated pieces of information:
448the encryption algorithm name as used by EVP_get_cipherbyname() and an 8
449byte B<salt> encoded as a set of hexadecimal digits.
450
451After this is the base64 encoded encrypted data.
452
453The encryption key is determined using EVP_bytestokey(), using B<salt> and an
454iteration count of 1. The IV used is the value of B<salt> and *not* the IV
455returned by EVP_bytestokey().
456
457=head1 BUGS
458
459The PEM read routines in some versions of OpenSSL will not correctly reuse
460an existing structure. Therefore the following:
461
462 PEM_read_bio(bp, &x, 0, NULL);
463
464where B<x> already contains a valid certificate, may not work, whereas:
465
466 X509_free(x);
467 x = PEM_read_bio(bp, NULL, 0, NULL);
468
469is guaranteed to work.
470
471=head1 RETURN CODES
472
473The read routines return either a pointer to the structure read or NULL
474is an error occurred.
475
476The write routines return 1 for success or 0 for failure.
diff --git a/src/lib/libssl/src/doc/crypto/rand.pod b/src/lib/libssl/src/doc/crypto/rand.pod
new file mode 100644
index 0000000000..295b681050
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/rand.pod
@@ -0,0 +1,158 @@
1=pod
2
3=head1 NAME
4
5rand - pseudo-random number generator
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_bytes(unsigned char *buf,int num);
12 int RAND_pseudo_bytes(unsigned char *buf,int num);
13
14 void RAND_seed(const void *buf,int num);
15 void RAND_add(const void *buf,int num,int entropy);
16 int RAND_status(void);
17 void RAND_screen(void);
18
19 int RAND_load_file(const char *file,long max_bytes);
20 int RAND_write_file(const char *file);
21 const char *RAND_file_name(char *file,int num);
22
23 int RAND_egd(const char *path);
24
25 void RAND_set_rand_method(RAND_METHOD *meth);
26 RAND_METHOD *RAND_get_rand_method(void);
27 RAND_METHOD *RAND_SSLeay(void);
28
29 void RAND_cleanup(void);
30
31=head1 DESCRIPTION
32
33These functions implement a cryptographically secure pseudo-random
34number generator (PRNG). It is used by other library functions for
35example to generate random keys, and applications can use it when they
36need randomness.
37
38A cryptographic PRNG must be seeded with unpredictable data such as
39mouse movements or keys pressed at random by the user. This is
40described in L<RAND_add(3)|RAND_add(3)>. Its state can be saved in a seed file
41(see L<RAND_load_file(3)|RAND_load_file(3)>) to avoid having to go through the
42seeding process whenever the application is started.
43
44L<RAND_bytes(3)|RAND_bytes(3)> describes how to obtain random data from the
45PRNG.
46
47=head1 INTERNALS
48
49The RAND_SSLeay() method implements a PRNG based on a cryptographic
50hash function.
51
52The following description of its design is based on the SSLeay
53documentation:
54
55First up I will state the things I believe I need for a good RNG.
56
57=over 4
58
59=item 1
60
61A good hashing algorithm to mix things up and to convert the RNG 'state'
62to random numbers.
63
64=item 2
65
66An initial source of random 'state'.
67
68=item 3
69
70The state should be very large. If the RNG is being used to generate
714096 bit RSA keys, 2 2048 bit random strings are required (at a minimum).
72If your RNG state only has 128 bits, you are obviously limiting the
73search space to 128 bits, not 2048. I'm probably getting a little
74carried away on this last point but it does indicate that it may not be
75a bad idea to keep quite a lot of RNG state. It should be easier to
76break a cipher than guess the RNG seed data.
77
78=item 4
79
80Any RNG seed data should influence all subsequent random numbers
81generated. This implies that any random seed data entered will have
82an influence on all subsequent random numbers generated.
83
84=item 5
85
86When using data to seed the RNG state, the data used should not be
87extractable from the RNG state. I believe this should be a
88requirement because one possible source of 'secret' semi random
89data would be a private key or a password. This data must
90not be disclosed by either subsequent random numbers or a
91'core' dump left by a program crash.
92
93=item 6
94
95Given the same initial 'state', 2 systems should deviate in their RNG state
96(and hence the random numbers generated) over time if at all possible.
97
98=item 7
99
100Given the random number output stream, it should not be possible to determine
101the RNG state or the next random number.
102
103=back
104
105The algorithm is as follows.
106
107There is global state made up of a 1023 byte buffer (the 'state'), a
108working hash value ('md'), and a counter ('count').
109
110Whenever seed data is added, it is inserted into the 'state' as
111follows.
112
113The input is chopped up into units of 20 bytes (or less for
114the last block). Each of these blocks is run through the hash
115function as follows: The data passed to the hash function
116is the current 'md', the same number of bytes from the 'state'
117(the location determined by in incremented looping index) as
118the current 'block', the new key data 'block', and 'count'
119(which is incremented after each use).
120The result of this is kept in 'md' and also xored into the
121'state' at the same locations that were used as input into the
122hash function. I
123believe this system addresses points 1 (hash function; currently
124SHA-1), 3 (the 'state'), 4 (via the 'md'), 5 (by the use of a hash
125function and xor).
126
127When bytes are extracted from the RNG, the following process is used.
128For each group of 10 bytes (or less), we do the following:
129
130Input into the hash function the top 10 bytes from the local 'md'
131(which is initialized from the global 'md' before any bytes are
132generated), the bytes that are to be overwritten by the random bytes,
133and bytes from the 'state' (incrementing looping index). From this
134digest output (which is kept in 'md'), the top (up to) 10 bytes are
135returned to the caller and the bottom (up to) 10 bytes are xored into
136the 'state'.
137
138Finally, after we have finished 'num' random bytes for the caller,
139'count' (which is incremented) and the local and global 'md' are fed
140into the hash function and the results are kept in the global 'md'.
141
142I believe the above addressed points 1 (use of SHA-1), 6 (by hashing
143into the 'state' the 'old' data from the caller that is about to be
144overwritten) and 7 (by not using the 10 bytes given to the caller to
145update the 'state', but they are used to update 'md').
146
147So of the points raised, only 2 is not addressed (but see
148L<RAND_add(3)|RAND_add(3)>).
149
150=head1 SEE ALSO
151
152L<BN_rand(3)|BN_rand(3)>, L<RAND_add(3)|RAND_add(3)>,
153L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_egd(3)|RAND_egd(3)>,
154L<RAND_bytes(3)|RAND_bytes(3)>,
155L<RAND_set_rand_method(3)|RAND_set_rand_method(3)>,
156L<RAND_cleanup(3)|RAND_cleanup(3)>
157
158=cut
diff --git a/src/lib/libssl/src/doc/crypto/rc4.pod b/src/lib/libssl/src/doc/crypto/rc4.pod
new file mode 100644
index 0000000000..b6d3a4342c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/rc4.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5RC4_set_key, RC4 - RC4 encryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/rc4.h>
10
11 void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
12
13 void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
14 unsigned char *outdata);
15
16=head1 DESCRIPTION
17
18This library implements the Alleged RC4 cipher, which is described for
19example in I<Applied Cryptography>. It is believed to be compatible
20with RC4[TM], a proprietary cipher of RSA Security Inc.
21
22RC4 is a stream cipher with variable key length. Typically, 128 bit
23(16 byte) keys are used for strong encryption, but shorter insecure
24key sizes have been widely used due to export restrictions.
25
26RC4 consists of a key setup phase and the actual encryption or
27decryption phase.
28
29RC4_set_key() sets up the B<RC4_KEY> B<key> using the B<len> bytes long
30key at B<data>.
31
32RC4() encrypts or decrypts the B<len> bytes of data at B<indata> using
33B<key> and places the result at B<outdata>. Repeated RC4() calls with
34the same B<key> yield a continuous key stream.
35
36Since RC4 is a stream cipher (the input is XORed with a pseudo-random
37key stream to produce the output), decryption uses the same function
38calls as encryption.
39
40Applications should use the higher level functions
41L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
42etc. instead of calling the RC4 functions directly.
43
44=head1 RETURN VALUES
45
46RC4_set_key() and RC4() do not return values.
47
48=head1 NOTE
49
50Certain conditions have to be observed to securely use stream ciphers.
51It is not permissible to perform multiple encryptions using the same
52key stream.
53
54=head1 SEE ALSO
55
56L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<rc2(3)|rc2(3)>
57
58=head1 HISTORY
59
60RC4_set_key() and RC4() are available in all versions of SSLeay and OpenSSL.
61
62=cut
diff --git a/src/lib/libssl/src/doc/crypto/ripemd.pod b/src/lib/libssl/src/doc/crypto/ripemd.pod
new file mode 100644
index 0000000000..31054b6a8c
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ripemd.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5RIPEMD160, RIPEMD160_Init, RIPEMD160_Update, RIPEMD160_Final -
6RIPEMD-160 hash function
7
8=head1 SYNOPSIS
9
10 #include <openssl/ripemd.h>
11
12 unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
13 unsigned char *md);
14
15 void RIPEMD160_Init(RIPEMD160_CTX *c);
16 void RIPEMD160_Update(RIPEMD_CTX *c, const void *data,
17 unsigned long len);
18 void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
19
20=head1 DESCRIPTION
21
22RIPEMD-160 is a cryptographic hash function with a
23160 bit output.
24
25RIPEMD160() computes the RIPEMD-160 message digest of the B<n>
26bytes at B<d> and places it in B<md> (which must have space for
27RIPEMD160_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest
28is placed in a static array.
29
30The following functions may be used if the message is not completely
31stored in memory:
32
33RIPEMD160_Init() initializes a B<RIPEMD160_CTX> structure.
34
35RIPEMD160_Update() can be called repeatedly with chunks of the message to
36be hashed (B<len> bytes at B<data>).
37
38RIPEMD160_Final() places the message digest in B<md>, which must have
39space for RIPEMD160_DIGEST_LENGTH == 20 bytes of output, and erases
40the B<RIPEMD160_CTX>.
41
42Applications should use the higher level functions
43L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead of calling the
44hash functions directly.
45
46=head1 RETURN VALUES
47
48RIPEMD160() returns a pointer to the hash value.
49
50RIPEMD160_Init(), RIPEMD160_Update() and RIPEMD160_Final() do not
51return values.
52
53=head1 CONFORMING TO
54
55ISO/IEC 10118-3 (draft) (??)
56
57=head1 SEE ALSO
58
59L<sha(3)|sha(3)>, L<hmac(3)|hmac(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
60
61=head1 HISTORY
62
63RIPEMD160(), RIPEMD160_Init(), RIPEMD160_Update() and
64RIPEMD160_Final() are available since SSLeay 0.9.0.
65
66=cut
diff --git a/src/lib/libssl/src/doc/crypto/rsa.pod b/src/lib/libssl/src/doc/crypto/rsa.pod
new file mode 100644
index 0000000000..0486c044a6
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/rsa.pod
@@ -0,0 +1,115 @@
1=pod
2
3=head1 NAME
4
5rsa - RSA public key cryptosystem
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12 void RSA_free(RSA *rsa);
13
14 int RSA_public_encrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16 int RSA_private_decrypt(int flen, unsigned char *from,
17 unsigned char *to, RSA *rsa, int padding);
18
19 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
20 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
21 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
22 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
23
24 int RSA_size(RSA *rsa);
25
26 RSA *RSA_generate_key(int num, unsigned long e,
27 void (*callback)(int,int,void *), void *cb_arg);
28
29 int RSA_check_key(RSA *rsa);
30
31 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
32 void RSA_blinding_off(RSA *rsa);
33
34 void RSA_set_default_method(RSA_METHOD *meth);
35 RSA_METHOD *RSA_get_default_method(void);
36 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
37 RSA_METHOD *RSA_get_method(RSA *rsa);
38 RSA_METHOD *RSA_PKCS1_SSLeay(void);
39 RSA_METHOD *RSA_PKCS1_RSAref(void);
40 RSA_METHOD *RSA_null_method(void);
41 int RSA_flags(RSA *rsa);
42 RSA *RSA_new_method(RSA_METHOD *method);
43
44 int RSA_print(BIO *bp, RSA *x, int offset);
45 int RSA_print_fp(FILE *fp, RSA *x, int offset);
46
47 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
48 int (*dup_func)(), void (*free_func)());
49 int RSA_set_ex_data(RSA *r,int idx,char *arg);
50 char *RSA_get_ex_data(RSA *r, int idx);
51
52 int RSA_private_encrypt(int flen, unsigned char *from,
53 unsigned char *to, RSA *rsa,int padding);
54 int RSA_public_decrypt(int flen, unsigned char *from,
55 unsigned char *to, RSA *rsa,int padding);
56
57 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
58 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
59 RSA *rsa);
60 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
61 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
62 RSA *rsa);
63
64=head1 DESCRIPTION
65
66These functions implement RSA public key encryption and signatures
67as defined in PKCS #1 v2.0 [RFC 2437].
68
69The B<RSA> structure consists of several BIGNUM components. It can
70contain public as well as private RSA keys:
71
72 struct
73 {
74 BIGNUM *n; // public modulus
75 BIGNUM *e; // public exponent
76 BIGNUM *d; // private exponent
77 BIGNUM *p; // secret prime factor
78 BIGNUM *q; // secret prime factor
79 BIGNUM *dmp1; // d mod (p-1)
80 BIGNUM *dmq1; // d mod (q-1)
81 BIGNUM *iqmp; // q^-1 mod p
82 // ...
83 };
84 RSA
85
86In public keys, the private exponent and the related secret values are
87B<NULL>.
88
89B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private keys, but the
90RSA operations are much faster when these values are available.
91
92=head1 CONFORMING TO
93
94SSL, PKCS #1 v2.0
95
96=head1 PATENTS
97
98RSA is covered by a US patent which expires in September 2000.
99
100=head1 SEE ALSO
101
102L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
103L<rand(3)|rand(3)>, L<RSA_new(3)|RSA_new(3)>,
104L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
105L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
106L<RSA_generate_key(3)|RSA_generate_key(3)>,
107L<RSA_check_key(3)|RSA_check_key(3)>,
108L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
109L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
110L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
111L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
112L<RSA_sign_ASN_OCTET_STRING(3)|RSA_sign_ASN_OCTET_STRING(3)>,
113L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
114
115=cut
diff --git a/src/lib/libssl/src/doc/crypto/sha.pod b/src/lib/libssl/src/doc/crypto/sha.pod
new file mode 100644
index 0000000000..0ba315d6d7
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/sha.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5SHA1, SHA1_Init, SHA1_Update, SHA1_Final - Secure Hash Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/sha.h>
10
11 unsigned char *SHA1(const unsigned char *d, unsigned long n,
12 unsigned char *md);
13
14 void SHA1_Init(SHA_CTX *c);
15 void SHA1_Update(SHA_CTX *c, const void *data,
16 unsigned long len);
17 void SHA1_Final(unsigned char *md, SHA_CTX *c);
18
19=head1 DESCRIPTION
20
21SHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a
22160 bit output.
23
24SHA1() computes the SHA-1 message digest of the B<n>
25bytes at B<d> and places it in B<md> (which must have space for
26SHA_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest
27is placed in a static array.
28
29The following functions may be used if the message is not completely
30stored in memory:
31
32SHA1_Init() initializes a B<SHA_CTX> structure.
33
34SHA1_Update() can be called repeatedly with chunks of the message to
35be hashed (B<len> bytes at B<data>).
36
37SHA1_Final() places the message digest in B<md>, which must have space
38for SHA_DIGEST_LENGTH == 20 bytes of output, and erases the B<SHA_CTX>.
39
40Applications should use the higher level functions
41L<EVP_DigestInit(3)|EVP_DigestInit(3)>
42etc. instead of calling the hash functions directly.
43
44The predecessor of SHA-1, SHA, is also implemented, but it should be
45used only when backward compatibility is required.
46
47=head1 RETURN VALUES
48
49SHA1() returns a pointer to the hash value.
50
51SHA1_Init(), SHA1_Update() and SHA1_Final() do not return values.
52
53=head1 CONFORMING TO
54
55SHA: US Federal Information Processing Standard FIPS PUB 180 (Secure Hash
56Standard),
57SHA-1: US Federal Information Processing Standard FIPS PUB 180-1 (Secure Hash
58Standard),
59ANSI X9.30
60
61=head1 SEE ALSO
62
63L<ripemd(3)|ripemd(3)>, L<hmac(3)|hmac(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
64
65=head1 HISTORY
66
67SHA1(), SHA1_Init(), SHA1_Update() and SHA1_Final() are available in all
68versions of SSLeay and OpenSSL.
69
70=cut
diff --git a/src/lib/libssl/src/doc/crypto/threads.pod b/src/lib/libssl/src/doc/crypto/threads.pod
new file mode 100644
index 0000000000..5da056f3f8
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/threads.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5CRYPTO_set_locking_callback, CRYPTO_set_id_callback - OpenSSL thread support
6
7=head1 SYNOPSIS
8
9 #include <openssl/crypto.h>
10
11 void CRYPTO_set_locking_callback(void (*locking_function)(int mode,
12 int n, const char *file, int line));
13
14 void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
15
16 int CRYPTO_num_locks(void);
17
18=head1 DESCRIPTION
19
20OpenSSL can safely be used in multi-threaded applications provided
21that two callback functions are set.
22
23locking_function(int mode, int n, const char *file, int line) is
24needed to perform locking on shared data stuctures. Multi-threaded
25applications will crash at random if it is not set.
26
27locking_function() must be able to handle up to CRYPTO_num_locks()
28different mutex locks. It sets the B<n>-th lock if B<mode> &
29B<CRYPTO_LOCK>, and releases it otherwise.
30
31B<file> and B<line> are the file number of the function setting the
32lock. They can be useful for debugging.
33
34id_function(void) is a function that returns a thread ID. It is not
35needed on Windows nor on platforms where getpid() returns a different
36ID for each thread (most notably Linux).
37
38=head1 RETURN VALUES
39
40CRYPTO_num_locks() returns the required number of locks.
41The other functions return no values.
42
43=head1 NOTE
44
45You can find out if OpenSSL was configured with thread support:
46
47 #define OPENSSL_THREAD_DEFINES
48 #include <openssl/opensslconf.h>
49 #if defined(THREADS)
50 // thread support enabled
51 #else
52 // no thread support
53 #endif
54
55=head1 EXAMPLES
56
57B<crypto/threads/mttest.c> shows examples of the callback functions on
58Solaris, Irix and Win32.
59
60=head1 HISTORY
61
62CRYPTO_set_locking_callback() and CRYPTO_set_id_callback() are
63available in all versions of SSLeay and OpenSSL.
64CRYPTO_num_locks() was added in OpenSSL 0.9.4.
65
66=head1 SEE ALSO
67
68L<crypto(3)|crypto(3)>
69
70=cut
diff --git a/src/lib/libssl/src/doc/crypto/ui.pod b/src/lib/libssl/src/doc/crypto/ui.pod
new file mode 100644
index 0000000000..2b3535a746
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ui.pod
@@ -0,0 +1,194 @@
1=pod
2
3=head1 NAME
4
5UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
6UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
7UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
8UI_add_error_string, UI_dup_error_string, UI_construct_prompt
9UI_add_user_data, UI_get0_user_data, UI_get0_result, UI_process,
10UI_ctrl, UI_set_default_method, UI_get_default_method, UI_get_method,
11UI_set_method, UI_OpenSSL, ERR_load_UI_strings - New User Interface
12
13=head1 SYNOPSIS
14
15 #include <openssl/ui.h>
16
17 typedef struct ui_st UI;
18 typedef struct ui_method_st UI_METHOD;
19
20 UI *UI_new(void);
21 UI *UI_new_method(const UI_METHOD *method);
22 void UI_free(UI *ui);
23
24 int UI_add_input_string(UI *ui, const char *prompt, int flags,
25 char *result_buf, int minsize, int maxsize);
26 int UI_dup_input_string(UI *ui, const char *prompt, int flags,
27 char *result_buf, int minsize, int maxsize);
28 int UI_add_verify_string(UI *ui, const char *prompt, int flags,
29 char *result_buf, int minsize, int maxsize, const char *test_buf);
30 int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
31 char *result_buf, int minsize, int maxsize, const char *test_buf);
32 int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
33 const char *ok_chars, const char *cancel_chars,
34 int flags, char *result_buf);
35 int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
36 const char *ok_chars, const char *cancel_chars,
37 int flags, char *result_buf);
38 int UI_add_info_string(UI *ui, const char *text);
39 int UI_dup_info_string(UI *ui, const char *text);
40 int UI_add_error_string(UI *ui, const char *text);
41 int UI_dup_error_string(UI *ui, const char *text);
42
43 /* These are the possible flags. They can be or'ed together. */
44 #define UI_INPUT_FLAG_ECHO 0x01
45 #define UI_INPUT_FLAG_DEFAULT_PWD 0x02
46
47 char *UI_construct_prompt(UI *ui_method,
48 const char *object_desc, const char *object_name);
49
50 void *UI_add_user_data(UI *ui, void *user_data);
51 void *UI_get0_user_data(UI *ui);
52
53 const char *UI_get0_result(UI *ui, int i);
54
55 int UI_process(UI *ui);
56
57 int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
58 #define UI_CTRL_PRINT_ERRORS 1
59 #define UI_CTRL_IS_REDOABLE 2
60
61 void UI_set_default_method(const UI_METHOD *meth);
62 const UI_METHOD *UI_get_default_method(void);
63 const UI_METHOD *UI_get_method(UI *ui);
64 const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
65
66 UI_METHOD *UI_OpenSSL(void);
67
68=head1 DESCRIPTION
69
70UI stands for User Interface, and is general purpose set of routines to
71prompt the user for text-based information. Through user-written methods
72(see L<ui_create(3)|ui_create(3)>), prompting can be done in any way
73imaginable, be it plain text prompting, through dialog boxes or from a
74cell phone.
75
76All the functions work through a context of the type UI. This context
77contains all the information needed to prompt correctly as well as a
78reference to a UI_METHOD, which is an ordered vector of functions that
79carry out the actual prompting.
80
81The first thing to do is to create a UI with UI_new() or UI_new_method(),
82then add information to it with the UI_add or UI_dup functions. Also,
83user-defined random data can be passed down to the underlying method
84through calls to UI_add_user_data. The default UI method doesn't care
85about these data, but other methods might. Finally, use UI_process()
86to actually perform the prompting and UI_get0_result() to find the result
87to the prompt.
88
89A UI can contain more than one prompt, which are performed in the given
90sequence. Each prompt gets an index number which is returned by the
91UI_add and UI_dup functions, and has to be used to get the corresponding
92result with UI_get0_result().
93
94The functions are as follows:
95
96UI_new() creates a new UI using the default UI method. When done with
97this UI, it should be freed using UI_free().
98
99UI_new_method() creates a new UI using the given UI method. When done with
100this UI, it should be freed using UI_free().
101
102UI_OpenSSL() returns the built-in UI method (note: not the default one,
103since the default can be changed. See further on). This method is the
104most machine/OS dependent part of OpenSSL and normally generates the
105most problems when porting.
106
107UI_free() removes a UI from memory, along with all other pieces of memory
108that's connected to it, like duplicated input strings, results and others.
109
110UI_add_input_string() and UI_add_verify_string() add a prompt to the UI,
111as well as flags and a result buffer and the desired minimum and maximum
112sizes of the result. The given information is used to prompt for
113information, for example a password, and to verify a password (i.e. having
114the user enter it twice and check that the same string was entered twice).
115UI_add_verify_string() takes and extra argument that should be a pointer
116to the result buffer of the input string that it's supposed to verify, or
117verification will fail.
118
119UI_add_input_boolean() adds a prompt to the UI that's supposed to be answered
120in a boolean way, with a single character for yes and a different character
121for no. A set of characters that can be used to cancel the prompt is given
122as well. The prompt itself is really divided in two, one part being the
123descriptive text (given through the I<prompt> argument) and one describing
124the possible answers (given through the I<action_desc> argument).
125
126UI_add_info_string() and UI_add_error_string() add strings that are shown at
127the same time as the prompt for extra information or to show an error string.
128The difference between the two is only conceptual. With the builtin method,
129there's no technical difference between them. Other methods may make a
130difference between them, however.
131
132The flags currently supported are UI_INPUT_FLAG_ECHO, which is relevant for
133UI_add_input_string() and will have the users response be echoed (when
134prompting for a password, this flag should obviously not be used, and
135UI_INPUT_FLAG_DEFAULT_PWD, which means that a default password of some
136sort will be used (completely depending on the application and the UI
137method).
138
139UI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(),
140UI_dup_info_string() and UI_dup_error_string() are basically the same
141as their UI_add counterparts, except that they make their own copies
142of all strings.
143
144UI_construct_prompt() is a helper function that can be used to create
145a prompt from two pieces of information: an description and a name.
146The default constructor (if there is none provided by the method used)
147creates a string "Enter I<description> for I<name>:". With the
148description "pass phrase" and the file name "foo.key", that becomes
149"Enter pass phrase for foo.key:". Other methods may create whatever
150string and may include encodings that will be processed by the other
151method functions.
152
153UI_add_user_data() adds a piece of memory for the method to use at any
154time. The builtin UI method doesn't care about this info. Note that several
155calls to this function doesn't add data, it replaces the previous blob
156with the one given as argument.
157
158UI_get0_user_data() retrieves the data that has last been given to the
159UI with UI_add_user_data().
160
161UI_get0_result() returns a pointer to the result buffer associated with
162the information indexed by I<i>.
163
164UI_process() goes through the information given so far, does all the printing
165and prompting and returns.
166
167UI_ctrl() adds extra control for the application author. For now, it
168understands two commands: UI_CTRL_PRINT_ERRORS, which makes UI_process()
169print the OpenSSL error stack as part of processing the UI, and
170UI_CTRL_IS_REDOABLE, which returns a flag saying if the used UI can
171be used again or not.
172
173UI_set_default_method() changes the default UI method to the one given.
174
175UI_get_default_method() returns a pointer to the current default UI method.
176
177UI_get_method() returns the UI method associated with a given UI.
178
179UI_set_method() changes the UI method associated with a given UI.
180
181=head1 SEE ALSO
182
183L<ui_create(3)|ui_create(3)>, L<ui_compat(3)|ui_compat(3)>
184
185=head1 HISTORY
186
187The UI section was first introduced in OpenSSL 0.9.7.
188
189=head1 AUTHOR
190
191Richard Levitte (richard@levitte.org) for the OpenSSL project
192(http://www.openssl.org).
193
194=cut
diff --git a/src/lib/libssl/src/doc/crypto/ui_compat.pod b/src/lib/libssl/src/doc/crypto/ui_compat.pod
new file mode 100644
index 0000000000..9ab3c69bf2
--- /dev/null
+++ b/src/lib/libssl/src/doc/crypto/ui_compat.pod
@@ -0,0 +1,55 @@
1=pod
2
3=head1 NAME
4
5des_read_password, des_read_2passwords, des_read_pw_string, des_read_pw -
6Compatibility user interface functions
7
8=head1 SYNOPSIS
9
10 int des_read_password(DES_cblock *key,const char *prompt,int verify);
11 int des_read_2passwords(DES_cblock *key1,DES_cblock *key2,
12 const char *prompt,int verify);
13
14 int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
15 int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
16
17=head1 DESCRIPTION
18
19The DES library contained a few routines to prompt for passwords. These
20aren't necessarely dependent on DES, and have therefore become part of the
21UI compatibility library.
22
23des_read_pw() writes the string specified by I<prompt> to standard output
24turns echo off and reads an input string from the terminal. The string is
25returned in I<buf>, which must have spac for at least I<size> bytes.
26If I<verify> is set, the user is asked for the password twice and unless
27the two copies match, an error is returned. The second password is stored
28in I<buff>, which must therefore also be at least I<size> bytes. A return
29code of -1 indicates a system error, 1 failure due to use interaction, and
300 is success. All other functions described here use des_read_pw() to do
31the work.
32
33des_read_pw_string() is a variant of des_read_pw() that provides a buffer
34for you if I<verify> is set.
35
36des_read_password() calls des_read_pw() and converts the password to a
37DES key by calling DES_string_to_key(); des_read_2password() operates in
38the same way as des_read_password() except that it generates two keys
39by using the DES_string_to_2key() function.
40
41=head1 NOTES
42
43des_read_pw_string() is available in the MIT Kerberos library as well, and
44is also available under the name EVP_read_pw_string().
45
46=head1 SEE ALSO
47
48L<ui(3)|ui(3)>, L<ui_create(3)|ui_create(3)>
49
50=head1 AUTHOR
51
52Richard Levitte (richard@levitte.org) for the OpenSSL project
53(http://www.openssl.org).
54
55=cut
diff --git a/src/lib/libssl/src/doc/openssl.txt b/src/lib/libssl/src/doc/openssl.txt
new file mode 100644
index 0000000000..91b85e5f14
--- /dev/null
+++ b/src/lib/libssl/src/doc/openssl.txt
@@ -0,0 +1,1174 @@
1
2This is some preliminary documentation for OpenSSL.
3
4==============================================================================
5 BUFFER Library
6==============================================================================
7
8The buffer library handles simple character arrays. Buffers are used for
9various purposes in the library, most notably memory BIOs.
10
11The library uses the BUF_MEM structure defined in buffer.h:
12
13typedef struct buf_mem_st
14{
15 int length; /* current number of bytes */
16 char *data;
17 int max; /* size of buffer */
18} BUF_MEM;
19
20'length' is the current size of the buffer in bytes, 'max' is the amount of
21memory allocated to the buffer. There are three functions which handle these
22and one "miscellaneous" function.
23
24BUF_MEM *BUF_MEM_new()
25
26This allocates a new buffer of zero size. Returns the buffer or NULL on error.
27
28void BUF_MEM_free(BUF_MEM *a)
29
30This frees up an already existing buffer. The data is zeroed before freeing
31up in case the buffer contains sensitive data.
32
33int BUF_MEM_grow(BUF_MEM *str, int len)
34
35This changes the size of an already existing buffer. It returns zero on error
36or the new size (i.e. 'len'). Any data already in the buffer is preserved if
37it increases in size.
38
39char * BUF_strdup(char *str)
40
41This is the previously mentioned strdup function: like the standard library
42strdup() it copies a null terminated string into a block of allocated memory
43and returns a pointer to the allocated block.
44
45Unlike the standard C library strdup() this function uses Malloc() and so
46should be used in preference to the standard library strdup() because it can
47be used for memory leak checking or replacing the malloc() function.
48
49The memory allocated from BUF_strdup() should be freed up using the Free()
50function.
51
52==============================================================================
53 OpenSSL X509V3 extension configuration
54==============================================================================
55
56OpenSSL X509V3 extension configuration: preliminary documentation.
57
58INTRODUCTION.
59
60For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
61possible to add and print out common X509 V3 certificate and CRL extensions.
62
63BEGINNERS NOTE
64
65For most simple applications you don't need to know too much about extensions:
66the default openssl.cnf values will usually do sensible things.
67
68If you want to know more you can initially quickly look through the sections
69describing how the standard OpenSSL utilities display and add extensions and
70then the list of supported extensions.
71
72For more technical information about the meaning of extensions see:
73
74http://www.imc.org/ietf-pkix/
75http://home.netscape.com/eng/security/certs.html
76
77PRINTING EXTENSIONS.
78
79Extension values are automatically printed out for supported extensions.
80
81openssl x509 -in cert.pem -text
82openssl crl -in crl.pem -text
83
84will give information in the extension printout, for example:
85
86 X509v3 extensions:
87 X509v3 Basic Constraints:
88 CA:TRUE
89 X509v3 Subject Key Identifier:
90 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
91 X509v3 Authority Key Identifier:
92 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
93 X509v3 Key Usage:
94 Certificate Sign, CRL Sign
95 X509v3 Subject Alternative Name:
96 email:email@1.address, email:email@2.address
97
98CONFIGURATION FILES.
99
100The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
101which certificate extensions to include. In each case a line:
102
103x509_extensions = extension_section
104
105indicates which section contains the extensions. In the case of 'req' the
106extension section is used when the -x509 option is present to create a
107self signed root certificate.
108
109The 'x509' utility also supports extensions when it signs a certificate.
110The -extfile option is used to set the configuration file containing the
111extensions. In this case a line with:
112
113extensions = extension_section
114
115in the nameless (default) section is used. If no such line is included then
116it uses the default section.
117
118You can also add extensions to CRLs: a line
119
120crl_extensions = crl_extension_section
121
122will include extensions when the -gencrl option is used with the 'ca' utility.
123You can add any extension to a CRL but of the supported extensions only
124issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
125CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
126CRL entry extensions can be displayed.
127
128NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
129you should not include a crl_extensions line in the configuration file.
130
131As with all configuration files you can use the inbuilt environment expansion
132to allow the values to be passed in the environment. Therefore if you have
133several extension sections used for different purposes you can have a line:
134
135x509_extensions = $ENV::ENV_EXT
136
137and set the ENV_EXT environment variable before calling the relevant utility.
138
139EXTENSION SYNTAX.
140
141Extensions have the basic form:
142
143extension_name=[critical,] extension_options
144
145the use of the critical option makes the extension critical. Extreme caution
146should be made when using the critical flag. If an extension is marked
147as critical then any client that does not understand the extension should
148reject it as invalid. Some broken software will reject certificates which
149have *any* critical extensions (these violates PKIX but we have to live
150with it).
151
152There are three main types of extension: string extensions, multi-valued
153extensions, and raw extensions.
154
155String extensions simply have a string which contains either the value itself
156or how it is obtained.
157
158For example:
159
160nsComment="This is a Comment"
161
162Multi-valued extensions have a short form and a long form. The short form
163is a list of names and values:
164
165basicConstraints=critical,CA:true,pathlen:1
166
167The long form allows the values to be placed in a separate section:
168
169basicConstraints=critical,@bs_section
170
171[bs_section]
172
173CA=true
174pathlen=1
175
176Both forms are equivalent. However it should be noted that in some cases the
177same name can appear multiple times, for example,
178
179subjectAltName=email:steve@here,email:steve@there
180
181in this case an equivalent long form is:
182
183subjectAltName=@alt_section
184
185[alt_section]
186
187email.1=steve@here
188email.2=steve@there
189
190This is because the configuration file code cannot handle the same name
191occurring twice in the same extension.
192
193The syntax of raw extensions is governed by the extension code: it can
194for example contain data in multiple sections. The correct syntax to
195use is defined by the extension code itself: check out the certificate
196policies extension for an example.
197
198In addition it is also possible to use the word DER to include arbitrary
199data in any extension.
200
2011.2.3.4=critical,DER:01:02:03:04
2021.2.3.4=DER:01020304
203
204The value following DER is a hex dump of the DER encoding of the extension
205Any extension can be placed in this form to override the default behaviour.
206For example:
207
208basicConstraints=critical,DER:00:01:02:03
209
210WARNING: DER should be used with caution. It is possible to create totally
211invalid extensions unless care is taken.
212
213CURRENTLY SUPPORTED EXTENSIONS.
214
215If you aren't sure about extensions then they can be largely ignored: its only
216when you want to do things like restrict certificate usage when you need to
217worry about them.
218
219The only extension that a beginner might want to look at is Basic Constraints.
220If in addition you want to try Netscape object signing the you should also
221look at Netscape Certificate Type.
222
223Literal String extensions.
224
225In each case the 'value' of the extension is placed directly in the
226extension. Currently supported extensions in this category are: nsBaseUrl,
227nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
228nsSslServerName and nsComment.
229
230For example:
231
232nsComment="This is a test comment"
233
234Bit Strings.
235
236Bit string extensions just consist of a list of supported bits, currently
237two extensions are in this category: PKIX keyUsage and the Netscape specific
238nsCertType.
239
240nsCertType (netscape certificate type) takes the flags: client, server, email,
241objsign, reserved, sslCA, emailCA, objCA.
242
243keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
244keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
245encipherOnly, decipherOnly.
246
247For example:
248
249nsCertType=server
250
251keyUsage=digitalSignature, nonRepudiation
252
253Hints on Netscape Certificate Type.
254
255Other than Basic Constraints this is the only extension a beginner might
256want to use, if you want to try Netscape object signing, otherwise it can
257be ignored.
258
259If you want a certificate that can be used just for object signing then:
260
261nsCertType=objsign
262
263will do the job. If you want to use it as a normal end user and server
264certificate as well then
265
266nsCertType=objsign,email,server
267
268is more appropriate. You cannot use a self signed certificate for object
269signing (well Netscape signtool can but it cheats!) so you need to create
270a CA certificate and sign an end user certificate with it.
271
272Side note: If you want to conform to the Netscape specifications then you
273should really also set:
274
275nsCertType=objCA
276
277in the *CA* certificate for just an object signing CA and
278
279nsCertType=objCA,emailCA,sslCA
280
281for everything. Current Netscape software doesn't enforce this so it can
282be omitted.
283
284Basic Constraints.
285
286This is generally the only extension you need to worry about for simple
287applications. If you want your certificate to be usable as a CA certificate
288(in addition to an end user certificate) then you set this to:
289
290basicConstraints=CA:TRUE
291
292if you want to be certain the certificate cannot be used as a CA then do:
293
294basicConstraints=CA:FALSE
295
296The rest of this section describes more advanced usage.
297
298Basic constraints is a multi-valued extension that supports a CA and an
299optional pathlen option. The CA option takes the values true and false and
300pathlen takes an integer. Note if the CA option is false the pathlen option
301should be omitted.
302
303The pathlen parameter indicates the maximum number of CAs that can appear
304below this one in a chain. So if you have a CA with a pathlen of zero it can
305only be used to sign end user certificates and not further CAs. This all
306assumes that the software correctly interprets this extension of course.
307
308Examples:
309
310basicConstraints=CA:TRUE
311basicConstraints=critical,CA:TRUE, pathlen:0
312
313NOTE: for a CA to be considered valid it must have the CA option set to
314TRUE. An end user certificate MUST NOT have the CA value set to true.
315According to PKIX recommendations it should exclude the extension entirely,
316however some software may require CA set to FALSE for end entity certificates.
317
318Subject Key Identifier.
319
320This is really a string extension and can take two possible values. Either
321a hex string giving details of the extension value to include or the word
322'hash' which then automatically follow PKIX guidelines in selecting and
323appropriate key identifier. The use of the hex string is strongly discouraged.
324
325Example: subjectKeyIdentifier=hash
326
327Authority Key Identifier.
328
329The authority key identifier extension permits two options. keyid and issuer:
330both can take the optional value "always".
331
332If the keyid option is present an attempt is made to copy the subject key
333identifier from the parent certificate. If the value "always" is present
334then an error is returned if the option fails.
335
336The issuer option copies the issuer and serial number from the issuer
337certificate. Normally this will only be done if the keyid option fails or
338is not included: the "always" flag will always include the value.
339
340Subject Alternative Name.
341
342The subject alternative name extension allows various literal values to be
343included in the configuration file. These include "email" (an email address)
344"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
345registered ID: OBJECT IDENTIFIER) and IP (and IP address).
346
347Also the email option include a special 'copy' value. This will automatically
348include and email addresses contained in the certificate subject name in
349the extension.
350
351Examples:
352
353subjectAltName=email:copy,email:my@other.address,URL:http://my.url.here/
354subjectAltName=email:my@other.address,RID:1.2.3.4
355
356Issuer Alternative Name.
357
358The issuer alternative name option supports all the literal options of
359subject alternative name. It does *not* support the email:copy option because
360that would not make sense. It does support an additional issuer:copy option
361that will copy all the subject alternative name values from the issuer
362certificate (if possible).
363
364CRL distribution points.
365
366This is a multi-valued extension that supports all the literal options of
367subject alternative name. Of the few software packages that currently interpret
368this extension most only interpret the URI option.
369
370Currently each option will set a new DistributionPoint with the fullName
371field set to the given value.
372
373Other fields like cRLissuer and reasons cannot currently be set or displayed:
374at this time no examples were available that used these fields.
375
376If you see this extension with <UNSUPPORTED> when you attempt to print it out
377or it doesn't appear to display correctly then let me know, including the
378certificate (mail me at steve@openssl.org) .
379
380Examples:
381
382crlDistributionPoints=URI:http://www.myhost.com/myca.crl
383crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
384
385Certificate Policies.
386
387This is a RAW extension. It attempts to display the contents of this extension:
388unfortunately this extension is often improperly encoded.
389
390The certificate policies extension will rarely be used in practice: few
391software packages interpret it correctly or at all. IE5 does partially
392support this extension: but it needs the 'ia5org' option because it will
393only correctly support a broken encoding. Of the options below only the
394policy OID, explicitText and CPS options are displayed with IE5.
395
396All the fields of this extension can be set by using the appropriate syntax.
397
398If you follow the PKIX recommendations of not including any qualifiers and just
399using only one OID then you just include the value of that OID. Multiple OIDs
400can be set separated by commas, for example:
401
402certificatePolicies= 1.2.4.5, 1.1.3.4
403
404If you wish to include qualifiers then the policy OID and qualifiers need to
405be specified in a separate section: this is done by using the @section syntax
406instead of a literal OID value.
407
408The section referred to must include the policy OID using the name
409policyIdentifier, cPSuri qualifiers can be included using the syntax:
410
411CPS.nnn=value
412
413userNotice qualifiers can be set using the syntax:
414
415userNotice.nnn=@notice
416
417The value of the userNotice qualifier is specified in the relevant section.
418This section can include explicitText, organization and noticeNumbers
419options. explicitText and organization are text strings, noticeNumbers is a
420comma separated list of numbers. The organization and noticeNumbers options
421(if included) must BOTH be present. If you use the userNotice option with IE5
422then you need the 'ia5org' option at the top level to modify the encoding:
423otherwise it will not be interpreted properly.
424
425Example:
426
427certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
428
429[polsect]
430
431policyIdentifier = 1.3.5.8
432CPS.1="http://my.host.name/"
433CPS.2="http://my.your.name/"
434userNotice.1=@notice
435
436[notice]
437
438explicitText="Explicit Text Here"
439organization="Organisation Name"
440noticeNumbers=1,2,3,4
441
442TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
443according to PKIX it should be of type DisplayText but Verisign uses an
444IA5STRING and IE5 needs this too.
445
446Display only extensions.
447
448Some extensions are only partially supported and currently are only displayed
449but cannot be set. These include private key usage period, CRL number, and
450CRL reason.
451
452==============================================================================
453 X509V3 Extension code: programmers guide
454==============================================================================
455
456The purpose of the extension code is twofold. It allows an extension to be
457created from a string or structure describing its contents and it prints out an
458extension in a human or machine readable form.
459
4601. Initialisation and cleanup.
461
462X509V3_add_standard_extensions();
463
464This function should be called before any other extension code. It adds support
465for some common PKIX and Netscape extensions. Additional custom extensions can
466be added as well (see later).
467
468void X509V3_EXT_cleanup(void);
469
470This function should be called last to cleanup the extension code. After this
471call no other extension calls should be made.
472
4732. Printing and parsing extensions.
474
475The simplest way to print out extensions is via the standard X509 printing
476routines: if you use the standard X509_print() function, the supported
477extensions will be printed out automatically.
478
479The following functions allow finer control over extension display:
480
481int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
482int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
483
484These two functions print out an individual extension to a BIO or FILE pointer.
485Currently the flag argument is unused and should be set to 0. The 'indent'
486argument is the number of spaces to indent each line.
487
488void *X509V3_EXT_d2i(X509_EXTENSION *ext);
489
490This function parses an extension and returns its internal structure. The
491precise structure you get back depends on the extension being parsed. If the
492extension if basicConstraints you will get back a pointer to a
493BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
494details about the structures returned. The returned structure should be freed
495after use using the relevant free function, BASIC_CONSTRAINTS_free() for
496example.
497
4983. Generating extensions.
499
500An extension will typically be generated from a configuration file, or some
501other kind of configuration database.
502
503int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
504 X509 *cert);
505int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
506 X509_CRL *crl);
507
508These functions add all the extensions in the given section to the given
509certificate or CRL. They will normally be called just before the certificate
510or CRL is due to be signed. Both return 0 on error on non zero for success.
511
512In each case 'conf' is the LHASH pointer of the configuration file to use
513and 'section' is the section containing the extension details.
514
515See the 'context functions' section for a description of the ctx paramater.
516
517
518X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
519 char *value);
520
521This function returns an extension based on a name and value pair, if the
522pair will not need to access other sections in a config file (or there is no
523config file) then the 'conf' parameter can be set to NULL.
524
525X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
526 char *value);
527
528This function creates an extension in the same way as X509V3_EXT_conf() but
529takes the NID of the extension rather than its name.
530
531For example to produce basicConstraints with the CA flag and a path length of
53210:
533
534x = X509V3_EXT_conf_nid(NULL, NULL, NID_basicConstraints, "CA:TRUE,pathlen:10");
535
536
537X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
538
539This function sets up an extension from its internal structure. The ext_nid
540parameter is the NID of the extension and 'crit' is the critical flag.
541
5424. Context functions.
543
544The following functions set and manipulate an extension context structure.
545The purpose of the extension context is to allow the extension code to
546access various structures relating to the "environment" of the certificate:
547for example the issuers certificate or the certificate request.
548
549void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
550 X509_REQ *req, X509_CRL *crl, int flags);
551
552This function sets up an X509V3_CTX structure with details of the certificate
553environment: specifically the issuers certificate, the subject certificate,
554the certificate request and the CRL: if these are not relevant or not
555available then they can be set to NULL. The 'flags' parameter should be set
556to zero.
557
558X509V3_set_ctx_test(ctx)
559
560This macro is used to set the 'ctx' structure to a 'test' value: this is to
561allow the syntax of an extension (or configuration file) to be tested.
562
563X509V3_set_ctx_nodb(ctx)
564
565This macro is used when no configuration database is present.
566
567void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
568
569This function is used to set the configuration database when it is an LHASH
570structure: typically a configuration file.
571
572The following functions are used to access a configuration database: they
573should only be used in RAW extensions.
574
575char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
576
577This function returns the value of the parameter "name" in "section", or NULL
578if there has been an error.
579
580void X509V3_string_free(X509V3_CTX *ctx, char *str);
581
582This function frees up the string returned by the above function.
583
584STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
585
586This function returns a whole section as a STACK_OF(CONF_VALUE) .
587
588void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
589
590This function frees up the STACK returned by the above function.
591
592Note: it is possible to use the extension code with a custom configuration
593database. To do this the "db_meth" element of the X509V3_CTX structure should
594be set to an X509V3_CTX_METHOD structure. This structure contains the following
595function pointers:
596
597char * (*get_string)(void *db, char *section, char *value);
598STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
599void (*free_string)(void *db, char * string);
600void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
601
602these will be called and passed the 'db' element in the X509V3_CTX structure
603to access the database. If a given function is not implemented or not required
604it can be set to NULL.
605
6065. String helper functions.
607
608There are several "i2s" and "s2i" functions that convert structures to and
609from ASCII strings. In all the "i2s" cases the returned string should be
610freed using Free() after use. Since some of these are part of other extension
611code they may take a 'method' parameter. Unless otherwise stated it can be
612safely set to NULL.
613
614char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
615
616This returns a hex string from an ASN1_OCTET_STRING.
617
618char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
619char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
620
621These return a string decimal representations of an ASN1_INTEGER and an
622ASN1_ENUMERATED type, respectively.
623
624ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
625 X509V3_CTX *ctx, char *str);
626
627This converts an ASCII hex string to an ASN1_OCTET_STRING.
628
629ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
630
631This converts a decimal ASCII string into an ASN1_INTEGER.
632
6336. Multi valued extension helper functions.
634
635The following functions can be used to manipulate STACKs of CONF_VALUE
636structures, as used by multi valued extensions.
637
638int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
639
640This function expects a boolean value in 'value' and sets 'asn1_bool' to
641it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
642strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
643"false", "N", "n", "NO" or "no".
644
645int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
646
647This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
648
649int X509V3_add_value(const char *name, const char *value,
650 STACK_OF(CONF_VALUE) **extlist);
651
652This simply adds a string name and value pair.
653
654int X509V3_add_value_uchar(const char *name, const unsigned char *value,
655 STACK_OF(CONF_VALUE) **extlist);
656
657The same as above but for an unsigned character value.
658
659int X509V3_add_value_bool(const char *name, int asn1_bool,
660 STACK_OF(CONF_VALUE) **extlist);
661
662This adds either "TRUE" or "FALSE" depending on the value of 'ans1_bool'
663
664int X509V3_add_value_bool_nf(char *name, int asn1_bool,
665 STACK_OF(CONF_VALUE) **extlist);
666
667This is the same as above except it adds nothing if asn1_bool is FALSE.
668
669int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
670 STACK_OF(CONF_VALUE) **extlist);
671
672This function adds the value of the ASN1_INTEGER in decimal form.
673
6747. Other helper functions.
675
676<to be added>
677
678ADDING CUSTOM EXTENSIONS.
679
680Currently there are three types of supported extensions.
681
682String extensions are simple strings where the value is placed directly in the
683extensions, and the string returned is printed out.
684
685Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
686or return a STACK_OF(CONF_VALUE).
687
688Raw extensions are just passed a BIO or a value and it is the extensions
689responsiblity to handle all the necessary printing.
690
691There are two ways to add an extension. One is simply as an alias to an already
692existing extension. An alias is an extension that is identical in ASN1 structure
693to an existing extension but has a different OBJECT IDENTIFIER. This can be
694done by calling:
695
696int X509V3_EXT_add_alias(int nid_to, int nid_from);
697
698'nid_to' is the new extension NID and 'nid_from' is the already existing
699extension NID.
700
701Alternatively an extension can be written from scratch. This involves writing
702the ASN1 code to encode and decode the extension and functions to print out and
703generate the extension from strings. The relevant functions are then placed in
704a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
705called.
706
707The X509V3_EXT_METHOD structure is described below.
708
709strut {
710int ext_nid;
711int ext_flags;
712X509V3_EXT_NEW ext_new;
713X509V3_EXT_FREE ext_free;
714X509V3_EXT_D2I d2i;
715X509V3_EXT_I2D i2d;
716X509V3_EXT_I2S i2s;
717X509V3_EXT_S2I s2i;
718X509V3_EXT_I2V i2v;
719X509V3_EXT_V2I v2i;
720X509V3_EXT_R2I r2i;
721X509V3_EXT_I2R i2r;
722
723void *usr_data;
724};
725
726The elements have the following meanings.
727
728ext_nid is the NID of the object identifier of the extension.
729
730ext_flags is set of flags. Currently the only external flag is
731 X509V3_EXT_MULTILINE which means a multi valued extensions
732 should be printed on separate lines.
733
734usr_data is an extension specific pointer to any relevant data. This
735 allows extensions to share identical code but have different
736 uses. An example of this is the bit string extension which uses
737 usr_data to contain a list of the bit names.
738
739All the remaining elements are function pointers.
740
741ext_new is a pointer to a function that allocates memory for the
742 extension ASN1 structure: for example ASN1_OBJECT_new().
743
744ext_free is a pointer to a function that free up memory of the extension
745 ASN1 structure: for example ASN1_OBJECT_free().
746
747d2i is the standard ASN1 function that converts a DER buffer into
748 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
749
750i2d is the standard ASN1 function that converts the internal
751 structure into the DER representation: for example
752 i2d_ASN1_IA5STRING().
753
754The remaining functions are depend on the type of extension. One i2X and
755one X2i should be set and the rest set to NULL. The types set do not need
756to match up, for example the extension could be set using the multi valued
757v2i function and printed out using the raw i2r.
758
759All functions have the X509V3_EXT_METHOD passed to them in the 'method'
760parameter and an X509V3_CTX structure. Extension code can then access the
761parent structure via the 'method' parameter to for example make use of the value
762of usr_data. If the code needs to use detail relating to the request it can
763use the 'ctx' parameter.
764
765A note should be given here about the 'flags' member of the 'ctx' parameter.
766If it has the value CTX_TEST then the configuration syntax is being checked
767and no actual certificate or CRL exists. Therefore any attempt in the config
768file to access such information should silently succeed. If the syntax is OK
769then it should simply return a (possibly bogus) extension, otherwise it
770should return NULL.
771
772char *i2s(struct v3_ext_method *method, void *ext);
773
774This function takes the internal structure in the ext parameter and returns
775a Malloc'ed string representing its value.
776
777void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
778
779This function takes the string representation in the ext parameter and returns
780an allocated internal structure: ext_free() will be used on this internal
781structure after use.
782
783i2v and v2i handle a STACK_OF(CONF_VALUE):
784
785typedef struct
786{
787 char *section;
788 char *name;
789 char *value;
790} CONF_VALUE;
791
792Only the name and value members are currently used.
793
794STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
795
796This function is passed the internal structure in the ext parameter and
797returns a STACK of CONF_VALUE structures. The values of name, value,
798section and the structure itself will be freed up with Free after use.
799Several helper functions are available to add values to this STACK.
800
801void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
802 STACK_OF(CONF_VALUE) *values);
803
804This function takes a STACK_OF(CONF_VALUE) structures and should set the
805values of the external structure. This typically uses the name element to
806determine which structure element to set and the value element to determine
807what to set it to. Several helper functions are available for this
808purpose (see above).
809
810int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
811
812This function is passed the internal extension structure in the ext parameter
813and sends out a human readable version of the extension to out. The 'indent'
814paremeter should be noted to determine the necessary amount of indentation
815needed on the output.
816
817void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
818
819This is just passed the string representation of the extension. It is intended
820to be used for more elaborate extensions where the standard single and multi
821valued options are insufficient. They can use the 'ctx' parameter to parse the
822configuration database themselves. See the context functions section for details
823of how to do this.
824
825Note: although this type takes the same parameters as the "r2s" function there
826is a subtle difference. Whereas an "r2i" function can access a configuration
827database an "s2i" function MUST NOT. This is so the internal code can safely
828assume that an "s2i" function will work without a configuration database.
829
830==============================================================================
831 PKCS#12 Library
832==============================================================================
833
834This section describes the internal PKCS#12 support. There are very few
835differences between the old external library and the new internal code at
836present. This may well change because the external library will not be updated
837much in future.
838
839This version now includes a couple of high level PKCS#12 functions which
840generally "do the right thing" and should make it much easier to handle PKCS#12
841structures.
842
843HIGH LEVEL FUNCTIONS.
844
845For most applications you only need concern yourself with the high level
846functions. They can parse and generate simple PKCS#12 files as produced by
847Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
848private key and certificate pair.
849
8501. Initialisation and cleanup.
851
852No special initialisation is needed for the internal PKCS#12 library: the
853standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
854add all algorithms (you should at least add SHA1 though) then you can manually
855initialise the PKCS#12 library with:
856
857PKCS12_PBE_add();
858
859The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
860called or it can be directly freed with:
861
862EVP_PBE_cleanup();
863
864after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
865be called.
866
8672. I/O functions.
868
869i2d_PKCS12_bio(bp, p12)
870
871This writes out a PKCS12 structure to a BIO.
872
873i2d_PKCS12_fp(fp, p12)
874
875This is the same but for a FILE pointer.
876
877d2i_PKCS12_bio(bp, p12)
878
879This reads in a PKCS12 structure from a BIO.
880
881d2i_PKCS12_fp(fp, p12)
882
883This is the same but for a FILE pointer.
884
8853. Parsing and creation functions.
886
8873.1 Parsing with PKCS12_parse().
888
889int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
890 STACK **ca);
891
892This function takes a PKCS12 structure and a password (ASCII, null terminated)
893and returns the private key, the corresponding certificate and any CA
894certificates. If any of these is not required it can be passed as a NULL.
895The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
896structure. Typically to read in a PKCS#12 file you might do:
897
898p12 = d2i_PKCS12_fp(fp, NULL);
899PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
900PKCS12_free(p12);
901
9023.2 PKCS#12 creation with PKCS12_create().
903
904PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
905 STACK *ca, int nid_key, int nid_cert, int iter,
906 int mac_iter, int keytype);
907
908This function will create a PKCS12 structure from a given password, name,
909private key, certificate and optional STACK of CA certificates. The remaining
9105 parameters can be set to 0 and sensible defaults will be used.
911
912The parameters nid_key and nid_cert are the key and certificate encryption
913algorithms, iter is the encryption iteration count, mac_iter is the MAC
914iteration count and keytype is the type of private key. If you really want
915to know what these last 5 parameters do then read the low level section.
916
917Typically to create a PKCS#12 file the following could be used:
918
919p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
920i2d_PKCS12_fp(fp, p12);
921PKCS12_free(p12);
922
923LOW LEVEL FUNCTIONS.
924
925In some cases the high level functions do not provide the necessary
926functionality. For example if you want to generate or parse more complex
927PKCS#12 files. The sample pkcs12 application uses the low level functions
928to display details about the internal structure of a PKCS#12 file.
929
930Introduction.
931
932This is a brief description of how a PKCS#12 file is represented internally:
933some knowledge of PKCS#12 is assumed.
934
935A PKCS#12 object contains several levels.
936
937At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
938CRL, a private key, encrypted or unencrypted, a set of safebags (so the
939structure can be nested) or other secrets (not documented at present).
940A safebag can optionally have attributes, currently these are: a unicode
941friendlyName (a Unicode string) or a localKeyID (a string of bytes).
942
943At the next level is an authSafe which is a set of safebags collected into
944a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
945
946At the top level is the PKCS12 structure itself which contains a set of
947authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
948contains a MAC which is a kind of password protected digest to preserve
949integrity (so any unencrypted stuff below can't be tampered with).
950
951The reason for these levels is so various objects can be encrypted in various
952ways. For example you might want to encrypt a set of private keys with
953triple-DES and then include the related certificates either unencrypted or
954with lower encryption. Yes it's the dreaded crypto laws at work again which
955allow strong encryption on private keys and only weak encryption on other
956stuff.
957
958To build one of these things you turn all certificates and keys into safebags
959(with optional attributes). You collect the safebags into (one or more) STACKS
960and convert these into authsafes (encrypted or unencrypted). The authsafes
961are collected into a STACK and added to a PKCS12 structure. Finally a MAC
962inserted.
963
964Pulling one apart is basically the reverse process. The MAC is verified against
965the given password. The authsafes are extracted and each authsafe split into
966a set of safebags (possibly involving decryption). Finally the safebags are
967decomposed into the original keys and certificates and the attributes used to
968match up private key and certificate pairs.
969
970Anyway here are the functions that do the dirty work.
971
9721. Construction functions.
973
9741.1 Safebag functions.
975
976M_PKCS12_x5092certbag(x509)
977
978This macro takes an X509 structure and returns a certificate bag. The
979X509 structure can be freed up after calling this function.
980
981M_PKCS12_x509crl2certbag(crl)
982
983As above but for a CRL.
984
985PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
986
987Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
988Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
989structure contains a private key data in plain text form it should be free'd
990up as soon as it has been encrypted for security reasons (freeing up the
991structure zeros out the sensitive data). This can be done with
992PKCS8_PRIV_KEY_INFO_free().
993
994PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
995
996This sets the key type when a key is imported into MSIE or Outlook 98. Two
997values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
998key that can also be used for signing but its size is limited in the export
999versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1000signing only key but the keysize is unlimited (well 16K is supposed to work).
1001If you are using the domestic version of MSIE then you can ignore this because
1002KEY_EX is not limited and can be used for both.
1003
1004PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1005
1006Convert a PKCS8 private key structure into a keybag. This routine embeds the
1007p8 structure in the keybag so p8 should not be freed up or used after it is
1008called. The p8 structure will be freed up when the safebag is freed.
1009
1010PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1011
1012Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1013embedded and can be freed up after use.
1014
1015int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1016int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1017
1018Add a local key id or a friendlyname to a safebag.
1019
10201.2 Authsafe functions.
1021
1022PKCS7 *PKCS12_pack_p7data(STACK *sk)
1023Take a stack of safebags and convert them into an unencrypted authsafe. The
1024stack of safebags can be freed up after calling this function.
1025
1026PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1027
1028As above but encrypted.
1029
10301.3 PKCS12 functions.
1031
1032PKCS12 *PKCS12_init(int mode)
1033
1034Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1035
1036M_PKCS12_pack_authsafes(p12, safes)
1037
1038This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1039
1040int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1041
1042Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1043that SHA-1 should be used.
1044
10452. Extraction Functions.
1046
10472.1 Safebags.
1048
1049M_PKCS12_bag_type(bag)
1050
1051Return the type of "bag". Returns one of the following
1052
1053NID_keyBag
1054NID_pkcs8ShroudedKeyBag 7
1055NID_certBag 8
1056NID_crlBag 9
1057NID_secretBag 10
1058NID_safeContentsBag 11
1059
1060M_PKCS12_cert_bag_type(bag)
1061
1062Returns type of certificate bag, following are understood.
1063
1064NID_x509Certificate 14
1065NID_sdsiCertificate 15
1066
1067M_PKCS12_crl_bag_type(bag)
1068
1069Returns crl bag type, currently only NID_crlBag is recognised.
1070
1071M_PKCS12_certbag2x509(bag)
1072
1073This macro extracts an X509 certificate from a certificate bag.
1074
1075M_PKCS12_certbag2x509crl(bag)
1076
1077As above but for a CRL.
1078
1079EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1080
1081Extract a private key from a PKCS8 private key info structure.
1082
1083M_PKCS12_decrypt_skey(bag, pass, passlen)
1084
1085Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1086Works with both RSA and DSA keys
1087
1088char *PKCS12_get_friendlyname(bag)
1089
1090Returns the friendlyName of a bag if present or NULL if none. The returned
1091string is a null terminated ASCII string allocated with Malloc(). It should
1092thus be freed up with Free() after use.
1093
10942.2 AuthSafe functions.
1095
1096M_PKCS12_unpack_p7data(p7)
1097
1098Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1099
1100#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1101
1102As above but for an encrypted content info.
1103
11042.3 PKCS12 functions.
1105
1106M_PKCS12_unpack_authsafes(p12)
1107
1108Extract a STACK of authsafes from a PKCS12 structure.
1109
1110M_PKCS12_mac_present(p12)
1111
1112Check to see if a MAC is present.
1113
1114int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1115
1116Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1117
1118
1119Notes.
1120
11211. All the function return 0 or NULL on error.
11222. Encryption based functions take a common set of parameters. These are
1123described below.
1124
1125pass, passlen
1126ASCII password and length. The password on the MAC is called the "integrity
1127password" the encryption password is called the "privacy password" in the
1128PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1129passed for the length it is worked out by the function itself (currently
1130this is sometimes done whatever is passed as the length but that may change).
1131
1132salt, saltlen
1133A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1134default length is used.
1135
1136iter
1137Iteration count. This is a measure of how many times an internal function is
1138called to encrypt the data. The larger this value is the longer it takes, it
1139makes dictionary attacks on passwords harder. NOTE: Some implementations do
1140not support an iteration count on the MAC. If the password for the MAC and
1141encryption is the same then there is no point in having a high iteration
1142count for encryption if the MAC has no count. The MAC could be attacked
1143and the password used for the main decryption.
1144
1145pbe_nid
1146This is the NID of the password based encryption method used. The following are
1147supported.
1148NID_pbe_WithSHA1And128BitRC4
1149NID_pbe_WithSHA1And40BitRC4
1150NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1151NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1152NID_pbe_WithSHA1And128BitRC2_CBC
1153NID_pbe_WithSHA1And40BitRC2_CBC
1154
1155Which you use depends on the implementation you are exporting to. "Export
1156grade" (i.e. cryptographically challenged) products cannot support all
1157algorithms. Typically you may be able to use any encryption on shrouded key
1158bags but they must then be placed in an unencrypted authsafe. Other authsafes
1159may only support 40bit encryption. Of course if you are using SSLeay
1160throughout you can strongly encrypt everything and have high iteration counts
1161on everything.
1162
11633. For decryption routines only the password and length are needed.
1164
11654. Unlike the external version the nid's of objects are the values of the
1166constants: that is NID_certBag is the real nid, therefore there is no
1167PKCS12_obj_offset() function. Note the object constants are not the same as
1168those of the external version. If you use these constants then you will need
1169to recompile your code.
1170
11715. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1172macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1173reused or freed up safely.
1174
diff --git a/src/lib/libssl/src/doc/openssl_button.gif b/src/lib/libssl/src/doc/openssl_button.gif
new file mode 100644
index 0000000000..3d3c90c9f8
--- /dev/null
+++ b/src/lib/libssl/src/doc/openssl_button.gif
Binary files differ
diff --git a/src/lib/libssl/src/doc/openssl_button.html b/src/lib/libssl/src/doc/openssl_button.html
new file mode 100644
index 0000000000..44c91bd3d0
--- /dev/null
+++ b/src/lib/libssl/src/doc/openssl_button.html
@@ -0,0 +1,7 @@
1
2<!-- the `Includes OpenSSL Cryptogaphy Software' button -->
3<!-- freely usable by any application linked against OpenSSL -->
4<a href="http://www.openssl.org/">
5<img src="openssl_button.gif"
6 width=102 height=47 border=0></a>
7
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CIPHER_get_name.pod b/src/lib/libssl/src/doc/ssl/SSL_CIPHER_get_name.pod
new file mode 100644
index 0000000000..7fea14ee68
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CIPHER_get_name.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5SSL_CIPHER_get_name, SSL_CIPHER_get_bits, SSL_CIPHER_get_version,
6SSL_CIPHER_description - get SSL_CIPHER properties
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 const char *SSL_CIPHER_get_name(SSL_CIPHER *cipher);
13 int SSL_CIPHER_get_bits(SSL_CIPHER *cipher, int *alg_bits);
14 char *SSL_CIPHER_get_version(SSL_CIPHER *cipher);
15 char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int size);
16
17=head1 DESCRIPTION
18
19SSL_CIPHER_get_name() returns a pointer to the name of B<cipher>. If the
20argument is the NULL pointer, a pointer to the constant value "NONE" is
21returned.
22
23SSL_CIPHER_get_bits() returns the number of secret bits used for B<cipher>. If
24B<alg_bits> is not NULL, it contains the number of bits processed by the
25chosen algorithm. If B<cipher> is NULL, 0 is returned.
26
27SSL_CIPHER_get_version() returns the protocol version for B<cipher>, currently
28"SSLv2", "SSLv3", or "TLSv1". If B<cipher> is NULL, "(NONE)" is returned.
29
30SSL_CIPHER_description() returns a textual description of the cipher used
31into the buffer B<buf> of length B<len> provided. B<len> must be at least
32128 bytes, otherwise the string "Buffer too small" is returned. If B<buf>
33is NULL, a buffer of 128 bytes is allocated using OPENSSL_malloc(). If the
34allocation fails, the string "OPENSSL_malloc Error" is returned.
35
36=head1 NOTES
37
38The number of bits processed can be different from the secret bits. An
39export cipher like e.g. EXP-RC4-MD5 has only 40 secret bits. The algorithm
40does use the full 128 bits (which would be returned for B<alg_bits>), of
41which however 88bits are fixed. The search space is hence only 40 bits.
42
43=head1 BUGS
44
45If SSL_CIPHER_description() is called with B<cipher> being NULL, the
46library crashes.
47
48=head1 RETURN VALUES
49
50See DESCRIPTION
51
52=head1 SEE ALSO
53
54L<ssl(3)|ssl(3)>, L<SSL_get_current_cipher(3)|SSL_get_current_cipher(3)>,
55L<SSL_get_ciphers(3)|SSL_get_ciphers(3)>
56
57=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_COMP_add_compression_method.pod b/src/lib/libssl/src/doc/ssl/SSL_COMP_add_compression_method.pod
new file mode 100644
index 0000000000..2a98739114
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_COMP_add_compression_method.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5SSL_COMP_add_compression_method - handle SSL/TLS integrated compression methods
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);
12
13=head1 DESCRIPTION
14
15SSL_COMP_add_compression_method() adds the compression method B<cm> with
16the identifier B<id> to the list of available compression methods. This
17list is globally maintained for all SSL operations within this application.
18It cannot be set for specific SSL_CTX or SSL objects.
19
20=head1 NOTES
21
22The TLS standard (or SSLv3) allows the integration of compression methods
23into the communication. The TLS RFC does however not specify compression
24methods or their corresponding identifiers, so there is currently no compatible
25way to integrate compression with unknown peers. It is therefore currently not
26recommended to integrate compression into applications. Applications for
27non-public use may agree on certain compression methods. Using different
28compression methods with the same identifier will lead to connection failure.
29
30An OpenSSL client speaking a protocol that allows compression (SSLv3, TLSv1)
31will unconditionally send the list of all compression methods enabled with
32SSL_COMP_add_compression_method() to the server during the handshake.
33Unlike the mechanisms to set a cipher list, there is no method available to
34restrict the list of compression method on a per connection basis.
35
36An OpenSSL server will match the identifiers listed by a client against
37its own compression methods and will unconditionally activate compression
38when a matching identifier is found. There is no way to restrict the list
39of compression methods supported on a per connection basis.
40
41The OpenSSL library has the compression methods B<COMP_rle()> and (when
42especially enabled during compilation) B<COMP_zlib()> available.
43
44=head1 WARNINGS
45
46Once the identities of the compression methods for the TLS protocol have
47been standardized, the compression API will most likely be changed. Using
48it in the current state is not recommended.
49
50=head1 RETURN VALUES
51
52SSL_COMP_add_compression_method() may return the following values:
53
54=over 4
55
56=item 1
57
58The operation succeeded.
59
60=item 0
61
62The operation failed. Check the error queue to find out the reason.
63
64=back
65
66=head1 SEE ALSO
67
68L<ssl(3)|ssl(3)>
69
70=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_add_extra_chain_cert.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_add_extra_chain_cert.pod
new file mode 100644
index 0000000000..21a9db0e2a
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_add_extra_chain_cert.pod
@@ -0,0 +1,38 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_add_extra_chain_cert - add certificate to chain
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_add_extra_chain_cert(SSL_CTX ctx, X509 *x509)
12
13=head1 DESCRIPTION
14
15SSL_CTX_add_extra_chain_cert() adds the certificate B<x509> to the certificate
16chain presented together with the certificate. Several certificates
17can be added one after the other.
18
19=head1 NOTES
20
21When constructing the certificate chain, the chain will be formed from
22these certificates explicitly specified. If no chain is specified,
23the library will try to complete the chain from the available CA
24certificates in the trusted CA storage, see
25L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
26
27=head1 RETURN VALUES
28
29SSL_CTX_add_extra_chain_cert() returns 1 on success. Check out the
30error stack to find out the reason for failure otherwise.
31
32=head1 SEE ALSO
33
34L<ssl(3)|ssl(3)>,
35L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
36L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
37
38=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_add_session.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_add_session.pod
new file mode 100644
index 0000000000..af326c2f73
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_add_session.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_add_session, SSL_add_session, SSL_CTX_remove_session, SSL_remove_session - manipulate session cache
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c);
12 int SSL_add_session(SSL_CTX *ctx, SSL_SESSION *c);
13
14 int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c);
15 int SSL_remove_session(SSL_CTX *ctx, SSL_SESSION *c);
16
17=head1 DESCRIPTION
18
19SSL_CTX_add_session() adds the session B<c> to the context B<ctx>. The
20reference count for session B<c> is incremented by 1. If a session with
21the same session id already exists, the old session is removed by calling
22L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>.
23
24SSL_CTX_remove_session() removes the session B<c> from the context B<ctx>.
25L<SSL_SESSION_free(3)|SSL_SESSION_free(3)> is called once for B<c>.
26
27SSL_add_session() and SSL_remove_session() are synonyms for their
28SSL_CTX_*() counterparts.
29
30=head1 NOTES
31
32When adding a new session to the internal session cache, it is examined
33whether a session with the same session id already exists. In this case
34it is assumed that both sessions are identical. If the same session is
35stored in a different SSL_SESSION object, The old session is
36removed and replaced by the new session. If the session is actually
37identical (the SSL_SESSION object is identical), SSL_CTX_add_session()
38is a no-op, and the return value is 0.
39
40
41=head1 RETURN VALUES
42
43The following values are returned by all functions:
44
45=over 4
46
47=item 0
48
49 The operation failed. In case of the add operation, it was tried to add
50 the same (identical) session twice. In case of the remove operation, the
51 session was not found in the cache.
52
53=item 1
54
55 The operation succeeded.
56
57=back
58
59=head1 SEE ALSO
60
61L<ssl(3)|ssl(3)>,
62L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
63L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>
64
65=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_ctrl.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_ctrl.pod
new file mode 100644
index 0000000000..fb6adcf50c
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_ctrl.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_ctrl, SSL_callback_ctrl - internal handling functions for SSL_CTX and SSL objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
12 long SSL_CTX_callback_ctrl(SSL_CTX *, int cmd, void (*fp)());
13
14 long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
15 long SSL_callback_ctrl(SSL *, int cmd, void (*fp)());
16
17=head1 DESCRIPTION
18
19The SSL_*_ctrl() family of functions is used to manipulate settings of
20the SSL_CTX and SSL objects. Depending on the command B<cmd> the arguments
21B<larg>, B<parg>, or B<fp> are evaluated. These functions should never
22be called directly. All functionalities needed are made available via
23other functions or macros.
24
25=head1 RETURN VALUES
26
27The return values of the SSL*_ctrl() functions depend on the command
28supplied via the B<cmd> parameter.
29
30=head1 SEE ALSO
31
32L<ssl(3)|ssl(3)>
33
34=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_flush_sessions.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_flush_sessions.pod
new file mode 100644
index 0000000000..148c36c871
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_flush_sessions.pod
@@ -0,0 +1,49 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_flush_sessions, SSL_flush_sessions - remove expired sessions
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);
12 void SSL_flush_sessions(SSL_CTX *ctx, long tm);
13
14=head1 DESCRIPTION
15
16SSL_CTX_flush_sessions() causes a run through the session cache of
17B<ctx> to remove sessions expired at time B<tm>.
18
19SSL_flush_sessions() is a synonym for SSL_CTX_flush_sessions().
20
21=head1 NOTES
22
23If enabled, the internal session cache will collect all sessions established
24up to the specified maximum number (see SSL_CTX_sess_set_cache_size()).
25As sessions will not be reused ones they are expired, they should be
26removed from the cache to save resources. This can either be done
27 automatically whenever 255 new sessions were established (see
28L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>)
29or manually by calling SSL_CTX_flush_sessions().
30
31The parameter B<tm> specifies the time which should be used for the
32expiration test, in most cases the actual time given by time(0)
33will be used.
34
35SSL_CTX_flush_sessions() will only check sessions stored in the internal
36cache. When a session is found and removed, the remove_session_cb is however
37called to synchronize with the external cache (see
38L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>).
39
40=head1 RETURN VALUES
41
42=head1 SEE ALSO
43
44L<ssl(3)|ssl(3)>,
45L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
46L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>,
47L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>
48
49=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_free.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_free.pod
new file mode 100644
index 0000000000..de69672422
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_free.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_free - free an allocated SSL_CTX object
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_free(SSL_CTX *ctx);
12
13=head1 DESCRIPTION
14
15SSL_CTX_free() decrements the reference count of B<ctx>, and removes the
16SSL_CTX object pointed to by B<ctx> and frees up the allocated memory if the
17the reference count has reached 0.
18
19It also calls the free()ing procedures for indirectly affected items, if
20applicable: the session cacahe, the list of ciphers, the list of Client CAs,
21the certificates and keys.
22
23=head1 RETURN VALUES
24
25SSL_CTX_free() does not provide diagnostic information.
26
27L<SSL_CTX_new(3)|SSL_CTX_new(3)>, L<ssl(3)|ssl(3)>
28
29=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_get_ex_new_index.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_get_ex_new_index.pod
new file mode 100644
index 0000000000..15067438c8
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_get_ex_new_index.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_get_ex_new_index, SSL_CTX_set_ex_data, SSL_CTX_get_ex_data - internal application specific data functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_CTX_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *arg);
17
18 void *SSL_CTX_get_ex_data(SSL_CTX *ctx, int idx);
19
20 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp);
26
27=head1 DESCRIPTION
28
29Several OpenSSL structures can have application specific data attached to them.
30These functions are used internally by OpenSSL to manipulate application
31specific data attached to a specific structure.
32
33SSL_CTX_get_ex_new_index() is used to register a new index for application
34specific data.
35
36SSL_CTX_set_ex_data() is used to store application data at B<arg> for B<idx>
37into the B<ctx> object.
38
39SSL_CTX_get_ex_data() is used to retrieve the information for B<idx> from
40B<ctx>.
41
42A detailed description for the B<*_get_ex_new_index()> functionality
43can be found in L<RSA_get_ex_new_index.pod(3)|RSA_get_ex_new_index.pod(3)>.
44The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
45L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
46
47=head1 SEE ALSO
48
49L<ssl(3)|ssl(3)>,
50L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
51L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
52
53=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_get_verify_mode.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_get_verify_mode.pod
new file mode 100644
index 0000000000..7f10c6e945
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_get_verify_mode.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
12 int SSL_get_verify_mode(SSL *ssl);
13 int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
14 int SSL_get_verify_depth(SSL *ssl);
15 int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int, X509_STORE_CTX *);
16 int (*SSL_get_verify_callback(SSL *ssl))(int, X509_STORE_CTX *);
17
18=head1 DESCRIPTION
19
20SSL_CTX_get_verify_mode() returns the verification mode currently set in
21B<ctx>.
22
23SSL_get_verify_mode() returns the verification mode currently set in
24B<ssl>.
25
26SSL_CTX_get_verify_depth() returns the verification depth limit currently set
27in B<ctx>. If no limit has been explicitly set, -1 is returned and the
28default value will be used.
29
30SSL_get_verify_depth() returns the verification depth limit currently set
31in B<ssl>. If no limit has been explicitly set, -1 is returned and the
32default value will be used.
33
34SSL_CTX_get_verify_callback() returns a function pointer to the verification
35callback currently set in B<ctx>. If no callback was explicitly set, the
36NULL pointer is returned and the default callback will be used.
37
38SSL_get_verify_callback() returns a function pointer to the verification
39callback currently set in B<ssl>. If no callback was explicitly set, the
40NULL pointer is returned and the default callback will be used.
41
42=head1 RETURN VALUES
43
44See DESCRIPTION
45
46=head1 SEE ALSO
47
48L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
49
50=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_load_verify_locations.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_load_verify_locations.pod
new file mode 100644
index 0000000000..88f18bd5ff
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_load_verify_locations.pod
@@ -0,0 +1,124 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_load_verify_locations - set default locations for trusted CA
6certificates
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
13 const char *CApath);
14
15=head1 DESCRIPTION
16
17SSL_CTX_load_verify_locations() specifies the locations for B<ctx>, at
18which CA certificates for verification purposes are located. The certificates
19available via B<CAfile> and B<CApath> are trusted.
20
21=head1 NOTES
22
23If B<CAfile> is not NULL, it points to a file of CA certificates in PEM
24format. The file can contain several CA certificates identified by
25
26 -----BEGIN CERTIFICATE-----
27 ... (CA certificate in base64 encoding) ...
28 -----END CERTIFICATE-----
29
30sequences. Before, between, and after the certificates text is allowed
31which can be used e.g. for descriptions of the certificates.
32
33The B<CAfile> is processed on execution of the SSL_CTX_load_verify_locations()
34function.
35
36If on an TLS/SSL server no special setting is performed using *client_CA_list()
37functions, the certificates contained in B<CAfile> are listed to the client
38as available CAs during the TLS/SSL handshake.
39
40If B<CApath> is not NULL, it points to a directory containing CA certificates
41in PEM format. The files each contain one CA certificate. The files are
42looked up by the CA subject name hash value, which must hence be available.
43If more than one CA certificate with the same name hash value exist, the
44extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search
45is performed in the ordering of the extension number, regardless of other
46properties of the certificates.
47Use the B<c_rehash> utility to create the necessary links.
48
49The certificates in B<CApath> are only looked up when required, e.g. when
50building the certificate chain or when actually performing the verification
51of a peer certificate.
52
53On a server, the certificates in B<CApath> are not listed as available
54CA certificates to a client during a TLS/SSL handshake.
55
56When looking up CA certificates, the OpenSSL library will first search the
57certificates in B<CAfile>, then those in B<CApath>. Certificate matching
58is done based on the subject name, the key identifier (if present), and the
59serial number as taken from the certificate to be verified. If these data
60do not match, the next certificate will be tried. If a first certificate
61matching the parameters is found, the verification process will be performed;
62no other certificates for the same parameters will be searched in case of
63failure.
64
65When building its own certificate chain, an OpenSSL client/server will
66try to fill in missing certificates from B<CAfile>/B<CApath>, if the
67certificate chain was not explicitly specified (see
68L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
69L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>.
70
71=head1 WARNINGS
72
73If several CA certificates matching the name, key identifier, and serial
74number condition are available, only the first one will be examined. This
75may lead to unexpected results if the same CA certificate is available
76with different expiration dates. If a "certificate expired" verification
77error occurs, no other certificate will be searched. Make sure to not
78have expired certificates mixed with valid ones.
79
80=head1 EXAMPLES
81
82Generate a CA certificate file with descriptive text from the CA certificates
83ca1.pem ca2.pem ca3.pem:
84
85 #!/bin/sh
86 rm CAfile.pem
87 for i in ca1.pem ca2.pem ca3.pem ; do
88 openssl x509 -in $i -text >> CAfile.pem
89 done
90
91Prepare the directory /some/where/certs containing several CA certificates
92for use as B<CApath>:
93
94 cd /some/where/certs
95 c_rehash .
96
97=head1 RETURN VALUES
98
99The following return values can occur:
100
101=over 4
102
103=item 0
104
105The operation failed because B<CAfile> and B<CApath> are NULL or the
106processing at one of the locations specified failed. Check the error
107stack to find out the reason.
108
109=item 1
110
111The operation succeeded.
112
113=back
114
115=head1 SEE ALSO
116
117L<ssl(3)|ssl(3)>,
118L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
119L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
120L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
121L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
122
123
124=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_new.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_new.pod
new file mode 100644
index 0000000000..e166c692c3
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_new.pod
@@ -0,0 +1,93 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_new - create a new SSL_CTX object as framework for TLS/SSL enabled functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 SSL_CTX *SSL_CTX_new(SSL_METHOD *method);
12
13=head1 DESCRIPTION
14
15SSL_CTX_new() creates a new B<SSL_CTX> object as framework to establish
16TLS/SSL enabled connections.
17
18=head1 NOTES
19
20The SSL_CTX object uses B<method> as connection method. The methods exist
21in a generic type (for client and server use), a server only type, and a
22client only type. B<method> can be of the following types:
23
24=over 4
25
26=item SSLv2_method(void), SSLv2_server_method(void), SSLv2_client_method(void)
27
28A TLS/SSL connection established with these methods will only understand
29the SSLv2 protocol. A client will send out SSLv2 client hello messages
30and will also indicate that it only understand SSLv2. A server will only
31understand SSLv2 client hello messages.
32
33=item SSLv3_method(void), SSLv3_server_method(void), SSLv3_client_method(void)
34
35A TLS/SSL connection established with these methods will only understand the
36SSLv3 and TLSv1 protocol. A client will send out SSLv3 client hello messages
37and will indicate that it also understands TLSv1. A server will only understand
38SSLv3 and TLSv1 client hello messages. This especially means, that it will
39not understand SSLv2 client hello messages which are widely used for
40compatibility reasons, see SSLv23_*_method().
41
42=item TLSv1_method(void), TLSv1_server_method(void), TLSv1_client_method(void)
43
44A TLS/SSL connection established with these methods will only understand the
45TLSv1 protocol. A client will send out TLSv1 client hello messages
46and will indicate that it only understands TLSv1. A server will only understand
47TLSv1 client hello messages. This especially means, that it will
48not understand SSLv2 client hello messages which are widely used for
49compatibility reasons, see SSLv23_*_method().
50
51=item SSLv23_method(void), SSLv23_server_method(void), SSLv23_client_method(void)
52
53A TLS/SSL connection established with these methods will understand the SSLv2,
54SSLv3, and TLSv1 protocol. A client will send out SSLv2 client hello messages
55and will indicate that it also understands SSLv3 and TLSv1. A server will
56understand SSLv2, SSLv3, and TLSv1 client hello messages. This is the best
57choice when compatibility is a concern.
58
59=back
60
61The list of protocols available can later be limited using the SSL_OP_NO_SSLv2,
62SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1 options of the B<SSL_CTX_set_options()> or
63B<SSL_set_options()> functions. Using these options it is possible to choose
64e.g. SSLv23_server_method() and be able to negotiate with all possible
65clients, but to only allow newer protocols like SSLv3 or TLSv1.
66
67SSL_CTX_new() initializes the list of ciphers, the session cache setting,
68the callbacks, the keys and certificates, and the options to its default
69values.
70
71=head1 RETURN VALUES
72
73The following return values can occur:
74
75=over 4
76
77=item NULL
78
79The creation of a new SSL_CTX object failed. Check the error stack to
80find out the reason.
81
82=item Pointer to an SSL_CTX object
83
84The return value points to an allocated SSL_CTX object.
85
86=back
87
88=head1 SEE ALSO
89
90L<SSL_CTX_free(3)|SSL_CTX_free(3)>, L<SSL_accept(3)|SSL_accept(3)>,
91L<ssl(3)|ssl(3)>
92
93=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_number.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_number.pod
new file mode 100644
index 0000000000..19aa4e2902
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_number.pod
@@ -0,0 +1,76 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_sess_number(SSL_CTX *ctx);
12 long SSL_CTX_sess_connect(SSL_CTX *ctx);
13 long SSL_CTX_sess_connect_good(SSL_CTX *ctx);
14 long SSL_CTX_sess_connect_renegotiate(SSL_CTX *ctx);
15 long SSL_CTX_sess_accept(SSL_CTX *ctx);
16 long SSL_CTX_sess_accept_good(SSL_CTX *ctx);
17 long SSL_CTX_sess_accept_renegotiate(SSL_CTX *ctx);
18 long SSL_CTX_sess_hits(SSL_CTX *ctx);
19 long SSL_CTX_sess_cb_hits(SSL_CTX *ctx);
20 long SSL_CTX_sess_misses(SSL_CTX *ctx);
21 long SSL_CTX_sess_timeouts(SSL_CTX *ctx);
22 long SSL_CTX_sess_cache_full(SSL_CTX *ctx);
23
24=head1 DESCRIPTION
25
26SSL_CTX_sess_number() returns the current number of sessions in the internal
27session cache.
28
29SSL_CTX_sess_connect() returns the number of started SSL/TLS handshakes in
30client mode.
31
32SSL_CTX_sess_connect_good() returns the number of successfully established
33SSL/TLS sessions in client mode.
34
35SSL_CTX_sess_connect_renegotiate() returns the number of start renegotiations
36in client mode.
37
38SSL_CTX_sess_accept() returns the number of started SSL/TLS handshakes in
39server mode.
40
41SSL_CTX_sess_accept_good() returns the number of successfully established
42SSL/TLS sessions in server mode.
43
44SSL_CTX_sess_accept_renegotiate() returns the number of start renegotiations
45in server mode.
46
47SSL_CTX_sess_hits() returns the number of successfully reused sessions.
48In client mode a session set with L<SSL_set_session(3)|SSL_set_session(3)>
49successfully reused is counted as a hit. In server mode a session successfully
50retrieved from internal or external cache is counted as a hit.
51
52SSL_CTX_sess_cb_hits() returns the number of successfully retrieved sessions
53from the external session cache in server mode.
54
55SSL_CTX_sess_misses() returns the number of sessions proposed by clients
56that were not found in the internal session cache in server mode.
57
58SSL_CTX_sess_timeouts() returns the number of sessions proposed by clients
59and either found in the internal or external session cache in server mode,
60 but that were invalid due to timeout. These sessions are not included in
61the SSL_CTX_sess_hits() count.
62
63SSL_CTX_sess_cache_full() returns the number of sessions that were removed
64because the maximum session cache size was exceeded.
65
66=head1 RETURN VALUES
67
68The functions return the values indicated in the DESCRIPTION section.
69
70=head1 SEE ALSO
71
72L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
73L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
74L<SSL_CTX_sess_set_cache_size(3)|SSL_CTX_sess_set_cache_size(3)>
75
76=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_cache_size.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_cache_size.pod
new file mode 100644
index 0000000000..d59a7db636
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_cache_size.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_sess_set_cache_size, SSL_CTX_sess_get_cache_size - manipulate session cache size
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, long t);
12 long SSL_CTX_sess_get_cache_size(SSL_CTX *ctx);
13
14=head1 DESCRIPTION
15
16SSL_CTX_sess_set_cache_size() sets the size of the internal session cache
17of context B<ctx> to B<t>.
18
19SSL_CTX_sess_get_cache_size() returns the currently valid session cache size.
20
21=head1 NOTES
22
23The internal session cache size is SSL_SESSION_CACHE_MAX_SIZE_DEFAULT,
24currently 1024*20, so that up to 20000 sessions can be held. This size
25can be modified using the SSL_CTX_sess_set_cache_size() call. A special
26case is the size 0, which is used for unlimited size.
27
28When the maximum number of sessions is reached, no more new sessions are
29added to the cache. New space may be added by calling
30L<SSL_CTX_flush_sessions(3)|<SSL_CTX_flush_sessions(3)> to remove
31expired sessions.
32
33If the size of the session cache is reduced and more sessions are already
34in the session cache, old session will be removed at the next time a
35session shall be added. This removal is not synchronized with the
36expiration of sessions.
37
38=head1 RETURN VALUES
39
40SSL_CTX_sess_set_cache_size() returns the previously valid size.
41
42SSL_CTX_sess_get_cache_size() returns the currently valid size.
43
44=head1 SEE ALSO
45
46L<ssl(3)|ssl(3)>,
47L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
48L<SSL_CTX_sess_number(3)|SSL_CTX_sess_number(3)>,
49L<SSL_CTX_flush_sessions(3)|<SSL_CTX_flush_sessions(3)>
50
51=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_get_cb.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_get_cb.pod
new file mode 100644
index 0000000000..b6f15b4404
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_sess_set_get_cb.pod
@@ -0,0 +1,81 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
12 int (*new_session_cb)(SSL *, SSL_SESSION *));
13 void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
14 void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *));
15 void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
16 SSL_SESSION (*get_session_cb)(SSL *, unsigned char *, int, int *));
17
18 int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, SSL_SESSION *sess);
19 void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
20 SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, unsigned char *data, int len, int *copy);
21
22 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
23 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
24 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,
25 int len, int *copy);
26
27=head1 DESCRIPTION
28
29SSL_CTX_sess_set_new_cb() sets the callback function, which is automatically
30called whenever a new session was negotiated.
31
32SSL_CTX_sess_set_remove_cb() sets the callback function, which is
33automatically called whenever a session is removed by the SSL engine,
34because it is considered faulty or the session has become obsolete because
35of exceeding the timeout value.
36
37SSL_CTX_sess_set_get_cb() sets the callback function which is called,
38whenever a SSL/TLS client proposed to resume a session but the session
39could not be found in the internal session cache (see
40L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>).
41(SSL/TLS server only.)
42
43SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb(), and
44SSL_CTX_sess_get_get_cb() allow to retrieve the function pointers of the
45provided callback functions. If a callback function has not been set,
46the NULL pointer is returned.
47
48=head1 NOTES
49
50In order to allow external session caching, synchronization with the internal
51session cache is realized via callback functions. Inside these callback
52functions, session can be saved to disk or put into a database using the
53L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)> interface.
54
55The new_session_cb() is called, whenever a new session has been negotiated
56and session caching is enabled (see
57L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>).
58The new_session_cb() is passed the B<ssl> connection and the ssl session
59B<sess>. If the callback returns B<0>, the session will be immediately
60removed again.
61
62The remove_session_cb() is called, whenever the SSL engine removes a session
63from the internal cache. This happens if the session is removed because
64it is expired or when a connection was not shutdown cleanly. The
65remove_session_cb() is passed the B<ctx> and the ssl session B<sess>.
66It does not provide any feedback.
67
68The get_session_cb() is only called on SSL/TLS servers with the session id
69proposed by the client. The get_session_cb() is always called, also when
70session caching was disabled. The get_session_cb() is passed the
71B<ssl> connection, the session id of length B<length> at the memory location
72B<data>. With the parameter B<copy> the callback can require the
73SSL engine to increment the reference count of the SSL_SESSION object.
74
75=head1 SEE ALSO
76
77L<ssl(3)|ssl(3)>, L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)>,
78L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
79L<SSL_CTX_flush_sessions(3)|<SSL_CTX_flush_sessions(3)>
80
81=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_sessions.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_sessions.pod
new file mode 100644
index 0000000000..e05aab3c1b
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_sessions.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_sessions - access internal session cache
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
12
13=head1 DESCRIPTION
14
15SSL_CTX_sessions() returns a pointer to the lhash databases containing the
16internal session cache for B<ctx>.
17
18=head1 NOTES
19
20The sessions in the internal session cache are kept in an
21L<lhash(3)|lhash(3)> type database. It is possible to directly
22access this database e.g. for searching. In parallel, the sessions
23form a linked list which is maintained separately from the
24L<lhash(3)|lhash(3)> operations, so that the database must not be
25modified directly but by using the
26L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)> family of functions.
27
28=head1 SEE ALSO
29
30L<ssl(3)|ssl(3)>, L<lhash(3)|lhash(3)>,
31L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)>,
32L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
33
34=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_store.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_store.pod
new file mode 100644
index 0000000000..81286ee650
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_store.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_cert_store, SSL_CTX_get_cert_store - manipulate X509 certificate verification storage
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store);
12 X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx);
13
14=head1 DESCRIPTION
15
16SSL_CTX_set_cert_store() sets/replaces the certificate verification storage
17of B<ctx> to/with B<store>. If another X505_STORE object is currently
18set in B<ctx>, it will be X509_STORE_free()ed.
19
20SSL_CTX_get_cert_store() returns a pointer to the current certificate
21verification storage.
22
23=head1 NOTES
24
25In order to verify the certificates presented by the peer, trusted CA
26certificates must be accessed. These CA certificates are made available
27via lookup methods, handled inside the X509_STORE. From the X509_STORE
28the X509_STORE_CTX used when verifying certificates is created.
29
30Typically the trusted certificate store is handled indirectly via using
31L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
32Using the SSL_CTX_set_cert_store() and SSL_CTX_get_cert_store() functions
33it is possible to manipulate the X509_STORE object beyond the
34L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
35call.
36
37Currently no detailed documentation on how to use the X509_STORE
38object is available. Not all members of the X509_STORE are used when
39the verification takes place. So will e.g. the verify_callback() be
40overridden with the verify_callback() set via the
41L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)> family of functions.
42This document must therefore be updated when documentation about the
43X509_STORE object and its handling becomes available.
44
45=head1 RETURN VALUES
46
47SSL_CTX_set_cert_store() does not return diagnostic output.
48
49SSL_CTX_get_cert_store() returns the current setting.
50
51=head1 SEE ALSO
52
53L<ssl(3)|ssl(3)>,
54L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
55L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
56
57=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_verify_callback.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_verify_callback.pod
new file mode 100644
index 0000000000..c0f4f85708
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cert_verify_callback.pod
@@ -0,0 +1,75 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_cert_verify_callback - set peer certificate verification procedure
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*callback)(X509_STORE_CTX *,void *), void *arg);
12
13=head1 DESCRIPTION
14
15SSL_CTX_set_cert_verify_callback() sets the verification callback function for
16I<ctx>. SSL objects that are created from I<ctx> inherit the setting valid at
17the time when L<SSL_new(3)|SSL_new(3)> is called.
18
19=head1 NOTES
20
21Whenever a certificate is verified during a SSL/TLS handshake, a verification
22function is called. If the application does not explicitly specify a
23verification callback function, the built-in verification function is used.
24If a verification callback I<callback> is specified via
25SSL_CTX_set_cert_verify_callback(), the supplied callback function is called
26instead. By setting I<callback> to NULL, the default behaviour is restored.
27
28When the verification must be performed, I<callback> will be called with
29the arguments callback(X509_STORE_CTX *x509_store_ctx, void *arg). The
30argument I<arg> is specified by the application when setting I<callback>.
31
32I<callback> should return 1 to indicate verification success and 0 to
33indicate verification failure. If SSL_VERIFY_PEER is set and I<callback>
34returns 0, the handshake will fail. As the verification procedure may
35allow to continue the connection in case of failure (by always returning 1)
36the verification result must be set in any case using the B<error>
37member of I<x509_store_ctx> so that the calling application will be informed
38about the detailed result of the verification procedure!
39
40Within I<x509_store_ctx>, I<callback> has access to the I<verify_callback>
41function set using L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>.
42
43=head1 WARNINGS
44
45Do not mix the verification callback described in this function with the
46B<verify_callback> function called during the verification process. The
47latter is set using the L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
48family of functions.
49
50Providing a complete verification procedure including certificate purpose
51settings etc is a complex task. The built-in procedure is quite powerful
52and in most cases it should be sufficient to modify its behaviour using
53the B<verify_callback> function.
54
55=head1 BUGS
56
57=head1 RETURN VALUES
58
59SSL_CTX_set_cert_verify_callback() does not provide diagnostic information.
60
61=head1 SEE ALSO
62
63L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
64L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
65L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
66
67=head1 HISTORY
68
69Previous to OpenSSL 0.9.7, the I<arg> argument to B<SSL_CTX_set_cert_verify_callback>
70was ignored, and I<callback> was called simply as
71 int (*callback)(X509_STORE_CTX *)
72To compile software written for previous versions of OpenSSL, a dummy
73argument will have to be added to I<callback>.
74
75=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cipher_list.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cipher_list.pod
new file mode 100644
index 0000000000..272d6b3de2
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_cipher_list.pod
@@ -0,0 +1,52 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_cipher_list, SSL_set_cipher_list
6- choose list of available SSL_CIPHERs
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
13 int SSL_set_cipher_list(SSL *ssl, const char *str);
14
15=head1 DESCRIPTION
16
17SSL_CTX_set_cipher_list() sets the list of available ciphers for B<ctx>
18using the control string B<str>. The format of the string is described
19in L<ciphers(1)|ciphers(1)>. The list of ciphers is inherited by all
20B<ssl> objects created from B<ctx>.
21
22SSL_set_cipher_list() sets the list of ciphers only for B<ssl>.
23
24=head1 NOTES
25
26The control string B<str> should be universally usable and not depend
27on details of the library configuration (ciphers compiled in). Thus no
28syntax checking takes place. Items that are not recognized, because the
29corresponding ciphers are not compiled in or because they are mistyped,
30are simply ignored. Failure is only flagged if no ciphers could be collected
31at all.
32
33It should be noted, that inclusion of a cipher to be used into the list is
34a necessary condition. On the client side, the inclusion into the list is
35also sufficient. On the server side, additional restrictions apply. All ciphers
36have additional requirements. ADH ciphers don't need a certificate, but
37DH-parameters must have been set. All other ciphers need a corresponding
38certificate and key. A RSA cipher can only be chosen, when a RSA certificate is
39available, the respective is valid for DSA ciphers. Ciphers using EDH need
40a certificate and key and DH-parameters.
41
42=head1 RETURN VALUES
43
44SSL_CTX_set_cipher_list() and SSL_set_cipher_list() return 1 if any cipher
45could be selected and 0 on complete failure.
46
47=head1 SEE ALSO
48
49L<ssl(3)|ssl(3)>, L<SSL_get_ciphers(3)|SSL_get_ciphers(3)>,
50L<ciphers(1)|ciphers(1)>
51
52=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_CA_list.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_CA_list.pod
new file mode 100644
index 0000000000..81e312761e
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_CA_list.pod
@@ -0,0 +1,90 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_client_CA_list, SSL_set_client_CA_list, SSL_CTX_add_client_CA,
6SSL_add_client_CA - set list of CAs sent to the client when requesting a
7client certificate
8
9=head1 SYNOPSIS
10
11 #include <openssl/ssl.h>
12
13 void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
14 void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
15 int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *cacert);
16 int SSL_add_client_CA(SSL *ssl, X509 *cacert);
17
18=head1 DESCRIPTION
19
20SSL_CTX_set_client_CA_list() sets the B<list> of CAs sent to the client when
21requesting a client certificate for B<ctx>.
22
23SSL_set_client_CA_list() sets the B<list> of CAs sent to the client when
24requesting a client certificate for the chosen B<ssl>, overriding the
25setting valid for B<ssl>'s SSL_CTX object.
26
27SSL_CTX_add_client_CA() adds the CA name extracted from B<cacert> to the
28list of CAs sent to the client when requesting a client certificate for
29B<ctx>.
30
31SSL_add_client_CA() adds the CA name extracted from B<cacert> to the
32list of CAs sent to the client when requesting a client certificate for
33the chosen B<ssl>, overriding the setting valid for B<ssl>'s SSL_CTX object.
34
35=head1 NOTES
36
37When a TLS/SSL server requests a client certificate (see
38B<SSL_CTX_set_verify_options()>), it sends a list of CAs, for which
39it will accept certificates, to the client. If no special list is provided,
40the CAs available using the B<CAfile> option in
41L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
42are sent.
43
44This list can be explicitly set using the SSL_CTX_set_client_CA_list() for
45B<ctx> and SSL_set_client_CA_list() for the specific B<ssl>. The list
46specified overrides the previous setting. The CAs listed do not become
47trusted (B<list> only contains the names, not the complete certificates); use
48L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
49to additionally load them for verification.
50
51SSL_CTX_add_client_CA() and SSL_add_client_CA() can be used to add additional
52items the list of client CAs. If no list was specified before using
53SSL_CTX_set_client_CA_list() or SSL_set_client_CA_list(), a new client
54CA list for B<ctx> or B<ssl> (as appropriate) is opened. The CAs implicitly
55specified using
56L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
57are no longer used automatically.
58
59These functions are only useful for TLS/SSL servers.
60
61=head1 RETURN VALUES
62
63SSL_CTX_set_client_CA_list() and SSL_set_client_CA_list() do not return
64diagnostic information.
65
66SSL_CTX_add_client_CA() and SSL_add_client_CA() have the following return
67values:
68
69=over 4
70
71=item 1
72
73The operation succeeded.
74
75=item 0
76
77A failure while manipulating the STACK_OF(X509_NAME) object occurred or
78the X509_NAME could not be extracted from B<cacert>. Check the error stack
79to find out the reason.
80
81=back
82
83=head1 SEE ALSO
84
85L<ssl(3)|ssl(3)>,
86L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
87L<SSL_load_client_CA_file(3)|SSL_load_client_CA_file(3)>
88L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
89
90=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_cert_cb.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_cert_cb.pod
new file mode 100644
index 0000000000..53e1827713
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_client_cert_cb.pod
@@ -0,0 +1,90 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_client_cert_cb, SSL_CTX_get_client_cert_cb - handle client certificate callback function
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
12 int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
13 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
14
15=head1 DESCRIPTION
16
17SSL_CTX_set_client_cert_cb() sets the B<client_cert_cb()> callback, that is
18called when a client certificate is requested by a server.
19When B<client_cert_cb()> is NULL, not callback function is used.
20
21SSL_CTX_get_client_cert_cb() returns a pointer to the currently set callback
22function.
23
24client_cert_cb() is the application defined callback. If it wants to
25set a certificate, a certificate/private key combination must be set
26using the B<x509> and B<pkey> arguments and "1" must be returned. The
27certificate will be installed into B<ssl>, see the NOTES and BUGS sections.
28If no certificate should be set, "0" has to be returned and the default
29certificate will be sent. A fatal error can be indicated by returning
30a negative value, in which case the handshake will be canceled.
31
32=head1 NOTES
33
34During a handshake (or renegotiation) a server may request a certificate
35from the client. A client certificate must only be sent, when the server
36did send the request.
37
38When no callback function is set, an OpenSSL client will send the certificate
39that was set using the
40L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)> family of functions.
41The TLS standard requires that only a certificate is sent, if it matches
42the list of acceptable CAs sent by the server. This constraint is
43violated by the default behavior of the OpenSSL library. Using the
44callback function it is possible to implement a proper selection routine
45or to allow a user interaction to choose the certificate to be sent.
46The callback function can obtain the list of acceptable CAs using the
47L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)> function.
48
49If a callback function is defined, the callback function will be called.
50If the callback function returns a certificate, the OpenSSL library
51will try to load the private key and certificate data into the SSL
52object using SSL_use_certificate() and SSL_use_private_key() functions.
53Thus it will permanently override the certificate and key previously
54installed and will not be reset by calling L<SSL_clear(3)|SSL_clear(3)>.
55If the callback returns no certificate, the OpenSSL library will send
56the certificate previously installed for the SSL_CTX object or the specific
57certificate of the SSL object, if available.
58
59=head1 BUGS
60
61The client_cert_cb() cannot return a complete certificate chain, it can
62only return one client certificate. If the chain only has a length of 2,
63the root CA certificate may be omitted according to the TLS standard and
64thus a standard conforming answer can be sent to the server. For a
65longer chain, the client must send the complete chain (with the option
66to leave out the root CA certificate). This can only be accomplished by
67either adding the intermediate CA certificates into the trusted
68certificate store for the SSL_CTX object (resulting in having to add
69CA certificates that otherwise maybe would not be trusted), or by adding
70the chain certificates using the
71L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
72function, which is only available for the SSL_CTX object as a whole and that
73therefore probably can only apply for one client certificate, making
74the concept of the callback function (to allow the choice from several
75certificates) questionable.
76
77Once the SSL object has been used in conjunction with the callback function,
78the certificate will be set for the SSL object and will not be cleared
79even when L<SSL_clear(3)|SSL_clear(3)> is being called. It is therefore
80mandatory to destroy the SSL object using L<SSL_free(3)|SSL_free(3)>
81and create a new one to return to the previous state.
82
83=head1 SEE ALSO
84
85L<ssl(3)|ssl(3)>, L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
86L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
87L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
88L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
89
90=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_default_passwd_cb.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_default_passwd_cb.pod
new file mode 100644
index 0000000000..a5343a1cf3
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_default_passwd_cb.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata - set passwd callback for encrypted PEM file handling
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
12 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
13
14 int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
15
16=head1 DESCRIPTION
17
18SSL_CTX_set_default_passwd_cb() sets the default password callback called
19when loading/storing a PEM certificate with encryption.
20
21SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to B<userdata> which
22will be provided to the password callback on invocation.
23
24The pem_passwd_cb(), which must be provided by the application, hands back the
25password to be used during decryption. On invocation a pointer to B<userdata>
26is provided. The pem_passwd_cb must write the password into the provided buffer
27B<buf> which is of size B<size>. The actual length of the password must
28be returned to the calling function. B<rwflag> indicates whether the
29callback is used for reading/decryption (rwflag=0) or writing/encryption
30(rwflag=1).
31
32=head1 NOTES
33
34When loading or storing private keys, a password might be supplied to
35protect the private key. The way this password can be supplied may depend
36on the application. If only one private key is handled, it can be practical
37to have pem_passwd_cb() handle the password dialog interactively. If several
38keys have to be handled, it can be practical to ask for the password once,
39then keep it in memory and use it several times. In the last case, the
40password could be stored into the B<userdata> storage and the
41pem_passwd_cb() only returns the password already stored.
42
43Other items in PEM formatting (certificates) can also be encrypted, it is
44however not usual, as certificate information is considered public.
45
46=head1 RETURN VALUES
47
48SSL_CTX_set_default_passwd_cb() and SSL_CTX_set_default_passwd_cb_userdata()
49do not provide diagnostic information.
50
51=head1 EXAMPLES
52
53The following example returns the password provided as B<userdata> to the
54calling function. The password is considered to be a '\0' terminated
55string. If the password does not fit into the buffer, the password is
56truncated.
57
58 int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
59 {
60 strncpy(buf, (char *)(password), size);
61 buf[size - 1] = '\0';
62 return(strlen(buf));
63 }
64
65=head1 SEE ALSO
66
67L<ssl(3)|ssl(3)>,
68L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>
69
70=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_generate_session_id.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_generate_session_id.pod
new file mode 100644
index 0000000000..798e8443a7
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_generate_session_id.pod
@@ -0,0 +1,150 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_generate_session_id, SSL_set_generate_session_id, SSL_has_matching_session_id - manipulate generation of SSL session IDs (server only)
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
12 unsigned int *id_len);
13
14 int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
15 int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB, cb);
16 int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
17 unsigned int id_len);
18
19=head1 DESCRIPTION
20
21SSL_CTX_set_generate_session_id() sets the callback function for generating
22new session ids for SSL/TLS sessions for B<ctx> to be B<cb>.
23
24SSL_set_generate_session_id() sets the callback function for generating
25new session ids for SSL/TLS sessions for B<ssl> to be B<cb>.
26
27SSL_has_matching_session_id() checks, whether a session with id B<id>
28(of length B<id_len>) is already contained in the internal session cache
29of the parent context of B<ssl>.
30
31=head1 NOTES
32
33When a new session is established between client and server, the server
34generates a session id. The session id is an arbitrary sequence of bytes.
35The length of the session id is 16 bytes for SSLv2 sessions and between
361 and 32 bytes for SSLv3/TLSv1. The session id is not security critical
37but must be unique for the server. Additionally, the session id is
38transmitted in the clear when reusing the session so it must not contain
39sensitive information.
40
41Without a callback being set, an OpenSSL server will generate a unique
42session id from pseudo random numbers of the maximum possible length.
43Using the callback function, the session id can be changed to contain
44additional information like e.g. a host id in order to improve load balancing
45or external caching techniques.
46
47The callback function receives a pointer to the memory location to put
48B<id> into and a pointer to the maximum allowed length B<id_len>. The
49buffer at location B<id> is only guaranteed to have the size B<id_len>.
50The callback is only allowed to generate a shorter id and reduce B<id_len>;
51the callback B<must never> increase B<id_len> or write to the location
52B<id> exceeding the given limit.
53
54If a SSLv2 session id is generated and B<id_len> is reduced, it will be
55restored after the callback has finished and the session id will be padded
56with 0x00. It is not recommended to change the B<id_len> for SSLv2 sessions.
57The callback can use the L<SSL_get_version(3)|SSL_get_version(3)> function
58to check, whether the session is of type SSLv2.
59
60The location B<id> is filled with 0x00 before the callback is called, so the
61callback may only fill part of the possible length and leave B<id_len>
62untouched while maintaining reproducibility.
63
64Since the sessions must be distinguished, session ids must be unique.
65Without the callback a random number is used, so that the probability
66of generating the same session id is extremely small (2^128 possible ids
67for an SSLv2 session, 2^256 for SSLv3/TLSv1). In order to assure the
68uniqueness of the generated session id, the callback must call
69SSL_has_matching_session_id() and generate another id if a conflict occurs.
70If an id conflict is not resolved, the handshake will fail.
71If the application codes e.g. a unique host id, a unique process number, and
72a unique sequence number into the session id, uniqueness could easily be
73achieved without randomness added (it should however be taken care that
74no confidential information is leaked this way). If the application can not
75guarantee uniqueness, it is recommended to use the maximum B<id_len> and
76fill in the bytes not used to code special information with random data
77to avoid collisions.
78
79SSL_has_matching_session_id() will only query the internal session cache,
80not the external one. Since the session id is generated before the
81handshake is completed, it is not immediately added to the cache. If
82another thread is using the same internal session cache, a race condition
83can occur in that another thread generates the same session id.
84Collisions can also occur when using an external session cache, since
85the external cache is not tested with SSL_has_matching_session_id()
86and the same race condition applies.
87
88When calling SSL_has_matching_session_id() for an SSLv2 session with
89reduced B<id_len>, the match operation will be performed using the
90fixed length required and with a 0x00 padded id.
91
92The callback must return 0 if it cannot generate a session id for whatever
93reason and return 1 on success.
94
95=head1 EXAMPLES
96
97The callback function listed will generate a session id with the
98server id given, and will fill the rest with pseudo random bytes:
99
100 const char session_id_prefix = "www-18";
101
102 #define MAX_SESSION_ID_ATTEMPTS 10
103 static int generate_session_id(const SSL *ssl, unsigned char *id,
104 unsigned int *id_len)
105 {
106 unsigned int count = 0;
107 const char *version;
108
109 version = SSL_get_version(ssl);
110 if (!strcmp(version, "SSLv2"))
111 /* we must not change id_len */;
112
113 do {
114 RAND_pseudo_bytes(id, *id_len);
115 /* Prefix the session_id with the required prefix. NB: If our
116 * prefix is too long, clip it - but there will be worse effects
117 * anyway, eg. the server could only possibly create 1 session
118 * ID (ie. the prefix!) so all future session negotiations will
119 * fail due to conflicts. */
120 memcpy(id, session_id_prefix,
121 (strlen(session_id_prefix) < *id_len) ?
122 strlen(session_id_prefix) : *id_len);
123 }
124 while(SSL_has_matching_session_id(ssl, id, *id_len) &&
125 (++count < MAX_SESSION_ID_ATTEMPTS));
126 if(count >= MAX_SESSION_ID_ATTEMPTS)
127 return 0;
128 return 1;
129 }
130
131
132=head1 RETURN VALUES
133
134SSL_CTX_set_generate_session_id() and SSL_set_generate_session_id()
135always return 1.
136
137SSL_has_matching_session_id() returns 1 if another session with the
138same id is already in the cache.
139
140=head1 SEE ALSO
141
142L<ssl(3)|ssl(3)>, L<SSL_get_version(3)|SSL_get_version(3)>
143
144=head1 HISTORY
145
146SSL_CTX_set_generate_session_id(), SSL_set_generate_session_id()
147and SSL_has_matching_session_id() have been introduced in
148OpenSSL 0.9.7.
149
150=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_info_callback.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_info_callback.pod
new file mode 100644
index 0000000000..63d0b8d33f
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_info_callback.pod
@@ -0,0 +1,153 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_info_callback, SSL_CTX_get_info_callback, SSL_set_info_callback, SSL_get_info_callback - handle information callback for SSL connections
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*callback)());
12 void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))();
13
14 void SSL_set_info_callback(SSL *ssl, void (*callback)());
15 void (*SSL_get_info_callback(SSL *ssl))();
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_info_callback() sets the B<callback> function, that can be used to
20obtain state information for SSL objects created from B<ctx> during connection
21setup and use. The setting for B<ctx> is overridden from the setting for
22a specific SSL object, if specified.
23When B<callback> is NULL, not callback function is used.
24
25SSL_set_info_callback() sets the B<callback> function, that can be used to
26obtain state information for B<ssl> during connection setup and use.
27When B<callback> is NULL, the callback setting currently valid for
28B<ctx> is used.
29
30SSL_CTX_get_info_callback() returns a pointer to the currently set information
31callback function for B<ctx>.
32
33SSL_get_info_callback() returns a pointer to the currently set information
34callback function for B<ssl>.
35
36=head1 NOTES
37
38When setting up a connection and during use, it is possible to obtain state
39information from the SSL/TLS engine. When set, an information callback function
40is called whenever the state changes, an alert appears, or an error occurs.
41
42The callback function is called as B<callback(SSL *ssl, int where, int ret)>.
43The B<where> argument specifies information about where (in which context)
44the callback function was called. If B<ret> is 0, an error condition occurred.
45If an alert is handled, SSL_CB_ALERT is set and B<ret> specifies the alert
46information.
47
48B<where> is a bitmask made up of the following bits:
49
50=over 4
51
52=item SSL_CB_LOOP
53
54Callback has been called to indicate state change inside a loop.
55
56=item SSL_CB_EXIT
57
58Callback has been called to indicate error exit of a handshake function.
59(May be soft error with retry option for non-blocking setups.)
60
61=item SSL_CB_READ
62
63Callback has been called during read operation.
64
65=item SSL_CB_WRITE
66
67Callback has been called during write operation.
68
69=item SSL_CB_ALERT
70
71Callback has been called due to an alert being sent or received.
72
73=item SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
74
75=item SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
76
77=item SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
78
79=item SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
80
81=item SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
82
83=item SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
84
85=item SSL_CB_HANDSHAKE_START
86
87Callback has been called because a new handshake is started.
88
89=item SSL_CB_HANDSHAKE_DONE 0x20
90
91Callback has been called because a handshake is finished.
92
93=back
94
95The current state information can be obtained using the
96L<SSL_state_string(3)|SSL_state_string(3)> family of functions.
97
98The B<ret> information can be evaluated using the
99L<SSL_alert_type_string(3)|SSL_alert_type_string(3)> family of functions.
100
101=head1 RETURN VALUES
102
103SSL_set_info_callback() does not provide diagnostic information.
104
105SSL_get_info_callback() returns the current setting.
106
107=head1 EXAMPLES
108
109The following example callback function prints state strings, information
110about alerts being handled and error messages to the B<bio_err> BIO.
111
112 void apps_ssl_info_callback(SSL *s, int where, int ret)
113 {
114 const char *str;
115 int w;
116
117 w=where& ~SSL_ST_MASK;
118
119 if (w & SSL_ST_CONNECT) str="SSL_connect";
120 else if (w & SSL_ST_ACCEPT) str="SSL_accept";
121 else str="undefined";
122
123 if (where & SSL_CB_LOOP)
124 {
125 BIO_printf(bio_err,"%s:%s\n",str,SSL_state_string_long(s));
126 }
127 else if (where & SSL_CB_ALERT)
128 {
129 str=(where & SSL_CB_READ)?"read":"write";
130 BIO_printf(bio_err,"SSL3 alert %s:%s:%s\n",
131 str,
132 SSL_alert_type_string_long(ret),
133 SSL_alert_desc_string_long(ret));
134 }
135 else if (where & SSL_CB_EXIT)
136 {
137 if (ret == 0)
138 BIO_printf(bio_err,"%s:failed in %s\n",
139 str,SSL_state_string_long(s));
140 else if (ret < 0)
141 {
142 BIO_printf(bio_err,"%s:error in %s\n",
143 str,SSL_state_string_long(s));
144 }
145 }
146 }
147
148=head1 SEE ALSO
149
150L<ssl(3)|ssl(3)>, L<SSL_state_string(3)|SSL_state_string(3)>,
151L<SSL_alert_type_string(3)|SSL_alert_type_string(3)>
152
153=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_max_cert_list.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_max_cert_list.pod
new file mode 100644
index 0000000000..da68cb9fc2
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_max_cert_list.pod
@@ -0,0 +1,77 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_set_max_cert_list(SSL_CTX *ctx, long size);
12 long SSL_CTX_get_max_cert_list(SSL_CTX *ctx);
13
14 long SSL_set_max_cert_list(SSL *ssl, long size);
15 long SSL_get_max_cert_list(SSL *ctx);
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_max_cert_list() sets the maximum size allowed for the peer's
20certificate chain for all SSL objects created from B<ctx> to be <size> bytes.
21The SSL objects inherit the setting valid for B<ctx> at the time
22L<SSL_new(3)|SSL_new(3)> is being called.
23
24SSL_CTX_get_max_cert_list() returns the currently set maximum size for B<ctx>.
25
26SSL_set_max_cert_list() sets the maximum size allowed for the peer's
27certificate chain for B<ssl> to be <size> bytes. This setting stays valid
28until a new value is set.
29
30SSL_get_max_cert_list() returns the currently set maximum size for B<ssl>.
31
32=head1 NOTES
33
34During the handshake process, the peer may send a certificate chain.
35The TLS/SSL standard does not give any maximum size of the certificate chain.
36The OpenSSL library handles incoming data by a dynamically allocated buffer.
37In order to prevent this buffer from growing without bounds due to data
38received from a faulty or malicious peer, a maximum size for the certificate
39chain is set.
40
41The default value for the maximum certificate chain size is 100kB (30kB
42on the 16bit DOS platform). This should be sufficient for usual certificate
43chains (OpenSSL's default maximum chain length is 10, see
44L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>, and certificates
45without special extensions have a typical size of 1-2kB).
46
47For special applications it can be necessary to extend the maximum certificate
48chain size allowed to be sent by the peer, see e.g. the work on
49"Internet X.509 Public Key Infrastructure Proxy Certificate Profile"
50and "TLS Delegation Protocol" at http://www.ietf.org/ and
51http://www.globus.org/ .
52
53Under normal conditions it should never be necessary to set a value smaller
54than the default, as the buffer is handled dynamically and only uses the
55memory actually required by the data sent by the peer.
56
57If the maximum certificate chain size allowed is exceeded, the handshake will
58fail with a SSL_R_EXCESSIVE_MESSAGE_SIZE error.
59
60=head1 RETURN VALUES
61
62SSL_CTX_set_max_cert_list() and SSL_set_max_cert_list() return the previously
63set value.
64
65SSL_CTX_get_max_cert_list() and SSL_get_max_cert_list() return the currently
66set value.
67
68=head1 SEE ALSO
69
70L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>,
71L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
72
73=head1 HISTORY
74
75SSL*_set/get_max_cert_list() have been introduced in OpenSSL 0.9.7.
76
77=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_mode.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_mode.pod
new file mode 100644
index 0000000000..9a035bb4d1
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_mode.pod
@@ -0,0 +1,78 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_mode, SSL_set_mode, SSL_CTX_get_mode, SSL_get_mode - manipulate SSL engine mode
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_set_mode(SSL_CTX *ctx, long mode);
12 long SSL_set_mode(SSL *ssl, long mode);
13
14 long SSL_CTX_get_mode(SSL_CTX *ctx);
15 long SSL_get_mode(SSL *ssl);
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_mode() adds the mode set via bitmask in B<mode> to B<ctx>.
20Options already set before are not cleared.
21
22SSL_set_mode() adds the mode set via bitmask in B<mode> to B<ssl>.
23Options already set before are not cleared.
24
25SSL_CTX_get_mode() returns the mode set for B<ctx>.
26
27SSL_get_mode() returns the mode set for B<ssl>.
28
29=head1 NOTES
30
31The following mode changes are available:
32
33=over 4
34
35=item SSL_MODE_ENABLE_PARTIAL_WRITE
36
37Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
38when just a single record has been written). When not set (the default),
39SSL_write() will only report success once the complete chunk was written.
40
41=item SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
42
43Make it possible to retry SSL_write() with changed buffer location
44(the buffer contents must stay the same). This is not the default to avoid
45the misconception that non-blocking SSL_write() behaves like
46non-blocking write().
47
48=item SSL_MODE_AUTO_RETRY
49
50Never bother the application with retries if the transport is blocking.
51If a renegotiation take place during normal operation, a
52L<SSL_read(3)|SSL_read(3)> or L<SSL_write(3)|SSL_write(3)> would return
53with -1 and indicate the need to retry with SSL_ERROR_WANT_READ.
54In a non-blocking environment applications must be prepared to handle
55incomplete read/write operations.
56In a blocking environment, applications are not always prepared to
57deal with read/write operations returning without success report. The
58flag SSL_MODE_AUTO_RETRY will cause read/write operations to only
59return after the handshake and successful completion.
60
61=back
62
63=head1 RETURN VALUES
64
65SSL_CTX_set_mode() and SSL_set_mode() return the new mode bitmask
66after adding B<mode>.
67
68SSL_CTX_get_mode() and SSL_get_mode() return the current bitmask.
69
70=head1 SEE ALSO
71
72L<ssl(3)|ssl(3)>, L<SSL_read(3)|SSL_read(3)>, L<SSL_write(3)|SSL_write(3)>
73
74=head1 HISTORY
75
76SSL_MODE_AUTO_RETRY as been added in OpenSSL 0.9.6.
77
78=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_msg_callback.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_msg_callback.pod
new file mode 100644
index 0000000000..a423932d0a
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_msg_callback.pod
@@ -0,0 +1,97 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 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));
12 void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
13
14 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));
15 void SSL_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_msg_callback() or SSL_set_msg_callback() can be used to
20define a message callback function I<cb> for observing all SSL/TLS
21protocol messages (such as handshake messages) that are received or
22sent. SSL_CTX_set_msg_callback_arg() and SSL_set_msg_callback_arg()
23can be used to set argument I<arg> to the callback function, which is
24available for arbitrary application use.
25
26SSL_CTX_set_msg_callback() and SSL_CTX_set_msg_callback_arg() specify
27default settings that will be copied to new B<SSL> objects by
28L<SSL_new(3)|SSL_new(3)>. SSL_set_msg_callback() and
29SSL_set_msg_callback_arg() modify the actual settings of an B<SSL>
30object. Using a B<0> pointer for I<cb> disables the message callback.
31
32When I<cb> is called by the SSL/TLS library for a protocol message,
33the function arguments have the following meaning:
34
35=over 4
36
37=item I<write_p>
38
39This flag is B<0> when a protocol message has been received and B<1>
40when a protocol message has been sent.
41
42=item I<version>
43
44The protocol version according to which the protocol message is
45interpreted by the library. Currently, this is one of
46B<SSL2_VERSION>, B<SSL3_VERSION> and B<TLS1_VERSION> (for SSL 2.0, SSL
473.0 and TLS 1.0, respectively).
48
49=item I<content_type>
50
51In the case of SSL 2.0, this is always B<0>. In the case of SSL 3.0
52or TLS 1.0, this is one of the B<ContentType> values defined in the
53protocol specification (B<change_cipher_spec(20)>, B<alert(21)>,
54B<handshake(22)>; but never B<application_data(23)> because the
55callback will only be called for protocol messages).
56
57=item I<buf>, I<len>
58
59I<buf> points to a buffer containing the protocol message, which
60consists of I<len> bytes. The buffer is no longer valid after the
61callback function has returned.
62
63=item I<ssl>
64
65The B<SSL> object that received or sent the message.
66
67=item I<arg>
68
69The user-defined argument optionally defined by
70SSL_CTX_set_msg_callback_arg() or SSL_set_msg_callback_arg().
71
72=head1 NOTES
73
74Protocol messages are passed to the callback function after decryption
75and fragment collection where applicable. (Thus record boundaries are
76not visible.)
77
78If processing a received protocol message results in an error,
79the callback function may not be called. For example, the callback
80function will never see messages that are considered too large to be
81processed.
82
83Due to automatic protocol version negotiation, I<version> is not
84necessarily the protocol version used by the sender of the message: If
85a TLS 1.0 ClientHello message is received by an SSL 3.0-only server,
86I<version> will be B<SSL3_VERSION>.
87
88=head1 SEE ALSO
89
90L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>
91
92=head1 HISTORY
93
94SSL_CTX_set_msg_callback(), SSL_CTX_set_msg_callback_arg(),
95SSL_set_msg_callback() and SSL_get_msg_callback_arg() were added in OpenSSL 0.9.7.
96
97=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_options.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_options.pod
new file mode 100644
index 0000000000..3dc7cc74ad
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_options.pod
@@ -0,0 +1,183 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_options, SSL_set_options, SSL_CTX_get_options, SSL_get_options - manipulate SSL engine options
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_set_options(SSL_CTX *ctx, long options);
12 long SSL_set_options(SSL *ssl, long options);
13
14 long SSL_CTX_get_options(SSL_CTX *ctx);
15 long SSL_get_options(SSL *ssl);
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_options() adds the options set via bitmask in B<options> to B<ctx>.
20Options already set before are not cleared.
21
22SSL_set_options() adds the options set via bitmask in B<options> to B<ssl>.
23Options already set before are not cleared.
24
25SSL_CTX_get_options() returns the options set for B<ctx>.
26
27SSL_get_options() returns the options set for B<ssl>.
28
29=head1 NOTES
30
31The behaviour of the SSL library can be changed by setting several options.
32The options are coded as bitmasks and can be combined by a logical B<or>
33operation (|). Options can only be added but can never be reset.
34
35During a handshake, the option settings of the SSL object used. When
36a new SSL object is created from a context using SSL_new(), the current
37option setting is copied. Changes to B<ctx> do not affect already created
38SSL objects. SSL_clear() does not affect the settings.
39
40The following B<bug workaround> options are available:
41
42=over 4
43
44=item SSL_OP_MICROSOFT_SESS_ID_BUG
45
46www.microsoft.com - when talking SSLv2, if session-id reuse is
47performed, the session-id passed back in the server-finished message
48is different from the one decided upon.
49
50=item SSL_OP_NETSCAPE_CHALLENGE_BUG
51
52Netscape-Commerce/1.12, when talking SSLv2, accepts a 32 byte
53challenge but then appears to only use 16 bytes when generating the
54encryption keys. Using 16 bytes is ok but it should be ok to use 32.
55According to the SSLv3 spec, one should use 32 bytes for the challenge
56when operating in SSLv2/v3 compatibility mode, but as mentioned above,
57this breaks this server so 16 bytes is the way to go.
58
59=item SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
60
61ssl3.netscape.com:443, first a connection is established with RC4-MD5.
62If it is then resumed, we end up using DES-CBC3-SHA. It should be
63RC4-MD5 according to 7.6.1.3, 'cipher_suite'.
64
65Netscape-Enterprise/2.01 (https://merchant.netscape.com) has this bug.
66It only really shows up when connecting via SSLv2/v3 then reconnecting
67via SSLv3. The cipher list changes....
68
69NEW INFORMATION. Try connecting with a cipher list of just
70DES-CBC-SHA:RC4-MD5. For some weird reason, each new connection uses
71RC4-MD5, but a re-connect tries to use DES-CBC-SHA. So netscape, when
72doing a re-connect, always takes the first cipher in the cipher list.
73
74=item SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
75
76...
77
78=item SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
79
80...
81
82=item SSL_OP_MSIE_SSLV2_RSA_PADDING
83
84...
85
86=item SSL_OP_SSLEAY_080_CLIENT_DH_BUG
87
88...
89
90=item SSL_OP_TLS_D5_BUG
91
92...
93
94=item SSL_OP_TLS_BLOCK_PADDING_BUG
95
96...
97
98=item SSL_OP_TLS_ROLLBACK_BUG
99
100Disable version rollback attack detection.
101
102During the client key exchange, the client must send the same information
103about acceptable SSL/TLS protocol levels as during the first hello. Some
104clients violate this rule by adapting to the server's answer. (Example:
105the client sends a SSLv2 hello and accepts up to SSLv3.1=TLSv1, the server
106only understands up to SSLv3. In this case the client must still use the
107same SSLv3.1=TLSv1 announcement. Some clients step down to SSLv3 with respect
108to the server's answer and violate the version rollback protection.)
109
110=item SSL_OP_ALL
111
112All of the above bug workarounds.
113
114=back
115
116It is save and recommended to use SSL_OP_ALL to enable the bug workaround
117options.
118
119The following B<modifying> options are available:
120
121=over 4
122
123=item SSL_OP_SINGLE_DH_USE
124
125Always create a new key when using temporary DH parameters.
126
127=item SSL_OP_EPHEMERAL_RSA
128
129Also use the temporary RSA key when doing RSA operations.
130
131=item SSL_OP_PKCS1_CHECK_1
132
133...
134
135=item SSL_OP_PKCS1_CHECK_2
136
137...
138
139=item SSL_OP_NETSCAPE_CA_DN_BUG
140
141If we accept a netscape connection, demand a client cert, have a
142non-self-sighed CA which does not have it's CA in netscape, and the
143browser has a cert, it will crash/hang. Works for 3.x and 4.xbeta
144
145=item SSL_OP_NON_EXPORT_FIRST
146
147On servers try to use non-export (stronger) ciphers first. This option does
148not work under all circumstances (in the code it is declared "broken").
149
150=item SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
151
152...
153
154=item SSL_OP_NO_SSLv2
155
156Do not use the SSLv2 protocol.
157
158=item SSL_OP_NO_SSLv3
159
160Do not use the SSLv3 protocol.
161
162=item SSL_OP_NO_TLSv1
163
164Do not use the TLSv1 protocol.
165
166=back
167
168=head1 RETURN VALUES
169
170SSL_CTX_set_options() and SSL_set_options() return the new options bitmask
171after adding B<options>.
172
173SSL_CTX_get_options() and SSL_get_options() return the current bitmask.
174
175=head1 SEE ALSO
176
177L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>
178
179=head1 HISTORY
180
181SSL_OP_TLS_ROLLBACK_BUG has been added in OpenSSL 0.9.6.
182
183=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_quiet_shutdown.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_quiet_shutdown.pod
new file mode 100644
index 0000000000..1d0526d59a
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_quiet_shutdown.pod
@@ -0,0 +1,63 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_quiet_shutdown, SSL_CTX_get_quiet_shutdown, SSL_set_quiet_shutdown, SSL_get_quiet_shutdown - manipulate shutdown behaviour
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
12 int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
13
14 void SSL_set_quiet_shutdown(SSL *ssl, int mode);
15 int SSL_get_quiet_shutdown(SSL *ssl);
16
17=head1 DESCRIPTION
18
19SSL_CTX_set_quiet_shutdown() sets the "quiet shutdown" flag for B<ctx> to be
20B<mode>. SSL objects created from B<ctx> inherit the B<mode> valid at the time
21L<SSL_new(3)|SSL_new(3)> is called. B<mode> may be 0 or 1.
22
23SSL_CTX_get_quiet_shutdown() returns the "quiet shutdown" setting of B<ctx>.
24
25SSL_set_quiet_shutdown() sets the "quiet shutdown" flag for B<ssl> to be
26B<mode>. The setting stays valid until B<ssl> is removed with
27L<SSL_free(3)|SSL_free(3)> or SSL_set_quiet_shutdown() is called again.
28It is not changed when L<SSL_clear(3)|SSL_clear(3)> is called.
29B<mode> may be 0 or 1.
30
31SSL_get_quiet_shutdown() returns the "quiet shutdown" setting of B<ssl>.
32
33=head1 NOTES
34
35Normally when a SSL connection is finished, the parties must send out
36"close notify" alert messages using L<SSL_shutdown(3)|SSL_shutdown(3)>
37for a clean shutdown.
38
39When setting the "quiet shutdown" flag to 1, L<SSL_shutdown(3)|SSL_shutdown(3)>
40will set the internal flags to SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.
41(L<SSL_shutdown(3)|SSL_shutdown(3)> then behaves like
42L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> called with
43SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.)
44The session is thus considered to be shutdown, but no "close notify" alert
45is sent to the peer. This behaviour violates the TLS standard.
46
47The default is normal shutdown behaviour as described by the TLS standard.
48
49=head1 RETURN VALUES
50
51SSL_CTX_set_quiet_shutdown() and SSL_set_quiet_shutdown() do not return
52diagnostic information.
53
54SSL_CTX_get_quiet_shutdown() and SSL_get_quiet_shutdown return the current
55setting.
56
57=head1 SEE ALSO
58
59L<ssl(3)|ssl(3)>, L<SSL_shutdown(3)|SSL_shutdown(3)>,
60L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>, L<SSL_new(3)|SSL_new(3)>,
61L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
62
63=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_cache_mode.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_cache_mode.pod
new file mode 100644
index 0000000000..083766f8d0
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_cache_mode.pod
@@ -0,0 +1,107 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_session_cache_mode, SSL_CTX_get_session_cache_mode - enable/disable session caching
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_set_session_cache_mode(SSL_CTX ctx, long mode);
12 long SSL_CTX_get_session_cache_mode(SSL_CTX ctx);
13
14=head1 DESCRIPTION
15
16SSL_CTX_set_session_cache_mode() enables/disables session caching
17by setting the operational mode for B<ctx> to <mode>.
18
19SSL_CTX_get_session_cache_mode() returns the currently used cache mode.
20
21=head1 NOTES
22
23The OpenSSL library can store/retrieve SSL/TLS sessions for later reuse.
24The sessions can be held in memory for each B<ctx>, if more than one
25SSL_CTX object is being maintained, the sessions are unique for each SSL_CTX
26object.
27
28In order to reuse a session, a client must send the session's id to the
29server. It can only send exactly one id. The server then decides whether it
30agrees in reusing the session or starts the handshake for a new session.
31
32A server will lookup up the session in its internal session storage. If
33the session is not found in internal storage or internal storage is
34deactivated, the server will try the external storage if available.
35
36Since a client may try to reuse a session intended for use in a different
37context, the session id context must be set by the server (see
38L<SSL_CTX_set_session_id_context(3)|SSL_CTX_set_session_id_context(3)>).
39
40The following session cache modes and modifiers are available:
41
42=over 4
43
44=item SSL_SESS_CACHE_OFF
45
46No session caching for client or server takes place.
47
48=item SSL_SESS_CACHE_CLIENT
49
50Client sessions are added to the session cache. As there is no reliable way
51for the OpenSSL library to know whether a session should be reused or which
52session to choose (due to the abstract BIO layer the SSL engine does not
53have details about the connection), the application must select the session
54to be reused by using the L<SSL_set_session(3)|SSL_set_session(3)>
55function. This option is not activated by default.
56
57=item SSL_SESS_CACHE_SERVER
58
59Server sessions are added to the session cache. When a client proposes a
60session to be reused, the session is looked up in the internal session cache.
61If the session is found, the server will try to reuse the session.
62This is the default.
63
64=item SSL_SESS_CACHE_BOTH
65
66Enable both SSL_SESS_CACHE_CLIENT and SSL_SESS_CACHE_SERVER at the same time.
67
68=item SSL_SESS_CACHE_NO_AUTO_CLEAR
69
70Normally the session cache is checked for expired sessions every
71255 connections using the
72L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> function. Since
73this may lead to a delay which cannot be controlled, the automatic
74flushing may be disabled and
75L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> can be called
76explicitly by the application.
77
78=item SSL_SESS_CACHE_NO_INTERNAL_LOOKUP
79
80By setting this flag sessions are cached in the internal storage but
81they are not looked up automatically. If an external session cache
82is enabled, sessions are looked up in the external cache. As automatic
83lookup only applies for SSL/TLS servers, the flag has no effect on
84clients.
85
86=back
87
88The default mode is SSL_SESS_CACHE_SERVER.
89
90=head1 RETURN VALUES
91
92SSL_CTX_set_session_cache_mode() returns the previously set cache mode.
93
94SSL_CTX_get_session_cache_mode() returns the currently set cache mode.
95
96
97=head1 SEE ALSO
98
99L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
100L<SSL_CTX_sess_number(3)|SSL_CTX_sess_number(3)>,
101L<SSL_CTX_sess_set_cache_size(3)|SSL_CTX_sess_set_cache_size(3)>,
102L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>,
103L<SSL_CTX_set_session_id_context(3)|SSL_CTX_set_session_id_context(3)>,
104L<SSL_CTX_set_timeout.pod(3)|SSL_CTX_set_timeout.pod(3)>,
105L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>
106
107=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_id_context.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_id_context.pod
new file mode 100644
index 0000000000..5949395159
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_session_id_context.pod
@@ -0,0 +1,82 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_session_id_context, SSL_set_session_id_context - set context within which session can be reused (server side only)
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
12 unsigned int sid_ctx_len);
13 int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
14 unsigned int sid_ctx_len);
15
16=head1 DESCRIPTION
17
18SSL_CTX_set_session_id_context() sets the context B<sid_ctx> of length
19B<sid_ctx_len> within which a session can be reused for the B<ctx> object.
20
21SSL_set_session_id_context() sets the context B<sid_ctx> of length
22B<sid_ctx_len> within which a session can be reused for the B<ssl> object.
23
24=head1 NOTES
25
26Sessions are generated within a certain context. When exporting/importing
27sessions with B<i2d_SSL_SESSION>/B<d2i_SSL_SESSION> it would be possible,
28to re-import a session generated from another context (e.g. another
29application), which might lead to malfunctions. Therefore each application
30must set its own session id context B<sid_ctx> which is used to distinguish
31the contexts and is stored in exported sessions. The B<sid_ctx> can be
32any kind of binary data with a given length, it is therefore possible
33to use e.g. the name of the application and/or the hostname and/or service
34name ...
35
36The session id context becomes part of the session. The session id context
37is set by the SSL/TLS server. The SSL_CTX_set_session_id_context() and
38SSL_set_session_id_context() functions are therefore only useful on the
39server side.
40
41OpenSSL clients will check the session id context returned by the server
42when reusing a session.
43
44The maximum length of the B<sid_ctx> is limited to
45B<SSL_MAX_SSL_SESSION_ID_LENGTH>.
46
47=head1 WARNINGS
48
49If the session id context is not set on an SSL/TLS server, stored sessions
50will not be reused but a fatal error will be flagged and the handshake
51will fail.
52
53If a server returns a different session id context to an OpenSSL client
54when reusing a session, an error will be flagged and the handshake will
55fail. OpenSSL servers will always return the correct session id context,
56as an OpenSSL server checks the session id context itself before reusing
57a session as described above.
58
59=head1 RETURN VALUES
60
61SSL_CTX_set_session_id_context() and SSL_set_session_id_context()
62return the following values:
63
64=over 4
65
66=item 0
67
68The length B<sid_ctx_len> of the session id context B<sid_ctx> exceeded
69the maximum allowed length of B<SSL_MAX_SSL_SESSION_ID_LENGTH>. The error
70is logged to the error stack.
71
72=item 1
73
74The operation succeeded.
75
76=back
77
78=head1 SEE ALSO
79
80L<ssl(3)|ssl(3)>
81
82=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_ssl_version.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_ssl_version.pod
new file mode 100644
index 0000000000..3091bd6895
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_ssl_version.pod
@@ -0,0 +1,60 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_ssl_version, SSL_set_ssl_method, SSL_get_ssl_method
6- choose a new TLS/SSL method
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 int SSL_CTX_set_ssl_version(SSL_CTX *ctx, SSL_METHOD *method);
13 int SSL_set_ssl_method(SSL *s, SSL_METHOD *method);
14 SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
15
16=head1 DESCRIPTION
17
18SSL_CTX_set_ssl_version() sets a new default TLS/SSL B<method> for SSL objects
19newly created from this B<ctx>. SSL objects already created with
20L<SSL_new(3)|SSL_new(3)> are not affected, except when SSL_clear() is
21being called.
22
23SSL_set_ssl_method() sets a new TLS/SSL B<method> for a particular B<ssl>
24object. It may be reset, when SSL_clear() is called.
25
26SSL_get_ssl_method() returns a function pointer to the TLS/SSL method
27set in B<ssl>.
28
29=head1 NOTES
30
31The available B<method> choices are described in
32L<SSL_CTX_new(3)|SSL_CTX_new(3)>.
33
34When SSL_clear() is called and no session is connected to an SSL object,
35the method of the SSL object is reset to the method currently set in
36the corresponding SSL_CTX object.
37
38=head1 RETURN VALUES
39
40The following return values can occur for SSL_CTX_set_ssl_version()
41and SSL_set_ssl_method():
42
43=over 4
44
45=item 0
46
47The new choice failed, check the error stack to find out the reason.
48
49=item 1
50
51The operation succeeded.
52
53=back
54
55=head1 SEE ALSO
56
57L<SSL_CTX_new(3)|SSL_CTX_new(3)>, L<SSL_new(3)|SSL_new(3)>,
58L<SSL_clear(3)|SSL_clear(3)>, L<ssl(3)|ssl(3)>
59
60=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_timeout.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_timeout.pod
new file mode 100644
index 0000000000..21faed12d4
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_timeout.pod
@@ -0,0 +1,55 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_timeout, SSL_CTX_get_timeout - manipulate timeout values for session caching
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
12 long SSL_CTX_get_timeout(SSL_CTX *ctx);
13
14=head1 DESCRIPTION
15
16SSL_CTX_set_timeout() sets the timeout for newly created sessions for
17B<ctx> to B<t>. The timeout value B<t> must be given in seconds.
18
19SSL_CTX_get_timeout() returns the currently set timeout value for B<ctx>.
20
21=head1 NOTES
22
23Whenever a new session is created, it is assigned a maximum lifetime. This
24lifetime is specified by storing the creation time of the session and the
25timeout value valid at this time. If the actual time is later than creation
26time plus timeout, the session is not reused.
27
28Due to this realization, all sessions behave according to the timeout value
29valid at the time of the session negotiation. Changes of the timeout value
30do not affect already established sessions.
31
32The expiration time of a single session can be modified using the
33L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)> family of functions.
34
35Expired sessions are removed from the internal session cache, whenever
36L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> is called, either
37directly by the application or automatically (see
38L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>)
39
40The default value for session timeout is 300 seconds.
41
42=head1 RETURN VALUES
43
44SSL_CTX_set_timeout() returns the previously set timeout value.
45
46SSL_CTX_get_timeout() returns the currently set timeout value.
47
48=head1 SEE ALSO
49
50L<ssl(3)|ssl(3)>,
51L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
52L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)>,
53L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>
54
55=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod
new file mode 100644
index 0000000000..29d1f8a6fb
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod
@@ -0,0 +1,170 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
12 DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
13 long SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
14
15 void SSL_set_tmp_dh_callback(SSL_CTX *ctx,
16 DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
17 long SSL_set_tmp_dh(SSL *ssl, DH *dh)
18
19 DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
20
21=head1 DESCRIPTION
22
23SSL_CTX_set_tmp_dh_callback() sets the callback function for B<ctx> to be
24used when a DH parameters are required to B<tmp_dh_callback>.
25The callback is inherited by all B<ssl> objects created from B<ctx>.
26
27SSL_CTX_set_tmp_dh() sets DH parameters to be used to be B<dh>.
28The key is inherited by all B<ssl> objects created from B<ctx>.
29
30SSL_set_tmp_dh_callback() sets the callback only for B<ssl>.
31
32SSL_set_tmp_dh() sets the parameters only for B<ssl>.
33
34These functions apply to SSL/TLS servers only.
35
36=head1 NOTES
37
38When using a cipher with RSA authentication, an ephemeral DH key exchange
39can take place. Ciphers with DSA keys always use ephemeral DH keys as well.
40In these cases, the session data are negotiated using the
41ephemeral/temporary DH key and the key supplied and certified
42by the certificate chain is only used for signing.
43Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.
44
45Using ephemeral DH key exchange yields forward secrecy, as the connection
46can only be decrypted, when the DH key is known. By generating a temporary
47DH key inside the server application that is lost when the application
48is left, it becomes impossible for an attacker to decrypt past sessions,
49even if he gets hold of the normal (certified) key, as this key was
50only used for signing.
51
52In order to perform a DH key exchange the server must use a DH group
53(DH parameters) and generate a DH key. The server will always generate a new
54DH key during the negotiation, when the DH parameters are supplied via
55callback and/or when the SSL_OP_SINGLE_DH_USE option of
56L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)> is set. It will
57immediately create a DH key, when DH parameters are supplied via
58SSL_CTX_set_tmp_dh() and SSL_OP_SINGLE_DH_USE is not set. In this case,
59it may happen that a key is generated on initialization without later
60being needed, while on the other hand the computer time during the
61negotiation is being saved.
62
63If "strong" primes were used to generate the DH parameters, it is not strictly
64necessary to generate a new key for each handshake but it does improve forward
65secrecy. If it is not assured, that "strong" primes were used (see especially
66the section about DSA parameters below), SSL_OP_SINGLE_DH_USE must be used
67in order to prevent small subgroup attacks. Always using SSL_OP_SINGLE_DH_USE
68has an impact on the computer time needed during negotiation, but it is not
69very large, so application authors/users should consider to always enable
70this option.
71
72As generating DH parameters is extremely time consuming, an application
73should not generate the parameters on the fly but supply the parameters.
74DH parameters can be reused, as the actual key is newly generated during
75the negotiation. The risk in reusing DH parameters is that an attacker
76may specialize on a very often used DH group. Applications should therefore
77generate their own DH parameters during the installation process using the
78openssl L<dhparam(1)|dhparam(1)> application. In order to reduce the computer
79time needed for this generation, it is possible to use DSA parameters
80instead (see L<dhparam(1)|dhparam(1)>), but in this case SSL_OP_SINGLE_DH_USE
81is mandatory.
82
83Application authors may compile in DH parameters. Files dh512.pem,
84dh1024.pem, dh2048.pem, and dh4096 in the 'apps' directory of current
85version of the OpenSSL distribution contain the 'SKIP' DH parameters,
86which use safe primes and were generated verifiably pseudo-randomly.
87These files can be converted into C code using the B<-C> option of the
88L<dhparam(1)|dhparam(1)> application.
89Authors may also generate their own set of parameters using
90L<dhparam(1)|dhparam(1)>, but a user may not be sure how the parameters were
91generated. The generation of DH parameters during installation is therefore
92recommended.
93
94An application may either directly specify the DH parameters or
95can supply the DH parameters via a callback function. The callback approach
96has the advantage, that the callback may supply DH parameters for different
97key lengths.
98
99The B<tmp_dh_callback> is called with the B<keylength> needed and
100the B<is_export> information. The B<is_export> flag is set, when the
101ephemeral DH key exchange is performed with an export cipher.
102
103=head1 EXAMPLES
104
105Handle DH parameters for key lengths of 512 and 1024 bits. (Error handling
106partly left out.)
107
108 ...
109 /* Set up ephemeral DH stuff */
110 DH *dh_512 = NULL;
111 DH *dh_1024 = NULL;
112 FILE *paramfile;
113
114 ...
115 /* "openssl dhparam -out dh_param_512.pem -2 512" */
116 paramfile = fopen("dh_param_512.pem", "r");
117 if (paramfile) {
118 dh_512 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
119 fclose(paramfile);
120 }
121 /* "openssl dhparam -out dh_param_1024.pem -2 1024" */
122 paramfile = fopen("dh_param_1024.pem", "r");
123 if (paramfile) {
124 dh_1024 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
125 fclose(paramfile);
126 }
127 ...
128
129 /* "openssl dhparam -C -2 512" etc... */
130 DH *get_dh512() { ... }
131 DH *get_dh1024() { ... }
132
133 DH *tmp_dh_callback(SSL *s, int is_export, int keylength)
134 {
135 DH *dh_tmp=NULL;
136
137 switch (keylength) {
138 case 512:
139 if (!dh_512)
140 dh_512 = get_dh512();
141 dh_tmp = dh_512;
142 break;
143 case 1024:
144 if (!dh_1024)
145 dh_1024 = get_dh1024();
146 dh_tmp = dh_1024;
147 break;
148 default:
149 /* Generating a key on the fly is very costly, so use what is there */
150 setup_dh_parameters_like_above();
151 }
152 return(dh_tmp);
153 }
154
155=head1 RETURN VALUES
156
157SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not return
158diagnostic output.
159
160SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do return 1 on success and 0
161on failure. Check the error queue to find out the reason of failure.
162
163=head1 SEE ALSO
164
165L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
166L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>,
167L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
168L<ciphers(1)|ciphers(1)>, L<dhparam(1)|dhparam(1)>
169
170=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod
new file mode 100644
index 0000000000..f85775927d
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod
@@ -0,0 +1,166 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
12 RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
13 long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
14 long SSL_CTX_need_tmp_rsa(SSL_CTX *ctx);
15
16 void SSL_set_tmp_rsa_callback(SSL_CTX *ctx,
17 RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
18 long SSL_set_tmp_rsa(SSL *ssl, RSA *rsa)
19 long SSL_need_tmp_rsa(SSL *ssl)
20
21 RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
22
23=head1 DESCRIPTION
24
25SSL_CTX_set_tmp_rsa_callback() sets the callback function for B<ctx> to be
26used when a temporary/ephemeral RSA key is required to B<tmp_rsa_callback>.
27The callback is inherited by all SSL objects newly created from B<ctx>
28with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
29
30SSL_CTX_set_tmp_rsa() sets the temporary/ephemeral RSA key to be used to be
31B<rsa>. The key is inherited by all SSL objects newly created from B<ctx>
32with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
33
34SSL_CTX_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed
35for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
36with a keysize larger than 512 bits is installed.
37
38SSL_set_tmp_rsa_callback() sets the callback only for B<ssl>.
39
40SSL_set_tmp_rsa() sets the key only for B<ssl>.
41
42SSL_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed,
43for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
44with a keysize larger than 512 bits is installed.
45
46These functions apply to SSL/TLS servers only.
47
48=head1 NOTES
49
50When using a cipher with RSA authentication, an ephemeral RSA key exchange
51can take place. In this case the session data are negotiated using the
52ephemeral/temporary RSA key and the RSA key supplied and certified
53by the certificate chain is only used for signing.
54
55Under previous export restrictions, ciphers with RSA keys shorter (512 bits)
56than the usual key length of 1024 bits were created. To use these ciphers
57with RSA keys of usual length, an ephemeral key exchange must be performed,
58as the normal (certified) key cannot be directly used.
59
60Using ephemeral RSA key exchange yields forward secrecy, as the connection
61can only be decrypted, when the RSA key is known. By generating a temporary
62RSA key inside the server application that is lost when the application
63is left, it becomes impossible for an attacker to decrypt past sessions,
64even if he gets hold of the normal (certified) RSA key, as this key was
65used for signing only. The downside is that creating a RSA key is
66computationally expensive.
67
68Additionally, the use of ephemeral RSA key exchange is only allowed in
69the TLS standard, when the RSA key can be used for signing only, that is
70for export ciphers. Using ephemeral RSA key exchange for other purposes
71violates the standard and can break interoperability with clients.
72It is therefore strongly recommended to not use ephemeral RSA key
73exchange and use EDH (Ephemeral Diffie-Hellman) key exchange instead
74in order to achieve forward secrecy (see
75L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
76
77On OpenSSL servers ephemeral RSA key exchange is therefore disabled by default
78and must be explicitly enabled using the SSL_OP_EPHEMERAL_RSA option of
79L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>, violating the TLS/SSL
80standard. When ephemeral RSA key exchange is required for export ciphers,
81it will automatically be used without this option!
82
83An application may either directly specify the key or can supply the key via
84a callback function. The callback approach has the advantage, that the
85callback may generate the key only in case it is actually needed. As the
86generation of a RSA key is however costly, it will lead to a significant
87delay in the handshake procedure. Another advantage of the callback function
88is that it can supply keys of different size (e.g. for SSL_OP_EPHEMERAL_RSA
89usage) while the explicit setting of the key is only useful for key size of
90512 bits to satisfy the export restricted ciphers and does give away key length
91if a longer key would be allowed.
92
93The B<tmp_rsa_callback> is called with the B<keylength> needed and
94the B<is_export> information. The B<is_export> flag is set, when the
95ephemeral RSA key exchange is performed with an export cipher.
96
97=head1 EXAMPLES
98
99Generate temporary RSA keys to prepare ephemeral RSA key exchange. As the
100generation of a RSA key costs a lot of computer time, they saved for later
101reuse. For demonstration purposes, two keys for 512 bits and 1024 bits
102respectively are generated.
103
104 ...
105 /* Set up ephemeral RSA stuff */
106 RSA *rsa_512 = NULL;
107 RSA *rsa_1024 = NULL;
108
109 rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
110 if (rsa_512 == NULL)
111 evaluate_error_queue();
112
113 rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
114 if (rsa_1024 == NULL)
115 evaluate_error_queue();
116
117 ...
118
119 RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
120 {
121 RSA *rsa_tmp=NULL;
122
123 switch (keylength) {
124 case 512:
125 if (rsa_512)
126 rsa_tmp = rsa_512;
127 else { /* generate on the fly, should not happen in this example */
128 rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
129 rsa_512 = rsa_tmp; /* Remember for later reuse */
130 }
131 break;
132 case 1024:
133 if (rsa_1024)
134 rsa_tmp=rsa_1024;
135 else
136 should_not_happen_in_this_example();
137 break;
138 default:
139 /* Generating a key on the fly is very costly, so use what is there */
140 if (rsa_1024)
141 rsa_tmp=rsa_1024;
142 else
143 rsa_tmp=rsa_512; /* Use at least a shorter key */
144 }
145 return(rsa_tmp);
146 }
147
148=head1 RETURN VALUES
149
150SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not return
151diagnostic output.
152
153SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and 0
154on failure. Check the error queue to find out the reason of failure.
155
156SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
157RSA key is needed and 0 otherwise.
158
159=head1 SEE ALSO
160
161L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
162L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
163L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
164L<SSL_new(3)|SSL_new(3)>, L<ciphers(1)|ciphers(1)>
165
166=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_set_verify.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_verify.pod
new file mode 100644
index 0000000000..fc0b76118f
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_set_verify.pod
@@ -0,0 +1,284 @@
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth - set peer certificate verification parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
12 int (*verify_callback)(int, X509_STORE_CTX *));
13 void SSL_set_verify(SSL *s, int mode,
14 int (*verify_callback)(int, X509_STORE_CTX *));
15 void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
16 void SSL_set_verify_depth(SSL *s, int depth);
17
18 int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
19
20=head1 DESCRIPTION
21
22SSL_CTX_set_verify() sets the verification flags for B<ctx> to be B<mode> and
23specifies the B<verify_callback> function to be used. If no callback function
24shall be specified, the NULL pointer can be used for B<verify_callback>.
25
26SSL_set_verify() sets the verification flags for B<ssl> to be B<mode> and
27specifies the B<verify_callback> function to be used. If no callback function
28shall be specified, the NULL pointer can be used for B<verify_callback>. In
29this case last B<verify_callback> set specifically for this B<ssl> remains. If
30no special B<callback> was set before, the default callback for the underlying
31B<ctx> is used, that was valid at the the time B<ssl> was created with
32L<SSL_new(3)|SSL_new(3)>.
33
34SSL_CTX_set_verify_depth() sets the maximum B<depth> for the certificate chain
35verification that shall be allowed for B<ctx>. (See the BUGS section.)
36
37SSL_set_verify_depth() sets the maximum B<depth> for the certificate chain
38verification that shall be allowed for B<ssl>. (See the BUGS section.)
39
40=head1 NOTES
41
42The verification of certificates can be controlled by a set of logically
43or'ed B<mode> flags:
44
45=over 4
46
47=item SSL_VERIFY_NONE
48
49B<Server mode:> the server will not send a client certificate request to the
50client, so the client will not send a certificate.
51
52B<Client mode:> if not using an anonymous cipher (by default disabled), the
53server will send a certificate which will be checked. The result of the
54certificate verification process can be checked after the TLS/SSL handshake
55using the L<SSL_get_verify_result(3)|SSL_get_verify_result(3)> function.
56The handshake will be continued regardless of the verification result.
57
58=item SSL_VERIFY_PEER
59
60B<Server mode:> the server sends a client certificate request to the client.
61The certificate returned (if any) is checked. If the verification process
62fails as indicated by B<verify_callback>, the TLS/SSL handshake is
63immediately terminated with an alert message containing the reason for
64the verification failure.
65The behaviour can be controlled by the additional
66SSL_VERIFY_FAIL_IF_NO_PEER_CERT and SSL_VERIFY_CLIENT_ONCE flags.
67
68B<Client mode:> the server certificate is verified. If the verification process
69fails as indicated by B<verify_callback>, the TLS/SSL handshake is
70immediately terminated with an alert message containing the reason for
71the verification failure. If no server certificate is sent, because an
72anonymous cipher is used, SSL_VERIFY_PEER is ignored.
73
74=item SSL_VERIFY_FAIL_IF_NO_PEER_CERT
75
76B<Server mode:> if the client did not return a certificate, the TLS/SSL
77handshake is immediately terminated with a "handshake failure" alert.
78This flag must be used together with SSL_VERIFY_PEER.
79
80B<Client mode:> ignored
81
82=item SSL_VERIFY_CLIENT_ONCE
83
84B<Server mode:> only request a client certificate on the initial TLS/SSL
85handshake. Do not ask for a client certificate again in case of a
86renegotiation. This flag must be used together with SSL_VERIFY_PEER.
87
88B<Client mode:> ignored
89
90=back
91
92Exactly one of the B<mode> flags SSL_VERIFY_NONE and SSL_VERIFY_PEER must be
93set at any time.
94
95SSL_CTX_set_verify_depth() and SSL_set_verify_depth() set the limit up
96to which depth certificates in a chain are used during the verification
97procedure. If the certificate chain is longer than allowed, the certificates
98above the limit are ignored. Error messages are generated as if these
99certificates would not be present, most likely a
100X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
101The depth count is "level 0:peer certificate", "level 1: CA certificate",
102"level 2: higher level CA certificate", and so on. Setting the maximum
103depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
104allowing for the peer certificate and additional 9 CA certificates.
105
106The B<verify_callback> function is used to control the behaviour when the
107SSL_VERIFY_PEER flag is set. It must be supplied by the application and
108receives two arguments: B<preverify_ok> indicates, whether the verification of
109the certificate in question was passed (preverify_ok=1) or not
110(preverify_ok=0). B<x509_ctx> is a pointer to the complete context used
111for the certificate chain verification.
112
113The certificate chain is checked starting with the deepest nesting level
114(the root CA certificate) and worked upward to the peer's certificate.
115At each level signatures and issuer attributes are checked. Whenever
116a verification error is found, the error number is stored in B<x509_ctx>
117and B<verify_callback> is called with B<preverify_ok>=0. By applying
118X509_CTX_store_* functions B<verify_callback> can locate the certificate
119in question and perform additional steps (see EXAMPLES). If no error is
120found for a certificate, B<verify_callback> is called with B<preverify_ok>=1
121before advancing to the next level.
122
123The return value of B<verify_callback> controls the strategy of the further
124verification process. If B<verify_callback> returns 0, the verification
125process is immediately stopped with "verification failed" state. If
126SSL_VERIFY_PEER is set, a verification failure alert is sent to the peer and
127the TLS/SSL handshake is terminated. If B<verify_callback> returns 1,
128the verification process is continued. If B<verify_callback> always returns
1291, the TLS/SSL handshake will never be terminated because of this application
130experiencing a verification failure. The calling process can however
131retrieve the error code of the last verification error using
132L<SSL_get_verify_result(3)|SSL_get_verify_result(3)> or by maintaining its
133own error storage managed by B<verify_callback>.
134
135If no B<verify_callback> is specified, the default callback will be used.
136Its return value is identical to B<preverify_ok>, so that any verification
137failure will lead to a termination of the TLS/SSL handshake with an
138alert message, if SSL_VERIFY_PEER is set.
139
140=head1 BUGS
141
142In client mode, it is not checked whether the SSL_VERIFY_PEER flag
143is set, but whether SSL_VERIFY_NONE is not set. This can lead to
144unexpected behaviour, if the SSL_VERIFY_PEER and SSL_VERIFY_NONE are not
145used as required (exactly one must be set at any time).
146
147The certificate verification depth set with SSL[_CTX]_verify_depth()
148stops the verification at a certain depth. The error message produced
149will be that of an incomplete certificate chain and not
150X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
151
152=head1 RETURN VALUES
153
154The SSL*_set_verify*() functions do not provide diagnostic information.
155
156=head1 EXAMPLES
157
158The following code sequence realizes an example B<verify_callback> function
159that will always continue the TLS/SSL handshake regardless of verification
160failure, if wished. The callback realizes a verification depth limit with
161more informational output.
162
163All verification errors are printed, informations about the certificate chain
164are printed on request.
165The example is realized for a server that does allow but not require client
166certificates.
167
168The example makes use of the ex_data technique to store application data
169into/retrieve application data from the SSL structure
170(see L<SSL_get_ex_new_index(3)|SSL_get_ex_new_index(3)>,
171L<SSL_get_ex_data_X509_STORE_CTX_idx(3)|SSL_get_ex_data_X509_STORE_CTX_idx(3)>).
172
173 ...
174 typedef struct {
175 int verbose_mode;
176 int verify_depth;
177 int always_continue;
178 } mydata_t;
179 int mydata_index;
180 ...
181 static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
182 {
183 char buf[256];
184 X509 *err_cert;
185 int err, depth;
186 SSL *ssl;
187 mydata_t *mydata;
188
189 err_cert = X509_STORE_CTX_get_current_cert(ctx);
190 err = X509_STORE_CTX_get_error(ctx);
191 depth = X509_STORE_CTX_get_error_depth(ctx);
192
193 /*
194 * Retrieve the pointer to the SSL of the connection currently treated
195 * and the application specific data stored into the SSL object.
196 */
197 ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
198 mydata = SSL_get_ex_data(ssl, mydata_index);
199
200 X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
201
202 /*
203 * Catch a too long certificate chain. The depth limit set using
204 * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
205 * that whenever the "depth>verify_depth" condition is met, we
206 * have violated the limit and want to log this error condition.
207 * We must do it here, because the CHAIN_TOO_LONG error would not
208 * be found explicitly; only errors introduced by cutting off the
209 * additional certificates would be logged.
210 */
211 if (depth > mydata->verify_depth) {
212 preverify_ok = 0;
213 err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
214 X509_STORE_CTX_set_error(ctx, err);
215 }
216 if (!preverify_ok) {
217 printf("verify error:num=%d:%s:depth=%d:%s\n", err,
218 X509_verify_cert_error_string(err), depth, buf);
219 }
220 else if (mydata->verbose_mode)
221 {
222 printf("depth=%d:%s\n", depth, buf);
223 }
224
225 /*
226 * At this point, err contains the last verification error. We can use
227 * it for something special
228 */
229 if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)
230 {
231 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256);
232 printf("issuer= %s\n", buf);
233 }
234
235 if (mydata->always_continue)
236 return 1;
237 else
238 return preverify_ok;
239 }
240 ...
241
242 mydata_t mydata;
243
244 ...
245 mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
246
247 ...
248 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
249 verify_callback);
250
251 /*
252 * Let the verify_callback catch the verify_depth error so that we get
253 * an appropriate error in the logfile.
254 */
255 SSL_CTX_set_verify_depth(verify_depth + 1);
256
257 /*
258 * Set up the SSL specific data into "mydata" and store it into th SSL
259 * structure.
260 */
261 mydata.verify_depth = verify_depth; ...
262 SSL_set_ex_data(ssl, mydata_index, &mydata);
263
264 ...
265 SSL_accept(ssl); /* check of success left out for clarity */
266 if (peer = SSL_get_peer_certificate(ssl))
267 {
268 if (SSL_get_verify_result(ssl) == X509_V_OK)
269 {
270 /* The client sent a certificate which verified OK */
271 }
272 }
273
274=head1 SEE ALSO
275
276L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>,
277L<SSL_CTX_get_verify_mode(3)|SSL_CTX_get_verify_mode(3)>,
278L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
279L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
280L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
281L<SSL_get_ex_data_X509_STORE_CTX_idx(3)|SSL_get_ex_data_X509_STORE_CTX_idx(3)>,
282L<SSL_get_ex_new_index(3)|SSL_get_ex_new_index(3)>
283
284=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_CTX_use_certificate.pod b/src/lib/libssl/src/doc/ssl/SSL_CTX_use_certificate.pod
new file mode 100644
index 0000000000..3b2fe6fc50
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_CTX_use_certificate.pod
@@ -0,0 +1,154 @@
1=pod
2
3=head1 NAME
4
5SSL_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
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
12 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
13 int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
14 int SSL_use_certificate(SSL *ssl, X509 *x);
15 int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
16 int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
17
18 int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
19
20 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
21 int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, unsigned char *d,
22 long len);
23 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
24 int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
25 int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
26 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
27 int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
28 int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
29 int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
30 int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
31 int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
32 int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
33
34 int SSL_CTX_check_private_key(SSL_CTX *ctx);
35 int SSL_check_private_key(SSL *ssl);
36
37=head1 DESCRIPTION
38
39These functions load the certificates and private keys into the SSL_CTX
40or SSL object, respectively.
41
42The SSL_CTX_* class of functions loads the certificates and keys into the
43SSL_CTX object B<ctx>. The information is passed to SSL objects B<ssl>
44created from B<ctx> with L<SSL_new(3)|SSL_new(3)> by copying, so that
45changes applied to B<ctx> do not propagate to already existing SSL objects.
46
47The SSL_* class of functions only loads certificates and keys into a
48specific SSL object. The specific information is kept, when
49L<SSL_clear(3)|SSL_clear(3)> is called for this SSL object.
50
51SSL_CTX_use_certificate() loads the certificate B<x> into B<ctx>,
52SSL_use_certificate() loads B<x> into B<ssl>. The rest of the
53certificates needed to form the complete certificate chain can be
54specified using the
55L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
56function.
57
58SSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from
59the memory location B<d> (with length B<len>) into B<ctx>,
60SSL_use_certificate_ASN1() loads the ASN1 encoded certificate into B<ssl>.
61
62SSL_CTX_use_certificate_file() loads the first certificate stored in B<file>
63into B<ctx>. The formatting B<type> of the certificate must be specified
64from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
65SSL_use_certificate_file() loads the certificate from B<file> into B<ssl>.
66See the NOTES section on why SSL_CTX_use_certificate_chain_file()
67should be preferred.
68
69SSL_CTX_use_certificate_chain_file() loads a certificate chain from
70B<file> into B<ctx>. The certificates must be in PEM format and must
71be sorted starting with the certificate to the highest level (root CA).
72There is no corresponding function working on a single SSL object.
73
74SSL_CTX_use_PrivateKey() adds B<pkey> as private key to B<ctx>.
75SSL_CTX_use_RSAPrivateKey() adds the private key B<rsa> of type RSA
76to B<ctx>. SSL_use_PrivateKey() adds B<pkey> as private key to B<ssl>;
77SSL_use_RSAPrivateKey() adds B<rsa> as private key of type RSA to B<ssl>.
78
79SSL_CTX_use_PrivateKey_ASN1() adds the private key of type B<pk>
80stored at memory location B<d> (length B<len>) to B<ctx>.
81SSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA
82stored at memory location B<d> (length B<len>) to B<ctx>.
83SSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the private
84key to B<ssl>.
85
86SSL_CTX_use_PrivateKey_file() adds the first private key found in
87B<file> to B<ctx>. The formatting B<type> of the certificate must be specified
88from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
89SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found in
90B<file> to B<ctx>. SSL_use_PrivateKey_file() adds the first private key found
91in B<file> to B<ssl>; SSL_use_RSAPrivateKey_file() adds the first private
92RSA key found to B<ssl>.
93
94SSL_CTX_check_private_key() checks the consistency of a private key with
95the corresponding certificate loaded into B<ctx>. If more than one
96key/certificate pair (RSA/DSA) is installed, the last item installed will
97be checked. If e.g. the last item was a RSA certificate or key, the RSA
98key/certificate pair will be checked. SSL_check_private_key() performs
99the same check for B<ssl>. If no key/certificate was explicitly added for
100this B<ssl>, the last item added into B<ctx> will be checked.
101
102=head1 NOTES
103
104The internal certificate store of OpenSSL can hold two private key/certificate
105pairs at a time: one key/certificate of type RSA and one key/certificate
106of type DSA. The certificate used depends on the cipher select, see
107also L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>.
108
109When reading certificates and private keys from file, files of type
110SSL_FILETYPE_ASN1 (also known as B<DER>, binary encoding) can only contain
111one certificate or private key, consequently
112SSL_CTX_use_certificate_chain_file() is only applicable to PEM formatting.
113Files of type SSL_FILETYPE_PEM can contain more than one item.
114
115SSL_CTX_use_certificate_chain_file() adds the first certificate found
116in the file to the certificate store. The other certificates are added
117to the store of chain certificates using
118L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>.
119There exists only one extra chain store, so that the same chain is appended
120to both types of certificates, RSA and DSA! If it is not intended to use
121both type of certificate at the same time, it is recommended to use the
122SSL_CTX_use_certificate_chain_file() instead of the
123SSL_CTX_use_certificate_file() function in order to allow the use of
124complete certificate chains even when no trusted CA storage is used or
125when the CA issuing the certificate shall not be added to the trusted
126CA storage.
127
128If additional certificates are needed to complete the chain during the
129TLS negotiation, CA certificates are additionally looked up in the
130locations of trusted CA certificates, see
131L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
132
133The private keys loaded from file can be encrypted. In order to successfully
134load encrypted keys, a function returning the passphrase must have been
135supplied, see
136L<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>.
137(Certificate files might be encrypted as well from the technical point
138of view, it however does not make sense as the data in the certificate
139is considered public anyway.)
140
141=head1 RETURN VALUES
142
143On success, the functions return 1.
144Otherwise check out the error stack to find out the reason.
145
146=head1 SEE ALSO
147
148L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>,
149L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
150L<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>,
151L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
152L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
153
154=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_SESSION_free.pod b/src/lib/libssl/src/doc/ssl/SSL_SESSION_free.pod
new file mode 100644
index 0000000000..df30ccbb32
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_SESSION_free.pod
@@ -0,0 +1,25 @@
1=pod
2
3=head1 NAME
4
5SSL_SESSION_free - free an allocated SSL_SESSION structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_SESSION_free(SSL_SESSION *session);
12
13=head1 DESCRIPTION
14
15SSL_SESSION_free() decrements the reference count of B<session> and removes
16the B<SSL_SESSION> structure pointed to by B<session> and frees up the allocated
17memory, if the the reference count has reached 0.
18
19=head1 RETURN VALUES
20
21SSL_SESSION_free() does not provide diagnostic information.
22
23L<ssl(3)|ssl(3)>, L<SSL_get_session(3)|SSL_get_session(3)>
24
25=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_ex_new_index.pod b/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_ex_new_index.pod
new file mode 100644
index 0000000000..dd5cb4f04b
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_ex_new_index.pod
@@ -0,0 +1,61 @@
1=pod
2
3=head1 NAME
4
5SSL_SESSION_get_ex_new_index, SSL_SESSION_set_ex_data, SSL_SESSION_get_ex_data - internal application specific data functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_SESSION_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int SSL_SESSION_set_ex_data(SSL_SESSION *session, int idx, void *arg);
17
18 void *SSL_SESSION_get_ex_data(SSL_SESSION *session, int idx);
19
20 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp);
26
27=head1 DESCRIPTION
28
29Several OpenSSL structures can have application specific data attached to them.
30These functions are used internally by OpenSSL to manipulate application
31specific data attached to a specific structure.
32
33SSL_SESSION_get_ex_new_index() is used to register a new index for application
34specific data.
35
36SSL_SESSION_set_ex_data() is used to store application data at B<arg> for B<idx>
37into the B<session> object.
38
39SSL_SESSION_get_ex_data() is used to retrieve the information for B<idx> from
40B<session>.
41
42A detailed description for the B<*_get_ex_new_index()> functionality
43can be found in L<RSA_get_ex_new_index.pod(3)|RSA_get_ex_new_index.pod(3)>.
44The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
45L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
46
47=head1 WARNINGS
48
49The application data is only maintained for sessions held in memory. The
50application data is not included when dumping the session with
51i2d_SSL_SESSION() (and all functions indirectly calling the dump functions
52like PEM_write_SSL_SESSION() and PEM_write_bio_SSL_SESSION()) and can
53therefore not be restored.
54
55=head1 SEE ALSO
56
57L<ssl(3)|ssl(3)>,
58L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
59L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
60
61=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_time.pod b/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_time.pod
new file mode 100644
index 0000000000..cd33b73aa3
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_SESSION_get_time.pod
@@ -0,0 +1,63 @@
1=pod
2
3=head1 NAME
4
5SSL_SESSION_get_time, SSL_SESSION_set_time, SSL_SESSION_get_timeout, SSL_SESSION_get_timeout - retrieve and manipulate session time and timeout settings
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_SESSION_get_time(SSL_SESSION *s);
12 long SSL_SESSION_set_time(SSL_SESSION *s, long tm);
13 long SSL_SESSION_get_timeout(SSL_SESSION *s);
14 long SSL_SESSION_set_timeout(SSL_SESSION *s, long tm);
15
16 long SSL_get_time(SSL_SESSION *s);
17 long SSL_set_time(SSL_SESSION *s, long tm);
18 long SSL_get_timeout(SSL_SESSION *s);
19 long SSL_set_timeout(SSL_SESSION *s, long tm);
20
21=head1 DESCRIPTION
22
23SSL_SESSION_get_time() returns the time at which the session B<s> was
24established. The time is given in seconds since the Epoch and therefore
25compatible to the time delivered by the time() call.
26
27SSL_SESSION_set_time() replaces the creation time of the session B<s> with
28the chosen value B<tm>.
29
30SSL_SESSION_get_timeout() returns the timeout value set for session B<s>
31in seconds.
32
33SSL_SESSION_set_timeout() sets the timeout value for session B<s> in seconds
34to B<tm>.
35
36The SSL_get_time(), SSL_set_time(), SSL_get_timeout(), and SSL_set_timeout()
37functions are synonyms for the SSL_SESSION_*() counterparts.
38
39=head1 NOTES
40
41Sessions are expired by examining the creation time and the timeout value.
42Both are set at creation time of the session to the actual time and the
43default timeout value at creation, respectively, as set by
44L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>.
45Using these functions it is possible to extend or shorten the lifetime
46of the session.
47
48=head1 RETURN VALUES
49
50SSL_SESSION_get_time() and SSL_SESSION_get_timeout() return the currently
51valid values.
52
53SSL_SESSION_set_time() and SSL_SESSION_set_timeout() return 1 on success.
54
55If any of the function is passed the NULL pointer for the session B<s>,
560 is returned.
57
58=head1 SEE ALSO
59
60L<ssl(3)|ssl(3)>,
61L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>
62
63=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_accept.pod b/src/lib/libssl/src/doc/ssl/SSL_accept.pod
new file mode 100644
index 0000000000..0c79ac515e
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_accept.pod
@@ -0,0 +1,72 @@
1=pod
2
3=head1 NAME
4
5SSL_accept - wait for a TLS/SSL client to initiate a TLS/SSL handshake
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_accept(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_accept() waits for a TLS/SSL client to initiate the TLS/SSL handshake.
16The communication channel must already have been set and assigned to the
17B<ssl> by setting an underlying B<BIO>.
18
19=head1 NOTES
20
21The behaviour of SSL_accept() depends on the underlying BIO.
22
23If the underlying BIO is B<blocking>, SSL_accept() will only return once the
24handshake has been finished or an error occurred, except for SGC (Server
25Gated Cryptography). For SGC, SSL_accept() may return with -1, but
26SSL_get_error() will yield B<SSL_ERROR_WANT_READ/WRITE> and SSL_accept()
27should be called again.
28
29If the underlying BIO is B<non-blocking>, SSL_accept() will also return
30when the underlying BIO could not satisfy the needs of SSL_accept()
31to continue the handshake. In this case a call to SSL_get_error() with the
32return value of SSL_accept() will yield B<SSL_ERROR_WANT_READ> or
33B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
34taking appropriate action to satisfy the needs of SSL_accept().
35The action depends on the underlying BIO. When using a non-blocking socket,
36nothing is to be done, but select() can be used to check for the required
37condition. When using a buffering BIO, like a BIO pair, data must be written
38into or retrieved out of the BIO before being able to continue.
39
40=head1 RETURN VALUES
41
42The following return values can occur:
43
44=over 4
45
46=item 1
47
48The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
49established.
50
51=item 0
52
53The TLS/SSL handshake was not successful but was shut down controlled and
54by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
55return value B<ret> to find out the reason.
56
57=item -1
58
59The TLS/SSL handshake was not successful because a fatal error occurred either
60at the protocol level or a connection failure occurred. The shutdown was
61not clean. It can also occur of action is need to continue the operation
62for non-blocking BIOs. Call SSL_get_error() with the return value B<ret>
63to find out the reason.
64
65=back
66
67=head1 SEE ALSO
68
69L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
70L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
71
72=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_alert_type_string.pod b/src/lib/libssl/src/doc/ssl/SSL_alert_type_string.pod
new file mode 100644
index 0000000000..94e28cc307
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_alert_type_string.pod
@@ -0,0 +1,228 @@
1=pod
2
3=head1 NAME
4
5SSL_alert_type_string, SSL_alert_type_string_long, SSL_alert_desc_string, SSL_alert_desc_string_long - get textual description of alert information
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 const char *SSL_alert_type_string(int value);
12 const char *SSL_alert_type_string_long(int value);
13
14 const char *SSL_alert_desc_string(int value);
15 const char *SSL_alert_desc_string_long(int value);
16
17=head1 DESCRIPTION
18
19SSL_alert_type_string() returns a one letter string indicating the
20type of the alert specified by B<value>.
21
22SSL_alert_type_string_long() returns a string indicating the type of the alert
23specified by B<value>.
24
25SSL_alert_desc_string() returns a two letter string as a short form
26describing the reason of the alert specified by B<value>.
27
28SSL_alert_desc_string_long() returns a string describing the reason
29of the alert specified by B<value>.
30
31=head1 NOTES
32
33When one side of an SSL/TLS communication wants to inform the peer about
34a special situation, it sends an alert. The alert is sent as a special message
35and does not influence the normal data stream (unless its contents results
36in the communication being canceled).
37
38A warning alert is sent, when a non-fatal error condition occurs. The
39"close notify" alert is sent as a warning alert. Other examples for
40non-fatal errors are certificate errors ("certificate expired",
41"unsupported certificate"), for which a warning alert may be sent.
42(The sending party may however decide to send a fatal error.) The
43receiving side may cancel the connection on reception of a warning
44alert on it discretion.
45
46Several alert messages must be sent as fatal alert messages as specified
47by the TLS RFC. A fatal alert always leads to a connection abort.
48
49=head1 RETURN VALUES
50
51The following strings can occur for SSL_alert_type_string() or
52SSL_alert_type_string_long():
53
54=over 4
55
56=item "W"/"warning"
57
58=item "F"/"fatal"
59
60=item "U"/"unknown"
61
62This indicates that no support is available for this alert type.
63Probably B<value> does not contain a correct alert message.
64
65=back
66
67The following strings can occur for SSL_alert_desc_string() or
68SSL_alert_desc_string_long():
69
70=over 4
71
72=item "CN"/"close notify"
73
74The connection shall be closed. This is a warning alert.
75
76=item "UM"/"unexpected message"
77
78An inappropriate message was received. This alert is always fatal
79and should never be observed in communication between proper
80implementations.
81
82=item "BM"/"bad record mac"
83
84This alert is returned if a record is received with an incorrect
85MAC. This message is always fatal.
86
87=item "DF"/"decompression failure"
88
89The decompression function received improper input (e.g. data
90that would expand to excessive length). This message is always
91fatal.
92
93=item "HF"/"handshake failure"
94
95Reception of a handshake_failure alert message indicates that the
96sender was unable to negotiate an acceptable set of security
97parameters given the options available. This is a fatal error.
98
99=item "NC"/"no certificate"
100
101A client, that was asked to send a certificate, does not send a certificate
102(SSLv3 only).
103
104=item "BC"/"bad certificate"
105
106A certificate was corrupt, contained signatures that did not
107verify correctly, etc
108
109=item "UC"/"unsupported certificate"
110
111A certificate was of an unsupported type.
112
113=item "CR"/"certificate revoked"
114
115A certificate was revoked by its signer.
116
117=item "CE"/"certificate expired"
118
119A certificate has expired or is not currently valid.
120
121=item "CU"/"certificate unknown"
122
123Some other (unspecified) issue arose in processing the
124certificate, rendering it unacceptable.
125
126=item "IP"/"illegal parameter"
127
128A field in the handshake was out of range or inconsistent with
129other fields. This is always fatal.
130
131=item "DC"/"decryption failed"
132
133A TLSCiphertext decrypted in an invalid way: either it wasn't an
134even multiple of the block length or its padding values, when
135checked, weren't correct. This message is always fatal.
136
137=item "RO"/"record overflow"
138
139A TLSCiphertext record was received which had a length more than
1402^14+2048 bytes, or a record decrypted to a TLSCompressed record
141with more than 2^14+1024 bytes. This message is always fatal.
142
143=item "CA"/"unknown CA"
144
145A valid certificate chain or partial chain was received, but the
146certificate was not accepted because the CA certificate could not
147be located or couldn't be matched with a known, trusted CA. This
148message is always fatal.
149
150=item "AD"/"access denied"
151
152A valid certificate was received, but when access control was
153applied, the sender decided not to proceed with negotiation.
154This message is always fatal.
155
156=item "DE"/"decode error"
157
158A message could not be decoded because some field was out of the
159specified range or the length of the message was incorrect. This
160message is always fatal.
161
162=item "CY"/"decrypt error"
163
164A handshake cryptographic operation failed, including being
165unable to correctly verify a signature, decrypt a key exchange,
166or validate a finished message.
167
168=item "ER"/"export restriction"
169
170A negotiation not in compliance with export restrictions was
171detected; for example, attempting to transfer a 1024 bit
172ephemeral RSA key for the RSA_EXPORT handshake method. This
173message is always fatal.
174
175=item "PV"/"protocol version"
176
177The protocol version the client has attempted to negotiate is
178recognized, but not supported. (For example, old protocol
179versions might be avoided for security reasons). This message is
180always fatal.
181
182=item "IS"/"insufficient security"
183
184Returned instead of handshake_failure when a negotiation has
185failed specifically because the server requires ciphers more
186secure than those supported by the client. This message is always
187fatal.
188
189=item "IE"/"internal error"
190
191An internal error unrelated to the peer or the correctness of the
192protocol makes it impossible to continue (such as a memory
193allocation failure). This message is always fatal.
194
195=item "US"/"user canceled"
196
197This handshake is being canceled for some reason unrelated to a
198protocol failure. If the user cancels an operation after the
199handshake is complete, just closing the connection by sending a
200close_notify is more appropriate. This alert should be followed
201by a close_notify. This message is generally a warning.
202
203=item "NR"/"no renegotiation"
204
205Sent by the client in response to a hello request or by the
206server in response to a client hello after initial handshaking.
207Either of these would normally lead to renegotiation; when that
208is not appropriate, the recipient should respond with this alert;
209at that point, the original requester can decide whether to
210proceed with the connection. One case where this would be
211appropriate would be where a server has spawned a process to
212satisfy a request; the process might receive security parameters
213(key length, authentication, etc.) at startup and it might be
214difficult to communicate changes to these parameters after that
215point. This message is always a warning.
216
217=item "UK"/"unknown"
218
219This indicates that no description is available for this alert type.
220Probably B<value> does not contain a correct alert message.
221
222=back
223
224=head1 SEE ALSO
225
226L<ssl(3)|ssl(3)>, L<SSL_CTX_set_info_callback(3)|SSL_CTX_set_info_callback(3)>
227
228=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_clear.pod b/src/lib/libssl/src/doc/ssl/SSL_clear.pod
new file mode 100644
index 0000000000..862fd8291d
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_clear.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5SSL_clear - reset SSL object to allow another connection
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_clear(SSL *ssl);
12
13=head1 DESCRIPTION
14
15Reset B<ssl> to allow another connection. All settings (method, ciphers,
16BIOs) are kept. A completely negotiated B<SSL_SESSION> is not freed but left
17untouched for the underlying B<SSL_CTX>.
18
19=head1 RETURN VALUES
20
21The following return values can occur:
22
23=over 4
24
25=item 0
26
27The SSL_clear() operation could not be performed. Check the error stack to
28find out the reason.
29
30=item 1
31
32The SSL_clear() operation was successful.
33
34=back
35
36L<SSL_new(3)|SSL_new(3)>, L<SSL_free(3)|SSL_free(3)>,
37L<ssl(3)|ssl(3)>
38
39=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_connect.pod b/src/lib/libssl/src/doc/ssl/SSL_connect.pod
new file mode 100644
index 0000000000..debe41744f
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_connect.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5SSL_connect - initiate the TLS/SSL handshake with an TLS/SSL server
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_connect(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_connect() initiates the TLS/SSL handshake with a server. The communication
16channel must already have been set and assigned to the B<ssl> by setting an
17underlying B<BIO>.
18
19=head1 NOTES
20
21The behaviour of SSL_connect() depends on the underlying BIO.
22
23If the underlying BIO is B<blocking>, SSL_connect() will only return once the
24handshake has been finished or an error occurred.
25
26If the underlying BIO is B<non-blocking>, SSL_connect() will also return
27when the underlying BIO could not satisfy the needs of SSL_connect()
28to continue the handshake. In this case a call to SSL_get_error() with the
29return value of SSL_connect() will yield B<SSL_ERROR_WANT_READ> or
30B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
31taking appropriate action to satisfy the needs of SSL_connect().
32The action depends on the underlying BIO. When using a non-blocking socket,
33nothing is to be done, but select() can be used to check for the required
34condition. When using a buffering BIO, like a BIO pair, data must be written
35into or retrieved out of the BIO before being able to continue.
36
37=head1 RETURN VALUES
38
39The following return values can occur:
40
41=over 4
42
43=item 1
44
45The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
46established.
47
48=item 0
49
50The TLS/SSL handshake was not successful but was shut down controlled and
51by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
52return value B<ret> to find out the reason.
53
54=item -1
55
56The TLS/SSL handshake was not successful, because a fatal error occurred either
57at the protocol level or a connection failure occurred. The shutdown was
58not clean. It can also occur of action is need to continue the operation
59for non-blocking BIOs. Call SSL_get_error() with the return value B<ret>
60to find out the reason.
61
62=back
63
64=head1 SEE ALSO
65
66L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_accept(3)|SSL_accept(3)>,
67L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
68
69=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_free.pod b/src/lib/libssl/src/doc/ssl/SSL_free.pod
new file mode 100644
index 0000000000..f3f0c345f8
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_free.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5SSL_free - free an allocated SSL structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_free(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_free() decrements the reference count of B<ssl>, and removes the SSL
16structure pointed to by B<ssl> and frees up the allocated memory if the
17the reference count has reached 0.
18
19It also calls the free()ing procedures for indirectly affected items, if
20applicable: the buffering BIO, the read and write BIOs,
21cipher lists specially created for this B<ssl>, the B<SSL_SESSION>.
22Do not explicitly free these indirectly freed up items before or after
23calling SSL_free(), as trying to free things twice may lead to program
24failure.
25
26=head1 RETURN VALUES
27
28SSL_free() does not provide diagnostic information.
29
30L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>,
31L<ssl(3)|ssl(3)>
32
33=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_SSL_CTX.pod b/src/lib/libssl/src/doc/ssl/SSL_get_SSL_CTX.pod
new file mode 100644
index 0000000000..52d0227b19
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_SSL_CTX.pod
@@ -0,0 +1,26 @@
1=pod
2
3=head1 NAME
4
5SSL_get_SSL_CTX - get the SSL_CTX from which an SSL is created
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_SSL_CTX() returns a pointer to the SSL_CTX object, from which
16B<ssl> was created with L<SSL_new(3)|SSL_new(3)>.
17
18=head1 RETURN VALUES
19
20The pointer to the SSL_CTX object is returned.
21
22=head1 SEE ALSO
23
24L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>
25
26=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_ciphers.pod b/src/lib/libssl/src/doc/ssl/SSL_get_ciphers.pod
new file mode 100644
index 0000000000..2a57455c23
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_ciphers.pod
@@ -0,0 +1,42 @@
1=pod
2
3=head1 NAME
4
5SSL_get_ciphers, SSL_get_cipher_list - get list of available SSL_CIPHERs
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *ssl);
12 const char *SSL_get_cipher_list(SSL *ssl, int priority);
13
14=head1 DESCRIPTION
15
16SSL_get_ciphers() returns the stack of available SSL_CIPHERs for B<ssl>,
17sorted by preference. If B<ssl> is NULL or no ciphers are available, NULL
18is returned.
19
20SSL_get_cipher_list() returns a pointer to the name of the SSL_CIPHER
21listed for B<ssl> with B<priority>. If B<ssl> is NULL, no ciphers are
22available, or there are less ciphers than B<priority> available, NULL
23is returned.
24
25=head1 NOTES
26
27The details of the ciphers obtained by SSL_get_ciphers() can be obtained using
28the L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)> family of functions.
29
30Call SSL_get_cipher_list() with B<priority> starting from 0 to obtain the
31sorted list of available ciphers, until NULL is returned.
32
33=head1 RETURN VALUES
34
35See DESCRIPTION
36
37=head1 SEE ALSO
38
39L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
40L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)>
41
42=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_client_CA_list.pod b/src/lib/libssl/src/doc/ssl/SSL_get_client_CA_list.pod
new file mode 100644
index 0000000000..40e01cf9c8
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_client_CA_list.pod
@@ -0,0 +1,52 @@
1=pod
2
3=head1 NAME
4
5SSL_get_client_CA_list, SSL_CTX_get_client_CA_list - get list of client CAs
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
12 STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx);
13
14=head1 DESCRIPTION
15
16SSL_CTX_get_client_CA_list() returns the list of client CAs explicitly set for
17B<ctx> using L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>.
18
19SSL_get_client_CA_list() returns the list of client CAs explicitly
20set for B<ssl> using SSL_set_client_CA_list() or B<ssl>'s SSL_CTX object with
21L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>, when in
22server mode. In client mode, SSL_get_client_CA_list returns the list of
23client CAs sent from the server, if any.
24
25=head1 RETURN VALUES
26
27SSL_CTX_set_client_CA_list() and SSL_set_client_CA_list() do not return
28diagnostic information.
29
30SSL_CTX_add_client_CA() and SSL_add_client_CA() have the following return
31values:
32
33=over 4
34
35=item STACK_OF(X509_NAMES)
36
37List of CA names explicitly set (for B<ctx> or in server mode) or send
38by the server (client mode).
39
40=item NULL
41
42No client CA list was explicitly set (for B<ctx> or in server mode) or
43the server did not send a list of CAs (client mode).
44
45=back
46
47=head1 SEE ALSO
48
49L<ssl(3)|ssl(3)>,
50L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>
51
52=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_current_cipher.pod b/src/lib/libssl/src/doc/ssl/SSL_get_current_cipher.pod
new file mode 100644
index 0000000000..2dd7261d89
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_current_cipher.pod
@@ -0,0 +1,43 @@
1=pod
2
3=head1 NAME
4
5SSL_get_current_cipher, SSL_get_cipher, SSL_get_cipher_name,
6SSL_get_cipher_bits, SSL_get_cipher_version - get SSL_CIPHER of a connection
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 SSL_CIPHER *SSL_get_current_cipher(SSL *ssl);
13 #define SSL_get_cipher(s) \
14 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
15 #define SSL_get_cipher_name(s) \
16 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
17 #define SSL_get_cipher_bits(s,np) \
18 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
19 #define SSL_get_cipher_version(s) \
20 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
21
22=head1 DESCRIPTION
23
24SSL_get_current_cipher() returns a pointer to an SSL_CIPHER object containing
25the description of the actually used cipher of a connection established with
26the B<ssl> object.
27
28SSL_get_cipher() and SSL_get_cipher_name() are identical macros to obtain the
29name of the currently used cipher. SSL_get_cipher_bits() is a
30macro to obtain the number of secret/algorithm bits used and
31SSL_get_cipher_version() returns the protocol name.
32See L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)> for more details.
33
34=head1 RETURN VALUES
35
36SSL_get_current_cipher() returns the cipher actually used or NULL, when
37no session has been established.
38
39=head1 SEE ALSO
40
41L<ssl(3)|ssl(3)>, L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)>
42
43=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_default_timeout.pod b/src/lib/libssl/src/doc/ssl/SSL_get_default_timeout.pod
new file mode 100644
index 0000000000..8d43b31345
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_default_timeout.pod
@@ -0,0 +1,41 @@
1=pod
2
3=head1 NAME
4
5SSL_get_default_timeout - get default session timeout value
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_get_default_timeout(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_default_timeout() returns the default timeout value assigned to
16SSL_SESSION objects negotiated for the protocol valid for B<ssl>.
17
18=head1 NOTES
19
20Whenever a new session is negotiated, it is assigned a timeout value,
21after which it will not be accepted for session reuse. If the timeout
22value was not explicitly set using
23L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>, the hardcoded default
24timeout for the protocol will be used.
25
26SSL_get_default_timeout() return this hardcoded value, which is 300 seconds
27for all currently supported protocols (SSLv2, SSLv3, and TLSv1).
28
29=head1 RETURN VALUES
30
31See description.
32
33=head1 SEE ALSO
34
35L<ssl(3)|ssl(3)>,
36L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
37L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)>,
38L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
39L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>
40
41=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_error.pod b/src/lib/libssl/src/doc/ssl/SSL_get_error.pod
new file mode 100644
index 0000000000..9cacdedc57
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_error.pod
@@ -0,0 +1,91 @@
1=pod
2
3=head1 NAME
4
5SSL_get_error - obtain result code for SSL I/O operation
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_get_error(SSL *ssl, int ret);
12
13=head1 DESCRIPTION
14
15SSL_get_error() returns a result code (suitable for the C "switch"
16statement) for a preceding call to SSL_connect(), SSL_accept(),
17SSL_read(), or SSL_write() on B<ssl>. The value returned by that
18SSL I/O function must be passed to SSL_get_error() in parameter
19B<ret>.
20
21In addition to B<ssl> and B<ret>, SSL_get_error() inspects the
22current thread's OpenSSL error queue. Thus, SSL_get_error() must be
23used in the same thread that performed the SSL I/O operation, and no
24other OpenSSL function calls should appear in between. The current
25thread's error queue must be empty before the SSL I/O operation is
26attempted, or SSL_get_error() will not work reliably.
27
28=head1 RETURN VALUES
29
30The following return values can currently occur:
31
32=over 4
33
34=item SSL_ERROR_NONE
35
36The SSL I/O operation completed. This result code is returned
37if and only if B<ret E<gt> 0>.
38
39=item SSL_ERROR_ZERO_RETURN
40
41The SSL connection has been closed. If the protocol version is SSL 3.0
42or TLS 1.0, this result code is returned only if a closure
43alerts has occurred in the protocol, i.e. if the connection has been
44closed cleanly.
45
46=item SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
47
48The operation did not complete; the same SSL I/O function should be
49called again later. There will be protocol progress if, by then, the
50underlying B<BIO> has data available for reading (if the result code is
51B<SSL_ERROR_WANT_READ>) or allows writing data (B<SSL_ERROR_WANT_WRITE>).
52For socket B<BIO>s (e.g. when SSL_set_fd() was used) this means that
53select() or poll() on the underlying socket can be used to find out
54when the SSL I/O function should be retried.
55
56Caveat: Any SSL I/O function can lead to either of
57B<SSL_ERROR_WANT_READ> and B<SSL_ERROR_WANT_WRITE>, i.e. SSL_read()
58may want to write data and SSL_write() may want to read data.
59
60=item SSL_ERROR_WANT_X509_LOOKUP
61
62The operation did not complete because an application callback set by
63SSL_CTX_set_client_cert_cb() has asked to be called again.
64The SSL I/O function should be called again later.
65Details depend on the application.
66
67=item SSL_ERROR_SYSCALL
68
69Some I/O error occurred. The OpenSSL error queue may contain more
70information on the error. If the error queue is empty
71(i.e. ERR_get_error() returns 0), B<ret> can be used to find out more
72about the error: If B<ret == 0>, an EOF was observed that violates
73the protocol. If B<ret == -1>, the underlying B<BIO> reported an
74I/O error (for socket I/O on Unix systems, consult B<errno> for details).
75
76=item SSL_ERROR_SSL
77
78A failure in the SSL library occurred, usually a protocol error. The
79OpenSSL error queue contains more information on the error.
80
81=back
82
83=head1 SEE ALSO
84
85L<ssl(3)|ssl(3)>, L<err(3)|err(3)>
86
87=head1 HISTORY
88
89SSL_get_error() was added in SSLeay 0.8.
90
91=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod b/src/lib/libssl/src/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
new file mode 100644
index 0000000000..165c6a5b2c
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
@@ -0,0 +1,61 @@
1=pod
2
3=head1 NAME
4
5SSL_get_ex_data_X509_STORE_CTX_idx - get ex_data index to access SSL structure
6from X509_STORE_CTX
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 int SSL_get_ex_data_X509_STORE_CTX_idx(void);
13
14=head1 DESCRIPTION
15
16SSL_get_ex_data_X509_STORE_CTX_idx() returns the index number under which
17the pointer to the SSL object is stored into the X509_STORE_CTX object.
18
19=head1 NOTES
20
21Whenever a X509_STORE_CTX object is created for the verification of the
22peers certificate during a handshake, a pointer to the SSL object is
23stored into the X509_STORE_CTX object to identify the connection affected.
24To retrieve this pointer the X509_STORE_CTX_get_ex_data() function can
25be used with the correct index. This index is globally the same for all
26X509_STORE_CTX objects and can be retrieved using
27SSL_get_ex_data_X509_STORE_CTX_idx(). The index value is set when
28SSL_get_ex_data_X509_STORE_CTX_idx() is first called either by the application
29program directly or indirectly during other SSL setup functions or during
30the handshake.
31
32The value depends on other index values defined for X509_STORE_CTX objects
33before the SSL index is created.
34
35=head1 RETURN VALUES
36
37=over 4
38
39=item E<gt>=0
40
41The index value to access the pointer.
42
43=item E<lt>0
44
45An error occurred, check the error stack for a detailed error message.
46
47=back
48
49=head1 EXAMPLES
50
51The index returned from SSL_get_ex_data_X509_STORE_CTX_idx() allows to
52access the SSL object for the connection to be accessed during the
53verify_callback() when checking the peers certificate. Please check
54the example in L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
55
56=head1 SEE ALSO
57
58L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
59L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
60
61=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_ex_new_index.pod b/src/lib/libssl/src/doc/ssl/SSL_get_ex_new_index.pod
new file mode 100644
index 0000000000..2b69bb1050
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_ex_new_index.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5SSL_get_ex_new_index, SSL_set_ex_data, SSL_get_ex_data - internal application specific data functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int SSL_set_ex_data(SSL *ssl, int idx, void *arg);
17
18 void *SSL_get_ex_data(SSL *ssl, int idx);
19
20 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp);
26
27=head1 DESCRIPTION
28
29Several OpenSSL structures can have application specific data attached to them.
30These functions are used internally by OpenSSL to manipulate application
31specific data attached to a specific structure.
32
33SSL_get_ex_new_index() is used to register a new index for application
34specific data.
35
36SSL_set_ex_data() is used to store application data at B<arg> for B<idx> into
37the B<ssl> object.
38
39SSL_get_ex_data() is used to retrieve the information for B<idx> from
40B<ssl>.
41
42A detailed description for the B<*_get_ex_new_index()> functionality
43can be found in L<RSA_get_ex_new_index.pod(3)|RSA_get_ex_new_index.pod(3)>.
44The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
45L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
46
47=head1 EXAMPLES
48
49An example on how to use the functionality is included in the example
50verify_callback() in L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>.
51
52=head1 SEE ALSO
53
54L<ssl(3)|ssl(3)>,
55L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
56L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>,
57L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
58
59=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_fd.pod b/src/lib/libssl/src/doc/ssl/SSL_get_fd.pod
new file mode 100644
index 0000000000..a3f7625931
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_fd.pod
@@ -0,0 +1,44 @@
1=pod
2
3=head1 NAME
4
5SSL_get_fd - get file descriptor linked to an SSL object
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_get_fd(SSL *ssl);
12 int SSL_get_rfd(SSL *ssl);
13 int SSL_get_wfd(SSL *ssl);
14
15=head1 DESCRIPTION
16
17SSL_get_fd() returns the file descriptor which is linked to B<ssl>.
18SSL_get_rfd() and SSL_get_wfd() return the file descriptors for the
19read or the write channel, which can be different. If the read and the
20write channel are different, SSL_get_fd() will return the file descriptor
21of the read channel.
22
23=head1 RETURN VALUES
24
25The following return values can occur:
26
27=over 4
28
29=item -1
30
31The operation failed, because the underlying BIO is not of the correct type
32(suitable for file descriptors).
33
34=item E<gt>=0
35
36The file descriptor linked to B<ssl>.
37
38=back
39
40=head1 SEE ALSO
41
42L<SSL_set_fd(3)|SSL_set_fd(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
43
44=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_peer_cert_chain.pod b/src/lib/libssl/src/doc/ssl/SSL_get_peer_cert_chain.pod
new file mode 100644
index 0000000000..e93e8206fa
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_peer_cert_chain.pod
@@ -0,0 +1,52 @@
1=pod
2
3=head1 NAME
4
5SSL_get_peer_cert_chain - get the X509 certificate chain of the peer
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 STACKOF(X509) *SSL_get_peer_cert_chain(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_peer_cert_chain() returns a pointer to STACKOF(X509) certificates
16forming the certificate chain of the peer. If called on the client side,
17the stack also contains the peer's certificate; if called on the server
18side, the peer's certificate must be obtained seperately using
19L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>.
20If the peer did not present a certificate, NULL is returned.
21
22=head1 NOTES
23
24The peer certificate chain is not necessarily available after reusing
25a session, in which case a NULL pointer is returned.
26
27The reference count of the STACKOF(X509) object is not incremented.
28If the corresponding session is freed, the pointer must not be used
29any longer.
30
31=head1 RETURN VALUES
32
33The following return values can occur:
34
35=over 4
36
37=item NULL
38
39No certificate was presented by the peer or no connection was established
40or the certificate chain is no longer available when a session is reused.
41
42=item Pointer to a STACKOF(X509)
43
44The return value points to the certificate chain presented by the peer.
45
46=back
47
48=head1 SEE ALSO
49
50L<ssl(3)|ssl(3)>, L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>
51
52=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_peer_certificate.pod b/src/lib/libssl/src/doc/ssl/SSL_get_peer_certificate.pod
new file mode 100644
index 0000000000..79c089aa51
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_peer_certificate.pod
@@ -0,0 +1,48 @@
1=pod
2
3=head1 NAME
4
5SSL_get_peer_certificate - get the X509 certificate of the peer
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 X509 *SSL_get_peer_certificate(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_peer_certificate() returns a pointer to the X509 certificate the
16peer presented. If the peer did not present a certificate, NULL is returned.
17
18=head1 NOTES
19
20That a certificate is returned does not indicate information about the
21verification state, use L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>
22to check the verification state.
23
24The reference count of the X509 object is incremented by one, so that it
25will not be destroyed when the session containing the peer certificate is
26freed. The X509 object must be explicitely freed using X509_free().
27
28=head1 RETURN VALUES
29
30The following return values can occur:
31
32=over 4
33
34=item NULL
35
36No certificate was presented by the peer or no connection was established.
37
38=item Pointer to an X509 certificate
39
40The return value points to the certificate presented by the peer.
41
42=back
43
44=head1 SEE ALSO
45
46L<ssl(3)|ssl(3)>, L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>
47
48=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_rbio.pod b/src/lib/libssl/src/doc/ssl/SSL_get_rbio.pod
new file mode 100644
index 0000000000..3d98233cac
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_rbio.pod
@@ -0,0 +1,40 @@
1=pod
2
3=head1 NAME
4
5SSL_get_rbio - get BIO linked to an SSL object
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 BIO *SSL_get_rbio(SSL *ssl);
12 BIO *SSL_get_wbio(SSL *ssl);
13
14=head1 DESCRIPTION
15
16SSL_get_rbio() and SSL_get_wbio() return pointers to the BIOs for the
17read or the write channel, which can be different. The reference count
18of the BIO is not incremented.
19
20=head1 RETURN VALUES
21
22The following return values can occur:
23
24=over 4
25
26=item NULL
27
28No BIO was connected to the SSL object
29
30=item Any other pointer
31
32The BIO linked to B<ssl>.
33
34=back
35
36=head1 SEE ALSO
37
38L<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
39
40=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_session.pod b/src/lib/libssl/src/doc/ssl/SSL_get_session.pod
new file mode 100644
index 0000000000..aff41fb9cf
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_session.pod
@@ -0,0 +1,48 @@
1=pod
2
3=head1 NAME
4
5SSL_get_session - retrieve TLS/SSL session data
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 SSL_SESSION *SSL_get_session(SSL *ssl);
12 SSL_SESSION *SSL_get0_session(SSL *ssl);
13 SSL_SESSION *SSL_get1_session(SSL *ssl);
14
15=head1 DESCRIPTION
16
17SSL_get_session() returns a pointer to the B<SSL_SESSION> actually used in
18B<ssl>. The reference count of the B<SSL_SESSION> is not incremented, so
19that the pointer can become invalid when the B<ssl> is freed and
20SSL_SESSION_free() is implicitly called.
21
22SSL_get0_session() is the same as SSL_get_session().
23
24SSL_get1_session() is the same as SSL_get_session(), but the reference
25count of the B<SSL_SESSION> is incremented by one.
26
27=head1 RETURN VALUES
28
29The following return values can occur:
30
31=over 4
32
33=item NULL
34
35There is no session available in B<ssl>.
36
37=item Pointer to an SSL
38
39The return value points to the data of an SSL session.
40
41=back
42
43=head1 SEE ALSO
44
45L<ssl(3)|ssl(3)>, L<SSL_free(3)|SSL_free(3)>,
46L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>
47
48=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_verify_result.pod b/src/lib/libssl/src/doc/ssl/SSL_get_verify_result.pod
new file mode 100644
index 0000000000..4d66236a05
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_verify_result.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5SSL_get_verify_result - get result of peer certificate verification
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 long SSL_get_verify_result(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_verify_result() returns the result of the verification of the
16X509 certificate presented by the peer, if any.
17
18=head1 NOTES
19
20SSL_get_verify_result() can only return one error code while the verification
21of a certificate can fail because of many reasons at the same time. Only
22the last verification error that occured during the processing is available
23from SSL_get_verify_result().
24
25The verification result is part of the established session and is restored
26when a session is reused.
27
28=head1 BUGS
29
30If no peer certificate was presented, the returned result code is
31X509_V_OK. This is because no verification error occured, it does however
32not indicate success. SSL_get_verify_result() is only useful in connection
33with L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>.
34
35=head1 RETURN VALUES
36
37The following return values can currently occur:
38
39=over 4
40
41=item X509_V_OK
42
43The verification succeeded or no peer certificate was presented.
44
45=item Any other value
46
47Documented in L<verify(1)|verify(1)>.
48
49=back
50
51=head1 SEE ALSO
52
53L<ssl(3)|ssl(3)>, L<SSL_set_verify_result(3)|SSL_set_verify_result(3)>,
54L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
55L<verify(1)|verify(1)>
56
57=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_get_version.pod b/src/lib/libssl/src/doc/ssl/SSL_get_version.pod
new file mode 100644
index 0000000000..24d5291256
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_get_version.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5SSL_get_version - get the protocol version of a connection.
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 const char *SSL_get_version(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_get_cipher_version() returns the name of the protocol used for the
16connection B<ssl>.
17
18=head1 RETURN VALUES
19
20The following strings can occur:
21
22=over 4
23
24=item SSLv2
25
26The connection uses the SSLv2 protocol.
27
28=item SSLv3
29
30The connection uses the SSLv3 protocol.
31
32=item TLSv1
33
34The connection uses the TLSv1 protocol.
35
36=item unknown
37
38This indicates that no version has been set (no connection established).
39
40=back
41
42=head1 SEE ALSO
43
44L<ssl(3)|ssl(3)>
45
46=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_library_init.pod b/src/lib/libssl/src/doc/ssl/SSL_library_init.pod
new file mode 100644
index 0000000000..ecf3c4858e
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_library_init.pod
@@ -0,0 +1,52 @@
1=pod
2
3=head1 NAME
4
5SSL_library_init, OpenSSL_add_ssl_algorithms, SSLeay_add_ssl_algorithms
6- initialize SSL library by registering algorithms
7
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
12 int SSL_library_init(void);
13 #define OpenSSL_add_ssl_algorithms() SSL_library_init()
14 #define SSLeay_add_ssl_algorithms() SSL_library_init()
15
16=head1 DESCRIPTION
17
18SSL_library_init() registers the available ciphers and digests.
19
20OpenSSL_add_ssl_algorithms() and SSLeay_add_ssl_algorithms() are synonyms
21for SSL_library_init().
22
23=head1 NOTES
24
25SSL_library_init() must be called before any other action takes place.
26
27=head1 WARNING
28
29SSL_library_init() only registers ciphers. Another important initialization
30is the seeding of the PRNG (Pseudo Random Number Generator), which has to
31be performed separately.
32
33=head1 EXAMPLES
34
35A typical TLS/SSL application will start with the library initialization,
36will provide readable error messages and will seed the PRNG.
37
38 SSL_load_error_strings(); /* readable error messages */
39 SSL_library_init(); /* initialize library */
40 actions_to_seed_PRNG();
41
42=head1 RETURN VALUES
43
44SSL_library_init() always returns "1", so it is safe to discard the return
45value.
46
47=head1 SEE ALSO
48
49L<ssl(3)|ssl(3)>, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>,
50L<RAND_add(3)|RAND_add(3)>
51
52=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_load_client_CA_file.pod b/src/lib/libssl/src/doc/ssl/SSL_load_client_CA_file.pod
new file mode 100644
index 0000000000..02527dc2ed
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_load_client_CA_file.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5SSL_load_client_CA_file - load certificate names from file
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
12
13=head1 DESCRIPTION
14
15SSL_load_client_CA_file() reads certificates from B<file> and returns
16a STACK_OF(X509_NAME) with the subject names found.
17
18=head1 NOTES
19
20SSL_load_client_CA_file() reads a file of PEM formatted certificates and
21extracts the X509_NAMES of the certificates found. While the name suggests
22the specific usage as support function for
23L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
24it is not limited to CA certificates.
25
26=head1 EXAMPLES
27
28Load names of CAs from file and use it as a client CA list:
29
30 SSL_CTX *ctx;
31 STACK_OF(X509_NAME) *cert_names;
32
33 ...
34 cert_names = SSL_load_client_CA_file("/path/to/CAfile.pem");
35 if (cert_names != NULL)
36 SSL_CTX_set_client_CA_list(ctx, cert_names);
37 else
38 error_handling();
39 ...
40
41=head1 RETURN VALUES
42
43The following return values can occur:
44
45=over 4
46
47=item NULL
48
49The operation failed, check out the error stack for the reason.
50
51=item Pointer to STACK_OF(X509_NAME)
52
53Pointer to the subject names of the successfully read certificates.
54
55=back
56
57=head1 SEE ALSO
58
59L<ssl(3)|ssl(3)>,
60L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>
61
62=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_new.pod b/src/lib/libssl/src/doc/ssl/SSL_new.pod
new file mode 100644
index 0000000000..8e8638fa95
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_new.pod
@@ -0,0 +1,42 @@
1=pod
2
3=head1 NAME
4
5SSL_new - create a new SSL structure for a connection
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 SSL *SSL_new(SSL_CTX *ctx);
12
13=head1 DESCRIPTION
14
15SSL_new() creates a new B<SSL> structure which is needed to hold the
16data for a TLS/SSL connection. The new structure inherits the settings
17of the underlying context B<ctx>: connection method (SSLv2/v3/TLSv1),
18options, verification settings, timeout settings.
19
20=head1 RETURN VALUES
21
22The following return values can occur:
23
24=over 4
25
26=item NULL
27
28The creation of a new SSL structure failed. Check the error stack to
29find out the reason.
30
31=item Pointer to an SSL structure
32
33The return value points to an allocated SSL structure.
34
35=back
36
37=head1 SEE ALSO
38
39L<SSL_free(3)|SSL_free(3)>, L<SSL_clear(3)|SSL_clear(3)>,
40L<ssl(3)|ssl(3)>
41
42=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_pending.pod b/src/lib/libssl/src/doc/ssl/SSL_pending.pod
new file mode 100644
index 0000000000..744e1855e1
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_pending.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5SSL_pending - obtain number of readable bytes buffered in an SSL object
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_pending(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_pending() returns the number of bytes which are available inside
16B<ssl> for immediate read.
17
18=head1 NOTES
19
20Data are received in blocks from the peer. Therefore data can be buffered
21inside B<ssl> and are ready for immediate retrieval with
22L<SSL_read(3)|SSL_read(3)>.
23
24=head1 RETURN VALUES
25
26The number of bytes pending is returned.
27
28L<SSL_read(3)|SSL_read(3)>, L<ssl(3)|ssl(3)>
29
30=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_read.pod b/src/lib/libssl/src/doc/ssl/SSL_read.pod
new file mode 100644
index 0000000000..072dc26cf2
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_read.pod
@@ -0,0 +1,77 @@
1=pod
2
3=head1 NAME
4
5SSL_read - read bytes from a TLS/SSL connection.
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_read(SSL *ssl, char *buf, int num);
12
13=head1 DESCRIPTION
14
15SSL_read() tries to read B<num> bytes from the specified B<ssl> into the
16buffer B<buf>.
17
18=head1 NOTES
19
20If necessary, SSL_read() will negotiate a TLS/SSL session, if
21not already explicitly performed by SSL_connect() or SSL_accept(). If the
22peer requests a re-negotiation, it will be performed transparently during
23the SSL_read() operation. The behaviour of SSL_read() depends on the
24underlying BIO.
25
26If the underlying BIO is B<blocking>, SSL_read() will only return, once the
27read operation has been finished or an error occurred.
28
29If the underlying BIO is B<non-blocking>, SSL_read() will also return
30when the underlying BIO could not satisfy the needs of SSL_read()
31to continue the operation. In this case a call to SSL_get_error() with the
32return value of SSL_read() will yield B<SSL_ERROR_WANT_READ> or
33B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
34call to SSL_read() can also cause write operations! The calling process
35then must repeat the call after taking appropriate action to satisfy the
36needs of SSL_read(). The action depends on the underlying BIO. When using a
37non-blocking socket, nothing is to be done, but select() can be used to check
38for the required condition. When using a buffering BIO, like a BIO pair, data
39must be written into or retrieved out of the BIO before being able to continue.
40
41=head1 WARNING
42
43When an SSL_read() operation has to be repeated because of
44B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
45with the same arguments.
46
47=head1 RETURN VALUES
48
49The following return values can occur:
50
51=over 4
52
53=item E<gt>0
54
55The read operation was successful; the return value is the number of
56bytes actually read from the TLS/SSL connection.
57
58=item 0
59
60The read operation was not successful, probably because no data was
61available. Call SSL_get_error() with the return value B<ret> to find out,
62whether an error occurred.
63
64=item -1
65
66The read operation was not successful, because either an error occurred
67or action must be taken by the calling process. Call SSL_get_error() with the
68return value B<ret> to find out the reason.
69
70=back
71
72=head1 SEE ALSO
73
74L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_write(3)|SSL_write(3)>,
75L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
76
77=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_rstate_string.pod b/src/lib/libssl/src/doc/ssl/SSL_rstate_string.pod
new file mode 100644
index 0000000000..bdb8a1fcd5
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_rstate_string.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5SSL_rstate_string, SSL_rstate_string_long - get textual description of state of an SSL object during read operation
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 const char *SSL_rstate_string(SSL *ssl);
12 const char *SSL_rstate_string_long(SSL *ssl);
13
14=head1 DESCRIPTION
15
16SSL_rstate_string() returns a 2 letter string indicating the current read state
17of the SSL object B<ssl>.
18
19SSL_rstate_string_long() returns a string indicating the current read state of
20the SSL object B<ssl>.
21
22=head1 NOTES
23
24When performing a read operation, the SSL/TLS engine must parse the record,
25consisting of header and body. When working in a blocking environment,
26SSL_rstate_string[_long]() should always return "RD"/"read done".
27
28This function should only seldom be needed in applications.
29
30=head1 RETURN VALUES
31
32SSL_rstate_string() and SSL_rstate_string_long() can return the following
33values:
34
35=over 4
36
37=item "RH"/"read header"
38
39The header of the record is being evaluated.
40
41=item "RB"/"read body"
42
43The body of the record is being evaluated.
44
45=item "RD"/"read done"
46
47The record has been completely processed.
48
49=item "unknown"/"unknown"
50
51The read state is unknown. This should never happen.
52
53=back
54
55=head1 SEE ALSO
56
57L<ssl(3)|ssl(3)>
58
59=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_session_reused.pod b/src/lib/libssl/src/doc/ssl/SSL_session_reused.pod
new file mode 100644
index 0000000000..da7d06264d
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_session_reused.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5SSL_session_reused - query whether a reused session was negotiated during handshake
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_session_reused(SSL *ssl);
12
13=head1 DESCRIPTION
14
15Query, whether a reused session was negotiated during the handshake.
16
17=head1 NOTES
18
19During the negotiation, a client can propose to reuse a session. The server
20then looks up the session in its cache. If both client and server agree
21on the session, it will be reused and a flag is being set that can be
22queried by the application.
23
24=head1 RETURN VALUES
25
26The following return values can occur:
27
28=over 4
29
30=item 0
31
32A new session was negotiated.
33
34=item 1
35
36A session was reused.
37
38=back
39
40=head1 SEE ALSO
41
42L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
43L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
44
45=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_bio.pod b/src/lib/libssl/src/doc/ssl/SSL_set_bio.pod
new file mode 100644
index 0000000000..67c9756d3f
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_bio.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5SSL_set_bio - connect the SSL object with a BIO
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio);
12
13=head1 DESCRIPTION
14
15SSL_set_bio() connects the BIOs B<rbio> and B<wbio> for the read and write
16operations of the TLS/SSL (encrypted) side of B<ssl>.
17
18The SSL engine inherits the behaviour of B<rbio> and B<wbio>, respectively.
19If a BIO is non-blocking, the B<ssl> will also have non-blocking behaviour.
20
21If there was already a BIO connected to B<ssl>, BIO_free() will be called
22(for both the reading and writing side, if different).
23
24=head1 RETURN VALUES
25
26SSL_set_bio() cannot fail.
27
28=head1 SEE ALSO
29
30L<SSL_get_rbio(3)|SSL_get_rbio(3)>,
31L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>,
32L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
33
34=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_connect_state.pod b/src/lib/libssl/src/doc/ssl/SSL_set_connect_state.pod
new file mode 100644
index 0000000000..a8c4463c64
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_connect_state.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5SSL_set_connect_state, SSL_get_accept_state - prepare SSL object to work in client or server mode
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_set_connect_state(SSL *ssl);
12
13 void SSL_set_accept_state(SSL *ssl);
14
15=head1 DESCRIPTION
16
17SSL_set_connect_state() B<ssl> to work in client mode.
18
19SSL_set_accept_state() B<ssl> to work in server mode.
20
21=head1 NOTES
22
23When the SSL_CTX object was created with L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
24it was either assigned a dedicated client method, a dedicated server
25method, or a generic method, that can be used for both client and
26server connections. (The method might have been changed with
27L<SSL_CTX_set_ssl_version(3)|SSL_CTX_set_ssl_version(3)> or
28SSL_set_ssl_method().)
29
30In order to successfully accomplish the handshake, the SSL routines need
31to know whether they should act in server or client mode. If the generic
32method was used, this is not clear from the method itself and must be set
33with either SSL_set_connect_state() or SSL_set_accept_state(). If these
34routines are not called, the default value set when L<SSL_new(3)|SSL_new(3)>
35is called is server mode.
36
37=head1 RETURN VALUES
38
39SSL_set_connect_state() and SSL_set_accept_state() do not return diagnostic
40information.
41
42=head1 SEE ALSO
43
44L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
45L<SSL_CTX_set_ssl_version(3)|SSL_CTX_set_ssl_version(3)>
46
47=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_fd.pod b/src/lib/libssl/src/doc/ssl/SSL_set_fd.pod
new file mode 100644
index 0000000000..70291128fc
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_fd.pod
@@ -0,0 +1,54 @@
1=pod
2
3=head1 NAME
4
5SSL_set_fd - connect the SSL object with a file descriptor
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_set_fd(SSL *ssl, int fd);
12 int SSL_set_rfd(SSL *ssl, int fd);
13 int SSL_set_wfd(SSL *ssl, int fd);
14
15=head1 DESCRIPTION
16
17SSL_set_fd() sets the file descriptor B<fd> as the input/output facility
18for the TLS/SSL (encrypted) side of B<ssl>. B<fd> will typically be the
19socket file descriptor of a network connection.
20
21When performing the operation, a B<socket BIO> is automatically created to
22interface between the B<ssl> and B<fd>. The BIO and hence the SSL engine
23inherit the behaviour of B<fd>. If B<fd> is non-blocking, the B<ssl> will
24also have non-blocking behaviour.
25
26If there was already a BIO connected to B<ssl>, BIO_free() will be called
27(for both the reading and writing side, if different).
28
29SSL_set_rfd() and SSL_set_wfd() perform the respective action, but only
30for the read channel or the write channel, which can be set independently.
31
32=head1 RETURN VALUES
33
34The following return values can occur:
35
36=over 4
37
38=item 0
39
40The operation failed. Check the error stack to find out why.
41
42=item 1
43
44The operation succeeded.
45
46=back
47
48=head1 SEE ALSO
49
50L<SSL_get_fd(3)|SSL_get_fd(3)>, L<SSL_set_bio(3)|SSL_set_bio(3)>,
51L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>,
52L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
53
54=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_session.pod b/src/lib/libssl/src/doc/ssl/SSL_set_session.pod
new file mode 100644
index 0000000000..9f78d9e434
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_session.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5SSL_set_session - set a TLS/SSL session to be used during TLS/SSL connect
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
12
13=head1 DESCRIPTION
14
15SSL_set_session() sets B<session> to be used when the TLS/SSL connection
16is to be established. SSL_set_session() is only useful for TLS/SSL clients.
17When the session is set, the reference count of B<session> is incremented
18by 1. If the session is not reused, the reference count is decremented
19again during SSL_connect().
20
21If there is already a session set inside B<ssl> (because it was set with
22SSL_set_session() before or because the same B<ssl> was already used for
23a connection), SSL_SESSION_free() will be called for that session.
24
25=head1 RETURN VALUES
26
27The following return values can occur:
28
29=over 4
30
31=item 0
32
33The operation failed; check the error stack to find out the reason.
34
35=item 1
36
37The operation succeeded.
38
39=back
40
41=head1 SEE ALSO
42
43L<ssl(3)|ssl(3)>, L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>
44
45=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_shutdown.pod b/src/lib/libssl/src/doc/ssl/SSL_set_shutdown.pod
new file mode 100644
index 0000000000..6b196c1f15
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_shutdown.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5SSL_set_shutdown, SSL_get_shutdown - manipulate shutdown state of an SSL connection
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_set_shutdown(SSL *ssl, int mode);
12
13 int SSL_get_shutdown(SSL *ssl);
14
15=head1 DESCRIPTION
16
17SSL_set_shutdown() sets the shutdown state of B<ssl> to B<mode>.
18
19SSL_get_shutdown() returns the shutdown mode of B<ssl>.
20
21=head1 NOTES
22
23The shutdown state of an ssl connection is a bitmask of:
24
25=over 4
26
27=item 0
28
29No shutdown setting, yet.
30
31=item SSL_SENT_SHUTDOWN
32
33A "close notify" shutdown alert was sent to the peer, the connection is being
34considered closed and the session is closed and correct.
35
36=item SSL_RECEIVED_SHUTDOWN
37
38A shutdown alert was received form the peer, either a normal "close notify"
39or a fatal error.
40
41=back
42
43SSL_SENT_SHUTDOWN and SSL_RECEIVED_SHUTDOWN can be set at the same time.
44
45The shutdown state of the connection is used to determine the state of
46the ssl session. If the session is still open, when
47L<SSL_clear(3)|SSL_clear(3)> or L<SSL_free(3)|SSL_free(3)> is called,
48it is considered bad and removed according to RFC2246.
49The actual condition for a correctly closed session is SSL_SENT_SHUTDOWN.
50SSL_set_shutdown() can be used to set this state without sending a
51close alert to the peer (see L<SSL_shutdown(3)|SSL_shutdown(3)>).
52
53If a "close notify" was received, SSL_RECEIVED_SHUTDOWN will be set,
54for setting SSL_SENT_SHUTDOWN the application must however still call
55L<SSL_shutdown(3)|SSL_shutdown(3)> or SSL_set_shutdown() itself.
56
57=head1 RETURN VALUES
58
59SSL_set_shutdown() does not return diagnostic information.
60
61SSL_get_shutdown() returns the current setting.
62
63=head1 SEE ALSO
64
65L<ssl(3)|ssl(3)>, L<SSL_shutdown(3)|SSL_shutdown(3)>,
66L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
67
68=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_set_verify_result.pod b/src/lib/libssl/src/doc/ssl/SSL_set_verify_result.pod
new file mode 100644
index 0000000000..04ab101aad
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_set_verify_result.pod
@@ -0,0 +1,38 @@
1=pod
2
3=head1 NAME
4
5SSL_set_verify_result - override result of peer certificate verification
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 void SSL_set_verify_result(SSL *ssl, long verify_result);
12
13=head1 DESCRIPTION
14
15SSL_set_verify_result() sets B<verify_result> of the object B<ssl> to be the
16result of the verification of the X509 certificate presented by the peer,
17if any.
18
19=head1 NOTES
20
21SSL_set_verify_result() overrides the verification result. It only changes
22the verification result of the B<ssl> object. It does not become part of the
23established session, so if the session is to be reused later, the original
24value will reappear.
25
26The valid codes for B<verify_result> are documented in L<verify(1)|verify(1)>.
27
28=head1 RETURN VALUES
29
30SSL_set_verify_result() does not provide a return value.
31
32=head1 SEE ALSO
33
34L<ssl(3)|ssl(3)>, L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
35L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
36L<verify(1)|verify(1)>
37
38=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_shutdown.pod b/src/lib/libssl/src/doc/ssl/SSL_shutdown.pod
new file mode 100644
index 0000000000..20e273bd4d
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_shutdown.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5SSL_shutdown - shut down a TLS/SSL connection
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_shutdown(SSL *ssl);
12
13=head1 DESCRIPTION
14
15SSL_shutdown() shuts down an active TLS/SSL connection. It sends the shutdown
16alert to the peer. The behaviour of SSL_shutdown() depends on the underlying
17BIO.
18
19If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
20handshake has been finished or an error occurred.
21
22If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
23when the underlying BIO could not satisfy the needs of SSL_shutdown()
24to continue the handshake. In this case a call to SSL_get_error() with the
25return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
26B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
27taking appropriate action to satisfy the needs of SSL_shutdown().
28The action depends on the underlying BIO. When using a non-blocking socket,
29nothing is to be done, but select() can be used to check for the required
30condition. When using a buffering BIO, like a BIO pair, data must be written
31into or retrieved out of the BIO before being able to continue.
32
33=head1 RETURN VALUES
34
35The following return values can occur:
36
37=over 4
38
39=item 1
40
41The shutdown was successfully completed.
42
43=item 0
44
45The shutdown was not successful. Call SSL_get_error() with the return
46value B<ret> to find out the reason.
47
48=item -1
49
50The shutdown was not successful because a fatal error occurred either
51at the protocol level or a connection failure occurred. It can also occur of
52action is need to continue the operation for non-blocking BIOs.
53Call SSL_get_error() with the return value B<ret> to find out the reason.
54
55=back
56
57=head1 SEE ALSO
58
59L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
60L<SSL_accept(3)|SSL_accept(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
61
62=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_state_string.pod b/src/lib/libssl/src/doc/ssl/SSL_state_string.pod
new file mode 100644
index 0000000000..b4be1aaa48
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_state_string.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5SSL_state_string, SSL_state_string_long - get textual description of state of an SSL object
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 const char *SSL_state_string(SSL *ssl);
12 const char *SSL_state_string_long(SSL *ssl);
13
14=head1 DESCRIPTION
15
16SSL_state_string() returns a 6 letter string indicating the current state
17of the SSL object B<ssl>.
18
19SSL_state_string_long() returns a string indicating the current state of
20the SSL object B<ssl>.
21
22=head1 NOTES
23
24During its use, an SSL objects passes several states. The state is internally
25maintained. Querying the state information is not very informative before
26or when a connection has been established. It however can be of significant
27interest during the handshake.
28
29When using non-blocking sockets, the function call performing the handshake
30may return with SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE condition,
31so that SSL_state_string[_long]() may be called.
32
33For both blocking or non-blocking sockets, the details state information
34can be used within the info_callback function set with the
35SSL_set_info_callback() call.
36
37=head1 RETURN VALUES
38
39Detailed description of possible states to be included later.
40
41=head1 SEE ALSO
42
43L<ssl(3)|ssl(3)>, L<SSL_CTX_set_info_callback(3)|SSL_CTX_set_info_callback(3)>
44
45=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_want.pod b/src/lib/libssl/src/doc/ssl/SSL_want.pod
new file mode 100644
index 0000000000..50cc89db80
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_want.pod
@@ -0,0 +1,77 @@
1=pod
2
3=head1 NAME
4
5SSL_want, SSL_want_nothing, SSL_want_read, SSL_want_write, SSL_want_x509_lookup - obtain state information TLS/SSL I/O operation
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_want(SSL *ssl);
12 int SSL_want_nothing(SSL *ssl);
13 int SSL_want_read(SSL *ssl);
14 int SSL_want_write(SSL *ssl);
15 int SSL_want_x509_lookup(SSL *ssl);
16
17=head1 DESCRIPTION
18
19SSL_want() returns state information for the SSL object B<ssl>.
20
21The other SSL_want_*() calls are shortcuts for the possible states returned
22by SSL_want().
23
24=head1 NOTES
25
26SSL_want() examines the internal state information of the SSL object. Its
27return values are similar to that of L<SSL_get_error(3)|SSL_get_error(3)>.
28Unlike L<SSL_get_error(3)|SSL_get_error(3)>, which also evaluates the
29error queue, the results are obtained by examining an internal state flag
30only. The information must therefore only be used for normal operation under
31non-blocking I/O. Error conditions are not handled and must be treated
32using L<SSL_get_error(3)|SSL_get_error(3)>.
33
34The result returned by SSL_want() should always be consistent with
35the result of L<SSL_get_error(3)|SSL_get_error(3)>.
36
37=head1 RETURN VALUES
38
39The following return values can currently occur for SSL_want():
40
41=over 4
42
43=item SSL_NOTHING
44
45There is no data to be written or to be read.
46
47=item SSL_WRITING
48
49There are data in the SSL buffer that must be written to the underlying
50B<BIO> layer in order to complete the actual SSL_*() operation.
51A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
52SSL_ERROR_WANT_WRITE.
53
54=item SSL_READING
55
56More data must be read from the underlying B<BIO> layer in order to
57complete the actual SSL_*() operation.
58A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
59SSL_ERROR_WANT_READ.
60
61=item SSL_X509_LOOKUP
62
63The operation did not complete because an application callback set by
64SSL_CTX_set_client_cert_cb() has asked to be called again.
65A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
66SSL_ERROR_WANT_X509_LOOKUP.
67
68=back
69
70SSL_want_nothing(), SSL_want_read(), SSL_want_write(), SSL_want_x509_lookup()
71return 1, when the corresponding condition is true or 0 otherwise.
72
73=head1 SEE ALSO
74
75L<ssl(3)|ssl(3)>, L<err(3)|err(3)>, L<SSL_get_error(3)|SSL_get_error(3)>
76
77=cut
diff --git a/src/lib/libssl/src/doc/ssl/SSL_write.pod b/src/lib/libssl/src/doc/ssl/SSL_write.pod
new file mode 100644
index 0000000000..db67c187e0
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/SSL_write.pod
@@ -0,0 +1,76 @@
1=pod
2
3=head1 NAME
4
5SSL_read - write bytes to a TLS/SSL connection.
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_write(SSL *ssl, char *buf, int num);
12
13=head1 DESCRIPTION
14
15SSL_write() writes B<num> bytes from the buffer B<buf> into the specified
16B<ssl> connection.
17
18=head1 NOTES
19
20If necessary, SSL_write() will negotiate a TLS/SSL session, if
21not already explicitly performed by SSL_connect() or SSL_accept(). If the
22peer requests a re-negotiation, it will be performed transparently during
23the SSL_write() operation. The behaviour of SSL_write() depends on the
24underlying BIO.
25
26If the underlying BIO is B<blocking>, SSL_write() will only return, once the
27write operation has been finished or an error occurred.
28
29If the underlying BIO is B<non-blocking>, SSL_write() will also return,
30when the underlying BIO could not satisfy the needs of SSL_write()
31to continue the operation. In this case a call to SSL_get_error() with the
32return value of SSL_write() will yield B<SSL_ERROR_WANT_READ> or
33B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
34call to SSL_write() can also cause write operations! The calling process
35then must repeat the call after taking appropriate action to satisfy the
36needs of SSL_write(). The action depends on the underlying BIO. When using a
37non-blocking socket, nothing is to be done, but select() can be used to check
38for the required condition. When using a buffering BIO, like a BIO pair, data
39must be written into or retrieved out of the BIO before being able to continue.
40
41=head1 WARNING
42
43When an SSL_write() operation has to be repeated because of
44B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
45with the same arguments.
46
47=head1 RETURN VALUES
48
49The following return values can occur:
50
51=over 4
52
53=item E<gt>0
54
55The write operation was successful, the return value is the number of
56bytes actually written to the TLS/SSL connection.
57
58=item 0
59
60The write operation was not successful. Call SSL_get_error() with the return
61value B<ret> to find out, whether an error occurred.
62
63=item -1
64
65The read operation was not successful, because either an error occurred
66or action must be taken by the calling process. Call SSL_get_error() with the
67return value B<ret> to find out the reason.
68
69=back
70
71=head1 SEE ALSO
72
73L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_read(3)|SSL_read(3)>,
74L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
75
76=cut
diff --git a/src/lib/libssl/src/doc/ssl/d2i_SSL_SESSION.pod b/src/lib/libssl/src/doc/ssl/d2i_SSL_SESSION.pod
new file mode 100644
index 0000000000..9a1ba6c47b
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/d2i_SSL_SESSION.pod
@@ -0,0 +1,56 @@
1=pod
2
3=head1 NAME
4
5d2i_SSL_SESSION, i2d_SSL_SESSION - convert SSL_SESSION object from/to ASN1 representation
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, long length);
12 int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16d2i_SSL_SESSION() transforms the external ASN1 representation of an SSL/TLS
17session, stored as binary data at location B<pp> with length B<length>, into
18an SSL_SESSION object.
19
20i2d_SSL_SESSION() transforms the SSL_SESSION object B<in> into the ASN1
21representation and stores it into the memory location pointed to by B<pp>.
22The length of the resulting ASN1 representation is returned. If B<pp> is
23the NULL pointer, only the length is calculated and returned.
24
25=head1 NOTES
26
27The SSL_SESSION object is built from several malloc()ed parts, it can
28therefore not be moved, copied or stored directly. In order to store
29session data on disk or into a database, it must be transformed into
30a binary ASN1 representation.
31
32When using d2i_SSL_SESSION(), the SSL_SESSION object is automatically
33allocated.
34
35When using i2d_SSL_SESSION(), the memory location pointed to by B<pp> must be
36large enough to hold the binary representation of the session. There is no
37known limit on the size of the created ASN1 representation, so the necessary
38amount of space should be obtained by first calling i2d_SSL_SESSION() with
39B<pp=NULL>, and obtain the size needed, then allocate the memory and
40call i2d_SSL_SESSION() again.
41
42=head1 RETURN VALUES
43
44d2i_SSL_SESSION() returns a pointer to the newly allocated SSL_SESSION
45object. In case of failure the NULL-pointer is returned and the error message
46can be retrieved from the error stack.
47
48i2d_SSL_SESSION() returns the size of the ASN1 representation in bytes.
49When the session is not valid, B<0> is returned and no operation is performed.
50
51=head1 SEE ALSO
52
53L<ssl(3)|ssl(3)>,
54L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>
55
56=cut
diff --git a/src/lib/libssl/src/doc/ssl/ssl.pod b/src/lib/libssl/src/doc/ssl/ssl.pod
new file mode 100644
index 0000000000..e53876654a
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssl/ssl.pod
@@ -0,0 +1,634 @@
1
2=pod
3
4=head1 NAME
5
6SSL - OpenSSL SSL/TLS library
7
8=head1 SYNOPSIS
9
10=head1 DESCRIPTION
11
12The OpenSSL B<ssl> library implements the Secure Sockets Layer (SSL v2/v3) and
13Transport Layer Security (TLS v1) protocols. It provides a rich API which is
14documented here.
15
16=head1 HEADER FILES
17
18Currently the OpenSSL B<ssl> library provides the following C header files
19containing the prototypes for the data structures and and functions:
20
21=over 4
22
23=item B<ssl.h>
24
25That's the common header file for the SSL/TLS API. Include it into your
26program to make the API of the B<ssl> library available. It internally
27includes both more private SSL headers and headers from the B<crypto> library.
28Whenever you need hard-core details on the internals of the SSL API, look
29inside this header file.
30
31=item B<ssl2.h>
32
33That's the sub header file dealing with the SSLv2 protocol only.
34I<Usually you don't have to include it explicitly because
35it's already included by ssl.h>.
36
37=item B<ssl3.h>
38
39That's the sub header file dealing with the SSLv3 protocol only.
40I<Usually you don't have to include it explicitly because
41it's already included by ssl.h>.
42
43=item B<ssl23.h>
44
45That's the sub header file dealing with the combined use of the SSLv2 and
46SSLv3 protocols.
47I<Usually you don't have to include it explicitly because
48it's already included by ssl.h>.
49
50=item B<tls1.h>
51
52That's the sub header file dealing with the TLSv1 protocol only.
53I<Usually you don't have to include it explicitly because
54it's already included by ssl.h>.
55
56=back
57
58=head1 DATA STRUCTURES
59
60Currently the OpenSSL B<ssl> library functions deals with the following data
61structures:
62
63=over 4
64
65=item B<SSL_METHOD> (SSL Method)
66
67That's a dispatch structure describing the internal B<ssl> library
68methods/functions which implement the various protocol versions (SSLv1, SSLv2
69and TLSv1). It's needed to create an B<SSL_CTX>.
70
71=item B<SSL_CIPHER> (SSL Cipher)
72
73This structure holds the algorithm information for a particular cipher which
74are a core part of the SSL/TLS protocol. The available ciphers are configured
75on a B<SSL_CTX> basis and the actually used ones are then part of the
76B<SSL_SESSION>.
77
78=item B<SSL_CTX> (SSL Context)
79
80That's the global context structure which is created by a server or client
81once per program life-time and which holds mainly default values for the
82B<SSL> structures which are later created for the connections.
83
84=item B<SSL_SESSION> (SSL Session)
85
86This is a structure containing the current SSL session details for a
87connection: B<SSL_CIPHER>s, client and server certificates, keys, etc.
88
89=item B<SSL> (SSL Connection)
90
91That's the main SSL/TLS structure which is created by a server or client per
92established connection. This actually is the core structure in the SSL API.
93Under run-time the application usually deals with this structure which has
94links to mostly all other structures.
95
96=back
97
98=head1 API FUNCTIONS
99
100Currently the OpenSSL B<ssl> library exports 214 API functions.
101They are documented in the following:
102
103=head2 DEALING WITH PROTOCOL METHODS
104
105Here we document the various API functions which deal with the SSL/TLS
106protocol methods defined in B<SSL_METHOD> structures.
107
108=over 4
109
110=item SSL_METHOD *B<SSLv2_client_method>(void);
111
112Constructor for the SSLv2 SSL_METHOD structure for a dedicated client.
113
114=item SSL_METHOD *B<SSLv2_server_method>(void);
115
116Constructor for the SSLv2 SSL_METHOD structure for a dedicated server.
117
118=item SSL_METHOD *B<SSLv2_method>(void);
119
120Constructor for the SSLv2 SSL_METHOD structure for combined client and server.
121
122=item SSL_METHOD *B<SSLv3_client_method>(void);
123
124Constructor for the SSLv3 SSL_METHOD structure for a dedicated client.
125
126=item SSL_METHOD *B<SSLv3_server_method>(void);
127
128Constructor for the SSLv3 SSL_METHOD structure for a dedicated server.
129
130=item SSL_METHOD *B<SSLv3_method>(void);
131
132Constructor for the SSLv3 SSL_METHOD structure for combined client and server.
133
134=item SSL_METHOD *B<TLSv1_client_method>(void);
135
136Constructor for the TLSv1 SSL_METHOD structure for a dedicated client.
137
138=item SSL_METHOD *B<TLSv1_server_method>(void);
139
140Constructor for the TLSv1 SSL_METHOD structure for a dedicated server.
141
142=item SSL_METHOD *B<TLSv1_method>(void);
143
144Constructor for the TLSv1 SSL_METHOD structure for combined client and server.
145
146=back
147
148=head2 DEALING WITH CIPHERS
149
150Here we document the various API functions which deal with the SSL/TLS
151ciphers defined in B<SSL_CIPHER> structures.
152
153=over 4
154
155=item char *B<SSL_CIPHER_description>(SSL_CIPHER *cipher, char *buf, int len);
156
157Write a string to I<buf> (with a maximum size of I<len>) containing a human
158readable description of I<cipher>. Returns I<buf>.
159
160=item int B<SSL_CIPHER_get_bits>(SSL_CIPHER *cipher, int *alg_bits);
161
162Determine the number of bits in I<cipher>. Because of export crippled ciphers
163there are two bits: The bits the algorithm supports in general (stored to
164I<alg_bits>) and the bits which are actually used (the return value).
165
166=item char *B<SSL_CIPHER_get_name>(SSL_CIPHER *cipher);
167
168Return the internal name of I<cipher> as a string. These are the various
169strings defined by the I<SSL2_TXT_xxx>, I<SSL3_TXT_xxx> and I<TLS1_TXT_xxx>
170definitions in the header files.
171
172=item char *B<SSL_CIPHER_get_version>(SSL_CIPHER *cipher);
173
174Returns a string like "C<TLSv1/SSLv3>" or "C<SSLv2>" which indicates the
175SSL/TLS protocol version to which I<cipher> belongs (i.e. where it was defined
176in the specification the first time).
177
178=back
179
180=head2 DEALING WITH PROTOCOL CONTEXTS
181
182Here we document the various API functions which deal with the SSL/TLS
183protocol context defined in the B<SSL_CTX> structure.
184
185=over 4
186
187=item int B<SSL_CTX_add_client_CA>(SSL_CTX *ctx, X509 *x);
188
189=item long B<SSL_CTX_add_extra_chain_cert>(SSL_CTX *ctx, X509 *x509);
190
191=item int B<SSL_CTX_add_session>(SSL_CTX *ctx, SSL_SESSION *c);
192
193=item int B<SSL_CTX_check_private_key>(SSL_CTX *ctx);
194
195=item long B<SSL_CTX_ctrl>(SSL_CTX *ctx, int cmd, long larg, char *parg);
196
197=item void B<SSL_CTX_flush_sessions>(SSL_CTX *s, long t);
198
199=item void B<SSL_CTX_free>(SSL_CTX *a);
200
201=item char *B<SSL_CTX_get_app_data>(SSL_CTX *ctx);
202
203=item X509_STORE *B<SSL_CTX_get_cert_store>(SSL_CTX *ctx);
204
205=item STACK *B<SSL_CTX_get_client_CA_list>(SSL_CTX *ctx);
206
207=item int (*B<SSL_CTX_get_client_cert_cb>(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
208
209=item char *B<SSL_CTX_get_ex_data>(SSL_CTX *s, int idx);
210
211=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))
212
213=item void (*B<SSL_CTX_get_info_callback>(SSL_CTX *ctx))(SSL *ssl, int cb, int ret);
214
215=item int B<SSL_CTX_get_quiet_shutdown>(SSL_CTX *ctx);
216
217=item int B<SSL_CTX_get_session_cache_mode>(SSL_CTX *ctx);
218
219=item long B<SSL_CTX_get_timeout>(SSL_CTX *ctx);
220
221=item int (*B<SSL_CTX_get_verify_callback>(SSL_CTX *ctx))(int ok, X509_STORE_CTX *ctx);
222
223=item int B<SSL_CTX_get_verify_mode>(SSL_CTX *ctx);
224
225=item int B<SSL_CTX_load_verify_locations>(SSL_CTX *ctx, char *CAfile, char *CApath);
226
227=item long B<SSL_CTX_need_tmp_RSA>(SSL_CTX *ctx);
228
229=item SSL_CTX *B<SSL_CTX_new>(SSL_METHOD *meth);
230
231=item int B<SSL_CTX_remove_session>(SSL_CTX *ctx, SSL_SESSION *c);
232
233=item int B<SSL_CTX_sess_accept>(SSL_CTX *ctx);
234
235=item int B<SSL_CTX_sess_accept_good>(SSL_CTX *ctx);
236
237=item int B<SSL_CTX_sess_accept_renegotiate>(SSL_CTX *ctx);
238
239=item int B<SSL_CTX_sess_cache_full>(SSL_CTX *ctx);
240
241=item int B<SSL_CTX_sess_cb_hits>(SSL_CTX *ctx);
242
243=item int B<SSL_CTX_sess_connect>(SSL_CTX *ctx);
244
245=item int B<SSL_CTX_sess_connect_good>(SSL_CTX *ctx);
246
247=item int B<SSL_CTX_sess_connect_renegotiate>(SSL_CTX *ctx);
248
249=item int B<SSL_CTX_sess_get_cache_size>(SSL_CTX *ctx);
250
251=item SSL_SESSION *(*B<SSL_CTX_sess_get_get_cb>(SSL_CTX *ctx))(SSL *ssl, unsigned char *data, int len, int *copy);
252
253=item int (*B<SSL_CTX_sess_get_new_cb>(SSL_CTX *ctx)(SSL *ssl, SSL_SESSION *sess);
254
255=item void (*B<SSL_CTX_sess_get_remove_cb>(SSL_CTX *ctx)(SSL_CTX *ctx, SSL_SESSION *sess);
256
257=item int B<SSL_CTX_sess_hits>(SSL_CTX *ctx);
258
259=item int B<SSL_CTX_sess_misses>(SSL_CTX *ctx);
260
261=item int B<SSL_CTX_sess_number>(SSL_CTX *ctx);
262
263=item void B<SSL_CTX_sess_set_cache_size>(SSL_CTX *ctx,t);
264
265=item void B<SSL_CTX_sess_set_get_cb>(SSL_CTX *ctx, SSL_SESSION *(*cb)(SSL *ssl, unsigned char *data, int len, int *copy));
266
267=item void B<SSL_CTX_sess_set_new_cb>(SSL_CTX *ctx, int (*cb)(SSL *ssl, SSL_SESSION *sess));
268
269=item void B<SSL_CTX_sess_set_remove_cb>(SSL_CTX *ctx, void (*cb)(SSL_CTX *ctx, SSL_SESSION *sess));
270
271=item int B<SSL_CTX_sess_timeouts>(SSL_CTX *ctx);
272
273=item LHASH *B<SSL_CTX_sessions>(SSL_CTX *ctx);
274
275=item void B<SSL_CTX_set_app_data>(SSL_CTX *ctx, void *arg);
276
277=item void B<SSL_CTX_set_cert_store>(SSL_CTX *ctx, X509_STORE *cs);
278
279=item void B<SSL_CTX_set_cert_verify_cb>(SSL_CTX *ctx, int (*cb)(SSL_CTX *), char *arg)
280
281=item int B<SSL_CTX_set_cipher_list>(SSL_CTX *ctx, char *str);
282
283=item void B<SSL_CTX_set_client_CA_list>(SSL_CTX *ctx, STACK *list);
284
285=item void B<SSL_CTX_set_client_cert_cb>(SSL_CTX *ctx, int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
286
287=item void B<SSL_CTX_set_default_passwd_cb>(SSL_CTX *ctx, int (*cb);(void))
288
289=item void B<SSL_CTX_set_default_read_ahead>(SSL_CTX *ctx, int m);
290
291=item int B<SSL_CTX_set_default_verify_paths>(SSL_CTX *ctx);
292
293=item int B<SSL_CTX_set_ex_data>(SSL_CTX *s, int idx, char *arg);
294
295=item void B<SSL_CTX_set_info_callback>(SSL_CTX *ctx, void (*cb)(SSL *ssl, int cb, int ret));
296
297=item void B<SSL_CTX_set_options>(SSL_CTX *ctx, unsigned long op);
298
299=item void B<SSL_CTX_set_quiet_shutdown>(SSL_CTX *ctx, int mode);
300
301=item void B<SSL_CTX_set_session_cache_mode>(SSL_CTX *ctx, int mode);
302
303=item int B<SSL_CTX_set_ssl_version>(SSL_CTX *ctx, SSL_METHOD *meth);
304
305=item void B<SSL_CTX_set_timeout>(SSL_CTX *ctx, long t);
306
307=item long B<SSL_CTX_set_tmp_dh>(SSL_CTX* ctx, DH *dh);
308
309=item long B<SSL_CTX_set_tmp_dh_callback>(SSL_CTX *ctx, DH *(*cb)(void));
310
311=item long B<SSL_CTX_set_tmp_rsa>(SSL_CTX *ctx, RSA *rsa);
312
313=item SSL_CTX_set_tmp_rsa_callback
314
315C<long B<SSL_CTX_set_tmp_rsa_callback>(SSL_CTX *B<ctx>, RSA *(*B<cb>)(SSL *B<ssl>, int B<export>, int B<keylength>));>
316
317Sets the callback which will be called when a temporary private key is
318required. The B<C<export>> flag will be set if the reason for needing
319a temp key is that an export ciphersuite is in use, in which case,
320B<C<keylength>> will contain the required keylength in bits. Generate a key of
321appropriate size (using ???) and return it.
322
323=item SSL_set_tmp_rsa_callback
324
325long B<SSL_set_tmp_rsa_callback>(SSL *ssl, RSA *(*cb)(SSL *ssl, int export, int keylength));
326
327The same as L<"SSL_CTX_set_tmp_rsa_callback">, except it operates on an SSL
328session instead of a context.
329
330=item void B<SSL_CTX_set_verify>(SSL_CTX *ctx, int mode, int (*cb);(void))
331
332=item int B<SSL_CTX_use_PrivateKey>(SSL_CTX *ctx, EVP_PKEY *pkey);
333
334=item int B<SSL_CTX_use_PrivateKey_ASN1>(int type, SSL_CTX *ctx, unsigned char *d, long len);
335
336=item int B<SSL_CTX_use_PrivateKey_file>(SSL_CTX *ctx, char *file, int type);
337
338=item int B<SSL_CTX_use_RSAPrivateKey>(SSL_CTX *ctx, RSA *rsa);
339
340=item int B<SSL_CTX_use_RSAPrivateKey_ASN1>(SSL_CTX *ctx, unsigned char *d, long len);
341
342=item int B<SSL_CTX_use_RSAPrivateKey_file>(SSL_CTX *ctx, char *file, int type);
343
344=item int B<SSL_CTX_use_certificate>(SSL_CTX *ctx, X509 *x);
345
346=item int B<SSL_CTX_use_certificate_ASN1>(SSL_CTX *ctx, int len, unsigned char *d);
347
348=item int B<SSL_CTX_use_certificate_file>(SSL_CTX *ctx, char *file, int type);
349
350=back
351
352=head2 DEALING WITH SESSIONS
353
354Here we document the various API functions which deal with the SSL/TLS
355sessions defined in the B<SSL_SESSION> structures.
356
357=over 4
358
359=item int B<SSL_SESSION_cmp>(SSL_SESSION *a, SSL_SESSION *b);
360
361=item void B<SSL_SESSION_free>(SSL_SESSION *ss);
362
363=item char *B<SSL_SESSION_get_app_data>(SSL_SESSION *s);
364
365=item char *B<SSL_SESSION_get_ex_data>(SSL_SESSION *s, int idx);
366
367=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))
368
369=item long B<SSL_SESSION_get_time>(SSL_SESSION *s);
370
371=item long B<SSL_SESSION_get_timeout>(SSL_SESSION *s);
372
373=item unsigned long B<SSL_SESSION_hash>(SSL_SESSION *a);
374
375=item SSL_SESSION *B<SSL_SESSION_new>(void);
376
377=item int B<SSL_SESSION_print>(BIO *bp, SSL_SESSION *x);
378
379=item int B<SSL_SESSION_print_fp>(FILE *fp, SSL_SESSION *x);
380
381=item void B<SSL_SESSION_set_app_data>(SSL_SESSION *s, char *a);
382
383=item int B<SSL_SESSION_set_ex_data>(SSL_SESSION *s, int idx, char *arg);
384
385=item long B<SSL_SESSION_set_time>(SSL_SESSION *s, long t);
386
387=item long B<SSL_SESSION_set_timeout>(SSL_SESSION *s, long t);
388
389=back
390
391=head2 DEALING WITH CONNECTIONS
392
393Here we document the various API functions which deal with the SSL/TLS
394connection defined in the B<SSL> structure.
395
396=over 4
397
398=item int B<SSL_accept>(SSL *ssl);
399
400=item int B<SSL_add_dir_cert_subjects_to_stack>(STACK *stack, const char *dir);
401
402=item int B<SSL_add_file_cert_subjects_to_stack>(STACK *stack, const char *file);
403
404=item int B<SSL_add_client_CA>(SSL *ssl, X509 *x);
405
406=item char *B<SSL_alert_desc_string>(int value);
407
408=item char *B<SSL_alert_desc_string_long>(int value);
409
410=item char *B<SSL_alert_type_string>(int value);
411
412=item char *B<SSL_alert_type_string_long>(int value);
413
414=item int B<SSL_check_private_key>(SSL *ssl);
415
416=item void B<SSL_clear>(SSL *ssl);
417
418=item long B<SSL_clear_num_renegotiations>(SSL *ssl);
419
420=item int B<SSL_connect>(SSL *ssl);
421
422=item void B<SSL_copy_session_id>(SSL *t, SSL *f);
423
424=item long B<SSL_ctrl>(SSL *ssl, int cmd, long larg, char *parg);
425
426=item int B<SSL_do_handshake>(SSL *ssl);
427
428=item SSL *B<SSL_dup>(SSL *ssl);
429
430=item STACK *B<SSL_dup_CA_list>(STACK *sk);
431
432=item void B<SSL_free>(SSL *ssl);
433
434=item SSL_CTX *B<SSL_get_SSL_CTX>(SSL *ssl);
435
436=item char *B<SSL_get_app_data>(SSL *ssl);
437
438=item X509 *B<SSL_get_certificate>(SSL *ssl);
439
440=item SSL_CIPHER *B<SSL_get_cipher>(SSL *ssl);
441
442=item int B<SSL_get_cipher_bits>(SSL *ssl, int *alg_bits);
443
444=item char *B<SSL_get_cipher_list>(SSL *ssl, int n);
445
446=item char *B<SSL_get_cipher_name>(SSL *ssl);
447
448=item char *B<SSL_get_cipher_version>(SSL *ssl);
449
450=item STACK *B<SSL_get_ciphers>(SSL *ssl);
451
452=item STACK *B<SSL_get_client_CA_list>(SSL *ssl);
453
454=item SSL_CIPHER *B<SSL_get_current_cipher>(SSL *ssl);
455
456=item long B<SSL_get_default_timeout>(SSL *ssl);
457
458=item int B<SSL_get_error>(SSL *ssl, int i);
459
460=item char *B<SSL_get_ex_data>(SSL *ssl, int idx);
461
462=item int B<SSL_get_ex_data_X509_STORE_CTX_idx>(void);
463
464=item int B<SSL_get_ex_new_index>(long argl, char *argp, int (*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
465
466=item int B<SSL_get_fd>(SSL *ssl);
467
468=item void (*B<SSL_get_info_callback>(SSL *ssl);)(void)
469
470=item STACK *B<SSL_get_peer_cert_chain>(SSL *ssl);
471
472=item X509 *B<SSL_get_peer_certificate>(SSL *ssl);
473
474=item EVP_PKEY *B<SSL_get_privatekey>(SSL *ssl);
475
476=item int B<SSL_get_quiet_shutdown>(SSL *ssl);
477
478=item BIO *B<SSL_get_rbio>(SSL *ssl);
479
480=item int B<SSL_get_read_ahead>(SSL *ssl);
481
482=item SSL_SESSION *B<SSL_get_session>(SSL *ssl);
483
484=item char *B<SSL_get_shared_ciphers>(SSL *ssl, char *buf, int len);
485
486=item int B<SSL_get_shutdown>(SSL *ssl);
487
488=item SSL_METHOD *B<SSL_get_ssl_method>(SSL *ssl);
489
490=item int B<SSL_get_state>(SSL *ssl);
491
492=item long B<SSL_get_time>(SSL *ssl);
493
494=item long B<SSL_get_timeout>(SSL *ssl);
495
496=item int (*B<SSL_get_verify_callback>(SSL *ssl);)(void)
497
498=item int B<SSL_get_verify_mode>(SSL *ssl);
499
500=item long B<SSL_get_verify_result>(SSL *ssl);
501
502=item char *B<SSL_get_version>(SSL *ssl);
503
504=item BIO *B<SSL_get_wbio>(SSL *ssl);
505
506=item int B<SSL_in_accept_init>(SSL *ssl);
507
508=item int B<SSL_in_before>(SSL *ssl);
509
510=item int B<SSL_in_connect_init>(SSL *ssl);
511
512=item int B<SSL_in_init>(SSL *ssl);
513
514=item int B<SSL_is_init_finished>(SSL *ssl);
515
516=item STACK *B<SSL_load_client_CA_file>(char *file);
517
518=item void B<SSL_load_error_strings>(void);
519
520=item SSL *B<SSL_new>(SSL_CTX *ctx);
521
522=item long B<SSL_num_renegotiations>(SSL *ssl);
523
524=item int B<SSL_peek>(SSL *ssl, char *buf, int num);
525
526=item int B<SSL_pending>(SSL *ssl);
527
528=item int B<SSL_read>(SSL *ssl, char *buf, int num);
529
530=item int B<SSL_renegotiate>(SSL *ssl);
531
532=item char *B<SSL_rstate_string>(SSL *ssl);
533
534=item char *B<SSL_rstate_string_long>(SSL *ssl);
535
536=item long B<SSL_session_reused>(SSL *ssl);
537
538=item void B<SSL_set_accept_state>(SSL *ssl);
539
540=item void B<SSL_set_app_data>(SSL *ssl, char *arg);
541
542=item void B<SSL_set_bio>(SSL *ssl, BIO *rbio, BIO *wbio);
543
544=item int B<SSL_set_cipher_list>(SSL *ssl, char *str);
545
546=item void B<SSL_set_client_CA_list>(SSL *ssl, STACK *list);
547
548=item void B<SSL_set_connect_state>(SSL *ssl);
549
550=item int B<SSL_set_ex_data>(SSL *ssl, int idx, char *arg);
551
552=item int B<SSL_set_fd>(SSL *ssl, int fd);
553
554=item void B<SSL_set_info_callback>(SSL *ssl, void (*cb);(void))
555
556=item void B<SSL_set_options>(SSL *ssl, unsigned long op);
557
558=item void B<SSL_set_quiet_shutdown>(SSL *ssl, int mode);
559
560=item void B<SSL_set_read_ahead>(SSL *ssl, int yes);
561
562=item int B<SSL_set_rfd>(SSL *ssl, int fd);
563
564=item int B<SSL_set_session>(SSL *ssl, SSL_SESSION *session);
565
566=item void B<SSL_set_shutdown>(SSL *ssl, int mode);
567
568=item int B<SSL_set_ssl_method>(SSL *ssl, SSL_METHOD *meth);
569
570=item void B<SSL_set_time>(SSL *ssl, long t);
571
572=item void B<SSL_set_timeout>(SSL *ssl, long t);
573
574=item void B<SSL_set_verify>(SSL *ssl, int mode, int (*callback);(void))
575
576=item void B<SSL_set_verify_result>(SSL *ssl, long arg);
577
578=item int B<SSL_set_wfd>(SSL *ssl, int fd);
579
580=item int B<SSL_shutdown>(SSL *ssl);
581
582=item int B<SSL_state>(SSL *ssl);
583
584=item char *B<SSL_state_string>(SSL *ssl);
585
586=item char *B<SSL_state_string_long>(SSL *ssl);
587
588=item long B<SSL_total_renegotiations>(SSL *ssl);
589
590=item int B<SSL_use_PrivateKey>(SSL *ssl, EVP_PKEY *pkey);
591
592=item int B<SSL_use_PrivateKey_ASN1>(int type, SSL *ssl, unsigned char *d, long len);
593
594=item int B<SSL_use_PrivateKey_file>(SSL *ssl, char *file, int type);
595
596=item int B<SSL_use_RSAPrivateKey>(SSL *ssl, RSA *rsa);
597
598=item int B<SSL_use_RSAPrivateKey_ASN1>(SSL *ssl, unsigned char *d, long len);
599
600=item int B<SSL_use_RSAPrivateKey_file>(SSL *ssl, char *file, int type);
601
602=item int B<SSL_use_certificate>(SSL *ssl, X509 *x);
603
604=item int B<SSL_use_certificate_ASN1>(SSL *ssl, int len, unsigned char *d);
605
606=item int B<SSL_use_certificate_file>(SSL *ssl, char *file, int type);
607
608=item int B<SSL_version>(SSL *ssl);
609
610=item int B<SSL_want>(SSL *ssl);
611
612=item int B<SSL_want_nothing>(SSL *ssl);
613
614=item int B<SSL_want_read>(SSL *ssl);
615
616=item int B<SSL_want_write>(SSL *ssl);
617
618=item int B<SSL_want_x509_lookup>(s);
619
620=item int B<SSL_write>(SSL *ssl, char *buf, int num);
621
622=back
623
624=head1 SEE ALSO
625
626L<openssl(1)|openssl(1)>, L<crypto(3)|crypto(3)>,
627L<SSL_get_error(3)|SSL_get_error(3)>
628
629=head1 HISTORY
630
631The L<ssl(3)|ssl(3)> document appeared in OpenSSL 0.9.2
632
633=cut
634
diff --git a/src/lib/libssl/src/doc/ssleay.txt b/src/lib/libssl/src/doc/ssleay.txt
new file mode 100644
index 0000000000..094e28ce48
--- /dev/null
+++ b/src/lib/libssl/src/doc/ssleay.txt
@@ -0,0 +1,7014 @@
1
2Bundle of old SSLeay documentation files [OBSOLETE!]
3
4==== readme ========================================================
5
6This is the old 0.6.6 docuementation. Most of the cipher stuff is still
7relevent but I'm working (very slowly) on new docuemtation.
8The current version can be found online at
9
10http://www.cryptsoft.com/ssleay/doc
11
12==== API.doc ========================================================
13
14SSL - SSLv2/v3/v23 etc.
15
16BIO - methods and how they plug together
17
18MEM - memory allocation callback
19
20CRYPTO - locking for threads
21
22EVP - Ciphers/Digests/signatures
23
24RSA - methods
25
26X509 - certificate retrieval
27
28X509 - validation
29
30X509 - X509v3 extensions
31
32Objects - adding object identifiers
33
34ASN.1 - parsing
35
36PEM - parsing
37
38==== ssl/readme =====================================================
39
4022 Jun 1996
41This file belongs in ../apps, but I'll leave it here because it deals
42with SSL :-) It is rather dated but it gives you an idea of how
43things work.
44===
45
4617 Jul 1995
47I have been changing things quite a bit and have not fully updated
48this file, so take what you read with a grain of salt
49eric
50===
51The s_client and s_server programs can be used to test SSL capable
52IP/port addresses and the verification of the X509 certificates in use
53by these services. I strongly advise having a look at the code to get
54an idea of how to use the authentication under SSLeay. Any feedback
55on changes and improvements would be greatly accepted.
56
57This file will probably be gibberish unless you have read
58rfc1421, rfc1422, rfc1423 and rfc1424 which describe PEM
59authentication.
60
61A Brief outline (and examples) how to use them to do so.
62
63NOTE:
64The environment variable SSL_CIPER is used to specify the prefered
65cipher to use, play around with setting it's value to combinations of
66RC4-MD5, EXP-RC4-MD5, CBC-DES-MD5, CBC3-DES-MD5, CFB-DES-NULL
67in a : separated list.
68
69This directory contains 3 X509 certificates which can be used by these programs.
70client.pem: a file containing a certificate and private key to be used
71 by s_client.
72server.pem :a file containing a certificate and private key to be used
73 by s_server.
74eay1024.pem:the certificate used to sign client.pem and server.pem.
75 This would be your CA's certificate. There is also a link
76 from the file a8556381.0 to eay1024.PEM. The value a8556381
77 is returned by 'x509 -hash -noout <eay1024.pem' and is the
78 value used by X509 verification routines to 'find' this
79 certificte when search a directory for it.
80 [the above is not true any more, the CA cert is
81 ../certs/testca.pem which is signed by ../certs/mincomca.pem]
82
83When testing the s_server, you may get
84bind: Address already in use
85errors. These indicate the port is still being held by the unix
86kernel and you are going to have to wait for it to let go of it. If
87this is the case, remember to use the port commands on the s_server and
88s_client to talk on an alternative port.
89
90=====
91s_client.
92This program can be used to connect to any IP/hostname:port that is
93talking SSL. Once connected, it will attempt to authenticate the
94certificate it was passed and if everything works as expected, a 2
95directional channel will be open. Any text typed will be sent to the
96other end. type Q<cr> to exit. Flags are as follows.
97-host arg : Arg is the host or IP address to connect to.
98-port arg : Arg is the port to connect to (https is 443).
99-verify arg : Turn on authentication of the server certificate.
100 : Arg specifies the 'depth', this will covered below.
101-cert arg : The optional certificate to use. This certificate
102 : will be returned to the server if the server
103 : requests it for client authentication.
104-key arg : The private key that matches the certificate
105 : specified by the -cert option. If this is not
106 : specified (but -cert is), the -cert file will be
107 : searched for the Private key. Both files are
108 : assumed to be in PEM format.
109-CApath arg : When to look for certificates when 'verifying' the
110 : certificate from the server.
111-CAfile arg : A file containing certificates to be used for
112 : 'verifying' the server certificate.
113-reconnect : Once a connection has been made, drop it and
114 : reconnect with same session-id. This is for testing :-).
115
116The '-verify n' parameter specifies not only to verify the servers
117certificate but to also only take notice of 'n' levels. The best way
118to explain is to show via examples.
119Given
120s_server -cert server.PEM is running.
121
122s_client
123 CONNECTED
124 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
125 issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
126 verify error:num=1:unable to get issuer certificate
127 verify return:1
128 CIPHER is CBC-DES-MD5
129What has happened is that the 'SSLeay demo server' certificate's
130issuer ('CA') could not be found but because verify is not on, we
131don't care and the connection has been made anyway. It is now 'up'
132using CBC-DES-MD5 mode. This is an unauthenticate secure channel.
133You may not be talking to the right person but the data going to them
134is encrypted.
135
136s_client -verify 0
137 CONNECTED
138 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
139 issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
140 verify error:num=1:unable to get issuer certificate
141 verify return:1
142 CIPHER is CBC-DES-MD5
143We are 'verifying' but only to depth 0, so since the 'SSLeay demo server'
144certificate passed the date and checksum, we are happy to proceed.
145
146s_client -verify 1
147 CONNECTED
148 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
149 issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
150 verify error:num=1:unable to get issuer certificate
151 verify return:0
152 ERROR
153 verify error:unable to get issuer certificate
154In this case we failed to make the connection because we could not
155authenticate the certificate because we could not find the
156'CA' certificate.
157
158s_client -verify 1 -CAfile eay1024.PEM
159 CONNECTED
160 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
161 verify return:1
162 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
163 verify return:1
164 CIPHER is CBC-DES-MD5
165We loaded the certificates from the file eay1024.PEM. Everything
166checked out and so we made the connection.
167
168s_client -verify 1 -CApath .
169 CONNECTED
170 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
171 verify return:1
172 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
173 verify return:1
174 CIPHER is CBC-DES-MD5
175We looked in out local directory for issuer certificates and 'found'
176a8556381.0 and so everything is ok.
177
178It is worth noting that 'CA' is a self certified certificate. If you
179are passed one of these, it will fail to 'verify' at depth 0 because
180we need to lookup the certifier of a certificate from some information
181that we trust and keep locally.
182
183SSL_CIPHER=CBC3-DES-MD5:RC4-MD5
184export SSL_CIPHER
185s_client -verify 10 -CApath . -reconnect
186 CONNECTED
187 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
188 verify return:1
189 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
190 verify return:1
191 drop the connection and reconnect with the same session id
192 CIPHER is CBC3-DES-MD5
193This has done a full connection and then re-estabished it with the
194same session id but a new socket. No RSA stuff occures on the second
195connection. Note that we said we would prefer to use CBC3-DES-MD5
196encryption and so, since the server supports it, we are.
197
198=====
199s_server
200This program accepts SSL connections on a specified port
201Once connected, it will estabish an SSL connection and optionaly
202attempt to authenticate the client. A 2 directional channel will be
203open. Any text typed will be sent to the other end. Type Q<cr> to exit.
204Flags are as follows.
205-port arg : Arg is the port to listen on.
206-verify arg : Turn on authentication of the client if they have a
207 : certificate. Arg specifies the 'depth'.
208-Verify arg : Turn on authentication of the client. If they don't
209 : have a valid certificate, drop the connection.
210-cert arg : The certificate to use. This certificate
211 : will be passed to the client. If it is not
212 : specified, it will default to server.PEM
213-key arg : The private key that matches the certificate
214 : specified by the -cert option. If this is not
215 : specified (but -cert is), the -cert file will be
216 : searched for the Private key. Both files are
217 : assumed to be in PEM format. Default is server.PEM
218-CApath arg : When to look for certificates when 'verifying' the
219 : certificate from the client.
220-CAfile arg : A file containing certificates to be used for
221 : 'verifying' the client certificate.
222
223For the following 'demo' I will specify the s_server command and
224the s_client command and then list the output from the s_server.
225s_server
226s_client
227 CONNECTED
228 CIPHER is CBC-DES-MD5
229Everything up and running
230
231s_server -verify 0
232s_client
233 CONNECTED
234 CIPHER is CBC-DES-MD5
235Ok since no certificate was returned and we don't care.
236
237s_server -verify 0
238./s_client -cert client.PEM
239 CONNECTED
240 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
241 issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
242 verify error:num=1:unable to get issuer certificate
243 verify return:1
244 CIPHER is CBC-DES-MD5
245Ok since we were only verifying to level 0
246
247s_server -verify 4
248s_client -cert client.PEM
249 CONNECTED
250 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
251 issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
252 verify error:num=1:unable to get issuer certificate
253 verify return:0
254 ERROR
255 verify error:unable to get issuer certificate
256Bad because we could not authenticate the returned certificate.
257
258s_server -verify 4 -CApath .
259s_client -cert client.PEM
260 CONNECTED
261 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
262 verify return:1
263 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
264 verify return:1
265 CIPHER is CBC-DES-MD5
266Ok because we could authenticate the returned certificate :-).
267
268s_server -Verify 0 -CApath .
269s_client
270 CONNECTED
271 ERROR
272 SSL error:function is:REQUEST_CERTIFICATE
273 :error is :client end did not return a certificate
274Error because no certificate returned.
275
276s_server -Verify 4 -CApath .
277s_client -cert client.PEM
278 CONNECTED
279 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
280 verify return:1
281 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
282 verify return:1
283 CIPHER is CBC-DES-MD5
284Full authentication of the client.
285
286So in summary to do full authentication of both ends
287s_server -Verify 9 -CApath .
288s_client -cert client.PEM -CApath . -verify 9
289From the server side
290 CONNECTED
291 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
292 verify return:1
293 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
294 verify return:1
295 CIPHER is CBC-DES-MD5
296From the client side
297 CONNECTED
298 depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
299 verify return:1
300 depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
301 verify return:1
302 CIPHER is CBC-DES-MD5
303
304For general probing of the 'internet https' servers for the
305distribution area, run
306s_client -host www.netscape.com -port 443 -verify 4 -CApath ../rsa/hash
307Then enter
308GET /
309and you should be talking to the https server on that host.
310
311www.rsa.com was refusing to respond to connections on 443 when I was
312testing.
313
314have fun :-).
315
316eric
317
318==== a_verify.doc ========================================================
319
320From eay@mincom.com Fri Oct 4 18:29:06 1996
321Received: by orb.mincom.oz.au id AA29080
322 (5.65c/IDA-1.4.4 for eay); Fri, 4 Oct 1996 08:29:07 +1000
323Date: Fri, 4 Oct 1996 08:29:06 +1000 (EST)
324From: Eric Young <eay@mincom.oz.au>
325X-Sender: eay@orb
326To: wplatzer <wplatzer@iaik.tu-graz.ac.at>
327Cc: Eric Young <eay@mincom.oz.au>, SSL Mailing List <ssl-users@mincom.com>
328Subject: Re: Netscape's Public Key
329In-Reply-To: <19961003134837.NTM0049@iaik.tu-graz.ac.at>
330Message-Id: <Pine.SOL.3.91.961004081346.8018K-100000@orb>
331Mime-Version: 1.0
332Content-Type: TEXT/PLAIN; charset=US-ASCII
333Status: RO
334X-Status:
335
336On Thu, 3 Oct 1996, wplatzer wrote:
337> I get Public Key from Netscape (Gold 3.0b4), but cannot do anything
338> with it... It looks like (asn1parse):
339>
340> 0:d=0 hl=3 l=180 cons: SEQUENCE
341> 3:d=1 hl=2 l= 96 cons: SEQUENCE
342> 5:d=2 hl=2 l= 92 cons: SEQUENCE
343> 7:d=3 hl=2 l= 13 cons: SEQUENCE
344> 9:d=4 hl=2 l= 9 prim: OBJECT :rsaEncryption
345> 20:d=4 hl=2 l= 0 prim: NULL
346> 22:d=3 hl=2 l= 75 prim: BIT STRING
347> 99:d=2 hl=2 l= 0 prim: IA5STRING :
348> 101:d=1 hl=2 l= 13 cons: SEQUENCE
349> 103:d=2 hl=2 l= 9 prim: OBJECT :md5withRSAEncryption
350> 114:d=2 hl=2 l= 0 prim: NULL
351> 116:d=1 hl=2 l= 65 prim: BIT STRING
352>
353> The first BIT STRING is the public key and the second BIT STRING is
354> the signature.
355> But a public key consists of the public exponent and the modulus. Are
356> both numbers in the first BIT STRING?
357> Is there a document simply describing this coding stuff (checking
358> signature, get the public key, etc.)?
359
360Minimal in SSLeay. If you want to see what the modulus and exponent are,
361try asn1parse -offset 25 -length 75 <key.pem
362asn1parse will currently stuff up on the 'length 75' part (fixed in next
363release) but it will print the stuff. If you are after more
364documentation on ASN.1, have a look at www.rsa.com and get their PKCS
365documents, most of my initial work on SSLeay was done using them.
366
367As for SSLeay,
368util/crypto.num and util/ssl.num are lists of all exported functions in
369the library (but not macros :-(.
370
371The ones for extracting public keys from certificates and certificate
372requests are EVP_PKEY * X509_REQ_extract_key(X509_REQ *req);
373EVP_PKEY * X509_extract_key(X509 *x509);
374
375To verify a signature on a signed ASN.1 object
376int X509_verify(X509 *a,EVP_PKEY *key);
377int X509_REQ_verify(X509_REQ *a,EVP_PKEY *key);
378int X509_CRL_verify(X509_CRL *a,EVP_PKEY *key);
379int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a,EVP_PKEY *key);
380
381I should mention that EVP_PKEY can be used to hold a public or a private key,
382since for things like RSA and DSS, a public key is just a subset of what
383is stored for the private key.
384
385To sign any of the above structures
386
387int X509_sign(X509 *a,EVP_PKEY *key,EVP_MD *md);
388int X509_REQ_sign(X509_REQ *a,EVP_PKEY *key,EVP_MD *md);
389int X509_CRL_sign(X509_CRL *a,EVP_PKEY *key,EVP_MD *md);
390int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *a,EVP_PKEY *key,EVP_MD *md);
391
392where md is the message digest to sign with.
393
394There are all defined in x509.h and all the _sign and _verify functions are
395actually macros to the ASN1_sign() and ASN1_verify() functions.
396These functions will put the correct algorithm identifiers in the correct
397places in the structures.
398
399eric
400--
401Eric Young | BOOL is tri-state according to Bill Gates.
402AARNet: eay@mincom.oz.au | RTFM Win32 GetMessage().
403
404==== x509 =======================================================
405
406X509_verify()
407X509_sign()
408
409X509_get_version()
410X509_get_serialNumber()
411X509_get_issuer()
412X509_get_subject()
413X509_get_notBefore()
414X509_get_notAfter()
415X509_get_pubkey()
416
417X509_set_version()
418X509_set_serialNumber()
419X509_set_issuer()
420X509_set_subject()
421X509_set_notBefore()
422X509_set_notAfter()
423X509_set_pubkey()
424
425X509_get_extensions()
426X509_set_extensions()
427
428X509_EXTENSIONS_clear()
429X509_EXTENSIONS_retrieve()
430X509_EXTENSIONS_add()
431X509_EXTENSIONS_delete()
432
433==== x509 attribute ================================================
434
435PKCS7
436 STACK of X509_ATTRIBUTES
437 ASN1_OBJECT
438 STACK of ASN1_TYPE
439
440So it is
441
442p7.xa[].obj
443p7.xa[].data[]
444
445get_obj_by_nid(STACK , nid)
446get_num_by_nid(STACK , nid)
447get_data_by_nid(STACK , nid, index)
448
449X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
450void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
451
452X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **ex,
453 int nid, STACK *value);
454
455X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **ex,
456 int nid, STACK *value);
457
458int X509_ATTRIBUTE_set_object(X509_ATTRIBUTE *ex,ASN1_OBJECT *obj);
459int X509_ATTRIBUTE_add_data(X509_ATTRIBUTE *ex, int index,
460 ASN1_TYPE *value);
461
462ASN1_OBJECT * X509_ATTRIBUTE_get_object(X509_ATTRIBUTE *ex);
463int X509_ATTRIBUTE_get_num(X509_ATTRIBUTE *ne);
464ASN1_TYPE * X509_ATTRIBUTE_get_data(X509_ATTRIBUTE *ne,int index);
465
466ASN1_TYPE * X509_ATTRIBUTE_get_data_by_NID(X509_ATTRIBUTE *ne,
467 ASN1_OBJECT *obj);
468
469X509_ATTRIBUTE *PKCS7_get_s_att_by_NID(PKCS7 *p7,int nid);
470X509_ATTRIBUTE *PKCS7_get_u_att_by_NID(PKCS7 *p7,int nid);
471
472==== x509 v3 ========================================================
473
474The 'new' system.
475
476The X509_EXTENSION_METHOD includes extensions and attributes and/or names.
477Basically everthing that can be added to an X509 with an OID identifying it.
478
479It operates via 2 methods per object id.
480int a2i_XXX(X509 *x,char *str,int len);
481int i2a_XXX(BIO *bp,X509 *x);
482
483The a2i_XXX function will add the object with a value converted from the
484string into the X509. Len can be -1 in which case the length is calculated
485via strlen(str). Applications can always use direct knowledge to load and
486unload the relevent objects themselves.
487
488i2a_XXX will print to the passed BIO, a text representation of the
489relevet object. Use a memory BIO if you want it printed to a buffer :-).
490
491X509_add_by_NID(X509 *x,int nid,char *str,int len);
492X509_add_by_OBJ(X509 *x,ASN1_OBJECT *obj,char *str,int len);
493
494X509_print_by_name(BIO *bp,X509 *x);
495X509_print_by_NID(BIO *bp,X509 *x);
496X509_print_by_OBJ(BIO *bp,X509 *x);
497
498==== verify ========================================================
499
500X509_verify_cert_chain(
501 CERT_STORE *cert_store,
502 STACK /* X509 */ *certs,
503 int *verify_result,
504 int (*verify_error_callback)()
505 char *argument_to_callback, /* SSL */
506
507app_verify_callback(
508 char *app_verify_arg, /* from SSL_CTX */
509 STACK /* X509 */ *certs,
510 int *verify_result,
511 int (*verify_error_callback)()
512 SSL *s,
513
514int X509_verify_cert(
515 CERT_STORE *cert_store,
516 X509 *x509,
517 int *verify_result,
518 int (*verify_error_callback)(),
519 char *arg,
520
521==== apps.doc ========================================================
522
523The applications
524
525Ok, where to begin....
526In the begining, when SSLeay was small (April 1995), there
527were but few applications, they did happily cohabit in
528the one bin directory. Then over time, they did multiply and grow,
529and they started to look like microsoft software; 500k to print 'hello world'.
530A new approach was needed. They were coalessed into one 'Monolithic'
531application, ssleay. This one program is composed of many programs that
532can all be compiled independantly.
533
534ssleay has 3 modes of operation.
5351) If the ssleay binaray has the name of one of its component programs, it
536executes that program and then exits. This can be achieve by using hard or
537symbolic links, or failing that, just renaming the binary.
5382) If the first argument to ssleay is the name of one of the component
539programs, that program runs that program and then exits.
5403) If there are no arguments, ssleay enters a 'command' mode. Each line is
541interpreted as a program name plus arguments. After each 'program' is run,
542ssleay returns to the comand line.
543
544dgst - message digests
545enc - encryption and base64 encoding
546
547ans1parse - 'pulls' appart ASN.1 encoded objects like certificates.
548
549dh - Diffle-Hellman parameter manipulation.
550rsa - RSA manipulations.
551crl - Certificate revokion list manipulations
552x509 - X509 cert fiddles, including signing.
553pkcs7 - pkcs7 manipulation, only DER versions right now.
554
555genrsa - generate an RSA private key.
556gendh - Generate a set of Diffle-Hellman parameters.
557req - Generate a PKCS#10 object, a certificate request.
558
559s_client - SSL client program
560s_server - SSL server program
561s_time - A SSL protocol timing program
562s_mult - Another SSL server, but it multiplexes
563 connections.
564s_filter - under development
565
566errstr - Convert SSLeay error numbers to strings.
567ca - Sign certificate requests, and generate
568 certificate revokion lists
569crl2pkcs7 - put a crl and certifcates into a pkcs7 object.
570speed - Benchmark the ciphers.
571verify - Check certificates
572hashdir - under development
573
574[ there a now a few more options, play with the program to see what they
575 are ]
576
577==== asn1.doc ========================================================
578
579The ASN.1 Routines.
580
581ASN.1 is a specification for how to encode structured 'data' in binary form.
582The approach I have take to the manipulation of structures and their encoding
583into ASN.1 is as follows.
584
585For each distinct structure there are 4 function of the following form
586TYPE *TYPE_new(void);
587void TYPE_free(TYPE *);
588TYPE *d2i_TYPE(TYPE **a,unsigned char **pp,long length);
589long i2d_TYPE(TYPE *a,unsigned char **pp); /* CHECK RETURN VALUE */
590
591where TYPE is the type of the 'object'. The TYPE that have these functions
592can be in one of 2 forms, either the internal C malloc()ed data structure
593or in the DER (a variant of ASN.1 encoding) binary encoding which is just
594an array of unsigned bytes. The 'i2d' functions converts from the internal
595form to the DER form and the 'd2i' functions convert from the DER form to
596the internal form.
597
598The 'new' function returns a malloc()ed version of the structure with all
599substructures either created or left as NULL pointers. For 'optional'
600fields, they are normally left as NULL to indicate no value. For variable
601size sub structures (often 'SET OF' or 'SEQUENCE OF' in ASN.1 syntax) the
602STACK data type is used to hold the values. Have a read of stack.doc
603and have a look at the relevant header files to see what I mean. If there
604is an error while malloc()ing the structure, NULL is returned.
605
606The 'free' function will free() all the sub components of a particular
607structure. If any of those sub components have been 'removed', replace
608them with NULL pointers, the 'free' functions are tolerant of NULL fields.
609
610The 'd2i' function copies a binary representation into a C structure. It
611operates as follows. 'a' is a pointer to a pointer to
612the structure to populate, 'pp' is a pointer to a pointer to where the DER
613byte string is located and 'length' is the length of the '*pp' data.
614If there are no errors, a pointer to the populated structure is returned.
615If there is an error, NULL is returned. Errors can occur because of
616malloc() failures but normally they will be due to syntax errors in the DER
617encoded data being parsed. It is also an error if there was an
618attempt to read more that 'length' bytes from '*p'. If
619everything works correctly, the value in '*p' is updated
620to point at the location just beyond where the DER
621structure was read from. In this way, chained calls to 'd2i' type
622functions can be made, with the pointer into the 'data' array being
623'walked' along the input byte array.
624Depending on the value passed for 'a', different things will be done. If
625'a' is NULL, a new structure will be malloc()ed and returned. If '*a' is
626NULL, a new structure will be malloc()ed and put into '*a' and returned.
627If '*a' is not NULL, the structure in '*a' will be populated, or in the
628case of an error, free()ed and then returned.
629Having these semantics means that a structure
630can call a 'd2i' function to populate a field and if the field is currently
631NULL, the structure will be created.
632
633The 'i2d' function type is used to copy a C structure to a byte array.
634The parameter 'a' is the structure to convert and '*p' is where to put it.
635As for the 'd2i' type structure, 'p' is updated to point after the last
636byte written. If p is NULL, no data is written. The function also returns
637the number of bytes written. Where this becomes useful is that if the
638function is called with a NULL 'p' value, the length is returned. This can
639then be used to malloc() an array of bytes and then the same function can
640be recalled passing the malloced array to be written to. e.g.
641
642int len;
643unsigned char *bytes,*p;
644len=i2d_X509(x,NULL); /* get the size of the ASN1 encoding of 'x' */
645if ((bytes=(unsigned char *)malloc(len)) == NULL)
646 goto err;
647p=bytes;
648i2d_X509(x,&p);
649
650Please note that a new variable, 'p' was passed to i2d_X509. After the
651call to i2d_X509 p has been incremented by len bytes.
652
653Now the reason for this functional organisation is that it allows nested
654structures to be built up by calling these functions as required. There
655are various macros used to help write the general 'i2d', 'd2i', 'new' and
656'free' functions. They are discussed in another file and would only be
657used by some-one wanting to add new structures to the library. As you
658might be able to guess, the process of writing ASN.1 files can be a bit CPU
659expensive for complex structures. I'm willing to live with this since the
660simpler library code make my life easier and hopefully most programs using
661these routines will have their execution profiles dominated by cipher or
662message digest routines.
663What follows is a list of 'TYPE' values and the corresponding ASN.1
664structure and where it is used.
665
666TYPE ASN.1
667ASN1_INTEGER INTEGER
668ASN1_BIT_STRING BIT STRING
669ASN1_OCTET_STRING OCTET STRING
670ASN1_OBJECT OBJECT IDENTIFIER
671ASN1_PRINTABLESTRING PrintableString
672ASN1_T61STRING T61String
673ASN1_IA5STRING IA5String
674ASN1_UTCTIME UTCTime
675ASN1_TYPE Any of the above mentioned types plus SEQUENCE and SET
676
677Most of the above mentioned types are actualled stored in the
678ASN1_BIT_STRING type and macros are used to differentiate between them.
679The 3 types used are
680
681typedef struct asn1_object_st
682 {
683 /* both null if a dynamic ASN1_OBJECT, one is
684 * defined if a 'static' ASN1_OBJECT */
685 char *sn,*ln;
686 int nid;
687 int length;
688 unsigned char *data;
689 } ASN1_OBJECT;
690This is used to store ASN1 OBJECTS. Read 'objects.doc' for details ono
691routines to manipulate this structure. 'sn' and 'ln' are used to hold text
692strings that represent the object (short name and long or lower case name).
693These are used by the 'OBJ' library. 'nid' is a number used by the OBJ
694library to uniquely identify objects. The ASN1 routines will populate the
695'length' and 'data' fields which will contain the bit string representing
696the object.
697
698typedef struct asn1_bit_string_st
699 {
700 int length;
701 int type;
702 unsigned char *data;
703 } ASN1_BIT_STRING;
704This structure is used to hold all the other base ASN1 types except for
705ASN1_UTCTIME (which is really just a 'char *'). Length is the number of
706bytes held in data and type is the ASN1 type of the object (there is a list
707in asn1.h).
708
709typedef struct asn1_type_st
710 {
711 int type;
712 union {
713 char *ptr;
714 ASN1_INTEGER * integer;
715 ASN1_BIT_STRING * bit_string;
716 ASN1_OCTET_STRING * octet_string;
717 ASN1_OBJECT * object;
718 ASN1_PRINTABLESTRING * printablestring;
719 ASN1_T61STRING * t61string;
720 ASN1_IA5STRING * ia5string;
721 ASN1_UTCTIME * utctime;
722 ASN1_BIT_STRING * set;
723 ASN1_BIT_STRING * sequence;
724 } value;
725 } ASN1_TYPE;
726This structure is used in a few places when 'any' type of object can be
727expected.
728
729X509 Certificate
730X509_CINF CertificateInfo
731X509_ALGOR AlgorithmIdentifier
732X509_NAME Name
733X509_NAME_ENTRY A single sub component of the name.
734X509_VAL Validity
735X509_PUBKEY SubjectPublicKeyInfo
736The above mentioned types are declared in x509.h. They are all quite
737straight forward except for the X509_NAME/X509_NAME_ENTRY pair.
738A X509_NAME is a STACK (see stack.doc) of X509_NAME_ENTRY's.
739typedef struct X509_name_entry_st
740 {
741 ASN1_OBJECT *object;
742 ASN1_BIT_STRING *value;
743 int set;
744 int size; /* temp variable */
745 } X509_NAME_ENTRY;
746The size is a temporary variable used by i2d_NAME and set is the set number
747for the particular NAME_ENTRY. A X509_NAME is encoded as a sequence of
748sequence of sets. Normally each set contains only a single item.
749Sometimes it contains more. Normally throughout this library there will be
750only one item per set. The set field contains the 'set' that this entry is
751a member of. So if you have just created a X509_NAME structure and
752populated it with X509_NAME_ENTRYs, you should then traverse the X509_NAME
753(which is just a STACK) and set the 'set/' field to incrementing numbers.
754For more details on why this is done, read the ASN.1 spec for Distinguished
755Names.
756
757X509_REQ CertificateRequest
758X509_REQ_INFO CertificateRequestInfo
759These are used to hold certificate requests.
760
761X509_CRL CertificateRevocationList
762These are used to hold a certificate revocation list
763
764RSAPrivateKey PrivateKeyInfo
765RSAPublicKey PublicKeyInfo
766Both these 'function groups' operate on 'RSA' structures (see rsa.doc).
767The difference is that the RSAPublicKey operations only manipulate the m
768and e fields in the RSA structure.
769
770DSAPrivateKey DSS private key
771DSAPublicKey DSS public key
772Both these 'function groups' operate on 'DSS' structures (see dsa.doc).
773The difference is that the RSAPublicKey operations only manipulate the
774XXX fields in the DSA structure.
775
776DHparams DHParameter
777This is used to hold the p and g value for The Diffie-Hellman operation.
778The function deal with the 'DH' strucure (see dh.doc).
779
780Now all of these function types can be used with several other functions to give
781quite useful set of general manipulation routines. Normally one would
782not uses these functions directly but use them via macros.
783
784char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
785'x' is the input structure case to a 'char *', 'i2d' is the 'i2d_TYPE'
786function for the type that 'x' is and d2i is the 'd2i_TYPE' function for the
787type that 'x' is. As is obvious from the parameters, this function
788duplicates the strucutre by transforming it into the DER form and then
789re-loading it into a new strucutre and returning the new strucutre. This
790is obviously a bit cpu intensive but when faced with a complex dynamic
791structure this is the simplest programming approach. There are macros for
792duplicating the major data types but is simple to add extras.
793
794char *ASN1_d2i_fp(char *(*new)(),char *(*d2i)(),FILE *fp,unsigned char **x);
795'x' is a pointer to a pointer of the 'desired type'. new and d2i are the
796corresponding 'TYPE_new' and 'd2i_TYPE' functions for the type and 'fp' is
797an open file pointer to read from. This function reads from 'fp' as much
798data as it can and then uses 'd2i' to parse the bytes to load and return
799the parsed strucutre in 'x' (if it was non-NULL) and to actually return the
800strucutre. The behavior of 'x' is as per all the other d2i functions.
801
802char *ASN1_d2i_bio(char *(*new)(),char *(*d2i)(),BIO *fp,unsigned char **x);
803The 'BIO' is the new IO type being used in SSLeay (see bio.doc). This
804function is the same as ASN1_d2i_fp() except for the BIO argument.
805ASN1_d2i_fp() actually calls this function.
806
807int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
808'x' is converted to bytes by 'i2d' and then written to 'out'. ASN1_i2d_fp
809and ASN1_d2i_fp are not really symetric since ASN1_i2d_fp will read all
810available data from the file pointer before parsing a single item while
811ASN1_i2d_fp can be used to write a sequence of data objects. To read a
812series of objects from a file I would sugest loading the file into a buffer
813and calling the relevent 'd2i' functions.
814
815char *ASN1_d2i_bio(char *(*new)(),char *(*d2i)(),BIO *fp,unsigned char **x);
816This function is the same as ASN1_i2d_fp() except for the BIO argument.
817ASN1_i2d_fp() actually calls this function.
818
819char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,int (*cb)());
820This function will read the next PEM encoded (base64) object of the same
821type as 'x' (loaded by the d2i function). 'name' is the name that is in
822the '-----BEGIN name-----' that designates the start of that object type.
823If the data is encrypted, 'cb' will be called to prompt for a password. If
824it is NULL a default function will be used to prompt from the password.
825'x' is delt with as per the standard 'd2i' function interface. This
826function can be used to read a series of objects from a file. While any
827data type can be encrypted (see PEM_ASN1_write) only RSA private keys tend
828to be encrypted.
829
830char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *fp,
831 char **x,int (*cb)());
832Same as PEM_ASN1_read() except using a BIO. This is called by
833PEM_ASN1_read().
834
835int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,EVP_CIPHER *enc,
836 unsigned char *kstr,int klen,int (*callback)());
837
838int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *fp,
839 char *x,EVP_CIPHER *enc,unsigned char *kstr,int klen,
840 int (*callback)());
841
842int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
843 ASN1_BIT_STRING *signature, char *data, RSA *rsa, EVP_MD *type);
844int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
845 ASN1_BIT_STRING *signature,char *data, RSA *rsa);
846
847int ASN1_BIT_STRING_cmp(ASN1_BIT_STRING *a, ASN1_BIT_STRING *b);
848ASN1_BIT_STRING *ASN1_BIT_STRING_type_new(int type );
849
850int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
851void ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
852ASN1_UTCTIME *ASN1_UTCTIME_dup(ASN1_UTCTIME *a);
853
854ASN1_BIT_STRING *d2i_asn1_print_type(ASN1_BIT_STRING **a,unsigned char **pp,
855 long length,int type);
856
857int i2d_ASN1_SET(STACK *a, unsigned char **pp,
858 int (*func)(), int ex_tag, int ex_class);
859STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
860 char *(*func)(), int ex_tag, int ex_class);
861
862int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *object);
863int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
864int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
865
866int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
867long ASN1_INTEGER_get(ASN1_INTEGER *a);
868ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
869BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
870
871/* given a string, return the correct type. Max is the maximum number
872 * of bytes to parse. It stops parsing when 'max' bytes have been
873 * processed or a '\0' is hit */
874int ASN1_PRINTABLE_type(unsigned char *s,int max);
875
876void ASN1_parse(BIO *fp,unsigned char *pp,long len);
877
878int i2d_ASN1_bytes(ASN1_BIT_STRING *a, unsigned char **pp, int tag, int class);
879ASN1_BIT_STRING *d2i_ASN1_bytes(ASN1_OCTET_STRING **a, unsigned char **pp,
880 long length, int Ptag, int Pclass);
881
882/* PARSING */
883int asn1_Finish(ASN1_CTX *c);
884
885/* SPECIALS */
886int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
887 int *pclass, long omax);
888int ASN1_check_infinite_end(unsigned char **p,long len);
889void ASN1_put_object(unsigned char **pp, int constructed, int length,
890 int tag, int class);
891int ASN1_object_size(int constructed, int length, int tag);
892
893X509 * X509_get_cert(CERTIFICATE_CTX *ctx,X509_NAME * name,X509 *tmp_x509);
894int X509_add_cert(CERTIFICATE_CTX *ctx,X509 *);
895
896char * X509_cert_verify_error_string(int n);
897int X509_add_cert_file(CERTIFICATE_CTX *c,char *file, int type);
898char * X509_gmtime (char *s, long adj);
899int X509_add_cert_dir (CERTIFICATE_CTX *c,char *dir, int type);
900int X509_load_verify_locations (CERTIFICATE_CTX *ctx,
901 char *file_env, char *dir_env);
902int X509_set_default_verify_paths(CERTIFICATE_CTX *cts);
903X509 * X509_new_D2i_X509(int len, unsigned char *p);
904char * X509_get_default_cert_area(void );
905char * X509_get_default_cert_dir(void );
906char * X509_get_default_cert_file(void );
907char * X509_get_default_cert_dir_env(void );
908char * X509_get_default_cert_file_env(void );
909char * X509_get_default_private_dir(void );
910X509_REQ *X509_X509_TO_req(X509 *x, RSA *rsa);
911int X509_cert_verify(CERTIFICATE_CTX *ctx,X509 *xs, int (*cb)());
912
913CERTIFICATE_CTX *CERTIFICATE_CTX_new();
914void CERTIFICATE_CTX_free(CERTIFICATE_CTX *c);
915
916void X509_NAME_print(BIO *fp, X509_NAME *name, int obase);
917int X509_print_fp(FILE *fp,X509 *x);
918int X509_print(BIO *fp,X509 *x);
919
920X509_INFO * X509_INFO_new(void);
921void X509_INFO_free(X509_INFO *a);
922
923char * X509_NAME_oneline(X509_NAME *a);
924
925#define X509_verify(x,rsa)
926#define X509_REQ_verify(x,rsa)
927#define X509_CRL_verify(x,rsa)
928
929#define X509_sign(x,rsa,md)
930#define X509_REQ_sign(x,rsa,md)
931#define X509_CRL_sign(x,rsa,md)
932
933#define X509_dup(x509)
934#define d2i_X509_fp(fp,x509)
935#define i2d_X509_fp(fp,x509)
936#define d2i_X509_bio(bp,x509)
937#define i2d_X509_bio(bp,x509)
938
939#define X509_CRL_dup(crl)
940#define d2i_X509_CRL_fp(fp,crl)
941#define i2d_X509_CRL_fp(fp,crl)
942#define d2i_X509_CRL_bio(bp,crl)
943#define i2d_X509_CRL_bio(bp,crl)
944
945#define X509_REQ_dup(req)
946#define d2i_X509_REQ_fp(fp,req)
947#define i2d_X509_REQ_fp(fp,req)
948#define d2i_X509_REQ_bio(bp,req)
949#define i2d_X509_REQ_bio(bp,req)
950
951#define RSAPrivateKey_dup(rsa)
952#define d2i_RSAPrivateKey_fp(fp,rsa)
953#define i2d_RSAPrivateKey_fp(fp,rsa)
954#define d2i_RSAPrivateKey_bio(bp,rsa)
955#define i2d_RSAPrivateKey_bio(bp,rsa)
956
957#define X509_NAME_dup(xn)
958#define X509_NAME_ENTRY_dup(ne)
959
960void X509_REQ_print_fp(FILE *fp,X509_REQ *req);
961void X509_REQ_print(BIO *fp,X509_REQ *req);
962
963RSA *X509_REQ_extract_key(X509_REQ *req);
964RSA *X509_extract_key(X509 *x509);
965
966int X509_issuer_and_serial_cmp(X509 *a, X509 *b);
967unsigned long X509_issuer_and_serial_hash(X509 *a);
968
969X509_NAME * X509_get_issuer_name(X509 *a);
970int X509_issuer_name_cmp(X509 *a, X509 *b);
971unsigned long X509_issuer_name_hash(X509 *a);
972
973X509_NAME * X509_get_subject_name(X509 *a);
974int X509_subject_name_cmp(X509 *a,X509 *b);
975unsigned long X509_subject_name_hash(X509 *x);
976
977int X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
978unsigned long X509_NAME_hash(X509_NAME *x);
979
980
981==== bio.doc ========================================================
982
983BIO Routines
984
985This documentation is rather sparse, you are probably best
986off looking at the code for specific details.
987
988The BIO library is a IO abstraction that was originally
989inspired by the need to have callbacks to perform IO to FILE
990pointers when using Windows 3.1 DLLs. There are two types
991of BIO; a source/sink type and a filter type.
992The source/sink methods are as follows:
993- BIO_s_mem() memory buffer - a read/write byte array that
994 grows until memory runs out :-).
995- BIO_s_file() FILE pointer - A wrapper around the normal
996 'FILE *' commands, good for use with stdin/stdout.
997- BIO_s_fd() File descriptor - A wrapper around file
998 descriptors, often used with pipes.
999- BIO_s_socket() Socket - Used around sockets. It is
1000 mostly in the Microsoft world that sockets are different
1001 from file descriptors and there are all those ugly winsock
1002 commands.
1003- BIO_s_null() Null - read nothing and write nothing.; a
1004 useful endpoint for filter type BIO's specifically things
1005 like the message digest BIO.
1006
1007The filter types are
1008- BIO_f_buffer() IO buffering - does output buffering into
1009 larger chunks and performs input buffering to allow gets()
1010 type functions.
1011- BIO_f_md() Message digest - a transparent filter that can
1012 be asked to return a message digest for the data that has
1013 passed through it.
1014- BIO_f_cipher() Encrypt or decrypt all data passing
1015 through the filter.
1016- BIO_f_base64() Base64 decode on read and encode on write.
1017- BIO_f_ssl() A filter that performs SSL encryption on the
1018 data sent through it.
1019
1020Base BIO functions.
1021The BIO library has a set of base functions that are
1022implemented for each particular type. Filter BIOs will
1023normally call the equivalent function on the source/sink BIO
1024that they are layered on top of after they have performed
1025some modification to the data stream. Multiple filter BIOs
1026can be 'push' into a stack of modifers, so to read from a
1027file, unbase64 it, then decrypt it, a BIO_f_cipher,
1028BIO_f_base64 and a BIO_s_file would probably be used. If a
1029sha-1 and md5 message digest needed to be generated, a stack
1030two BIO_f_md() BIOs and a BIO_s_null() BIO could be used.
1031The base functions are
1032- BIO *BIO_new(BIO_METHOD *type); Create a new BIO of type 'type'.
1033- int BIO_free(BIO *a); Free a BIO structure. Depending on
1034 the configuration, this will free the underlying data
1035 object for a source/sink BIO.
1036- int BIO_read(BIO *b, char *data, int len); Read upto 'len'
1037 bytes into 'data'.
1038- int BIO_gets(BIO *bp,char *buf, int size); Depending on
1039 the BIO, this can either be a 'get special' or a get one
1040 line of data, as per fgets();
1041- int BIO_write(BIO *b, char *data, int len); Write 'len'
1042 bytes from 'data' to the 'b' BIO.
1043- int BIO_puts(BIO *bp,char *buf); Either a 'put special' or
1044 a write null terminated string as per fputs().
1045- long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg); A
1046 control function which is used to manipulate the BIO
1047 structure and modify it's state and or report on it. This
1048 function is just about never used directly, rather it
1049 should be used in conjunction with BIO_METHOD specific
1050 macros.
1051- BIO *BIO_push(BIO *new_top, BIO *old); new_top is apped to the
1052 top of the 'old' BIO list. new_top should be a filter BIO.
1053 All writes will go through 'new_top' first and last on read.
1054 'old' is returned.
1055- BIO *BIO_pop(BIO *bio); the new topmost BIO is returned, NULL if
1056 there are no more.
1057
1058If a particular low level BIO method is not supported
1059(normally BIO_gets()), -2 will be returned if that method is
1060called. Otherwise the IO methods (read, write, gets, puts)
1061will return the number of bytes read or written, and 0 or -1
1062for error (or end of input). For the -1 case,
1063BIO_should_retry(bio) can be called to determine if it was a
1064genuine error or a temporary problem. -2 will also be
1065returned if the BIO has not been initalised yet, in all
1066cases, the correct error codes are set (accessible via the
1067ERR library).
1068
1069
1070The following functions are convenience functions:
1071- int BIO_printf(BIO *bio, char * format, ..); printf but
1072 to a BIO handle.
1073- long BIO_ctrl_int(BIO *bp,int cmd,long larg,int iarg); a
1074 convenience function to allow a different argument types
1075 to be passed to BIO_ctrl().
1076- int BIO_dump(BIO *b,char *bytes,int len); output 'len'
1077 bytes from 'bytes' in a hex dump debug format.
1078- long BIO_debug_callback(BIO *bio, int cmd, char *argp, int
1079 argi, long argl, long ret) - a default debug BIO callback,
1080 this is mentioned below. To use this one normally has to
1081 use the BIO_set_callback_arg() function to assign an
1082 output BIO for the callback to use.
1083- BIO *BIO_find_type(BIO *bio,int type); when there is a 'stack'
1084 of BIOs, this function scan the list and returns the first
1085 that is of type 'type', as listed in buffer.h under BIO_TYPE_XXX.
1086- void BIO_free_all(BIO *bio); Free the bio and all other BIOs
1087 in the list. It walks the bio->next_bio list.
1088
1089
1090
1091Extra commands are normally implemented as macros calling BIO_ctrl().
1092- BIO_number_read(BIO *bio) - the number of bytes processed
1093 by BIO_read(bio,.).
1094- BIO_number_written(BIO *bio) - the number of bytes written
1095 by BIO_write(bio,.).
1096- BIO_reset(BIO *bio) - 'reset' the BIO.
1097- BIO_eof(BIO *bio) - non zero if we are at the current end
1098 of input.
1099- BIO_set_close(BIO *bio, int close_flag) - set the close flag.
1100- BIO_get_close(BIO *bio) - return the close flag.
1101 BIO_pending(BIO *bio) - return the number of bytes waiting
1102 to be read (normally buffered internally).
1103- BIO_flush(BIO *bio) - output any data waiting to be output.
1104- BIO_should_retry(BIO *io) - after a BIO_read/BIO_write
1105 operation returns 0 or -1, a call to this function will
1106 return non zero if you should retry the call later (this
1107 is for non-blocking IO).
1108- BIO_should_read(BIO *io) - we should retry when data can
1109 be read.
1110- BIO_should_write(BIO *io) - we should retry when data can
1111 be written.
1112- BIO_method_name(BIO *io) - return a string for the method name.
1113- BIO_method_type(BIO *io) - return the unique ID of the BIO method.
1114- BIO_set_callback(BIO *io, long (*callback)(BIO *io, int
1115 cmd, char *argp, int argi, long argl, long ret); - sets
1116 the debug callback.
1117- BIO_get_callback(BIO *io) - return the assigned function
1118 as mentioned above.
1119- BIO_set_callback_arg(BIO *io, char *arg) - assign some
1120 data against the BIO. This is normally used by the debug
1121 callback but could in reality be used for anything. To
1122 get an idea of how all this works, have a look at the code
1123 in the default debug callback mentioned above. The
1124 callback can modify the return values.
1125
1126Details of the BIO_METHOD structure.
1127typedef struct bio_method_st
1128 {
1129 int type;
1130 char *name;
1131 int (*bwrite)();
1132 int (*bread)();
1133 int (*bputs)();
1134 int (*bgets)();
1135 long (*ctrl)();
1136 int (*create)();
1137 int (*destroy)();
1138 } BIO_METHOD;
1139
1140The 'type' is the numeric type of the BIO, these are listed in buffer.h;
1141'Name' is a textual representation of the BIO 'type'.
1142The 7 function pointers point to the respective function
1143methods, some of which can be NULL if not implemented.
1144The BIO structure
1145typedef struct bio_st
1146 {
1147 BIO_METHOD *method;
1148 long (*callback)(BIO * bio, int mode, char *argp, int
1149 argi, long argl, long ret);
1150 char *cb_arg; /* first argument for the callback */
1151 int init;
1152 int shutdown;
1153 int flags; /* extra storage */
1154 int num;
1155 char *ptr;
1156 struct bio_st *next_bio; /* used by filter BIOs */
1157 int references;
1158 unsigned long num_read;
1159 unsigned long num_write;
1160 } BIO;
1161
1162- 'Method' is the BIO method.
1163- 'callback', when configured, is called before and after
1164 each BIO method is called for that particular BIO. This
1165 is intended primarily for debugging and of informational feedback.
1166- 'init' is 0 when the BIO can be used for operation.
1167 Often, after a BIO is created, a number of operations may
1168 need to be performed before it is available for use. An
1169 example is for BIO_s_sock(). A socket needs to be
1170 assigned to the BIO before it can be used.
1171- 'shutdown', this flag indicates if the underlying
1172 comunication primative being used should be closed/freed
1173 when the BIO is closed.
1174- 'flags' is used to hold extra state. It is primarily used
1175 to hold information about why a non-blocking operation
1176 failed and to record startup protocol information for the
1177 SSL BIO.
1178- 'num' and 'ptr' are used to hold instance specific state
1179 like file descriptors or local data structures.
1180- 'next_bio' is used by filter BIOs to hold the pointer of the
1181 next BIO in the chain. written data is sent to this BIO and
1182 data read is taken from it.
1183- 'references' is used to indicate the number of pointers to
1184 this structure. This needs to be '1' before a call to
1185 BIO_free() is made if the BIO_free() function is to
1186 actually free() the structure, otherwise the reference
1187 count is just decreased. The actual BIO subsystem does
1188 not really use this functionality but it is useful when
1189 used in more advanced applicaion.
1190- num_read and num_write are the total number of bytes
1191 read/written via the 'read()' and 'write()' methods.
1192
1193BIO_ctrl operations.
1194The following is the list of standard commands passed as the
1195second parameter to BIO_ctrl() and should be supported by
1196all BIO as best as possible. Some are optional, some are
1197manditory, in any case, where is makes sense, a filter BIO
1198should pass such requests to underlying BIO's.
1199- BIO_CTRL_RESET - Reset the BIO back to an initial state.
1200- BIO_CTRL_EOF - return 0 if we are not at the end of input,
1201 non 0 if we are.
1202- BIO_CTRL_INFO - BIO specific special command, normal
1203 information return.
1204- BIO_CTRL_SET - set IO specific parameter.
1205- BIO_CTRL_GET - get IO specific parameter.
1206- BIO_CTRL_GET_CLOSE - Get the close on BIO_free() flag, one
1207 of BIO_CLOSE or BIO_NOCLOSE.
1208- BIO_CTRL_SET_CLOSE - Set the close on BIO_free() flag.
1209- BIO_CTRL_PENDING - Return the number of bytes available
1210 for instant reading
1211- BIO_CTRL_FLUSH - Output pending data, return number of bytes output.
1212- BIO_CTRL_SHOULD_RETRY - After an IO error (-1 returned)
1213 should we 'retry' when IO is possible on the underlying IO object.
1214- BIO_CTRL_RETRY_TYPE - What kind of IO are we waiting on.
1215
1216The following command is a special BIO_s_file() specific option.
1217- BIO_CTRL_SET_FILENAME - specify a file to open for IO.
1218
1219The BIO_CTRL_RETRY_TYPE needs a little more explanation.
1220When performing non-blocking IO, or say reading on a memory
1221BIO, when no data is present (or cannot be written),
1222BIO_read() and/or BIO_write() will return -1.
1223BIO_should_retry(bio) will return true if this is due to an
1224IO condition rather than an actual error. In the case of
1225BIO_s_mem(), a read when there is no data will return -1 and
1226a should retry when there is more 'read' data.
1227The retry type is deduced from 2 macros
1228BIO_should_read(bio) and BIO_should_write(bio).
1229Now while it may appear obvious that a BIO_read() failure
1230should indicate that a retry should be performed when more
1231read data is available, this is often not true when using
1232things like an SSL BIO. During the SSL protocol startup
1233multiple reads and writes are performed, triggered by any
1234SSL_read or SSL_write.
1235So to write code that will transparently handle either a
1236socket or SSL BIO,
1237 i=BIO_read(bio,..)
1238 if (I == -1)
1239 {
1240 if (BIO_should_retry(bio))
1241 {
1242 if (BIO_should_read(bio))
1243 {
1244 /* call us again when BIO can be read */
1245 }
1246 if (BIO_should_write(bio))
1247 {
1248 /* call us again when BIO can be written */
1249 }
1250 }
1251 }
1252
1253At this point in time only read and write conditions can be
1254used but in the future I can see the situation for other
1255conditions, specifically with SSL there could be a condition
1256of a X509 certificate lookup taking place and so the non-
1257blocking BIO_read would require a retry when the certificate
1258lookup subsystem has finished it's lookup. This is all
1259makes more sense and is easy to use in a event loop type
1260setup.
1261When using the SSL BIO, either SSL_read() or SSL_write()s
1262can be called during the protocol startup and things will
1263still work correctly.
1264The nice aspect of the use of the BIO_should_retry() macro
1265is that all the errno codes that indicate a non-fatal error
1266are encapsulated in one place. The Windows specific error
1267codes and WSAGetLastError() calls are also hidden from the
1268application.
1269
1270Notes on each BIO method.
1271Normally buffer.h is just required but depending on the
1272BIO_METHOD, ssl.h or evp.h will also be required.
1273
1274BIO_METHOD *BIO_s_mem(void);
1275- BIO_set_mem_buf(BIO *bio, BUF_MEM *bm, int close_flag) -
1276 set the underlying BUF_MEM structure for the BIO to use.
1277- BIO_get_mem_ptr(BIO *bio, char **pp) - if pp is not NULL,
1278 set it to point to the memory array and return the number
1279 of bytes available.
1280A read/write BIO. Any data written is appended to the
1281memory array and any read is read from the front. This BIO
1282can be used for read/write at the same time. BIO_gets() is
1283supported in the fgets() sense.
1284BIO_CTRL_INFO can be used to retrieve pointers to the memory
1285buffer and it's length.
1286
1287BIO_METHOD *BIO_s_file(void);
1288- BIO_set_fp(BIO *bio, FILE *fp, int close_flag) - set 'FILE *' to use.
1289- BIO_get_fp(BIO *bio, FILE **fp) - get the 'FILE *' in use.
1290- BIO_read_filename(BIO *bio, char *name) - read from file.
1291- BIO_write_filename(BIO *bio, char *name) - write to file.
1292- BIO_append_filename(BIO *bio, char *name) - append to file.
1293This BIO sits over the normal system fread()/fgets() type
1294functions. Gets() is supported. This BIO in theory could be
1295used for read and write but it is best to think of each BIO
1296of this type as either a read or a write BIO, not both.
1297
1298BIO_METHOD *BIO_s_socket(void);
1299BIO_METHOD *BIO_s_fd(void);
1300- BIO_sock_should_retry(int i) - the underlying function
1301 used to determine if a call should be retried; the
1302 argument is the '0' or '-1' returned by the previous BIO
1303 operation.
1304- BIO_fd_should_retry(int i) - same as the
1305- BIO_sock_should_retry() except that it is different internally.
1306- BIO_set_fd(BIO *bio, int fd, int close_flag) - set the
1307 file descriptor to use
1308- BIO_get_fd(BIO *bio, int *fd) - get the file descriptor.
1309These two methods are very similar. Gets() is not
1310supported, if you want this functionality, put a
1311BIO_f_buffer() onto it. This BIO is bi-directional if the
1312underlying file descriptor is. This is normally the case
1313for sockets but not the case for stdio descriptors.
1314
1315BIO_METHOD *BIO_s_null(void);
1316Read and write as much data as you like, it all disappears
1317into this BIO.
1318
1319BIO_METHOD *BIO_f_buffer(void);
1320- BIO_get_buffer_num_lines(BIO *bio) - return the number of
1321 complete lines in the buffer.
1322- BIO_set_buffer_size(BIO *bio, long size) - set the size of
1323 the buffers.
1324This type performs input and output buffering. It performs
1325both at the same time. The size of the buffer can be set
1326via the set buffer size option. Data buffered for output is
1327only written when the buffer fills.
1328
1329BIO_METHOD *BIO_f_ssl(void);
1330- BIO_set_ssl(BIO *bio, SSL *ssl, int close_flag) - the SSL
1331 structure to use.
1332- BIO_get_ssl(BIO *bio, SSL **ssl) - get the SSL structure
1333 in use.
1334The SSL bio is a little different from normal BIOs because
1335the underlying SSL structure is a little different. A SSL
1336structure performs IO via a read and write BIO. These can
1337be different and are normally set via the
1338SSL_set_rbio()/SSL_set_wbio() calls. The SSL_set_fd() calls
1339are just wrappers that create socket BIOs and then call
1340SSL_set_bio() where the read and write BIOs are the same.
1341The BIO_push() operation makes the SSLs IO BIOs the same, so
1342make sure the BIO pushed is capable of two directional
1343traffic. If it is not, you will have to install the BIOs
1344via the more conventional SSL_set_bio() call. BIO_pop() will retrieve
1345the 'SSL read' BIO.
1346
1347BIO_METHOD *BIO_f_md(void);
1348- BIO_set_md(BIO *bio, EVP_MD *md) - set the message digest
1349 to use.
1350- BIO_get_md(BIO *bio, EVP_MD **mdp) - return the digest
1351 method in use in mdp, return 0 if not set yet.
1352- BIO_reset() reinitializes the digest (EVP_DigestInit())
1353 and passes the reset to the underlying BIOs.
1354All data read or written via BIO_read() or BIO_write() to
1355this BIO will be added to the calculated digest. This
1356implies that this BIO is only one directional. If read and
1357write operations are performed, two separate BIO_f_md() BIOs
1358are reuqired to generate digests on both the input and the
1359output. BIO_gets(BIO *bio, char *md, int size) will place the
1360generated digest into 'md' and return the number of bytes.
1361The EVP_MAX_MD_SIZE should probably be used to size the 'md'
1362array. Reading the digest will also reset it.
1363
1364BIO_METHOD *BIO_f_cipher(void);
1365- BIO_reset() reinitializes the cipher.
1366- BIO_flush() should be called when the last bytes have been
1367 output to flush the final block of block ciphers.
1368- BIO_get_cipher_status(BIO *b), when called after the last
1369 read from a cipher BIO, returns non-zero if the data
1370 decrypted correctly, otherwise, 0.
1371- BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *key,
1372 unsigned char *iv, int encrypt) This function is used to
1373 setup a cipher BIO. The length of key and iv are
1374 specified by the choice of EVP_CIPHER. Encrypt is 1 to
1375 encrypt and 0 to decrypt.
1376
1377BIO_METHOD *BIO_f_base64(void);
1378- BIO_flush() should be called when the last bytes have been output.
1379This BIO base64 encodes when writing and base64 decodes when
1380reading. It will scan the input until a suitable begin line
1381is found. After reading data, BIO_reset() will reset the
1382BIO to start scanning again. Do not mix reading and writing
1383on the same base64 BIO. It is meant as a single stream BIO.
1384
1385Directions type
1386both BIO_s_mem()
1387one/both BIO_s_file()
1388both BIO_s_fd()
1389both BIO_s_socket()
1390both BIO_s_null()
1391both BIO_f_buffer()
1392one BIO_f_md()
1393one BIO_f_cipher()
1394one BIO_f_base64()
1395both BIO_f_ssl()
1396
1397It is easy to mix one and two directional BIOs, all one has
1398to do is to keep two separate BIO pointers for reading and
1399writing and be careful about usage of underlying BIOs. The
1400SSL bio by it's very nature has to be two directional but
1401the BIO_push() command will push the one BIO into the SSL
1402BIO for both reading and writing.
1403
1404The best example program to look at is apps/enc.c and/or perhaps apps/dgst.c.
1405
1406
1407==== blowfish.doc ========================================================
1408
1409The Blowfish library.
1410
1411Blowfish is a block cipher that operates on 64bit (8 byte) quantities. It
1412uses variable size key, but 128bit (16 byte) key would normally be considered
1413good. It can be used in all the modes that DES can be used. This
1414library implements the ecb, cbc, cfb64, ofb64 modes.
1415
1416Blowfish is quite a bit faster that DES, and much faster than IDEA or
1417RC2. It is one of the faster block ciphers.
1418
1419For all calls that have an 'input' and 'output' variables, they can be the
1420same.
1421
1422This library requires the inclusion of 'blowfish.h'.
1423
1424All of the encryption functions take what is called an BF_KEY as an
1425argument. An BF_KEY is an expanded form of the Blowfish key.
1426For all modes of the Blowfish algorithm, the BF_KEY used for
1427decryption is the same one that was used for encryption.
1428
1429The define BF_ENCRYPT is passed to specify encryption for the functions
1430that require an encryption/decryption flag. BF_DECRYPT is passed to
1431specify decryption.
1432
1433Please note that any of the encryption modes specified in my DES library
1434could be used with Blowfish. I have only implemented ecb, cbc, cfb64 and
1435ofb64 for the following reasons.
1436- ecb is the basic Blowfish encryption.
1437- cbc is the normal 'chaining' form for block ciphers.
1438- cfb64 can be used to encrypt single characters, therefore input and output
1439 do not need to be a multiple of 8.
1440- ofb64 is similar to cfb64 but is more like a stream cipher, not as
1441 secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
1442- If you want triple Blowfish, thats 384 bits of key and you must be totally
1443 obsessed with security. Still, if you want it, it is simple enough to
1444 copy the function from the DES library and change the des_encrypt to
1445 BF_encrypt; an exercise left for the paranoid reader :-).
1446
1447The functions are as follows:
1448
1449void BF_set_key(
1450BF_KEY *ks;
1451int len;
1452unsigned char *key;
1453 BF_set_key converts an 'len' byte key into a BF_KEY.
1454 A 'ks' is an expanded form of the 'key' which is used to
1455 perform actual encryption. It can be regenerated from the Blowfish key
1456 so it only needs to be kept when encryption or decryption is about
1457 to occur. Don't save or pass around BF_KEY's since they
1458 are CPU architecture dependent, 'key's are not. Blowfish is an
1459 interesting cipher in that it can be used with a variable length
1460 key. 'len' is the length of 'key' to be used as the key.
1461 A 'len' of 16 is recomended by me, but blowfish can use upto
1462 72 bytes. As a warning, blowfish has a very very slow set_key
1463 function, it actually runs BF_encrypt 521 times.
1464
1465void BF_encrypt(unsigned long *data, BF_KEY *key);
1466void BF_decrypt(unsigned long *data, BF_KEY *key);
1467 These are the Blowfish encryption function that gets called by just
1468 about every other Blowfish routine in the library. You should not
1469 use this function except to implement 'modes' of Blowfish.
1470 I say this because the
1471 functions that call this routine do the conversion from 'char *' to
1472 long, and this needs to be done to make sure 'non-aligned' memory
1473 access do not occur.
1474 Data is a pointer to 2 unsigned long's and key is the
1475 BF_KEY to use.
1476
1477void BF_ecb_encrypt(
1478unsigned char *in,
1479unsigned char *out,
1480BF_KEY *key,
1481int encrypt);
1482 This is the basic Electronic Code Book form of Blowfish (in DES this
1483 mode is called Electronic Code Book so I'm going to use the term
1484 for blowfish as well.
1485 Input is encrypted into output using the key represented by
1486 key. Depending on the encrypt, encryption or
1487 decryption occurs. Input is 8 bytes long and output is 8 bytes.
1488
1489void BF_cbc_encrypt(
1490unsigned char *in,
1491unsigned char *out,
1492long length,
1493BF_KEY *ks,
1494unsigned char *ivec,
1495int encrypt);
1496 This routine implements Blowfish in Cipher Block Chaining mode.
1497 Input, which should be a multiple of 8 bytes is encrypted
1498 (or decrypted) to output which will also be a multiple of 8 bytes.
1499 The number of bytes is in length (and from what I've said above,
1500 should be a multiple of 8). If length is not a multiple of 8, bad
1501 things will probably happen. ivec is the initialisation vector.
1502 This function updates iv after each call so that it can be passed to
1503 the next call to BF_cbc_encrypt().
1504
1505void BF_cfb64_encrypt(
1506unsigned char *in,
1507unsigned char *out,
1508long length,
1509BF_KEY *schedule,
1510unsigned char *ivec,
1511int *num,
1512int encrypt);
1513 This is one of the more useful functions in this Blowfish library, it
1514 implements CFB mode of Blowfish with 64bit feedback.
1515 This allows you to encrypt an arbitrary number of bytes,
1516 you do not require 8 byte padding. Each call to this
1517 routine will encrypt the input bytes to output and then update ivec
1518 and num. Num contains 'how far' we are though ivec.
1519 'Encrypt' is used to indicate encryption or decryption.
1520 CFB64 mode operates by using the cipher to generate a stream
1521 of bytes which is used to encrypt the plain text.
1522 The cipher text is then encrypted to generate the next 64 bits to
1523 be xored (incrementally) with the next 64 bits of plain
1524 text. As can be seen from this, to encrypt or decrypt,
1525 the same 'cipher stream' needs to be generated but the way the next
1526 block of data is gathered for encryption is different for
1527 encryption and decryption.
1528
1529void BF_ofb64_encrypt(
1530unsigned char *in,
1531unsigned char *out,
1532long length,
1533BF_KEY *schedule,
1534unsigned char *ivec,
1535int *num);
1536 This functions implements OFB mode of Blowfish with 64bit feedback.
1537 This allows you to encrypt an arbitrary number of bytes,
1538 you do not require 8 byte padding. Each call to this
1539 routine will encrypt the input bytes to output and then update ivec
1540 and num. Num contains 'how far' we are though ivec.
1541 This is in effect a stream cipher, there is no encryption or
1542 decryption mode.
1543
1544For reading passwords, I suggest using des_read_pw_string() from my DES library.
1545To generate a password from a text string, I suggest using MD5 (or MD2) to
1546produce a 16 byte message digest that can then be passed directly to
1547BF_set_key().
1548
1549=====
1550For more information about the specific Blowfish modes in this library
1551(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
1552documentation on my DES library. What is said about DES is directly
1553applicable for Blowfish.
1554
1555
1556==== bn.doc ========================================================
1557
1558The Big Number library.
1559
1560#include "bn.h" when using this library.
1561
1562This big number library was written for use in implementing the RSA and DH
1563public key encryption algorithms. As such, features such as negative
1564numbers have not been extensively tested but they should work as expected.
1565This library uses dynamic memory allocation for storing its data structures
1566and so there are no limit on the size of the numbers manipulated by these
1567routines but there is always the requirement to check return codes from
1568functions just in case a memory allocation error has occurred.
1569
1570The basic object in this library is a BIGNUM. It is used to hold a single
1571large integer. This type should be considered opaque and fields should not
1572be modified or accessed directly.
1573typedef struct bignum_st
1574 {
1575 int top; /* Index of last used d. */
1576 BN_ULONG *d; /* Pointer to an array of 'BITS2' bit chunks. */
1577 int max; /* Size of the d array. */
1578 int neg;
1579 } BIGNUM;
1580The big number is stored in a malloced array of BN_ULONG's. A BN_ULONG can
1581be either 16, 32 or 64 bits in size, depending on the 'number of bits'
1582specified in bn.h.
1583The 'd' field is this array. 'max' is the size of the 'd' array that has
1584been allocated. 'top' is the 'last' entry being used, so for a value of 4,
1585bn.d[0]=4 and bn.top=1. 'neg' is 1 if the number is negative.
1586When a BIGNUM is '0', the 'd' field can be NULL and top == 0.
1587
1588Various routines in this library require the use of 'temporary' BIGNUM
1589variables during their execution. Due to the use of dynamic memory
1590allocation to create BIGNUMs being rather expensive when used in
1591conjunction with repeated subroutine calls, the BN_CTX structure is
1592used. This structure contains BN_CTX BIGNUMs. BN_CTX
1593is the maximum number of temporary BIGNUMs any publicly exported
1594function will use.
1595
1596#define BN_CTX 12
1597typedef struct bignum_ctx
1598 {
1599 int tos; /* top of stack */
1600 BIGNUM *bn[BN_CTX]; /* The variables */
1601 } BN_CTX;
1602
1603The functions that follow have been grouped according to function. Most
1604arithmetic functions return a result in the first argument, sometimes this
1605first argument can also be an input parameter, sometimes it cannot. These
1606restrictions are documented.
1607
1608extern BIGNUM *BN_value_one;
1609There is one variable defined by this library, a BIGNUM which contains the
1610number 1. This variable is useful for use in comparisons and assignment.
1611
1612Get Size functions.
1613
1614int BN_num_bits(BIGNUM *a);
1615 This function returns the size of 'a' in bits.
1616
1617int BN_num_bytes(BIGNUM *a);
1618 This function (macro) returns the size of 'a' in bytes.
1619 For conversion of BIGNUMs to byte streams, this is the number of
1620 bytes the output string will occupy. If the output byte
1621 format specifies that the 'top' bit indicates if the number is
1622 signed, so an extra '0' byte is required if the top bit on a
1623 positive number is being written, it is upto the application to
1624 make this adjustment. Like I said at the start, I don't
1625 really support negative numbers :-).
1626
1627Creation/Destruction routines.
1628
1629BIGNUM *BN_new();
1630 Return a new BIGNUM object. The number initially has a value of 0. If
1631 there is an error, NULL is returned.
1632
1633void BN_free(BIGNUM *a);
1634 Free()s a BIGNUM.
1635
1636void BN_clear(BIGNUM *a);
1637 Sets 'a' to a value of 0 and also zeros all unused allocated
1638 memory. This function is used to clear a variable of 'sensitive'
1639 data that was held in it.
1640
1641void BN_clear_free(BIGNUM *a);
1642 This function zeros the memory used by 'a' and then free()'s it.
1643 This function should be used to BN_free() BIGNUMS that have held
1644 sensitive numeric values like RSA private key values. Both this
1645 function and BN_clear tend to only be used by RSA and DH routines.
1646
1647BN_CTX *BN_CTX_new(void);
1648 Returns a new BN_CTX. NULL on error.
1649
1650void BN_CTX_free(BN_CTX *c);
1651 Free a BN_CTX structure. The BIGNUMs in 'c' are BN_clear_free()ed.
1652
1653BIGNUM *bn_expand(BIGNUM *b, int bits);
1654 This is an internal function that should not normally be used. It
1655 ensures that 'b' has enough room for a 'bits' bit number. It is
1656 mostly used by the various BIGNUM routines. If there is an error,
1657 NULL is returned. if not, 'b' is returned.
1658
1659BIGNUM *BN_copy(BIGNUM *to, BIGNUM *from);
1660 The 'from' is copied into 'to'. NULL is returned if there is an
1661 error, otherwise 'to' is returned.
1662
1663BIGNUM *BN_dup(BIGNUM *a);
1664 A new BIGNUM is created and returned containing the value of 'a'.
1665 NULL is returned on error.
1666
1667Comparison and Test Functions.
1668
1669int BN_is_zero(BIGNUM *a)
1670 Return 1 if 'a' is zero, else 0.
1671
1672int BN_is_one(a)
1673 Return 1 is 'a' is one, else 0.
1674
1675int BN_is_word(a,w)
1676 Return 1 if 'a' == w, else 0. 'w' is a BN_ULONG.
1677
1678int BN_cmp(BIGNUM *a, BIGNUM *b);
1679 Return -1 if 'a' is less than 'b', 0 if 'a' and 'b' are the same
1680 and 1 is 'a' is greater than 'b'. This is a signed comparison.
1681
1682int BN_ucmp(BIGNUM *a, BIGNUM *b);
1683 This function is the same as BN_cmp except that the comparison
1684 ignores the sign of the numbers.
1685
1686Arithmetic Functions
1687For all of these functions, 0 is returned if there is an error and 1 is
1688returned for success. The return value should always be checked. eg.
1689if (!BN_add(r,a,b)) goto err;
1690Unless explicitly mentioned, the 'return' value can be one of the
1691'parameters' to the function.
1692
1693int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
1694 Add 'a' and 'b' and return the result in 'r'. This is r=a+b.
1695
1696int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b);
1697 Subtract 'a' from 'b' and put the result in 'r'. This is r=a-b.
1698
1699int BN_lshift(BIGNUM *r, BIGNUM *a, int n);
1700 Shift 'a' left by 'n' bits. This is r=a*(2^n).
1701
1702int BN_lshift1(BIGNUM *r, BIGNUM *a);
1703 Shift 'a' left by 1 bit. This form is more efficient than
1704 BN_lshift(r,a,1). This is r=a*2.
1705
1706int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
1707 Shift 'a' right by 'n' bits. This is r=int(a/(2^n)).
1708
1709int BN_rshift1(BIGNUM *r, BIGNUM *a);
1710 Shift 'a' right by 1 bit. This form is more efficient than
1711 BN_rshift(r,a,1). This is r=int(a/2).
1712
1713int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b);
1714 Multiply a by b and return the result in 'r'. 'r' must not be
1715 either 'a' or 'b'. It has to be a different BIGNUM.
1716 This is r=a*b.
1717
1718int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
1719 Multiply a by a and return the result in 'r'. 'r' must not be
1720 'a'. This function is alot faster than BN_mul(r,a,a). This is r=a*a.
1721
1722int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx);
1723 Divide 'm' by 'd' and return the result in 'dv' and the remainder
1724 in 'rem'. Either of 'dv' or 'rem' can be NULL in which case that
1725 value is not returned. 'ctx' needs to be passed as a source of
1726 temporary BIGNUM variables.
1727 This is dv=int(m/d), rem=m%d.
1728
1729int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx);
1730 Find the remainder of 'm' divided by 'd' and return it in 'rem'.
1731 'ctx' holds the temporary BIGNUMs required by this function.
1732 This function is more efficient than BN_div(NULL,rem,m,d,ctx);
1733 This is rem=m%d.
1734
1735int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *m,BN_CTX *ctx);
1736 Multiply 'a' by 'b' and return the remainder when divided by 'm'.
1737 'ctx' holds the temporary BIGNUMs required by this function.
1738 This is r=(a*b)%m.
1739
1740int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx);
1741 Raise 'a' to the 'p' power and return the remainder when divided by
1742 'm'. 'ctx' holds the temporary BIGNUMs required by this function.
1743 This is r=(a^p)%m.
1744
1745int BN_reciprocal(BIGNUM *r, BIGNUM *m, BN_CTX *ctx);
1746 Return the reciprocal of 'm'. 'ctx' holds the temporary variables
1747 required. This function returns -1 on error, otherwise it returns
1748 the number of bits 'r' is shifted left to make 'r' into an integer.
1749 This number of bits shifted is required in BN_mod_mul_reciprocal().
1750 This is r=(1/m)<<(BN_num_bits(m)+1).
1751
1752int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BIGNUM *m,
1753 BIGNUM *i, int nb, BN_CTX *ctx);
1754 This function is used to perform an efficient BN_mod_mul()
1755 operation. If one is going to repeatedly perform BN_mod_mul() with
1756 the same modulus is worth calculating the reciprocal of the modulus
1757 and then using this function. This operation uses the fact that
1758 a/b == a*r where r is the reciprocal of b. On modern computers
1759 multiplication is very fast and big number division is very slow.
1760 'x' is multiplied by 'y' and then divided by 'm' and the remainder
1761 is returned. 'i' is the reciprocal of 'm' and 'nb' is the number
1762 of bits as returned from BN_reciprocal(). Normal usage is as follows.
1763 bn=BN_reciprocal(i,m);
1764 for (...)
1765 { BN_mod_mul_reciprocal(r,x,y,m,i,bn,ctx); }
1766 This is r=(x*y)%m. Internally it is approximately
1767 r=(x*y)-m*(x*y/m) or r=(x*y)-m*((x*y*i) >> bn)
1768 This function is used in BN_mod_exp() and BN_is_prime().
1769
1770Assignment Operations
1771
1772int BN_one(BIGNUM *a)
1773 Set 'a' to hold the value one.
1774 This is a=1.
1775
1776int BN_zero(BIGNUM *a)
1777 Set 'a' to hold the value zero.
1778 This is a=0.
1779
1780int BN_set_word(BIGNUM *a, unsigned long w);
1781 Set 'a' to hold the value of 'w'. 'w' is an unsigned long.
1782 This is a=w.
1783
1784unsigned long BN_get_word(BIGNUM *a);
1785 Returns 'a' in an unsigned long. Not remarkably, often 'a' will
1786 be biger than a word, in which case 0xffffffffL is returned.
1787
1788Word Operations
1789These functions are much more efficient that the normal bignum arithmetic
1790operations.
1791
1792BN_ULONG BN_mod_word(BIGNUM *a, unsigned long w);
1793 Return the remainder of 'a' divided by 'w'.
1794 This is return(a%w).
1795
1796int BN_add_word(BIGNUM *a, unsigned long w);
1797 Add 'w' to 'a'. This function does not take the sign of 'a' into
1798 account. This is a+=w;
1799
1800Bit operations.
1801
1802int BN_is_bit_set(BIGNUM *a, int n);
1803 This function return 1 if bit 'n' is set in 'a' else 0.
1804
1805int BN_set_bit(BIGNUM *a, int n);
1806 This function sets bit 'n' to 1 in 'a'.
1807 This is a&= ~(1<<n);
1808
1809int BN_clear_bit(BIGNUM *a, int n);
1810 This function sets bit 'n' to zero in 'a'. Return 0 if less
1811 than 'n' bits in 'a' else 1. This is a&= ~(1<<n);
1812
1813int BN_mask_bits(BIGNUM *a, int n);
1814 Truncate 'a' to n bits long. This is a&= ~((~0)<<n)
1815
1816Format conversion routines.
1817
1818BIGNUM *BN_bin2bn(unsigned char *s, int len,BIGNUM *ret);
1819 This function converts 'len' bytes in 's' into a BIGNUM which
1820 is put in 'ret'. If ret is NULL, a new BIGNUM is created.
1821 Either this new BIGNUM or ret is returned. The number is
1822 assumed to be in bigendian form in 's'. By this I mean that
1823 to 'ret' is created as follows for 'len' == 5.
1824 ret = s[0]*2^32 + s[1]*2^24 + s[2]*2^16 + s[3]*2^8 + s[4];
1825 This function cannot be used to convert negative numbers. It
1826 is always assumed the number is positive. The application
1827 needs to diddle the 'neg' field of th BIGNUM its self.
1828 The better solution would be to save the numbers in ASN.1 format
1829 since this is a defined standard for storing big numbers.
1830 Look at the functions
1831
1832 ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
1833 BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
1834 int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
1835 ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
1836 long length;
1837
1838int BN_bn2bin(BIGNUM *a, unsigned char *to);
1839 This function converts 'a' to a byte string which is put into
1840 'to'. The representation is big-endian in that the most
1841 significant byte of 'a' is put into to[0]. This function
1842 returns the number of bytes used to hold 'a'. BN_num_bytes(a)
1843 would return the same value and can be used to determine how
1844 large 'to' needs to be. If the number is negative, this
1845 information is lost. Since this library was written to
1846 manipulate large positive integers, the inability to save and
1847 restore them is not considered to be a problem by me :-).
1848 As for BN_bin2bn(), look at the ASN.1 integer encoding funtions
1849 for SSLeay. They use BN_bin2bn() and BN_bn2bin() internally.
1850
1851char *BN_bn2ascii(BIGNUM *a);
1852 This function returns a malloc()ed string that contains the
1853 ascii hexadecimal encoding of 'a'. The number is in bigendian
1854 format with a '-' in front if the number is negative.
1855
1856int BN_ascii2bn(BIGNUM **bn, char *a);
1857 The inverse of BN_bn2ascii. The function returns the number of
1858 characters from 'a' were processed in generating a the bignum.
1859 error is inticated by 0 being returned. The number is a
1860 hex digit string, optionally with a leading '-'. If *bn
1861 is null, a BIGNUM is created and returned via that variable.
1862
1863int BN_print_fp(FILE *fp, BIGNUM *a);
1864 'a' is printed to file pointer 'fp'. It is in the same format
1865 that is output from BN_bn2ascii(). 0 is returned on error,
1866 1 if things are ok.
1867
1868int BN_print(BIO *bp, BIGNUM *a);
1869 Same as BN_print except that the output is done to the SSLeay libraries
1870 BIO routines. BN_print_fp() actually calls this function.
1871
1872Miscellaneous Routines.
1873
1874int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
1875 This function returns in 'rnd' a random BIGNUM that is bits
1876 long. If bottom is 1, the number returned is odd. If top is set,
1877 the top 2 bits of the number are set. This is useful because if
1878 this is set, 2 'n; bit numbers multiplied together will return a 2n
1879 bit number. If top was not set, they could produce a 2n-1 bit
1880 number.
1881
1882BIGNUM *BN_mod_inverse(BIGNUM *a, BIGNUM *n,BN_CTX *ctx);
1883 This function create a new BIGNUM and returns it. This number
1884 is the inverse mod 'n' of 'a'. By this it is meant that the
1885 returned value 'r' satisfies (a*r)%n == 1. This function is
1886 used in the generation of RSA keys. 'ctx', as per usual,
1887 is used to hold temporary variables that are required by the
1888 function. NULL is returned on error.
1889
1890int BN_gcd(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
1891 'r' has the greatest common divisor of 'a' and 'b'. 'ctx' is
1892 used for temporary variables and 0 is returned on error.
1893
1894int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(),BN_CTX *ctx,
1895 char *cb_arg);
1896 This function is used to check if a BIGNUM ('p') is prime.
1897 It performs this test by using the Miller-Rabin randomised
1898 primality test. This is a probalistic test that requires a
1899 number of rounds to ensure the number is prime to a high
1900 degree of probability. Since this can take quite some time, a
1901 callback function can be passed and it will be called each
1902 time 'p' passes a round of the prime testing. 'callback' will
1903 be called as follows, callback(1,n,cb_arg) where n is the number of
1904 the round, just passed. As per usual 'ctx' contains temporary
1905 variables used. If ctx is NULL, it does not matter, a local version
1906 will be malloced. This parameter is present to save some mallocing
1907 inside the function but probably could be removed.
1908 0 is returned on error.
1909 'ncheck' is the number of Miller-Rabin tests to run. It is
1910 suggested to use the value 'BN_prime_checks' by default.
1911
1912BIGNUM *BN_generate_prime(
1913int bits,
1914int strong,
1915BIGNUM *a,
1916BIGNUM *rems,
1917void (*callback)());
1918char *cb_arg
1919 This function is used to generate prime numbers. It returns a
1920 new BIGNUM that has a high probability of being a prime.
1921 'bits' is the number of bits that
1922 are to be in the prime. If 'strong' is true, the returned prime
1923 will also be a strong prime ((p-1)/2 is also prime).
1924 While searching for the prime ('p'), we
1925 can add the requirement that the prime fill the following
1926 condition p%a == rem. This can be used to help search for
1927 primes with specific features, which is required when looking
1928 for primes suitable for use with certain 'g' values in the
1929 Diffie-Hellman key exchange algorithm. If 'a' is NULL,
1930 this condition is not checked. If rem is NULL, rem is assumed
1931 to be 1. Since this search for a prime
1932 can take quite some time, if callback is not NULL, it is called
1933 in the following situations.
1934 We have a suspected prime (from a quick sieve),
1935 callback(0,sus_prime++,cb_arg). Each item to be passed to BN_is_prime().
1936 callback(1,round++,cb_arg). Each successful 'round' in BN_is_prime().
1937 callback(2,round,cb_arg). For each successful BN_is_prime() test.
1938
1939Hints
1940-----
1941
1942DSA wants 64*32 to use word mont mul, but RSA wants to use full.
1943
1944==== callback.doc ========================================================
1945
1946Callback functions used in SSLeay.
1947
1948--------------------------
1949The BIO library.
1950
1951Each BIO structure can have a callback defined against it. This callback is
1952called 2 times for each BIO 'function'. It is passed 6 parameters.
1953BIO_debug_callback() is an example callback which is defined in
1954crypto/buffer/bio_cb.c and is used in apps/dgst.c This is intended mostly
1955for debuging or to notify the application of IO.
1956
1957long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi,long argl,
1958 long ret);
1959bio is the BIO being called, cmd is the type of BIO function being called.
1960Look at the BIO_CB_* defines in buffer.h. Argp and argi are the arguments
1961passed to BIO_read(), BIO_write, BIO_gets(), BIO_puts(). In the case of
1962BIO_ctrl(), argl is also defined. The first time the callback is called,
1963before the underlying function has been executed, 0 is passed as 'ret', and
1964if the return code from the callback is not > 0, the call is aborted
1965and the returned <= 0 value is returned.
1966The second time the callback is called, the 'cmd' value also has
1967BIO_CB_RETURN logically 'or'ed with it. The 'ret' value is the value returned
1968from the actuall function call and whatever the callback returns is returned
1969from the BIO function.
1970
1971BIO_set_callback(b,cb) can be used to set the callback function
1972(b is a BIO), and BIO_set_callback_arg(b,arg) can be used to
1973set the cb_arg argument in the BIO strucutre. This field is only intended
1974to be used by application, primarily in the callback function since it is
1975accessable since the BIO is passed.
1976
1977--------------------------
1978The PEM library.
1979
1980The pem library only really uses one type of callback,
1981static int def_callback(char *buf, int num, int verify);
1982which is used to return a password string if required.
1983'buf' is the buffer to put the string in. 'num' is the size of 'buf'
1984and 'verify' is used to indicate that the password should be checked.
1985This last flag is mostly used when reading a password for encryption.
1986
1987For all of these functions, a NULL callback will call the above mentioned
1988default callback. This default function does not work under Windows 3.1.
1989For other machines, it will use an application defined prompt string
1990(EVP_set_pw_prompt(), which defines a library wide prompt string)
1991if defined, otherwise it will use it's own PEM password prompt.
1992It will then call EVP_read_pw_string() to get a password from the console.
1993If your application wishes to use nice fancy windows to retrieve passwords,
1994replace this function. The callback should return the number of bytes read
1995into 'buf'. If the number of bytes <= 0, it is considered an error.
1996
1997Functions that take this callback are listed below. For the 'read' type
1998functions, the callback will only be required if the PEM data is encrypted.
1999
2000For the Write functions, normally a password can be passed in 'kstr', of
2001'klen' bytes which will be used if the 'enc' cipher is not NULL. If
2002'kstr' is NULL, the callback will be used to retrieve a password.
2003
2004int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
2005 int (*callback)());
2006char *PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x,int (*cb)());
2007char *PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,int (*cb)());
2008int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x,
2009 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
2010int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,
2011 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
2012STACK *PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)());
2013STACK *PEM_X509_INFO_read_bio(BIO *fp, STACK *sk, int (*cb)());
2014
2015#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
2016#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
2017#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
2018#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
2019#define PEM_read_SSL_SESSION(fp,x,cb)
2020#define PEM_read_X509(fp,x,cb)
2021#define PEM_read_X509_REQ(fp,x,cb)
2022#define PEM_read_X509_CRL(fp,x,cb)
2023#define PEM_read_RSAPrivateKey(fp,x,cb)
2024#define PEM_read_DSAPrivateKey(fp,x,cb)
2025#define PEM_read_PrivateKey(fp,x,cb)
2026#define PEM_read_PKCS7(fp,x,cb)
2027#define PEM_read_DHparams(fp,x,cb)
2028#define PEM_read_bio_SSL_SESSION(bp,x,cb)
2029#define PEM_read_bio_X509(bp,x,cb)
2030#define PEM_read_bio_X509_REQ(bp,x,cb)
2031#define PEM_read_bio_X509_CRL(bp,x,cb)
2032#define PEM_read_bio_RSAPrivateKey(bp,x,cb)
2033#define PEM_read_bio_DSAPrivateKey(bp,x,cb)
2034#define PEM_read_bio_PrivateKey(bp,x,cb)
2035#define PEM_read_bio_PKCS7(bp,x,cb)
2036#define PEM_read_bio_DHparams(bp,x,cb)
2037int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
2038RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
2039
2040Now you will notice that macros like
2041#define PEM_write_X509(fp,x) \
2042 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
2043 (char *)x, NULL,NULL,0,NULL)
2044Don't do encryption normally. If you want to PEM encrypt your X509 structure,
2045either just call PEM_ASN1_write directly or just define you own
2046macro variant. As you can see, this macro just sets all encryption related
2047parameters to NULL.
2048
2049
2050--------------------------
2051The SSL library.
2052
2053#define SSL_set_info_callback(ssl,cb)
2054#define SSL_CTX_set_info_callback(ctx,cb)
2055void callback(SSL *ssl,int location,int ret)
2056This callback is called each time around the SSL_connect()/SSL_accept()
2057state machine. So it will be called each time the SSL protocol progresses.
2058It is mostly present for use when debugging. When SSL_connect() or
2059SSL_accept() return, the location flag is SSL_CB_ACCEPT_EXIT or
2060SSL_CB_CONNECT_EXIT and 'ret' is the value about to be returned.
2061Have a look at the SSL_CB_* defines in ssl.h. If an info callback is defined
2062against the SSL_CTX, it is called unless there is one set against the SSL.
2063Have a look at
2064void client_info_callback() in apps/s_client() for an example.
2065
2066Certificate verification.
2067void SSL_set_verify(SSL *s, int mode, int (*callback) ());
2068void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*callback)());
2069This callback is used to help verify client and server X509 certificates.
2070It is actually passed to X509_cert_verify(), along with the SSL structure
2071so you have to read about X509_cert_verify() :-). The SSL_CTX version is used
2072if the SSL version is not defined. X509_cert_verify() is the function used
2073by the SSL part of the library to verify certificates. This function is
2074nearly always defined by the application.
2075
2076void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg);
2077int callback(char *arg,SSL *s,X509 *xs,STACK *cert_chain);
2078This call is used to replace the SSLeay certificate verification code.
2079The 'arg' is kept in the SSL_CTX and is passed to the callback.
2080If the callback returns 0, the certificate is rejected, otherwise it
2081is accepted. The callback is replacing the X509_cert_verify() call.
2082This feature is not often used, but if you wished to implement
2083some totally different certificate authentication system, this 'hook' is
2084vital.
2085
2086SSLeay keeps a cache of session-ids against each SSL_CTX. These callbacks can
2087be used to notify the application when a SSL_SESSION is added to the cache
2088or to retrieve a SSL_SESSION that is not in the cache from the application.
2089#define SSL_CTX_sess_set_get_cb(ctx,cb)
2090SSL_SESSION *callback(SSL *s,char *session_id,int session_id_len,int *copy);
2091If defined, this callback is called to return the SESSION_ID for the
2092session-id in 'session_id', of 'session_id_len' bytes. 'copy' is set to 1
2093if the server is to 'take a copy' of the SSL_SESSION structure. It is 0
2094if the SSL_SESSION is being 'passed in' so the SSLeay library is now
2095responsible for 'free()ing' the structure. Basically it is used to indicate
2096if the reference count on the SSL_SESSION structure needs to be incremented.
2097
2098#define SSL_CTX_sess_set_new_cb(ctx,cb)
2099int callback(SSL *s, SSL_SESSION *sess);
2100When a new connection is established, if the SSL_SESSION is going to be added
2101to the cache, this callback is called. Return 1 if a 'copy' is required,
2102otherwise, return 0. This return value just causes the reference count
2103to be incremented (on return of a 1), this means the application does
2104not need to worry about incrementing the refernece count (and the
2105locking that implies in a multi-threaded application).
2106
2107void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)());
2108This sets the SSL password reading function.
2109It is mostly used for windowing applications
2110and used by PEM_read_bio_X509() and PEM_read_bio_RSAPrivateKey()
2111calls inside the SSL library. The only reason this is present is because the
2112calls to PEM_* functions is hidden in the SSLeay library so you have to
2113pass in the callback some how.
2114
2115#define SSL_CTX_set_client_cert_cb(ctx,cb)
2116int callback(SSL *s,X509 **x509, EVP_PKEY **pkey);
2117Called when a client certificate is requested but there is not one set
2118against the SSL_CTX or the SSL. If the callback returns 1, x509 and
2119pkey need to point to valid data. The library will free these when
2120required so if the application wants to keep these around, increment
2121their reference counts. If 0 is returned, no client cert is
2122available. If -1 is returned, it is assumed that the callback needs
2123to be called again at a later point in time. SSL_connect will return
2124-1 and SSL_want_x509_lookup(ssl) returns true. Remember that
2125application data can be attached to an SSL structure via the
2126SSL_set_app_data(SSL *ssl,char *data) call.
2127
2128--------------------------
2129The X509 library.
2130
2131int X509_cert_verify(CERTIFICATE_CTX *ctx,X509 *xs, int (*cb)(),
2132 int *error,char *arg,STACK *cert_chain);
2133int verify_callback(int ok,X509 *xs,X509 *xi,int depth,int error,char *arg,
2134 STACK *cert_chain);
2135
2136X509_cert_verify() is used to authenticate X509 certificates. The 'ctx' holds
2137the details of the various caches and files used to locate certificates.
2138'xs' is the certificate to verify and 'cb' is the application callback (more
2139detail later). 'error' will be set to the error code and 'arg' is passed
2140to the 'cb' callback. Look at the VERIFY_* defines in crypto/x509/x509.h
2141
2142When ever X509_cert_verify() makes a 'negative' decision about a
2143certitificate, the callback is called. If everything checks out, the
2144callback is called with 'VERIFY_OK' or 'VERIFY_ROOT_OK' (for a self
2145signed cert that is not the passed certificate).
2146
2147The callback is passed the X509_cert_verify opinion of the certificate
2148in 'ok', the certificate in 'xs', the issuer certificate in 'xi',
2149the 'depth' of the certificate in the verification 'chain', the
2150VERIFY_* code in 'error' and the argument passed to X509_cert_verify()
2151in 'arg'. cert_chain is a list of extra certs to use if they are not
2152in the cache.
2153
2154The callback can be used to look at the error reason, and then return 0
2155for an 'error' or '1' for ok. This will override the X509_cert_verify()
2156opinion of the certificates validity. Processing will continue depending on
2157the return value. If one just wishes to use the callback for informational
2158reason, just return the 'ok' parameter.
2159
2160--------------------------
2161The BN and DH library.
2162
2163BIGNUM *BN_generate_prime(int bits,int strong,BIGNUM *add,
2164 BIGNUM *rem,void (*callback)(int,int));
2165int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int),
2166
2167Read doc/bn.doc for the description of these 2.
2168
2169DH *DH_generate_parameters(int prime_len,int generator,
2170 void (*callback)(int,int));
2171Read doc/bn.doc for the description of the callback, since it is just passed
2172to BN_generate_prime(), except that it is also called as
2173callback(3,0) by this function.
2174
2175--------------------------
2176The CRYPTO library.
2177
2178void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file,
2179 int line));
2180void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,
2181 int type,char *file, int line));
2182void CRYPTO_set_id_callback(unsigned long (*func)(void));
2183
2184Read threads.doc for info on these ones.
2185
2186
2187==== cipher.doc ========================================================
2188
2189The Cipher subroutines.
2190
2191These routines require "evp.h" to be included.
2192
2193These functions are a higher level interface to the various cipher
2194routines found in this library. As such, they allow the same code to be
2195used to encrypt and decrypt via different ciphers with only a change
2196in an initial parameter. These routines also provide buffering for block
2197ciphers.
2198
2199These routines all take a pointer to the following structure to specify
2200which cipher to use. If you wish to use a new cipher with these routines,
2201you would probably be best off looking an how an existing cipher is
2202implemented and copying it. At this point in time, I'm not going to go
2203into many details. This structure should be considered opaque
2204
2205typedef struct pem_cipher_st
2206 {
2207 int type;
2208 int block_size;
2209 int key_len;
2210 int iv_len;
2211 void (*enc_init)(); /* init for encryption */
2212 void (*dec_init)(); /* init for decryption */
2213 void (*do_cipher)(); /* encrypt data */
2214 } EVP_CIPHER;
2215
2216The type field is the object NID of the cipher type
2217(read the section on Objects for an explanation of what a NID is).
2218The cipher block_size is how many bytes need to be passed
2219to the cipher at a time. Key_len is the
2220length of the key the cipher requires and iv_len is the length of the
2221initialisation vector required. enc_init is the function
2222called to initialise the ciphers context for encryption and dec_init is the
2223function to initialise for decryption (they need to be different, especially
2224for the IDEA cipher).
2225
2226One reason for specifying the Cipher via a pointer to a structure
2227is that if you only use des-cbc, only the des-cbc routines will
2228be included when you link the program. If you passed an integer
2229that specified which cipher to use, the routine that mapped that
2230integer to a set of cipher functions would cause all the ciphers
2231to be link into the code. This setup also allows new ciphers
2232to be added by the application (with some restrictions).
2233
2234The thirteen ciphers currently defined in this library are
2235
2236EVP_CIPHER *EVP_des_ecb(); /* DES in ecb mode, iv=0, block=8, key= 8 */
2237EVP_CIPHER *EVP_des_ede(); /* DES in ecb ede mode, iv=0, block=8, key=16 */
2238EVP_CIPHER *EVP_des_ede3(); /* DES in ecb ede mode, iv=0, block=8, key=24 */
2239EVP_CIPHER *EVP_des_cfb(); /* DES in cfb mode, iv=8, block=1, key= 8 */
2240EVP_CIPHER *EVP_des_ede_cfb(); /* DES in ede cfb mode, iv=8, block=1, key=16 */
2241EVP_CIPHER *EVP_des_ede3_cfb();/* DES in ede cfb mode, iv=8, block=1, key=24 */
2242EVP_CIPHER *EVP_des_ofb(); /* DES in ofb mode, iv=8, block=1, key= 8 */
2243EVP_CIPHER *EVP_des_ede_ofb(); /* DES in ede ofb mode, iv=8, block=1, key=16 */
2244EVP_CIPHER *EVP_des_ede3_ofb();/* DES in ede ofb mode, iv=8, block=1, key=24 */
2245EVP_CIPHER *EVP_des_cbc(); /* DES in cbc mode, iv=8, block=8, key= 8 */
2246EVP_CIPHER *EVP_des_ede_cbc(); /* DES in cbc ede mode, iv=8, block=8, key=16 */
2247EVP_CIPHER *EVP_des_ede3_cbc();/* DES in cbc ede mode, iv=8, block=8, key=24 */
2248EVP_CIPHER *EVP_desx_cbc(); /* DES in desx cbc mode,iv=8, block=8, key=24 */
2249EVP_CIPHER *EVP_rc4(); /* RC4, iv=0, block=1, key=16 */
2250EVP_CIPHER *EVP_idea_ecb(); /* IDEA in ecb mode, iv=0, block=8, key=16 */
2251EVP_CIPHER *EVP_idea_cfb(); /* IDEA in cfb mode, iv=8, block=1, key=16 */
2252EVP_CIPHER *EVP_idea_ofb(); /* IDEA in ofb mode, iv=8, block=1, key=16 */
2253EVP_CIPHER *EVP_idea_cbc(); /* IDEA in cbc mode, iv=8, block=8, key=16 */
2254EVP_CIPHER *EVP_rc2_ecb(); /* RC2 in ecb mode, iv=0, block=8, key=16 */
2255EVP_CIPHER *EVP_rc2_cfb(); /* RC2 in cfb mode, iv=8, block=1, key=16 */
2256EVP_CIPHER *EVP_rc2_ofb(); /* RC2 in ofb mode, iv=8, block=1, key=16 */
2257EVP_CIPHER *EVP_rc2_cbc(); /* RC2 in cbc mode, iv=8, block=8, key=16 */
2258EVP_CIPHER *EVP_bf_ecb(); /* Blowfish in ecb mode,iv=0, block=8, key=16 */
2259EVP_CIPHER *EVP_bf_cfb(); /* Blowfish in cfb mode,iv=8, block=1, key=16 */
2260EVP_CIPHER *EVP_bf_ofb(); /* Blowfish in ofb mode,iv=8, block=1, key=16 */
2261EVP_CIPHER *EVP_bf_cbc(); /* Blowfish in cbc mode,iv=8, block=8, key=16 */
2262
2263The meaning of the compound names is as follows.
2264des The base cipher is DES.
2265idea The base cipher is IDEA
2266rc4 The base cipher is RC4-128
2267rc2 The base cipher is RC2-128
2268ecb Electronic Code Book form of the cipher.
2269cbc Cipher Block Chaining form of the cipher.
2270cfb 64 bit Cipher Feedback form of the cipher.
2271ofb 64 bit Output Feedback form of the cipher.
2272ede The cipher is used in Encrypt, Decrypt, Encrypt mode. The first
2273 and last keys are the same.
2274ede3 The cipher is used in Encrypt, Decrypt, Encrypt mode.
2275
2276All the Cipher routines take a EVP_CIPHER_CTX pointer as an argument.
2277The state of the cipher is kept in this structure.
2278
2279typedef struct EVP_CIPHER_Ctx_st
2280 {
2281 EVP_CIPHER *cipher;
2282 int encrypt; /* encrypt or decrypt */
2283 int buf_len; /* number we have left */
2284 unsigned char buf[8];
2285 union {
2286 .... /* cipher specific stuff */
2287 } c;
2288 } EVP_CIPHER_CTX;
2289
2290Cipher is a pointer the the EVP_CIPHER for the current context. The encrypt
2291flag indicates encryption or decryption. buf_len is the number of bytes
2292currently being held in buf.
2293The 'c' union holds the cipher specify context.
2294
2295The following functions are to be used.
2296
2297int EVP_read_pw_string(
2298char *buf,
2299int len,
2300char *prompt,
2301int verify,
2302 This function is the same as des_read_pw_string() (des.doc).
2303
2304void EVP_set_pw_prompt(char *prompt);
2305 This function sets the 'default' prompt to use to use in
2306 EVP_read_pw_string when the prompt parameter is NULL. If the
2307 prompt parameter is NULL, this 'default prompt' feature is turned
2308 off. Be warned, this is a global variable so weird things
2309 will happen if it is used under Win16 and care must be taken
2310 with a multi-threaded version of the library.
2311
2312char *EVP_get_pw_prompt();
2313 This returns a pointer to the default prompt string. NULL
2314 if it is not set.
2315
2316int EVP_BytesToKey(
2317EVP_CIPHER *type,
2318EVP_MD *md,
2319unsigned char *salt,
2320unsigned char *data,
2321int datal,
2322int count,
2323unsigned char *key,
2324unsigned char *iv);
2325 This function is used to generate a key and an initialisation vector
2326 for a specified cipher from a key string and a salt. Type
2327 specifies the cipher the 'key' is being generated for. Md is the
2328 message digest algorithm to use to generate the key and iv. The salt
2329 is an optional 8 byte object that is used to help seed the key
2330 generator.
2331 If the salt value is NULL, it is just not used. Datal is the
2332 number of bytes to use from 'data' in the key generation.
2333 This function returns the key size for the specified cipher, if
2334 data is NULL, this value is returns and no other
2335 computation is performed. Count is
2336 the number of times to loop around the key generator. I would
2337 suggest leaving it's value as 1. Key and iv are the structures to
2338 place the returning iv and key in. If they are NULL, no value is
2339 generated for that particular value.
2340 The algorithm used is as follows
2341
2342 /* M[] is an array of message digests
2343 * MD() is the message digest function */
2344 M[0]=MD(data . salt);
2345 for (i=1; i<count; i++) M[0]=MD(M[0]);
2346
2347 i=1
2348 while (data still needed for key and iv)
2349 {
2350 M[i]=MD(M[i-1] . data . salt);
2351 for (i=1; i<count; i++) M[i]=MD(M[i]);
2352 i++;
2353 }
2354
2355 If the salt is NULL, it is not used.
2356 The digests are concatenated together.
2357 M = M[0] . M[1] . M[2] .......
2358
2359 For key= 8, iv=8 => key=M[0.. 8], iv=M[ 9 .. 16].
2360 For key=16, iv=0 => key=M[0..16].
2361 For key=16, iv=8 => key=M[0..16], iv=M[17 .. 24].
2362 For key=24, iv=8 => key=M[0..24], iv=M[25 .. 32].
2363
2364 This routine will produce DES-CBC keys and iv that are compatible
2365 with the PKCS-5 standard when md2 or md5 are used. If md5 is
2366 used, the salt is NULL and count is 1, this routine will produce
2367 the password to key mapping normally used with RC4.
2368 I have attempted to logically extend the PKCS-5 standard to
2369 generate keys and iv for ciphers that require more than 16 bytes,
2370 if anyone knows what the correct standard is, please inform me.
2371 When using sha or sha1, things are a bit different under this scheme,
2372 since sha produces a 20 byte digest. So for ciphers requiring
2373 24 bits of data, 20 will come from the first MD and 4 will
2374 come from the second.
2375
2376 I have considered having a separate function so this 'routine'
2377 can be used without the requirement of passing a EVP_CIPHER *,
2378 but I have decided to not bother. If you wish to use the
2379 function without official EVP_CIPHER structures, just declare
2380 a local one and set the key_len and iv_len fields to the
2381 length you desire.
2382
2383The following routines perform encryption and decryption 'by parts'. By
2384this I mean that there are groups of 3 routines. An Init function that is
2385used to specify a cipher and initialise data structures. An Update routine
2386that does encryption/decryption, one 'chunk' at a time. And finally a
2387'Final' function that finishes the encryption/decryption process.
2388All these functions take a EVP_CIPHER pointer to specify which cipher to
2389encrypt/decrypt with. They also take a EVP_CIPHER_CTX object as an
2390argument. This structure is used to hold the state information associated
2391with the operation in progress.
2392
2393void EVP_EncryptInit(
2394EVP_CIPHER_CTX *ctx,
2395EVP_CIPHER *type,
2396unsigned char *key,
2397unsigned char *iv);
2398 This function initialise a EVP_CIPHER_CTX for encryption using the
2399 cipher passed in the 'type' field. The cipher is initialised to use
2400 'key' as the key and 'iv' for the initialisation vector (if one is
2401 required). If the type, key or iv is NULL, the value currently in the
2402 EVP_CIPHER_CTX is reused. So to perform several decrypt
2403 using the same cipher, key and iv, initialise with the cipher,
2404 key and iv the first time and then for subsequent calls,
2405 reuse 'ctx' but pass NULL for type, key and iv. You must make sure
2406 to pass a key that is large enough for a particular cipher. I
2407 would suggest using the EVP_BytesToKey() function.
2408
2409void EVP_EncryptUpdate(
2410EVP_CIPHER_CTX *ctx,
2411unsigned char *out,
2412int *outl,
2413unsigned char *in,
2414int inl);
2415 This function takes 'inl' bytes from 'in' and outputs bytes
2416 encrypted by the cipher 'ctx' was initialised with into 'out'. The
2417 number of bytes written to 'out' is put into outl. If a particular
2418 cipher encrypts in blocks, less or more bytes than input may be
2419 output. Currently the largest block size used by supported ciphers
2420 is 8 bytes, so 'out' should have room for 'inl+7' bytes. Normally
2421 EVP_EncryptInit() is called once, followed by lots and lots of
2422 calls to EVP_EncryptUpdate, followed by a single EVP_EncryptFinal
2423 call.
2424
2425void EVP_EncryptFinal(
2426EVP_CIPHER_CTX *ctx,
2427unsigned char *out,
2428int *outl);
2429 Because quite a large number of ciphers are block ciphers, there is
2430 often an incomplete block to write out at the end of the
2431 encryption. EVP_EncryptFinal() performs processing on this last
2432 block. The last block in encoded in such a way that it is possible
2433 to determine how many bytes in the last block are valid. For 8 byte
2434 block size ciphers, if only 5 bytes in the last block are valid, the
2435 last three bytes will be filled with the value 3. If only 2 were
2436 valid, the other 6 would be filled with sixes. If all 8 bytes are
2437 valid, a extra 8 bytes are appended to the cipher stream containing
2438 nothing but 8 eights. These last bytes are output into 'out' and
2439 the number of bytes written is put into 'outl' These last bytes
2440 are output into 'out' and the number of bytes written is put into
2441 'outl'. This form of block cipher finalisation is compatible with
2442 PKCS-5. Please remember that even if you are using ciphers like
2443 RC4 that has no blocking and so the function will not write
2444 anything into 'out', it would still be a good idea to pass a
2445 variable for 'out' that can hold 8 bytes just in case the cipher is
2446 changed some time in the future. It should also be remembered
2447 that the EVP_CIPHER_CTX contains the password and so when one has
2448 finished encryption with a particular EVP_CIPHER_CTX, it is good
2449 practice to zero the structure
2450 (ie. memset(ctx,0,sizeof(EVP_CIPHER_CTX)).
2451
2452void EVP_DecryptInit(
2453EVP_CIPHER_CTX *ctx,
2454EVP_CIPHER *type,
2455unsigned char *key,
2456unsigned char *iv);
2457 This function is basically the same as EVP_EncryptInit() accept that
2458 is prepares the EVP_CIPHER_CTX for decryption.
2459
2460void EVP_DecryptUpdate(
2461EVP_CIPHER_CTX *ctx,
2462unsigned char *out,
2463int *outl,
2464unsigned char *in,
2465int inl);
2466 This function is basically the same as EVP_EncryptUpdate()
2467 except that it performs decryption. There is one
2468 fundamental difference though. 'out' can not be the same as
2469 'in' for any ciphers with a block size greater than 1 if more
2470 than one call to EVP_DecryptUpdate() will be made. This
2471 is because this routine can hold a 'partial' block between
2472 calls. When a partial block is decrypted (due to more bytes
2473 being passed via this function, they will be written to 'out'
2474 overwriting the input bytes in 'in' that have not been read
2475 yet. From this it should also be noted that 'out' should
2476 be at least one 'block size' larger than 'inl'. This problem
2477 only occurs on the second and subsequent call to
2478 EVP_DecryptUpdate() when using a block cipher.
2479
2480int EVP_DecryptFinal(
2481EVP_CIPHER_CTX *ctx,
2482unsigned char *out,
2483int *outl);
2484 This function is different to EVP_EncryptFinal in that it 'removes'
2485 any padding bytes appended when the data was encrypted. Due to the
2486 way in which 1 to 8 bytes may have been appended when encryption
2487 using a block cipher, 'out' can end up with 0 to 7 bytes being put
2488 into it. When decoding the padding bytes, it is possible to detect
2489 an incorrect decryption. If the decryption appears to be wrong, 0
2490 is returned. If everything seems ok, 1 is returned. For ciphers
2491 with a block size of 1 (RC4), this function would normally not
2492 return any bytes and would always return 1. Just because this
2493 function returns 1 does not mean the decryption was correct. It
2494 would normally be wrong due to either the wrong key/iv or
2495 corruption of the cipher data fed to EVP_DecryptUpdate().
2496 As for EVP_EncryptFinal, it is a good idea to zero the
2497 EVP_CIPHER_CTX after use since the structure contains the key used
2498 to decrypt the data.
2499
2500The following Cipher routines are convenience routines that call either
2501EVP_EncryptXxx or EVP_DecryptXxx depending on weather the EVP_CIPHER_CTX
2502was setup to encrypt or decrypt.
2503
2504void EVP_CipherInit(
2505EVP_CIPHER_CTX *ctx,
2506EVP_CIPHER *type,
2507unsigned char *key,
2508unsigned char *iv,
2509int enc);
2510 This function take arguments that are the same as EVP_EncryptInit()
2511 and EVP_DecryptInit() except for the extra 'enc' flag. If 1, the
2512 EVP_CIPHER_CTX is setup for encryption, if 0, decryption.
2513
2514void EVP_CipherUpdate(
2515EVP_CIPHER_CTX *ctx,
2516unsigned char *out,
2517int *outl,
2518unsigned char *in,
2519int inl);
2520 Again this function calls either EVP_EncryptUpdate() or
2521 EVP_DecryptUpdate() depending on state in the 'ctx' structure.
2522 As noted for EVP_DecryptUpdate(), when this routine is used
2523 for decryption with block ciphers, 'out' should not be the
2524 same as 'in'.
2525
2526int EVP_CipherFinal(
2527EVP_CIPHER_CTX *ctx,
2528unsigned char *outm,
2529int *outl);
2530 This routine call EVP_EncryptFinal() or EVP_DecryptFinal()
2531 depending on the state information in 'ctx'. 1 is always returned
2532 if the mode is encryption, otherwise the return value is the return
2533 value of EVP_DecryptFinal().
2534
2535==== cipher.m ========================================================
2536
2537Date: Tue, 15 Oct 1996 08:16:14 +1000 (EST)
2538From: Eric Young <eay@mincom.com>
2539X-Sender: eay@orb
2540To: Roland Haring <rharing@tandem.cl>
2541Cc: ssl-users@mincom.com
2542Subject: Re: Symmetric encryption with ssleay
2543In-Reply-To: <m0vBpyq-00001aC@tandemnet.tandem.cl>
2544Message-Id: <Pine.SOL.3.91.961015075623.11394A-100000@orb>
2545Mime-Version: 1.0
2546Content-Type: TEXT/PLAIN; charset=US-ASCII
2547Sender: ssl-lists-owner@mincom.com
2548Precedence: bulk
2549Status: RO
2550X-Status:
2551
2552On Fri, 11 Oct 1996, Roland Haring wrote:
2553> THE_POINT:
2554> Would somebody be so kind to give me the minimum basic
2555> calls I need to do to libcrypto.a to get some text encrypted
2556> and decrypted again? ...hopefully with code included to do
2557> base64 encryption and decryption ... e.g. that sign-it.c code
2558> posted some while ago was a big help :-) (please, do not point
2559> me to apps/enc.c where I suspect my Heissenbug to be hidden :-)
2560
2561Ok, the base64 encoding stuff in 'enc.c' does the wrong thing sometimes
2562when the data is less than a line long (this is for decoding). I'll dig
2563up the exact fix today and post it. I am taking longer on 0.6.5 than I
2564intended so I'll just post this patch.
2565
2566The documentation to read is in
2567doc/cipher.doc,
2568doc/encode.doc (very sparse :-).
2569and perhaps
2570doc/digest.doc,
2571
2572The basic calls to encrypt with say triple DES are
2573
2574Given
2575char key[EVP_MAX_KEY_LENGTH];
2576char iv[EVP_MAX_IV_LENGTH];
2577EVP_CIPHER_CTX ctx;
2578unsigned char out[512+8];
2579int outl;
2580
2581/* optional generation of key/iv data from text password using md5
2582 * via an upward compatable verson of PKCS#5. */
2583EVP_BytesToKey(EVP_des_ede3_cbc,EVP_md5,NULL,passwd,strlen(passwd),
2584 key,iv);
2585
2586/* Initalise the EVP_CIPHER_CTX */
2587EVP_EncryptInit(ctx,EVP_des_ede3_cbc,key,iv);
2588
2589while (....)
2590 {
2591 /* This is processing 512 bytes at a time, the bytes are being
2592 * copied into 'out', outl bytes are output. 'out' should not be the
2593 * same as 'in' for reasons mentioned in the documentation. */
2594 EVP_EncryptUpdate(ctx,out,&outl,in,512);
2595 }
2596
2597/* Output the last 'block'. If the cipher is a block cipher, the last
2598 * block is encoded in such a way so that a wrong decryption will normally be
2599 * detected - again, one of the PKCS standards. */
2600
2601EVP_EncryptFinal(ctx,out,&outl);
2602
2603To decrypt, use the EVP_DecryptXXXXX functions except that EVP_DecryptFinal()
2604will return 0 if the decryption fails (only detectable on block ciphers).
2605
2606You can also use
2607EVP_CipherInit()
2608EVP_CipherUpdate()
2609EVP_CipherFinal()
2610which does either encryption or decryption depending on an extra
2611parameter to EVP_CipherInit().
2612
2613
2614To do the base64 encoding,
2615EVP_EncodeInit()
2616EVP_EncodeUpdate()
2617EVP_EncodeFinal()
2618
2619EVP_DecodeInit()
2620EVP_DecodeUpdate()
2621EVP_DecodeFinal()
2622
2623where the encoding is quite simple, but the decoding can be a bit more
2624fun (due to dud input).
2625
2626EVP_DecodeUpdate() returns -1 for an error on an input line, 0 if the
2627'last line' was just processed, and 1 if more lines should be submitted.
2628
2629EVP_DecodeFinal() returns -1 for an error or 1 if things are ok.
2630
2631So the loop becomes
2632EVP_DecodeInit(....)
2633for (;;)
2634 {
2635 i=EVP_DecodeUpdate(....);
2636 if (i < 0) goto err;
2637
2638 /* process the data */
2639
2640 if (i == 0) break;
2641 }
2642EVP_DecodeFinal(....);
2643/* process the data */
2644
2645The problem in 'enc.c' is that I was stuff the processing up after the
2646EVP_DecodeFinal(...) when the for(..) loop was not being run (one line of
2647base64 data) and this was because 'enc.c' tries to scan over a file until
2648it hits the first valid base64 encoded line.
2649
2650hope this helps a bit.
2651eric
2652--
2653Eric Young | BOOL is tri-state according to Bill Gates.
2654AARNet: eay@mincom.oz.au | RTFM Win32 GetMessage().
2655
2656==== conf.doc ========================================================
2657
2658The CONF library.
2659
2660The CONF library is a simple set of routines that can be used to configure
2661programs. It is a superset of the genenv() function with some extra
2662structure.
2663
2664The library consists of 5 functions.
2665
2666LHASH *CONF_load(LHASH *config,char *file);
2667This function is called to load in a configuration file. Multiple
2668configuration files can be loaded, with each subsequent 'load' overwriting
2669any already defined 'variables'. If there is an error, NULL is returned.
2670If config is NULL, a new LHASH structure is created and returned, otherwise
2671the new data in the 'file' is loaded into the 'config' structure.
2672
2673void CONF_free(LHASH *config);
2674This function free()s the data in config.
2675
2676char *CONF_get_string(LHASH *config,char *section,char *name);
2677This function returns the string found in 'config' that corresponds to the
2678'section' and 'name' specified. Classes and the naming system used will be
2679discussed later in this document. If the variable is not defined, an NULL
2680is returned.
2681
2682long CONF_get_long(LHASH *config,char *section, char *name);
2683This function is the same as CONF_get_string() except that it converts the
2684string to an long and returns it. If variable is not a number or the
2685variable does not exist, 0 is returned. This is a little problematic but I
2686don't know of a simple way around it.
2687
2688STACK *CONF_get_section(LHASH *config, char *section);
2689This function returns a 'stack' of CONF_VALUE items that are all the
2690items defined in a particular section. DO NOT free() any of the
2691variable returned. They will disappear when CONF_free() is called.
2692
2693The 'lookup' model.
2694The configuration file is divided into 'sections'. Each section is started by
2695a line of the form '[ section ]'. All subsequent variable definitions are
2696of this section. A variable definition is a simple alpha-numeric name
2697followed by an '=' and then the data. A section or variable name can be
2698described by a regular expression of the following form '[A-Za-z0-9_]+'.
2699The value of the variable is the text after the '=' until the end of the
2700line, stripped of leading and trailing white space.
2701At this point I should mention that a '#' is a comment character, \ is the
2702escape character, and all three types of quote can be used to stop any
2703special interpretation of the data.
2704Now when the data is being loaded, variable expansion can occur. This is
2705done by expanding any $NAME sequences into the value represented by the
2706variable NAME. If the variable is not in the current section, the different
2707section can be specified by using the $SECTION::NAME form. The ${NAME} form
2708also works and is very useful for expanding variables inside strings.
2709
2710When a variable is looked up, there are 2 special section. 'default', which
2711is the initial section, and 'ENV' which is the processes environment
2712variables (accessed via getenv()). When a variable is looked up, it is
2713first 'matched' with it's section (if one was specified), if this fails, the
2714'default' section is matched.
2715If the 'lhash' variable passed was NULL, the environment is searched.
2716
2717Now why do we bother with sections? So we can have multiple programs using
2718the same configuration file, or multiple instances of the same program
2719using different variables. It also provides a nice mechanism to override
2720the processes environment variables (eg ENV::HOME=/tmp). If there is a
2721program specific variable missing, we can have default values.
2722Multiple configuration files can be loaded, with each new value clearing
2723any predefined values. A system config file can provide 'default' values,
2724and application/usr specific files can provide overriding values.
2725
2726Examples
2727
2728# This is a simple example
2729SSLEAY_HOME = /usr/local/ssl
2730ENV::PATH = $SSLEAY_HOME/bin:$PATH # override my path
2731
2732[X509]
2733cert_dir = $SSLEAY_HOME/certs # /usr/local/ssl/certs
2734
2735[SSL]
2736CIPHER = DES-EDE-MD5:RC4-MD5
2737USER_CERT = $HOME/${USER}di'r 5' # /home/eay/eaydir 5
2738USER_CERT = $HOME/\${USER}di\'r # /home/eay/${USER}di'r
2739USER_CERT = "$HOME/${US"ER}di\'r # $HOME/${USER}di'r
2740
2741TEST = 1234\
27425678\
27439ab # TEST=123456789ab
2744TTT = 1234\n\n # TTT=1234<nl><nl>
2745
2746
2747
2748==== des.doc ========================================================
2749
2750The DES library.
2751
2752Please note that this library was originally written to operate with
2753eBones, a version of Kerberos that had had encryption removed when it left
2754the USA and then put back in. As such there are some routines that I will
2755advise not using but they are still in the library for historical reasons.
2756For all calls that have an 'input' and 'output' variables, they can be the
2757same.
2758
2759This library requires the inclusion of 'des.h'.
2760
2761All of the encryption functions take what is called a des_key_schedule as an
2762argument. A des_key_schedule is an expanded form of the des key.
2763A des_key is 8 bytes of odd parity, the type used to hold the key is a
2764des_cblock. A des_cblock is an array of 8 bytes, often in this library
2765description I will refer to input bytes when the function specifies
2766des_cblock's as input or output, this just means that the variable should
2767be a multiple of 8 bytes.
2768
2769The define DES_ENCRYPT is passed to specify encryption, DES_DECRYPT to
2770specify decryption. The functions and global variable are as follows:
2771
2772int des_check_key;
2773 DES keys are supposed to be odd parity. If this variable is set to
2774 a non-zero value, des_set_key() will check that the key has odd
2775 parity and is not one of the known weak DES keys. By default this
2776 variable is turned off;
2777
2778void des_set_odd_parity(
2779des_cblock *key );
2780 This function takes a DES key (8 bytes) and sets the parity to odd.
2781
2782int des_is_weak_key(
2783des_cblock *key );
2784 This function returns a non-zero value if the DES key passed is a
2785 weak, DES key. If it is a weak key, don't use it, try a different
2786 one. If you are using 'random' keys, the chances of hitting a weak
2787 key are 1/2^52 so it is probably not worth checking for them.
2788
2789int des_set_key(
2790des_cblock *key,
2791des_key_schedule schedule);
2792 Des_set_key converts an 8 byte DES key into a des_key_schedule.
2793 A des_key_schedule is an expanded form of the key which is used to
2794 perform actual encryption. It can be regenerated from the DES key
2795 so it only needs to be kept when encryption or decryption is about
2796 to occur. Don't save or pass around des_key_schedule's since they
2797 are CPU architecture dependent, DES keys are not. If des_check_key
2798 is non zero, zero is returned if the key has the wrong parity or
2799 the key is a weak key, else 1 is returned.
2800
2801int des_key_sched(
2802des_cblock *key,
2803des_key_schedule schedule);
2804 An alternative name for des_set_key().
2805
2806int des_rw_mode; /* defaults to DES_PCBC_MODE */
2807 This flag holds either DES_CBC_MODE or DES_PCBC_MODE (default).
2808 This specifies the function to use in the enc_read() and enc_write()
2809 functions.
2810
2811void des_encrypt(
2812unsigned long *data,
2813des_key_schedule ks,
2814int enc);
2815 This is the DES encryption function that gets called by just about
2816 every other DES routine in the library. You should not use this
2817 function except to implement 'modes' of DES. I say this because the
2818 functions that call this routine do the conversion from 'char *' to
2819 long, and this needs to be done to make sure 'non-aligned' memory
2820 access do not occur. The characters are loaded 'little endian',
2821 have a look at my source code for more details on how I use this
2822 function.
2823 Data is a pointer to 2 unsigned long's and ks is the
2824 des_key_schedule to use. enc, is non zero specifies encryption,
2825 zero if decryption.
2826
2827void des_encrypt2(
2828unsigned long *data,
2829des_key_schedule ks,
2830int enc);
2831 This functions is the same as des_encrypt() except that the DES
2832 initial permutation (IP) and final permutation (FP) have been left
2833 out. As for des_encrypt(), you should not use this function.
2834 It is used by the routines in my library that implement triple DES.
2835 IP() des_encrypt2() des_encrypt2() des_encrypt2() FP() is the same
2836 as des_encrypt() des_encrypt() des_encrypt() except faster :-).
2837
2838void des_ecb_encrypt(
2839des_cblock *input,
2840des_cblock *output,
2841des_key_schedule ks,
2842int enc);
2843 This is the basic Electronic Code Book form of DES, the most basic
2844 form. Input is encrypted into output using the key represented by
2845 ks. If enc is non zero (DES_ENCRYPT), encryption occurs, otherwise
2846 decryption occurs. Input is 8 bytes long and output is 8 bytes.
2847 (the des_cblock structure is 8 chars).
2848
2849void des_ecb3_encrypt(
2850des_cblock *input,
2851des_cblock *output,
2852des_key_schedule ks1,
2853des_key_schedule ks2,
2854des_key_schedule ks3,
2855int enc);
2856 This is the 3 key EDE mode of ECB DES. What this means is that
2857 the 8 bytes of input is encrypted with ks1, decrypted with ks2 and
2858 then encrypted again with ks3, before being put into output;
2859 C=E(ks3,D(ks2,E(ks1,M))). There is a macro, des_ecb2_encrypt()
2860 that only takes 2 des_key_schedules that implements,
2861 C=E(ks1,D(ks2,E(ks1,M))) in that the final encrypt is done with ks1.
2862
2863void des_cbc_encrypt(
2864des_cblock *input,
2865des_cblock *output,
2866long length,
2867des_key_schedule ks,
2868des_cblock *ivec,
2869int enc);
2870 This routine implements DES in Cipher Block Chaining mode.
2871 Input, which should be a multiple of 8 bytes is encrypted
2872 (or decrypted) to output which will also be a multiple of 8 bytes.
2873 The number of bytes is in length (and from what I've said above,
2874 should be a multiple of 8). If length is not a multiple of 8, I'm
2875 not being held responsible :-). ivec is the initialisation vector.
2876 This function does not modify this variable. To correctly implement
2877 cbc mode, you need to do one of 2 things; copy the last 8 bytes of
2878 cipher text for use as the next ivec in your application,
2879 or use des_ncbc_encrypt().
2880 Only this routine has this problem with updating the ivec, all
2881 other routines that are implementing cbc mode update ivec.
2882
2883void des_ncbc_encrypt(
2884des_cblock *input,
2885des_cblock *output,
2886long length,
2887des_key_schedule sk,
2888des_cblock *ivec,
2889int enc);
2890 For historical reasons, des_cbc_encrypt() did not update the
2891 ivec with the value requires so that subsequent calls to
2892 des_cbc_encrypt() would 'chain'. This was needed so that the same
2893 'length' values would not need to be used when decrypting.
2894 des_ncbc_encrypt() does the right thing. It is the same as
2895 des_cbc_encrypt accept that ivec is updates with the correct value
2896 to pass in subsequent calls to des_ncbc_encrypt(). I advise using
2897 des_ncbc_encrypt() instead of des_cbc_encrypt();
2898
2899void des_xcbc_encrypt(
2900des_cblock *input,
2901des_cblock *output,
2902long length,
2903des_key_schedule sk,
2904des_cblock *ivec,
2905des_cblock *inw,
2906des_cblock *outw,
2907int enc);
2908 This is RSA's DESX mode of DES. It uses inw and outw to
2909 'whiten' the encryption. inw and outw are secret (unlike the iv)
2910 and are as such, part of the key. So the key is sort of 24 bytes.
2911 This is much better than cbc des.
2912
2913void des_3cbc_encrypt(
2914des_cblock *input,
2915des_cblock *output,
2916long length,
2917des_key_schedule sk1,
2918des_key_schedule sk2,
2919des_cblock *ivec1,
2920des_cblock *ivec2,
2921int enc);
2922 This function is flawed, do not use it. I have left it in the
2923 library because it is used in my des(1) program and will function
2924 correctly when used by des(1). If I removed the function, people
2925 could end up unable to decrypt files.
2926 This routine implements outer triple cbc encryption using 2 ks and
2927 2 ivec's. Use des_ede2_cbc_encrypt() instead.
2928
2929void des_ede3_cbc_encrypt(
2930des_cblock *input,
2931des_cblock *output,
2932long length,
2933des_key_schedule ks1,
2934des_key_schedule ks2,
2935des_key_schedule ks3,
2936des_cblock *ivec,
2937int enc);
2938 This function implements outer triple CBC DES encryption with 3
2939 keys. What this means is that each 'DES' operation
2940 inside the cbc mode is really an C=E(ks3,D(ks2,E(ks1,M))).
2941 Again, this is cbc mode so an ivec is requires.
2942 This mode is used by SSL.
2943 There is also a des_ede2_cbc_encrypt() that only uses 2
2944 des_key_schedule's, the first being reused for the final
2945 encryption. C=E(ks1,D(ks2,E(ks1,M))). This form of triple DES
2946 is used by the RSAref library.
2947
2948void des_pcbc_encrypt(
2949des_cblock *input,
2950des_cblock *output,
2951long length,
2952des_key_schedule ks,
2953des_cblock *ivec,
2954int enc);
2955 This is Propagating Cipher Block Chaining mode of DES. It is used
2956 by Kerberos v4. It's parameters are the same as des_ncbc_encrypt().
2957
2958void des_cfb_encrypt(
2959unsigned char *in,
2960unsigned char *out,
2961int numbits,
2962long length,
2963des_key_schedule ks,
2964des_cblock *ivec,
2965int enc);
2966 Cipher Feedback Back mode of DES. This implementation 'feeds back'
2967 in numbit blocks. The input (and output) is in multiples of numbits
2968 bits. numbits should to be a multiple of 8 bits. Length is the
2969 number of bytes input. If numbits is not a multiple of 8 bits,
2970 the extra bits in the bytes will be considered padding. So if
2971 numbits is 12, for each 2 input bytes, the 4 high bits of the
2972 second byte will be ignored. So to encode 72 bits when using
2973 a numbits of 12 take 12 bytes. To encode 72 bits when using
2974 numbits of 9 will take 16 bytes. To encode 80 bits when using
2975 numbits of 16 will take 10 bytes. etc, etc. This padding will
2976 apply to both input and output.
2977
2978
2979void des_cfb64_encrypt(
2980unsigned char *in,
2981unsigned char *out,
2982long length,
2983des_key_schedule ks,
2984des_cblock *ivec,
2985int *num,
2986int enc);
2987 This is one of the more useful functions in this DES library, it
2988 implements CFB mode of DES with 64bit feedback. Why is this
2989 useful you ask? Because this routine will allow you to encrypt an
2990 arbitrary number of bytes, no 8 byte padding. Each call to this
2991 routine will encrypt the input bytes to output and then update ivec
2992 and num. num contains 'how far' we are though ivec. If this does
2993 not make much sense, read more about cfb mode of DES :-).
2994
2995void des_ede3_cfb64_encrypt(
2996unsigned char *in,
2997unsigned char *out,
2998long length,
2999des_key_schedule ks1,
3000des_key_schedule ks2,
3001des_key_schedule ks3,
3002des_cblock *ivec,
3003int *num,
3004int enc);
3005 Same as des_cfb64_encrypt() accept that the DES operation is
3006 triple DES. As usual, there is a macro for
3007 des_ede2_cfb64_encrypt() which reuses ks1.
3008
3009void des_ofb_encrypt(
3010unsigned char *in,
3011unsigned char *out,
3012int numbits,
3013long length,
3014des_key_schedule ks,
3015des_cblock *ivec);
3016 This is a implementation of Output Feed Back mode of DES. It is
3017 the same as des_cfb_encrypt() in that numbits is the size of the
3018 units dealt with during input and output (in bits).
3019
3020void des_ofb64_encrypt(
3021unsigned char *in,
3022unsigned char *out,
3023long length,
3024des_key_schedule ks,
3025des_cblock *ivec,
3026int *num);
3027 The same as des_cfb64_encrypt() except that it is Output Feed Back
3028 mode.
3029
3030void des_ede3_ofb64_encrypt(
3031unsigned char *in,
3032unsigned char *out,
3033long length,
3034des_key_schedule ks1,
3035des_key_schedule ks2,
3036des_key_schedule ks3,
3037des_cblock *ivec,
3038int *num);
3039 Same as des_ofb64_encrypt() accept that the DES operation is
3040 triple DES. As usual, there is a macro for
3041 des_ede2_ofb64_encrypt() which reuses ks1.
3042
3043int des_read_pw_string(
3044char *buf,
3045int length,
3046char *prompt,
3047int verify);
3048 This routine is used to get a password from the terminal with echo
3049 turned off. Buf is where the string will end up and length is the
3050 size of buf. Prompt is a string presented to the 'user' and if
3051 verify is set, the key is asked for twice and unless the 2 copies
3052 match, an error is returned. A return code of -1 indicates a
3053 system error, 1 failure due to use interaction, and 0 is success.
3054
3055unsigned long des_cbc_cksum(
3056des_cblock *input,
3057des_cblock *output,
3058long length,
3059des_key_schedule ks,
3060des_cblock *ivec);
3061 This function produces an 8 byte checksum from input that it puts in
3062 output and returns the last 4 bytes as a long. The checksum is
3063 generated via cbc mode of DES in which only the last 8 byes are
3064 kept. I would recommend not using this function but instead using
3065 the EVP_Digest routines, or at least using MD5 or SHA. This
3066 function is used by Kerberos v4 so that is why it stays in the
3067 library.
3068
3069char *des_fcrypt(
3070const char *buf,
3071const char *salt
3072char *ret);
3073 This is my fast version of the unix crypt(3) function. This version
3074 takes only a small amount of space relative to other fast
3075 crypt() implementations. This is different to the normal crypt
3076 in that the third parameter is the buffer that the return value
3077 is written into. It needs to be at least 14 bytes long. This
3078 function is thread safe, unlike the normal crypt.
3079
3080char *crypt(
3081const char *buf,
3082const char *salt);
3083 This function calls des_fcrypt() with a static array passed as the
3084 third parameter. This emulates the normal non-thread safe semantics
3085 of crypt(3).
3086
3087void des_string_to_key(
3088char *str,
3089des_cblock *key);
3090 This function takes str and converts it into a DES key. I would
3091 recommend using MD5 instead and use the first 8 bytes of output.
3092 When I wrote the first version of these routines back in 1990, MD5
3093 did not exist but I feel these routines are still sound. This
3094 routines is compatible with the one in MIT's libdes.
3095
3096void des_string_to_2keys(
3097char *str,
3098des_cblock *key1,
3099des_cblock *key2);
3100 This function takes str and converts it into 2 DES keys.
3101 I would recommend using MD5 and using the 16 bytes as the 2 keys.
3102 I have nothing against these 2 'string_to_key' routines, it's just
3103 that if you say that your encryption key is generated by using the
3104 16 bytes of an MD5 hash, every-one knows how you generated your
3105 keys.
3106
3107int des_read_password(
3108des_cblock *key,
3109char *prompt,
3110int verify);
3111 This routine combines des_read_pw_string() with des_string_to_key().
3112
3113int des_read_2passwords(
3114des_cblock *key1,
3115des_cblock *key2,
3116char *prompt,
3117int verify);
3118 This routine combines des_read_pw_string() with des_string_to_2key().
3119
3120void des_random_seed(
3121des_cblock key);
3122 This routine sets a starting point for des_random_key().
3123
3124void des_random_key(
3125des_cblock ret);
3126 This function return a random key. Make sure to 'seed' the random
3127 number generator (with des_random_seed()) before using this function.
3128 I personally now use a MD5 based random number system.
3129
3130int des_enc_read(
3131int fd,
3132char *buf,
3133int len,
3134des_key_schedule ks,
3135des_cblock *iv);
3136 This function will write to a file descriptor the encrypted data
3137 from buf. This data will be preceded by a 4 byte 'byte count' and
3138 will be padded out to 8 bytes. The encryption is either CBC of
3139 PCBC depending on the value of des_rw_mode. If it is DES_PCBC_MODE,
3140 pcbc is used, if DES_CBC_MODE, cbc is used. The default is to use
3141 DES_PCBC_MODE.
3142
3143int des_enc_write(
3144int fd,
3145char *buf,
3146int len,
3147des_key_schedule ks,
3148des_cblock *iv);
3149 This routines read stuff written by des_enc_read() and decrypts it.
3150 I have used these routines quite a lot but I don't believe they are
3151 suitable for non-blocking io. If you are after a full
3152 authentication/encryption over networks, have a look at SSL instead.
3153
3154unsigned long des_quad_cksum(
3155des_cblock *input,
3156des_cblock *output,
3157long length,
3158int out_count,
3159des_cblock *seed);
3160 This is a function from Kerberos v4 that is not anything to do with
3161 DES but was needed. It is a cksum that is quicker to generate than
3162 des_cbc_cksum(); I personally would use MD5 routines now.
3163=====
3164Modes of DES
3165Quite a bit of the following information has been taken from
3166 AS 2805.5.2
3167 Australian Standard
3168 Electronic funds transfer - Requirements for interfaces,
3169 Part 5.2: Modes of operation for an n-bit block cipher algorithm
3170 Appendix A
3171
3172There are several different modes in which DES can be used, they are
3173as follows.
3174
3175Electronic Codebook Mode (ECB) (des_ecb_encrypt())
3176- 64 bits are enciphered at a time.
3177- The order of the blocks can be rearranged without detection.
3178- The same plaintext block always produces the same ciphertext block
3179 (for the same key) making it vulnerable to a 'dictionary attack'.
3180- An error will only affect one ciphertext block.
3181
3182Cipher Block Chaining Mode (CBC) (des_cbc_encrypt())
3183- a multiple of 64 bits are enciphered at a time.
3184- The CBC mode produces the same ciphertext whenever the same
3185 plaintext is encrypted using the same key and starting variable.
3186- The chaining operation makes the ciphertext blocks dependent on the
3187 current and all preceding plaintext blocks and therefore blocks can not
3188 be rearranged.
3189- The use of different starting variables prevents the same plaintext
3190 enciphering to the same ciphertext.
3191- An error will affect the current and the following ciphertext blocks.
3192
3193Cipher Feedback Mode (CFB) (des_cfb_encrypt())
3194- a number of bits (j) <= 64 are enciphered at a time.
3195- The CFB mode produces the same ciphertext whenever the same
3196 plaintext is encrypted using the same key and starting variable.
3197- The chaining operation makes the ciphertext variables dependent on the
3198 current and all preceding variables and therefore j-bit variables are
3199 chained together and can not be rearranged.
3200- The use of different starting variables prevents the same plaintext
3201 enciphering to the same ciphertext.
3202- The strength of the CFB mode depends on the size of k (maximal if
3203 j == k). In my implementation this is always the case.
3204- Selection of a small value for j will require more cycles through
3205 the encipherment algorithm per unit of plaintext and thus cause
3206 greater processing overheads.
3207- Only multiples of j bits can be enciphered.
3208- An error will affect the current and the following ciphertext variables.
3209
3210Output Feedback Mode (OFB) (des_ofb_encrypt())
3211- a number of bits (j) <= 64 are enciphered at a time.
3212- The OFB mode produces the same ciphertext whenever the same
3213 plaintext enciphered using the same key and starting variable. More
3214 over, in the OFB mode the same key stream is produced when the same
3215 key and start variable are used. Consequently, for security reasons
3216 a specific start variable should be used only once for a given key.
3217- The absence of chaining makes the OFB more vulnerable to specific attacks.
3218- The use of different start variables values prevents the same
3219 plaintext enciphering to the same ciphertext, by producing different
3220 key streams.
3221- Selection of a small value for j will require more cycles through
3222 the encipherment algorithm per unit of plaintext and thus cause
3223 greater processing overheads.
3224- Only multiples of j bits can be enciphered.
3225- OFB mode of operation does not extend ciphertext errors in the
3226 resultant plaintext output. Every bit error in the ciphertext causes
3227 only one bit to be in error in the deciphered plaintext.
3228- OFB mode is not self-synchronising. If the two operation of
3229 encipherment and decipherment get out of synchronism, the system needs
3230 to be re-initialised.
3231- Each re-initialisation should use a value of the start variable
3232 different from the start variable values used before with the same
3233 key. The reason for this is that an identical bit stream would be
3234 produced each time from the same parameters. This would be
3235 susceptible to a ' known plaintext' attack.
3236
3237Triple ECB Mode (des_ecb3_encrypt())
3238- Encrypt with key1, decrypt with key2 and encrypt with key3 again.
3239- As for ECB encryption but increases the key length to 168 bits.
3240 There are theoretic attacks that can be used that make the effective
3241 key length 112 bits, but this attack also requires 2^56 blocks of
3242 memory, not very likely, even for the NSA.
3243- If both keys are the same it is equivalent to encrypting once with
3244 just one key.
3245- If the first and last key are the same, the key length is 112 bits.
3246 There are attacks that could reduce the key space to 55 bit's but it
3247 requires 2^56 blocks of memory.
3248- If all 3 keys are the same, this is effectively the same as normal
3249 ecb mode.
3250
3251Triple CBC Mode (des_ede3_cbc_encrypt())
3252- Encrypt with key1, decrypt with key2 and then encrypt with key3.
3253- As for CBC encryption but increases the key length to 168 bits with
3254 the same restrictions as for triple ecb mode.
3255
3256==== digest.doc ========================================================
3257
3258
3259The Message Digest subroutines.
3260
3261These routines require "evp.h" to be included.
3262
3263These functions are a higher level interface to the various message digest
3264routines found in this library. As such, they allow the same code to be
3265used to digest via different algorithms with only a change in an initial
3266parameter. They are basically just a front-end to the MD2, MD5, SHA
3267and SHA1
3268routines.
3269
3270These routines all take a pointer to the following structure to specify
3271which message digest algorithm to use.
3272typedef struct evp_md_st
3273 {
3274 int type;
3275 int pkey_type;
3276 int md_size;
3277 void (*init)();
3278 void (*update)();
3279 void (*final)();
3280
3281 int required_pkey_type; /*EVP_PKEY_xxx */
3282 int (*sign)();
3283 int (*verify)();
3284 } EVP_MD;
3285
3286If additional message digest algorithms are to be supported, a structure of
3287this type needs to be declared and populated and then the Digest routines
3288can be used with that algorithm. The type field is the object NID of the
3289digest type (read the section on Objects for an explanation). The pkey_type
3290is the Object type to use when the a message digest is generated by there
3291routines and then is to be signed with the pkey algorithm. Md_size is
3292the size of the message digest returned. Init, update
3293and final are the relevant functions to perform the message digest function
3294by parts. One reason for specifying the message digest to use via this
3295mechanism is that if you only use md5, only the md5 routines will
3296be included in you linked program. If you passed an integer
3297that specified which message digest to use, the routine that mapped that
3298integer to a set of message digest functions would cause all the message
3299digests functions to be link into the code. This setup also allows new
3300message digest functions to be added by the application.
3301
3302The six message digests defined in this library are
3303
3304EVP_MD *EVP_md2(void); /* RSA sign/verify */
3305EVP_MD *EVP_md5(void); /* RSA sign/verify */
3306EVP_MD *EVP_sha(void); /* RSA sign/verify */
3307EVP_MD *EVP_sha1(void); /* RSA sign/verify */
3308EVP_MD *EVP_dss(void); /* DSA sign/verify */
3309EVP_MD *EVP_dss1(void); /* DSA sign/verify */
3310
3311All the message digest routines take a EVP_MD_CTX pointer as an argument.
3312The state of the message digest is kept in this structure.
3313
3314typedef struct pem_md_ctx_st
3315 {
3316 EVP_MD *digest;
3317 union {
3318 unsigned char base[4]; /* this is used in my library as a
3319 * 'pointer' to all union elements
3320 * structures. */
3321 MD2_CTX md2;
3322 MD5_CTX md5;
3323 SHA_CTX sha;
3324 } md;
3325 } EVP_MD_CTX;
3326
3327The Digest functions are as follows.
3328
3329void EVP_DigestInit(
3330EVP_MD_CTX *ctx,
3331EVP_MD *type);
3332 This function is used to initialise the EVP_MD_CTX. The message
3333 digest that will associated with 'ctx' is specified by 'type'.
3334
3335void EVP_DigestUpdate(
3336EVP_MD_CTX *ctx,
3337unsigned char *data,
3338unsigned int cnt);
3339 This function is used to pass more data to the message digest
3340 function. 'cnt' bytes are digested from 'data'.
3341
3342void EVP_DigestFinal(
3343EVP_MD_CTX *ctx,
3344unsigned char *md,
3345unsigned int *len);
3346 This function finishes the digestion and puts the message digest
3347 into 'md'. The length of the message digest is put into len;
3348 EVP_MAX_MD_SIZE is the size of the largest message digest that
3349 can be returned from this function. Len can be NULL if the
3350 size of the digest is not required.
3351
3352
3353==== encode.doc ========================================================
3354
3355
3356void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
3357void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
3358 int *outl,unsigned char *in,int inl);
3359void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
3360int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n);
3361
3362void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
3363int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
3364 unsigned char *in, int inl);
3365int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
3366 char *out, int *outl);
3367int EVP_DecodeBlock(unsigned char *t, unsigned
3368 char *f, int n);
3369
3370
3371==== envelope.doc ========================================================
3372
3373The following routines are use to create 'digital' envelopes.
3374By this I mean that they perform various 'higher' level cryptographic
3375functions. Have a read of 'cipher.doc' and 'digest.doc' since those
3376routines are used by these functions.
3377cipher.doc contains documentation about the cipher part of the
3378envelope library and digest.doc contatins the description of the
3379message digests supported.
3380
3381To 'sign' a document involves generating a message digest and then encrypting
3382the digest with an private key.
3383
3384#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
3385#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
3386Due to the fact this operation is basically just an extended message
3387digest, the first 2 functions are macro calls to Digest generating
3388functions.
3389
3390int EVP_SignFinal(
3391EVP_MD_CTX *ctx,
3392unsigned char *md,
3393unsigned int *s,
3394EVP_PKEY *pkey);
3395 This finalisation function finishes the generation of the message
3396digest and then encrypts the digest (with the correct message digest
3397object identifier) with the EVP_PKEY private key. 'ctx' is the message digest
3398context. 'md' will end up containing the encrypted message digest. This
3399array needs to be EVP_PKEY_size(pkey) bytes long. 's' will actually
3400contain the exact length. 'pkey' of course is the private key. It is
3401one of EVP_PKEY_RSA or EVP_PKEY_DSA type.
3402If there is an error, 0 is returned, otherwise 1.
3403
3404Verify is used to check an signed message digest.
3405
3406#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
3407#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
3408Since the first step is to generate a message digest, the first 2 functions
3409are macros.
3410
3411int EVP_VerifyFinal(
3412EVP_MD_CTX *ctx,
3413unsigned char *md,
3414unsigned int s,
3415EVP_PKEY *pkey);
3416 This function finishes the generation of the message digest and then
3417compares it with the supplied encrypted message digest. 'md' contains the
3418's' bytes of encrypted message digest. 'pkey' is used to public key decrypt
3419the digest. It is then compared with the message digest just generated.
3420If they match, 1 is returned else 0.
3421
3422int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
3423 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
3424Must have at least one public key, error is 0. I should also mention that
3425the buffers pointed to by 'ek' need to be EVP_PKEY_size(pubk[n]) is size.
3426
3427#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
3428void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
3429
3430
3431int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
3432 int ekl,unsigned char *iv,EVP_PKEY *priv);
34330 on failure
3434
3435#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
3436
3437int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
3438Decrypt final return code
3439
3440
3441==== error.doc ========================================================
3442
3443The error routines.
3444
3445The 'error' system I've implemented is intended to server 2 purpose, to
3446record the reason why a command failed and to record where in the libraries
3447the failure occurred. It is more or less setup to record a 'trace' of which
3448library components were being traversed when the error occurred.
3449
3450When an error is recorded, it is done so a as single unsigned long which is
3451composed of three parts. The top byte is the 'library' number, the middle
345212 bytes is the function code, and the bottom 12 bits is the 'reason' code.
3453
3454Each 'library', or should a say, 'section' of the SSLeay library has a
3455different unique 'library' error number. Each function in the library has
3456a number that is unique for that library. Each 'library' also has a number
3457for each 'error reason' that is only unique for that 'library'.
3458
3459Due to the way these error routines record a 'error trace', there is an
3460array per thread that is used to store the error codes.
3461The various functions in this library are used to access
3462and manipulate this array.
3463
3464void ERR_put_error(int lib, int func,int reason);
3465 This routine records an error in library 'lib', function 'func'
3466and reason 'reason'. As errors get 'put' into the buffer, they wrap
3467around and overwrite old errors if too many are written. It is assumed
3468that the last errors are the most important.
3469
3470unsigned long ERR_get_error(void );
3471 This function returns the last error added to the error buffer.
3472In effect it is popping the value off the buffer so repeated calls will
3473continue to return values until there are no more errors to return in which
3474case 0 is returned.
3475
3476unsigned long ERR_peek_error(void );
3477 This function returns the value of the last error added to the
3478error buffer but does not 'pop' it from the buffer.
3479
3480void ERR_clear_error(void );
3481 This function clears the error buffer, discarding all unread
3482errors.
3483
3484While the above described error system obviously produces lots of different
3485error number, a method for 'reporting' these errors in a human readable
3486form is required. To achieve this, each library has the option of
3487'registering' error strings.
3488
3489typedef struct ERR_string_data_st
3490 {
3491 unsigned long error;
3492 char *string;
3493 } ERR_STRING_DATA;
3494
3495The 'ERR_STRING_DATA' contains an error code and the corresponding text
3496string. To add new function error strings for a library, the
3497ERR_STRING_DATA needs to be 'registered' with the library.
3498
3499void ERR_load_strings(unsigned long lib,ERR_STRING_DATA *err);
3500 This function 'registers' the array of ERR_STRING_DATA pointed to by
3501'err' as error text strings for the error library 'lib'.
3502
3503void ERR_free_strings(void);
3504 This function free()s all the loaded error strings.
3505
3506char *ERR_error_string(unsigned long error,char *buf);
3507 This function returns a text string that is a human readable
3508version of the error represented by 'error'. Buff should be at least 120
3509bytes long and if it is NULL, the return value is a pointer to a static
3510variable that will contain the error string, otherwise 'buf' is returned.
3511If there is not a text string registered for a particular error, a text
3512string containing the error number is returned instead.
3513
3514void ERR_print_errors(BIO *bp);
3515void ERR_print_errors_fp(FILE *fp);
3516 This function is a convenience routine that prints the error string
3517for each error until all errors have been accounted for.
3518
3519char *ERR_lib_error_string(unsigned long e);
3520char *ERR_func_error_string(unsigned long e);
3521char *ERR_reason_error_string(unsigned long e);
3522The above three functions return the 3 different components strings for the
3523error 'e'. ERR_error_string() uses these functions.
3524
3525void ERR_load_ERR_strings(void );
3526 This function 'registers' the error strings for the 'ERR' module.
3527
3528void ERR_load_crypto_strings(void );
3529 This function 'register' the error strings for just about every
3530library in the SSLeay package except for the SSL routines. There is no
3531need to ever register any error text strings and you will probably save in
3532program size. If on the other hand you do 'register' all errors, it is
3533quite easy to determine why a particular routine failed.
3534
3535As a final footnote as to why the error system is designed as it is.
35361) I did not want a single 'global' error code.
35372) I wanted to know which subroutine a failure occurred in.
35383) For Windows NT etc, it should be simple to replace the 'key' routines
3539 with code to pass error codes back to the application.
35404) I wanted the option of meaningful error text strings.
3541
3542Late breaking news - the changes to support threads.
3543
3544Each 'thread' has an 'ERR_STATE' state associated with it.
3545ERR_STATE *ERR_get_state(void ) will return the 'state' for the calling
3546thread/process.
3547
3548ERR_remove_state(unsigned long pid); will 'free()' this state. If pid == 0
3549the current 'thread/process' will have it's error state removed.
3550If you do not remove the error state of a thread, this could be considered a
3551form of memory leak, so just after 'reaping' a thread that has died,
3552call ERR_remove_state(pid).
3553
3554Have a read of thread.doc for more details for what is required for
3555multi-threading support. All the other error routines will
3556work correctly when using threads.
3557
3558
3559==== idea.doc ========================================================
3560
3561The IDEA library.
3562IDEA is a block cipher that operates on 64bit (8 byte) quantities. It
3563uses a 128bit (16 byte) key. It can be used in all the modes that DES can
3564be used. This library implements the ecb, cbc, cfb64 and ofb64 modes.
3565
3566For all calls that have an 'input' and 'output' variables, they can be the
3567same.
3568
3569This library requires the inclusion of 'idea.h'.
3570
3571All of the encryption functions take what is called an IDEA_KEY_SCHEDULE as an
3572argument. An IDEA_KEY_SCHEDULE is an expanded form of the idea key.
3573For all modes of the IDEA algorithm, the IDEA_KEY_SCHEDULE used for
3574decryption is different to the one used for encryption.
3575
3576The define IDEA_ENCRYPT is passed to specify encryption for the functions
3577that require an encryption/decryption flag. IDEA_DECRYPT is passed to
3578specify decryption. For some mode there is no encryption/decryption
3579flag since this is determined by the IDEA_KEY_SCHEDULE.
3580
3581So to encrypt you would do the following
3582idea_set_encrypt_key(key,encrypt_ks);
3583idea_ecb_encrypt(...,encrypt_ks);
3584idea_cbc_encrypt(....,encrypt_ks,...,IDEA_ENCRYPT);
3585
3586To Decrypt
3587idea_set_encrypt_key(key,encrypt_ks);
3588idea_set_decrypt_key(encrypt_ks,decrypt_ks);
3589idea_ecb_encrypt(...,decrypt_ks);
3590idea_cbc_encrypt(....,decrypt_ks,...,IDEA_DECRYPT);
3591
3592Please note that any of the encryption modes specified in my DES library
3593could be used with IDEA. I have only implemented ecb, cbc, cfb64 and
3594ofb64 for the following reasons.
3595- ecb is the basic IDEA encryption.
3596- cbc is the normal 'chaining' form for block ciphers.
3597- cfb64 can be used to encrypt single characters, therefore input and output
3598 do not need to be a multiple of 8.
3599- ofb64 is similar to cfb64 but is more like a stream cipher, not as
3600 secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
3601- If you want triple IDEA, thats 384 bits of key and you must be totally
3602 obsessed with security. Still, if you want it, it is simple enough to
3603 copy the function from the DES library and change the des_encrypt to
3604 idea_encrypt; an exercise left for the paranoid reader :-).
3605
3606The functions are as follows:
3607
3608void idea_set_encrypt_key(
3609unsigned char *key;
3610IDEA_KEY_SCHEDULE *ks);
3611 idea_set_encrypt_key converts a 16 byte IDEA key into an
3612 IDEA_KEY_SCHEDULE. The IDEA_KEY_SCHEDULE is an expanded form of
3613 the key which can be used to perform IDEA encryption.
3614 An IDEA_KEY_SCHEDULE is an expanded form of the key which is used to
3615 perform actual encryption. It can be regenerated from the IDEA key
3616 so it only needs to be kept when encryption is about
3617 to occur. Don't save or pass around IDEA_KEY_SCHEDULE's since they
3618 are CPU architecture dependent, IDEA keys are not.
3619
3620void idea_set_decrypt_key(
3621IDEA_KEY_SCHEDULE *encrypt_ks,
3622IDEA_KEY_SCHEDULE *decrypt_ks);
3623 This functions converts an encryption IDEA_KEY_SCHEDULE into a
3624 decryption IDEA_KEY_SCHEDULE. For all decryption, this conversion
3625 of the key must be done. In some modes of IDEA, an
3626 encryption/decryption flag is also required, this is because these
3627 functions involve block chaining and the way this is done changes
3628 depending on which of encryption of decryption is being done.
3629 Please note that there is no quick way to generate the decryption
3630 key schedule other than generating the encryption key schedule and
3631 then converting it.
3632
3633void idea_encrypt(
3634unsigned long *data,
3635IDEA_KEY_SCHEDULE *ks);
3636 This is the IDEA encryption function that gets called by just about
3637 every other IDEA routine in the library. You should not use this
3638 function except to implement 'modes' of IDEA. I say this because the
3639 functions that call this routine do the conversion from 'char *' to
3640 long, and this needs to be done to make sure 'non-aligned' memory
3641 access do not occur.
3642 Data is a pointer to 2 unsigned long's and ks is the
3643 IDEA_KEY_SCHEDULE to use. Encryption or decryption depends on the
3644 IDEA_KEY_SCHEDULE.
3645
3646void idea_ecb_encrypt(
3647unsigned char *input,
3648unsigned char *output,
3649IDEA_KEY_SCHEDULE *ks);
3650 This is the basic Electronic Code Book form of IDEA (in DES this
3651 mode is called Electronic Code Book so I'm going to use the term
3652 for idea as well :-).
3653 Input is encrypted into output using the key represented by
3654 ks. Depending on the IDEA_KEY_SCHEDULE, encryption or
3655 decryption occurs. Input is 8 bytes long and output is 8 bytes.
3656
3657void idea_cbc_encrypt(
3658unsigned char *input,
3659unsigned char *output,
3660long length,
3661IDEA_KEY_SCHEDULE *ks,
3662unsigned char *ivec,
3663int enc);
3664 This routine implements IDEA in Cipher Block Chaining mode.
3665 Input, which should be a multiple of 8 bytes is encrypted
3666 (or decrypted) to output which will also be a multiple of 8 bytes.
3667 The number of bytes is in length (and from what I've said above,
3668 should be a multiple of 8). If length is not a multiple of 8, bad
3669 things will probably happen. ivec is the initialisation vector.
3670 This function updates iv after each call so that it can be passed to
3671 the next call to idea_cbc_encrypt().
3672
3673void idea_cfb64_encrypt(
3674unsigned char *in,
3675unsigned char *out,
3676long length,
3677des_key_schedule ks,
3678des_cblock *ivec,
3679int *num,
3680int enc);
3681 This is one of the more useful functions in this IDEA library, it
3682 implements CFB mode of IDEA with 64bit feedback.
3683 This allows you to encrypt an arbitrary number of bytes,
3684 you do not require 8 byte padding. Each call to this
3685 routine will encrypt the input bytes to output and then update ivec
3686 and num. Num contains 'how far' we are though ivec.
3687 Enc is used to indicate encryption or decryption.
3688 One very important thing to remember is that when decrypting, use
3689 the encryption form of the key.
3690 CFB64 mode operates by using the cipher to
3691 generate a stream of bytes which is used to encrypt the plain text.
3692 The cipher text is then encrypted to generate the next 64 bits to
3693 be xored (incrementally) with the next 64 bits of plain
3694 text. As can be seen from this, to encrypt or decrypt,
3695 the same 'cipher stream' needs to be generated but the way the next
3696 block of data is gathered for encryption is different for
3697 encryption and decryption. What this means is that to encrypt
3698 idea_set_encrypt_key(key,ks);
3699 idea_cfb64_encrypt(...,ks,..,IDEA_ENCRYPT)
3700 do decrypt
3701 idea_set_encrypt_key(key,ks)
3702 idea_cfb64_encrypt(...,ks,...,IDEA_DECRYPT)
3703 Note: The same IDEA_KEY_SCHEDULE but different encryption flags.
3704 For idea_cbc or idea_ecb, idea_set_decrypt_key() would need to be
3705 used to generate the IDEA_KEY_SCHEDULE for decryption.
3706 The reason I'm stressing this point is that I just wasted 3 hours
3707 today trying to decrypt using this mode and the decryption form of
3708 the key :-(.
3709
3710void idea_ofb64_encrypt(
3711unsigned char *in,
3712unsigned char *out,
3713long length,
3714des_key_schedule ks,
3715des_cblock *ivec,
3716int *num);
3717 This functions implements OFB mode of IDEA with 64bit feedback.
3718 This allows you to encrypt an arbitrary number of bytes,
3719 you do not require 8 byte padding. Each call to this
3720 routine will encrypt the input bytes to output and then update ivec
3721 and num. Num contains 'how far' we are though ivec.
3722 This is in effect a stream cipher, there is no encryption or
3723 decryption mode. The same key and iv should be used to
3724 encrypt and decrypt.
3725
3726For reading passwords, I suggest using des_read_pw_string() from my DES library.
3727To generate a password from a text string, I suggest using MD5 (or MD2) to
3728produce a 16 byte message digest that can then be passed directly to
3729idea_set_encrypt_key().
3730
3731=====
3732For more information about the specific IDEA modes in this library
3733(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
3734documentation on my DES library. What is said about DES is directly
3735applicable for IDEA.
3736
3737
3738==== legal.doc ========================================================
3739
3740From eay@mincom.com Thu Jun 27 00:25:45 1996
3741Received: by orb.mincom.oz.au id AA15821
3742 (5.65c/IDA-1.4.4 for eay); Wed, 26 Jun 1996 14:25:45 +1000
3743Date: Wed, 26 Jun 1996 14:25:45 +1000 (EST)
3744From: Eric Young <eay@mincom.oz.au>
3745X-Sender: eay@orb
3746To: Ken Toll <ktoll@ren.digitalage.com>
3747Cc: Eric Young <eay@mincom.oz.au>, ssl-talk@netscape.com
3748Subject: Re: Unidentified subject!
3749In-Reply-To: <9606261950.ZM28943@ren.digitalage.com>
3750Message-Id: <Pine.SOL.3.91.960626131156.28573K-100000@orb>
3751Mime-Version: 1.0
3752Content-Type: TEXT/PLAIN; charset=US-ASCII
3753Status: O
3754X-Status:
3755
3756
3757This is a little off topic but since SSLeay is a free implementation of
3758the SSLv2 protocol, I feel it is worth responding on the topic of if it
3759is actually legal for Americans to use free cryptographic software.
3760
3761On Wed, 26 Jun 1996, Ken Toll wrote:
3762> Is the U.S the only country that SSLeay cannot be used commercially
3763> (because of RSAref) or is that going to be an issue with every country
3764> that a client/server application (non-web browser/server) is deployed
3765> and sold?
3766
3767>From what I understand, the software patents that apply to algorithms
3768like RSA and DH only apply in the USA. The IDEA algorithm I believe is
3769patened in europe (USA?), but considing how little it is used by other SSL
3770implementations, it quite easily be left out of the SSLeay build
3771(this can be done with a compile flag).
3772
3773Actually if the RSA patent did apply outside the USA, it could be rather
3774interesting since RSA is not alowed to let RSA toolkits outside of the USA
3775[1], and since these are the only forms that they will alow the algorithm
3776to be used in, it would mean that non-one outside of the USA could produce
3777public key software which would be a very strong statment for
3778international patent law to make :-). This logic is a little flawed but
3779it still points out some of the more interesting permutations of USA
3780patent law and ITAR restrictions.
3781
3782Inside the USA there is also the unresolved issue of RC4/RC2 which were
3783made public on sci.crypt in Sep 1994 (RC4) and Feb 1996 (RC2). I have
3784copies of the origional postings if people are interested. RSA I believe
3785claim that they were 'trade-secrets' and that some-one broke an NDA in
3786revealing them. Other claim they reverse engineered the algorithms from
3787compiled binaries. If the algorithms were reverse engineered, I belive
3788RSA had no legal leg to stand on. If an NDA was broken, I don't know.
3789Regardless, RSA, I belive, is willing to go to court over the issue so
3790licencing is probably the best idea, or at least talk to them.
3791If there are people who actually know more about this, pease let me know, I
3792don't want to vilify or spread miss-information if I can help it.
3793
3794If you are not producing a web browser, it is easy to build SSLeay with
3795RC2/RC4 removed. Since RC4 is the defacto standard cipher in
3796all web software (and it is damn fast) it is more or less required for
3797www use. For non www use of SSL, especially for an application where
3798interoperability with other vendors is not critical just leave it out.
3799
3800Removing IDEA, RC2 and RC4 would only leave DES and Triple DES but
3801they should be ok. Considing that Triple DES can encrypt at rates of
3802410k/sec on a pentium 100, and 940k/sec on a P6/200, this is quite
3803reasonable performance. Single DES clocks in at 1160k/s and 2467k/s
3804respectivly is actually quite fast for those not so paranoid (56 bit key).[1]
3805
3806> Is it possible to get a certificate for commercial use outside of the U.S.?
3807yes.
3808
3809Thawte Consulting issues certificates (they are the people who sell the
3810 Sioux httpd server and are based in South Africa)
3811Verisign will issue certificates for Sioux (sold from South Africa), so this
3812 proves that they will issue certificate for OS use if they are
3813 happy with the quality of the software.
3814
3815(The above mentioned companies just the ones that I know for sure are issuing
3816 certificates outside the USA).
3817
3818There is always the point that if you are using SSL for an intra net,
3819SSLeay provides programs that can be used so you can issue your own
3820certificates. They need polishing but at least it is a good starting point.
3821
3822I am not doing anything outside Australian law by implementing these
3823algorithms (to the best of my knowedge). It is another example of how
3824the world legal system does not cope with the internet very well.
3825
3826I may start making shared libraries available (I have now got DLL's for
3827Windows). This will mean that distributions into the usa could be
3828shipped with a version with a reduced cipher set and the versions outside
3829could use the DLL/shared library with all the ciphers (and without RSAref).
3830
3831This could be completly hidden from the application, so this would not
3832even require a re-linking.
3833
3834This is the reverse of what people were talking about doing to get around
3835USA export regulations :-)
3836
3837eric
3838
3839[1]: The RSAref2.0 tookit is available on at least 3 ftp sites in Europe
3840 and one in South Africa.
3841
3842[2]: Since I always get questions when I post benchmark numbers :-),
3843 DES performace figures are in 1000's of bytes per second in cbc
3844 mode using an 8192 byte buffer. The pentium 100 was running Windows NT
3845 3.51 DLLs and the 686/200 was running NextStep.
3846 I quote pentium 100 benchmarks because it is basically the
3847 'entry level' computer that most people buy for personal use.
3848 Windows 95 is the OS shipping on those boxes, so I'll give
3849 NT numbers (the same Win32 runtime environment). The 686
3850 numbers are present as an indication of where we will be in a
3851 few years.
3852--
3853Eric Young | BOOL is tri-state according to Bill Gates.
3854AARNet: eay@mincom.oz.au | RTFM Win32 GetMessage().
3855
3856
3857
3858==== lhash.doc ========================================================
3859
3860The LHASH library.
3861
3862I wrote this library in 1991 and have since forgotten why I called it lhash.
3863It implements a hash table from an article I read at the
3864time from 'Communications of the ACM'. What makes this hash
3865table different is that as the table fills, the hash table is
3866increased (or decreased) in size via realloc().
3867When a 'resize' is done, instead of all hashes being redistributed over
3868twice as many 'buckets', one bucket is split. So when an 'expand' is done,
3869there is only a minimal cost to redistribute some values. Subsequent
3870inserts will cause more single 'bucket' redistributions but there will
3871never be a sudden large cost due to redistributing all the 'buckets'.
3872
3873The state for a particular hash table is kept in the LHASH structure.
3874The LHASH structure also records statistics about most aspects of accessing
3875the hash table. This is mostly a legacy of my writing this library for
3876the reasons of implementing what looked like a nice algorithm rather than
3877for a particular software product.
3878
3879Internal stuff you probably don't want to know about.
3880The decision to increase or decrease the hash table size is made depending
3881on the 'load' of the hash table. The load is the number of items in the
3882hash table divided by the size of the hash table. The default values are
3883as follows. If (hash->up_load < load) => expand.
3884if (hash->down_load > load) => contract. The 'up_load' has a default value of
38851 and 'down_load' has a default value of 2. These numbers can be modified
3886by the application by just playing with the 'up_load' and 'down_load'
3887variables. The 'load' is kept in a form which is multiplied by 256. So
3888hash->up_load=8*256; will cause a load of 8 to be set.
3889
3890If you are interested in performance the field to watch is
3891num_comp_calls. The hash library keeps track of the 'hash' value for
3892each item so when a lookup is done, the 'hashes' are compared, if
3893there is a match, then a full compare is done, and
3894hash->num_comp_calls is incremented. If num_comp_calls is not equal
3895to num_delete plus num_retrieve it means that your hash function is
3896generating hashes that are the same for different values. It is
3897probably worth changing your hash function if this is the case because
3898even if your hash table has 10 items in a 'bucked', it can be searched
3899with 10 'unsigned long' compares and 10 linked list traverses. This
3900will be much less expensive that 10 calls to you compare function.
3901
3902LHASH *lh_new(
3903unsigned long (*hash)(),
3904int (*cmp)());
3905 This function is used to create a new LHASH structure. It is passed
3906 function pointers that are used to store and retrieve values passed
3907 into the hash table. The 'hash'
3908 function is a hashing function that will return a hashed value of
3909 it's passed structure. 'cmp' is passed 2 parameters, it returns 0
3910 is they are equal, otherwise, non zero.
3911 If there are any problems (usually malloc failures), NULL is
3912 returned, otherwise a new LHASH structure is returned. The
3913 hash value is normally truncated to a power of 2, so make sure
3914 that your hash function returns well mixed low order bits.
3915
3916void lh_free(
3917LHASH *lh);
3918 This function free()s a LHASH structure. If there is malloced
3919 data in the hash table, it will not be freed. Consider using the
3920 lh_doall function to deallocate any remaining entries in the hash
3921 table.
3922
3923char *lh_insert(
3924LHASH *lh,
3925char *data);
3926 This function inserts the data pointed to by data into the lh hash
3927 table. If there is already and entry in the hash table entry, the
3928 value being replaced is returned. A NULL is returned if the new
3929 entry does not clash with an entry already in the table (the normal
3930 case) or on a malloc() failure (perhaps I should change this....).
3931 The 'char *data' is exactly what is passed to the hash and
3932 comparison functions specified in lh_new().
3933
3934char *lh_delete(
3935LHASH *lh,
3936char *data);
3937 This routine deletes an entry from the hash table. The value being
3938 deleted is returned. NULL is returned if there is no such value in
3939 the hash table.
3940
3941char *lh_retrieve(
3942LHASH *lh,
3943char *data);
3944 If 'data' is in the hash table it is returned, else NULL is
3945 returned. The way these routines would normally be uses is that a
3946 dummy structure would have key fields populated and then
3947 ret=lh_retrieve(hash,&dummy);. Ret would now be a pointer to a fully
3948 populated structure.
3949
3950void lh_doall(
3951LHASH *lh,
3952void (*func)(char *a));
3953 This function will, for every entry in the hash table, call function
3954 'func' with the data item as parameters.
3955 This function can be quite useful when used as follows.
3956 void cleanup(STUFF *a)
3957 { STUFF_free(a); }
3958 lh_doall(hash,cleanup);
3959 lh_free(hash);
3960 This can be used to free all the entries, lh_free() then
3961 cleans up the 'buckets' that point to nothing. Be careful
3962 when doing this. If you delete entries from the hash table,
3963 in the call back function, the table may decrease in size,
3964 moving item that you are
3965 currently on down lower in the hash table. This could cause
3966 some entries to be skipped. The best solution to this problem
3967 is to set lh->down_load=0 before you start. This will stop
3968 the hash table ever being decreased in size.
3969
3970void lh_doall_arg(
3971LHASH *lh;
3972void(*func)(char *a,char *arg));
3973char *arg;
3974 This function is the same as lh_doall except that the function
3975 called will be passed 'arg' as the second argument.
3976
3977unsigned long lh_strhash(
3978char *c);
3979 This function is a demo string hashing function. Since the LHASH
3980 routines would normally be passed structures, this routine would
3981 not normally be passed to lh_new(), rather it would be used in the
3982 function passed to lh_new().
3983
3984The next three routines print out various statistics about the state of the
3985passed hash table. These numbers are all kept in the lhash structure.
3986
3987void lh_stats(
3988LHASH *lh,
3989FILE *out);
3990 This function prints out statistics on the size of the hash table,
3991 how many entries are in it, and the number and result of calls to
3992 the routines in this library.
3993
3994void lh_node_stats(
3995LHASH *lh,
3996FILE *out);
3997 For each 'bucket' in the hash table, the number of entries is
3998 printed.
3999
4000void lh_node_usage_stats(
4001LHASH *lh,
4002FILE *out);
4003 This function prints out a short summary of the state of the hash
4004 table. It prints what I call the 'load' and the 'actual load'.
4005 The load is the average number of data items per 'bucket' in the
4006 hash table. The 'actual load' is the average number of items per
4007 'bucket', but only for buckets which contain entries. So the
4008 'actual load' is the average number of searches that will need to
4009 find an item in the hash table, while the 'load' is the average number
4010 that will be done to record a miss.
4011
4012==== md2.doc ========================================================
4013
4014The MD2 library.
4015MD2 is a message digest algorithm that can be used to condense an arbitrary
4016length message down to a 16 byte hash. The functions all need to be passed
4017a MD2_CTX which is used to hold the MD2 context during multiple MD2_Update()
4018function calls. The normal method of use for this library is as follows
4019
4020MD2_Init(...);
4021MD2_Update(...);
4022...
4023MD2_Update(...);
4024MD2_Final(...);
4025
4026This library requires the inclusion of 'md2.h'.
4027
4028The main negative about MD2 is that it is slow, especially when compared
4029to MD5.
4030
4031The functions are as follows:
4032
4033void MD2_Init(
4034MD2_CTX *c);
4035 This function needs to be called to initiate a MD2_CTX structure for
4036 use.
4037
4038void MD2_Update(
4039MD2_CTX *c;
4040unsigned char *data;
4041unsigned long len);
4042 This updates the message digest context being generated with 'len'
4043 bytes from the 'data' pointer. The number of bytes can be any
4044 length.
4045
4046void MD2_Final(
4047unsigned char *md;
4048MD2_CTX *c;
4049 This function is called when a message digest of the data digested
4050 with MD2_Update() is wanted. The message digest is put in the 'md'
4051 array and is MD2_DIGEST_LENGTH (16) bytes long.
4052
4053unsigned char *MD2(
4054unsigned long n;
4055unsigned char *d;
4056unsigned char *md;
4057 This function performs a MD2_Init(), followed by a MD2_Update()
4058 followed by a MD2_Final() (using a local MD2_CTX).
4059 The resulting digest is put into 'md' if it is not NULL.
4060 Regardless of the value of 'md', the message
4061 digest is returned from the function. If 'md' was NULL, the message
4062 digest returned is being stored in a static structure.
4063
4064==== md5.doc ========================================================
4065
4066The MD5 library.
4067MD5 is a message digest algorithm that can be used to condense an arbitrary
4068length message down to a 16 byte hash. The functions all need to be passed
4069a MD5_CTX which is used to hold the MD5 context during multiple MD5_Update()
4070function calls. This library also contains random number routines that are
4071based on MD5
4072
4073The normal method of use for this library is as follows
4074
4075MD5_Init(...);
4076MD5_Update(...);
4077...
4078MD5_Update(...);
4079MD5_Final(...);
4080
4081This library requires the inclusion of 'md5.h'.
4082
4083The functions are as follows:
4084
4085void MD5_Init(
4086MD5_CTX *c);
4087 This function needs to be called to initiate a MD5_CTX structure for
4088 use.
4089
4090void MD5_Update(
4091MD5_CTX *c;
4092unsigned char *data;
4093unsigned long len);
4094 This updates the message digest context being generated with 'len'
4095 bytes from the 'data' pointer. The number of bytes can be any
4096 length.
4097
4098void MD5_Final(
4099unsigned char *md;
4100MD5_CTX *c;
4101 This function is called when a message digest of the data digested
4102 with MD5_Update() is wanted. The message digest is put in the 'md'
4103 array and is MD5_DIGEST_LENGTH (16) bytes long.
4104
4105unsigned char *MD5(
4106unsigned char *d;
4107unsigned long n;
4108unsigned char *md;
4109 This function performs a MD5_Init(), followed by a MD5_Update()
4110 followed by a MD5_Final() (using a local MD5_CTX).
4111 The resulting digest is put into 'md' if it is not NULL.
4112 Regardless of the value of 'md', the message
4113 digest is returned from the function. If 'md' was NULL, the message
4114 digest returned is being stored in a static structure.
4115
4116
4117==== memory.doc ========================================================
4118
4119In the interests of debugging SSLeay, there is an option to compile
4120using some simple memory leak checking.
4121
4122All malloc(), free() and realloc() calls in SSLeay now go via
4123Malloc(), Free() and Realloc() (except those in crypto/lhash).
4124
4125If CRYPTO_MDEBUG is defined, these calls are #defined to
4126CRYPTO_malloc(), CRYPTO_free() and CRYPTO_realloc().
4127If it is not defined, they are #defined to malloc(), free() and realloc().
4128
4129the CRYPTO_malloc() routines by default just call the underlying library
4130functons.
4131
4132If CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) is called, memory leak detection is
4133turned on. CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) turns it off.
4134
4135When turned on, each Malloc() or Realloc() call is recored along with the file
4136and line number from where the call was made. (This is done using the
4137lhash library which always uses normal system malloc(3) routines).
4138
4139void CRYPTO_mem_leaks(BIO *b);
4140void CRYPTO_mem_leaks_fp(FILE *fp);
4141These both print out the list of memory that has not been free()ed.
4142This will probably be rather hard to read, but if you look for the 'top level'
4143structure allocation, this will often give an idea as to what is not being
4144free()ed. I don't expect people to use this stuff normally.
4145
4146==== ca.1 ========================================================
4147
4148From eay@orb.mincom.oz.au Thu Dec 28 23:56:45 1995
4149Received: by orb.mincom.oz.au id AA07374
4150 (5.65c/IDA-1.4.4 for eay); Thu, 28 Dec 1995 13:56:45 +1000
4151Date: Thu, 28 Dec 1995 13:56:45 +1000 (EST)
4152From: Eric Young <eay@mincom.oz.au>
4153X-Sender: eay@orb
4154To: sameer <sameer@c2.org>
4155Cc: ssleay@mincom.oz.au
4156Subject: Re: 'ca'
4157In-Reply-To: <199512230440.UAA23410@infinity.c2.org>
4158Message-Id: <Pine.SOL.3.91.951228133525.7269A-100000@orb>
4159Mime-Version: 1.0
4160Content-Type: TEXT/PLAIN; charset=US-ASCII
4161Status: RO
4162X-Status:
4163
4164On Fri, 22 Dec 1995, sameer wrote:
4165> I could use documentation on 'ca'. Thanks.
4166
4167Very quickly.
4168The ca program uses the ssleay.conf file for most of its configuration
4169
4170./ca -help
4171
4172 -verbose - Talk alot while doing things
4173 -config file - A config file. If you don't want to use the
4174 default config file
4175 -name arg - The particular CA definition to use
4176 In the config file, the section to use for parameters. This lets
4177 multiple setups to be contained in the one file. By default, the
4178 default_ca variable is looked up in the [ ca ] section. So in the
4179 shipped ssleay.conf, the CA definition used is CA_default. It could be
4180 any other name.
4181 -gencrl days - Generate a new CRL, days is when the next CRL is due
4182 This will generate a new certificate revocion list.
4183 -days arg - number of days to certify the certificate for
4184 When certifiying certificates, this is the number of days to use.
4185 -md arg - md to use, one of md2, md5, sha or sha1
4186 -policy arg - The CA 'policy' to support
4187 I'll describe this later, but there are 2 policies definied in the
4188 shipped ssleay.conf
4189 -keyfile arg - PEM RSA private key file
4190 -key arg - key to decode the RSA private key if it is encrypted
4191 since we need to keep the CA's RSA key encrypted
4192 -cert - The CA certificate
4193 -in file - The input PEM encoded certificate request(s)
4194 -out file - Where to put the output file(s)
4195 -outdir dir - Where to put output certificates
4196 The -out options concatinates all the output certificied
4197 certificates to one file, -outdir puts them in a directory,
4198 named by serial number.
4199 -infiles .... - The last argument, requests to process
4200 The certificate requests to process, -in is the same.
4201
4202Just about all the above have default values defined in ssleay.conf.
4203
4204The key variables in ssleay.conf are (for the pariticular '-name' being
4205used, in the default, it is CA_default).
4206
4207dir is where all the CA database stuff is kept.
4208certs is where all the previously issued certificates are kept.
4209The database is a simple text database containing the following tab separated
4210fields.
4211status: a value of 'R' - revoked, 'E' -expired or 'V' valid.
4212issued date: When the certificate was certified.
4213revoked date: When it was revoked, blank if not revoked.
4214serial number: The certificate serial number.
4215certificate: Where the certificate is located.
4216CN: The name of the certificate.
4217
4218The demo file has quite a few made up values it it. The last 2 were
4219added by the ca program and are acurate.
4220The CA program does not update the 'certificate' file correctly right now.
4221The serial field should be unique as should the CN/status combination.
4222The ca program checks these at startup. What still needs to be
4223wrtten is a program to 'regenerate' the data base file from the issued
4224certificate list (and a CRL list).
4225
4226Back to the CA_default variables.
4227
4228Most of the variables are commented.
4229
4230policy is the default policy.
4231
4232Ok for policies, they define the order and which fields must be present
4233in the certificate request and what gets filled in.
4234
4235So a value of
4236countryName = match
4237means that the country name must match the CA certificate.
4238organizationalUnitName = optional
4239The org.Unit,Name does not have to be present and
4240commonName = supplied
4241commonName must be supplied in the certificate request.
4242
4243For the 'policy_match' polocy, the order of the attributes in the
4244generated certiticate would be
4245countryName
4246stateOrProvinceName
4247organizationName
4248organizationalUnitName
4249commonName
4250emailAddress
4251
4252Have a play, it sort of makes sense. If you think about how the persona
4253requests operate, it is similar to the 'policy_match' policy and the
4254'policy_anything' is similar to what versign is doing.
4255
4256I hope this helps a bit. Some backend scripts are definitly needed to
4257update the database and to make certificate revocion easy. All
4258certificates issued should also be kept forever (or until they expire?)
4259
4260hope this helps
4261eric (who has to run off an buy some cheap knee pads for the caving in 4
4262days time :-)
4263
4264--
4265Eric Young | Signature removed since it was generating
4266AARNet: eay@mincom.oz.au | more followups than the message contents :-)
4267
4268
4269==== ms3-ca.doc ========================================================
4270
4271Date: Mon, 9 Jun 97 08:00:33 +0200
4272From: Holger.Reif@PrakInf.TU-Ilmenau.DE (Holger Reif)
4273Subject: ms3-ca.doc
4274Organization: TU Ilmenau, Fak. IA, FG Telematik
4275Content-Length: 14575
4276Status: RO
4277X-Status:
4278
4279Loading client certs into MSIE 3.01
4280===================================
4281
4282This document conatains all the information necessary to succesfully set up
4283some scripts to issue client certs to Microsoft Internet Explorer. It
4284includes the required knowledge about the model MSIE uses for client
4285certification and includes complete sample scripts ready to play with. The
4286scripts were tested against a modified ca program of SSLeay 0.6.6 and should
4287work with the regular ca program that comes with version 0.8.0. I haven't
4288tested against MSIE 4.0
4289
4290You can use the information contained in this document in either way you
4291want. However if you feel it saved you a lot of time I ask you to be as fair
4292as to mention my name: Holger Reif <reif@prakinf.tu-ilmenau.de>.
4293
42941.) The model used by MSIE
4295--------------------------
4296
4297The Internet Explorer doesn't come with a embedded engine for installing
4298client certs like Netscape's Navigator. It rather uses the CryptoAPI (CAPI)
4299defined by Microsoft. CAPI comes with WindowsNT 4.0 or is installed together
4300with Internet Explorer since 3.01. The advantage of this approach is a higher
4301flexibility because the certificates in the (per user) system open
4302certificate store may be used by other applications as well. The drawback
4303however is that you need to do a bit more work to get a client cert issued.
4304
4305CAPI defines functions which will handle basic cryptographic work, eg.
4306generating keys, encrypting some data, signing text or building a certificate
4307request. The procedure is as follows: A CAPI function generates you a key
4308pair and saves it into the certificate store. After that one builds a
4309Distinguished Name. Together with that key pair another CAPI function forms a
4310PKCS#10 request which you somehow need to submit to a CA. Finally the issued
4311cert is given to a yet another CAPI function which saves it into the
4312certificate store.
4313
4314The certificate store with the user's keys and certs is in the registry. You
4315will find it under HKEY_CURRENT_USER/Software/Microsoft/Cryptography/ (I
4316leave it to you as a little exercise to figure out what all the entries mean
4317;-). Note that the keys are protected only with the user's usual Windows
4318login password.
4319
43202.) The practical usage
4321-----------------------
4322
4323Unfortunatly since CAPI is a system API you can't access its functions from
4324HTML code directly. For this purpose Microsoft provides a wrapper called
4325certenr3.dll. This DLL accesses the CAPI functions and provides an interface
4326usable from Visual Basic Script. One needs to install that library on the
4327computer which wants to have client cert. The easiest way is to load it as an
4328ActiveX control (certenr3.dll is properly authenticode signed by MS ;-). If
4329you have ever enrolled e cert request at a CA you will have installed it.
4330
4331At time of writing certenr3.dll is contained in
4332http://www.microsoft.com/workshop/prog/security/csa/certenr3.exe. It comes
4333with an README file which explains the available functions. It is labeled
4334beta but every CA seems to use it anyway. The license.txt allows you the
4335usage for your own purposes (as far as I understood) and a somehow limited
4336distribution.
4337
4338The two functions of main interest are GenerateKeyPair and AcceptCredentials.
4339For complete explanation of all possible parameters see the README file. Here
4340are only minimal required parameters and their values.
4341
4342GenerateKeyPair(sessionID, FASLE, szName, 0, "ClientAuth", TRUE, FALSE, 1)
4343- sessionID is a (locally to that computer) unique string to correlate the
4344generated key pair with a cert installed later.
4345- szName is the DN of the form "C=DE; S=Thueringen; L=Ilmenau; CN=Holger
4346Reif; 1.2.840.113549.1.9.1=reif@prakinf.tu-ilmenau.de". Note that S is the
4347abreviation for StateOrProvince. The recognized abreviation include CN, O, C,
4348OU, G, I, L, S, T. If the abreviation is unknown (eg. for PKCS#9 email addr)
4349you need to use the full object identifier. The starting point for searching
4350them could be crypto/objects.h since all OIDs know to SSLeay are listed
4351there.
4352- note: the possible ninth parameter which should give a default name to the
4353certificate storage location doesn't seem to work. Changes to the constant
4354values in the call above doesn't seem to make sense. You can't generate
4355PKCS#10 extensions with that function.
4356
4357The result of GenerateKeyPair is the base64 encoded PKCS#10 request. However
4358it has a little strange format that SSLeay doesn't accept. (BTW I feel the
4359decision of rejecting that format as standard conforming.) It looks like
4360follows:
4361 1st line with 76 chars
4362 2nd line with 76 chars
4363 ...
4364 (n-2)th line with 76 chars
4365 (n-1)th line contains a multiple of 4 chars less then 76 (possible
4366empty)
4367 (n)th line has zero or 4 chars (then with 1 or 2 equal signs - the
4368 original text's lenght wasn'T a multiple of 3)
4369 The line separator has two chars: 0x0d 0x0a
4370
4371AcceptCredentials(sessionID, credentials, 0, FALSE)
4372- sessionID needs to be the same as while generating the key pair
4373- credentials is the base64 encoded PKCS#7 object containing the cert.
4374
4375CRL's and CA certs are not required simply just the client cert. (It seems to
4376me that both are not even checked somehow.) The only format of the base64
4377encoded object I succesfully used was all characters in a very long string
4378without line feeds or carriage returns. (Hey, it doesn't matter, only a
4379computer reads it!)
4380
4381The result should be S_OK. For error handling see the example that comes with
4382certenr3.dll.
4383
4384A note about ASN.1 character encodings. certenr3.dll seems to know only about
43852 of them: UniversalString and PrintableString. First it is definitely wrong
4386for an email address which is IA5STRING (checked by ssleay's ca). Second
4387unfortunately MSIE (at least until version 3.02) can't handle UniversalString
4388correctly - they just blow up you cert store! Therefore ssleay's ca (starting
4389from version 0.8.0) tries to convert the encodings automatically to IA5STRING
4390or TeletexString. The beef is it will work only for the latin-1 (western)
4391charset. Microsoft still has to do abit of homework...
4392
43933.) An example
4394--------------
4395
4396At least you need two steps: generating the key & request and then installing
4397the certificate. A real world CA would have some more steps involved, eg.
4398accepting some license. Note that both scripts shown below are just
4399experimental state without any warrenty!
4400
4401First how to generate a request. Note that we can't use a static page because
4402of the sessionID. I generate it from system time plus pid and hope it is
4403unique enough. Your are free to feed it through md5 to get more impressive
4404ID's ;-) Then the intended text is read in with sed which inserts the
4405sessionID.
4406
4407-----BEGIN ms-enroll.cgi-----
4408#!/bin/sh
4409SESSION_ID=`date '+%y%m%d%H%M%S'`$$
4410echo Content-type: text/html
4411echo
4412sed s/template_for_sessId/$SESSION_ID/ <<EOF
4413<HTML><HEAD>
4414<TITLE>Certificate Enrollment Test Page</TITLE>
4415</HEAD><BODY>
4416
4417<OBJECT
4418 classid="clsid:33BEC9E0-F78F-11cf-B782-00C04FD7BF43"
4419 codebase=certenr3.dll
4420 id=certHelper
4421 >
4422</OBJECT>
4423
4424<CENTER>
4425<H2>enrollment for a personal cert</H2>
4426<BR><HR WIDTH=50%><BR><P>
4427<FORM NAME="MSIE_Enrollment" ACTION="ms-gencert.cgi" ENCTYPE=x-www-form-
4428encoded METHOD=POST>
4429<TABLE>
4430 <TR><TD>Country</TD><TD><INPUT NAME="Country" VALUE=""></TD></TR>
4431 <TR><TD>State</TD><TD><INPUT NAME="StateOrProvince" VALUE=""></TD></TR>
4432 <TR><TD>Location</TD><TD><INPUT NAME="Location" VALUE=""></TD></TR>
4433 <TR><TD>Organization</TD><TD><INPUT NAME="Organization"
4434VALUE=""></TD></TR>
4435 <TR><TD>Organizational Unit</TD>
4436 <TD><INPUT NAME="OrganizationalUnit" VALUE=""></TD></TR>
4437 <TR><TD>Name</TD><TD><INPUT NAME="CommonName" VALUE=""></TD></TR>
4438 <TR><TD>eMail Address</TD>
4439 <TD><INPUT NAME="EmailAddress" VALUE=""></TD></TR>
4440 <TR><TD></TD>
4441 <TD><INPUT TYPE="BUTTON" NAME="submit" VALUE="Beantragen"></TD></TR>
4442</TABLE>
4443 <INPUT TYPE="hidden" NAME="SessionId" VALUE="template_for_sessId">
4444 <INPUT TYPE="hidden" NAME="Request" VALUE="">
4445</FORM>
4446<BR><HR WIDTH=50%><BR><P>
4447</CENTER>
4448
4449<SCRIPT LANGUAGE=VBS>
4450 Dim DN
4451
4452 Sub Submit_OnClick
4453 Dim TheForm
4454 Set TheForm = Document.MSIE_Enrollment
4455 sessionId = TheForm.SessionId.value
4456 reqHardware = FALSE
4457 C = TheForm.Country.value
4458 SP = TheForm.StateOrProvince.value
4459 L = TheForm.Location.value
4460 O = TheForm.Organization.value
4461 OU = TheForm.OrganizationalUnit.value
4462 CN = TheForm.CommonName.value
4463 Email = TheForm.EmailAddress.value
4464 szPurpose = "ClientAuth"
4465 doAcceptanceUINow = FALSE
4466 doOnline = TRUE
4467
4468 DN = ""
4469
4470 Call Add_RDN("C", C)
4471 Call Add_RDN("S", SP)
4472 Call Add_RDN("L", L)
4473 Call Add_RDN("O", O)
4474 Call Add_RDN("OU", OU)
4475 Call Add_RDN("CN", CN)
4476 Call Add_RDN("1.2.840.113549.1.9.1", Email)
4477 ' rsadsi
4478 ' pkcs
4479 ' pkcs9
4480 ' eMailAddress
4481 On Error Resume Next
4482 sz10 = certHelper.GenerateKeyPair(sessionId, _
4483 FALSE, DN, 0, ClientAuth, FASLE, TRUE, 1)_
4484 theError = Err.Number
4485 On Error Goto 0
4486 if (sz10 = Empty OR theError <> 0) Then
4487 sz = "The error '" & Hex(theError) & "' occurred." & chr(13) & _
4488 chr(10) & "Your credentials could not be generated."
4489 result = MsgBox(sz, 0, "Credentials Enrollment")
4490 Exit Sub
4491 else
4492 TheForm.Request.value = sz10
4493 TheForm.Submit
4494 end if
4495 End Sub
4496
4497 Sub Add_RDN(sn, value)
4498 if (value <> "") then
4499 if (DN <> "") then
4500 DN = DN & "; "
4501 end if
4502 DN = DN & sn & "=" & value
4503 end if
4504 End Sub
4505</SCRIPT>
4506</BODY>
4507</HTML>
4508EOF
4509-----END ms-enroll.cgi-----
4510
4511Second, how to extract the request and feed the certificate back? We need to
4512"normalize" the base64 encoding of the PKCS#10 format which means
4513regenerating the lines and wrapping with BEGIN and END line. This is done by
4514gawk. The request is taken by ca the normal way. Then the cert needs to be
4515packed into a PKCS#7 structure (note: the use of a CRL is necessary for
4516crl2pkcs7 as of version 0.6.6. Starting with 0.8.0 it it might probably be
4517ommited). Finally we need to format the PKCS#7 object and generate the HTML
4518text. I use two templates to have a clearer script.
4519
45201st note: postit2 is slightly modified from a program I found at ncsa's ftp
4521site. Grab it from http://www.easterngraphics.com/certs/IX9704/postit2.c. You
4522need utils.c from there too.
4523
45242nd note: I'm note quite sure wether the gawk script really handles all
4525possible inputs for the request right! Today I don't use this construction
4526anymore myself.
4527
45283d note: the cert must be of version 3! This could be done with the nsComment
4529line in ssleay.cnf...
4530
4531------BEGIN ms-gencert.cgi-----
4532#!/bin/sh
4533FILE="/tmp/"`date '+%y%m%d%H%M%S'-`$$
4534rm -f "$FILE".*
4535
4536HOME=`pwd`; export HOME # as ssleay.cnf insists on having such an env var
4537cd /usr/local/ssl #where demoCA (as named in ssleay.conf) is located
4538
4539postit2 -s " " -i 0x0d > "$FILE".inp # process the FORM vars
4540
4541SESSION_ID=`gawk '$1 == "SessionId" { print $2; exit }' "$FILE".inp`
4542
4543gawk \
4544 'BEGIN { \
4545 OFS = ""; \
4546 print "-----BEGIN CERTIFICATE REQUEST-----"; \
4547 req_seen=0 \
4548 } \
4549 $1 == "Request" { \
4550 req_seen=1; \
4551 if (length($2) == 72) print($2); \
4552 lastline=$2; \
4553 next; \
4554 } \
4555 { \
4556 if (req_seen == 1) { \
4557 if (length($1) >= 72) print($1); \
4558 else if (length(lastline) < 72) { \
4559 req_seen=0; \
4560 print (lastline,$1); \
4561 } \
4562 lastline=$1; \
4563 } \
4564 } \
4565 END { \
4566 print "-----END CERTIFICATE REQUEST-----"; \
4567 }' > "$FILE".pem < "$FILE".inp
4568
4569ssleay ca -batch -in "$FILE".pem -key passwd -out "$FILE".out
4570ssleay crl2pkcs7 -certfile "$FILE".out -out "$FILE".pkcs7 -in demoCA/crl.pem
4571
4572sed s/template_for_sessId/$SESSION_ID/ <ms-enroll2a.html >"$FILE".cert
4573/usr/local/bin/gawk \
4574 'BEGIN { \
4575 OFS = ""; \
4576 dq = sprintf("%c",34); \
4577 } \
4578 $0 ~ "PKCS7" { next; } \
4579 { \
4580 print dq$0dq" & _"; \
4581 }' <"$FILE".pkcs7 >> "$FILE".cert
4582cat ms-enroll2b.html >>"$FILE".cert
4583
4584echo Content-type: text/html
4585echo Content-length: `wc -c "$FILE".cert`
4586echo
4587cat "$FILE".cert
4588rm -f "$FILE".*
4589-----END ms-gencert.cgi-----
4590
4591----BEGIN ms-enroll2a.html----
4592<HTML><HEAD><TITLE>Certificate Acceptance Test Page</TITLE></HEAD><BODY>
4593
4594<OBJECT
4595 classid="clsid:33BEC9E0-F78F-11cf-B782-00C04FD7BF43"
4596 codebase=certenr3.dll
4597 id=certHelper
4598 >
4599</OBJECT>
4600
4601<CENTER>
4602<H2>Your personal certificate</H2>
4603<BR><HR WIDTH=50%><BR><P>
4604Press the button!
4605<P><INPUT TYPE=BUTTON VALUE="Nimm mich!" NAME="InstallCert">
4606</CENTER>
4607<BR><HR WIDTH=50%><BR>
4608
4609<SCRIPT LANGUAGE=VBS>
4610 Sub InstallCert_OnClick
4611
4612 sessionId = "template_for_sessId"
4613credentials = "" & _
4614----END ms-enroll2a.html----
4615
4616----BEGIN ms-enroll2b.html----
4617""
4618 On Error Resume Next
4619 result = certHelper.AcceptCredentials(sessionId, credentials, 0,
4620FALSE)
4621 if (IsEmpty(result)) Then
4622 sz = "The error '" & Err.Number & "' occurred." & chr(13) &
4623chr(10) & "This Digital ID could not be registered."
4624 msgOut = MsgBox(sz, 0, "Credentials Registration Error")
4625 navigate "error.html"
4626 else
4627 sz = "Digital ID successfully registered."
4628 msgOut = MsgBox(sz, 0, "Credentials Registration")
4629 navigate "success.html"
4630 end if
4631 Exit Sub
4632 End Sub
4633</SCRIPT>
4634</BODY>
4635</HTML>
4636----END ms-enroll2b.html----
4637
46384.) What do do with the cert?
4639-----------------------------
4640
4641The cert is visible (without restarting MSIE) under the following menu:
4642View->Options->Security->Personal certs. You can examine it's contents at
4643least partially.
4644
4645To use it for client authentication you need to use SSL3.0 (fortunately
4646SSLeay supports it with 0.8.0). Furthermore MSIE is told to only supports a
4647kind of automatic selection of certs (I personally wasn't able to test it
4648myself). But there is a requirement that the issuer of the server cert and
4649the issuer of the client cert needs to be the same (according to a developer
4650from MS). Which means: you need may more then one cert to talk to all
4651servers...
4652
4653I'm sure we will get a bit more experience after ApacheSSL is available for
4654SSLeay 0.8.8.
4655
4656
4657I hope you enjoyed reading and that in future questions on this topic will
4658rarely appear on ssl-users@moncom.com ;-)
4659
4660Ilmenau, 9th of June 1997
4661Holger Reif <reif@prakinf.tu-ilmenau.de>
4662--
4663read you later - Holger Reif
4664---------------------------------------- Signaturprojekt Deutsche Einheit
4665TU Ilmenau - Informatik - Telematik (Verdamp lang her)
4666Holger.Reif@PrakInf.TU-Ilmenau.DE Alt wie ein Baum werden, um ueber
4667http://Remus.PrakInf.TU-Ilmenau.DE/Reif/ alle 7 Bruecken gehen zu koennen
4668
4669
4670==== ns-ca.doc ========================================================
4671
4672The following documentation was supplied by Jeff Barber, who provided the
4673patch to the CA program to add this functionality.
4674
4675eric
4676--
4677Jeff Barber Email: jeffb@issl.atl.hp.com
4678
4679Hewlett Packard Phone: (404) 648-9503
4680Internet and System Security Lab Fax: (404) 648-9516
4681
4682 oo
4683---------------------cut /\ here for ns-ca.doc ------------------------------
4684
4685This document briefly describes how to use SSLeay to implement a
4686certificate authority capable of dynamically serving up client
4687certificates for version 3.0 beta 5 (and presumably later) versions of
4688the Netscape Navigator. Before describing how this is done, it's
4689important to understand a little about how the browser implements its
4690client certificate support. This is documented in some detail in the
4691URLs based at <URL:http://home.netscape.com/eng/security/certs.html>.
4692Here's a brief overview:
4693
4694- The Navigator supports a new HTML tag "KEYGEN" which will cause
4695 the browser to generate an RSA key pair when you submit a form
4696 containing the tag. The public key, along with an optional
4697 challenge (supposedly provided for use in certificate revocation
4698 but I don't use it) is signed, DER-encoded, base-64 encoded
4699 and sent to the web server as the value of the variable
4700 whose NAME is provided in the KEYGEN tag. The private key is
4701 stored by the browser in a local key database.
4702
4703 This "Signed Public Key And Challenge" (SPKAC) arrives formatted
4704 into 64 character lines (which are of course URL-encoded when
4705 sent via HTTP -- i.e. spaces, newlines and most punctuatation are
4706 encoded as "%HH" where HH is the hex equivalent of the ASCII code).
4707 Note that the SPKAC does not contain the other usual attributes
4708 of a certificate request, especially the subject name fields.
4709 These must be otherwise encoded in the form for submission along
4710 with the SPKAC.
4711
4712- Either immediately (in response to this form submission), or at
4713 some later date (a real CA will probably verify your identity in
4714 some way before issuing the certificate), a web server can send a
4715 certificate based on the public key and other attributes back to
4716 the browser by encoding it in DER (the binary form) and sending it
4717 to the browser as MIME type:
4718 "Content-type: application/x-x509-user-cert"
4719
4720 The browser uses the public key encoded in the certificate to
4721 associate the certificate with the appropriate private key in
4722 its local key database. Now, the certificate is "installed".
4723
4724- When a server wants to require authentication based on client
4725 certificates, it uses the right signals via the SSL protocol to
4726 trigger the Navigator to ask you which certificate you want to
4727 send. Whether the certificate is accepted is dependent on CA
4728 certificates and so forth installed in the server and is beyond
4729 the scope of this document.
4730
4731
4732Now, here's how the SSLeay package can be used to provide client
4733certficates:
4734
4735- You prepare a file for input to the SSLeay ca application.
4736 The file contains a number of "name = value" pairs that identify
4737 the subject. The names here are the same subject name component
4738 identifiers used in the CA section of the lib/ssleay.conf file,
4739 such as "emailAddress", "commonName" "organizationName" and so
4740 forth. Both the long version and the short version (e.g. "Email",
4741 "CN", "O") can be used.
4742
4743 One more name is supported: this one is "SPKAC". Its value
4744 is simply the value of the base-64 encoded SPKAC sent by the
4745 browser (with all the newlines and other space charaters
4746 removed -- and newline escapes are NOT supported).
4747
4748 [ As of SSLeay 0.6.4, multiple lines are supported.
4749 Put a \ at the end of each line and it will be joined with the
4750 previous line with the '\n' removed - eay ]
4751
4752 Here's a sample input file:
4753
4754C = US
4755SP = Georgia
4756O = Some Organization, Inc.
4757OU = Netscape Compatibility Group
4758CN = John X. Doe
4759Email = jxdoe@someorg.com
4760SPKAC = MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAwmk6FMJ4uAVIYbcvIOx5+bDGTfvL8X5gE+R67ccMk6rCSGbVQz2cetyQtnI+VIs0NwdD6wjuSuVtVFbLoHonowIDAQABFgAwDQYJKoZIhvcNAQEEBQADQQBFZDUWFl6BJdomtN1Bi53mwijy1rRgJ4YirF15yBEDM3DjAQkKXHYOIX+qpz4KXKnl6EYxTnGSFL5wWt8X2iyx
4761
4762- You execute the ca command (either from a CGI program run out of
4763 the web server, or as a later manual task) giving it the above
4764 file as input. For example, if the file were named /tmp/cert.req,
4765 you'd run:
4766 $SSLDIR/bin/ca -spkac /tmp/cert.req -out /tmp/cert
4767
4768 The output is in DER format (binary) if a -out argument is
4769 provided, as above; otherwise, it's in the PEM format (base-64
4770 encoded DER). Also, the "-batch" switch is implied by the
4771 "-spkac" so you don't get asked whether to complete the signing
4772 (probably it shouldn't work this way but I was only interested
4773 in hacking together an online CA that could be used for issuing
4774 test certificates).
4775
4776 The "-spkac" capability doesn't support multiple files (I think).
4777
4778 Any CHALLENGE provided in the SPKAC is simply ignored.
4779
4780 The interactions between the identification fields you provide
4781 and those identified in your lib/ssleay.conf are the same as if
4782 you did an ordinary "ca -in infile -out outfile" -- that is, if
4783 something is marked as required in the ssleay.conf file and it
4784 isn't found in the -spkac file, the certificate won't be issued.
4785
4786- Now, you pick up the output from /tmp/cert and pass it back to
4787 the Navigator prepending the Content-type string described earlier.
4788
4789- In order to run the ca command out of a CGI program, you must
4790 provide a password to decrypt the CA's private key. You can
4791 do this by using "echo MyKeyPassword | $SSLDIR/bin/ca ..."
4792 I think there's a way to not encrypt the key file in the first
4793 place, but I didn't see how to do that, so I made a small change
4794 to the library that allows the password to be accepted from a pipe.
4795 Either way is UTTERLY INSECURE and a real CA would never do that.
4796
4797 [ You can use the 'ssleay rsa' command to remove the password
4798 from the private key, or you can use the '-key' option to the
4799 ca command to specify the decryption key on the command line
4800 or use the -nodes option when generating the key.
4801 ca will try to clear the command line version of the password
4802 but for quite a few operating systems, this is not possible.
4803 - eric ]
4804
4805So, what do you have to do to make use of this stuff to create an online
4806demo CA capability with SSLeay?
4807
48081 Create an HTML form for your users. The form should contain
4809 fields for all of the required or optional fields in ssleay.conf.
4810 The form must contain a KEYGEN tag somewhere with at least a NAME
4811 attribute.
4812
48132 Create a CGI program to process the form input submitted by the
4814 browser. The CGI program must URL-decode the variables and create
4815 the file described above, containing subject identification info
4816 as well as the SPKAC block. It should then run the the ca program
4817 with the -spkac option. If it works (check the exit status),
4818 return the new certificate with the appropriate MIME type. If not,
4819 return the output of the ca command with MIME type "text/plain".
4820
48213 Set up your web server to accept connections signed by your demo
4822 CA. This probably involves obtaining the PEM-encoded CA certificate
4823 (ordinarily in $SSLDIR/CA/cacert.pem) and installing it into a
4824 server database. See your server manual for instructions.
4825
4826
4827==== obj.doc ========================================================
4828
4829The Object library.
4830
4831As part of my Crypto library, I found I required a method of identifying various
4832objects. These objects normally had 3 different values associated with
4833them, a short text name, a long (or lower case) text name, and an
4834ASN.1 Object Identifier (which is a sequence of numbers).
4835This library contains a static list of objects and functions to lookup
4836according to one type and to return the other types.
4837
4838To use these routines, 'Object.h' needs to be included.
4839
4840For each supported object, #define entries are defined as follows
4841#define SN_Algorithm "Algorithm"
4842#define LN_algorithm "algorithm"
4843#define NID_algorithm 38
4844#define OBJ_algorithm 1L,3L,14L,3L,2L
4845
4846SN_ stands for short name.
4847LN_ stands for either long name or lowercase name.
4848NID_ stands for Numeric ID. I each object has a unique NID and this
4849 should be used internally to identify objects.
4850OBJ_ stands for ASN.1 Object Identifier or ASN1_OBJECT as defined in the
4851 ASN1 routines. These values are used in ASN1 encoding.
4852
4853The following functions are to be used to return pointers into a static
4854definition of these types. What this means is "don't try to free() any
4855pointers returned from these functions.
4856
4857ASN1_OBJECT *OBJ_nid2obj(
4858int n);
4859 Return the ASN1_OBJECT that corresponds to a NID of n.
4860
4861char *OBJ_nid2ln(
4862int n);
4863 Return the long/lower case name of the object represented by the
4864 NID of n.
4865
4866char *OBJ_nid2sn(
4867int n);
4868 Return the short name for the object represented by the NID of n.
4869
4870ASN1_OBJECT *OBJ_dup(
4871ASN1_OBJECT *o);
4872 Duplicate and return a new ASN1_OBJECT that is the same as the
4873 passed parameter.
4874
4875int OBJ_obj2nid(
4876ASN1_OBJECT *o);
4877 Given ASN1_OBJECT o, return the NID that corresponds.
4878
4879int OBJ_ln2nid(
4880char *s);
4881 Given the long/lower case name 's', return the NID of the object.
4882
4883int OBJ_sn2nid(
4884char *s);
4885 Given the short name 's', return the NID of the object.
4886
4887char *OBJ_bsearch(
4888char *key,
4889char *base,
4890int num,
4891int size,
4892int (*cmp)());
4893 Since I have come across a few platforms that do not have the
4894 bsearch() function, OBJ_bsearch is my version of that function.
4895 Feel free to use this function, but you may as well just use the
4896 normal system bsearch(3) if it is present. This version also
4897 has tolerance of being passed NULL pointers.
4898
4899==== keys ===========================================================
4900
4901EVP_PKEY_DSA
4902EVP_PKEY_DSA2
4903EVP_PKEY_DSA3
4904EVP_PKEY_DSA4
4905
4906EVP_PKEY_RSA
4907EVP_PKEY_RSA2
4908
4909valid DSA pkey types
4910 NID_dsa
4911 NID_dsaWithSHA
4912 NID_dsaWithSHA1
4913 NID_dsaWithSHA1_2
4914
4915valid RSA pkey types
4916 NID_rsaEncryption
4917 NID_rsa
4918
4919NID_dsaWithSHA NID_dsaWithSHA DSA SHA
4920NID_dsa NID_dsaWithSHA1 DSA SHA1
4921NID_md2 NID_md2WithRSAEncryption RSA-pkcs1 MD2
4922NID_md5 NID_md5WithRSAEncryption RSA-pkcs1 MD5
4923NID_mdc2 NID_mdc2WithRSA RSA-none MDC2
4924NID_ripemd160 NID_ripemd160WithRSA RSA-pkcs1 RIPEMD160
4925NID_sha NID_shaWithRSAEncryption RSA-pkcs1 SHA
4926NID_sha1 NID_sha1WithRSAEncryption RSA-pkcs1 SHA1
4927
4928==== rand.doc ========================================================
4929
4930My Random number library.
4931
4932These routines can be used to generate pseudo random numbers and can be
4933used to 'seed' the pseudo random number generator (RNG). The RNG make no
4934effort to reproduce the same random number stream with each execution.
4935Various other routines in the SSLeay library 'seed' the RNG when suitable
4936'random' input data is available. Read the section at the end for details
4937on the design of the RNG.
4938
4939void RAND_bytes(
4940unsigned char *buf,
4941int num);
4942 This routine puts 'num' random bytes into 'buf'. One should make
4943 sure RAND_seed() has been called before using this routine.
4944
4945void RAND_seed(
4946unsigned char *buf,
4947int num);
4948 This routine adds more 'seed' data the RNG state. 'num' bytes
4949 are added to the RNG state, they are taken from 'buf'. This
4950 routine can be called with sensitive data such as user entered
4951 passwords. This sensitive data is in no way recoverable from
4952 the RAND library routines or state. Try to pass as much data
4953 from 'random' sources as possible into the RNG via this function.
4954 Also strongly consider using the RAND_load_file() and
4955 RAND_write_file() routines.
4956
4957void RAND_cleanup();
4958 When a program has finished with the RAND library, if it so
4959 desires, it can 'zero' all RNG state.
4960
4961The following 3 routines are convenience routines that can be used to
4962'save' and 'restore' data from/to the RNG and it's state.
4963Since the more 'random' data that is feed as seed data the better, why not
4964keep it around between executions of the program? Of course the
4965application should pass more 'random' data in via RAND_seed() and
4966make sure no-one can read the 'random' data file.
4967
4968char *RAND_file_name(
4969char *buf,
4970int size);
4971 This routine returns a 'default' name for the location of a 'rand'
4972 file. The 'rand' file should keep a sequence of random bytes used
4973 to initialise the RNG. The filename is put in 'buf'. Buf is 'size'
4974 bytes long. Buf is returned if things go well, if they do not,
4975 NULL is returned. The 'rand' file name is generated in the
4976 following way. First, if there is a 'RANDFILE' environment
4977 variable, it is returned. Second, if there is a 'HOME' environment
4978 variable, $HOME/.rand is returned. Third, NULL is returned. NULL
4979 is also returned if a buf would overflow.
4980
4981int RAND_load_file(
4982char *file,
4983long number);
4984 This function 'adds' the 'file' into the RNG state. It does this by
4985 doing a RAND_seed() on the value returned from a stat() system call
4986 on the file and if 'number' is non-zero, upto 'number' bytes read
4987 from the file. The number of bytes passed to RAND_seed() is returned.
4988
4989int RAND_write_file(
4990char *file),
4991 RAND_write_file() writes N random bytes to the file 'file', where
4992 N is the size of the internal RND state (currently 1k).
4993 This is a suitable method of saving RNG state for reloading via
4994 RAND_load_file().
4995
4996What follows is a description of this RNG and a description of the rational
4997behind it's design.
4998
4999It should be noted that this RNG is intended to be used to generate
5000'random' keys for various ciphers including generation of DH and RSA keys.
5001
5002It should also be noted that I have just created a system that I am happy with.
5003It may be overkill but that does not worry me. I have not spent that much
5004time on this algorithm so if there are glaring errors, please let me know.
5005Speed has not been a consideration in the design of these routines.
5006
5007First up I will state the things I believe I need for a good RNG.
50081) A good hashing algorithm to mix things up and to convert the RNG 'state'
5009 to random numbers.
50102) An initial source of random 'state'.
50113) The state should be very large. If the RNG is being used to generate
5012 4096 bit RSA keys, 2 2048 bit random strings are required (at a minimum).
5013 If your RNG state only has 128 bits, you are obviously limiting the
5014 search space to 128 bits, not 2048. I'm probably getting a little
5015 carried away on this last point but it does indicate that it may not be
5016 a bad idea to keep quite a lot of RNG state. It should be easier to
5017 break a cipher than guess the RNG seed data.
50184) Any RNG seed data should influence all subsequent random numbers
5019 generated. This implies that any random seed data entered will have
5020 an influence on all subsequent random numbers generated.
50215) When using data to seed the RNG state, the data used should not be
5022 extractable from the RNG state. I believe this should be a
5023 requirement because one possible source of 'secret' semi random
5024 data would be a private key or a password. This data must
5025 not be disclosed by either subsequent random numbers or a
5026 'core' dump left by a program crash.
50276) Given the same initial 'state', 2 systems should deviate in their RNG state
5028 (and hence the random numbers generated) over time if at all possible.
50297) Given the random number output stream, it should not be possible to determine
5030 the RNG state or the next random number.
5031
5032
5033The algorithm is as follows.
5034
5035There is global state made up of a 1023 byte buffer (the 'state'), a
5036working message digest ('md') and a counter ('count').
5037
5038Whenever seed data is added, it is inserted into the 'state' as
5039follows.
5040 The input is chopped up into units of 16 bytes (or less for
5041 the last block). Each of these blocks is run through the MD5
5042 message digest. The data passed to the MD5 digest is the
5043 current 'md', the same number of bytes from the 'state'
5044 (the location determined by in incremented looping index) as
5045 the current 'block' and the new key data 'block'. The result
5046 of this is kept in 'md' and also xored into the 'state' at the
5047 same locations that were used as input into the MD5.
5048 I believe this system addresses points 1 (MD5), 3 (the 'state'),
5049 4 (via the 'md'), 5 (by the use of MD5 and xor).
5050
5051When bytes are extracted from the RNG, the following process is used.
5052For each group of 8 bytes (or less), we do the following,
5053 Input into MD5, the top 8 bytes from 'md', the byte that are
5054 to be overwritten by the random bytes and bytes from the
5055 'state' (incrementing looping index). From this digest output
5056 (which is kept in 'md'), the top (upto) 8 bytes are
5057 returned to the caller and the bottom (upto) 8 bytes are xored
5058 into the 'state'.
5059 Finally, after we have finished 'generation' random bytes for the
5060 called, 'count' (which is incremented) and 'md' are fed into MD5 and
5061 the results are kept in 'md'.
5062 I believe the above addressed points 1 (use of MD5), 6 (by
5063 hashing into the 'state' the 'old' data from the caller that
5064 is about to be overwritten) and 7 (by not using the 8 bytes
5065 given to the caller to update the 'state', but they are used
5066 to update 'md').
5067
5068So of the points raised, only 2 is not addressed, but sources of
5069random data will always be a problem.
5070
5071
5072==== rc2.doc ========================================================
5073
5074The RC2 library.
5075
5076RC2 is a block cipher that operates on 64bit (8 byte) quantities. It
5077uses variable size key, but 128bit (16 byte) key would normally be considered
5078good. It can be used in all the modes that DES can be used. This
5079library implements the ecb, cbc, cfb64, ofb64 modes.
5080
5081I have implemented this library from an article posted to sci.crypt on
508211-Feb-1996. I personally don't know how far to trust the RC2 cipher.
5083While it is capable of having a key of any size, not much reseach has
5084publically been done on it at this point in time (Apr-1996)
5085since the cipher has only been public for a few months :-)
5086It is of a similar speed to DES and IDEA, so unless it is required for
5087meeting some standard (SSLv2, perhaps S/MIME), it would probably be advisable
5088to stick to IDEA, or for the paranoid, Tripple DES.
5089
5090Mind you, having said all that, I should mention that I just read alot and
5091implement ciphers, I'm a 'babe in the woods' when it comes to evaluating
5092ciphers :-).
5093
5094For all calls that have an 'input' and 'output' variables, they can be the
5095same.
5096
5097This library requires the inclusion of 'rc2.h'.
5098
5099All of the encryption functions take what is called an RC2_KEY as an
5100argument. An RC2_KEY is an expanded form of the RC2 key.
5101For all modes of the RC2 algorithm, the RC2_KEY used for
5102decryption is the same one that was used for encryption.
5103
5104The define RC2_ENCRYPT is passed to specify encryption for the functions
5105that require an encryption/decryption flag. RC2_DECRYPT is passed to
5106specify decryption.
5107
5108Please note that any of the encryption modes specified in my DES library
5109could be used with RC2. I have only implemented ecb, cbc, cfb64 and
5110ofb64 for the following reasons.
5111- ecb is the basic RC2 encryption.
5112- cbc is the normal 'chaining' form for block ciphers.
5113- cfb64 can be used to encrypt single characters, therefore input and output
5114 do not need to be a multiple of 8.
5115- ofb64 is similar to cfb64 but is more like a stream cipher, not as
5116 secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
5117- If you want triple RC2, thats 384 bits of key and you must be totally
5118 obsessed with security. Still, if you want it, it is simple enough to
5119 copy the function from the DES library and change the des_encrypt to
5120 RC2_encrypt; an exercise left for the paranoid reader :-).
5121
5122The functions are as follows:
5123
5124void RC2_set_key(
5125RC2_KEY *ks;
5126int len;
5127unsigned char *key;
5128int bits;
5129 RC2_set_key converts an 'len' byte key into a RC2_KEY.
5130 A 'ks' is an expanded form of the 'key' which is used to
5131 perform actual encryption. It can be regenerated from the RC2 key
5132 so it only needs to be kept when encryption or decryption is about
5133 to occur. Don't save or pass around RC2_KEY's since they
5134 are CPU architecture dependent, 'key's are not. RC2 is an
5135 interesting cipher in that it can be used with a variable length
5136 key. 'len' is the length of 'key' to be used as the key.
5137 A 'len' of 16 is recomended. The 'bits' argument is an
5138 interesting addition which I only found out about in Aug 96.
5139 BSAFE uses this parameter to 'limit' the number of bits used
5140 for the key. To use the 'key' unmodified, set bits to 1024.
5141 This is what old versions of my RC2 library did (SSLeay 0.6.3).
5142 RSAs BSAFE library sets this parameter to be 128 if 128 bit
5143 keys are being used. So to be compatable with BSAFE, set it
5144 to 128, if you don't want to reduce RC2's key length, leave it
5145 at 1024.
5146
5147void RC2_encrypt(
5148unsigned long *data,
5149RC2_KEY *key,
5150int encrypt);
5151 This is the RC2 encryption function that gets called by just about
5152 every other RC2 routine in the library. You should not use this
5153 function except to implement 'modes' of RC2. I say this because the
5154 functions that call this routine do the conversion from 'char *' to
5155 long, and this needs to be done to make sure 'non-aligned' memory
5156 access do not occur.
5157 Data is a pointer to 2 unsigned long's and key is the
5158 RC2_KEY to use. Encryption or decryption is indicated by 'encrypt'.
5159 which can have the values RC2_ENCRYPT or RC2_DECRYPT.
5160
5161void RC2_ecb_encrypt(
5162unsigned char *in,
5163unsigned char *out,
5164RC2_KEY *key,
5165int encrypt);
5166 This is the basic Electronic Code Book form of RC2 (in DES this
5167 mode is called Electronic Code Book so I'm going to use the term
5168 for rc2 as well.
5169 Input is encrypted into output using the key represented by
5170 key. Depending on the encrypt, encryption or
5171 decryption occurs. Input is 8 bytes long and output is 8 bytes.
5172
5173void RC2_cbc_encrypt(
5174unsigned char *in,
5175unsigned char *out,
5176long length,
5177RC2_KEY *ks,
5178unsigned char *ivec,
5179int encrypt);
5180 This routine implements RC2 in Cipher Block Chaining mode.
5181 Input, which should be a multiple of 8 bytes is encrypted
5182 (or decrypted) to output which will also be a multiple of 8 bytes.
5183 The number of bytes is in length (and from what I've said above,
5184 should be a multiple of 8). If length is not a multiple of 8, bad
5185 things will probably happen. ivec is the initialisation vector.
5186 This function updates iv after each call so that it can be passed to
5187 the next call to RC2_cbc_encrypt().
5188
5189void RC2_cfb64_encrypt(
5190unsigned char *in,
5191unsigned char *out,
5192long length,
5193RC2_KEY *schedule,
5194unsigned char *ivec,
5195int *num,
5196int encrypt);
5197 This is one of the more useful functions in this RC2 library, it
5198 implements CFB mode of RC2 with 64bit feedback.
5199 This allows you to encrypt an arbitrary number of bytes,
5200 you do not require 8 byte padding. Each call to this
5201 routine will encrypt the input bytes to output and then update ivec
5202 and num. Num contains 'how far' we are though ivec.
5203 'Encrypt' is used to indicate encryption or decryption.
5204 CFB64 mode operates by using the cipher to generate a stream
5205 of bytes which is used to encrypt the plain text.
5206 The cipher text is then encrypted to generate the next 64 bits to
5207 be xored (incrementally) with the next 64 bits of plain
5208 text. As can be seen from this, to encrypt or decrypt,
5209 the same 'cipher stream' needs to be generated but the way the next
5210 block of data is gathered for encryption is different for
5211 encryption and decryption.
5212
5213void RC2_ofb64_encrypt(
5214unsigned char *in,
5215unsigned char *out,
5216long length,
5217RC2_KEY *schedule,
5218unsigned char *ivec,
5219int *num);
5220 This functions implements OFB mode of RC2 with 64bit feedback.
5221 This allows you to encrypt an arbitrary number of bytes,
5222 you do not require 8 byte padding. Each call to this
5223 routine will encrypt the input bytes to output and then update ivec
5224 and num. Num contains 'how far' we are though ivec.
5225 This is in effect a stream cipher, there is no encryption or
5226 decryption mode.
5227
5228For reading passwords, I suggest using des_read_pw_string() from my DES library.
5229To generate a password from a text string, I suggest using MD5 (or MD2) to
5230produce a 16 byte message digest that can then be passed directly to
5231RC2_set_key().
5232
5233=====
5234For more information about the specific RC2 modes in this library
5235(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
5236documentation on my DES library. What is said about DES is directly
5237applicable for RC2.
5238
5239
5240==== rc4.doc ========================================================
5241
5242The RC4 library.
5243RC4 is a stream cipher that operates on a byte stream. It can be used with
5244any length key but I would recommend normally using 16 bytes.
5245
5246This library requires the inclusion of 'rc4.h'.
5247
5248The RC4 encryption function takes what is called an RC4_KEY as an argument.
5249The RC4_KEY is generated by the RC4_set_key function from the key bytes.
5250
5251RC4, being a stream cipher, does not have an encryption or decryption mode.
5252It produces a stream of bytes that the input stream is xor'ed against and
5253so decryption is just a case of 'encrypting' again with the same key.
5254
5255I have only put in one 'mode' for RC4 which is the normal one. This means
5256there is no initialisation vector and there is no feedback of the cipher
5257text into the cipher. This implies that you should not ever use the
5258same key twice if you can help it. If you do, you leave yourself open to
5259known plain text attacks; if you know the plain text and
5260corresponding cipher text in one message, all messages that used the same
5261key can have the cipher text decoded for the corresponding positions in the
5262cipher stream.
5263
5264The main positive feature of RC4 is that it is a very fast cipher; about 4
5265times faster that DES. This makes it ideally suited to protocols where the
5266key is randomly chosen, like SSL.
5267
5268The functions are as follows:
5269
5270void RC4_set_key(
5271RC4_KEY *key;
5272int len;
5273unsigned char *data);
5274 This function initialises the RC4_KEY structure with the key passed
5275 in 'data', which is 'len' bytes long. The key data can be any
5276 length but 16 bytes seems to be a good number.
5277
5278void RC4(
5279RC4_KEY *key;
5280unsigned long len;
5281unsigned char *in;
5282unsigned char *out);
5283 Do the actual RC4 encryption/decryption. Using the 'key', 'len'
5284 bytes are transformed from 'in' to 'out'. As mentioned above,
5285 decryption is the operation as encryption.
5286
5287==== ref.doc ========================================================
5288
5289I have lots more references etc, and will update this list in the future,
529030 Aug 1996 - eay
5291
5292
5293SSL The SSL Protocol - from Netscapes.
5294
5295RC4 Newsgroups: sci.crypt
5296 From: sterndark@netcom.com (David Sterndark)
5297 Subject: RC4 Algorithm revealed.
5298 Message-ID: <sternCvKL4B.Hyy@netcom.com>
5299
5300RC2 Newsgroups: sci.crypt
5301 From: pgut01@cs.auckland.ac.nz (Peter Gutmann)
5302 Subject: Specification for Ron Rivests Cipher No.2
5303 Message-ID: <4fk39f$f70@net.auckland.ac.nz>
5304
5305MD2 RFC1319 The MD2 Message-Digest Algorithm
5306MD5 RFC1321 The MD5 Message-Digest Algorithm
5307
5308X509 Certificates
5309 RFC1421 Privacy Enhancement for Internet Electronic Mail: Part I
5310 RFC1422 Privacy Enhancement for Internet Electronic Mail: Part II
5311 RFC1423 Privacy Enhancement for Internet Electronic Mail: Part III
5312 RFC1424 Privacy Enhancement for Internet Electronic Mail: Part IV
5313
5314RSA and various standard encoding
5315 PKCS#1 RSA Encryption Standard
5316 PKCS#5 Password-Based Encryption Standard
5317 PKCS#7 Cryptographic Message Syntax Standard
5318 A Layman's Guide to a Subset of ASN.1, BER, and DER
5319 An Overview of the PKCS Standards
5320 Some Examples of the PKCS Standards
5321
5322IDEA Chapter 3 The Block Cipher IDEA
5323
5324RSA, prime number generation and bignum algorithms
5325 Introduction To Algorithms,
5326 Thomas Cormen, Charles Leiserson, Ronald Rivest,
5327 Section 29 Arithmetic Circuits
5328 Section 33 Number-Theoretic Algorithms
5329
5330Fast Private Key algorithm
5331 Fast Decipherment Algorithm for RSA Public-Key Cryptosystem
5332 J.-J. Quisquater and C. Couvreur, Electronics Letters,
5333 14th October 1982, Vol. 18 No. 21
5334
5335Prime number generation and bignum algorithms.
5336 PGP-2.3a
5337
5338==== rsa.doc ========================================================
5339
5340The RSA encryption and utility routines.
5341
5342The RSA routines are built on top of a big number library (the BN library).
5343There are support routines in the X509 library for loading and manipulating
5344the various objects in the RSA library. When errors are returned, read
5345about the ERR library for how to access the error codes.
5346
5347All RSA encryption is done according to the PKCS-1 standard which is
5348compatible with PEM and RSAref. This means that any values being encrypted
5349must be less than the size of the modulus in bytes, minus 10, bytes long.
5350
5351This library uses RAND_bytes()() for it's random data, make sure to feed
5352RAND_seed() with lots of interesting and varied data before using these
5353routines.
5354
5355The RSA library has one specific data type, the RSA structure.
5356It is composed of 8 BIGNUM variables (see the BN library for details) and
5357can hold either a private RSA key or a public RSA key.
5358Some RSA libraries have different structures for public and private keys, I
5359don't. For my libraries, a public key is determined by the fact that the
5360RSA->d value is NULL. These routines will operate on any size RSA keys.
5361While I'm sure 4096 bit keys are very very secure, they take a lot longer
5362to process that 1024 bit keys :-).
5363
5364The function in the RSA library are as follows.
5365
5366RSA *RSA_new();
5367 This function creates a new RSA object. The sub-fields of the RSA
5368 type are also malloced so you should always use this routine to
5369 create RSA variables.
5370
5371void RSA_free(
5372RSA *rsa);
5373 This function 'frees' an RSA structure. This routine should always
5374 be used to free the RSA structure since it will also 'free' any
5375 sub-fields of the RSA type that need freeing.
5376
5377int RSA_size(
5378RSA *rsa);
5379 This function returns the size of the RSA modulus in bytes. Why do
5380 I need this you may ask, well the reason is that when you encrypt
5381 with RSA, the output string will be the size of the RSA modulus.
5382 So the output for the RSA_encrypt and the input for the RSA_decrypt
5383 routines need to be RSA_size() bytes long, because this is how many
5384 bytes are expected.
5385
5386For the following 4 RSA encryption routines, it should be noted that
5387RSA_private_decrypt() should be used on the output from
5388RSA_public_encrypt() and RSA_public_decrypt() should be used on
5389the output from RSA_private_encrypt().
5390
5391int RSA_public_encrypt(
5392int from_len;
5393unsigned char *from
5394unsigned char *to
5395RSA *rsa);
5396 This function implements RSA public encryption, the rsa variable
5397 should be a public key (but can be a private key). 'from_len'
5398 bytes taken from 'from' and encrypted and put into 'to'. 'to' needs
5399 to be at least RSA_size(rsa) bytes long. The number of bytes
5400 written into 'to' is returned. -1 is returned on an error. The
5401 operation performed is
5402 to = from^rsa->e mod rsa->n.
5403
5404int RSA_private_encrypt(
5405int from_len;
5406unsigned char *from
5407unsigned char *to
5408RSA *rsa);
5409 This function implements RSA private encryption, the rsa variable
5410 should be a private key. 'from_len' bytes taken from
5411 'from' and encrypted and put into 'to'. 'to' needs
5412 to be at least RSA_size(rsa) bytes long. The number of bytes
5413 written into 'to' is returned. -1 is returned on an error. The
5414 operation performed is
5415 to = from^rsa->d mod rsa->n.
5416
5417int RSA_public_decrypt(
5418int from_len;
5419unsigned char *from
5420unsigned char *to
5421RSA *rsa);
5422 This function implements RSA public decryption, the rsa variable
5423 should be a public key (but can be a private key). 'from_len'
5424 bytes are taken from 'from' and decrypted. The decrypted data is
5425 put into 'to'. The number of bytes encrypted is returned. -1 is
5426 returned to indicate an error. The operation performed is
5427 to = from^rsa->e mod rsa->n.
5428
5429int RSA_private_decrypt(
5430int from_len;
5431unsigned char *from
5432unsigned char *to
5433RSA *rsa);
5434 This function implements RSA private decryption, the rsa variable
5435 should be a private key. 'from_len' bytes are taken
5436 from 'from' and decrypted. The decrypted data is
5437 put into 'to'. The number of bytes encrypted is returned. -1 is
5438 returned to indicate an error. The operation performed is
5439 to = from^rsa->d mod rsa->n.
5440
5441int RSA_mod_exp(
5442BIGNUM *n;
5443BIGNUM *p;
5444RSA *rsa);
5445 Normally you will never use this routine.
5446 This is really an internal function which is called by
5447 RSA_private_encrypt() and RSA_private_decrypt(). It performs
5448 n=n^p mod rsa->n except that it uses the 5 extra variables in the
5449 RSA structure to make this more efficient.
5450
5451RSA *RSA_generate_key(
5452int bits;
5453unsigned long e;
5454void (*callback)();
5455char *cb_arg;
5456 This routine is used to generate RSA private keys. It takes
5457 quite a period of time to run and should only be used to
5458 generate initial private keys that should then be stored
5459 for later use. The passed callback function
5460 will be called periodically so that feedback can be given
5461 as to how this function is progressing.
5462 'bits' is the length desired for the modulus, so it would be 1024
5463 to generate a 1024 bit private key.
5464 'e' is the value to use for the public exponent 'e'. Traditionally
5465 it is set to either 3 or 0x10001.
5466 The callback function (if not NULL) is called in the following
5467 situations.
5468 when we have generated a suspected prime number to test,
5469 callback(0,num1++,cb_arg). When it passes a prime number test,
5470 callback(1,num2++,cb_arg). When it is rejected as one of
5471 the 2 primes required due to gcd(prime,e value) != 0,
5472 callback(2,num3++,cb_arg). When finally accepted as one
5473 of the 2 primes, callback(3,num4++,cb_arg).
5474
5475
5476==== rsaref.doc ========================================================
5477
5478This package can be compiled to use the RSAref library.
5479This library is not allowed outside of the USA but inside the USA it is
5480claimed by RSA to be the only RSA public key library that can be used
5481besides BSAFE..
5482
5483There are 2 files, rsaref/rsaref.c and rsaref/rsaref.h that contain the glue
5484code to use RSAref. These files were written by looking at the PGP
5485source code and seeing which routines it used to access RSAref.
5486I have also been sent by some-one a copy of the RSAref header file that
5487contains the library error codes.
5488
5489[ Jun 1996 update - I have recently gotten hold of RSAref 2.0 from
5490 South Africa and have been doing some performace tests. ]
5491
5492They have now been tested against the recently announced RSAEURO
5493library.
5494
5495There are 2 ways to use SSLeay and RSAref. First, to build so that
5496the programs must be linked with RSAref, add '-DRSAref' to CFLAG in the top
5497level makefile and -lrsaref (or where ever you are keeping RSAref) to
5498EX_LIBS.
5499
5500To build a makefile via util/mk1mf.pl to do this, use the 'rsaref' option.
5501
5502The second method is to build as per normal and link applications with
5503the RSAglue library. The correct library order would be
5504cc -o cmd cmd.o -lssl -lRSAglue -lcrypto -lrsaref -ldes
5505The RSAglue library is built in the rsa directory and is NOT
5506automatically installed.
5507
5508Be warned that the RSAEURO library, that is claimed to be compatible
5509with RSAref contains a different value for the maximum number of bits
5510supported. This changes structure sizes and so if you are using
5511RSAEURO, change the value of RSAref_MAX_BITS in rsa/rsaref.h
5512
5513
5514==== s_mult.doc ========================================================
5515
5516s_mult is a test program I hacked up on a Sunday for testing non-blocking
5517IO. It has a select loop at it's centre that handles multiple readers
5518and writers.
5519
5520Try the following command
5521ssleay s_mult -echo -nbio -ssl -v
5522echo - sends any sent text back to the sender
5523nbio - turns on non-blocking IO
5524ssl - accept SSL connections, default is normal text
5525v - print lots
5526 type Q<cr> to quit
5527
5528In another window, run the following
5529ssleay s_client -pause </etc/termcap
5530
5531The pause option puts in a 1 second pause in each read(2)/write(2) call
5532so the other end will have read()s fail.
5533
5534==== session.doc ========================================================
5535
5536I have just checked over and re-worked the session stuff.
5537The following brief example will ignore all setup information to do with
5538authentication.
5539
5540Things operate as follows.
5541
5542The SSL environment has a 'context', a SSL_CTX structure. This holds the
5543cached SSL_SESSIONS (which can be reused) and the certificate lookup
5544information. Each SSL structure needs to be associated with a SSL_CTX.
5545Normally only one SSL_CTX structure is needed per program.
5546
5547SSL_CTX *SSL_CTX_new(void );
5548void SSL_CTX_free(SSL_CTX *);
5549These 2 functions create and destroy SSL_CTX structures
5550
5551The SSL_CTX has a session_cache_mode which is by default,
5552in SSL_SESS_CACHE_SERVER mode. What this means is that the library
5553will automatically add new session-id's to the cache apon sucsessful
5554SSL_accept() calls.
5555If SSL_SESS_CACHE_CLIENT is set, then client certificates are also added
5556to the cache.
5557SSL_set_session_cache_mode(ctx,mode) will set the 'mode' and
5558SSL_get_session_cache_mode(ctx) will get the cache 'mode'.
5559The modes can be
5560SSL_SESS_CACHE_OFF - no caching
5561SSL_SESS_CACHE_CLIENT - only SSL_connect()
5562SSL_SESS_CACHE_SERVER - only SSL_accept()
5563SSL_SESS_NO_CACHE_BOTH - Either SSL_accept() or SSL_connect().
5564If SSL_SESS_CACHE_NO_AUTO_CLEAR is set, old timed out sessions are
5565not automatically removed each 255, SSL_connect()s or SSL_accept()s.
5566
5567By default, apon every 255 successful SSL_connect() or SSL_accept()s,
5568the cache is flush. Please note that this could be expensive on
5569a heavily loaded SSL server, in which case, turn this off and
5570clear the cache of old entries 'manually' (with one of the functions
5571listed below) every few hours. Perhaps I should up this number, it is hard
5572to say. Remember, the '255' new calls is just a mechanims to get called
5573every now and then, in theory at most 255 new session-id's will have been
5574added but if 100 are added every minute, you would still have
5575500 in the cache before any would start being flushed (assuming a 3 minute
5576timeout)..
5577
5578int SSL_CTX_sess_hits(SSL_CTX *ctx);
5579int SSL_CTX_sess_misses(SSL_CTX *ctx);
5580int SSL_CTX_sess_timeouts(SSL_CTX *ctx);
5581These 3 functions return statistics about the SSL_CTX. These 3 are the
5582number of session id reuses. hits is the number of reuses, misses are the
5583number of lookups that failed, and timeouts is the number of cached
5584entries ignored because they had timeouted.
5585
5586ctx->new_session_cb is a function pointer to a function of type
5587int new_session_callback(SSL *ssl,SSL_SESSION *new);
5588This function, if set in the SSL_CTX structure is called whenever a new
5589SSL_SESSION is added to the cache. If the callback returns non-zero, it
5590means that the application will have to do a SSL_SESSION_free()
5591on the structure (this is
5592to do with the cache keeping the reference counts correct, without the
5593application needing to know about it.
5594The 'active' parameter is the current SSL session for which this connection
5595was created.
5596
5597void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,int (*cb)());
5598to set the callback,
5599int (*cb)() SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)
5600to get the callback.
5601
5602If the 'get session' callback is set, when a session id is looked up and
5603it is not in the session-id cache, this callback is called. The callback is
5604of the form
5605SSL_SESSION *get_session_callback(unsigned char *sess_id,int sess_id_len,
5606 int *copy);
5607
5608The get_session_callback is intended to return null if no session id is found.
5609The reference count on the SSL_SESSION in incremented by the SSL library,
5610if copy is 1. Otherwise, the reference count is not modified.
5611
5612void SSL_CTX_sess_set_get_cb(ctx,cb) sets the callback and
5613int (*cb)()SSL_CTX_sess_get_get_cb(ctx) returns the callback.
5614
5615These callbacks are basically indended to be used by processes to
5616send their session-id's to other processes. I currently have not implemented
5617non-blocking semantics for these callbacks, it is upto the appication
5618to make the callbacks effiecent if they require blocking (perhaps
5619by 'saving' them and then 'posting them' when control returns from
5620the SSL_accept().
5621
5622LHASH *SSL_CTX_sessions(SSL_CTX *ctx)
5623This returns the session cache. The lhash strucutre can be accessed for
5624statistics about the cache.
5625
5626void lh_stats(LHASH *lh, FILE *out);
5627void lh_node_stats(LHASH *lh, FILE *out);
5628void lh_node_usage_stats(LHASH *lh, FILE *out);
5629
5630can be used to print details about it's activity and current state.
5631You can also delve directly into the lhash structure for 14 different
5632counters that are kept against the structure. When I wrote the lhash library,
5633I was interested in gathering statistics :-).
5634Have a read of doc/lhash.doc in the SSLeay distribution area for more details
5635on the lhash library.
5636
5637Now as mentioned ealier, when a SSL is created, it needs a SSL_CTX.
5638SSL * SSL_new(SSL_CTX *);
5639
5640This stores a session. A session is secret information shared between 2
5641SSL contexts. It will only be created if both ends of the connection have
5642authenticated their peer to their satisfaction. It basically contains
5643the information required to use a particular secret key cipher.
5644
5645To retrieve the SSL_CTX being used by a SSL,
5646SSL_CTX *SSL_get_SSL_CTX(SSL *s);
5647
5648Now when a SSL session is established between to programs, the 'session'
5649information that is cached in the SSL_CTX can me manipulated by the
5650following functions.
5651int SSL_set_session(SSL *s, SSL_SESSION *session);
5652This will set the SSL_SESSION to use for the next SSL_connect(). If you use
5653this function on an already 'open' established SSL connection, 'bad things
5654will happen'. This function is meaning-less when used on a ssl strucutre
5655that is just about to be used in a SSL_accept() call since the
5656SSL_accept() will either create a new session or retrieve one from the
5657cache.
5658
5659SSL_SESSION *SSL_get_session(SSL *s);
5660This will return the SSL_SESSION for the current SSL, NULL if there is
5661no session associated with the SSL structure.
5662
5663The SSL sessions are kept in the SSL_CTX in a hash table, to remove a
5664session
5665void SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
5666and to add one
5667int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
5668SSL_CTX_add_session() returns 1 if the session was already in the cache (so it
5669was not added).
5670Whenever a new session is created via SSL_connect()/SSL_accept(),
5671they are automatically added to the cache, depending on the session_cache_mode
5672settings. SSL_set_session()
5673does not add it to the cache. Just call SSL_CTX_add_session() if you do want the
5674session added. For a 'client' this would not normally be the case.
5675SSL_CTX_add_session() is not normally ever used, except for doing 'evil' things
5676which the next 2 funtions help you do.
5677
5678int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
5679SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
5680These 2 functions are in the standard ASN1 library form and can be used to
5681load and save to a byte format, the SSL_SESSION structure.
5682With these functions, you can save and read these structures to a files or
5683arbitary byte string.
5684The PEM_write_SSL_SESSION(fp,x) and PEM_read_SSL_SESSION(fp,x,cb) will
5685write to a file pointer in base64 encoding.
5686
5687What you can do with this, is pass session information between separate
5688processes. Please note, that you will probably also need to modify the
5689timeout information on the SSL_SESSIONs.
5690
5691long SSL_get_time(SSL_SESSION *s)
5692will return the 'time' that the session
5693was loaded. The timeout is relative to this time. This information is
5694saved when the SSL_SESSION is converted to binarary but it is stored
5695in as a unix long, which is rather OS dependant, but easy to convert back.
5696
5697long SSL_set_time(SSL_SESSION *s,long t) will set the above mentioned time.
5698The time value is just the value returned from time(3), and should really
5699be defined by be to be time_t.
5700
5701long SSL_get_timeout(SSL_SESSION *s);
5702long SSL_set_timeout(SSL_SESSION *s,long t);
5703These 2 retrieve and set the timeout which is just a number of secconds
5704from the 'SSL_get_time()' value. When this time period has elapesed,
5705the session will no longer be in the cache (well it will actually be removed
5706the next time it is attempted to be retrieved, so you could 'bump'
5707the timeout so it remains valid).
5708The 'time' and 'timeout' are set on a session when it is created, not reset
5709each time it is reused. If you did wish to 'bump it', just after establishing
5710a connection, do a
5711SSL_set_time(ssl,time(NULL));
5712
5713You can also use
5714SSL_CTX_set_timeout(SSL_CTX *ctx,unsigned long t) and
5715SSL_CTX_get_timeout(SSL_CTX *ctx) to manipulate the default timeouts for
5716all SSL connections created against a SSL_CTX. If you set a timeout in
5717an SSL_CTX, all new SSL's created will inherit the timeout. It can be over
5718written by the SSL_set_timeout(SSL *s,unsigned long t) function call.
5719If you 'set' the timeout back to 0, the system default will be used.
5720
5721SSL_SESSION *SSL_SESSION_new();
5722void SSL_SESSION_free(SSL_SESSION *ses);
5723These 2 functions are used to create and dispose of SSL_SESSION functions.
5724You should not ever normally need to use them unless you are using
5725i2d_SSL_SESSION() and/or d2i_SSL_SESSION(). If you 'load' a SSL_SESSION
5726via d2i_SSL_SESSION(), you will need to SSL_SESSION_free() it.
5727Both SSL_set_session() and SSL_CTX_add_session() will 'take copies' of the
5728structure (via reference counts) when it is passed to them.
5729
5730SSL_CTX_flush_sessions(ctx,time);
5731The first function will clear all sessions from the cache, which have expired
5732relative to 'time' (which could just be time(NULL)).
5733
5734SSL_CTX_flush_sessions(ctx,0);
5735This is a special case that clears everything.
5736
5737As a final comment, a 'session' is not enough to establish a new
5738connection. If a session has timed out, a certificate and private key
5739need to have been associated with the SSL structure.
5740SSL_copy_session_id(SSL *to,SSL *from); will copy not only the session
5741strucutre but also the private key and certificate associated with
5742'from'.
5743
5744EXAMPLES.
5745
5746So lets play at being a wierd SSL server.
5747
5748/* setup a context */
5749ctx=SSL_CTX_new();
5750
5751/* Lets load some session from binary into the cache, why one would do
5752 * this is not toally clear, but passing between programs does make sense
5753 * Perhaps you are using 4096 bit keys and are happy to keep them
5754 * valid for a week, to avoid the RSA overhead of 15 seconds, I'm not toally
5755 * sure, perhaps this is a process called from an SSL inetd and this is being
5756 * passed to the application. */
5757session=d2i_SSL_SESSION(....)
5758SSL_CTX_add_session(ctx,session);
5759
5760/* Lets even add a session from a file */
5761session=PEM_read_SSL_SESSION(....)
5762SSL_CTX_add_session(ctx,session);
5763
5764/* create a new SSL structure */
5765ssl=SSL_new(ctx);
5766
5767/* At this point we want to be able to 'create' new session if
5768 * required, so we need a certificate and RSAkey. */
5769SSL_use_RSAPrivateKey_file(ssl,...)
5770SSL_use_certificate_file(ssl,...)
5771
5772/* Now since we are a server, it make little sence to load a session against
5773 * the ssl strucutre since a SSL_accept() will either create a new session or
5774 * grab an existing one from the cache. */
5775
5776/* grab a socket descriptor */
5777fd=accept(...);
5778
5779/* associated it with the ssl strucutre */
5780SSL_set_fd(ssl,fd);
5781
5782SSL_accept(ssl); /* 'do' SSL using out cert and RSA key */
5783
5784/* Lets print out the session details or lets save it to a file,
5785 * perhaps with a secret key cipher, so that we can pass it to the FBI
5786 * when they want to decode the session :-). While we have RSA
5787 * this does not matter much but when I do SSLv3, this will allow a mechanism
5788 * for the server/client to record the information needed to decode
5789 * the traffic that went over the wire, even when using Diffie-Hellman */
5790PEM_write_SSL_SESSION(SSL_get_session(ssl),stdout,....)
5791
5792Lets 'connect' back to the caller using the same session id.
5793
5794ssl2=SSL_new(ctx);
5795fd2=connect(them);
5796SSL_set_fd(ssl2,fd2);
5797SSL_set_session(ssl2,SSL_get_session(ssl));
5798SSL_connect(ssl2);
5799
5800/* what the hell, lets accept no more connections using this session */
5801SSL_CTX_remove_session(SSL_get_SSL_CTX(ssl),SSL_get_session(ssl));
5802
5803/* we could have just as easily used ssl2 since they both are using the
5804 * same session.
5805 * You will note that both ssl and ssl2 are still using the session, and
5806 * the SSL_SESSION structure will be free()ed when both ssl and ssl2
5807 * finish using the session. Also note that you could continue to initiate
5808 * connections using this session by doing SSL_get_session(ssl) to get the
5809 * existing session, but SSL_accept() will not be able to find it to
5810 * use for incoming connections.
5811 * Of corse, the session will timeout at the far end and it will no
5812 * longer be accepted after a while. The time and timeout are ignored except
5813 * by SSL_accept(). */
5814
5815/* Since we have had our server running for 10 weeks, and memory is getting
5816 * short, perhaps we should clear the session cache to remove those
5817 * 100000 session entries that have expired. Some may consider this
5818 * a memory leak :-) */
5819
5820SSL_CTX_flush_sessions(ctx,time(NULL));
5821
5822/* Ok, after a bit more time we wish to flush all sessions from the cache
5823 * so that all new connections will be authenticated and incure the
5824 * public key operation overhead */
5825
5826SSL_CTX_flush_sessions(ctx,0);
5827
5828/* As a final note, to copy everything to do with a SSL, use */
5829SSL_copy_session_id(SSL *to,SSL *from);
5830/* as this also copies the certificate and RSA key so new session can
5831 * be established using the same details */
5832
5833
5834==== sha.doc ========================================================
5835
5836The SHA (Secure Hash Algorithm) library.
5837SHA is a message digest algorithm that can be used to condense an arbitrary
5838length message down to a 20 byte hash. The functions all need to be passed
5839a SHA_CTX which is used to hold the SHA context during multiple SHA_Update()
5840function calls. The normal method of use for this library is as follows
5841This library contains both SHA and SHA-1 digest algorithms. SHA-1 is
5842an update to SHA (which should really be called SHA-0 now) which
5843tweaks the algorithm slightly. The SHA-1 algorithm is used by simply
5844using SHA1_Init(), SHA1_Update(), SHA1_Final() and SHA1() instead of the
5845SHA*() calls
5846
5847SHA_Init(...);
5848SHA_Update(...);
5849...
5850SHA_Update(...);
5851SHA_Final(...);
5852
5853This library requires the inclusion of 'sha.h'.
5854
5855The functions are as follows:
5856
5857void SHA_Init(
5858SHA_CTX *c);
5859 This function needs to be called to initiate a SHA_CTX structure for
5860 use.
5861
5862void SHA_Update(
5863SHA_CTX *c;
5864unsigned char *data;
5865unsigned long len);
5866 This updates the message digest context being generated with 'len'
5867 bytes from the 'data' pointer. The number of bytes can be any
5868 length.
5869
5870void SHA_Final(
5871unsigned char *md;
5872SHA_CTX *c;
5873 This function is called when a message digest of the data digested
5874 with SHA_Update() is wanted. The message digest is put in the 'md'
5875 array and is SHA_DIGEST_LENGTH (20) bytes long.
5876
5877unsigned char *SHA(
5878unsigned char *d;
5879unsigned long n;
5880unsigned char *md;
5881 This function performs a SHA_Init(), followed by a SHA_Update()
5882 followed by a SHA_Final() (using a local SHA_CTX).
5883 The resulting digest is put into 'md' if it is not NULL.
5884 Regardless of the value of 'md', the message
5885 digest is returned from the function. If 'md' was NULL, the message
5886 digest returned is being stored in a static structure.
5887
5888
5889==== speed.doc ========================================================
5890
5891To get an idea of the performance of this library, use
5892ssleay speed
5893
5894perl util/sp-diff.pl file1 file2
5895
5896will print out the relative differences between the 2 files which are
5897expected to be the output from the speed program.
5898
5899The performace of the library is very dependant on the Compiler
5900quality and various flags used to build.
5901
5902---
5903
5904These are some numbers I did comparing RSAref and SSLeay on a Pentium 100.
5905[ These numbers are all out of date, as of SSL - 0.6.1 the RSA
5906operations are about 2 times faster, so check the version number ]
5907
5908RSA performance.
5909
5910SSLeay 0.6.0
5911Pentium 100, 32meg, Windows NT Workstation 3.51
5912linux - gcc v 2.7.0 -O3 -fomit-frame-pointer -m486
5913and
5914Windows NT - Windows NT 3.51 - Visual C++ 4.1 - 586 code + 32bit assember
5915Windows 3.1 - Windows NT 3.51 - Visual C++ 1.52c - 286 code + 32bit assember
5916NT Dos Shell- Windows NT 3.51 - Visual C++ 1.52c - 286 code + 16bit assember
5917
5918Times are how long it takes to do an RSA private key operation.
5919
5920 512bits 1024bits
5921-------------------------------
5922SSLeay NT dll 0.042s 0.202s see above
5923SSLeay linux 0.046s 0.218s Assember inner loops (normal build)
5924SSLeay linux 0.067s 0.380s Pure C code with BN_LLONG defined
5925SSLeay W3.1 dll 0.108s 0.478s see above
5926SSLeay linux 0.109s 0.713s C without BN_LLONG.
5927RSAref2.0 linux 0.149s 0.936s
5928SSLeay MS-DOS 0.197s 1.049s see above
5929
5930486DX66, 32meg, Windows NT Server 3.51
5931 512bits 1024bits
5932-------------------------------
5933SSLeay NT dll 0.084s 0.495s <- SSLeay 0.6.3
5934SSLeay NT dll 0.154s 0.882s
5935SSLeay W3.1 dll 0.335s 1.538s
5936SSLeay MS-DOS 0.490s 2.790s
5937
5938What I find cute is that I'm still faster than RSAref when using standard C,
5939without using the 'long long' data type :-), %35 faster for 512bit and we
5940scale up to 3.2 times faster for the 'default linux' build. I should mention
5941that people should 'try' to use either x86-lnx.s (elf), x86-lnxa.s or
5942x86-sol.s for any x86 based unix they are building on. The only problems
5943with be with syntax but the performance gain is quite large, especially for
5944servers. The code is very simple, you just need to modify the 'header'.
5945
5946The message is, if you are stuck using RSAref, the RSA performance will be
5947bad. Considering the code was compiled for a pentium, the 486DX66 number
5948would indicate 'Use RSAref and turn you Pentium 100 into a 486DX66' :-).
5949[ As of verson 0.6.1, it would be correct to say 'turn you pentium 100
5950 into a 486DX33' :-) ]
5951
5952I won't tell people if the DLL's are using RSAref or my stuff if no-one
5953asks :-).
5954
5955eric
5956
5957PS while I know I could speed things up further, I will probably not do
5958 so due to the effort involved. I did do some timings on the
5959 SSLeay bignum format -> RSAref number format conversion that occurs
5960 each time RSAref is used by SSLeay, and the numbers are trivial.
5961 0.00012s a call for 512bit vs 0.149s for the time spent in the function.
5962 0.00018s for 1024bit vs 0.938s. Insignificant.
5963 So the 'way to go', to support faster RSA libraries, if people are keen,
5964 is to write 'glue' code in a similar way that I do for RSAref and send it
5965 to me :-).
5966 My base library still has the advantage of being able to operate on
5967 any size numbers, and is not that far from the performance from the
5968 leaders in the field. (-%30?)
5969 [ Well as of 0.6.1 I am now the leader in the filed on x86 (we at
5970 least very close :-) ]
5971
5972 I suppose I should also mention some other numbers RSAref numbers, again
5973 on my Pentium.
5974 DES CBC EDE-DES MD5
5975 RSAref linux 830k/s 302k/s 4390k/s
5976 SSLeay linux 855k/s 319k/s 10025k/s
5977 SSLeay NT 1158k/s 410k/s 10470k/s
5978 SSLeay w31 378k/s 143k/s 2383k/s (fully 16bit)
5979
5980 Got to admit that Visual C++ 4.[01] is a damn fine compiler :-)
5981--
5982Eric Young | BOOL is tri-state according to Bill Gates.
5983AARNet: eay@cryptsoft.com | RTFM Win32 GetMessage().
5984
5985
5986
5987
5988==== ssl-ciph.doc ========================================================
5989
5990This is a quick high level summery of how things work now.
5991
5992Each SSLv2 and SSLv3 cipher is composed of 4 major attributes plus a few extra
5993minor ones.
5994
5995They are 'The key exchange algorithm', which is RSA for SSLv2 but can also
5996be Diffle-Hellman for SSLv3.
5997
5998An 'Authenticion algorithm', which can be RSA, Diffle-Helman, DSS or
5999none.
6000
6001The cipher
6002
6003The MAC digest.
6004
6005A cipher can also be an export cipher and is either an SSLv2 or a
6006SSLv3 ciphers.
6007
6008To specify which ciphers to use, one can either specify all the ciphers,
6009one at a time, or use 'aliases' to specify the preference and order for
6010the ciphers.
6011
6012There are a large number of aliases, but the most importaint are
6013kRSA, kDHr, kDHd and kEDH for key exchange types.
6014
6015aRSA, aDSS, aNULL and aDH for authentication
6016DES, 3DES, RC4, RC2, IDEA and eNULL for ciphers
6017MD5, SHA0 and SHA1 digests
6018
6019Now where this becomes interesting is that these can be put together to
6020specify the order and ciphers you wish to use.
6021
6022To speed this up there are also aliases for certian groups of ciphers.
6023The main ones are
6024SSLv2 - all SSLv2 ciphers
6025SSLv3 - all SSLv3 ciphers
6026EXP - all export ciphers
6027LOW - all low strngth ciphers (no export ciphers, normally single DES)
6028MEDIUM - 128 bit encryption
6029HIGH - Triple DES
6030
6031These aliases can be joined in a : separated list which specifies to
6032add ciphers, move them to the current location and delete them.
6033
6034A simpler way to look at all of this is to use the 'ssleay ciphers -v' command.
6035The default library cipher spec is
6036!ADH:RC4+RSA:HIGH:MEDIUM:LOW:EXP:+SSLv2:+EXP
6037which means, first, remove from consideration any ciphers that do not
6038authenticate. Next up, use ciphers using RC4 and RSA. Next include the HIGH,
6039MEDIUM and the LOW security ciphers. Finish up by adding all the export
6040ciphers on the end, then 'pull' all the SSLv2 and export ciphers to
6041the end of the list.
6042
6043The results are
6044$ ssleay ciphers -v '!ADH:RC4+RSA:HIGH:MEDIUM:LOW:EXP:+SSLv2:+EXP'
6045
6046RC4-SHA SSLv3 Kx=RSA Au=RSA Enc=RC4(128) Mac=SHA1
6047RC4-MD5 SSLv3 Kx=RSA Au=RSA Enc=RC4(128) Mac=MD5
6048EDH-RSA-DES-CBC3-SHA SSLv3 Kx=DH Au=RSA Enc=3DES(168) Mac=SHA1
6049EDH-DSS-DES-CBC3-SHA SSLv3 Kx=DH Au=DSS Enc=3DES(168) Mac=SHA1
6050DES-CBC3-SHA SSLv3 Kx=RSA Au=RSA Enc=3DES(168) Mac=SHA1
6051IDEA-CBC-MD5 SSLv3 Kx=RSA Au=RSA Enc=IDEA(128) Mac=SHA1
6052EDH-RSA-DES-CBC-SHA SSLv3 Kx=DH Au=RSA Enc=DES(56) Mac=SHA1
6053EDH-DSS-DES-CBC-SHA SSLv3 Kx=DH Au=DSS Enc=DES(56) Mac=SHA1
6054DES-CBC-SHA SSLv3 Kx=RSA Au=RSA Enc=DES(56) Mac=SHA1
6055DES-CBC3-MD5 SSLv2 Kx=RSA Au=RSA Enc=3DES(168) Mac=MD5
6056DES-CBC-MD5 SSLv2 Kx=RSA Au=RSA Enc=DES(56) Mac=MD5
6057IDEA-CBC-MD5 SSLv2 Kx=RSA Au=RSA Enc=IDEA(128) Mac=MD5
6058RC2-CBC-MD5 SSLv2 Kx=RSA Au=RSA Enc=RC2(128) Mac=MD5
6059RC4-MD5 SSLv2 Kx=RSA Au=RSA Enc=RC4(128) Mac=MD5
6060EXP-EDH-RSA-DES-CBC SSLv3 Kx=DH(512) Au=RSA Enc=DES(40) Mac=SHA1 export
6061EXP-EDH-DSS-DES-CBC-SHA SSLv3 Kx=DH(512) Au=DSS Enc=DES(40) Mac=SHA1 export
6062EXP-DES-CBC-SHA SSLv3 Kx=RSA(512) Au=RSA Enc=DES(40) Mac=SHA1 export
6063EXP-RC2-CBC-MD5 SSLv3 Kx=RSA(512) Au=RSA Enc=RC2(40) Mac=MD5 export
6064EXP-RC4-MD5 SSLv3 Kx=RSA(512) Au=RSA Enc=RC4(40) Mac=MD5 export
6065EXP-RC2-CBC-MD5 SSLv2 Kx=RSA(512) Au=RSA Enc=RC2(40) Mac=MD5 export
6066EXP-RC4-MD5 SSLv2 Kx=RSA(512) Au=RSA Enc=RC4(40) Mac=MD5 export
6067
6068I would recoment people use the 'ssleay ciphers -v "text"'
6069command to check what they are going to use.
6070
6071Anyway, I'm falling asleep here so I'll do some more tomorrow.
6072
6073eric
6074
6075==== ssl.doc ========================================================
6076
6077SSL_CTX_sessions(SSL_CTX *ctx) - the session-id hash table.
6078
6079/* Session-id cache stats */
6080SSL_CTX_sess_number
6081SSL_CTX_sess_connect
6082SSL_CTX_sess_connect_good
6083SSL_CTX_sess_accept
6084SSL_CTX_sess_accept_good
6085SSL_CTX_sess_hits
6086SSL_CTX_sess_cb_hits
6087SSL_CTX_sess_misses
6088SSL_CTX_sess_timeouts
6089
6090/* Session-id application notification callbacks */
6091SSL_CTX_sess_set_new_cb
6092SSL_CTX_sess_get_new_cb
6093SSL_CTX_sess_set_get_cb
6094SSL_CTX_sess_get_get_cb
6095
6096/* Session-id cache operation mode */
6097SSL_CTX_set_session_cache_mode
6098SSL_CTX_get_session_cache_mode
6099
6100/* Set default timeout values to use. */
6101SSL_CTX_set_timeout
6102SSL_CTX_get_timeout
6103
6104/* Global SSL initalisation informational callback */
6105SSL_CTX_set_info_callback
6106SSL_CTX_get_info_callback
6107SSL_set_info_callback
6108SSL_get_info_callback
6109
6110/* If the SSL_accept/SSL_connect returned with -1, these indicate when
6111 * we should re-call *.
6112SSL_want
6113SSL_want_nothing
6114SSL_want_read
6115SSL_want_write
6116SSL_want_x509_lookup
6117
6118/* Where we are in SSL initalisation, used in non-blocking, perhaps
6119 * have a look at ssl/bio_ssl.c */
6120SSL_state
6121SSL_is_init_finished
6122SSL_in_init
6123SSL_in_connect_init
6124SSL_in_accept_init
6125
6126/* Used to set the 'inital' state so SSL_in_connect_init and SSL_in_accept_init
6127 * can be used to work out which function to call. */
6128SSL_set_connect_state
6129SSL_set_accept_state
6130
6131/* Where to look for certificates for authentication */
6132SSL_set_default_verify_paths /* calles SSL_load_verify_locations */
6133SSL_load_verify_locations
6134
6135/* get info from an established connection */
6136SSL_get_session
6137SSL_get_certificate
6138SSL_get_SSL_CTX
6139
6140SSL_CTX_new
6141SSL_CTX_free
6142SSL_new
6143SSL_clear
6144SSL_free
6145
6146SSL_CTX_set_cipher_list
6147SSL_get_cipher
6148SSL_set_cipher_list
6149SSL_get_cipher_list
6150SSL_get_shared_ciphers
6151
6152SSL_accept
6153SSL_connect
6154SSL_read
6155SSL_write
6156
6157SSL_debug
6158
6159SSL_get_read_ahead
6160SSL_set_read_ahead
6161SSL_set_verify
6162
6163SSL_pending
6164
6165SSL_set_fd
6166SSL_set_rfd
6167SSL_set_wfd
6168SSL_set_bio
6169SSL_get_fd
6170SSL_get_rbio
6171SSL_get_wbio
6172
6173SSL_use_RSAPrivateKey
6174SSL_use_RSAPrivateKey_ASN1
6175SSL_use_RSAPrivateKey_file
6176SSL_use_PrivateKey
6177SSL_use_PrivateKey_ASN1
6178SSL_use_PrivateKey_file
6179SSL_use_certificate
6180SSL_use_certificate_ASN1
6181SSL_use_certificate_file
6182
6183ERR_load_SSL_strings
6184SSL_load_error_strings
6185
6186/* human readable version of the 'state' of the SSL connection. */
6187SSL_state_string
6188SSL_state_string_long
6189/* These 2 report what kind of IO operation the library was trying to
6190 * perform last. Probably not very usefull. */
6191SSL_rstate_string
6192SSL_rstate_string_long
6193
6194SSL_get_peer_certificate
6195
6196SSL_SESSION_new
6197SSL_SESSION_print_fp
6198SSL_SESSION_print
6199SSL_SESSION_free
6200i2d_SSL_SESSION
6201d2i_SSL_SESSION
6202
6203SSL_get_time
6204SSL_set_time
6205SSL_get_timeout
6206SSL_set_timeout
6207SSL_copy_session_id
6208SSL_set_session
6209SSL_CTX_add_session
6210SSL_CTX_remove_session
6211SSL_CTX_flush_sessions
6212
6213BIO_f_ssl
6214
6215/* used to hold information as to why a certificate verification failed */
6216SSL_set_verify_result
6217SSL_get_verify_result
6218
6219/* can be used by the application to associate data with an SSL structure.
6220 * It needs to be 'free()ed' by the application */
6221SSL_set_app_data
6222SSL_get_app_data
6223
6224/* The following all set values that are kept in the SSL_CTX but
6225 * are used as the default values when an SSL session is created.
6226 * They are over writen by the relevent SSL_xxxx functions */
6227
6228/* SSL_set_verify */
6229void SSL_CTX_set_default_verify
6230
6231/* This callback, if set, totaly overrides the normal SSLeay verification
6232 * functions and should return 1 on sucesss and 0 on failure */
6233void SSL_CTX_set_cert_verify_callback
6234
6235/* The following are the same as the equivilent SSL_xxx functions.
6236 * Only one copy of this information is kept and if a particular
6237 * SSL structure has a local override, it is totally separate structure.
6238 */
6239int SSL_CTX_use_RSAPrivateKey
6240int SSL_CTX_use_RSAPrivateKey_ASN1
6241int SSL_CTX_use_RSAPrivateKey_file
6242int SSL_CTX_use_PrivateKey
6243int SSL_CTX_use_PrivateKey_ASN1
6244int SSL_CTX_use_PrivateKey_file
6245int SSL_CTX_use_certificate
6246int SSL_CTX_use_certificate_ASN1
6247int SSL_CTX_use_certificate_file
6248
6249
6250==== ssl_ctx.doc ========================================================
6251
6252This is now a bit dated, quite a few of the SSL_ functions could be
6253SSL_CTX_ functions. I will update this in the future. 30 Aug 1996
6254
6255From eay@orb.mincom.oz.au Mon Dec 11 21:37:08 1995
6256Received: by orb.mincom.oz.au id AA00696
6257 (5.65c/IDA-1.4.4 for eay); Mon, 11 Dec 1995 11:37:08 +1000
6258Date: Mon, 11 Dec 1995 11:37:08 +1000 (EST)
6259From: Eric Young <eay@mincom.oz.au>
6260X-Sender: eay@orb
6261To: sameer <sameer@c2.org>
6262Cc: Eric Young <eay@mincom.oz.au>
6263Subject: Re: PEM_readX509 oesn't seem to be working
6264In-Reply-To: <199512110102.RAA12521@infinity.c2.org>
6265Message-Id: <Pine.SOL.3.91.951211112115.28608D-100000@orb>
6266Mime-Version: 1.0
6267Content-Type: TEXT/PLAIN; charset=US-ASCII
6268Status: RO
6269X-Status:
6270
6271On Sun, 10 Dec 1995, sameer wrote:
6272> OK, that's solved. I've found out that it is saying "no
6273> certificate set" in SSL_accept because s->conn == NULL
6274> so there is some place I need to initialize s->conn that I am
6275> not initializing it.
6276
6277The full order of things for a server should be.
6278
6279ctx=SSL_CTX_new();
6280
6281/* The next line should not really be using ctx->cert but I'll leave it
6282 * this way right now... I don't want a X509_ routine to know about an SSL
6283 * structure, there should be an SSL_load_verify_locations... hmm, I may
6284 * add it tonight.
6285 */
6286X509_load_verify_locations(ctx->cert,CAfile,CApath);
6287
6288/* Ok now for each new connection we do the following */
6289con=SSL_new(ctx);
6290SSL_set_fd(con,s);
6291SSL_set_verify(con,verify,verify_callback);
6292
6293/* set the certificate and private key to use. */
6294SSL_use_certificate_ASN1(con,X509_certificate);
6295SSL_use_RSAPrivateKey_ASN1(con,RSA_private_key);
6296
6297SSL_accept(con);
6298
6299SSL_read(con)/SSL_write(con);
6300
6301There is a bit more than that but that is basically the structure.
6302
6303Create a context and specify where to lookup certificates.
6304
6305foreach connection
6306 {
6307 create a SSL structure
6308 set the certificate and private key
6309 do a SSL_accept
6310
6311 we should now be ok
6312 }
6313
6314eric
6315--
6316Eric Young | Signature removed since it was generating
6317AARNet: eay@mincom.oz.au | more followups than the message contents :-)
6318
6319
6320
6321==== ssleay.doc ========================================================
6322
6323SSLeay: a cryptographic kitchen sink.
6324
63251st December 1995
6326Way back at the start of April 1995, I was looking for a mindless
6327programming project. A friend of mine (Tim Hudson) said "why don't you do SSL,
6328it has DES encryption in it and I would not mind using it in a SSL telnet".
6329While it was true I had written a DES library in previous years, litle
6330did I know what an expansive task SSL would turn into.
6331
6332First of all, the SSL protocol contains DES encryption. Well and good. My
6333DES library was fast and portable. It also contained the RSA's RC4 stream
6334cipher. Again, not a problem, some-one had just posted to sci.crypt
6335something that was claimed to be RC4. It also contained IDEA, I had the
6336specifications, not a problem to implement. MD5, an RFC, trivial, at most
6337I could spend a week or so trying to see if I could speed up the
6338implementation. All in all a nice set of ciphers.
6339Then the first 'expantion of the scope', RSA public key
6340encryption. Since I did not knowing a thing about public key encryption
6341or number theory, this appeared quite a daunting task. Just writing a
6342big number library would be problomatic in itself, let alone making it fast.
6343At this point the scope of 'implementing SSL' expands eponentialy.
6344First of all, the RSA private keys were being kept in ASN.1 format.
6345Thankfully the RSA PKCS series of documents explains this format. So I now
6346needed to be able to encode and decode arbitary ASN.1 objects. The Public
6347keys were embeded in X509 certificates. Hmm... these are not only
6348ASN.1 objects but they make up a heirachy of authentication. To
6349authenticate a X509 certificate one needs to retrieve it's issuers
6350certificate etc etc. Hmm..., so I also need to implement some kind
6351of certificate management software. I would also have to implement
6352software to authenticate certificates. At this point the support code made
6353the SSL part of my library look quite small.
6354Around this time, the first version of SSLeay was released.
6355
6356Ah, but here was the problem, I was not happy with the code so far. As may
6357have become obvious, I had been treating all of this as a learning
6358exersize, so I have completely written the library myself. As such, due
6359to the way it had grown like a fungus, much of the library was not
6360'elagent' or neat. There were global and static variables all over the
6361place, the SSL part did not even handle non-blocking IO.
6362The Great rewrite began.
6363
6364As of this point in time, the 'Great rewrite' has almost finished. So what
6365follows is an approximate list of what is actually SSLeay 0.5.0
6366
6367/********* This needs to be updated for 0.6.0+ *************/
6368
6369---
6370The library contains the following routines. Please note that most of these
6371functions are not specfic for SSL or any other particular cipher
6372implementation. I have tried to make all the routines as general purpose
6373as possible. So you should not think of this library as an SSL
6374implemtation, but rather as a library of cryptographic functions
6375that also contains SSL. I refer to each of these function groupings as
6376libraries since they are often capable of functioning as independant
6377libraries
6378
6379First up, the general ciphers and message digests supported by the library.
6380
6381MD2 rfc???, a standard 'by parts' interface to this algorithm.
6382MD5 rfc???, the same type of interface as for the MD2 library except a
6383 different algorithm.
6384SHA THe Secure Hash Algorithm. Again the same type of interface as
6385 MD2/MD5 except the digest is 20 bytes.
6386SHA1 The 'revised' version of SHA. Just about identical to SHA except
6387 for one tweak of an inner loop.
6388DES This is my libdes library that has been floating around for the last
6389 few years. It has been enhanced for no other reason than completeness.
6390 It now supports ecb, cbc, cfb, ofb, cfb64, ofb64 in normal mode and
6391 triple DES modes of ecb, cbc, cfb64 and ofb64. cfb64 and ofb64 are
6392 functional interfaces to the 64 bit modes of cfb and ofb used in
6393 such a way thay they function as single character interfaces.
6394RC4 The RSA Inc. stream cipher.
6395RC2 The RSA Inc. block cipher.
6396IDEA An implmentation of the IDEA cipher, the library supports ecb, cbc,
6397 cfb64 and ofb64 modes of operation.
6398
6399Now all the above mentioned ciphers and digests libraries support high
6400speed, minimal 'crap in the way' type interfaces. For fastest and
6401lowest level access, these routines should be used directly.
6402
6403Now there was also the matter of public key crypto systems. These are
6404based on large integer arithmatic.
6405
6406BN This is my large integer library. It supports all the normal
6407 arithmentic operations. It uses malloc extensivly and as such has
6408 no limits of the size of the numbers being manipulated. If you
6409 wish to use 4000 bit RSA moduli, these routines will handle it.
6410 This library also contains routines to 'generate' prime numbers and
6411 to test for primality. The RSA and DH libraries sit on top of this
6412 library. As of this point in time, I don't support SHA, but
6413 when I do add it, it will just sit on top of the routines contained
6414 in this library.
6415RSA This implements the RSA public key algorithm. It also contains
6416 routines that will generate a new private/public key pair.
6417 All the RSA functions conform to the PKCS#1 standard.
6418DH This is an implementation of the
6419 Diffie-Hellman protocol. There are all the require routines for
6420 the protocol, plus extra routines that can be used to generate a
6421 strong prime for use with a specified generator. While this last
6422 routine is not generally required by applications implementing DH,
6423 It is present for completeness and because I thing it is much
6424 better to be able to 'generate' your own 'magic' numbers as oposed
6425 to using numbers suplied by others. I conform to the PKCS#3
6426 standard where required.
6427
6428You may have noticed the preceeding section mentions the 'generation' of
6429prime numbers. Now this requries the use of 'random numbers'.
6430
6431RAND This psuedo-random number library is based on MD5 at it's core
6432 and a large internal state (2k bytes). Once you have entered enough
6433 seed data into this random number algorithm I don't feel
6434 you will ever need to worry about it generating predictable output.
6435 Due to the way I am writing a portable library, I have left the
6436 issue of how to get good initial random seed data upto the
6437 application but I do have support routines for saving and loading a
6438 persistant random number state for use between program runs.
6439
6440Now to make all these ciphers easier to use, a higher level
6441interface was required. In this form, the same function would be used to
6442encrypt 'by parts', via any one of the above mentioned ciphers.
6443
6444EVP The Digital EnVeloPe library is quite large. At it's core are
6445 function to perform encryption and decryption by parts while using
6446 an initial parameter to specify which of the 17 different ciphers
6447 or 4 different message digests to use. On top of these are implmented
6448 the digital signature functions, sign, verify, seal and open.
6449 Base64 encoding of binary data is also done in this library.
6450
6451PEM rfc???? describe the format for Privacy Enhanced eMail.
6452 As part of this standard, methods of encoding digital enveloped
6453 data is an ascii format are defined. As such, I use a form of these
6454 to encode enveloped data. While at this point in time full support
6455 for PEM has not been built into the library, a minimal subset of
6456 the secret key and Base64 encoding is present. These reoutines are
6457 mostly used to Ascii encode binary data with a 'type' associated
6458 with it and perhaps details of private key encryption used to
6459 encrypt the data.
6460
6461PKCS7 This is another Digital Envelope encoding standard which uses ASN.1
6462 to encode the data. At this point in time, while there are some
6463 routines to encode and decode this binary format, full support is
6464 not present.
6465
6466As Mentioned, above, there are several different ways to encode
6467data structures.
6468
6469ASN1 This library is more a set of primatives used to encode the packing
6470 and unpacking of data structures. It is used by the X509
6471 certificate standard and by the PKCS standards which are used by
6472 this library. It also contains routines for duplicating and signing
6473 the structures asocisated with X509.
6474
6475X509 The X509 library contains routines for packing and unpacking,
6476 verifying and just about every thing else you would want to do with
6477 X509 certificates.
6478
6479PKCS7 PKCS-7 is a standard for encoding digital envelope data
6480 structures. At this point in time the routines will load and save
6481 DER forms of these structees. They need to be re-worked to support
6482 the BER form which is the normal way PKCS-7 is encoded. If the
6483 previous 2 sentances don't make much sense, don't worry, this
6484 library is not used by this version of SSLeay anyway.
6485
6486OBJ ASN.1 uses 'object identifiers' to identify objects. A set of
6487 functions were requred to translate from ASN.1 to an intenger, to a
6488 character string. This library provieds these translations
6489
6490Now I mentioned an X509 library. X509 specified a hieachy of certificates
6491which needs to be traversed to authenticate particular certificates.
6492
6493METH This library is used to push 'methods' of retrieving certificates
6494 into the library. There are some supplied 'methods' with SSLeay
6495 but applications can add new methods if they so desire.
6496 This library has not been finished and is not being used in this
6497 version.
6498
6499Now all the above are required for use in the initial point of this project.
6500
6501SSL The SSL protocol. This is a full implmentation of SSL v 2. It
6502 support both server and client authentication. SSL v 3 support
6503 will be added when the SSL v 3 specification is released in it's
6504 final form.
6505
6506Now quite a few of the above mentioned libraries rely on a few 'complex'
6507data structures. For each of these I have a library.
6508
6509Lhash This is a hash table library which is used extensivly.
6510
6511STACK An implemetation of a Stack data structure.
6512
6513BUF A simple character array structure that also support a function to
6514 check that the array is greater that a certain size, if it is not,
6515 it is realloced so that is it.
6516
6517TXT_DB A simple memory based text file data base. The application can specify
6518 unique indexes that will be enforced at update time.
6519
6520CONF Most of the programs written for this library require a configuration
6521 file. Instead of letting programs constantly re-implment this
6522 subsystem, the CONF library provides a consistant and flexable
6523 interface to not only configuration files but also environment
6524 variables.
6525
6526But what about when something goes wrong?
6527The one advantage (and perhaps disadvantage) of all of these
6528functions being in one library was the ability to implement a
6529single error reporting system.
6530
6531ERR This library is used to report errors. The error system records
6532 library number, function number (in the library) and reason
6533 number. Multiple errors can be reported so that an 'error' trace
6534 is created. The errors can be printed in numeric or textual form.
6535
6536
6537==== ssluse.doc ========================================================
6538
6539We have an SSL_CTX which contains global information for lots of
6540SSL connections. The session-id cache and the certificate verificate cache.
6541It also contains default values for use when certificates are used.
6542
6543SSL_CTX
6544 default cipher list
6545 session-id cache
6546 certificate cache
6547 default session-id timeout period
6548 New session-id callback
6549 Required session-id callback
6550 session-id stats
6551 Informational callback
6552 Callback that is set, overrides the SSLeay X509 certificate
6553 verification
6554 The default Certificate/Private Key pair
6555 Default read ahead mode.
6556 Default verify mode and verify callback. These are not used
6557 if the over ride callback mentioned above is used.
6558
6559Each SSL can have the following defined for it before a connection is made.
6560
6561Certificate
6562Private key
6563Ciphers to use
6564Certificate verify mode and callback
6565IO object to use in the comunication.
6566Some 'read-ahead' mode information.
6567A previous session-id to re-use.
6568
6569A connection is made by using SSL_connect or SSL_accept.
6570When non-blocking IO is being used, there are functions that can be used
6571to determin where and why the SSL_connect or SSL_accept did not complete.
6572This information can be used to recall the functions when the 'error'
6573condition has dissapeared.
6574
6575After the connection has been made, information can be retrived about the
6576SSL session and the session-id values that have been decided apon.
6577The 'peer' certificate can be retrieved.
6578
6579The session-id values include
6580'start time'
6581'timeout length'
6582
6583
6584
6585==== stack.doc ========================================================
6586
6587The stack data structure is used to store an ordered list of objects.
6588It is basically misnamed to call it a stack but it can function that way
6589and that is what I originally used it for. Due to the way element
6590pointers are kept in a malloc()ed array, the most efficient way to use this
6591structure is to add and delete elements from the end via sk_pop() and
6592sk_push(). If you wish to do 'lookups' sk_find() is quite efficient since
6593it will sort the stack (if required) and then do a binary search to lookup
6594the requested item. This sorting occurs automatically so just sk_push()
6595elements on the stack and don't worry about the order. Do remember that if
6596you do a sk_find(), the order of the elements will change.
6597
6598You should never need to 'touch' this structure directly.
6599typedef struct stack_st
6600 {
6601 unsigned int num;
6602 char **data;
6603 int sorted;
6604
6605 unsigned int num_alloc;
6606 int (*comp)();
6607 } STACK;
6608
6609'num' holds the number of elements in the stack, 'data' is the array of
6610elements. 'sorted' is 1 is the list has been sorted, 0 if not.
6611
6612num_alloc is the number of 'nodes' allocated in 'data'. When num becomes
6613larger than num_alloc, data is realloced to a larger size.
6614If 'comp' is set, it is a function that is used to compare 2 of the items
6615in the stack. The function should return -1, 0 or 1, depending on the
6616ordering.
6617
6618#define sk_num(sk) ((sk)->num)
6619#define sk_value(sk,n) ((sk)->data[n])
6620
6621These 2 macros should be used to access the number of elements in the
6622'stack' and to access a pointer to one of the values.
6623
6624STACK *sk_new(int (*c)());
6625 This creates a new stack. If 'c', the comparison function, is not
6626specified, the various functions that operate on a sorted 'stack' will not
6627work (sk_find()). NULL is returned on failure.
6628
6629void sk_free(STACK *);
6630 This function free()'s a stack structure. The elements in the
6631stack will not be freed so one should 'pop' and free all elements from the
6632stack before calling this function or call sk_pop_free() instead.
6633
6634void sk_pop_free(STACK *st; void (*func)());
6635 This function calls 'func' for each element on the stack, passing
6636the element as the argument. sk_free() is then called to free the 'stack'
6637structure.
6638
6639int sk_insert(STACK *sk,char *data,int where);
6640 This function inserts 'data' into stack 'sk' at location 'where'.
6641If 'where' is larger that the number of elements in the stack, the element
6642is put at the end. This function tends to be used by other 'stack'
6643functions. Returns 0 on failure, otherwise the number of elements in the
6644new stack.
6645
6646char *sk_delete(STACK *st,int loc);
6647 Remove the item a location 'loc' from the stack and returns it.
6648Returns NULL if the 'loc' is out of range.
6649
6650char *sk_delete_ptr(STACK *st, char *p);
6651 If the data item pointed to by 'p' is in the stack, it is deleted
6652from the stack and returned. NULL is returned if the element is not in the
6653stack.
6654
6655int sk_find(STACK *st,char *data);
6656 Returns the location that contains a value that is equal to
6657the 'data' item. If the comparison function was not set, this function
6658does a linear search. This function actually qsort()s the stack if it is not
6659in order and then uses bsearch() to do the initial search. If the
6660search fails,, -1 is returned. For mutliple items with the same
6661value, the index of the first in the array is returned.
6662
6663int sk_push(STACK *st,char *data);
6664 Append 'data' to the stack. 0 is returned if there is a failure
6665(due to a malloc failure), else 1. This is
6666sk_insert(st,data,sk_num(st));
6667
6668int sk_unshift(STACK *st,char *data);
6669 Prepend 'data' to the front (location 0) of the stack. This is
6670sk_insert(st,data,0);
6671
6672char *sk_shift(STACK *st);
6673 Return and delete from the stack the first element in the stack.
6674This is sk_delete(st,0);
6675
6676char *sk_pop(STACK *st);
6677 Return and delete the last element on the stack. This is
6678sk_delete(st,sk_num(sk)-1);
6679
6680void sk_zero(STACK *st);
6681 Removes all items from the stack. It does not 'free'
6682pointers but is a quick way to clear a 'stack of references'.
6683
6684==== threads.doc ========================================================
6685
6686How to compile SSLeay for multi-threading.
6687
6688Well basically it is quite simple, set the compiler flags and build.
6689I have only really done much testing under Solaris and Windows NT.
6690If you library supports localtime_r() and gmtime_r() add,
6691-DTHREADS to the makefile parameters. You can probably survive with out
6692this define unless you are going to have multiple threads generating
6693certificates at once. It will not affect the SSL side of things.
6694
6695The approach I have taken to doing locking is to make the application provide
6696callbacks to perform locking and so that the SSLeay library can distinguish
6697between threads (for the error state).
6698
6699To have a look at an example program, 'cd mt; vi mttest.c'.
6700To build under solaris, sh solaris.sh, for Windows NT or Windows 95,
6701win32.bat
6702
6703This will build mttest which will fire up 10 threads that talk SSL
6704to each other 10 times.
6705To enable everything to work, the application needs to call
6706
6707CRYPTO_set_id_callback(id_function);
6708CRYPTO_set_locking_callback(locking_function);
6709
6710before any multithreading is started.
6711id_function does not need to be defined under Windows NT or 95, the
6712correct function will be called if it is not. Under unix, getpid()
6713is call if the id_callback is not defined, for solaris this is wrong
6714(since threads id's are not pid's) but under IRIX it is correct
6715(threads are just processes sharing the data segement).
6716
6717The locking_callback is used to perform locking by the SSLeay library.
6718eg.
6719
6720void solaris_locking_callback(mode,type,file,line)
6721int mode;
6722int type;
6723char *file;
6724int line;
6725 {
6726 if (mode & CRYPTO_LOCK)
6727 mutex_lock(&(lock_cs[type]));
6728 else
6729 mutex_unlock(&(lock_cs[type]));
6730 }
6731
6732Now in this case I have used mutexes instead of read/write locks, since they
6733are faster and there are not many read locks in SSLeay, you may as well
6734always use write locks. file and line are __FILE__ and __LINE__ from
6735the compile and can be usefull when debugging.
6736
6737Now as you can see, 'type' can be one of a range of values, these values are
6738defined in crypto/crypto.h
6739CRYPTO_get_lock_name(type) will return a text version of what the lock is.
6740There are CRYPTO_NUM_LOCKS locks required, so under solaris, the setup
6741for multi-threading can be
6742
6743static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
6744
6745void thread_setup()
6746 {
6747 int i;
6748
6749 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
6750 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
6751 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
6752 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
6753 }
6754
6755As a final note, under Windows NT or Windows 95, you have to be careful
6756not to mix the various threaded, unthreaded and debug libraries.
6757Normally if they are mixed incorrectly, mttest will crash just after printing
6758out some usage statistics at the end. This is because the
6759different system libraries use different malloc routines and if
6760data is malloc()ed inside crypt32.dll or ssl32.dll and then free()ed by a
6761different library malloc, things get very confused.
6762
6763The default SSLeay DLL builds use /MD, so if you use this on your
6764application, things will work as expected. If you use /MDd,
6765you will probably have to rebuild SSLeay using this flag.
6766I should modify util/mk1mf.pl so it does all this correctly, but
6767this has not been done yet.
6768
6769One last warning. Because locking overheads are actually quite large, the
6770statistics collected against the SSL_CTX for successfull connections etc
6771are not locked when updated. This does make it possible for these
6772values to be slightly lower than they should be, if you are
6773running multithreaded on a multi-processor box, but this does not really
6774matter much.
6775
6776
6777==== txt_db.doc ========================================================
6778
6779TXT_DB, a simple text based in memory database.
6780
6781It holds rows of ascii data, for which the only special character is '\0'.
6782The rows can be of an unlimited length.
6783
6784==== why.doc ========================================================
6785
6786This file is more of a note for other people who wish to understand why
6787the build environment is the way it is :-).
6788
6789The include files 'depend' as follows.
6790Each of
6791crypto/*/*.c includes crypto/cryptlib.h
6792ssl/*.c include ssl/ssl_locl.h
6793apps/*.c include apps/apps.h
6794crypto/cryptlib.h, ssl/ssl_locl.h and apps/apps.h
6795all include e_os.h which contains OS/environment specific information.
6796If you need to add something todo with a particular environment,
6797add it to this file. It is worth remembering that quite a few libraries,
6798like lhash, des, md, sha etc etc do not include crypto/cryptlib.h. This
6799is because these libraries should be 'independantly compilable' and so I
6800try to keep them this way.
6801e_os.h is not so much a part of SSLeay, as the placing in one spot all the
6802evil OS dependant muck.
6803
6804I wanted to automate as many things as possible. This includes
6805error number generation. A
6806make errors
6807will scan the source files for error codes, append them to the correct
6808header files, and generate the functions to print the text version
6809of the error numbers. So don't even think about adding error numbers by
6810hand, put them in the form
6811XXXerr(XXXX_F_XXXX,YYYY_R_YYYY);
6812on line and it will be automatically picked up my a make errors.
6813
6814In a similar vein, programs to be added into ssleay in the apps directory
6815just need to have an entry added to E_EXE in makefile.ssl and
6816everthing will work as expected. Don't edit progs.h by hand.
6817
6818make links re-generates the symbolic links that are used. The reason why
6819I keep everything in its own directory, and don't put all the
6820test programs and header files in 'test' and 'include' is because I want
6821to keep the 'sub-libraries' independant. I still 'pull' out
6822indervidual libraries for use in specific projects where the code is
6823required. I have used the 'lhash' library in just about every software
6824project I have worked on :-).
6825
6826make depend generates dependancies and
6827make dclean removes them.
6828
6829You will notice that I use perl quite a bit when I could be using 'sed'.
6830The reason I decided to do this was to just stick to one 'extra' program.
6831For Windows NT, I have perl and no sed.
6832
6833The util/mk1mf.pl program can be used to generate a single makefile.
6834I use this because makefiles under Microsoft are horrific.
6835Each C compiler seems to have different linker formats, which have
6836to be used because the retarted C compilers explode when you do
6837cl -o file *.o.
6838
6839Now some would argue that I should just use the single makefile. I don't
6840like it during develoment for 2 reasons. First, the actuall make
6841command takes a long time. For my current setup, if I'm in
6842crypto/bn and I type make, only the crypto/bn directory gets rebuilt,
6843which is nice when you are modifying prototypes in bn.h which
6844half the SSLeay depends on. The second is that to add a new souce file
6845I just plonk it in at the required spot in the local makefile. This
6846then alows me to keep things local, I don't need to modify a 'global'
6847tables (the make for unix, the make for NT, the make for w31...).
6848When I am ripping apart a library structure, it is nice to only
6849have to worry about one directory :-).
6850
6851Having said all this, for the hell of it I put together 2 files that
6852#include all the souce code (generated by doing a ls */*.o after a build).
6853crypto.c takes only 30 seconds to build under NT and 2 minutes under linux
6854for my pentium100. Much faster that the normal build :-).
6855Again, the problem is that when using libraries, every program linked
6856to libcrypto.a would suddenly get 330k of library when it may only need
68571k. This technique does look like a nice way to do shared libraries though.
6858
6859Oh yes, as a final note, to 'build' a distribution, I just type
6860make dist.
6861This cleans and packages everything. The directory needs to be called
6862SSLeay since the make does a 'cd ..' and renames and tars things up.
6863
6864==== req.1 ========================================================
6865
6866The 'req' command is used to manipulate and deal with pkcs#10
6867certificate requests.
6868
6869It's default mode of operation is to load a certificate and then
6870write it out again.
6871
6872By default the 'req' is read from stdin in 'PEM' format.
6873The -inform option can be used to specify 'pem' format or 'der'
6874format. PEM format is the base64 encoding of the DER format.
6875
6876By default 'req' then writes the request back out. -outform can be used
6877to indicate the desired output format, be it 'pem' or 'der'.
6878
6879To specify an input file, use the '-in' option and the '-out' option
6880can be used to specify the output file.
6881
6882If you wish to perform a command and not output the certificate
6883request afterwards, use the '-noout' option.
6884
6885When a certificate is loaded, it can be printed in a human readable
6886ascii format via the '-text' option.
6887
6888To check that the signature on a certificate request is correct, use
6889the '-verify' option to make sure that the private key contained in the
6890certificate request corresponds to the signature.
6891
6892Besides the default mode, there is also the 'generate a certificate
6893request' mode. There are several flags that trigger this mode.
6894
6895-new will generate a new RSA key (if required) and then prompts
6896the user for details for the certificate request.
6897-newkey has an argument that is the number of bits to make the new
6898key. This function also triggers '-new'.
6899
6900The '-new' option can have a key to use specified instead of having to
6901load one, '-key' is used to specify the file containg the key.
6902-keyform can be used to specify the format of the key. Only
6903'pem' and 'der' formats are supported, later, 'netscape' format may be added.
6904
6905Finally there is the '-x509' options which makes req output a self
6906signed x509 certificate instead of a certificate request.
6907
6908Now as you may have noticed, there are lots of default options that
6909cannot be specified via the command line. They are held in a 'template'
6910or 'configuration file'. The -config option specifies which configuration
6911file to use. See conf.doc for details on the syntax of this file.
6912
6913The req command uses the 'req' section of the config file.
6914
6915---
6916# The following variables are defined. For this example I will populate
6917# the various values
6918[ req ]
6919default_bits = 512 # default number of bits to use.
6920default_keyfile = testkey.pem # Where to write the generated keyfile
6921 # if not specified.
6922distinguished_name= req_dn # The section that contains the
6923 # information about which 'object' we
6924 # want to put in the DN.
6925attributes = req_attr # The objects we want for the
6926 # attributes field.
6927encrypt_rsa_key = no # Should we encrypt newly generated
6928 # keys. I strongly recommend 'yes'.
6929
6930# The distinguished name section. For the following entries, the
6931# object names must exist in the SSLeay header file objects.h. If they
6932# do not, they will be silently ignored. The entries have the following
6933# format.
6934# <object_name> => string to prompt with
6935# <object_name>_default => default value for people
6936# <object_name>_value => Automatically use this value for this field.
6937# <object_name>_min => minimum number of characters for data (def. 0)
6938# <object_name>_max => maximum number of characters for data (def. inf.)
6939# All of these entries are optional except for the first one.
6940[ req_dn ]
6941countryName = Country Name (2 letter code)
6942countryName_default = AU
6943
6944stateOrProvinceName = State or Province Name (full name)
6945stateOrProvinceName_default = Queensland
6946
6947localityName = Locality Name (eg, city)
6948
6949organizationName = Organization Name (eg, company)
6950organizationName_default = Mincom Pty Ltd
6951
6952organizationalUnitName = Organizational Unit Name (eg, section)
6953organizationalUnitName_default = MTR
6954
6955commonName = Common Name (eg, YOUR name)
6956commonName_max = 64
6957
6958emailAddress = Email Address
6959emailAddress_max = 40
6960
6961# The next section is the attributes section. This is exactly the
6962# same as for the previous section except that the resulting objects are
6963# put in the attributes field.
6964[ req_attr ]
6965challengePassword = A challenge password
6966challengePassword_min = 4
6967challengePassword_max = 20
6968
6969unstructuredName = An optional company name
6970
6971----
6972Also note that the order that attributes appear in this file is the
6973order they will be put into the distinguished name.
6974
6975Once this request has been generated, it can be sent to a CA for
6976certifying.
6977
6978----
6979A few quick examples....
6980
6981To generate a new request and a new key
6982req -new
6983
6984To generate a new request and a 1058 bit key
6985req -newkey 1058
6986
6987To generate a new request using a pre-existing key
6988req -new -key key.pem
6989
6990To generate a self signed x509 certificate from a certificate
6991request using a supplied key, and we want to see the text form of the
6992output certificate (which we will put in the file selfSign.pem
6993req -x509 -in req.pem -key key.pem -text -out selfSign.pem
6994
6995Verify that the signature is correct on a certificate request.
6996req -verify -in req.pem
6997
6998Verify that the signature was made using a specified public key.
6999req -verify -in req.pem -key key.pem
7000
7001Print the contents of a certificate request
7002req -text -in req.pem
7003
7004==== danger ========================================================
7005
7006If you specify a SSLv2 cipher, and the mode is SSLv23 and the server
7007can talk SSLv3, it will claim there is no cipher since you should be
7008using SSLv3.
7009
7010When tracing debug stuff, remember BIO_s_socket() is different to
7011BIO_s_connect().
7012
7013BSD/OS assember is not working
7014
diff --git a/src/lib/libssl/src/doc/standards.txt b/src/lib/libssl/src/doc/standards.txt
new file mode 100644
index 0000000000..61ccc5d7e0
--- /dev/null
+++ b/src/lib/libssl/src/doc/standards.txt
@@ -0,0 +1,121 @@
1Standards related to OpenSSL
2============================
3
4[Please, this is currently a draft. I made a first try at finding
5 documents that describe parts of what OpenSSL implements. There are
6 big gaps, and I've most certainly done something wrong. Please
7 correct whatever is... Also, this note should be removed when this
8 file is reaching a somewhat correct state. -- Richard Levitte]
9
10
11All pointers in here will be either URL's or blobs of text borrowed
12from miscellaneous indexes, like rfc-index.txt (index of RFCs),
131id-index.txt (index of Internet drafts) and the like.
14
15To find the latest possible RFCs, it's recommended to either browse
16ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and
17use the search mechanism found there.
18To find the latest possible Internet drafts, it's recommended to
19browse ftp://ftp.isi.edu/internet-drafts/.
20To find the latest possible PKCS, it's recommended to browse
21http://www.rsasecurity.com/rsalabs/pkcs/.
22
23
24Implemented:
25------------
26
27These are documents that describe things that are implemented in OpenSSL.
28
291319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992.
30 (Format: TXT=25661 bytes) (Status: INFORMATIONAL)
31
321320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
33 TXT=32407 bytes) (Status: INFORMATIONAL)
34
351321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
36 TXT=35222 bytes) (Status: INFORMATIONAL)
37
382246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999.
39 (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD)
40
412268 A Description of the RC2(r) Encryption Algorithm. R. Rivest.
42 January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL)
43
442314 PKCS 10: Certification Request Syntax Version 1.5. B. Kaliski.
45 March 1998. (Format: TXT=15814 bytes) (Status: INFORMATIONAL)
46
472315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski.
48 March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL)
49
502437 PKCS #1: RSA Cryptography Specifications Version 2.0. B. Kaliski,
51 J. Staddon. October 1998. (Format: TXT=73529 bytes) (Obsoletes
52 RFC2313) (Status: INFORMATIONAL)
53
542459 Internet X.509 Public Key Infrastructure Certificate and CRL
55 Profile. R. Housley, W. Ford, W. Polk, D. Solo. January 1999.
56 (Format: TXT=278438 bytes) (Status: PROPOSED STANDARD)
57
58PKCS#8: Private-Key Information Syntax Standard
59
60PKCS#12: Personal Information Exchange Syntax Standard, version 1.0.
61
62
63Related:
64--------
65
66These are documents that are close to OpenSSL, for example the
67STARTTLS documents.
68
691421 Privacy Enhancement for Internet Electronic Mail: Part I: Message
70 Encryption and Authentication Procedures. J. Linn. February 1993.
71 (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED
72 STANDARD)
73
741422 Privacy Enhancement for Internet Electronic Mail: Part II:
75 Certificate-Based Key Management. S. Kent. February 1993. (Format:
76 TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD)
77
781423 Privacy Enhancement for Internet Electronic Mail: Part III:
79 Algorithms, Modes, and Identifiers. D. Balenson. February 1993.
80 (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED
81 STANDARD)
82
831424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key
84 Certification and Related Services. B. Kaliski. February 1993.
85 (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD)
86
872487 SMTP Service Extension for Secure SMTP over TLS. P. Hoffman.
88 January 1999. (Format: TXT=15120 bytes) (Status: PROPOSED STANDARD)
89
902585 Internet X.509 Public Key Infrastructure Operational Protocols:
91 FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813
92 bytes) (Status: PROPOSED STANDARD)
93
942595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999.
95 (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD)
96
972712 Addition of Kerberos Cipher Suites to Transport Layer Security
98 (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes)
99 (Status: PROPOSED STANDARD)
100
1012817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May
102 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED
103 STANDARD)
104
1052818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes)
106 (Status: INFORMATIONAL)
107
108 "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt>
109
110
111To be implemented:
112------------------
113
114These are documents that describe things that are planed to be
115implemented in the hopefully short future.
116
1172560 X.509 Internet Public Key Infrastructure Online Certificate
118 Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin,
119 C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED
120 STANDARD)
121
diff --git a/src/lib/libssl/src/e_os2.h b/src/lib/libssl/src/e_os2.h
new file mode 100644
index 0000000000..bd97b921a8
--- /dev/null
+++ b/src/lib/libssl/src/e_os2.h
@@ -0,0 +1,38 @@
1/* e_os2.h */
2
3#ifndef HEADER_E_OS2_H
4#define HEADER_E_OS2_H
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#include <openssl/opensslconf.h> /* OPENSSL_UNISTD */
11
12#ifdef MSDOS
13# define OPENSSL_UNISTD_IO <io.h>
14# define OPENSSL_DECLARE_EXIT extern void exit(int);
15#else
16# define OPENSSL_UNISTD_IO OPENSSL_UNISTD
17# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
18#endif
19
20/* Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN,
21 to define and declare certain global
22 symbols that, with some compilers under VMS, have to be defined and
23 declared explicitely with globaldef and globalref. On other OS:es,
24 these macros are defined with something sensible. */
25
26#if defined(VMS) && !defined(__DECC)
27# define OPENSSL_EXTERN globalref
28# define OPENSSL_GLOBAL globaldef
29#else
30# define OPENSSL_EXTERN extern
31# define OPENSSL_GLOBAL
32#endif
33
34#ifdef __cplusplus
35}
36#endif
37#endif
38
diff --git a/src/lib/libssl/src/install.com b/src/lib/libssl/src/install.com
new file mode 100644
index 0000000000..16eac9aab2
--- /dev/null
+++ b/src/lib/libssl/src/install.com
@@ -0,0 +1,88 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ARCH = "AXP"
16$ IF F$GETSYI("CPU") .LT. 128 THEN ARCH = "VAX"
17$
18$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
19$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
20$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
21 - ".][000000" - "[000000." - "][" - "[" - "]"
22$ ROOT = ROOT_DEV + "[" + ROOT_DIR
23$
24$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
25$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
26$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
27$ DEFINE/NOLOG WRK_SSLLIB WRK_SSLROOT:[LIB]
28$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
29$ DEFINE/NOLOG WRK_SSLVEXE WRK_SSLROOT:[VAX_EXE]
30$ DEFINE/NOLOG WRK_SSLAEXE WRK_SSLROOT:[ALPHA_EXE]
31$ DEFINE/NOLOG WRK_SSLCERTS WRK_SSLROOT:[CERTS]
32$ DEFINE/NOLOG WRK_SSLPRIVATE WRK_SSLROOT:[PRIVATE]
33$
34$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
35 CREATE/DIR/LOG WRK_SSLROOT:[000000]
36$ IF F$PARSE("WRK_SSLVEXE:") .EQS. "" THEN -
37 CREATE/DIR/LOG WRK_SSLVEXE:
38$ IF F$PARSE("WRK_SSLAEXE:") .EQS. "" THEN -
39 CREATE/DIR/LOG WRK_SSLAEXE:
40$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN -
41 CREATE/DIR/LOG WRK_SSLVLIB:
42$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN -
43 CREATE/DIR/LOG WRK_SSLALIB:
44$ IF F$PARSE("WRK_SSLLIB:") .EQS. "" THEN -
45 CREATE/DIR/LOG WRK_SSLLIB:
46$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
47 CREATE/DIR/LOG WRK_SSLINCLUDE:
48$ IF F$PARSE("WRK_SSLCERTS:") .EQS. "" THEN -
49 CREATE/DIR/LOG WRK_SSLCERTS:
50$ IF F$PARSE("WRK_SSLPRIVATE:") .EQS. "" THEN -
51 CREATE/DIR/LOG WRK_SSLPRIVATE:
52$ IF F$PARSE("WRK_SSLROOT:[VMS]") .EQS. "" THEN -
53 CREATE/DIR/LOG WRK_SSLROOT:[VMS]
54$
55$ SDIRS := CRYPTO,SSL,RSAREF,APPS,VMS!,TEST,TOOLS
56$ EXHEADER := e_os.h,e_os2.h
57$
58$ COPY 'EXHEADER' WRK_SSLINCLUDE: /LOG
59$
60$ I = 0
61$ LOOP_SDIRS:
62$ D = F$ELEMENT(I, ",", SDIRS)
63$ I = I + 1
64$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
65$ WRITE SYS$OUTPUT "Installing ",D," files."
66$ SET DEFAULT [.'D']
67$ @INSTALL 'ROOT']
68$ SET DEFAULT [-]
69$ GOTO LOOP_SDIRS
70$ LOOP_SDIRS_END:
71$
72$ DEASSIGN WRK_SSLROOT
73$ DEASSIGN WRK_SSLVLIB
74$ DEASSIGN WRK_SSLALIB
75$ DEASSIGN WRK_SSLLIB
76$ DEASSIGN WRK_SSLINCLUDE
77$ DEASSIGN WRK_SSLVEXE
78$ DEASSIGN WRK_SSLAEXE
79$ DEASSIGN WRK_SSLCERTS
80$ DEASSIGN WRK_SSLPRIVATE
81$
82$ WRITE SYS$OUTPUT ""
83$ WRITE SYS$OUTPUT " Installation done!"
84$ WRITE SYS$OUTPUT ""
85$ WRITE SYS$OUTPUT " You might want to purge ",ROOT,"...]"
86$ WRITE SYS$OUTPUT ""
87$
88$ EXIT
diff --git a/src/lib/libssl/src/ms/bcb4.bat b/src/lib/libssl/src/ms/bcb4.bat
new file mode 100644
index 0000000000..71a670e794
--- /dev/null
+++ b/src/lib/libssl/src/ms/bcb4.bat
@@ -0,0 +1,6 @@
1perl Configure BC-32
2perl util\mkfiles.pl > MINFO
3
4@rem create make file
5perl util\mk1mf.pl no-asm BC-NT > bcb.mak
6
diff --git a/src/lib/libssl/src/ms/do_masm.bat b/src/lib/libssl/src/ms/do_masm.bat
new file mode 100644
index 0000000000..5b64fecdb0
--- /dev/null
+++ b/src/lib/libssl/src/ms/do_masm.bat
@@ -0,0 +1,68 @@
1@echo off
2echo Generating x86 for MASM assember
3
4echo Bignum
5cd crypto\bn\asm
6perl x86.pl win32 > bn-win32.asm
7cd ..\..\..
8
9echo DES
10cd crypto\des\asm
11perl des-586.pl win32 > d-win32.asm
12cd ..\..\..
13
14echo "crypt(3)"
15
16cd crypto\des\asm
17perl crypt586.pl win32 > y-win32.asm
18cd ..\..\..
19
20echo Blowfish
21
22cd crypto\bf\asm
23perl bf-586.pl win32 > b-win32.asm
24cd ..\..\..
25
26echo CAST5
27cd crypto\cast\asm
28perl cast-586.pl win32 > c-win32.asm
29cd ..\..\..
30
31echo RC4
32cd crypto\rc4\asm
33perl rc4-586.pl win32 > r4-win32.asm
34cd ..\..\..
35
36echo MD5
37cd crypto\md5\asm
38perl md5-586.pl win32 > m5-win32.asm
39cd ..\..\..
40
41echo SHA1
42cd crypto\sha\asm
43perl sha1-586.pl win32 > s1-win32.asm
44cd ..\..\..
45
46echo RIPEMD160
47cd crypto\ripemd\asm
48perl rmd-586.pl win32 > rm-win32.asm
49cd ..\..\..
50
51echo RC5\32
52cd crypto\rc5\asm
53perl rc5-586.pl win32 > r5-win32.asm
54cd ..\..\..
55
56echo on
57
58perl util\mkfiles.pl >MINFO
59rem perl util\mk1mf.pl VC-MSDOS no-sock >ms\msdos.mak
60rem perl util\mk1mf.pl VC-W31-32 >ms\w31.mak
61perl util\mk1mf.pl dll VC-W31-32 >ms\w31dll.mak
62perl util\mk1mf.pl VC-WIN32 >ms\nt.mak
63perl util\mk1mf.pl dll VC-WIN32 >ms\ntdll.mak
64
65perl util\mkdef.pl 16 libeay > ms\libeay16.def
66perl util\mkdef.pl 32 libeay > ms\libeay32.def
67perl util\mkdef.pl 16 ssleay > ms\ssleay16.def
68perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
diff --git a/src/lib/libssl/src/ms/do_nasm.bat b/src/lib/libssl/src/ms/do_nasm.bat
new file mode 100644
index 0000000000..8859c15457
--- /dev/null
+++ b/src/lib/libssl/src/ms/do_nasm.bat
@@ -0,0 +1,69 @@
1
2@echo off
3echo Generating x86 for NASM assember
4
5echo Bignum
6cd crypto\bn\asm
7perl x86.pl win32n > bn-win32.asm
8cd ..\..\..
9
10echo DES
11cd crypto\des\asm
12perl des-586.pl win32n > d-win32.asm
13cd ..\..\..
14
15echo "crypt(3)"
16
17cd crypto\des\asm
18perl crypt586.pl win32n > y-win32.asm
19cd ..\..\..
20
21echo Blowfish
22
23cd crypto\bf\asm
24perl bf-586.pl win32n > b-win32.asm
25cd ..\..\..
26
27echo CAST5
28cd crypto\cast\asm
29perl cast-586.pl win32n > c-win32.asm
30cd ..\..\..
31
32echo RC4
33cd crypto\rc4\asm
34perl rc4-586.pl win32n > r4-win32.asm
35cd ..\..\..
36
37echo MD5
38cd crypto\md5\asm
39perl md5-586.pl win32n > m5-win32.asm
40cd ..\..\..
41
42echo SHA1
43cd crypto\sha\asm
44perl sha1-586.pl win32n > s1-win32.asm
45cd ..\..\..
46
47echo RIPEMD160
48cd crypto\ripemd\asm
49perl rmd-586.pl win32n > rm-win32.asm
50cd ..\..\..
51
52echo RC5\32
53cd crypto\rc5\asm
54perl rc5-586.pl win32n > r5-win32.asm
55cd ..\..\..
56
57echo on
58
59perl util\mkfiles.pl >MINFO
60rem perl util\mk1mf.pl VC-MSDOS no-sock >ms\msdos.mak
61rem perl util\mk1mf.pl VC-W31-32 >ms\w31.mak
62perl util\mk1mf.pl dll VC-W31-32 >ms\w31dll.mak
63perl util\mk1mf.pl nasm VC-WIN32 >ms\nt.mak
64perl util\mk1mf.pl dll nasm VC-WIN32 >ms\ntdll.mak
65
66perl util\mkdef.pl 16 libeay > ms\libeay16.def
67perl util\mkdef.pl 32 libeay > ms\libeay32.def
68perl util\mkdef.pl 16 ssleay > ms\ssleay16.def
69perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
diff --git a/src/lib/libssl/src/ms/do_nt.bat b/src/lib/libssl/src/ms/do_nt.bat
new file mode 100644
index 0000000000..9c06c27caa
--- /dev/null
+++ b/src/lib/libssl/src/ms/do_nt.bat
@@ -0,0 +1,7 @@
1
2perl util\mkfiles.pl >MINFO
3perl util\mk1mf.pl no-asm VC-NT >ms\nt.mak
4perl util\mk1mf.pl dll no-asm VC-NT >ms\ntdll.mak
5
6perl util\mkdef.pl libeay NT > ms\libeay32.def
7perl util\mkdef.pl ssleay NT > ms\ssleay32.def
diff --git a/src/lib/libssl/src/ms/mingw32.bat b/src/lib/libssl/src/ms/mingw32.bat
new file mode 100644
index 0000000000..1726c55bcd
--- /dev/null
+++ b/src/lib/libssl/src/ms/mingw32.bat
@@ -0,0 +1,92 @@
1@rem OpenSSL with Mingw32+GNU as
2@rem ---------------------------
3
4perl Configure Mingw32 %1 %2 %3 %4 %5 %6 %7 %8
5
6@echo off
7
8perl -e "exit 1 if '%1' eq 'no-asm'"
9if errorlevel 1 goto noasm
10
11echo Generating x86 for GNU assember
12
13echo Bignum
14cd crypto\bn\asm
15perl x86.pl gaswin > bn-win32.s
16cd ..\..\..
17
18echo DES
19cd crypto\des\asm
20perl des-586.pl gaswin > d-win32.s
21cd ..\..\..
22
23echo crypt
24cd crypto\des\asm
25perl crypt586.pl gaswin > y-win32.s
26cd ..\..\..
27
28echo Blowfish
29cd crypto\bf\asm
30perl bf-586.pl gaswin > b-win32.s
31cd ..\..\..
32
33echo CAST5
34cd crypto\cast\asm
35perl cast-586.pl gaswin > c-win32.s
36cd ..\..\..
37
38echo RC4
39cd crypto\rc4\asm
40perl rc4-586.pl gaswin > r4-win32.s
41cd ..\..\..
42
43echo MD5
44cd crypto\md5\asm
45perl md5-586.pl gaswin > m5-win32.s
46cd ..\..\..
47
48echo SHA1
49cd crypto\sha\asm
50perl sha1-586.pl gaswin > s1-win32.s
51cd ..\..\..
52
53echo RIPEMD160
54cd crypto\ripemd\asm
55perl rmd-586.pl gaswin > rm-win32.s
56cd ..\..\..
57
58echo RC5\32
59cd crypto\rc5\asm
60perl rc5-586.pl gaswin > r5-win32.s
61cd ..\..\..
62
63:noasm
64
65echo Generating makefile
66perl util\mkfiles.pl >MINFO
67perl util\mk1mf.pl gaswin Mingw32 >ms\mingw32a.mak
68perl util\mk1mf.pl gaswin Mingw32-files >ms\mingw32f.mak
69echo Generating DLL definition files
70perl util\mkdef.pl 32 libeay >ms\libeay32.def
71if errorlevel 1 goto end
72perl util\mkdef.pl 32 ssleay >ms\ssleay32.def
73if errorlevel 1 goto end
74
75rem Create files -- this can be skipped if using the GNU file utilities
76make -f ms/mingw32f.mak
77echo You can ignore the error messages above
78
79echo Building the libraries
80make -f ms/mingw32a.mak
81if errorlevel 1 goto end
82
83echo Generating the DLLs and input libraries
84dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32
85if errorlevel 1 goto end
86dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a
87if errorlevel 1 goto end
88
89echo Done compiling OpenSSL
90
91:end
92
diff --git a/src/lib/libssl/src/ms/mw.bat b/src/lib/libssl/src/ms/mw.bat
new file mode 100644
index 0000000000..dc37913b71
--- /dev/null
+++ b/src/lib/libssl/src/ms/mw.bat
@@ -0,0 +1,31 @@
1@rem OpenSSL with Mingw32
2@rem --------------------
3
4@rem Makefile
5perl util\mkfiles.pl >MINFO
6perl util\mk1mf.pl Mingw32 >ms\mingw32.mak
7perl util\mk1mf.pl Mingw32-files >ms\mingw32f.mak
8@rem DLL definition files
9perl util\mkdef.pl 32 libeay >ms\libeay32.def
10if errorlevel 1 goto end
11perl util\mkdef.pl 32 ssleay >ms\ssleay32.def
12if errorlevel 1 goto end
13
14@rem Create files -- this can be skipped if using the GNU file utilities
15make -f ms/mingw32f.mak
16echo You can ignore the error messages above
17
18@rem Build the libraries
19make -f ms/mingw32.mak
20if errorlevel 1 goto end
21
22@rem Generate the DLLs and input libraries
23dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32
24if errorlevel 1 goto end
25dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a
26if errorlevel 1 goto end
27
28echo Done compiling OpenSSL
29
30:end
31
diff --git a/src/lib/libssl/src/ms/tlhelp32.h b/src/lib/libssl/src/ms/tlhelp32.h
new file mode 100644
index 0000000000..8f4222e34f
--- /dev/null
+++ b/src/lib/libssl/src/ms/tlhelp32.h
@@ -0,0 +1,136 @@
1/*
2 tlhelp32.h - Include file for Tool help functions.
3
4 Written by Mumit Khan <khan@nanotech.wisc.edu>
5
6 This file is part of a free library for the Win32 API.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
12*/
13#ifndef _TLHELP32_H
14#define _TLHELP32_H
15#ifdef __cplusplus
16extern "C" {
17#endif
18#define HF32_DEFAULT 1
19#define HF32_SHARED 2
20#define LF32_FIXED 0x1
21#define LF32_FREE 0x2
22#define LF32_MOVEABLE 0x4
23#define MAX_MODULE_NAME32 255
24#define TH32CS_SNAPHEAPLIST 0x1
25#define TH32CS_SNAPPROCESS 0x2
26#define TH32CS_SNAPTHREAD 0x4
27#define TH32CS_SNAPMODULE 0x8
28#define TH32CS_SNAPALL (TH32CS_SNAPHEAPLIST|TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE)
29#define TH32CS_INHERIT 0x80000000
30typedef struct tagHEAPLIST32 {
31 DWORD dwSize;
32 DWORD th32ProcessID;
33 DWORD th32HeapID;
34 DWORD dwFlags;
35} HEAPLIST32,*PHEAPLIST32,*LPHEAPLIST32;
36typedef struct tagHEAPENTRY32 {
37 DWORD dwSize;
38 HANDLE hHandle;
39 DWORD dwAddress;
40 DWORD dwBlockSize;
41 DWORD dwFlags;
42 DWORD dwLockCount;
43 DWORD dwResvd;
44 DWORD th32ProcessID;
45 DWORD th32HeapID;
46} HEAPENTRY32,*PHEAPENTRY32,*LPHEAPENTRY32;
47typedef struct tagPROCESSENTRY32W {
48 DWORD dwSize;
49 DWORD cntUsage;
50 DWORD th32ProcessID;
51 DWORD th32DefaultHeapID;
52 DWORD th32ModuleID;
53 DWORD cntThreads;
54 DWORD th32ParentProcessID;
55 LONG pcPriClassBase;
56 DWORD dwFlags;
57 WCHAR szExeFile[MAX_PATH];
58} PROCESSENTRY32W,*PPROCESSENTRY32W,*LPPROCESSENTRY32W;
59typedef struct tagPROCESSENTRY32 {
60 DWORD dwSize;
61 DWORD cntUsage;
62 DWORD th32ProcessID;
63 DWORD th32DefaultHeapID;
64 DWORD th32ModuleID;
65 DWORD cntThreads;
66 DWORD th32ParentProcessID;
67 LONG pcPriClassBase;
68 DWORD dwFlags;
69 CHAR szExeFile[MAX_PATH];
70} PROCESSENTRY32,*PPROCESSENTRY32,*LPPROCESSENTRY32;
71typedef struct tagTHREADENTRY32 {
72 DWORD dwSize;
73 DWORD cntUsage;
74 DWORD th32ThreadID;
75 DWORD th32OwnerProcessID;
76 LONG tpBasePri;
77 LONG tpDeltaPri;
78 DWORD dwFlags;
79} THREADENTRY32,*PTHREADENTRY32,*LPTHREADENTRY32;
80typedef struct tagMODULEENTRY32W {
81 DWORD dwSize;
82 DWORD th32ModuleID;
83 DWORD th32ProcessID;
84 DWORD GlblcntUsage;
85 DWORD ProccntUsage;
86 BYTE *modBaseAddr;
87 DWORD modBaseSize;
88 HMODULE hModule;
89 WCHAR szModule[MAX_MODULE_NAME32 + 1];
90 WCHAR szExePath[MAX_PATH];
91} MODULEENTRY32W,*PMODULEENTRY32W,*LPMODULEENTRY32W;
92typedef struct tagMODULEENTRY32 {
93 DWORD dwSize;
94 DWORD th32ModuleID;
95 DWORD th32ProcessID;
96 DWORD GlblcntUsage;
97 DWORD ProccntUsage;
98 BYTE *modBaseAddr;
99 DWORD modBaseSize;
100 HMODULE hModule;
101 char szModule[MAX_MODULE_NAME32 + 1];
102 char szExePath[MAX_PATH];
103} MODULEENTRY32,*PMODULEENTRY32,*LPMODULEENTRY32;
104BOOL WINAPI Heap32First(LPHEAPENTRY32,DWORD,DWORD);
105BOOL WINAPI Heap32ListFirst(HANDLE,LPHEAPLIST32);
106BOOL WINAPI Heap32ListNext(HANDLE,LPHEAPLIST32);
107BOOL WINAPI Heap32Next(LPHEAPENTRY32);
108BOOL WINAPI Module32First(HANDLE,LPMODULEENTRY32);
109BOOL WINAPI Module32FirstW(HANDLE,LPMODULEENTRY32W);
110BOOL WINAPI Module32Next(HANDLE,LPMODULEENTRY32);
111BOOL WINAPI Module32NextW(HANDLE,LPMODULEENTRY32W);
112BOOL WINAPI Process32First(HANDLE,LPPROCESSENTRY32);
113BOOL WINAPI Process32FirstW(HANDLE,LPPROCESSENTRY32W);
114BOOL WINAPI Process32Next(HANDLE,LPPROCESSENTRY32);
115BOOL WINAPI Process32NextW(HANDLE,LPPROCESSENTRY32W);
116BOOL WINAPI Thread32First(HANDLE,LPTHREADENTRY32);
117BOOL WINAPI Thread32Next(HANDLE,LPTHREADENTRY32);
118BOOL WINAPI Toolhelp32ReadProcessMemory(DWORD,LPCVOID,LPVOID,DWORD,LPDWORD);
119HANDLE WINAPI CreateToolhelp32Snapshot(DWORD,DWORD);
120#ifdef UNICODE
121#define LPMODULEENTRY32 LPMODULEENTRY32W
122#define LPPROCESSENTRY32 LPPROCESSENTRY32W
123#define MODULEENTRY32 MODULEENTRY32W
124#define Module32First Module32FirstW
125#define Module32Next Module32NextW
126#define PMODULEENTRY32 PMODULEENTRY32W
127#define PPROCESSENTRY32 PPROCESSENTRY32W
128#define PROCESSENTRY32 PROCESSENTRY32W
129#define Process32First Process32FirstW
130#define Process32Next Process32NextW
131#endif /* UNICODE */
132#ifdef __cplusplus
133}
134#endif
135#endif /* _TLHELP32_H */
136
diff --git a/src/lib/libssl/src/ms/x86asm.bat b/src/lib/libssl/src/ms/x86asm.bat
new file mode 100644
index 0000000000..4d80e706e4
--- /dev/null
+++ b/src/lib/libssl/src/ms/x86asm.bat
@@ -0,0 +1,57 @@
1
2@echo off
3echo Generating x86 assember
4
5echo Bignum
6cd crypto\bn\asm
7perl x86.pl win32n > bn-win32.asm
8cd ..\..\..
9
10echo DES
11cd crypto\des\asm
12perl des-586.pl win32n > d-win32.asm
13cd ..\..\..
14
15echo "crypt(3)"
16
17cd crypto\des\asm
18perl crypt586.pl win32n > y-win32.asm
19cd ..\..\..
20
21echo Blowfish
22
23cd crypto\bf\asm
24perl bf-586.pl win32n > b-win32.asm
25cd ..\..\..
26
27echo CAST5
28cd crypto\cast\asm
29perl cast-586.pl win32n > c-win32.asm
30cd ..\..\..
31
32echo RC4
33cd crypto\rc4\asm
34perl rc4-586.pl win32n > r4-win32.asm
35cd ..\..\..
36
37echo MD5
38cd crypto\md5\asm
39perl md5-586.pl win32n > m5-win32.asm
40cd ..\..\..
41
42echo SHA1
43cd crypto\sha\asm
44perl sha1-586.pl win32n > s1-win32.asm
45cd ..\..\..
46
47echo RIPEMD160
48cd crypto\ripemd\asm
49perl rmd-586.pl win32n > rm-win32.asm
50cd ..\..\..
51
52echo RC5\32
53cd crypto\rc5\asm
54perl rc5-586.pl win32n > r5-win32.asm
55cd ..\..\..
56
57echo on
diff --git a/src/lib/libssl/src/openssl.doxy b/src/lib/libssl/src/openssl.doxy
new file mode 100644
index 0000000000..479c311470
--- /dev/null
+++ b/src/lib/libssl/src/openssl.doxy
@@ -0,0 +1,7 @@
1PROJECT_NAME=OpenSSL
2GENERATE_LATEX=no
3OUTPUT_DIRECTORY=doxygen
4INPUT=ssl include
5FILE_PATTERNS=*.c *.h
6RECURSIVE=yes
7PREDEFINED=DOXYGEN
diff --git a/src/lib/libssl/src/openssl.spec b/src/lib/libssl/src/openssl.spec
new file mode 100644
index 0000000000..1c8f4e9d81
--- /dev/null
+++ b/src/lib/libssl/src/openssl.spec
@@ -0,0 +1,213 @@
1%define libmaj 0
2%define libmin 9
3%define librel 6
4#%define librev
5Release: 1
6
7%define openssldir /var/ssl
8
9Summary: Secure Sockets Layer and cryptography libraries and tools
10Name: openssl-engine
11Version: %{libmaj}.%{libmin}.%{librel}
12#Version: %{libmaj}.%{libmin}.%{librel}%{librev}
13Source0: ftp://ftp.openssl.org/source/%{name}-%{version}.tar.gz
14Copyright: Freely distributable
15Group: System Environment/Libraries
16Provides: SSL
17URL: http://www.openssl.org/
18Packager: Damien Miller <djm@mindrot.org>
19BuildRoot: /var/tmp/%{name}-%{version}-root
20
21%description
22The OpenSSL Project is a collaborative effort to develop a robust,
23commercial-grade, fully featured, and Open Source toolkit implementing the
24Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1)
25protocols as well as a full-strength general purpose cryptography library.
26The project is managed by a worldwide community of volunteers that use the
27Internet to communicate, plan, and develop the OpenSSL tookit and its related
28documentation.
29
30OpenSSL is based on the excellent SSLeay library developed from Eric A.
31Young and Tim J. Hudson. The OpenSSL toolkit is licensed under an
32Apache-style licence, which basically means that you are free to get and
33use it for commercial and non-commercial purposes.
34
35This package contains the base OpenSSL cryptography and SSL/TLS
36libraries and tools.
37
38%package devel
39Summary: Secure Sockets Layer and cryptography static libraries and headers
40Group: Development/Libraries
41Requires: openssl-engine
42%description devel
43The OpenSSL Project is a collaborative effort to develop a robust,
44commercial-grade, fully featured, and Open Source toolkit implementing the
45Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1)
46protocols as well as a full-strength general purpose cryptography library.
47The project is managed by a worldwide community of volunteers that use the
48Internet to communicate, plan, and develop the OpenSSL tookit and its related
49documentation.
50
51OpenSSL is based on the excellent SSLeay library developed from Eric A.
52Young and Tim J. Hudson. The OpenSSL toolkit is licensed under an
53Apache-style licence, which basically means that you are free to get and
54use it for commercial and non-commercial purposes.
55
56This package contains the the OpenSSL cryptography and SSL/TLS
57static libraries and header files required when developing applications.
58
59%package doc
60Summary: OpenSSL miscellaneous files
61Group: Documentation
62Requires: openssl-engine
63%description doc
64The OpenSSL Project is a collaborative effort to develop a robust,
65commercial-grade, fully featured, and Open Source toolkit implementing the
66Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1)
67protocols as well as a full-strength general purpose cryptography library.
68The project is managed by a worldwide community of volunteers that use the
69Internet to communicate, plan, and develop the OpenSSL tookit and its related
70documentation.
71
72OpenSSL is based on the excellent SSLeay library developed from Eric A.
73Young and Tim J. Hudson. The OpenSSL toolkit is licensed under an
74Apache-style licence, which basically means that you are free to get and
75use it for commercial and non-commercial purposes.
76
77This package contains the the OpenSSL cryptography and SSL/TLS extra
78documentation and POD files from which the man pages were produced.
79
80%prep
81
82%setup -q
83
84%build
85
86%define CONFIG_FLAGS -DSSL_ALLOW_ADH --prefix=/usr
87
88perl util/perlpath.pl /usr/bin/perl
89
90%ifarch i386 i486 i586 i686
91./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-elf
92#!#./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-elf shared
93%endif
94%ifarch ppc
95./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-ppc
96#!#./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-ppc shared
97%endif
98%ifarch alpha
99./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-alpha
100#!#./Configure %{CONFIG_FLAGS} --openssldir=%{openssldir} linux-alpha shared
101%endif
102LD_LIBRARY_PATH=`pwd` make
103LD_LIBRARY_PATH=`pwd` make rehash
104LD_LIBRARY_PATH=`pwd` make test
105
106%install
107rm -rf $RPM_BUILD_ROOT
108make install MANDIR=/usr/man INSTALL_PREFIX="$RPM_BUILD_ROOT"
109
110# Rename manpages
111for x in $RPM_BUILD_ROOT/usr/man/man*/*
112 do mv ${x} ${x}ssl
113done
114
115# Install RSAref stuff
116install -m644 rsaref/rsaref.h $RPM_BUILD_ROOT/usr/include/openssl
117install -m644 libRSAglue.a $RPM_BUILD_ROOT/usr/lib
118
119# Make backwards-compatibility symlink to ssleay
120ln -s /usr/bin/openssl $RPM_BUILD_ROOT/usr/bin/ssleay
121
122# Install shared libs
123install -m644 libcrypto.a $RPM_BUILD_ROOT/usr/lib
124#!#install -m755 libcrypto.so.%{libmaj}.%{libmin}.%{librel} $RPM_BUILD_ROOT/usr/lib
125install -m644 libssl.a $RPM_BUILD_ROOT/usr/lib
126#!#install -m755 libssl.so.%{libmaj}.%{libmin}.%{librel} $RPM_BUILD_ROOT/usr/lib
127(
128 cd $RPM_BUILD_ROOT/usr/lib
129 #!#ln -s libcrypto.so.%{libmaj}.%{libmin}.%{librel} libcrypto.so.%{libmaj}
130 #!#ln -s libcrypto.so.%{libmaj}.%{libmin}.%{librel} libcrypto.so
131 #!#ln -s libssl.so.%{libmaj}.%{libmin}.%{librel} libssl.so.%{libmaj}
132 #!#ln -s libssl.so.%{libmaj}.%{libmin}.%{librel} libssl.so
133)
134
135%clean
136rm -rf $RPM_BUILD_ROOT
137
138%files
139%defattr(0644,root,root,0755)
140%doc CHANGES CHANGES.SSLeay LICENSE NEWS README
141
142%attr(0755,root,root) /usr/bin/*
143#!#%attr(0755,root,root) /usr/lib/*.so*
144%attr(0755,root,root) %{openssldir}/misc/*
145%attr(0644,root,root) /usr/man/man[157]/*
146
147%config %attr(0644,root,root) %{openssldir}/openssl.cnf
148%dir %attr(0755,root,root) %{openssldir}/certs
149%dir %attr(0755,root,root) %{openssldir}/lib
150%dir %attr(0755,root,root) %{openssldir}/misc
151%dir %attr(0750,root,root) %{openssldir}/private
152
153%files devel
154%doc CHANGES CHANGES.SSLeay LICENSE NEWS README
155
156%defattr(0644,root,root,0755)
157%attr(0644,root,root) /usr/lib/*.a
158%attr(0644,root,root) /usr/include/openssl/*
159%attr(0644,root,root) /usr/man/man[3]/*
160
161%files doc
162%doc CHANGES CHANGES.SSLeay LICENSE NEWS README
163%doc doc
164
165%post
166ldconfig
167
168%postun
169ldconfig
170
171%changelog
172* Thu Sep 14 2000 Richard Levitte <richard@levitte.org>
173- Changed to adapt to the new (supported) way of making shared libraries
174- Installs all static libraries, not just libRSAglue.a
175- Extra documents now end up in a separate document package
176* Sun Feb 27 2000 Damien Miller <djm@mindrot.org>
177- Merged patches to spec
178- Updated to 0.9.5beta2 (now with manpages)
179* Sat Feb 5 2000 Michal Jaegermann <michal@harddata.com>
180- added 'linux-alpha' to configuration
181- fixed nasty absolute links
182* Tue Jan 25 2000 Bennett Todd <bet@rahul.net>
183- Added -DSSL_ALLOW_ADH, bumped Release to 4
184* Thu Oct 14 1999 Damien Miller <djm@mindrot.org>
185- Set default permissions
186- Removed documentation from devel sub-package
187* Thu Sep 30 1999 Damien Miller <djm@mindrot.org>
188- Added "make test" stage
189- GPG signed
190* Tue Sep 10 1999 Damien Miller <damien@ibs.com.au>
191- Updated to version 0.9.4
192* Tue May 25 1999 Damien Miller <damien@ibs.com.au>
193- Updated to version 0.9.3
194- Added attributes for all files
195- Paramatised openssl directory
196* Sat Mar 20 1999 Carlo M. Arenas Belon <carenas@jmconsultores.com.pe>
197- Added "official" bnrec patch and taking other out
198- making a link from ssleay to openssl binary
199- putting all changelog together on SPEC file
200* Fri Mar 5 1999 Henri Gomez <gomez@slib.fr>
201- Added bnrec patch
202* Tue Dec 29 1998 Jonathan Ruano <kobalt@james.encomix.es>
203- minimum spec and patches changes for openssl
204- modified for openssl sources
205* Sat Aug 8 1998 Khimenko Victor <khim@sch57.msk.ru>
206- shared library creating process honours $RPM_OPT_FLAGS
207- shared libarry supports threads (as well as static library)
208* Wed Jul 22 1998 Khimenko Victor <khim@sch57.msk.ru>
209- building of shared library completely reworked
210* Tue Jul 21 1998 Khimenko Victor <khim@sch57.msk.ru>
211- RPM is BuildRoot'ed
212* Tue Feb 10 1998 Khimenko Victor <khim@sch57.msk.ru>
213- all stuff is moved out of /usr/local
diff --git a/src/lib/libssl/src/os2/OS2-EMX.cmd b/src/lib/libssl/src/os2/OS2-EMX.cmd
new file mode 100644
index 0000000000..8b2a092c68
--- /dev/null
+++ b/src/lib/libssl/src/os2/OS2-EMX.cmd
@@ -0,0 +1,61 @@
1@echo off
2
3perl Configure OS2-EMX
4perl util\mkfiles.pl > MINFO
5
6@rem create make file
7perl util\mk1mf.pl OS2-EMX > OS2-EMX.mak
8
9echo Generating x86 for GNU assember
10
11echo Bignum
12cd crypto\bn\asm
13rem perl x86.pl a.out > bn-os2.asm
14perl bn-586.pl a.out > bn-os2.asm
15perl co-586.pl a.out > co-os2.asm
16cd ..\..\..
17
18echo DES
19cd crypto\des\asm
20perl des-586.pl a.out > d-os2.asm
21cd ..\..\..
22
23echo crypt(3)
24cd crypto\des\asm
25perl crypt586.pl a.out > y-os2.asm
26cd ..\..\..
27
28echo Blowfish
29cd crypto\bf\asm
30perl bf-586.pl a.out > b-os2.asm
31cd ..\..\..
32
33echo CAST5
34cd crypto\cast\asm
35perl cast-586.pl a.out > c-os2.asm
36cd ..\..\..
37
38echo RC4
39cd crypto\rc4\asm
40perl rc4-586.pl a.out > r4-os2.asm
41cd ..\..\..
42
43echo MD5
44cd crypto\md5\asm
45perl md5-586.pl a.out > m5-os2.asm
46cd ..\..\..
47
48echo SHA1
49cd crypto\sha\asm
50perl sha1-586.pl a.out > s1-os2.asm
51cd ..\..\..
52
53echo RIPEMD160
54cd crypto\ripemd\asm
55perl rmd-586.pl a.out > rm-os2.asm
56cd ..\..\..
57
58echo RC5\32
59cd crypto\rc5\asm
60perl rc5-586.pl a.out > r5-os2.asm
61cd ..\..\..
diff --git a/src/lib/libssl/src/shlib/Makefile.hpux10-cc b/src/lib/libssl/src/shlib/Makefile.hpux10-cc
new file mode 100644
index 0000000000..4dc62ebd9e
--- /dev/null
+++ b/src/lib/libssl/src/shlib/Makefile.hpux10-cc
@@ -0,0 +1,51 @@
1# Makefile.hpux-cc
2
3major=1
4
5slib=libssl
6sh_slib=$(slib).so.$(major)
7
8clib=libcrypto
9sh_clib=$(clib).so.$(major)
10
11all : $(clib).sl $(slib).sl
12
13
14$(clib)_pic.a : $(clib).a
15 echo "Copying $? to $@"
16 cp -p $? $@
17
18$(slib)_pic.a : $(slib).a
19 echo "Copying $? to $@"
20 cp -p $? $@
21
22$(sh_clib) : $(clib)_pic.a
23 echo "collecting all object files for $@"
24 find . -name \*.o -print > allobjs
25 for obj in `ar t $(clib)_pic.a`; \
26 do \
27 grep /$$obj allobjs; \
28 done >objlist
29 echo "linking $@"
30 ld -b -s -z +h $@ -o $@ `cat objlist` -lc
31 rm allobjs objlist
32
33$(clib).sl : $(sh_clib)
34 rm -f $@
35 ln -s $? $@
36
37$(sh_slib) : $(slib)_pic.a $(clib).sl
38 echo "collecting all object files for $@"
39 find . -name \*.o -print > allobjs
40 for obj in `ar t $(slib)_pic.a`; \
41 do \
42 grep /$$obj allobjs; \
43 done >objlist
44 echo "linking $@"
45 ld -b -s -z +h $@ +b /usr/local/ssl/lib:/usr/lib -o $@ `cat objlist` \
46 -L. -lcrypto -lc
47 rm -f allobjs objlist
48
49$(slib).sl : $(sh_slib)
50 rm -f $@
51 ln -s $? $@
diff --git a/src/lib/libssl/src/shlib/hpux10-cc.sh b/src/lib/libssl/src/shlib/hpux10-cc.sh
new file mode 100644
index 0000000000..903baaa4e7
--- /dev/null
+++ b/src/lib/libssl/src/shlib/hpux10-cc.sh
@@ -0,0 +1,90 @@
1#!/usr/bin/sh
2#
3# Run this script from the OpenSSL root directory:
4# sh shlib/hpux10-cc.sh
5#
6# HP-UX (10.20) shared library installation:
7# Compile and install OpenSSL with best possible optimization:
8# - shared libraries are compiled and installed with +O4 optimization
9# - executable(s) are compiled and installed with +O4 optimization
10# - static libraries are compiled and installed with +O3 optimization,
11# to avoid the time consuming +O4 link-time optimization when using
12# these libraries. (The shared libs are already optimized during build
13# at +O4.)
14#
15# This script must be run with appropriate privileges to install into
16# /usr/local/ssl. HP-UX prevents used executables and shared libraries
17# from being deleted or overwritten. Stop all processes using already
18# installed items of OpenSSL.
19#
20# WARNING: At high optimization levels, HP's ANSI-C compiler can chew up
21# large amounts of memory and CPU time. Make sure to have at least
22# 128MB of RAM available and that your kernel is configured to allow
23# at least 128MB data size (maxdsiz parameter).
24# The installation process can take several hours, even on fast
25# machines. +O4 optimization of the libcrypto.sl shared library may
26# take 1 hour on a C200 (200MHz PA8200 CPU), +O3 compilation of
27# fcrypt_b.c can take 20 minutes on this machine. Stay patient.
28#
29# SITEFLAGS: site specific flags. I do use +DAportable, since I have to
30# support older PA1.1-type CPUs. Your mileage may vary.
31# +w1 enables enhanced warnings, useful when working with snaphots.
32#
33SITEFLAGS="+DAportable +w1"
34#
35# Set the default additions to build with HP-UX.
36# -D_REENTRANT must/should be defined on HP-UX manually, since we do call
37# Configure directly.
38# +Oall increases the optimization done.
39#
40MYFLAGS="-D_REENTRANT +Oall $SITEFLAGS"
41
42# Configure for pic and build the static pic libraries
43perl5 Configure hpux-parisc-cc-o4 +z ${MYFLAGS}
44make clean
45make DIRS="crypto ssl"
46# Rename the static pic libs and build dynamic libraries from them
47# Be prepared to see a lot of warnings about shared libraries being built
48# with optimizations higher than +O2. When using these libraries, it is
49# not possible to replace internal library functions with functions from
50# the program to be linked.
51#
52make -f shlib/Makefile.hpux10-cc
53
54# Copy the libraries to /usr/local/ssl/lib (they have to be in their
55# final location when linking applications).
56# If the directories are still there, no problem.
57mkdir /usr/local
58mkdir /usr/local/ssl
59mkdir /usr/local/ssl/lib
60chmod 444 lib*_pic.a
61chmod 555 lib*.so.1
62cp -p lib*_pic.a lib*.so.1 /usr/local/ssl/lib
63(cd /usr/local/ssl/lib ; ln -sf libcrypto.so.1 libcrypto.sl ; ln -sf libssl.so.1 libssl.sl)
64
65# Reconfigure without pic to compile the executables. Unfortunately, while
66# performing this task we have to recompile the library components, even
67# though we use the already installed shared libs anyway.
68#
69perl5 Configure hpux-parisc-cc-o4 ${MYFLAGS}
70
71make clean
72
73# Hack the Makefiles to pick up the dynamic libraries during linking
74#
75sed 's/^PEX_LIBS=.*$/PEX_LIBS=-L\/usr\/local\/ssl\/lib -Wl,+b,\/usr\/local\/ssl\/lib:\/usr\/lib/' Makefile.ssl >xxx; mv xxx Makefile.ssl
76sed 's/-L\.\.//' apps/Makefile.ssl >xxx; mv xxx apps/Makefile.ssl
77sed 's/-L\.\.//' test/Makefile.ssl >xxx; mv xxx test/Makefile.ssl
78# Build the static libs and the executables in one make.
79make
80# Install everything
81make install
82
83# Finally build the static libs with +O3. This time we only need the libraries,
84# once created, they are simply copied into place.
85#
86perl5 Configure hpux-parisc-cc ${MYFLAGS}
87make clean
88make DIRS="crypto ssl"
89chmod 644 libcrypto.a libssl.a
90cp -p libcrypto.a libssl.a /usr/local/ssl/lib
diff --git a/src/lib/libssl/src/shlib/solaris-sc4.sh b/src/lib/libssl/src/shlib/solaris-sc4.sh
new file mode 100644
index 0000000000..b0766b35f7
--- /dev/null
+++ b/src/lib/libssl/src/shlib/solaris-sc4.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2
3major="1"
4
5slib=libssl
6sh_slib=$slib.so.$major
7
8clib=libcrypto
9sh_clib=$clib.so.$major
10
11echo collecting all object files for $clib.so
12OBJS=
13find . -name \*.o -print > allobjs
14for obj in `ar t libcrypto.a`
15do
16 OBJS="$OBJS `grep $obj allobjs`"
17done
18
19echo linking $clib.so
20cc -G -o $sh_clib -h $sh_clib $OBJS -lnsl -lsocket
21
22rm -f $clib.so
23ln -s $sh_clib $clib.so
24
25echo collecting all object files for $slib.so
26OBJS=
27for obj in `ar t libssl.a`
28do
29 OBJS="$OBJS `grep $obj allobjs`"
30done
31
32echo linking $slib.so
33cc -G -o $sh_slib -h $sh_slib $OBJS -L. -lcrypto
34
35rm -f $slib.so
36ln -s $sh_slib $slib.so
37
38rm -f allobjs
39
40mv libRSAglue.a libRSAglue.a.orig
41mv libcrypto.a libcrypto.a.orig
42mv libssl.a libssl.a.orig
diff --git a/src/lib/libssl/src/shlib/svr5-shared-gcc.sh b/src/lib/libssl/src/shlib/svr5-shared-gcc.sh
new file mode 100644
index 0000000000..b36a0375a6
--- /dev/null
+++ b/src/lib/libssl/src/shlib/svr5-shared-gcc.sh
@@ -0,0 +1,48 @@
1#!/usr/bin/sh
2
3major="0"
4minor="9.7"
5
6slib=libssl
7sh_slib=$slib.so.$major.$minor
8
9clib=libcrypto
10sh_clib=$clib.so.$major.$minor
11
12FLAGS="-O3 -DFILIO_H -fomit-frame-pointer -pthread
13SHFLAGS="-DPIC -fPIC"
14
15touch $sh_clib
16touch $sh_slib
17
18echo collecting all object files for $clib.so
19OBJS=
20find . -name \*.o -print > allobjs
21for obj in `ar t libcrypto.a`
22do
23 OBJS="$OBJS `grep $obj allobjs`"
24done
25
26echo linking $clib.so
27gcc -G -o $sh_clib -h $sh_clib $OBJS -lnsl -lsocket
28
29rm -f $clib.so
30ln -s $sh_clib $clib.so
31
32echo collecting all object files for $slib.so
33OBJS=
34for obj in `ar t libssl.a`
35do
36 OBJS="$OBJS `grep $obj allobjs`"
37done
38
39echo linking $slib.so
40gcc -G -o $sh_slib -h $sh_slib $OBJS -L. -lcrypto
41
42rm -f $slib.so
43ln -s $sh_slib $slib.so
44
45mv libRSAglue.a libRSAglue.a.orig
46mv libcrypto.a libcrypto.a.orig
47mv libssl.a libssl.a.orig
48
diff --git a/src/lib/libssl/src/shlib/svr5-shared-installed b/src/lib/libssl/src/shlib/svr5-shared-installed
new file mode 100644
index 0000000000..544f5a9417
--- /dev/null
+++ b/src/lib/libssl/src/shlib/svr5-shared-installed
@@ -0,0 +1,28 @@
1#!/usr/bin/sh
2
3major="0"
4minor="9.7"
5
6slib=libssl
7sh_slib=$slib.so.$major.$minor
8
9clib=libcrypto
10sh_clib=$clib.so.$major.$minor
11
12# If you want them in /usr/local/lib then change INSTALLTOP to point there.
13#INSTALLTOP=/usr/local/ssl/lib
14INSTALLTOP=/usr/local/lib
15
16cp -p $sh_clib $INSTALLTOP
17cp -p $sh_slib $INSTALLTOP
18
19PWD=`pwd`
20cd $INSTALLTOP
21rm -f $INSTALLTOP/$clib.so
22ln -s $INSTALLTOP/$sh_clib $clib.so
23
24rm -f $INSTALLTOP/$slib.so
25ln -s $INSTALLTOP/$sh_slib $slib.so
26
27cd $PWD
28
diff --git a/src/lib/libssl/src/shlib/svr5-shared.sh b/src/lib/libssl/src/shlib/svr5-shared.sh
new file mode 100644
index 0000000000..a70bb65baa
--- /dev/null
+++ b/src/lib/libssl/src/shlib/svr5-shared.sh
@@ -0,0 +1,48 @@
1#!/usr/bin/sh
2
3major="0"
4minor="9.7"
5
6slib=libssl
7sh_slib=$slib.so.$major.$minor
8
9clib=libcrypto
10sh_clib=$clib.so.$major.$minor
11
12FLAGS="-O -DFILIO_H -Kalloca -Kthread"
13SHFLAGS="-Kpic -DPIC"
14
15touch $sh_clib
16touch $sh_slib
17
18echo collecting all object files for $clib.so
19OBJS=
20find . -name \*.o -print > allobjs
21for obj in `ar t libcrypto.a`
22do
23 OBJS="$OBJS `grep $obj allobjs`"
24done
25
26echo linking $clib.so
27cc -G -o $sh_clib -h $sh_clib $OBJS -lnsl -lsocket
28
29rm -f $clib.so
30ln -s $sh_clib $clib.so
31
32echo collecting all object files for $slib.so
33OBJS=
34for obj in `ar t libssl.a`
35do
36 OBJS="$OBJS `grep $obj allobjs`"
37done
38
39echo linking $slib.so
40cc -G -o $sh_slib -h $sh_slib $OBJS -L. -lcrypto
41
42rm -f $slib.so
43ln -s $sh_slib $slib.so
44
45mv libRSAglue.a libRSAglue.a.orig
46mv libcrypto.a libcrypto.a.orig
47mv libssl.a libssl.a.orig
48
diff --git a/src/lib/libssl/src/ssl/install.com b/src/lib/libssl/src/ssl/install.com
new file mode 100644
index 0000000000..2b62f4e499
--- /dev/null
+++ b/src/lib/libssl/src/ssl/install.com
@@ -0,0 +1,102 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
23$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
24$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
25$ DEFINE/NOLOG WRK_SSLVEXE WRK_SSLROOT:[VAX_EXE]
26$ DEFINE/NOLOG WRK_SSLAEXE WRK_SSLROOT:[ALPHA_EXE]
27$
28$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
29 CREATE/DIR/LOG WRK_SSLROOT:[000000]
30$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLVLIB:
32$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLALIB:
34$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
35 CREATE/DIR/LOG WRK_SSLINCLUDE:
36$ IF F$PARSE("WRK_SSLVEXE:") .EQS. "" THEN -
37 CREATE/DIR/LOG WRK_SSLVEXE:
38$ IF F$PARSE("WRK_SSLAEXE:") .EQS. "" THEN -
39 CREATE/DIR/LOG WRK_SSLAEXE:
40$
41$ EXHEADER := ssl.h,ssl2.h,ssl3.h,ssl23.h,tls1.h
42$ E_EXE := ssl_task
43$ LIBS := LIBSSL
44$
45$ VEXE_DIR := [-.VAX.EXE.SSL]
46$ AEXE_DIR := [-.AXP.EXE.SSL]
47$
48$ COPY 'EXHEADER' WRK_SSLINCLUDE:/LOG
49$
50$ I = 0
51$ LOOP_EXE:
52$ E = F$EDIT(F$ELEMENT(I, ",", E_EXE),"TRIM")
53$ I = I + 1
54$ IF E .EQS. "," THEN GOTO LOOP_EXE_END
55$ SET NOON
56$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
57$ THEN
58$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVEXE:'E'.EXE/log
59$ SET FILE/PROT=W:RE WRK_SSLVEXE:'E'.EXE
60$ ENDIF
61$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
62$ THEN
63$ COPY 'AEXE_DIR''E'.EXE WRK_SSLAEXE:'E'.EXE/log
64$ SET FILE/PROT=W:RE WRK_SSLAEXE:'E'.EXE
65$ ENDIF
66$ SET ON
67$ GOTO LOOP_EXE
68$ LOOP_EXE_END:
69$
70$ I = 0
71$ LOOP_LIB:
72$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
73$ I = I + 1
74$ IF E .EQS. "," THEN GOTO LOOP_LIB_END
75$ SET NOON
76$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. ""
77$ THEN
78$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log
79$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB
80$ ENDIF
81$ ! Preparing for the time when we have shareable images
82$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
83$ THEN
84$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log
85$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE
86$ ENDIF
87$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. ""
88$ THEN
89$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log
90$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB
91$ ENDIF
92$ ! Preparing for the time when we have shareable images
93$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
94$ THEN
95$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log
96$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE
97$ ENDIF
98$ SET ON
99$ GOTO LOOP_LIB
100$ LOOP_LIB_END:
101$
102$ EXIT
diff --git a/src/lib/libssl/src/ssl/kssl.c b/src/lib/libssl/src/ssl/kssl.c
new file mode 100644
index 0000000000..d3c7be7581
--- /dev/null
+++ b/src/lib/libssl/src/ssl/kssl.c
@@ -0,0 +1,2195 @@
1/* ssl/kssl.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.
3 */
4/* ====================================================================
5 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58
59/* ssl/kssl.c -- Routines to support (& debug) Kerberos5 auth for openssl
60**
61** 19990701 VRS Started.
62** 200011?? Jeffrey Altman, Richard Levitte
63** Generalized for Heimdal, Newer MIT, & Win32.
64** Integrated into main OpenSSL 0.9.7 snapshots.
65** 20010413 Simon Wilkinson, VRS
66** Real RFC2712 KerberosWrapper replaces AP_REQ.
67*/
68
69#include <openssl/opensslconf.h>
70
71#define _XOPEN_SOURCE /* glibc2 needs this to declare strptime() */
72#include <time.h>
73#include <string.h>
74
75#include <openssl/ssl.h>
76#include <openssl/evp.h>
77#include <openssl/objects.h>
78#include <openssl/krb5_asn.h>
79
80#ifndef OPENSSL_NO_KRB5
81
82/*
83 * When OpenSSL is built on Windows, we do not want to require that
84 * the Kerberos DLLs be available in order for the OpenSSL DLLs to
85 * work. Therefore, all Kerberos routines are loaded at run time
86 * and we do not link to a .LIB file.
87 */
88
89#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
90/*
91 * The purpose of the following pre-processor statements is to provide
92 * compatibility with different releases of MIT Kerberos for Windows.
93 * All versions up to 1.2 used macros. But macros do not allow for
94 * a binary compatible interface for DLLs. Therefore, all macros are
95 * being replaced by function calls. The following code will allow
96 * an OpenSSL DLL built on Windows to work whether or not the macro
97 * or function form of the routines are utilized.
98 */
99#ifdef krb5_cc_get_principal
100#define NO_DEF_KRB5_CCACHE
101#undef krb5_cc_get_principal
102#endif
103#define krb5_cc_get_principal kssl_krb5_cc_get_principal
104
105#define krb5_free_data_contents kssl_krb5_free_data_contents
106#define krb5_free_context kssl_krb5_free_context
107#define krb5_auth_con_free kssl_krb5_auth_con_free
108#define krb5_free_principal kssl_krb5_free_principal
109#define krb5_mk_req_extended kssl_krb5_mk_req_extended
110#define krb5_get_credentials kssl_krb5_get_credentials
111#define krb5_cc_default kssl_krb5_cc_default
112#define krb5_sname_to_principal kssl_krb5_sname_to_principal
113#define krb5_init_context kssl_krb5_init_context
114#define krb5_free_ticket kssl_krb5_free_ticket
115#define krb5_rd_req kssl_krb5_rd_req
116#define krb5_kt_default kssl_krb5_kt_default
117#define krb5_kt_resolve kssl_krb5_kt_resolve
118/* macros in mit 1.2.2 and earlier; functions in mit 1.2.3 and greater */
119#ifndef krb5_kt_close
120#define krb5_kt_close kssl_krb5_kt_close
121#endif /* krb5_kt_close */
122#ifndef krb5_kt_get_entry
123#define krb5_kt_get_entry kssl_krb5_kt_get_entry
124#endif /* krb5_kt_get_entry */
125#define krb5_auth_con_init kssl_krb5_auth_con_init
126
127#define krb5_principal_compare kssl_krb5_principal_compare
128#define krb5_decrypt_tkt_part kssl_krb5_decrypt_tkt_part
129#define krb5_timeofday kssl_krb5_timeofday
130#define krb5_rc_default kssl_krb5_rc_default
131
132#ifdef krb5_rc_initialize
133#undef krb5_rc_initialize
134#endif
135#define krb5_rc_initialize kssl_krb5_rc_initialize
136
137#ifdef krb5_rc_get_lifespan
138#undef krb5_rc_get_lifespan
139#endif
140#define krb5_rc_get_lifespan kssl_krb5_rc_get_lifespan
141
142#ifdef krb5_rc_destroy
143#undef krb5_rc_destroy
144#endif
145#define krb5_rc_destroy kssl_krb5_rc_destroy
146
147#define valid_cksumtype kssl_valid_cksumtype
148#define krb5_checksum_size kssl_krb5_checksum_size
149#define krb5_kt_free_entry kssl_krb5_kt_free_entry
150#define krb5_auth_con_setrcache kssl_krb5_auth_con_setrcache
151#define krb5_auth_con_getrcache kssl_krb5_auth_con_getrcache
152#define krb5_get_server_rcache kssl_krb5_get_server_rcache
153
154/* Prototypes for built in stubs */
155void kssl_krb5_free_data_contents(krb5_context, krb5_data *);
156void kssl_krb5_free_principal(krb5_context, krb5_principal );
157krb5_error_code kssl_krb5_kt_resolve(krb5_context,
158 krb5_const char *,
159 krb5_keytab *);
160krb5_error_code kssl_krb5_kt_default(krb5_context,
161 krb5_keytab *);
162krb5_error_code kssl_krb5_free_ticket(krb5_context, krb5_ticket *);
163krb5_error_code kssl_krb5_rd_req(krb5_context, krb5_auth_context *,
164 krb5_const krb5_data *,
165 krb5_const_principal, krb5_keytab,
166 krb5_flags *,krb5_ticket **);
167
168krb5_boolean kssl_krb5_principal_compare(krb5_context, krb5_const_principal,
169 krb5_const_principal);
170krb5_error_code kssl_krb5_mk_req_extended(krb5_context,
171 krb5_auth_context *,
172 krb5_const krb5_flags,
173 krb5_data *,
174 krb5_creds *,
175 krb5_data * );
176krb5_error_code kssl_krb5_init_context(krb5_context *);
177void kssl_krb5_free_context(krb5_context);
178krb5_error_code kssl_krb5_cc_default(krb5_context,krb5_ccache *);
179krb5_error_code kssl_krb5_sname_to_principal(krb5_context,
180 krb5_const char *,
181 krb5_const char *,
182 krb5_int32,
183 krb5_principal *);
184krb5_error_code kssl_krb5_get_credentials(krb5_context,
185 krb5_const krb5_flags,
186 krb5_ccache,
187 krb5_creds *,
188 krb5_creds * *);
189krb5_error_code kssl_krb5_auth_con_init(krb5_context,
190 krb5_auth_context *);
191krb5_error_code kssl_krb5_cc_get_principal(krb5_context context,
192 krb5_ccache cache,
193 krb5_principal *principal);
194krb5_error_code kssl_krb5_auth_con_free(krb5_context,krb5_auth_context);
195size_t kssl_krb5_checksum_size(krb5_context context,krb5_cksumtype ctype);
196krb5_boolean kssl_valid_cksumtype(krb5_cksumtype ctype);
197krb5_error_code krb5_kt_free_entry(krb5_context,krb5_keytab_entry FAR * );
198krb5_error_code kssl_krb5_auth_con_setrcache(krb5_context,
199 krb5_auth_context,
200 krb5_rcache);
201krb5_error_code kssl_krb5_get_server_rcache(krb5_context,
202 krb5_const krb5_data *,
203 krb5_rcache *);
204krb5_error_code kssl_krb5_auth_con_getrcache(krb5_context,
205 krb5_auth_context,
206 krb5_rcache *);
207
208/* Function pointers (almost all Kerberos functions are _stdcall) */
209static void (_stdcall *p_krb5_free_data_contents)(krb5_context, krb5_data *)
210 =NULL;
211static void (_stdcall *p_krb5_free_principal)(krb5_context, krb5_principal )
212 =NULL;
213static krb5_error_code(_stdcall *p_krb5_kt_resolve)
214 (krb5_context, krb5_const char *, krb5_keytab *)=NULL;
215static krb5_error_code (_stdcall *p_krb5_kt_default)(krb5_context,
216 krb5_keytab *)=NULL;
217static krb5_error_code (_stdcall *p_krb5_free_ticket)(krb5_context,
218 krb5_ticket *)=NULL;
219static krb5_error_code (_stdcall *p_krb5_rd_req)(krb5_context,
220 krb5_auth_context *,
221 krb5_const krb5_data *,
222 krb5_const_principal,
223 krb5_keytab, krb5_flags *,
224 krb5_ticket **)=NULL;
225static krb5_error_code (_stdcall *p_krb5_mk_req_extended)
226 (krb5_context, krb5_auth_context *,
227 krb5_const krb5_flags, krb5_data *, krb5_creds *,
228 krb5_data * )=NULL;
229static krb5_error_code (_stdcall *p_krb5_init_context)(krb5_context *)=NULL;
230static void (_stdcall *p_krb5_free_context)(krb5_context)=NULL;
231static krb5_error_code (_stdcall *p_krb5_cc_default)(krb5_context,
232 krb5_ccache *)=NULL;
233static krb5_error_code (_stdcall *p_krb5_sname_to_principal)
234 (krb5_context, krb5_const char *, krb5_const char *,
235 krb5_int32, krb5_principal *)=NULL;
236static krb5_error_code (_stdcall *p_krb5_get_credentials)
237 (krb5_context, krb5_const krb5_flags, krb5_ccache,
238 krb5_creds *, krb5_creds **)=NULL;
239static krb5_error_code (_stdcall *p_krb5_auth_con_init)
240 (krb5_context, krb5_auth_context *)=NULL;
241static krb5_error_code (_stdcall *p_krb5_cc_get_principal)
242 (krb5_context context, krb5_ccache cache,
243 krb5_principal *principal)=NULL;
244static krb5_error_code (_stdcall *p_krb5_auth_con_free)
245 (krb5_context, krb5_auth_context)=NULL;
246static krb5_error_code (_stdcall *p_krb5_decrypt_tkt_part)
247 (krb5_context, krb5_const krb5_keyblock *,
248 krb5_ticket *)=NULL;
249static krb5_error_code (_stdcall *p_krb5_timeofday)
250 (krb5_context context, krb5_int32 *timeret)=NULL;
251static krb5_error_code (_stdcall *p_krb5_rc_default)
252 (krb5_context context, krb5_rcache *rc)=NULL;
253static krb5_error_code (_stdcall *p_krb5_rc_initialize)
254 (krb5_context context, krb5_rcache rc,
255 krb5_deltat lifespan)=NULL;
256static krb5_error_code (_stdcall *p_krb5_rc_get_lifespan)
257 (krb5_context context, krb5_rcache rc,
258 krb5_deltat *lifespan)=NULL;
259static krb5_error_code (_stdcall *p_krb5_rc_destroy)
260 (krb5_context context, krb5_rcache rc)=NULL;
261static krb5_boolean (_stdcall *p_krb5_principal_compare)
262 (krb5_context, krb5_const_principal, krb5_const_principal)=NULL;
263static size_t (_stdcall *p_krb5_checksum_size)(krb5_context context,krb5_cksumtype ctype)=NULL;
264static krb5_boolean (_stdcall *p_valid_cksumtype)(krb5_cksumtype ctype)=NULL;
265static krb5_error_code (_stdcall *p_krb5_kt_free_entry)
266 (krb5_context,krb5_keytab_entry * )=NULL;
267static krb5_error_code (_stdcall * p_krb5_auth_con_setrcache)(krb5_context,
268 krb5_auth_context,
269 krb5_rcache)=NULL;
270static krb5_error_code (_stdcall * p_krb5_get_server_rcache)(krb5_context,
271 krb5_const krb5_data *,
272 krb5_rcache *)=NULL;
273static krb5_error_code (* p_krb5_auth_con_getrcache)(krb5_context,
274 krb5_auth_context,
275 krb5_rcache *)=NULL;
276static krb5_error_code (_stdcall * p_krb5_kt_close)(krb5_context context,
277 krb5_keytab keytab)=NULL;
278static krb5_error_code (_stdcall * p_krb5_kt_get_entry)(krb5_context context,
279 krb5_keytab keytab,
280 krb5_const_principal principal, krb5_kvno vno,
281 krb5_enctype enctype, krb5_keytab_entry *entry)=NULL;
282static int krb5_loaded = 0; /* only attempt to initialize func ptrs once */
283
284/* Function to Load the Kerberos 5 DLL and initialize function pointers */
285void
286load_krb5_dll(void)
287 {
288 HANDLE hKRB5_32;
289
290 krb5_loaded++;
291 hKRB5_32 = LoadLibrary("KRB5_32");
292 if (!hKRB5_32)
293 return;
294
295 (FARPROC) p_krb5_free_data_contents =
296 GetProcAddress( hKRB5_32, "krb5_free_data_contents" );
297 (FARPROC) p_krb5_free_context =
298 GetProcAddress( hKRB5_32, "krb5_free_context" );
299 (FARPROC) p_krb5_auth_con_free =
300 GetProcAddress( hKRB5_32, "krb5_auth_con_free" );
301 (FARPROC) p_krb5_free_principal =
302 GetProcAddress( hKRB5_32, "krb5_free_principal" );
303 (FARPROC) p_krb5_mk_req_extended =
304 GetProcAddress( hKRB5_32, "krb5_mk_req_extended" );
305 (FARPROC) p_krb5_get_credentials =
306 GetProcAddress( hKRB5_32, "krb5_get_credentials" );
307 (FARPROC) p_krb5_cc_get_principal =
308 GetProcAddress( hKRB5_32, "krb5_cc_get_principal" );
309 (FARPROC) p_krb5_cc_default =
310 GetProcAddress( hKRB5_32, "krb5_cc_default" );
311 (FARPROC) p_krb5_sname_to_principal =
312 GetProcAddress( hKRB5_32, "krb5_sname_to_principal" );
313 (FARPROC) p_krb5_init_context =
314 GetProcAddress( hKRB5_32, "krb5_init_context" );
315 (FARPROC) p_krb5_free_ticket =
316 GetProcAddress( hKRB5_32, "krb5_free_ticket" );
317 (FARPROC) p_krb5_rd_req =
318 GetProcAddress( hKRB5_32, "krb5_rd_req" );
319 (FARPROC) p_krb5_principal_compare =
320 GetProcAddress( hKRB5_32, "krb5_principal_compare" );
321 (FARPROC) p_krb5_decrypt_tkt_part =
322 GetProcAddress( hKRB5_32, "krb5_decrypt_tkt_part" );
323 (FARPROC) p_krb5_timeofday =
324 GetProcAddress( hKRB5_32, "krb5_timeofday" );
325 (FARPROC) p_krb5_rc_default =
326 GetProcAddress( hKRB5_32, "krb5_rc_default" );
327 (FARPROC) p_krb5_rc_initialize =
328 GetProcAddress( hKRB5_32, "krb5_rc_initialize" );
329 (FARPROC) p_krb5_rc_get_lifespan =
330 GetProcAddress( hKRB5_32, "krb5_rc_get_lifespan" );
331 (FARPROC) p_krb5_rc_destroy =
332 GetProcAddress( hKRB5_32, "krb5_rc_destroy" );
333 (FARPROC) p_krb5_kt_default =
334 GetProcAddress( hKRB5_32, "krb5_kt_default" );
335 (FARPROC) p_krb5_kt_resolve =
336 GetProcAddress( hKRB5_32, "krb5_kt_resolve" );
337 (FARPROC) p_krb5_auth_con_init =
338 GetProcAddress( hKRB5_32, "krb5_auth_con_init" );
339 (FARPROC) p_valid_cksumtype =
340 GetProcAddress( hKRB5_32, "valid_cksumtype" );
341 (FARPROC) p_krb5_checksum_size =
342 GetProcAddress( hKRB5_32, "krb5_checksum_size" );
343 (FARPROC) p_krb5_kt_free_entry =
344 GetProcAddress( hKRB5_32, "krb5_kt_free_entry" );
345 (FARPROC) p_krb5_auth_con_setrcache =
346 GetProcAddress( hKRB5_32, "krb5_auth_con_setrcache" );
347 (FARPROC) p_krb5_get_server_rcache =
348 GetProcAddress( hKRB5_32, "krb5_get_server_rcache" );
349 (FARPROC) p_krb5_auth_con_getrcache =
350 GetProcAddress( hKRB5_32, "krb5_auth_con_getrcache" );
351 (FARPROC) p_krb5_kt_close =
352 GetProcAddress( hKRB5_32, "krb5_kt_close" );
353 (FARPROC) p_krb5_kt_get_entry =
354 GetProcAddress( hKRB5_32, "krb5_kt_get_entry" );
355 }
356
357/* Stubs for each function to be dynamicly loaded */
358void
359kssl_krb5_free_data_contents(krb5_context CO, krb5_data * data)
360 {
361 if (!krb5_loaded)
362 load_krb5_dll();
363
364 if ( p_krb5_free_data_contents )
365 p_krb5_free_data_contents(CO,data);
366 }
367
368krb5_error_code
369kssl_krb5_mk_req_extended (krb5_context CO,
370 krb5_auth_context * pACO,
371 krb5_const krb5_flags F,
372 krb5_data * pD1,
373 krb5_creds * pC,
374 krb5_data * pD2)
375 {
376 if (!krb5_loaded)
377 load_krb5_dll();
378
379 if ( p_krb5_mk_req_extended )
380 return(p_krb5_mk_req_extended(CO,pACO,F,pD1,pC,pD2));
381 else
382 return KRB5KRB_ERR_GENERIC;
383 }
384krb5_error_code
385kssl_krb5_auth_con_init(krb5_context CO,
386 krb5_auth_context * pACO)
387 {
388 if (!krb5_loaded)
389 load_krb5_dll();
390
391 if ( p_krb5_auth_con_init )
392 return(p_krb5_auth_con_init(CO,pACO));
393 else
394 return KRB5KRB_ERR_GENERIC;
395 }
396krb5_error_code
397kssl_krb5_auth_con_free (krb5_context CO,
398 krb5_auth_context ACO)
399 {
400 if (!krb5_loaded)
401 load_krb5_dll();
402
403 if ( p_krb5_auth_con_free )
404 return(p_krb5_auth_con_free(CO,ACO));
405 else
406 return KRB5KRB_ERR_GENERIC;
407 }
408krb5_error_code
409kssl_krb5_get_credentials(krb5_context CO,
410 krb5_const krb5_flags F,
411 krb5_ccache CC,
412 krb5_creds * pCR,
413 krb5_creds ** ppCR)
414 {
415 if (!krb5_loaded)
416 load_krb5_dll();
417
418 if ( p_krb5_get_credentials )
419 return(p_krb5_get_credentials(CO,F,CC,pCR,ppCR));
420 else
421 return KRB5KRB_ERR_GENERIC;
422 }
423krb5_error_code
424kssl_krb5_sname_to_principal(krb5_context CO,
425 krb5_const char * pC1,
426 krb5_const char * pC2,
427 krb5_int32 I,
428 krb5_principal * pPR)
429 {
430 if (!krb5_loaded)
431 load_krb5_dll();
432
433 if ( p_krb5_sname_to_principal )
434 return(p_krb5_sname_to_principal(CO,pC1,pC2,I,pPR));
435 else
436 return KRB5KRB_ERR_GENERIC;
437 }
438
439krb5_error_code
440kssl_krb5_cc_default(krb5_context CO,
441 krb5_ccache * pCC)
442 {
443 if (!krb5_loaded)
444 load_krb5_dll();
445
446 if ( p_krb5_cc_default )
447 return(p_krb5_cc_default(CO,pCC));
448 else
449 return KRB5KRB_ERR_GENERIC;
450 }
451
452krb5_error_code
453kssl_krb5_init_context(krb5_context * pCO)
454 {
455 if (!krb5_loaded)
456 load_krb5_dll();
457
458 if ( p_krb5_init_context )
459 return(p_krb5_init_context(pCO));
460 else
461 return KRB5KRB_ERR_GENERIC;
462 }
463
464void
465kssl_krb5_free_context(krb5_context CO)
466 {
467 if (!krb5_loaded)
468 load_krb5_dll();
469
470 if ( p_krb5_free_context )
471 p_krb5_free_context(CO);
472 }
473
474void
475kssl_krb5_free_principal(krb5_context c, krb5_principal p)
476 {
477 if (!krb5_loaded)
478 load_krb5_dll();
479
480 if ( p_krb5_free_principal )
481 p_krb5_free_principal(c,p);
482 }
483
484krb5_error_code
485kssl_krb5_kt_resolve(krb5_context con,
486 krb5_const char * sz,
487 krb5_keytab * kt)
488 {
489 if (!krb5_loaded)
490 load_krb5_dll();
491
492 if ( p_krb5_kt_resolve )
493 return(p_krb5_kt_resolve(con,sz,kt));
494 else
495 return KRB5KRB_ERR_GENERIC;
496 }
497
498krb5_error_code
499kssl_krb5_kt_default(krb5_context con,
500 krb5_keytab * kt)
501 {
502 if (!krb5_loaded)
503 load_krb5_dll();
504
505 if ( p_krb5_kt_default )
506 return(p_krb5_kt_default(con,kt));
507 else
508 return KRB5KRB_ERR_GENERIC;
509 }
510
511krb5_error_code
512kssl_krb5_free_ticket(krb5_context con,
513 krb5_ticket * kt)
514 {
515 if (!krb5_loaded)
516 load_krb5_dll();
517
518 if ( p_krb5_free_ticket )
519 return(p_krb5_free_ticket(con,kt));
520 else
521 return KRB5KRB_ERR_GENERIC;
522 }
523
524krb5_error_code
525kssl_krb5_rd_req(krb5_context con, krb5_auth_context * pacon,
526 krb5_const krb5_data * data,
527 krb5_const_principal princ, krb5_keytab keytab,
528 krb5_flags * flags, krb5_ticket ** pptkt)
529 {
530 if (!krb5_loaded)
531 load_krb5_dll();
532
533 if ( p_krb5_rd_req )
534 return(p_krb5_rd_req(con,pacon,data,princ,keytab,flags,pptkt));
535 else
536 return KRB5KRB_ERR_GENERIC;
537 }
538
539krb5_boolean
540krb5_principal_compare(krb5_context con, krb5_const_principal princ1,
541 krb5_const_principal princ2)
542 {
543 if (!krb5_loaded)
544 load_krb5_dll();
545
546 if ( p_krb5_principal_compare )
547 return(p_krb5_principal_compare(con,princ1,princ2));
548 else
549 return KRB5KRB_ERR_GENERIC;
550 }
551
552krb5_error_code
553krb5_decrypt_tkt_part(krb5_context con, krb5_const krb5_keyblock *keys,
554 krb5_ticket *ticket)
555 {
556 if (!krb5_loaded)
557 load_krb5_dll();
558
559 if ( p_krb5_decrypt_tkt_part )
560 return(p_krb5_decrypt_tkt_part(con,keys,ticket));
561 else
562 return KRB5KRB_ERR_GENERIC;
563 }
564
565krb5_error_code
566krb5_timeofday(krb5_context con, krb5_int32 *timeret)
567 {
568 if (!krb5_loaded)
569 load_krb5_dll();
570
571 if ( p_krb5_timeofday )
572 return(p_krb5_timeofday(con,timeret));
573 else
574 return KRB5KRB_ERR_GENERIC;
575 }
576
577krb5_error_code
578krb5_rc_default(krb5_context con, krb5_rcache *rc)
579 {
580 if (!krb5_loaded)
581 load_krb5_dll();
582
583 if ( p_krb5_rc_default )
584 return(p_krb5_rc_default(con,rc));
585 else
586 return KRB5KRB_ERR_GENERIC;
587 }
588
589krb5_error_code
590krb5_rc_initialize(krb5_context con, krb5_rcache rc, krb5_deltat lifespan)
591 {
592 if (!krb5_loaded)
593 load_krb5_dll();
594
595 if ( p_krb5_rc_initialize )
596 return(p_krb5_rc_initialize(con, rc, lifespan));
597 else
598 return KRB5KRB_ERR_GENERIC;
599 }
600
601krb5_error_code
602krb5_rc_get_lifespan(krb5_context con, krb5_rcache rc, krb5_deltat *lifespanp)
603 {
604 if (!krb5_loaded)
605 load_krb5_dll();
606
607 if ( p_krb5_rc_get_lifespan )
608 return(p_krb5_rc_get_lifespan(con, rc, lifespanp));
609 else
610 return KRB5KRB_ERR_GENERIC;
611 }
612
613krb5_error_code
614krb5_rc_destroy(krb5_context con, krb5_rcache rc)
615 {
616 if (!krb5_loaded)
617 load_krb5_dll();
618
619 if ( p_krb5_rc_destroy )
620 return(p_krb5_rc_destroy(con, rc));
621 else
622 return KRB5KRB_ERR_GENERIC;
623 }
624
625size_t
626krb5_checksum_size(krb5_context context,krb5_cksumtype ctype)
627 {
628 if (!krb5_loaded)
629 load_krb5_dll();
630
631 if ( p_krb5_checksum_size )
632 return(p_krb5_checksum_size(context, ctype));
633 else
634 return KRB5KRB_ERR_GENERIC;
635 }
636
637krb5_boolean
638valid_cksumtype(krb5_cksumtype ctype)
639 {
640 if (!krb5_loaded)
641 load_krb5_dll();
642
643 if ( p_valid_cksumtype )
644 return(p_valid_cksumtype(ctype));
645 else
646 return KRB5KRB_ERR_GENERIC;
647 }
648
649krb5_error_code
650krb5_kt_free_entry(krb5_context con,krb5_keytab_entry * entry)
651 {
652 if (!krb5_loaded)
653 load_krb5_dll();
654
655 if ( p_krb5_kt_free_entry )
656 return(p_krb5_kt_free_entry(con,entry));
657 else
658 return KRB5KRB_ERR_GENERIC;
659 }
660
661/* Structure definitions */
662#ifndef NO_DEF_KRB5_CCACHE
663#ifndef krb5_x
664#define krb5_x(ptr,args) ((ptr)?((*(ptr)) args):(abort(),1))
665#define krb5_xc(ptr,args) ((ptr)?((*(ptr)) args):(abort(),(char*)0))
666#endif
667
668typedef krb5_pointer krb5_cc_cursor; /* cursor for sequential lookup */
669
670typedef struct _krb5_ccache
671 {
672 krb5_magic magic;
673 struct _krb5_cc_ops FAR *ops;
674 krb5_pointer data;
675 } *krb5_ccache;
676
677typedef struct _krb5_cc_ops
678 {
679 krb5_magic magic;
680 char *prefix;
681 char * (KRB5_CALLCONV *get_name)
682 (krb5_context, krb5_ccache);
683 krb5_error_code (KRB5_CALLCONV *resolve)
684 (krb5_context, krb5_ccache *, const char *);
685 krb5_error_code (KRB5_CALLCONV *gen_new)
686 (krb5_context, krb5_ccache *);
687 krb5_error_code (KRB5_CALLCONV *init)
688 (krb5_context, krb5_ccache, krb5_principal);
689 krb5_error_code (KRB5_CALLCONV *destroy)
690 (krb5_context, krb5_ccache);
691 krb5_error_code (KRB5_CALLCONV *close)
692 (krb5_context, krb5_ccache);
693 krb5_error_code (KRB5_CALLCONV *store)
694 (krb5_context, krb5_ccache, krb5_creds *);
695 krb5_error_code (KRB5_CALLCONV *retrieve)
696 (krb5_context, krb5_ccache,
697 krb5_flags, krb5_creds *, krb5_creds *);
698 krb5_error_code (KRB5_CALLCONV *get_princ)
699 (krb5_context, krb5_ccache, krb5_principal *);
700 krb5_error_code (KRB5_CALLCONV *get_first)
701 (krb5_context, krb5_ccache, krb5_cc_cursor *);
702 krb5_error_code (KRB5_CALLCONV *get_next)
703 (krb5_context, krb5_ccache,
704 krb5_cc_cursor *, krb5_creds *);
705 krb5_error_code (KRB5_CALLCONV *end_get)
706 (krb5_context, krb5_ccache, krb5_cc_cursor *);
707 krb5_error_code (KRB5_CALLCONV *remove_cred)
708 (krb5_context, krb5_ccache,
709 krb5_flags, krb5_creds *);
710 krb5_error_code (KRB5_CALLCONV *set_flags)
711 (krb5_context, krb5_ccache, krb5_flags);
712 } krb5_cc_ops;
713#endif /* NO_DEF_KRB5_CCACHE */
714
715krb5_error_code
716kssl_krb5_cc_get_principal
717 (krb5_context context, krb5_ccache cache,
718 krb5_principal *principal)
719 {
720 if ( p_krb5_cc_get_principal )
721 return(p_krb5_cc_get_principal(context,cache,principal));
722 else
723 return(krb5_x
724 ((cache)->ops->get_princ,(context, cache, principal)));
725 }
726
727krb5_error_code
728kssl_krb5_auth_con_setrcache(krb5_context con, krb5_auth_context acon,
729 krb5_rcache rcache)
730 {
731 if ( p_krb5_auth_con_setrcache )
732 return(p_krb5_auth_con_setrcache(con,acon,rcache));
733 else
734 return KRB5KRB_ERR_GENERIC;
735 }
736
737krb5_error_code
738kssl_krb5_get_server_rcache(krb5_context con, krb5_const krb5_data * data,
739 krb5_rcache * rcache)
740 {
741 if ( p_krb5_get_server_rcache )
742 return(p_krb5_get_server_rcache(con,data,rcache));
743 else
744 return KRB5KRB_ERR_GENERIC;
745 }
746
747krb5_error_code
748kssl_krb5_auth_con_getrcache(krb5_context con, krb5_auth_context acon,
749 krb5_rcache * prcache)
750 {
751 if ( p_krb5_auth_con_getrcache )
752 return(p_krb5_auth_con_getrcache(con,acon, prcache));
753 else
754 return KRB5KRB_ERR_GENERIC;
755 }
756
757krb5_error_code
758kssl_krb5_kt_close(krb5_context context, krb5_keytab keytab)
759 {
760 if ( p_krb5_kt_close )
761 return(p_krb5_kt_close(context,keytab));
762 else
763 return KRB5KRB_ERR_GENERIC;
764 }
765
766krb5_error_code
767kssl_krb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
768 krb5_const_principal principal, krb5_kvno vno,
769 krb5_enctype enctype, krb5_keytab_entry *entry)
770 {
771 if ( p_krb5_kt_get_entry )
772 return(p_krb5_kt_get_entry(context,keytab,principal,vno,enctype,entry));
773 else
774 return KRB5KRB_ERR_GENERIC;
775 }
776#endif /* OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32 */
777
778char
779*kstring(char *string)
780 {
781 static char *null = "[NULL]";
782
783 return ((string == NULL)? null: string);
784 }
785
786#define MAXKNUM 255
787char
788*knumber(int len, krb5_octet *contents)
789 {
790 static char buf[MAXKNUM+1];
791 int i;
792
793 BIO_snprintf(buf, MAXKNUM, "[%d] ", len);
794
795 for (i=0; i < len && MAXKNUM > strlen(buf)+3; i++)
796 {
797 BIO_snprintf(&buf[strlen(buf)], 3, "%02x", contents[i]);
798 }
799
800 return (buf);
801 }
802
803
804/* Given KRB5 enctype (basically DES or 3DES),
805** return closest match openssl EVP_ encryption algorithm.
806** Return NULL for unknown or problematic (krb5_dk_encrypt) enctypes.
807** Assume ENCTYPE_*_RAW (krb5_raw_encrypt) are OK.
808*/
809const EVP_CIPHER *
810kssl_map_enc(krb5_enctype enctype)
811 {
812 switch (enctype)
813 {
814 case ENCTYPE_DES_HMAC_SHA1: /* EVP_des_cbc(); */
815 case ENCTYPE_DES_CBC_CRC:
816 case ENCTYPE_DES_CBC_MD4:
817 case ENCTYPE_DES_CBC_MD5:
818 case ENCTYPE_DES_CBC_RAW:
819 return EVP_des_cbc();
820 break;
821 case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
822 case ENCTYPE_DES3_CBC_SHA:
823 case ENCTYPE_DES3_CBC_RAW:
824 return EVP_des_ede3_cbc();
825 break;
826 default: return NULL;
827 break;
828 }
829 }
830
831
832/* Return true:1 if p "looks like" the start of the real authenticator
833** described in kssl_skip_confound() below. The ASN.1 pattern is
834** "62 xx 30 yy" (APPLICATION-2, SEQUENCE), where xx-yy =~ 2, and
835** xx and yy are possibly multi-byte length fields.
836*/
837int kssl_test_confound(unsigned char *p)
838 {
839 int len = 2;
840 int xx = 0, yy = 0;
841
842 if (*p++ != 0x62) return 0;
843 if (*p > 0x82) return 0;
844 switch(*p) {
845 case 0x82: p++; xx = (*p++ << 8); xx += *p++; break;
846 case 0x81: p++; xx = *p++; break;
847 case 0x80: return 0;
848 default: xx = *p++; break;
849 }
850 if (*p++ != 0x30) return 0;
851 if (*p > 0x82) return 0;
852 switch(*p) {
853 case 0x82: p++; len+=2; yy = (*p++ << 8); yy += *p++; break;
854 case 0x81: p++; len++; yy = *p++; break;
855 case 0x80: return 0;
856 default: yy = *p++; break;
857 }
858
859 return (xx - len == yy)? 1: 0;
860 }
861
862/* Allocate, fill, and return cksumlens array of checksum lengths.
863** This array holds just the unique elements from the krb5_cksumarray[].
864** array[n] == 0 signals end of data.
865**
866** The krb5_cksumarray[] was an internal variable that has since been
867** replaced by a more general method for storing the data. It should
868** not be used. Instead we use real API calls and make a guess for
869** what the highest assigned CKSUMTYPE_ constant is. As of 1.2.2
870** it is 0x000c (CKSUMTYPE_HMAC_SHA1_DES3). So we will use 0x0010.
871*/
872size_t *populate_cksumlens(void)
873 {
874 int i, j, n;
875 static size_t *cklens = NULL;
876
877#ifdef KRB5_MIT_OLD11
878 n = krb5_max_cksum;
879#else
880 n = 0x0010;
881#endif /* KRB5_MIT_OLD11 */
882
883#ifdef KRB5CHECKAUTH
884 if (!cklens && !(cklens = (size_t *) calloc(sizeof(int),n+1))) return NULL;
885
886 for (i=0; i < n; i++) {
887 if (!valid_cksumtype(i)) continue; /* array has holes */
888 for (j=0; j < n; j++) {
889 if (cklens[j] == 0) {
890 cklens[j] = krb5_checksum_size(NULL,i);
891 break; /* krb5 elem was new: add */
892 }
893 if (cklens[j] == krb5_checksum_size(NULL,i)) {
894 break; /* ignore duplicate elements */
895 }
896 }
897 }
898#endif /* KRB5CHECKAUTH */
899
900 return cklens;
901 }
902
903/* Return pointer to start of real authenticator within authenticator, or
904** return NULL on error.
905** Decrypted authenticator looks like this:
906** [0 or 8 byte confounder] [4-24 byte checksum] [real authent'r]
907** This hackery wouldn't be necessary if MIT KRB5 1.0.6 had the
908** krb5_auth_con_getcksumtype() function advertised in its krb5.h.
909*/
910unsigned char *kssl_skip_confound(krb5_enctype etype, unsigned char *a)
911 {
912 int i, conlen;
913 size_t cklen;
914 static size_t *cksumlens = NULL;
915 unsigned char *test_auth;
916
917 conlen = (etype)? 8: 0;
918
919 if (!cksumlens && !(cksumlens = populate_cksumlens())) return NULL;
920 for (i=0; (cklen = cksumlens[i]) != 0; i++)
921 {
922 test_auth = a + conlen + cklen;
923 if (kssl_test_confound(test_auth)) return test_auth;
924 }
925
926 return NULL;
927 }
928
929
930/* Set kssl_err error info when reason text is a simple string
931** kssl_err = struct { int reason; char text[KSSL_ERR_MAX+1]; }
932*/
933void
934kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text)
935 {
936 if (kssl_err == NULL) return;
937
938 kssl_err->reason = reason;
939 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX, text);
940 return;
941 }
942
943
944/* Display contents of krb5_data struct, for debugging
945*/
946void
947print_krb5_data(char *label, krb5_data *kdata)
948 {
949 int i;
950
951 printf("%s[%d] ", label, kdata->length);
952 for (i=0; i < kdata->length; i++)
953 {
954 if (0 && isprint((int) kdata->data[i]))
955 printf( "%c ", kdata->data[i]);
956 else
957 printf( "%02x ", (unsigned char) kdata->data[i]);
958 }
959 printf("\n");
960 }
961
962
963/* Display contents of krb5_authdata struct, for debugging
964*/
965void
966print_krb5_authdata(char *label, krb5_authdata **adata)
967 {
968 if (adata == NULL)
969 {
970 printf("%s, authdata==0\n", label);
971 return;
972 }
973 printf("%s [%p]\n", label, adata);
974#if 0
975 {
976 int i;
977 printf("%s[at%d:%d] ", label, adata->ad_type, adata->length);
978 for (i=0; i < adata->length; i++)
979 {
980 printf((isprint(adata->contents[i]))? "%c ": "%02x",
981 adata->contents[i]);
982 }
983 printf("\n");
984 }
985#endif
986 }
987
988
989/* Display contents of krb5_keyblock struct, for debugging
990*/
991void
992print_krb5_keyblock(char *label, krb5_keyblock *keyblk)
993 {
994 int i;
995
996 if (keyblk == NULL)
997 {
998 printf("%s, keyblk==0\n", label);
999 return;
1000 }
1001#ifdef KRB5_HEIMDAL
1002 printf("%s\n\t[et%d:%d]: ", label, keyblk->keytype,
1003 keyblk->keyvalue->length);
1004 for (i=0; i < keyblk->keyvalue->length; i++)
1005 {
1006 printf("%02x",(unsigned char *)(keyblk->keyvalue->contents)[i]);
1007 }
1008 printf("\n");
1009#else
1010 printf("%s\n\t[et%d:%d]: ", label, keyblk->enctype, keyblk->length);
1011 for (i=0; i < keyblk->length; i++)
1012 {
1013 printf("%02x",keyblk->contents[i]);
1014 }
1015 printf("\n");
1016#endif
1017 }
1018
1019
1020/* Display contents of krb5_principal_data struct, for debugging
1021** (krb5_principal is typedef'd == krb5_principal_data *)
1022*/
1023void
1024print_krb5_princ(char *label, krb5_principal_data *princ)
1025 {
1026 int i, ui, uj;
1027
1028 printf("%s principal Realm: ", label);
1029 if (princ == NULL) return;
1030 for (ui=0; ui < princ->realm.length; ui++) putchar(princ->realm.data[ui]);
1031 printf(" (nametype %d) has %d strings:\n", princ->type,princ->length);
1032 for (i=0; i < princ->length; i++)
1033 {
1034 printf("\t%d [%d]: ", i, princ->data[i].length);
1035 for (uj=0; uj < princ->data[i].length; uj++) {
1036 putchar(princ->data[i].data[uj]);
1037 }
1038 printf("\n");
1039 }
1040 return;
1041 }
1042
1043
1044/* Given krb5 service (typically "kssl") and hostname in kssl_ctx,
1045** Return encrypted Kerberos ticket for service @ hostname.
1046** If authenp is non-NULL, also return encrypted authenticator,
1047** whose data should be freed by caller.
1048** (Originally was: Create Kerberos AP_REQ message for SSL Client.)
1049**
1050** 19990628 VRS Started; Returns Kerberos AP_REQ message.
1051** 20010409 VRS Modified for RFC2712; Returns enc tkt.
1052** 20010606 VRS May also return optional authenticator.
1053*/
1054krb5_error_code
1055kssl_cget_tkt( /* UPDATE */ KSSL_CTX *kssl_ctx,
1056 /* OUT */ krb5_data **enc_ticketp,
1057 /* UPDATE */ krb5_data *authenp,
1058 /* OUT */ KSSL_ERR *kssl_err)
1059 {
1060 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1061 krb5_context krb5context = NULL;
1062 krb5_auth_context krb5auth_context = NULL;
1063 krb5_ccache krb5ccdef = NULL;
1064 krb5_creds krb5creds, *krb5credsp = NULL;
1065 krb5_data krb5_app_req;
1066
1067 kssl_err_set(kssl_err, 0, "");
1068 memset((char *)&krb5creds, 0, sizeof(krb5creds));
1069
1070 if (!kssl_ctx)
1071 {
1072 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1073 "No kssl_ctx defined.\n");
1074 goto err;
1075 }
1076 else if (!kssl_ctx->service_host)
1077 {
1078 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1079 "kssl_ctx service_host undefined.\n");
1080 goto err;
1081 }
1082
1083 if ((krb5rc = krb5_init_context(&krb5context)) != 0)
1084 {
1085 BIO_snprintf(kssl_err->text,KSSL_ERR_MAX,
1086 "krb5_init_context() fails: %d\n", krb5rc);
1087 kssl_err->reason = SSL_R_KRB5_C_INIT;
1088 goto err;
1089 }
1090
1091 if ((krb5rc = krb5_sname_to_principal(krb5context,
1092 kssl_ctx->service_host,
1093 (kssl_ctx->service_name)? kssl_ctx->service_name: KRB5SVC,
1094 KRB5_NT_SRV_HST, &krb5creds.server)) != 0)
1095 {
1096 BIO_snprintf(kssl_err->text,KSSL_ERR_MAX,
1097 "krb5_sname_to_principal() fails for %s/%s\n",
1098 kssl_ctx->service_host,
1099 (kssl_ctx->service_name)? kssl_ctx->service_name:
1100 KRB5SVC);
1101 kssl_err->reason = SSL_R_KRB5_C_INIT;
1102 goto err;
1103 }
1104
1105 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
1106 {
1107 kssl_err_set(kssl_err, SSL_R_KRB5_C_CC_PRINC,
1108 "krb5_cc_default fails.\n");
1109 goto err;
1110 }
1111
1112 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
1113 &krb5creds.client)) != 0)
1114 {
1115 kssl_err_set(kssl_err, SSL_R_KRB5_C_CC_PRINC,
1116 "krb5_cc_get_principal() fails.\n");
1117 goto err;
1118 }
1119
1120 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
1121 &krb5creds, &krb5credsp)) != 0)
1122 {
1123 kssl_err_set(kssl_err, SSL_R_KRB5_C_GET_CRED,
1124 "krb5_get_credentials() fails.\n");
1125 goto err;
1126 }
1127
1128 *enc_ticketp = &krb5credsp->ticket;
1129#ifdef KRB5_HEIMDAL
1130 kssl_ctx->enctype = krb5credsp->session.keytype;
1131#else
1132 kssl_ctx->enctype = krb5credsp->keyblock.enctype;
1133#endif
1134
1135 krb5rc = KRB5KRB_ERR_GENERIC;
1136 /* caller should free data of krb5_app_req */
1137 /* 20010406 VRS deleted for real KerberosWrapper
1138 ** 20010605 VRS reinstated to offer Authenticator to KerberosWrapper
1139 */
1140 krb5_app_req.length = 0;
1141 if (authenp)
1142 {
1143 krb5_data krb5in_data;
1144 unsigned char *p;
1145 long arlen;
1146 KRB5_APREQBODY *ap_req;
1147
1148 authenp->length = 0;
1149 krb5in_data.data = NULL;
1150 krb5in_data.length = 0;
1151 if ((krb5rc = krb5_mk_req_extended(krb5context,
1152 &krb5auth_context, 0, &krb5in_data, krb5credsp,
1153 &krb5_app_req)) != 0)
1154 {
1155 kssl_err_set(kssl_err, SSL_R_KRB5_C_MK_REQ,
1156 "krb5_mk_req_extended() fails.\n");
1157 goto err;
1158 }
1159
1160 arlen = krb5_app_req.length;
1161 p = (unsigned char *)krb5_app_req.data;
1162 ap_req = (KRB5_APREQBODY *) d2i_KRB5_APREQ(NULL, &p, arlen);
1163 if (ap_req)
1164 {
1165 authenp->length = i2d_KRB5_ENCDATA(
1166 ap_req->authenticator, NULL);
1167 if (authenp->length &&
1168 (authenp->data = malloc(authenp->length)))
1169 {
1170 unsigned char *adp = (unsigned char *)authenp->data;
1171 authenp->length = i2d_KRB5_ENCDATA(
1172 ap_req->authenticator, &adp);
1173 }
1174 }
1175
1176 if (ap_req) KRB5_APREQ_free((KRB5_APREQ *) ap_req);
1177 if (krb5_app_req.length)
1178 kssl_krb5_free_data_contents(krb5context,&krb5_app_req);
1179 }
1180#ifdef KRB5_HEIMDAL
1181 if (kssl_ctx_setkey(kssl_ctx, &krb5credsp->session))
1182 {
1183 kssl_err_set(kssl_err, SSL_R_KRB5_C_INIT,
1184 "kssl_ctx_setkey() fails.\n");
1185 }
1186#else
1187 if (kssl_ctx_setkey(kssl_ctx, &krb5credsp->keyblock))
1188 {
1189 kssl_err_set(kssl_err, SSL_R_KRB5_C_INIT,
1190 "kssl_ctx_setkey() fails.\n");
1191 }
1192#endif
1193 else krb5rc = 0;
1194
1195 err:
1196#ifdef KSSL_DEBUG
1197 kssl_ctx_show(kssl_ctx);
1198#endif /* KSSL_DEBUG */
1199
1200 if (krb5creds.client) krb5_free_principal(krb5context,
1201 krb5creds.client);
1202 if (krb5creds.server) krb5_free_principal(krb5context,
1203 krb5creds.server);
1204 if (krb5auth_context) krb5_auth_con_free(krb5context,
1205 krb5auth_context);
1206 if (krb5context) krb5_free_context(krb5context);
1207 return (krb5rc);
1208 }
1209
1210
1211/* Given d2i_-decoded asn1ticket, allocate and return a new krb5_ticket.
1212** Return Kerberos error code and kssl_err struct on error.
1213** Allocates krb5_ticket and krb5_principal; caller should free these.
1214**
1215** 20010410 VRS Implemented krb5_decode_ticket() as
1216** old_krb5_decode_ticket(). Missing from MIT1.0.6.
1217** 20010615 VRS Re-cast as openssl/asn1 d2i_*() functions.
1218** Re-used some of the old krb5_decode_ticket()
1219** code here. This tkt should alloc/free just
1220** like the real thing.
1221*/
1222krb5_error_code
1223kssl_TKT2tkt( /* IN */ krb5_context krb5context,
1224 /* IN */ KRB5_TKTBODY *asn1ticket,
1225 /* OUT */ krb5_ticket **krb5ticket,
1226 /* OUT */ KSSL_ERR *kssl_err )
1227 {
1228 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1229 krb5_ticket *new5ticket = NULL;
1230 ASN1_GENERALSTRING *gstr_svc, *gstr_host;
1231
1232 *krb5ticket = NULL;
1233
1234 if (asn1ticket == NULL || asn1ticket->realm == NULL ||
1235 asn1ticket->sname == NULL ||
1236 sk_ASN1_GENERALSTRING_num(asn1ticket->sname->namestring) < 2)
1237 {
1238 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1239 "Null field in asn1ticket.\n");
1240 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1241 return KRB5KRB_ERR_GENERIC;
1242 }
1243
1244 if ((new5ticket = (krb5_ticket *) calloc(1, sizeof(krb5_ticket)))==NULL)
1245 {
1246 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1247 "Unable to allocate new krb5_ticket.\n");
1248 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1249 return ENOMEM; /* or KRB5KRB_ERR_GENERIC; */
1250 }
1251
1252 gstr_svc = sk_ASN1_GENERALSTRING_value(asn1ticket->sname->namestring, 0);
1253 gstr_host = sk_ASN1_GENERALSTRING_value(asn1ticket->sname->namestring, 1);
1254
1255 if ((krb5rc = kssl_build_principal_2(krb5context,
1256 &new5ticket->server,
1257 asn1ticket->realm->length, (char *)asn1ticket->realm->data,
1258 gstr_svc->length, (char *)gstr_svc->data,
1259 gstr_host->length, (char *)gstr_host->data)) != 0)
1260 {
1261 free(new5ticket);
1262 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1263 "Error building ticket server principal.\n");
1264 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1265 return krb5rc; /* or KRB5KRB_ERR_GENERIC; */
1266 }
1267
1268 krb5_princ_type(krb5context, new5ticket->server) =
1269 asn1ticket->sname->nametype->data[0];
1270 new5ticket->enc_part.enctype = asn1ticket->encdata->etype->data[0];
1271 new5ticket->enc_part.kvno = asn1ticket->encdata->kvno->data[0];
1272 new5ticket->enc_part.ciphertext.length =
1273 asn1ticket->encdata->cipher->length;
1274 if ((new5ticket->enc_part.ciphertext.data =
1275 calloc(1, asn1ticket->encdata->cipher->length)) == NULL)
1276 {
1277 free(new5ticket);
1278 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1279 "Error allocating cipher in krb5ticket.\n");
1280 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1281 return KRB5KRB_ERR_GENERIC;
1282 }
1283 else
1284 {
1285 memcpy(new5ticket->enc_part.ciphertext.data,
1286 asn1ticket->encdata->cipher->data,
1287 asn1ticket->encdata->cipher->length);
1288 }
1289
1290 *krb5ticket = new5ticket;
1291 return 0;
1292 }
1293
1294
1295/* Given krb5 service name in KSSL_CTX *kssl_ctx (typically "kssl"),
1296** and krb5 AP_REQ message & message length,
1297** Return Kerberos session key and client principle
1298** to SSL Server in KSSL_CTX *kssl_ctx.
1299**
1300** 19990702 VRS Started.
1301*/
1302krb5_error_code
1303kssl_sget_tkt( /* UPDATE */ KSSL_CTX *kssl_ctx,
1304 /* IN */ krb5_data *indata,
1305 /* OUT */ krb5_ticket_times *ttimes,
1306 /* OUT */ KSSL_ERR *kssl_err )
1307 {
1308 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1309 static krb5_context krb5context = NULL;
1310 static krb5_auth_context krb5auth_context = NULL;
1311 krb5_ticket *krb5ticket = NULL;
1312 KRB5_TKTBODY *asn1ticket = NULL;
1313 unsigned char *p;
1314 krb5_keytab krb5keytab = NULL;
1315 krb5_keytab_entry kt_entry;
1316 krb5_principal krb5server;
1317 krb5_rcache rcache = NULL;
1318
1319 kssl_err_set(kssl_err, 0, "");
1320
1321 if (!kssl_ctx)
1322 {
1323 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1324 "No kssl_ctx defined.\n");
1325 goto err;
1326 }
1327
1328#ifdef KSSL_DEBUG
1329 printf("in kssl_sget_tkt(%s)\n", kstring(kssl_ctx->service_name));
1330#endif /* KSSL_DEBUG */
1331
1332 if (!krb5context && (krb5rc = krb5_init_context(&krb5context)))
1333 {
1334 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1335 "krb5_init_context() fails.\n");
1336 goto err;
1337 }
1338 if (krb5auth_context &&
1339 (krb5rc = krb5_auth_con_free(krb5context, krb5auth_context)))
1340 {
1341 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1342 "krb5_auth_con_free() fails.\n");
1343 goto err;
1344 }
1345 else krb5auth_context = NULL;
1346 if (!krb5auth_context &&
1347 (krb5rc = krb5_auth_con_init(krb5context, &krb5auth_context)))
1348 {
1349 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1350 "krb5_auth_con_init() fails.\n");
1351 goto err;
1352 }
1353
1354
1355 if ((krb5rc = krb5_auth_con_getrcache(krb5context, krb5auth_context,
1356 &rcache)))
1357 {
1358 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1359 "krb5_auth_con_getrcache() fails.\n");
1360 goto err;
1361 }
1362
1363 if ((krb5rc = krb5_sname_to_principal(krb5context, NULL,
1364 (kssl_ctx->service_name)? kssl_ctx->service_name: KRB5SVC,
1365 KRB5_NT_SRV_HST, &krb5server)) != 0)
1366 {
1367 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1368 "krb5_sname_to_principal() fails.\n");
1369 goto err;
1370 }
1371
1372 if (rcache == NULL)
1373 {
1374 if ((krb5rc = krb5_get_server_rcache(krb5context,
1375 krb5_princ_component(krb5context, krb5server, 0),
1376 &rcache)))
1377 {
1378 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1379 "krb5_get_server_rcache() fails.\n");
1380 goto err;
1381 }
1382 }
1383
1384 if ((krb5rc = krb5_auth_con_setrcache(krb5context, krb5auth_context, rcache)))
1385 {
1386 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1387 "krb5_auth_con_setrcache() fails.\n");
1388 goto err;
1389 }
1390
1391
1392 /* kssl_ctx->keytab_file == NULL ==> use Kerberos default
1393 */
1394 if (kssl_ctx->keytab_file)
1395 {
1396 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->keytab_file,
1397 &krb5keytab);
1398 if (krb5rc)
1399 {
1400 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1401 "krb5_kt_resolve() fails.\n");
1402 goto err;
1403 }
1404 }
1405 else
1406 {
1407 krb5rc = krb5_kt_default(krb5context,&krb5keytab);
1408 if (krb5rc)
1409 {
1410 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1411 "krb5_kt_default() fails.\n");
1412 goto err;
1413 }
1414 }
1415
1416 /* Actual Kerberos5 krb5_recvauth() has initial conversation here
1417 ** o check KRB5_SENDAUTH_BADAUTHVERS
1418 ** unless KRB5_RECVAUTH_SKIP_VERSION
1419 ** o check KRB5_SENDAUTH_BADAPPLVERS
1420 ** o send "0" msg if all OK
1421 */
1422
1423 /* 20010411 was using AP_REQ instead of true KerberosWrapper
1424 **
1425 ** if ((krb5rc = krb5_rd_req(krb5context, &krb5auth_context,
1426 ** &krb5in_data, krb5server, krb5keytab,
1427 ** &ap_option, &krb5ticket)) != 0) { Error }
1428 */
1429
1430 p = (unsigned char *)indata->data;
1431 if ((asn1ticket = (KRB5_TKTBODY *) d2i_KRB5_TICKET(NULL, &p,
1432 (long) indata->length)) == NULL)
1433 {
1434 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1435 "d2i_KRB5_TICKET() ASN.1 decode failure.\n");
1436 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1437 goto err;
1438 }
1439
1440 /* Was: krb5rc = krb5_decode_ticket(krb5in_data,&krb5ticket)) != 0) */
1441 if ((krb5rc = kssl_TKT2tkt(krb5context, asn1ticket, &krb5ticket,
1442 kssl_err)) != 0)
1443 {
1444 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1445 "Error converting ASN.1 ticket to krb5_ticket.\n");
1446 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1447 goto err;
1448 }
1449
1450 if (! krb5_principal_compare(krb5context, krb5server,
1451 krb5ticket->server)) {
1452 krb5rc = KRB5_PRINC_NOMATCH;
1453 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1454 "server principal != ticket principal\n");
1455 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1456 goto err;
1457 }
1458 if ((krb5rc = krb5_kt_get_entry(krb5context, krb5keytab,
1459 krb5ticket->server, krb5ticket->enc_part.kvno,
1460 krb5ticket->enc_part.enctype, &kt_entry)) != 0) {
1461 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1462 "krb5_kt_get_entry() fails with %x.\n", krb5rc);
1463 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1464 goto err;
1465 }
1466 if ((krb5rc = krb5_decrypt_tkt_part(krb5context, &kt_entry.key,
1467 krb5ticket)) != 0) {
1468 BIO_snprintf(kssl_err->text, KSSL_ERR_MAX,
1469 "krb5_decrypt_tkt_part() failed.\n");
1470 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
1471 goto err;
1472 }
1473 else {
1474 krb5_kt_free_entry(krb5context, &kt_entry);
1475#ifdef KSSL_DEBUG
1476 {
1477 int i; krb5_address **paddr = krb5ticket->enc_part2->caddrs;
1478 printf("Decrypted ticket fields:\n");
1479 printf("\tflags: %X, transit-type: %X",
1480 krb5ticket->enc_part2->flags,
1481 krb5ticket->enc_part2->transited.tr_type);
1482 print_krb5_data("\ttransit-data: ",
1483 &(krb5ticket->enc_part2->transited.tr_contents));
1484 printf("\tcaddrs: %p, authdata: %p\n",
1485 krb5ticket->enc_part2->caddrs,
1486 krb5ticket->enc_part2->authorization_data);
1487 if (paddr)
1488 {
1489 printf("\tcaddrs:\n");
1490 for (i=0; paddr[i] != NULL; i++)
1491 {
1492 krb5_data d;
1493 d.length=paddr[i]->length;
1494 d.data=paddr[i]->contents;
1495 print_krb5_data("\t\tIP: ", &d);
1496 }
1497 }
1498 printf("\tstart/auth/end times: %d / %d / %d\n",
1499 krb5ticket->enc_part2->times.starttime,
1500 krb5ticket->enc_part2->times.authtime,
1501 krb5ticket->enc_part2->times.endtime);
1502 }
1503#endif /* KSSL_DEBUG */
1504 }
1505
1506 krb5rc = KRB5_NO_TKT_SUPPLIED;
1507 if (!krb5ticket || !krb5ticket->enc_part2 ||
1508 !krb5ticket->enc_part2->client ||
1509 !krb5ticket->enc_part2->client->data ||
1510 !krb5ticket->enc_part2->session)
1511 {
1512 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
1513 "bad ticket from krb5_rd_req.\n");
1514 }
1515 else if (kssl_ctx_setprinc(kssl_ctx, KSSL_CLIENT,
1516 &krb5ticket->enc_part2->client->realm,
1517 krb5ticket->enc_part2->client->data))
1518 {
1519 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
1520 "kssl_ctx_setprinc() fails.\n");
1521 }
1522 else if (kssl_ctx_setkey(kssl_ctx, krb5ticket->enc_part2->session))
1523 {
1524 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
1525 "kssl_ctx_setkey() fails.\n");
1526 }
1527 else if (krb5ticket->enc_part2->flags & TKT_FLG_INVALID)
1528 {
1529 krb5rc = KRB5KRB_AP_ERR_TKT_INVALID;
1530 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
1531 "invalid ticket from krb5_rd_req.\n");
1532 }
1533 else krb5rc = 0;
1534
1535 kssl_ctx->enctype = krb5ticket->enc_part.enctype;
1536 ttimes->authtime = krb5ticket->enc_part2->times.authtime;
1537 ttimes->starttime = krb5ticket->enc_part2->times.starttime;
1538 ttimes->endtime = krb5ticket->enc_part2->times.endtime;
1539 ttimes->renew_till = krb5ticket->enc_part2->times.renew_till;
1540
1541 err:
1542#ifdef KSSL_DEBUG
1543 kssl_ctx_show(kssl_ctx);
1544#endif /* KSSL_DEBUG */
1545
1546 if (asn1ticket) KRB5_TICKET_free((KRB5_TICKET *) asn1ticket);
1547 if (krb5keytab) krb5_kt_close(krb5context, krb5keytab);
1548 if (krb5ticket) krb5_free_ticket(krb5context, krb5ticket);
1549 if (krb5server) krb5_free_principal(krb5context, krb5server);
1550 return (krb5rc);
1551 }
1552
1553
1554/* Allocate & return a new kssl_ctx struct.
1555*/
1556KSSL_CTX *
1557kssl_ctx_new(void)
1558 {
1559 return ((KSSL_CTX *) calloc(1, sizeof(KSSL_CTX)));
1560 }
1561
1562
1563/* Frees a kssl_ctx struct and any allocated memory it holds.
1564** Returns NULL.
1565*/
1566KSSL_CTX *
1567kssl_ctx_free(KSSL_CTX *kssl_ctx)
1568 {
1569 if (kssl_ctx == NULL) return kssl_ctx;
1570
1571 if (kssl_ctx->key) memset(kssl_ctx->key, 0,
1572 kssl_ctx->length);
1573 if (kssl_ctx->key) free(kssl_ctx->key);
1574 if (kssl_ctx->client_princ) free(kssl_ctx->client_princ);
1575 if (kssl_ctx->service_host) free(kssl_ctx->service_host);
1576 if (kssl_ctx->service_name) free(kssl_ctx->service_name);
1577 if (kssl_ctx->keytab_file) free(kssl_ctx->keytab_file);
1578
1579 free(kssl_ctx);
1580 return (KSSL_CTX *) NULL;
1581 }
1582
1583
1584/* Given a (krb5_data *) entity (and optional realm),
1585** set the plain (char *) client_princ or service_host member
1586** of the kssl_ctx struct.
1587*/
1588krb5_error_code
1589kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,
1590 krb5_data *realm, krb5_data *entity)
1591 {
1592 char **princ;
1593 int length;
1594
1595 if (kssl_ctx == NULL || entity == NULL) return KSSL_CTX_ERR;
1596
1597 switch (which)
1598 {
1599 case KSSL_CLIENT: princ = &kssl_ctx->client_princ; break;
1600 case KSSL_SERVER: princ = &kssl_ctx->service_host; break;
1601 default: return KSSL_CTX_ERR; break;
1602 }
1603 if (*princ) free(*princ);
1604
1605 length = entity->length + ((realm)? realm->length + 2: 1);
1606 if ((*princ = calloc(1, length)) == NULL)
1607 return KSSL_CTX_ERR;
1608 else
1609 {
1610 strncpy(*princ, entity->data, entity->length);
1611 (*princ)[entity->length]='\0';
1612 if (realm)
1613 {
1614 strcat (*princ, "@");
1615 (void) strncat(*princ, realm->data, realm->length);
1616 (*princ)[entity->length+1+realm->length]='\0';
1617 }
1618 }
1619
1620 return KSSL_CTX_OK;
1621 }
1622
1623
1624/* Set one of the plain (char *) string members of the kssl_ctx struct.
1625** Default values should be:
1626** which == KSSL_SERVICE => "khost" (KRB5SVC)
1627** which == KSSL_KEYTAB => "/etc/krb5.keytab" (KRB5KEYTAB)
1628*/
1629krb5_error_code
1630kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text)
1631 {
1632 char **string;
1633
1634 if (!kssl_ctx) return KSSL_CTX_ERR;
1635
1636 switch (which)
1637 {
1638 case KSSL_SERVICE: string = &kssl_ctx->service_name; break;
1639 case KSSL_SERVER: string = &kssl_ctx->service_host; break;
1640 case KSSL_CLIENT: string = &kssl_ctx->client_princ; break;
1641 case KSSL_KEYTAB: string = &kssl_ctx->keytab_file; break;
1642 default: return KSSL_CTX_ERR; break;
1643 }
1644 if (*string) free(*string);
1645
1646 if (!text)
1647 {
1648 *string = '\0';
1649 return KSSL_CTX_OK;
1650 }
1651
1652 if ((*string = calloc(1, strlen(text) + 1)) == NULL)
1653 return KSSL_CTX_ERR;
1654 else
1655 strcpy(*string, text);
1656
1657 return KSSL_CTX_OK;
1658 }
1659
1660
1661/* Copy the Kerberos session key from a (krb5_keyblock *) to a kssl_ctx
1662** struct. Clear kssl_ctx->key if Kerberos session key is NULL.
1663*/
1664krb5_error_code
1665kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session)
1666 {
1667 int length;
1668 krb5_enctype enctype;
1669 krb5_octet FAR *contents = NULL;
1670
1671 if (!kssl_ctx) return KSSL_CTX_ERR;
1672
1673 if (kssl_ctx->key)
1674 {
1675 memset(kssl_ctx->key, 0, kssl_ctx->length);
1676 free(kssl_ctx->key);
1677 }
1678
1679 if (session)
1680 {
1681
1682#ifdef KRB5_HEIMDAL
1683 length = session->keyvalue->length;
1684 enctype = session->keytype;
1685 contents = session->keyvalue->contents;
1686#else
1687 length = session->length;
1688 enctype = session->enctype;
1689 contents = session->contents;
1690#endif
1691 kssl_ctx->enctype = enctype;
1692 kssl_ctx->length = length;
1693 }
1694 else
1695 {
1696 kssl_ctx->enctype = ENCTYPE_UNKNOWN;
1697 kssl_ctx->length = 0;
1698 return KSSL_CTX_OK;
1699 }
1700
1701 if ((kssl_ctx->key =
1702 (krb5_octet FAR *) calloc(1, kssl_ctx->length)) == NULL)
1703 {
1704 kssl_ctx->length = 0;
1705 return KSSL_CTX_ERR;
1706 }
1707 else
1708 memcpy(kssl_ctx->key, contents, length);
1709
1710 return KSSL_CTX_OK;
1711 }
1712
1713
1714/* Display contents of kssl_ctx struct
1715*/
1716void
1717kssl_ctx_show(KSSL_CTX *kssl_ctx)
1718 {
1719 int i;
1720
1721 printf("kssl_ctx: ");
1722 if (kssl_ctx == NULL)
1723 {
1724 printf("NULL\n");
1725 return;
1726 }
1727 else
1728 printf("%p\n", kssl_ctx);
1729
1730 printf("\tservice:\t%s\n",
1731 (kssl_ctx->service_name)? kssl_ctx->service_name: "NULL");
1732 printf("\tclient:\t%s\n",
1733 (kssl_ctx->client_princ)? kssl_ctx->client_princ: "NULL");
1734 printf("\tserver:\t%s\n",
1735 (kssl_ctx->service_host)? kssl_ctx->service_host: "NULL");
1736 printf("\tkeytab:\t%s\n",
1737 (kssl_ctx->keytab_file)? kssl_ctx->keytab_file: "NULL");
1738 printf("\tkey [%d:%d]:\t",
1739 kssl_ctx->enctype, kssl_ctx->length);
1740
1741 for (i=0; i < kssl_ctx->length && kssl_ctx->key; i++)
1742 {
1743 printf("%02x", kssl_ctx->key[i]);
1744 }
1745 printf("\n");
1746 return;
1747 }
1748
1749 int
1750 kssl_keytab_is_available(KSSL_CTX *kssl_ctx)
1751{
1752 krb5_context krb5context = NULL;
1753 krb5_keytab krb5keytab = NULL;
1754 krb5_keytab_entry entry;
1755 krb5_principal princ = NULL;
1756 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1757 int rc = 0;
1758
1759 if ((krb5rc = krb5_init_context(&krb5context)))
1760 return(0);
1761
1762 /* kssl_ctx->keytab_file == NULL ==> use Kerberos default
1763 */
1764 if (kssl_ctx->keytab_file)
1765 {
1766 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->keytab_file,
1767 &krb5keytab);
1768 if (krb5rc)
1769 goto exit;
1770 }
1771 else
1772 {
1773 krb5rc = krb5_kt_default(krb5context,&krb5keytab);
1774 if (krb5rc)
1775 goto exit;
1776 }
1777
1778 /* the host key we are looking for */
1779 krb5rc = krb5_sname_to_principal(krb5context, NULL,
1780 kssl_ctx->service_name ? kssl_ctx->service_name: KRB5SVC,
1781 KRB5_NT_SRV_HST, &princ);
1782
1783 krb5rc = krb5_kt_get_entry(krb5context, krb5keytab,
1784 princ,
1785 0 /* IGNORE_VNO */,
1786 0 /* IGNORE_ENCTYPE */,
1787 &entry);
1788 if ( krb5rc == KRB5_KT_NOTFOUND ) {
1789 rc = 1;
1790 goto exit;
1791 } else if ( krb5rc )
1792 goto exit;
1793
1794 krb5_kt_free_entry(krb5context, &entry);
1795 rc = 1;
1796
1797 exit:
1798 if (krb5keytab) krb5_kt_close(krb5context, krb5keytab);
1799 if (princ) krb5_free_principal(krb5context, princ);
1800 if (krb5context) krb5_free_context(krb5context);
1801 return(rc);
1802}
1803
1804int
1805kssl_tgt_is_available(KSSL_CTX *kssl_ctx)
1806 {
1807 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1808 krb5_context krb5context = NULL;
1809 krb5_ccache krb5ccdef = NULL;
1810 krb5_creds krb5creds, *krb5credsp = NULL;
1811 int rc = 0;
1812
1813 memset((char *)&krb5creds, 0, sizeof(krb5creds));
1814
1815 if (!kssl_ctx)
1816 return(0);
1817
1818 if (!kssl_ctx->service_host)
1819 return(0);
1820
1821 if ((krb5rc = krb5_init_context(&krb5context)) != 0)
1822 goto err;
1823
1824 if ((krb5rc = krb5_sname_to_principal(krb5context,
1825 kssl_ctx->service_host,
1826 (kssl_ctx->service_name)? kssl_ctx->service_name: KRB5SVC,
1827 KRB5_NT_SRV_HST, &krb5creds.server)) != 0)
1828 goto err;
1829
1830 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
1831 goto err;
1832
1833 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
1834 &krb5creds.client)) != 0)
1835 goto err;
1836
1837 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
1838 &krb5creds, &krb5credsp)) != 0)
1839 goto err;
1840
1841 rc = 1;
1842
1843 err:
1844#ifdef KSSL_DEBUG
1845 kssl_ctx_show(kssl_ctx);
1846#endif /* KSSL_DEBUG */
1847
1848 if (krb5creds.client) krb5_free_principal(krb5context, krb5creds.client);
1849 if (krb5creds.server) krb5_free_principal(krb5context, krb5creds.server);
1850 if (krb5context) krb5_free_context(krb5context);
1851 return(rc);
1852 }
1853
1854#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WIN32)
1855void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data)
1856 {
1857#ifdef KRB5_HEIMDAL
1858 data->length = 0;
1859 if (data->data)
1860 free(data->data);
1861#elif defined(KRB5_MIT_OLD11)
1862 if (data->data) {
1863 krb5_xfree(data->data);
1864 data->data = 0;
1865 }
1866#else
1867 krb5_free_data_contents(NULL, data);
1868#endif
1869 }
1870#endif /* !OPENSSL_SYS_WINDOWS && !OPENSSL_SYS_WIN32 */
1871
1872
1873/* Given pointers to KerberosTime and struct tm structs, convert the
1874** KerberosTime string to struct tm. Note that KerberosTime is a
1875** ASN1_GENERALIZEDTIME value, constrained to GMT with no fractional
1876** seconds as defined in RFC 1510.
1877** Return pointer to the (partially) filled in struct tm on success,
1878** return NULL on failure.
1879*/
1880struct tm *k_gmtime(ASN1_GENERALIZEDTIME *gtime, struct tm *k_tm)
1881 {
1882 char c, *p;
1883
1884 if (!k_tm) return NULL;
1885 if (gtime == NULL || gtime->length < 14) return NULL;
1886 if (gtime->data == NULL) return NULL;
1887
1888 p = (char *)&gtime->data[14];
1889
1890 c = *p; *p = '\0'; p -= 2; k_tm->tm_sec = atoi(p); *(p+2) = c;
1891 c = *p; *p = '\0'; p -= 2; k_tm->tm_min = atoi(p); *(p+2) = c;
1892 c = *p; *p = '\0'; p -= 2; k_tm->tm_hour = atoi(p); *(p+2) = c;
1893 c = *p; *p = '\0'; p -= 2; k_tm->tm_mday = atoi(p); *(p+2) = c;
1894 c = *p; *p = '\0'; p -= 2; k_tm->tm_mon = atoi(p)-1; *(p+2) = c;
1895 c = *p; *p = '\0'; p -= 4; k_tm->tm_year = atoi(p)-1900; *(p+4) = c;
1896
1897 return k_tm;
1898 }
1899
1900
1901/* Helper function for kssl_validate_times().
1902** We need context->clockskew, but krb5_context is an opaque struct.
1903** So we try to sneek the clockskew out through the replay cache.
1904** If that fails just return a likely default (300 seconds).
1905*/
1906krb5_deltat get_rc_clockskew(krb5_context context)
1907 {
1908 krb5_rcache rc;
1909 krb5_deltat clockskew;
1910
1911 if (krb5_rc_default(context, &rc)) return KSSL_CLOCKSKEW;
1912 if (krb5_rc_initialize(context, rc, 0)) return KSSL_CLOCKSKEW;
1913 if (krb5_rc_get_lifespan(context, rc, &clockskew)) {
1914 clockskew = KSSL_CLOCKSKEW;
1915 }
1916 (void) krb5_rc_destroy(context, rc);
1917 return clockskew;
1918 }
1919
1920
1921/* kssl_validate_times() combines (and more importantly exposes)
1922** the MIT KRB5 internal function krb5_validate_times() and the
1923** in_clock_skew() macro. The authenticator client time is checked
1924** to be within clockskew secs of the current time and the current
1925** time is checked to be within the ticket start and expire times.
1926** Either check may be omitted by supplying a NULL value.
1927** Returns 0 for valid times, SSL_R_KRB5* error codes otherwise.
1928** See Also: (Kerberos source)/krb5/lib/krb5/krb/valid_times.c
1929** 20010420 VRS
1930*/
1931krb5_error_code kssl_validate_times( krb5_timestamp atime,
1932 krb5_ticket_times *ttimes)
1933 {
1934 krb5_deltat skew;
1935 krb5_timestamp start, now;
1936 krb5_error_code rc;
1937 krb5_context context;
1938
1939 if ((rc = krb5_init_context(&context))) return SSL_R_KRB5_S_BAD_TICKET;
1940 skew = get_rc_clockskew(context);
1941 if ((rc = krb5_timeofday(context,&now))) return SSL_R_KRB5_S_BAD_TICKET;
1942 krb5_free_context(context);
1943
1944 if (atime && labs(atime - now) >= skew) return SSL_R_KRB5_S_TKT_SKEW;
1945
1946 if (! ttimes) return 0;
1947
1948 start = (ttimes->starttime != 0)? ttimes->starttime: ttimes->authtime;
1949 if (start - now > skew) return SSL_R_KRB5_S_TKT_NYV;
1950 if ((now - ttimes->endtime) > skew) return SSL_R_KRB5_S_TKT_EXPIRED;
1951
1952#ifdef KSSL_DEBUG
1953 printf("kssl_validate_times: %d |<- | %d - %d | < %d ->| %d\n",
1954 start, atime, now, skew, ttimes->endtime);
1955#endif /* KSSL_DEBUG */
1956
1957 return 0;
1958 }
1959
1960
1961/* Decode and decrypt given DER-encoded authenticator, then pass
1962** authenticator ctime back in *atimep (or 0 if time unavailable).
1963** Returns krb5_error_code and kssl_err on error. A NULL
1964** authenticator (authentp->length == 0) is not considered an error.
1965** Note that kssl_check_authent() makes use of the KRB5 session key;
1966** you must call kssl_sget_tkt() to get the key before calling this routine.
1967*/
1968krb5_error_code kssl_check_authent(
1969 /* IN */ KSSL_CTX *kssl_ctx,
1970 /* IN */ krb5_data *authentp,
1971 /* OUT */ krb5_timestamp *atimep,
1972 /* OUT */ KSSL_ERR *kssl_err )
1973 {
1974 krb5_error_code krb5rc = 0;
1975 KRB5_ENCDATA *dec_authent = NULL;
1976 KRB5_AUTHENTBODY *auth = NULL;
1977 krb5_enctype enctype;
1978 EVP_CIPHER_CTX ciph_ctx;
1979 const EVP_CIPHER *enc = NULL;
1980 unsigned char iv[EVP_MAX_IV_LENGTH];
1981 unsigned char *p, *unenc_authent;
1982 int padl, outl, unencbufsize;
1983 struct tm tm_time, *tm_l, *tm_g;
1984 time_t now, tl, tg, tr, tz_offset;
1985
1986 EVP_CIPHER_CTX_init(&ciph_ctx);
1987 *atimep = 0;
1988 kssl_err_set(kssl_err, 0, "");
1989
1990#ifndef KRB5CHECKAUTH
1991 authentp = NULL;
1992#else
1993#if KRB5CHECKAUTH == 0
1994 authentp = NULL;
1995#endif
1996#endif /* KRB5CHECKAUTH */
1997
1998 if (authentp == NULL || authentp->length == 0) return 0;
1999
2000#ifdef KSSL_DEBUG
2001 {
2002 unsigned int ui;
2003 printf("kssl_check_authent: authenticator[%d]:\n",authentp->length);
2004 p = authentp->data;
2005 for (ui=0; ui < authentp->length; ui++) printf("%02x ",p[ui]);
2006 printf("\n");
2007 }
2008#endif /* KSSL_DEBUG */
2009
2010 unencbufsize = 2 * authentp->length;
2011 if ((unenc_authent = calloc(1, unencbufsize)) == NULL)
2012 {
2013 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2014 "Unable to allocate authenticator buffer.\n");
2015 krb5rc = KRB5KRB_ERR_GENERIC;
2016 goto err;
2017 }
2018
2019 p = (unsigned char *)authentp->data;
2020 if ((dec_authent = d2i_KRB5_ENCDATA(NULL, &p,
2021 (long) authentp->length)) == NULL)
2022 {
2023 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2024 "Error decoding authenticator.\n");
2025 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2026 goto err;
2027 }
2028
2029 enctype = dec_authent->etype->data[0]; /* should = kssl_ctx->enctype */
2030#if !defined(KRB5_MIT_OLD11)
2031 switch ( enctype ) {
2032 case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
2033 case ENCTYPE_DES3_CBC_SHA:
2034 case ENCTYPE_DES3_CBC_RAW:
2035 krb5rc = 0; /* Skip, can't handle derived keys */
2036 goto err;
2037 }
2038#endif
2039 enc = kssl_map_enc(enctype);
2040 memset(iv, 0, EVP_MAX_IV_LENGTH); /* per RFC 1510 */
2041
2042 if (enc == NULL)
2043 {
2044 /* Disable kssl_check_authent for ENCTYPE_DES3_CBC_SHA1.
2045 ** This enctype indicates the authenticator was encrypted
2046 ** using key-usage derived keys which openssl cannot decrypt.
2047 */
2048 goto err;
2049 }
2050 if (!EVP_DecryptInit_ex(&ciph_ctx, enc, NULL, kssl_ctx->key, iv))
2051 {
2052 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2053 "EVP_DecryptInit_ex error decrypting authenticator.\n");
2054 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2055 goto err;
2056 }
2057 if (!EVP_DecryptUpdate(&ciph_ctx, unenc_authent, &outl,
2058 dec_authent->cipher->data, dec_authent->cipher->length))
2059 {
2060 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2061 "EVP_DecryptUpdate error decrypting authenticator.\n");
2062 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2063 goto err;
2064 }
2065 if (outl > unencbufsize)
2066 {
2067 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2068 "Buffer overflow decrypting authenticator.\n");
2069 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2070 goto err;
2071 }
2072 if (!EVP_DecryptFinal_ex(&ciph_ctx, &(unenc_authent[outl]), &padl))
2073 {
2074 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2075 "EVP_DecryptFinal_ex error decrypting authenticator.\n");
2076 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2077 goto err;
2078 }
2079 outl += padl;
2080 if (outl > unencbufsize)
2081 {
2082 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2083 "Buffer overflow decrypting authenticator.\n");
2084 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2085 goto err;
2086 }
2087 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
2088
2089#ifdef KSSL_DEBUG
2090 printf("kssl_check_authent: decrypted authenticator[%d] =\n", outl);
2091 for (padl=0; padl < outl; padl++) printf("%02x ",unenc_authent[padl]);
2092 printf("\n");
2093#endif /* KSSL_DEBUG */
2094
2095 if ((p = kssl_skip_confound(enctype, unenc_authent)) == NULL)
2096 {
2097 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2098 "confounded by authenticator.\n");
2099 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2100 goto err;
2101 }
2102 outl -= p - unenc_authent;
2103
2104 if ((auth = (KRB5_AUTHENTBODY *) d2i_KRB5_AUTHENT(NULL, &p,
2105 (long) outl))==NULL)
2106 {
2107 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
2108 "Error decoding authenticator body.\n");
2109 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2110 goto err;
2111 }
2112
2113 memset(&tm_time,0,sizeof(struct tm));
2114 if (k_gmtime(auth->ctime, &tm_time) &&
2115 ((tr = mktime(&tm_time)) != (time_t)(-1)))
2116 {
2117 now = time(&now);
2118 tm_l = localtime(&now); tl = mktime(tm_l);
2119 tm_g = gmtime(&now); tg = mktime(tm_g);
2120 tz_offset = tg - tl;
2121
2122 *atimep = tr - tz_offset;
2123 }
2124
2125#ifdef KSSL_DEBUG
2126 printf("kssl_check_authent: returns %d for client time ", *atimep);
2127 if (auth && auth->ctime && auth->ctime->length && auth->ctime->data)
2128 printf("%.*s\n", auth->ctime->length, auth->ctime->data);
2129 else printf("NULL\n");
2130#endif /* KSSL_DEBUG */
2131
2132 err:
2133 if (auth) KRB5_AUTHENT_free((KRB5_AUTHENT *) auth);
2134 if (dec_authent) KRB5_ENCDATA_free(dec_authent);
2135 if (unenc_authent) free(unenc_authent);
2136 return krb5rc;
2137 }
2138
2139
2140/* Replaces krb5_build_principal_ext(), with varargs length == 2 (svc, host),
2141** because I dont't know how to stub varargs.
2142** Returns krb5_error_code == ENOMEM on alloc error, otherwise
2143** passes back newly constructed principal, which should be freed by caller.
2144*/
2145krb5_error_code kssl_build_principal_2(
2146 /* UPDATE */ krb5_context context,
2147 /* OUT */ krb5_principal *princ,
2148 /* IN */ int rlen, const char *realm,
2149 /* IN */ int slen, const char *svc,
2150 /* IN */ int hlen, const char *host)
2151 {
2152 krb5_data *p_data = NULL;
2153 krb5_principal new_p = NULL;
2154 char *new_r = NULL;
2155
2156 if ((p_data = (krb5_data *) calloc(2, sizeof(krb5_data))) == NULL ||
2157 (new_p = (krb5_principal) calloc(1, sizeof(krb5_principal_data)))
2158 == NULL) goto err;
2159 new_p->length = 2;
2160 new_p->data = p_data;
2161
2162 if ((new_r = calloc(1, rlen + 1)) == NULL) goto err;
2163 memcpy(new_r, realm, rlen);
2164 krb5_princ_set_realm_length(context, new_p, rlen);
2165 krb5_princ_set_realm_data(context, new_p, new_r);
2166
2167 if ((new_p->data[0].data = calloc(1, slen + 1)) == NULL) goto err;
2168 memcpy(new_p->data[0].data, svc, slen);
2169 new_p->data[0].length = slen;
2170
2171 if ((new_p->data[1].data = calloc(1, hlen + 1)) == NULL) goto err;
2172 memcpy(new_p->data[1].data, host, hlen);
2173 new_p->data[1].length = hlen;
2174
2175 krb5_princ_type(context, new_p) = KRB5_NT_UNKNOWN;
2176 *princ = new_p;
2177 return 0;
2178
2179 err:
2180 if (new_p && new_p[0].data) free(new_p[0].data);
2181 if (new_p && new_p[1].data) free(new_p[1].data);
2182 if (new_p) free(new_p);
2183 if (new_r) free(new_r);
2184 return ENOMEM;
2185 }
2186
2187
2188#else /* !OPENSSL_NO_KRB5 */
2189
2190#if defined(PEDANTIC) || defined(OPENSSL_SYS_VMS)
2191static int dummy=(int)&dummy;
2192#endif
2193
2194#endif /* !OPENSSL_NO_KRB5 */
2195
diff --git a/src/lib/libssl/src/ssl/kssl.h b/src/lib/libssl/src/ssl/kssl.h
new file mode 100644
index 0000000000..cf7ebdd168
--- /dev/null
+++ b/src/lib/libssl/src/ssl/kssl.h
@@ -0,0 +1,173 @@
1/* ssl/kssl.h -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60** 19990701 VRS Started.
61*/
62
63#ifndef KSSL_H
64#define KSSL_H
65
66#include <openssl/opensslconf.h>
67
68#ifndef OPENSSL_NO_KRB5
69
70#include <stdio.h>
71#include <ctype.h>
72#include <krb5.h>
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78/*
79** Depending on which KRB5 implementation used, some types from
80** the other may be missing. Resolve that here and now
81*/
82#ifdef KRB5_HEIMDAL
83typedef unsigned char krb5_octet;
84#define FAR
85#endif
86
87/* Uncomment this to debug kssl problems or
88** to trace usage of the Kerberos session key
89**
90** #define KSSL_DEBUG
91*/
92
93#ifndef KRB5SVC
94#define KRB5SVC "host"
95#endif
96
97#ifndef KRB5KEYTAB
98#define KRB5KEYTAB "/etc/krb5.keytab"
99#endif
100
101#ifndef KRB5SENDAUTH
102#define KRB5SENDAUTH 1
103#endif
104
105#ifndef KRB5CHECKAUTH
106#define KRB5CHECKAUTH 1
107#endif
108
109#ifndef KSSL_CLOCKSKEW
110#define KSSL_CLOCKSKEW 300;
111#endif
112
113#define KSSL_ERR_MAX 255
114typedef struct kssl_err_st {
115 int reason;
116 char text[KSSL_ERR_MAX+1];
117 } KSSL_ERR;
118
119
120/* Context for passing
121** (1) Kerberos session key to SSL, and
122** (2) Config data between application and SSL lib
123*/
124typedef struct kssl_ctx_st
125 {
126 /* used by: disposition: */
127 char *service_name; /* C,S default ok (kssl) */
128 char *service_host; /* C input, REQUIRED */
129 char *client_princ; /* S output from krb5 ticket */
130 char *keytab_file; /* S NULL (/etc/krb5.keytab) */
131 char *cred_cache; /* C NULL (default) */
132 krb5_enctype enctype;
133 int length;
134 krb5_octet FAR *key;
135 } KSSL_CTX;
136
137#define KSSL_CLIENT 1
138#define KSSL_SERVER 2
139#define KSSL_SERVICE 3
140#define KSSL_KEYTAB 4
141
142#define KSSL_CTX_OK 0
143#define KSSL_CTX_ERR 1
144#define KSSL_NOMEM 2
145
146/* Public (for use by applications that use OpenSSL with Kerberos 5 support */
147krb5_error_code kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text);
148KSSL_CTX *kssl_ctx_new(void);
149KSSL_CTX *kssl_ctx_free(KSSL_CTX *kssl_ctx);
150void kssl_ctx_show(KSSL_CTX *kssl_ctx);
151krb5_error_code kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,
152 krb5_data *realm, krb5_data *entity);
153krb5_error_code kssl_cget_tkt(KSSL_CTX *kssl_ctx, krb5_data **enc_tktp,
154 krb5_data *authenp, KSSL_ERR *kssl_err);
155krb5_error_code kssl_sget_tkt(KSSL_CTX *kssl_ctx, krb5_data *indata,
156 krb5_ticket_times *ttimes, KSSL_ERR *kssl_err);
157krb5_error_code kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session);
158void kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text);
159void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data);
160krb5_error_code kssl_build_principal_2(krb5_context context,
161 krb5_principal *princ, int rlen, const char *realm,
162 int slen, const char *svc, int hlen, const char *host);
163krb5_error_code kssl_validate_times(krb5_timestamp atime,
164 krb5_ticket_times *ttimes);
165krb5_error_code kssl_check_authent(KSSL_CTX *kssl_ctx, krb5_data *authentp,
166 krb5_timestamp *atimep, KSSL_ERR *kssl_err);
167unsigned char *kssl_skip_confound(krb5_enctype enctype, unsigned char *authn);
168
169#ifdef __cplusplus
170}
171#endif
172#endif /* OPENSSL_NO_KRB5 */
173#endif /* KSSL_H */
diff --git a/src/lib/libssl/src/ssl/kssl_lcl.h b/src/lib/libssl/src/ssl/kssl_lcl.h
new file mode 100644
index 0000000000..4cd8dd2d7f
--- /dev/null
+++ b/src/lib/libssl/src/ssl/kssl_lcl.h
@@ -0,0 +1,87 @@
1/* ssl/kssl.h -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef KSSL_LCL_H
60#define KSSL_LCL_H
61
62#include <openssl/kssl.h>
63
64#ifndef OPENSSL_NO_KRB5
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/* Private (internal to OpenSSL) */
71void print_krb5_data(char *label, krb5_data *kdata);
72void print_krb5_authdata(char *label, krb5_authdata **adata);
73void print_krb5_keyblock(char *label, krb5_keyblock *keyblk);
74
75char *kstring(char *string);
76char *knumber(int len, krb5_octet *contents);
77
78EVP_CIPHER *kssl_map_enc(krb5_enctype enctype);
79
80int kssl_keytab_is_available(KSSL_CTX *kssl_ctx);
81int kssl_tgt_is_available(KSSL_CTX *kssl_ctx);
82
83#ifdef __cplusplus
84}
85#endif
86#endif /* OPENSSL_NO_KRB5 */
87#endif /* KSSL_LCL_H */
diff --git a/src/lib/libssl/src/ssl/ssl-lib.com b/src/lib/libssl/src/ssl/ssl-lib.com
new file mode 100644
index 0000000000..75fa89f193
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl-lib.com
@@ -0,0 +1,1200 @@
1$!
2$! SSL-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command file compiles and creates the "[.xxx.EXE.SSL]LIBSSL.OLB"
11$! library for OpenSSL. The "xxx" denotes the machine architecture of AXP
12$! or VAX.
13$!
14$! It is written to detect what type of machine you are compiling on
15$! (i.e. AXP or VAX) and which "C" compiler you have (i.e. VAXC, DECC
16$! or GNU C) or you can specify which compiler to use.
17$!
18$! Specify the following as P1 to build just that part or ALL to just
19$! build everything.
20$!
21$! LIBRARY To just compile the [.xxx.EXE.SSL]LIBSSL.OLB Library.
22$! SSL_TASK To just compile the [.xxx.EXE.SSL]SSL_TASK.EXE
23$!
24$! Specify RSAREF as P2 to compile with the RSAREF library instead of
25$! the regular one. If you specify NORSAREF it will compile with the
26$! regular RSAREF routines. (Note: If you are in the United States
27$! you MUST compile with RSAREF unless you have a license from RSA).
28$!
29$! Note: The RSAREF libraries are NOT INCLUDED and you have to
30$! download it from "ftp://ftp.rsa.com/rsaref". You have to
31$! get the ".tar-Z" file as the ".zip" file dosen't have the
32$! directory structure stored. You have to extract the file
33$! into the [.RSAREF] directory under the root directory as that
34$! is where the scripts will look for the files.
35$!
36$! Specify DEBUG or NODEBUG as P3 to compile with or without debugger
37$! information.
38$!
39$! Specify which compiler at P4 to try to compile under.
40$!
41$! VAXC For VAX C.
42$! DECC For DEC C.
43$! GNUC For GNU C.
44$!
45$! If you don't speficy a compiler, it will try to determine which
46$! "C" compiler to use.
47$!
48$! P5, if defined, sets a TCP/IP library to use, through one of the following
49$! keywords:
50$!
51$! UCX for UCX
52$! SOCKETSHR for SOCKETSHR+NETLIB
53$!
54$! P6, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
55$!
56$!
57$! Define A TCP/IP Library That We Will Need To Link To.
58$! (That Is, If We Need To Link To One.)
59$!
60$ TCPIP_LIB = ""
61$!
62$! Check Which Architecture We Are Using.
63$!
64$ IF (F$GETSYI("CPU").GE.128)
65$ THEN
66$!
67$! The Architecture Is AXP.
68$!
69$ ARCH := AXP
70$!
71$! Else...
72$!
73$ ELSE
74$!
75$! The Architecture Is VAX.
76$!
77$ ARCH := VAX
78$!
79$! End The Architecture Check.
80$!
81$ ENDIF
82$!
83$! Check To Make Sure We Have Valid Command Line Parameters.
84$!
85$ GOSUB CHECK_OPTIONS
86$!
87$! Initialise logical names and such
88$!
89$ GOSUB INITIALISE
90$!
91$! Tell The User What Kind of Machine We Run On.
92$!
93$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
94$!
95$! Define The OBJ Directory.
96$!
97$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.SSL]
98$!
99$! Check To See If The Architecture Specific OBJ Directory Exists.
100$!
101$ IF (F$PARSE(OBJ_DIR).EQS."")
102$ THEN
103$!
104$! It Dosen't Exist, So Create It.
105$!
106$ CREATE/DIR 'OBJ_DIR'
107$!
108$! End The Architecture Specific OBJ Directory Check.
109$!
110$ ENDIF
111$!
112$! Define The EXE Directory.
113$!
114$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.SSL]
115$!
116$! Check To See If The Architecture Specific Directory Exists.
117$!
118$ IF (F$PARSE(EXE_DIR).EQS."")
119$ THEN
120$!
121$! It Dosen't Exist, So Create It.
122$!
123$ CREATE/DIR 'EXE_DIR'
124$!
125$! End The Architecture Specific Directory Check.
126$!
127$ ENDIF
128$!
129$! Define The Library Name.
130$!
131$ SSL_LIB := 'EXE_DIR'LIBSSL.OLB
132$!
133$! Define The CRYPTO-LIB We Are To Use.
134$!
135$ CRYPTO_LIB := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
136$!
137$! Define The RSAREF-LIB We Are To Use.
138$!
139$ RSAREF_LIB := SYS$DISK:[-.'ARCH'.EXE.RSAREF]LIBRSAGLUE.OLB
140$!
141$! Check To See What We Are To Do.
142$!
143$ IF (BUILDALL.EQS."TRUE")
144$ THEN
145$!
146$! Since Nothing Special Was Specified, Do Everything.
147$!
148$ GOSUB LIBRARY
149$ GOSUB SSL_TASK
150$!
151$! Else...
152$!
153$ ELSE
154$!
155$! Build Just What The User Wants Us To Build.
156$!
157$ GOSUB 'BUILDALL'
158$!
159$! End The BUILDALL Check.
160$!
161$ ENDIF
162$!
163$! Time To EXIT.
164$!
165$ EXIT:
166$ GOSUB CLEANUP
167$ EXIT
168$!
169$! Compile The Library.
170$!
171$ LIBRARY:
172$!
173$! Check To See If We Already Have A "[.xxx.EXE.SSL]LIBSSL.OLB" Library...
174$!
175$ IF (F$SEARCH(SSL_LIB).EQS."")
176$ THEN
177$!
178$! Guess Not, Create The Library.
179$!
180$ LIBRARY/CREATE/OBJECT 'SSL_LIB'
181$!
182$! End The Library Exist Check.
183$!
184$ ENDIF
185$!
186$! Define The Different SSL "library" Files.
187$!
188$ LIB_SSL = "s2_meth,s2_srvr,s2_clnt,s2_lib,s2_enc,s2_pkt,"+ -
189 "s3_meth,s3_srvr,s3_clnt,s3_lib,s3_enc,s3_pkt,s3_both,"+ -
190 "s23_meth,s23_srvr,s23_clnt,s23_lib,s23_pkt,"+ -
191 "t1_meth,t1_srvr,t1_clnt,t1_lib,t1_enc,"+ -
192 "ssl_lib,ssl_err2,ssl_cert,ssl_sess,"+ -
193 "ssl_ciph,ssl_stat,ssl_rsa,"+ -
194 "ssl_asn1,ssl_txt,ssl_algs,"+ -
195 "bio_ssl,ssl_err"
196$!
197$! Tell The User That We Are Compiling The Library.
198$!
199$ WRITE SYS$OUTPUT "Building The ",SSL_LIB," Library."
200$!
201$! Define A File Counter And Set It To "0"
202$!
203$ FILE_COUNTER = 0
204$!
205$! Top Of The File Loop.
206$!
207$ NEXT_FILE:
208$!
209$! O.K, Extract The File Name From The File List.
210$!
211$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_SSL)
212$!
213$! Check To See If We Are At The End Of The File List.
214$!
215$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
216$!
217$! Increment The Counter.
218$!
219$ FILE_COUNTER = FILE_COUNTER + 1
220$!
221$! Create The Source File Name.
222$!
223$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
224$!
225$! Create The Object File Name.
226$!
227$ OBJECT_FILE = OBJ_DIR + FILE_NAME + ".OBJ"
228$ ON WARNING THEN GOTO NEXT_FILE
229$!
230$! Check To See If The File We Want To Compile Is Actually There.
231$!
232$ IF (F$SEARCH(SOURCE_FILE).EQS."")
233$ THEN
234$!
235$! Tell The User That The File Dosen't Exist.
236$!
237$ WRITE SYS$OUTPUT ""
238$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
239$ WRITE SYS$OUTPUT ""
240$!
241$! Exit The Build.
242$!
243$ EXIT
244$!
245$! End The File Exists Check.
246$!
247$ ENDIF
248$!
249$! Tell The User What File We Are Compiling.
250$!
251$ WRITE SYS$OUTPUT " ",FILE_NAME,".c"
252$!
253$! Compile The File.
254$!
255$ ON ERROR THEN GOTO NEXT_FILE
256$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
257$!
258$! Add It To The Library.
259$!
260$ LIBRARY/REPLACE/OBJECT 'SSL_LIB' 'OBJECT_FILE'
261$!
262$! Time To Clean Up The Object File.
263$!
264$ DELETE 'OBJECT_FILE';*
265$!
266$! Go Back And Get The Next File Name.
267$!
268$ GOTO NEXT_FILE
269$!
270$! All Done With This Library.
271$!
272$ FILE_DONE:
273$!
274$! Tell The User That We Are All Done.
275$!
276$ WRITE SYS$OUTPUT "Library ",SSL_LIB," Compiled."
277$!
278$! Time To RETURN.
279$!
280$ RETURN
281$ SSL_TASK:
282$!
283$! Check To See If We Have The Proper Libraries.
284$!
285$ GOSUB LIB_CHECK
286$!
287$! Check To See If We Have A Linker Option File.
288$!
289$ GOSUB CHECK_OPT_FILE
290$!
291$! Check To See If The File We Want To Compile Is Actually There.
292$!
293$ IF (F$SEARCH("SYS$DISK:[]SSL_TASK.C").EQS."")
294$ THEN
295$!
296$! Tell The User That The File Dosen't Exist.
297$!
298$ WRITE SYS$OUTPUT ""
299$ WRITE SYS$OUTPUT "The File SSL_TASK.C Dosen't Exist."
300$ WRITE SYS$OUTPUT ""
301$!
302$! Exit The Build.
303$!
304$ EXIT
305$!
306$! End The SSL_TASK.C File Check.
307$!
308$ ENDIF
309$!
310$! Tell The User We Are Creating The SSL_TASK.
311$!
312$ WRITE SYS$OUTPUT "Creating SSL_TASK OSU HTTP SSL Engine."
313$!
314$! Compile The File.
315$!
316$ CC5/OBJECT='OBJ_DIR'SSL_TASK.OBJ SYS$DISK:[]SSL_TASK.C
317$!
318$! Link The Program, Check To See If We Need To Link With RSAREF Or Not.
319$!
320$ IF (RSAREF.EQS."TRUE")
321$ THEN
322$!
323$! Check To See If We Are To Link With A Specific TCP/IP Library.
324$!
325$ IF (TCPIP_LIB.NES."")
326$ THEN
327$!
328$! Link With The RSAREF Library And A Specific TCP/IP Library.
329$!
330$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
331 'OBJ_DIR'SSL_TASK.OBJ, -
332 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
333 'TCPIP_LIB','OPT_FILE'/OPTION
334$!
335$! Else...
336$!
337$ ELSE
338$!
339$! Link With The RSAREF Library And NO TCP/IP Library.
340$!
341$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
342 'OBJ_DIR'SSL_TASK.OBJ, -
343 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
344 'OPT_FILE'/OPTION
345$!
346$! End The TCP/IP Library Check.
347$!
348$ ENDIF
349$!
350$! Else...
351$!
352$ ELSE
353$!
354$! Don't Link With The RSAREF Routines.
355$!
356$!
357$! Check To See If We Are To Link With A Specific TCP/IP Library.
358$!
359$ IF (TCPIP_LIB.NES."")
360$ THEN
361$!
362$! Don't Link With The RSAREF Routines And TCP/IP Library.
363$!
364$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
365 'OBJ_DIR'SSL_TASK.OBJ, -
366 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
367 'TCPIP_LIB','OPT_FILE'/OPTION
368$!
369$! Else...
370$!
371$ ELSE
372$!
373$! Don't Link With The RSAREF Routines And Link With A TCP/IP Library.
374$!
375$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
376 'OBJ_DIR'SSL_TASK.OBJ,-
377 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
378 'OPT_FILE'/OPTION
379$!
380$! End The TCP/IP Library Check.
381$!
382$ ENDIF
383$!
384$! End The RSAREF Link Check.
385$!
386$ ENDIF
387$!
388$! Time To Return.
389$!
390$ RETURN
391$!
392$! Check For The Link Option FIle.
393$!
394$ CHECK_OPT_FILE:
395$!
396$! Check To See If We Need To Make A VAX C Option File.
397$!
398$ IF (COMPILER.EQS."VAXC")
399$ THEN
400$!
401$! Check To See If We Already Have A VAX C Linker Option File.
402$!
403$ IF (F$SEARCH(OPT_FILE).EQS."")
404$ THEN
405$!
406$! We Need A VAX C Linker Option File.
407$!
408$ CREATE 'OPT_FILE'
409$DECK
410!
411! Default System Options File To Link Agianst
412! The Sharable VAX C Runtime Library.
413!
414SYS$SHARE:VAXCRTL.EXE/SHARE
415$EOD
416$!
417$! End The Option File Check.
418$!
419$ ENDIF
420$!
421$! End The VAXC Check.
422$!
423$ ENDIF
424$!
425$! Check To See If We Need A GNU C Option File.
426$!
427$ IF (COMPILER.EQS."GNUC")
428$ THEN
429$!
430$! Check To See If We Already Have A GNU C Linker Option File.
431$!
432$ IF (F$SEARCH(OPT_FILE).EQS."")
433$ THEN
434$!
435$! We Need A GNU C Linker Option File.
436$!
437$ CREATE 'OPT_FILE'
438$DECK
439!
440! Default System Options File To Link Agianst
441! The Sharable C Runtime Library.
442!
443GNU_CC:[000000]GCCLIB/LIBRARY
444SYS$SHARE:VAXCRTL/SHARE
445$EOD
446$!
447$! End The Option File Check.
448$!
449$ ENDIF
450$!
451$! End The GNU C Check.
452$!
453$ ENDIF
454$!
455$! Check To See If We Need A DEC C Option File.
456$!
457$ IF (COMPILER.EQS."DECC")
458$ THEN
459$!
460$! Check To See If We Already Have A DEC C Linker Option File.
461$!
462$ IF (F$SEARCH(OPT_FILE).EQS."")
463$ THEN
464$!
465$! Figure Out If We Need An AXP Or A VAX Linker Option File.
466$!
467$ IF (ARCH.EQS."VAX")
468$ THEN
469$!
470$! We Need A DEC C Linker Option File For VAX.
471$!
472$ CREATE 'OPT_FILE'
473$DECK
474!
475! Default System Options File To Link Agianst
476! The Sharable DEC C Runtime Library.
477!
478SYS$SHARE:DECC$SHR.EXE/SHARE
479$EOD
480$!
481$! Else...
482$!
483$ ELSE
484$!
485$! Create The AXP Linker Option File.
486$!
487$ CREATE 'OPT_FILE'
488$DECK
489!
490! Default System Options File For AXP To Link Agianst
491! The Sharable C Runtime Library.
492!
493SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
494SYS$SHARE:CMA$OPEN_RTL/SHARE
495$EOD
496$!
497$! End The VAX/AXP DEC C Option File Check.
498$!
499$ ENDIF
500$!
501$! End The Option File Search.
502$!
503$ ENDIF
504$!
505$! End The DEC C Check.
506$!
507$ ENDIF
508$!
509$! Tell The User What Linker Option File We Are Using.
510$!
511$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
512$!
513$! Time To RETURN.
514$!
515$ RETURN
516$ LIB_CHECK:
517$!
518$! Look For The VAX Library LIBSSL.OLB.
519$!
520$ IF (F$SEARCH(SSL_LIB).EQS."")
521$ THEN
522$!
523$! Tell The User We Can't Find The LIBSSL.OLB Library.
524$!
525$ WRITE SYS$OUTPUT ""
526$ WRITE SYS$OUTPUT "Can't Find The Library ",SSL_LIB,"."
527$ WRITE SYS$OUTPUT "We Can't Link Without It."
528$ WRITE SYS$OUTPUT ""
529$!
530$! Since We Can't Link Without It, Exit.
531$!
532$ EXIT
533$!
534$! End The LIBSSL.OLB Library Check.
535$!
536$ ENDIF
537$!
538$! Look For The Library LIBCRYPTO.OLB.
539$!
540$ IF (F$SEARCH(CRYPTO_LIB).EQS."")
541$ THEN
542$!
543$! Tell The User We Can't Find The LIBCRYPTO.OLB Library.
544$!
545$ WRITE SYS$OUTPUT ""
546$ WRITE SYS$OUTPUT "Can't Find The Library ",CRYPTO_LIB,"."
547$ WRITE SYS$OUTPUT "We Can't Link Without It."
548$ WRITE SYS$OUTPUT ""
549$!
550$! Since We Can't Link Without It, Exit.
551$!
552$ EXIT
553$!
554$! End The LIBCRYPTO.OLB Library Check.
555$!
556$ ENDIF
557$!
558$! Check To See If We Need The RSAREF Library.
559$!
560$ IF (RSAREF.EQS."TRUE")
561$ THEN
562$!
563$! Look For The Library LIBRSAGLUE.OLB.
564$!
565$ IF (F$SEARCH(RSAREF_LIB).EQS."")
566$ THEN
567$!
568$! Tell The User We Can't Find The LIBRSAGLUE.OLB Library.
569$!
570$ WRITE SYS$OUTPUT ""
571$ WRITE SYS$OUTPUT "Can't Find The Library ",RSAREF_LIB,"."
572$ WRITE SYS$OUTPUT "We Can't Link Without It."
573$ WRITE SYS$OUTPUT ""
574$!
575$! Since We Can't Link Without It, Exit.
576$!
577$ EXIT
578$!
579$! End The LIBRSAGLUE.OLB Library Check.
580$!
581$ ENDIF
582$!
583$! End The RSAREF Library Check.
584$!
585$ ENDIF
586$!
587$! Time To Return.
588$!
589$ RETURN
590$!
591$! Check The User's Options.
592$!
593$ CHECK_OPTIONS:
594$!
595$! Check To See If P1 Is Blank.
596$!
597$ IF (P1.EQS."ALL")
598$ THEN
599$!
600$! P1 Is Blank, So Build Everything.
601$!
602$ BUILDALL = "TRUE"
603$!
604$! Else...
605$!
606$ ELSE
607$!
608$! Else, Check To See If P1 Has A Valid Arguement.
609$!
610$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."SSL_TASK")
611$ THEN
612$!
613$! A Valid Arguement.
614$!
615$ BUILDALL = P1
616$!
617$! Else...
618$!
619$ ELSE
620$!
621$! Tell The User We Don't Know What They Want.
622$!
623$ WRITE SYS$OUTPUT ""
624$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
625$ WRITE SYS$OUTPUT ""
626$ WRITE SYS$OUTPUT " ALL : Just Build Everything."
627$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.SSL]LIBSSL.OLB Library."
628$ WRITE SYS$OUTPUT " SSL_TASK : To Compile Just The [.xxx.EXE.SSL]SSL_TASK.EXE Program."
629$ WRITE SYS$OUTPUT ""
630$ WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
631$ WRITE SYS$OUTPUT ""
632$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
633$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
634$ WRITE SYS$OUTPUT ""
635$!
636$! Time To EXIT.
637$!
638$ EXIT
639$!
640$! End The Valid Arguement Check.
641$!
642$ ENDIF
643$!
644$! End The P1 Check.
645$!
646$ ENDIF
647$!
648$! Check To See If P2 Is Blank.
649$!
650$ IF (P2.EQS."NORSAREF")
651$ THEN
652$!
653$! P2 Is NORSAREF, So Compile With The Regular RSA Libraries.
654$!
655$ RSAREF = "FALSE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Check To See If We Are To Use The RSAREF Library.
662$!
663$ IF (P2.EQS."RSAREF")
664$ THEN
665$!
666$! Check To Make Sure We Have The RSAREF Source Code Directory.
667$!
668$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
669$ THEN
670$!
671$! We Don't Have The RSAREF Souce Code Directory, So Tell The
672$! User This.
673$!
674$ WRITE SYS$OUTPUT ""
675$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
676$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
677$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
678$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
679$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
680$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
681$ WRITE SYS$OUTPUT ""
682$!
683$! Time To Exit.
684$!
685$ EXIT
686$!
687$! Else, Compile Using The RSAREF Library.
688$!
689$ ELSE
690$ RSAREF = "TRUE"
691$ ENDIF
692$ ELSE
693$!
694$! They Entered An Invalid Option..
695$!
696$ WRITE SYS$OUTPUT ""
697$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
698$ WRITE SYS$OUTPUT ""
699$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
700$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
701$ WRITE SYS$OUTPUT ""
702$!
703$! Time To EXIT.
704$!
705$ EXIT
706$!
707$! End The Valid Arguement Check.
708$!
709$ ENDIF
710$!
711$! End The P2 Check.
712$!
713$ ENDIF
714$!
715$! Check To See If P3 Is Blank.
716$!
717$ IF (P3.EQS."NODEBUG")
718$ THEN
719$!
720$! P3 Is NODEBUG, So Compile Without Debugger Information.
721$!
722$ DEBUGGER = "NODEBUG"
723$ TRACEBACK = "NOTRACEBACK"
724$ GCC_OPTIMIZE = "OPTIMIZE"
725$ CC_OPTIMIZE = "OPTIMIZE"
726$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
727$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
728$!
729$! Else...
730$!
731$ ELSE
732$!
733$! Check To See If We Are To Compile With Debugger Information.
734$!
735$ IF (P3.EQS."DEBUG")
736$ THEN
737$!
738$! Compile With Debugger Information.
739$!
740$ DEBUGGER = "DEBUG"
741$ TRACEBACK = "TRACEBACK"
742$ GCC_OPTIMIZE = "NOOPTIMIZE"
743$ CC_OPTIMIZE = "NOOPTIMIZE"
744$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
745$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
746$ ELSE
747$!
748$! Tell The User Entered An Invalid Option..
749$!
750$ WRITE SYS$OUTPUT ""
751$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
752$ WRITE SYS$OUTPUT ""
753$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
754$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
755$ WRITE SYS$OUTPUT ""
756$!
757$! Time To EXIT.
758$!
759$ EXIT
760$!
761$! End The Valid Arguement Check.
762$!
763$ ENDIF
764$!
765$! End The P3 Check.
766$!
767$ ENDIF
768$!
769$! Special Threads For OpenVMS v7.1 Or Later
770$!
771$! Written By: Richard Levitte
772$! richard@levitte.org
773$!
774$!
775$! Check To See If We Have A Option For P6.
776$!
777$ IF (P6.EQS."")
778$ THEN
779$!
780$! Get The Version Of VMS We Are Using.
781$!
782$ ISSEVEN :=
783$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
784$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
785$!
786$! Check To See If The VMS Version Is v7.1 Or Later.
787$!
788$ IF (TMP.GE.71)
789$ THEN
790$!
791$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
792$!
793$ ISSEVEN := ,PTHREAD_USE_D4
794$!
795$! End The VMS Version Check.
796$!
797$ ENDIF
798$!
799$! End The P6 Check.
800$!
801$ ENDIF
802$!
803$! Check To See If P4 Is Blank.
804$!
805$ IF (P4.EQS."")
806$ THEN
807$!
808$! O.K., The User Didn't Specify A Compiler, Let's Try To
809$! Find Out Which One To Use.
810$!
811$! Check To See If We Have GNU C.
812$!
813$ IF (F$TRNLNM("GNU_CC").NES."")
814$ THEN
815$!
816$! Looks Like GNUC, Set To Use GNUC.
817$!
818$ P4 = "GNUC"
819$!
820$! End The GNU C Compiler Check.
821$!
822$ ELSE
823$!
824$! Check To See If We Have VAXC Or DECC.
825$!
826$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
827$ THEN
828$!
829$! Looks Like DECC, Set To Use DECC.
830$!
831$ P4 = "DECC"
832$!
833$! Else...
834$!
835$ ELSE
836$!
837$! Looks Like VAXC, Set To Use VAXC.
838$!
839$ P4 = "VAXC"
840$!
841$! End The VAXC Compiler Check.
842$!
843$ ENDIF
844$!
845$! End The DECC & VAXC Compiler Check.
846$!
847$ ENDIF
848$!
849$! End The Compiler Check.
850$!
851$ ENDIF
852$!
853$! Check To See If We Have A Option For P5.
854$!
855$ IF (P5.EQS."")
856$ THEN
857$!
858$! Find out what socket library we have available
859$!
860$ IF F$PARSE("SOCKETSHR:") .NES. ""
861$ THEN
862$!
863$! We have SOCKETSHR, and it is my opinion that it's the best to use.
864$!
865$ P5 = "SOCKETSHR"
866$!
867$! Tell the user
868$!
869$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
870$!
871$! Else, let's look for something else
872$!
873$ ELSE
874$!
875$! Like UCX (the reason to do this before Multinet is that the UCX
876$! emulation is easier to use...)
877$!
878$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
879 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
880 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
881$ THEN
882$!
883$! Last resort: a UCX or UCX-compatible library
884$!
885$ P5 = "UCX"
886$!
887$! Tell the user
888$!
889$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
890$!
891$! That was all...
892$!
893$ ENDIF
894$ ENDIF
895$ ENDIF
896$!
897$! Set Up Initial CC Definitions, Possibly With User Ones
898$!
899$ CCDEFS = "VMS=1,TCPIP_TYPE_''P5'"
900$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
901$ CCEXTRAFLAGS = ""
902$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
903$ CCDISABLEWARNINGS = ""
904$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
905 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
906$!
907$! Check To See If The User Entered A Valid Paramter.
908$!
909$ IF (P4.EQS."VAXC").OR.(P4.EQS."DECC").OR.(P4.EQS."GNUC")
910$ THEN
911$!
912$! Check To See If The User Wanted DECC.
913$!
914$ IF (P4.EQS."DECC")
915$ THEN
916$!
917$! Looks Like DECC, Set To Use DECC.
918$!
919$ COMPILER = "DECC"
920$!
921$! Tell The User We Are Using DECC.
922$!
923$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
924$!
925$! Use DECC...
926$!
927$ CC = "CC"
928$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
929 THEN CC = "CC/DECC"
930$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
931 "/NOLIST/PREFIX=ALL" + -
932 "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS
933$!
934$! Define The Linker Options File Name.
935$!
936$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
937$!
938$! End DECC Check.
939$!
940$ ENDIF
941$!
942$! Check To See If We Are To Use VAXC.
943$!
944$ IF (P4.EQS."VAXC")
945$ THEN
946$!
947$! Looks Like VAXC, Set To Use VAXC.
948$!
949$ COMPILER = "VAXC"
950$!
951$! Tell The User We Are Using VAX C.
952$!
953$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
954$!
955$! Compile Using VAXC.
956$!
957$ CC = "CC"
958$ IF ARCH.EQS."AXP"
959$ THEN
960$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
961$ EXIT
962$ ENDIF
963$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
964$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
965 "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS
966$ CCDEFS = CCDEFS + ",""VAXC"""
967$!
968$! Define <sys> As SYS$COMMON:[SYSLIB]
969$!
970$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
971$!
972$! Define The Linker Options File Name.
973$!
974$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
975$!
976$! End VAXC Check
977$!
978$ ENDIF
979$!
980$! Check To See If We Are To Use GNU C.
981$!
982$ IF (P4.EQS."GNUC")
983$ THEN
984$!
985$! Looks Like GNUC, Set To Use GNUC.
986$!
987$ COMPILER = "GNUC"
988$!
989$! Tell The User We Are Using GNUC.
990$!
991$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
992$!
993$! Use GNU C...
994$!
995$ IF F$TYPE(GCC) .EQS. "" THEN GCC := GCC
996$ CC = GCC+"/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
997 "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS
998$!
999$! Define The Linker Options File Name.
1000$!
1001$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
1002$!
1003$! End The GNU C Check.
1004$!
1005$ ENDIF
1006$!
1007$! Set up default defines
1008$!
1009$ CCDEFS = """FLAT_INC=1""," + CCDEFS
1010$!
1011$! Check To See If We Are To Compile With RSAREF Routines.
1012$!
1013$ IF (RSAREF.EQS."TRUE")
1014$ THEN
1015$!
1016$! Compile With RSAREF.
1017$!
1018$ CCDEFS = CCDEFS + ",""RSAref=1"""
1019$!
1020$! Tell The User This.
1021$!
1022$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
1023$!
1024$! Else, We Don't Care. Compile Without The RSAREF Library.
1025$!
1026$ ELSE
1027$!
1028$! Tell The User We Are Compile Without The RSAREF Routines.
1029$!
1030$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
1031$!
1032$! End The RSAREF Check.
1033$!
1034$ ENDIF
1035$!
1036$! Finish up the definition of CC.
1037$!
1038$ IF COMPILER .EQS. "DECC"
1039$ THEN
1040$ IF CCDISABLEWARNINGS .EQS. ""
1041$ THEN
1042$ CC4DISABLEWARNINGS = "DOLLARID"
1043$ ELSE
1044$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1045$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1046$ ENDIF
1047$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1048$ ELSE
1049$ CCDISABLEWARNINGS = ""
1050$ CC4DISABLEWARNINGS = ""
1051$ ENDIF
1052$ CC2 = CC + "/DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
1053$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1054$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1055$ IF COMPILER .EQS. "DECC"
1056$ THEN
1057$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1058$ CC5 = CC3 - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1059$ ELSE
1060$ CC4 = CC
1061$ CC5 = CC3
1062$ ENDIF
1063$!
1064$! Show user the result
1065$!
1066$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
1067$!
1068$! Else The User Entered An Invalid Arguement.
1069$!
1070$ ELSE
1071$!
1072$! Tell The User We Don't Know What They Want.
1073$!
1074$ WRITE SYS$OUTPUT ""
1075$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1076$ WRITE SYS$OUTPUT ""
1077$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1078$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
1079$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
1080$ WRITE SYS$OUTPUT ""
1081$!
1082$! Time To EXIT.
1083$!
1084$ EXIT
1085$ ENDIF
1086$!
1087$! Time to check the contents, and to make sure we get the correct library.
1088$!
1089$ IF P5.EQS."SOCKETSHR" .OR. P5.EQS."MULTINET" .OR. P5.EQS."UCX"
1090$ THEN
1091$!
1092$! Check to see if SOCKETSHR was chosen
1093$!
1094$ IF P5.EQS."SOCKETSHR"
1095$ THEN
1096$!
1097$! Set the library to use SOCKETSHR
1098$!
1099$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
1100$!
1101$! Done with SOCKETSHR
1102$!
1103$ ENDIF
1104$!
1105$! Check to see if MULTINET was chosen
1106$!
1107$ IF P5.EQS."MULTINET"
1108$ THEN
1109$!
1110$! Set the library to use UCX emulation.
1111$!
1112$ P5 = "UCX"
1113$!
1114$! Done with MULTINET
1115$!
1116$ ENDIF
1117$!
1118$! Check to see if UCX was chosen
1119$!
1120$ IF P5.EQS."UCX"
1121$ THEN
1122$!
1123$! Set the library to use UCX.
1124$!
1125$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
1126$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1127$ THEN
1128$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1129$ ELSE
1130$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1131 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1132$ ENDIF
1133$!
1134$! Done with UCX
1135$!
1136$ ENDIF
1137$!
1138$! Print info
1139$!
1140$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1141$!
1142$! Else The User Entered An Invalid Arguement.
1143$!
1144$ ELSE
1145$!
1146$! Tell The User We Don't Know What They Want.
1147$!
1148$ WRITE SYS$OUTPUT ""
1149$ WRITE SYS$OUTPUT "The Option ",P5," Is Invalid. The Valid Options Are:"
1150$ WRITE SYS$OUTPUT ""
1151$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1152$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1153$ WRITE SYS$OUTPUT ""
1154$!
1155$! Time To EXIT.
1156$!
1157$ EXIT
1158$!
1159$! Done with TCP/IP libraries
1160$!
1161$ ENDIF
1162$!
1163$! Time To RETURN...
1164$!
1165$ RETURN
1166$!
1167$ INITIALISE:
1168$!
1169$! Save old value of the logical name OPENSSL
1170$!
1171$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1172$!
1173$! Save directory information
1174$!
1175$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1176$ __TOP = __HERE - "SSL]"
1177$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1178$!
1179$! Set up the logical name OPENSSL to point at the include directory
1180$!
1181$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1182$!
1183$! Done
1184$!
1185$ RETURN
1186$!
1187$ CLEANUP:
1188$!
1189$! Restore the logical name OPENSSL if it had a value
1190$!
1191$ IF __SAVE_OPENSSL .EQS. ""
1192$ THEN
1193$ DEASSIGN OPENSSL
1194$ ELSE
1195$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1196$ ENDIF
1197$!
1198$! Done
1199$!
1200$ RETURN
diff --git a/src/lib/libssl/src/test/VMSca-response.1 b/src/lib/libssl/src/test/VMSca-response.1
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/src/lib/libssl/src/test/VMSca-response.1
@@ -0,0 +1 @@
diff --git a/src/lib/libssl/src/test/VMSca-response.2 b/src/lib/libssl/src/test/VMSca-response.2
new file mode 100644
index 0000000000..9b48ee4cf9
--- /dev/null
+++ b/src/lib/libssl/src/test/VMSca-response.2
@@ -0,0 +1,2 @@
1y
2y
diff --git a/src/lib/libssl/src/test/bctest b/src/lib/libssl/src/test/bctest
new file mode 100644
index 0000000000..bdb3218f7a
--- /dev/null
+++ b/src/lib/libssl/src/test/bctest
@@ -0,0 +1,111 @@
1#!/bin/sh
2
3# This script is used by test/Makefile.ssl to check whether a sane 'bc'
4# is installed.
5# ('make test_bn' should not try to run 'bc' if it does not exist or if
6# it is a broken 'bc' version that is known to cause trouble.)
7#
8# If 'bc' works, we also test if it knows the 'print' command.
9#
10# In any case, output an appropriate command line for running (or not
11# running) bc.
12
13
14IFS=:
15try_without_dir=true
16# First we try "bc", then "$dir/bc" for each item in $PATH.
17for dir in dummy:$PATH; do
18 if [ "$try_without_dir" = true ]; then
19 # first iteration
20 bc=bc
21 try_without_dir=false
22 else
23 # second and later iterations
24 bc="$dir/bc"
25 if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix
26 bc=''
27 fi
28 fi
29
30 if [ ! "$bc" = '' ]; then
31 failure=none
32
33
34 # Test for SunOS 5.[78] bc bug
35 "$bc" >tmp.bctest <<\EOF
36obase=16
37ibase=16
38a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
39CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
4010F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
41C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
423BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
434FC3CADF855448B24A9D7640BCF473E
44b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
459209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
468B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
473ED0E2017D60A68775B75481449
48(a/b)*b + (a%b) - a
49EOF
50 if [ 0 != "`cat tmp.bctest`" ]; then
51 failure=SunOStest
52 fi
53
54
55 if [ "$failure" = none ]; then
56 # Test for SCO bc bug.
57 "$bc" >tmp.bctest <<\EOF
58obase=16
59ibase=16
60-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
619DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
6211B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
631239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
64AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
65F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
66B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
6702EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
6885EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
69A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
70E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
718C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
7204E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
7389C8D71
74AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
75928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
768A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
7737F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
78E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
79F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
809E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
81D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
825296964
83EOF
84 if [ "0
850" != "`cat tmp.bctest`" ]; then
86 failure=SCOtest
87 fi
88 fi
89
90
91 if [ "$failure" = none ]; then
92 # bc works; now check if it knows the 'print' command.
93 if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ]
94 then
95 echo "$bc"
96 else
97 echo "sed 's/print.*//' | $bc"
98 fi
99 exit 0
100 fi
101
102 echo "$bc does not work properly ('$failure' failed). Looking for another bc ..." >&2
103 fi
104done
105
106echo "No working bc found. Consider installing GNU bc." >&2
107if [ "$1" = ignore ]; then
108 echo "cat >/dev/null"
109 exit 0
110fi
111exit 1
diff --git a/src/lib/libssl/src/test/maketests.com b/src/lib/libssl/src/test/maketests.com
new file mode 100644
index 0000000000..e4b052e688
--- /dev/null
+++ b/src/lib/libssl/src/test/maketests.com
@@ -0,0 +1,1053 @@
1$!
2$! MAKETESTS.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates all the various different
11$! "test" programs for the different types of encryption for OpenSSL.
12$! It was written so it would try to determine what "C" compiler to
13$! use or you can specify which "C" compiler to use.
14$!
15$! The test "executeables" will be placed in a directory called
16$! [.xxx.EXE.TEST] where "xxx" denotes AXP or VAX depending on your machines
17$! architecture.
18$!
19$! Specify RSAREF as P1 to compile with the RSAREF library instead of
20$! the regular one. If you specify NORSAREF it will compile with the
21$! regular RSAREF routines. (Note: If you are in the United States
22$! you MUST compile with RSAREF unless you have a license from RSA).
23$!
24$! Note: The RSAREF libraries are NOT INCLUDED and you have to
25$! download it from "ftp://ftp.rsa.com/rsaref". You have to
26$! get the ".tar-Z" file as the ".zip" file dosen't have the
27$! directory structure stored. You have to extract the file
28$! into the [.RSAREF] directory under the root directory as that
29$! is where the scripts will look for the files.
30$!
31$! Specify DEBUG or NODEBUG P2 to compile with or without debugger
32$! information.
33$!
34$! Specify which compiler at P3 to try to compile under.
35$!
36$! VAXC For VAX C.
37$! DECC For DEC C.
38$! GNUC For GNU C.
39$!
40$! If you don't speficy a compiler, it will try to determine which
41$! "C" compiler to use.
42$!
43$! P4, if defined, sets a TCP/IP library to use, through one of the following
44$! keywords:
45$!
46$! UCX for UCX
47$! SOCKETSHR for SOCKETSHR+NETLIB
48$!
49$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
50$!
51$!
52$! Define A TCP/IP Library That We Will Need To Link To.
53$! (That is, If Wee Need To Link To One.)
54$!
55$ TCPIP_LIB = ""
56$!
57$! Check Which Architecture We Are Using.
58$!
59$ IF (F$GETSYI("CPU").GE.128)
60$ THEN
61$!
62$! The Architecture Is AXP.
63$!
64$ ARCH := AXP
65$!
66$! Else...
67$!
68$ ELSE
69$!
70$! The Architecture Is VAX.
71$!
72$ ARCH := VAX
73$!
74$! End The Architecture Check.
75$!
76$ ENDIF
77$!
78$! Check To Make Sure We Have Valid Command Line Parameters.
79$!
80$ GOSUB CHECK_OPTIONS
81$!
82$! Initialise logical names and such
83$!
84$ GOSUB INITIALISE
85$!
86$! Tell The User What Kind of Machine We Run On.
87$!
88$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
89$!
90$! Define The CRYPTO-LIB We Are To Use.
91$!
92$ CRYPTO_LIB := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
93$!
94$! Define The RSAREF-LIB We Are To Use.
95$!
96$ RSAREF_LIB := SYS$DISK:[-.'ARCH'.EXE.RSAREF]LIBRSAGLUE.OLB
97$!
98$! Define The SSL We Are To Use.
99$!
100$ SSL_LIB := SYS$DISK:[-.'ARCH'.EXE.SSL]LIBSSL.OLB
101$!
102$! Define The OBJ Directory.
103$!
104$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.TEST]
105$!
106$! Check To See If The Architecture Specific OBJ Directory Exists.
107$!
108$ IF (F$PARSE(OBJ_DIR).EQS."")
109$ THEN
110$!
111$! The EXE Directory Dosen't Exist, So Create It.
112$!
113$ CREATE/DIRECTORY 'OBJ_DIR'
114$!
115$! End The Architecture Specific OBJ Directory Check.
116$!
117$ ENDIF
118$!
119$! Define The EXE Directory.
120$!
121$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.TEST]
122$!
123$! Check To See If The Architecture Specific EXE Directory Exists.
124$!
125$ IF (F$PARSE(EXE_DIR).EQS."")
126$ THEN
127$!
128$! The EXE Directory Dosen't Exist, So Create It.
129$!
130$ CREATE/DIRECTORY 'EXE_DIR'
131$!
132$! End The Architecture Specific EXE Directory Check.
133$!
134$ ENDIF
135$!
136$! Check To See If We Have The Proper Libraries.
137$!
138$ GOSUB LIB_CHECK
139$!
140$! Check To See If We Have A Linker Option File.
141$!
142$ GOSUB CHECK_OPT_FILE
143$!
144$! Define The TEST Files.
145$!
146$ TEST_FILES = "BNTEST,IDEATEST,MD2TEST,MD5TEST,HMACTEST,"+ -
147 "RC2TEST,RC4TEST,RC5TEST,"+ -
148 "DESTEST,SHATEST,SHA1TEST,MDC2TEST,RMDTEST,"+ -
149 "RANDTEST,DHTEST,"+ -
150 "BFTEST,CASTTEST,SSLTEST,EXPTEST,DSATEST,RSA_OAEP_TEST"
151$ TCPIP_PROGRAMS = ",,"
152$ IF COMPILER .EQS. "VAXC" THEN -
153 TCPIP_PROGRAMS = ",SSLTEST,"
154$!
155$! Define A File Counter And Set It To "0".
156$!
157$ FILE_COUNTER = 0
158$!
159$! Top Of The File Loop.
160$!
161$ NEXT_FILE:
162$!
163$! O.K, Extract The File Name From The File List.
164$!
165$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",TEST_FILES)
166$!
167$! Check To See If We Are At The End Of The File List.
168$!
169$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
170$!
171$! Increment The Counter.
172$!
173$ FILE_COUNTER = FILE_COUNTER + 1
174$!
175$! Create The Source File Name.
176$!
177$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
178$!
179$! Create The Object File Name.
180$!
181$ OBJECT_FILE = OBJ_DIR + FILE_NAME + ".OBJ"
182$!
183$! Create The Executable File Name.
184$!
185$ EXE_FILE = EXE_DIR + FILE_NAME + ".EXE"
186$ ON WARNING THEN GOTO NEXT_FILE
187$!
188$! Check To See If The File We Want To Compile Actually Exists.
189$!
190$ IF (F$SEARCH(SOURCE_FILE).EQS."")
191$ THEN
192$!
193$! Tell The User That The File Dosen't Exist.
194$!
195$ WRITE SYS$OUTPUT ""
196$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
197$ WRITE SYS$OUTPUT ""
198$!
199$! Exit The Build.
200$!
201$ GOTO EXIT
202$ ENDIF
203$!
204$! Tell The User What We Are Building.
205$!
206$ WRITE SYS$OUTPUT "Building The ",FILE_NAME," Test Program."
207$!
208$! Compile The File.
209$!
210$ ON ERROR THEN GOTO NEXT_FILE
211$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
212$ ON WARNING THEN GOTO NEXT_FILE
213$!
214$! Check If What We Are About To Compile Works Without A TCP/IP Library.
215$!
216$ IF ((TCPIP_LIB.EQS."").AND.((TCPIP_PROGRAMS-FILE_NAME).NES.TCPIP_PROGRAMS))
217$ THEN
218$!
219$! Inform The User That A TCP/IP Library Is Needed To Compile This Program.
220$!
221$ WRITE SYS$OUTPUT FILE_NAME," Needs A TCP/IP Library. Can't Link. Skipping..."
222$ GOTO NEXT_FILE
223$!
224$! End The TCP/IP Library Check.
225$!
226$ ENDIF
227$!
228$! Link The Program, Check To See If We Need To Link With RSAREF Or Not.
229$!
230$ IF (RSAREF.EQS."TRUE")
231$ THEN
232$!
233$! Check To See If We Are To Link With A Specific TCP/IP Library.
234$!
235$ IF (TCPIP_LIB.NES."")
236$ THEN
237$!
238$! Link With The RSAREF Library And A Specific TCP/IP Library.
239$!
240$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
241 'OBJECT_FILE',-
242 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
243 'TCPIP_LIB','OPT_FILE'/OPTION
244$!
245$! Else...
246$!
247$ ELSE
248$!
249$! Link With The RSAREF Library And NO TCP/IP Library.
250$!
251$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
252 'OBJECT_FILE', -
253 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
254 'OPT_FILE'/OPTION
255$!
256$! End The TCP/IP Library Check.
257$!
258$ ENDIF
259$!
260$! Else...
261$!
262$ ELSE
263$!
264$! Don't Link With The RSAREF Routines.
265$!
266$!
267$! Check To See If We Are To Link With A Specific TCP/IP Library.
268$!
269$ IF (TCPIP_LIB.NES."")
270$ THEN
271$!
272$! Don't Link With The RSAREF Routines And TCP/IP Library.
273$!
274$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
275 'OBJECT_FILE', -
276 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
277 'TCPIP_LIB','OPT_FILE'/OPTION
278$!
279$! Else...
280$!
281$ ELSE
282$!
283$! Don't Link With The RSAREF Routines And Link With A TCP/IP Library.
284$!
285$ LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
286 'OBJECT_FILE', -
287 'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
288 'OPT_FILE'/OPTION
289$!
290$! End The TCP/IP Library Check.
291$!
292$ ENDIF
293$!
294$! End The RSAREF Link Check.
295$!
296$ ENDIF
297$!
298$! Go Back And Do It Again.
299$!
300$ GOTO NEXT_FILE
301$!
302$! All Done With This Library Part.
303$!
304$ FILE_DONE:
305$!
306$! All Done, Time To Exit.
307$!
308$ EXIT:
309$ GOSUB CLEANUP
310$ EXIT
311$!
312$! Check For The Link Option FIle.
313$!
314$ CHECK_OPT_FILE:
315$!
316$! Check To See If We Need To Make A VAX C Option File.
317$!
318$ IF (COMPILER.EQS."VAXC")
319$ THEN
320$!
321$! Check To See If We Already Have A VAX C Linker Option File.
322$!
323$ IF (F$SEARCH(OPT_FILE).EQS."")
324$ THEN
325$!
326$! We Need A VAX C Linker Option File.
327$!
328$ CREATE 'OPT_FILE'
329$DECK
330!
331! Default System Options File To Link Agianst
332! The Sharable VAX C Runtime Library.
333!
334SYS$SHARE:VAXCRTL.EXE/SHARE
335$EOD
336$!
337$! End The Option File Check.
338$!
339$ ENDIF
340$!
341$! End The VAXC Check.
342$!
343$ ENDIF
344$!
345$! Check To See If We Need A GNU C Option File.
346$!
347$ IF (COMPILER.EQS."GNUC")
348$ THEN
349$!
350$! Check To See If We Already Have A GNU C Linker Option File.
351$!
352$ IF (F$SEARCH(OPT_FILE).EQS."")
353$ THEN
354$!
355$! We Need A GNU C Linker Option File.
356$!
357$ CREATE 'OPT_FILE'
358$DECK
359!
360! Default System Options File To Link Agianst
361! The Sharable C Runtime Library.
362!
363GNU_CC:[000000]GCCLIB/LIBRARY
364SYS$SHARE:VAXCRTL/SHARE
365$EOD
366$!
367$! End The Option File Check.
368$!
369$ ENDIF
370$!
371$! End The GNU C Check.
372$!
373$ ENDIF
374$!
375$! Check To See If We Need A DEC C Option File.
376$!
377$ IF (COMPILER.EQS."DECC")
378$ THEN
379$!
380$! Check To See If We Already Have A DEC C Linker Option File.
381$!
382$ IF (F$SEARCH(OPT_FILE).EQS."")
383$ THEN
384$!
385$! Figure Out If We Need An AXP Or A VAX Linker Option File.
386$!
387$ IF (ARCH.EQS."VAX")
388$ THEN
389$!
390$! We Need A DEC C Linker Option File For VAX.
391$!
392$ CREATE 'OPT_FILE'
393$DECK
394!
395! Default System Options File To Link Agianst
396! The Sharable DEC C Runtime Library.
397!
398SYS$SHARE:DECC$SHR.EXE/SHARE
399$EOD
400$!
401$! Else...
402$!
403$ ELSE
404$!
405$! Create The AXP Linker Option File.
406$!
407$ CREATE 'OPT_FILE'
408$DECK
409!
410! Default System Options File For AXP To Link Agianst
411! The Sharable C Runtime Library.
412!
413SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
414SYS$SHARE:CMA$OPEN_RTL/SHARE
415$EOD
416$!
417$! End The VAX/AXP DEC C Option File Check.
418$!
419$ ENDIF
420$!
421$! End The Option File Search.
422$!
423$ ENDIF
424$!
425$! End The DEC C Check.
426$!
427$ ENDIF
428$!
429$! Tell The User What Linker Option File We Are Using.
430$!
431$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
432$!
433$! Time To RETURN.
434$!
435$ RETURN
436$!
437$! Check To See If We Have The Appropiate Libraries.
438$!
439$ LIB_CHECK:
440$!
441$! Look For The Library LIBCRYPTO.OLB.
442$!
443$ IF (F$SEARCH(CRYPTO_LIB).EQS."")
444$ THEN
445$!
446$! Tell The User We Can't Find The LIBCRYPTO.OLB Library.
447$!
448$ WRITE SYS$OUTPUT ""
449$ WRITE SYS$OUTPUT "Can't Find The Library ",CRYPTO_LIB,"."
450$ WRITE SYS$OUTPUT "We Can't Link Without It."
451$ WRITE SYS$OUTPUT ""
452$!
453$! Since We Can't Link Without It, Exit.
454$!
455$ EXIT
456$!
457$! End The Crypto Library Check.
458$!
459$ ENDIF
460$!
461$! See If We Need The RSAREF Library...
462$!
463$ IF (RSAREF.EQS."TRUE")
464$ THEN
465$!
466$! Look For The Library LIBRSAGLUE.OLB.
467$!
468$ IF (F$SEARCH(RSAREF_LIB).EQS."")
469$ THEN
470$!
471$! Tell The User We Can't Find The LIBRSAGLUE.OLB Library.
472$!
473$ WRITE SYS$OUTPUT ""
474$ WRITE SYS$OUTPUT "Can't Find The Library ",RSAREF_LIB,"."
475$ WRITE SYS$OUTPUT "We Can't Link Without It."
476$ WRITE SYS$OUTPUT ""
477$!
478$! Since We Can't Link Without It, Exit.
479$!
480$ EXIT
481$ ENDIF
482$!
483$! End The RSAREF Library Check.
484$!
485$ ENDIF
486$!
487$! Look For The Library LIBSSL.OLB.
488$!
489$ IF (F$SEARCH(SSL_LIB).EQS."")
490$ THEN
491$!
492$! Tell The User We Can't Find The LIBSSL.OLB Library.
493$!
494$ WRITE SYS$OUTPUT ""
495$ WRITE SYS$OUTPUT "Can't Find The Library ",SSL_LIB,"."
496$ WRITE SYS$OUTPUT "Some Of The Test Programs Need To Link To It."
497$ WRITE SYS$OUTPUT ""
498$!
499$! Since We Can't Link Without It, Exit.
500$!
501$ EXIT
502$!
503$! End The SSL Library Check.
504$!
505$ ENDIF
506$!
507$! Time To Return.
508$!
509$ RETURN
510$!
511$! Check The User's Options.
512$!
513$ CHECK_OPTIONS:
514$!
515$! Check To See If P1 Is Blank.
516$!
517$ IF (P1.EQS."NORSAREF")
518$ THEN
519$!
520$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries.
521$!
522$ RSAREF = "FALSE"
523$ ELSE
524$!
525$! Check To See If We Are To Use The RSAREF Library.
526$!
527$ IF (P1.EQS."RSAREF")
528$ THEN
529$!
530$! Check To Make Sure We Have The RSAREF Source Code Directory.
531$!
532$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
533$ THEN
534$!
535$! We Don't Have The RSAREF Souce Code Directory, So Tell The
536$! User This.
537$!
538$ WRITE SYS$OUTPUT ""
539$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
540$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
541$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
542$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
543$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
544$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
545$ WRITE SYS$OUTPUT ""
546$!
547$! Time To Exit.
548$!
549$ EXIT
550$!
551$! Else, Compile Using The RSAREF Library.
552$!
553$ ELSE
554$ RSAREF = "TRUE"
555$ ENDIF
556$ ELSE
557$!
558$! They Entered An Invalid Option..
559$!
560$ WRITE SYS$OUTPUT ""
561$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
562$ WRITE SYS$OUTPUT ""
563$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
564$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
565$ WRITE SYS$OUTPUT ""
566$!
567$! Time To EXIT.
568$!
569$ EXIT
570$!
571$! End The Valid Arguement Check.
572$!
573$ ENDIF
574$!
575$! End The P1 Check.
576$!
577$ ENDIF
578$!
579$! Check To See If P2 Is Blank.
580$!
581$ IF (P2.EQS."NODEBUG")
582$ THEN
583$!
584$! P2 Is NODEBUG, So Compile Without Debugger Information.
585$!
586$ DEBUGGER = "NODEBUG"
587$ TRACEBACK = "NOTRACEBACK"
588$ GCC_OPTIMIZE = "OPTIMIZE"
589$ CC_OPTIMIZE = "OPTIMIZE"
590$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
591$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
592$!
593$! Else...
594$!
595$ ELSE
596$!
597$! Check To See If We Are To Compile With Debugger Information.
598$!
599$ IF (P2.EQS."DEBUG")
600$ THEN
601$!
602$! Compile With Debugger Information.
603$!
604$ DEBUGGER = "DEBUG"
605$ TRACEBACK = "TRACEBACK"
606$ GCC_OPTIMIZE = "NOOPTIMIZE"
607$ CC_OPTIMIZE = "NOOPTIMIZE"
608$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
609$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
610$!
611$! Else...
612$!
613$ ELSE
614$!
615$! Tell The User Entered An Invalid Option..
616$!
617$ WRITE SYS$OUTPUT ""
618$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
619$ WRITE SYS$OUTPUT ""
620$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
621$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
622$ WRITE SYS$OUTPUT ""
623$!
624$! Time To EXIT.
625$!
626$ EXIT
627$!
628$! End The Valid Arguement Check.
629$!
630$ ENDIF
631$!
632$! End The P3 Check.
633$!
634$ ENDIF
635$!
636$! Check To See If P3 Is Blank.
637$!
638$ IF (P3.EQS."")
639$ THEN
640$!
641$! O.K., The User Didn't Specify A Compiler, Let's Try To
642$! Find Out Which One To Use.
643$!
644$! Check To See If We Have GNU C.
645$!
646$ IF (F$TRNLNM("GNU_CC").NES."")
647$ THEN
648$!
649$! Looks Like GNUC, Set To Use GNUC.
650$!
651$ P3 = "GNUC"
652$!
653$! End The GNU C Compiler Check.
654$!
655$ ELSE
656$!
657$! Check To See If We Have VAXC Or DECC.
658$!
659$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
660$ THEN
661$!
662$! Looks Like DECC, Set To Use DECC.
663$!
664$ P3 = "DECC"
665$!
666$! Else...
667$!
668$ ELSE
669$!
670$! Looks Like VAXC, Set To Use VAXC.
671$!
672$ P3 = "VAXC"
673$!
674$! End The VAXC Compiler Check.
675$!
676$ ENDIF
677$!
678$! End The DECC & VAXC Compiler Check.
679$!
680$ ENDIF
681$!
682$! End The Compiler Check.
683$!
684$ ENDIF
685$!
686$! Check To See If We Have A Option For P4.
687$!
688$ IF (P4.EQS."")
689$ THEN
690$!
691$! Find out what socket library we have available
692$!
693$ IF F$PARSE("SOCKETSHR:") .NES. ""
694$ THEN
695$!
696$! We have SOCKETSHR, and it is my opinion that it's the best to use.
697$!
698$ P4 = "SOCKETSHR"
699$!
700$! Tell the user
701$!
702$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
703$!
704$! Else, let's look for something else
705$!
706$ ELSE
707$!
708$! Like UCX (the reason to do this before Multinet is that the UCX
709$! emulation is easier to use...)
710$!
711$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
712 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
713 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
714$ THEN
715$!
716$! Last resort: a UCX or UCX-compatible library
717$!
718$ P4 = "UCX"
719$!
720$! Tell the user
721$!
722$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
723$!
724$! That was all...
725$!
726$ ENDIF
727$ ENDIF
728$ ENDIF
729$!
730$! Set Up Initial CC Definitions, Possibly With User Ones
731$!
732$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'"
733$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
734$ CCEXTRAFLAGS = ""
735$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
736$ CCDISABLEWARNINGS = ""
737$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
738 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
739$!
740$! Check To See If The User Entered A Valid Paramter.
741$!
742$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
743$ THEN
744$!
745$! Check To See If The User Wanted DECC.
746$!
747$ IF (P3.EQS."DECC")
748$ THEN
749$!
750$! Looks Like DECC, Set To Use DECC.
751$!
752$ COMPILER = "DECC"
753$!
754$! Tell The User We Are Using DECC.
755$!
756$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
757$!
758$! Use DECC...
759$!
760$ CC = "CC"
761$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
762 THEN CC = "CC/DECC"
763$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
764 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
765$!
766$! Define The Linker Options File Name.
767$!
768$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
769$!
770$! End DECC Check.
771$!
772$ ENDIF
773$!
774$! Check To See If We Are To Use VAXC.
775$!
776$ IF (P3.EQS."VAXC")
777$ THEN
778$!
779$! Looks Like VAXC, Set To Use VAXC.
780$!
781$ COMPILER = "VAXC"
782$!
783$! Tell The User We Are Using VAX C.
784$!
785$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
786$!
787$! Compile Using VAXC.
788$!
789$ CC = "CC"
790$ IF ARCH.EQS."AXP"
791$ THEN
792$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
793$ EXIT
794$ ENDIF
795$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
796$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
797$ CCDEFS = CCDEFS + ",""VAXC"""
798$!
799$! Define <sys> As SYS$COMMON:[SYSLIB]
800$!
801$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
802$!
803$! Define The Linker Options File Name.
804$!
805$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
806$!
807$! End VAXC Check
808$!
809$ ENDIF
810$!
811$! Check To See If We Are To Use GNU C.
812$!
813$ IF (P3.EQS."GNUC")
814$ THEN
815$!
816$! Looks Like GNUC, Set To Use GNUC.
817$!
818$ COMPILER = "GNUC"
819$!
820$! Tell The User We Are Using GNUC.
821$!
822$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
823$!
824$! Use GNU C...
825$!
826$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
827$!
828$! Define The Linker Options File Name.
829$!
830$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
831$!
832$! End The GNU C Check.
833$!
834$ ENDIF
835$!
836$! Set up default defines
837$!
838$ CCDEFS = """FLAT_INC=1""," + CCDEFS
839$!
840$! Check To See If We Are To Compile With RSAREF Routines.
841$!
842$ IF (RSAREF.EQS."TRUE")
843$ THEN
844$!
845$! Compile With RSAREF.
846$!
847$ CCDEFS = CCDEFS + ",""RSAref=1"""
848$!
849$! Tell The User This.
850$!
851$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
852$!
853$! Else, We Don't Care. Compile Without The RSAREF Library.
854$!
855$ ELSE
856$!
857$! Tell The User We Are Compile Without The RSAREF Routines.
858$!
859$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
860$!
861$! End The RSAREF Check.
862$!
863$ ENDIF
864$!
865$! Finish up the definition of CC.
866$!
867$ IF COMPILER .EQS. "DECC"
868$ THEN
869$ IF CCDISABLEWARNINGS .EQS. ""
870$ THEN
871$ CC4DISABLEWARNINGS = "DOLLARID"
872$ ELSE
873$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
874$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
875$ ENDIF
876$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
877$ ELSE
878$ CCDISABLEWARNINGS = ""
879$ CC4DISABLEWARNINGS = ""
880$ ENDIF
881$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
882$!
883$! Show user the result
884$!
885$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
886$!
887$! Else The User Entered An Invalid Arguement.
888$!
889$ ELSE
890$!
891$! Tell The User We Don't Know What They Want.
892$!
893$ WRITE SYS$OUTPUT ""
894$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
895$ WRITE SYS$OUTPUT ""
896$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
897$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
898$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
899$ WRITE SYS$OUTPUT ""
900$!
901$! Time To EXIT.
902$!
903$ EXIT
904$ ENDIF
905$!
906$! Time to check the contents, and to make sure we get the correct library.
907$!
908$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX"
909$ THEN
910$!
911$! Check to see if SOCKETSHR was chosen
912$!
913$ IF P4.EQS."SOCKETSHR"
914$ THEN
915$!
916$! Set the library to use SOCKETSHR
917$!
918$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
919$!
920$! Done with SOCKETSHR
921$!
922$ ENDIF
923$!
924$! Check to see if MULTINET was chosen
925$!
926$ IF P4.EQS."MULTINET"
927$ THEN
928$!
929$! Set the library to use UXC emulation.
930$!
931$ P4 = "UCX"
932$!
933$! Done with MULTINET
934$!
935$ ENDIF
936$!
937$! Check to see if UCX was chosen
938$!
939$ IF P4.EQS."UCX"
940$ THEN
941$!
942$! Set the library to use UCX.
943$!
944$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
945$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
946$ THEN
947$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
948$ ELSE
949$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
950 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
951$ ENDIF
952$!
953$! Done with UCX
954$!
955$ ENDIF
956$!
957$! Print info
958$!
959$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
960$!
961$! Else The User Entered An Invalid Arguement.
962$!
963$ ELSE
964$!
965$! Tell The User We Don't Know What They Want.
966$!
967$ WRITE SYS$OUTPUT ""
968$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
969$ WRITE SYS$OUTPUT ""
970$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
971$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
972$ WRITE SYS$OUTPUT ""
973$!
974$! Time To EXIT.
975$!
976$ EXIT
977$!
978$! Done with TCP/IP libraries
979$!
980$ ENDIF
981$!
982$! Special Threads For OpenVMS v7.1 Or Later
983$!
984$! Written By: Richard Levitte
985$! richard@levitte.org
986$!
987$!
988$! Check To See If We Have A Option For P5.
989$!
990$ IF (P5.EQS."")
991$ THEN
992$!
993$! Get The Version Of VMS We Are Using.
994$!
995$ ISSEVEN :=
996$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
997$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
998$!
999$! Check To See If The VMS Version Is v7.1 Or Later.
1000$!
1001$ IF (TMP.GE.71)
1002$ THEN
1003$!
1004$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
1005$!
1006$ ISSEVEN := ,PTHREAD_USE_D4
1007$!
1008$! End The VMS Version Check.
1009$!
1010$ ENDIF
1011$!
1012$! End The P5 Check.
1013$!
1014$ ENDIF
1015$!
1016$! Time To RETURN...
1017$!
1018$ RETURN
1019$!
1020$ INITIALISE:
1021$!
1022$! Save old value of the logical name OPENSSL
1023$!
1024$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1025$!
1026$! Save directory information
1027$!
1028$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1029$ __TOP = __HERE - "TEST]"
1030$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1031$!
1032$! Set up the logical name OPENSSL to point at the include directory
1033$!
1034$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1035$!
1036$! Done
1037$!
1038$ RETURN
1039$!
1040$ CLEANUP:
1041$!
1042$! Restore the logical name OPENSSL if it had a value
1043$!
1044$ IF __SAVE_OPENSSL .EQS. ""
1045$ THEN
1046$ DEASSIGN OPENSSL
1047$ ELSE
1048$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1049$ ENDIF
1050$!
1051$! Done
1052$!
1053$ RETURN
diff --git a/src/lib/libssl/src/test/tcrl.com b/src/lib/libssl/src/test/tcrl.com
new file mode 100644
index 0000000000..cef21467bb
--- /dev/null
+++ b/src/lib/libssl/src/test/tcrl.com
@@ -0,0 +1,78 @@
1$! TCRL.COM -- Tests crl keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl crl
8$
9$ t := testcrl.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing CRL conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$! write sys$output "p -> t"
19$! 'cmd' -in fff.p -inform p -outform t -out f.t
20$! if $severity .ne. 1 then exit 3
21$ write sys$output "p -> p"
22$ 'cmd' -in fff.p -inform p -outform p -out f.p
23$ if $severity .ne. 1 then exit 3
24$
25$ write sys$output "d -> d"
26$ 'cmd' -in f.d -inform d -outform d -out ff.d1
27$ if $severity .ne. 1 then exit 3
28$! write sys$output "t -> d"
29$! 'cmd' -in f.t -inform t -outform d -out ff.d2
30$! if $severity .ne. 1 then exit 3
31$ write sys$output "p -> d"
32$ 'cmd' -in f.p -inform p -outform d -out ff.d3
33$ if $severity .ne. 1 then exit 3
34$
35$! write sys$output "d -> t"
36$! 'cmd' -in f.d -inform d -outform t -out ff.t1
37$! if $severity .ne. 1 then exit 3
38$! write sys$output "t -> t"
39$! 'cmd' -in f.t -inform t -outform t -out ff.t2
40$! if $severity .ne. 1 then exit 3
41$! write sys$output "p -> t"
42$! 'cmd' -in f.p -inform p -outform t -out ff.t3
43$! if $severity .ne. 1 then exit 3
44$
45$ write sys$output "d -> p"
46$ 'cmd' -in f.d -inform d -outform p -out ff.p1
47$ if $severity .ne. 1 then exit 3
48$! write sys$output "t -> p"
49$! 'cmd' -in f.t -inform t -outform p -out ff.p2
50$! if $severity .ne. 1 then exit 3
51$ write sys$output "p -> p"
52$ 'cmd' -in f.p -inform p -outform p -out ff.p3
53$ if $severity .ne. 1 then exit 3
54$
55$ difference/output=nl: fff.p f.p
56$ if $severity .ne. 1 then exit 3
57$ difference/output=nl: fff.p ff.p1
58$ if $severity .ne. 1 then exit 3
59$! difference/output=nl: fff.p ff.p2
60$! if $severity .ne. 1 then exit 3
61$ difference/output=nl: fff.p ff.p3
62$ if $severity .ne. 1 then exit 3
63$
64$! difference/output=nl: f.t ff.t1
65$! if $severity .ne. 1 then exit 3
66$! difference/output=nl: f.t ff.t2
67$! if $severity .ne. 1 then exit 3
68$! difference/output=nl: f.t ff.t3
69$! if $severity .ne. 1 then exit 3
70$
71$ difference/output=nl: f.p ff.p1
72$ if $severity .ne. 1 then exit 3
73$! difference/output=nl: f.p ff.p2
74$! if $severity .ne. 1 then exit 3
75$ difference/output=nl: f.p ff.p3
76$ if $severity .ne. 1 then exit 3
77$
78$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/testca.com b/src/lib/libssl/src/test/testca.com
new file mode 100644
index 0000000000..ea75479cd5
--- /dev/null
+++ b/src/lib/libssl/src/test/testca.com
@@ -0,0 +1,76 @@
1$! TESTCA.COM
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ openssl := mcr 'exe_dir'openssl
8$
9$ SSLEAY_CONFIG="-config ""CAss.cnf"""
10$
11$ set noon
12$ if f$search("demoCA.dir") .nes. ""
13$ then
14$ call deltree [.demoCA]*.*
15$ set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
16$ delete demoCA.dir;*
17$ endif
18$ set on
19$ open/read sys$ca_input VMSca-response.1
20$ @[-.apps]CA.com -input sys$ca_input -newca
21$ close sys$ca_input
22$ if $severity .ne. 1 then exit 3
23$
24$
25$ SSLEAY_CONFIG="-config ""Uss.cnf"""
26$ @[-.apps]CA.com -newreq
27$ if $severity .ne. 1 then exit 3
28$
29$
30$ SSLEAY_CONFIG="-config [-.apps]openssl-vms.cnf"
31$ open/read sys$ca_input VMSca-response.2
32$ @[-.apps]CA.com -input sys$ca_input -sign
33$ close sys$ca_input
34$ if $severity .ne. 1 then exit 3
35$
36$
37$ @[-.apps]CA.com -verify newcert.pem
38$ if $severity .ne. 1 then exit 3
39$
40$ set noon
41$ call deltree [.demoCA]*.*
42$ set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
43$ delete demoCA.dir;*,newcert.pem;*,newreq.pem;*
44$ set on
45$! #usage: CA -newcert|-newreq|-newca|-sign|-verify
46$
47$ exit
48$
49$ deltree: subroutine ! P1 is a name of a directory
50$ on control_y then goto dt_STOP
51$ on warning then goto dt_exit
52$ _dt_def = f$trnlnm("SYS$DISK")+f$directory()
53$ if f$parse(p1) .eqs. "" then exit
54$ set default 'f$parse(p1,,,"DEVICE")''f$parse(p1,,,"DIRECTORY")'
55$ p1 = f$parse(p1,,,"NAME") + f$parse(p1,,,"TYPE")
56$ _fp = f$parse(".DIR",p1)
57$ dt_loop:
58$ _f = f$search(_fp)
59$ if _f .eqs. "" then goto dt_loopend
60$ call deltree [.'f$parse(_f,,,"NAME")']*.*
61$ goto dt_loop
62$ dt_loopend:
63$ _fp = f$parse(p1,".;*")
64$ if f$search(_fp) .eqs. "" then goto dt_exit
65$ set noon
66$ set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) '_fp'
67$ set on
68$ delete/nolog '_fp'
69$ dt_exit:
70$ set default '_dt_def'
71$ exit
72$ dt_STOP:
73$ set default '_dt_def'
74$ stop/id=""
75$ exit
76$ endsubroutine
diff --git a/src/lib/libssl/src/test/testenc.com b/src/lib/libssl/src/test/testenc.com
new file mode 100644
index 0000000000..0756e8bada
--- /dev/null
+++ b/src/lib/libssl/src/test/testenc.com
@@ -0,0 +1,50 @@
1$! TESTENC.COM -- Test encoding and decoding
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ testsrc := makefile.ssl
8$ test := p.txt
9$ cmd := mcr 'exe_dir'openssl
10$
11$ copy 'testsrc' 'test'
12$
13$ write sys$output "cat"
14$ 'cmd' enc -in 'test' -out 'test'-cipher
15$ 'cmd' enc -in 'test'-cipher -out 'test'-clear
16$ difference/output=nl: 'test' 'test'-clear
17$ if $severity .ne. 1 then exit 3
18$ delete 'test'-cipher;*,'test'-clear;*
19$
20$ write sys$output "base64"
21$ 'cmd' enc -a -e -in 'test' -out 'test'-cipher
22$ 'cmd' enc -a -d -in 'test'-cipher -out 'test'-clear
23$ difference/output=nl: 'test' 'test'-clear
24$ if $severity .ne. 1 then exit 3
25$ delete 'test'-cipher;*,'test'-clear;*
26$
27$ define/user sys$output 'test'-cipher-commands
28$ 'cmd' list-cipher-commands
29$ open/read f 'test'-cipher-commands
30$ loop_cipher_commands:
31$ read/end=loop_cipher_commands_end f i
32$ write sys$output i
33$ 'cmd' 'i' -bufsize 113 -e -k test -in 'test' -out 'test'-'i'-cipher
34$ 'cmd' 'i' -bufsize 157 -d -k test -in 'test'-'i'-cipher -out 'test'-'i'-clear
35$ difference/output=nl: 'test' 'test'-'i'-clear
36$ if $severity .ne. 1 then exit 3
37$ delete 'test'-'i'-cipher;*,'test'-'i'-clear;*
38$
39$ write sys$output i," base64"
40$ 'cmd' 'i' -bufsize 113 -a -e -k test -in 'test' -out 'test'-'i'-cipher
41$ 'cmd' 'i' -bufsize 157 -a -d -k test -in 'test'-'i'-cipher -out 'test'-'i'-clear
42$ difference/output=nl: 'test' 'test'-'i'-clear
43$ if $severity .ne. 1 then exit 3
44$ delete 'test'-'i'-cipher;*,'test'-'i'-clear;*
45$
46$ goto loop_cipher_commands
47$ loop_cipher_commands_end:
48$ close f
49$ delete 'test'-cipher-commands;*
50$ delete 'test';*
diff --git a/src/lib/libssl/src/test/testgen.com b/src/lib/libssl/src/test/testgen.com
new file mode 100644
index 0000000000..ec302f524a
--- /dev/null
+++ b/src/lib/libssl/src/test/testgen.com
@@ -0,0 +1,35 @@
1$! TETSGEN.COM
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ T := testcert
8$ KEY = 512
9$ CA := [-.certs]testca.pem
10$
11$ set noon
12$ if f$search(T+".1;*") .nes. "" then delete 'T'.1;*
13$ if f$search(T+".2;*") .nes. "" then delete 'T'.2;*
14$ if f$search(T+".key;*") .nes. "" then delete 'T'.key;*
15$ set on
16$
17$ write sys$output "generating certificate request"
18$
19$ write sys$output "There should be a 2 sequences of .'s and some +'s."
20$ write sys$output "There should not be more that at most 80 per line"
21$ write sys$output "This could take some time."
22$
23$ mcr 'exe_dir'openssl req -config test.cnf -new -out testreq.pem
24$ if $severity .ne. 1
25$ then
26$ write sys$output "problems creating request"
27$ exit 3
28$ endif
29$
30$ mcr 'exe_dir'openssl req -verify -in testreq.pem -noout
31$ if $severity .ne. 1
32$ then
33$ write sys$output "signature on req is wrong"
34$ exit 3
35$ endif
diff --git a/src/lib/libssl/src/test/tests.com b/src/lib/libssl/src/test/tests.com
new file mode 100644
index 0000000000..147b8aa838
--- /dev/null
+++ b/src/lib/libssl/src/test/tests.com
@@ -0,0 +1,203 @@
1$! TESTS.COM -- Performs the necessary tests
2$!
3$! P1 tests to be performed. Empty means all.
4$
5$ __proc = f$element(0,";",f$environment("procedure"))
6$ __here = f$parse(f$parse("A.;",__proc) - "A.;","[]A.;") - "A.;"
7$ __save_default = f$environment("default")
8$ __arch := VAX
9$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
10$ texe_dir := sys$disk:[-.'__arch'.exe.test]
11$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
12$
13$ set default '__here'
14$ on control_y then goto exit
15$ on error then goto exit
16$
17$ if p1 .nes. ""
18$ then
19$ tests = p1
20$ else
21$ tests := -
22 test_des,test_idea,test_sha,test_md5,test_hmac,test_md2,test_mdc2,-
23 test_rc2,test_rc4,test_rc5,test_bf,test_cast,-
24 test_rand,test_bn,test_enc,test_x509,test_rsa,test_crl,test_sid,-
25 test_reqgen,test_req,test_pkcs7,test_verify,test_dh,test_dsa,-
26 test_ss,test_ssl,test_ca
27$ endif
28$ tests = f$edit(tests,"COLLAPSE")
29$
30$ BNTEST := bntest
31$ EXPTEST := exptest
32$ IDEATEST := ideatest
33$ SHATEST := shatest
34$ SHA1TEST := sha1test
35$ MDC2TEST := mdc2test
36$ RMDTEST := rmdtest
37$ MD2TEST := md2test
38$ MD5TEST := md5test
39$ HMACTEST := hmactest
40$ RC2TEST := rc2test
41$ RC4TEST := rc4test
42$ RC5TEST := rc5test
43$ BFTEST := bftest
44$ CASTTEST := casttest
45$ DESTEST := destest
46$ RANDTEST := randtest
47$ DHTEST := dhtest
48$ DSATEST := dsatest
49$ METHTEST := methtest
50$ SSLTEST := ssltest
51$ RSATEST := rsa_oaep_test
52$
53$ tests_i = 0
54$ loop_tests:
55$ tests_e = f$element(tests_i,",",tests)
56$ tests_i = tests_i + 1
57$ if tests_e .eqs. "," then goto exit
58$ goto 'tests_e'
59$
60$ test_des:
61$ mcr 'texe_dir''destest'
62$ goto loop_tests
63$ test_idea:
64$ mcr 'texe_dir''ideatest'
65$ goto loop_tests
66$ test_sha:
67$ mcr 'texe_dir''shatest'
68$ mcr 'texe_dir''sha1test'
69$ goto loop_tests
70$ test_mdc2:
71$ mcr 'texe_dir''mdc2test'
72$ goto loop_tests
73$ test_md5:
74$ mcr 'texe_dir''md5test'
75$ goto loop_tests
76$ test_hmac:
77$ mcr 'texe_dir''hmactest'
78$ goto loop_tests
79$ test_md2:
80$ mcr 'texe_dir''md2test'
81$ goto loop_tests
82$ test_rmd:
83$ mcr 'texe_dir''rmdtest'
84$ goto loop_tests
85$ test_bf:
86$ mcr 'texe_dir''bftest'
87$ goto loop_tests
88$ test_cast:
89$ mcr 'texe_dir''casttest'
90$ goto loop_tests
91$ test_rc2:
92$ mcr 'texe_dir''rc2test'
93$ goto loop_tests
94$ test_rc4:
95$ mcr 'texe_dir''rc4test'
96$ goto loop_tests
97$ test_rc5:
98$ mcr 'texe_dir''rc5test'
99$ goto loop_tests
100$ test_rand:
101$ mcr 'texe_dir''randtest'
102$ goto loop_tests
103$ test_enc:
104$ @testenc.com
105$ goto loop_tests
106$ test_x509:
107$ define sys$error nla0:
108$ write sys$output "test normal x509v1 certificate"
109$ @tx509.com
110$ write sys$output "test first x509v3 certificate"
111$ @tx509.com v3-cert1.pem
112$ write sys$output "test second x509v3 certificate"
113$ @tx509.com v3-cert2.pem
114$ deassign sys$error
115$ goto loop_tests
116$ test_rsa:
117$ define sys$error nla0:
118$ @trsa.com
119$ deassign sys$error
120$ mcr 'texe_dir''rsatest'
121$ goto loop_tests
122$ test_crl:
123$ define sys$error nla0:
124$ @tcrl.com
125$ deassign sys$error
126$ goto loop_tests
127$ test_sid:
128$ define sys$error nla0:
129$ @tsid.com
130$ deassign sys$error
131$ goto loop_tests
132$ test_req:
133$ define sys$error nla0:
134$ @treq.com
135$ @treq.com testreq2.pem
136$ deassign sys$error
137$ goto loop_tests
138$ test_pkcs7:
139$ define sys$error nla0:
140$ @tpkcs7.com
141$ @tpkcs7d.com
142$ deassign sys$error
143$ goto loop_tests
144$ test_bn:
145$ write sys$output "starting big number library test, could take a while..."
146$ create bntest-vms.fdl
147FILE
148 ORGANIZATION sequential
149RECORD
150 FORMAT stream_lf
151$ create/fdl=bntest-vms.fdl bntest-vms.sh
152$ open/append foo bntest-vms.sh
153$ type/output=foo: sys$input:
154<< __FOO__ bc | awk '{ \
155if ($$0 != "0") {print "error"; exit(1); } \
156if (((NR+1)%64) == 0) print NR+1," tests done"; }'
157$ define/user sys$output bntest-vms.tmp
158$ mcr 'texe_dir''bntest'
159$ copy bntest-vms.tmp foo:
160$ delete bntest-vms.tmp;*
161$ type/output=foo: sys$input:
162__FOO__
163$ close foo
164$ write sys$output "-- copy the [.test]bntest-vms.sh file to a Unix system and run it"
165$ write sys$output "-- through sh or bash to verify that the bignum operations went well."
166$ write sys$output ""
167$ write sys$output "test a^b%c implementations"
168$ mcr 'texe_dir''exptest'
169$ goto loop_tests
170$ test_verify:
171$ write sys$output "The following command should have some OK's and some failures"
172$ write sys$output "There are definitly a few expired certificates"
173$ @tverify.com
174$ goto loop_tests
175$ test_dh:
176$ write sys$output "Generate as set of DH parameters"
177$ mcr 'texe_dir''dhtest'
178$ goto loop_tests
179$ test_dsa:
180$ write sys$output "Generate as set of DSA parameters"
181$ mcr 'texe_dir''dsatest'
182$ goto loop_tests
183$ test_reqgen:
184$ write sys$output "Generate and verify a certificate request"
185$ @testgen.com
186$ goto loop_tests
187$ test_ss:
188$ write sys$output "Generate and certify a test certificate"
189$ @testss.com
190$ goto loop_tests
191$ test_ssl:
192$ write sys$output "test SSL protocol"
193$ @testssl.com
194$ goto loop_tests
195$ test_ca:
196$ write sys$output "Generate and certify a test certificate via the 'ca' program"
197$ @testca.com
198$ goto loop_tests
199$
200$
201$ exit:
202$ set default '__save_default'
203$ exit
diff --git a/src/lib/libssl/src/test/testss.com b/src/lib/libssl/src/test/testss.com
new file mode 100644
index 0000000000..ce2c4b43f6
--- /dev/null
+++ b/src/lib/libssl/src/test/testss.com
@@ -0,0 +1,105 @@
1$! TESTSS.COM
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ digest="-mdc2"
8$ reqcmd := mcr 'exe_dir'openssl req
9$ x509cmd := mcr 'exe_dir'openssl x509 'digest'
10$ verifycmd := mcr 'exe_dir'openssl verify
11$ dummycnf := sys$disk:[-.apps]openssl-vms.cnf
12$
13$ CAkey="""keyCA.ss"""
14$ CAcert="""certCA.ss"""
15$ CAreq="""reqCA.ss"""
16$ CAconf="""CAss.cnf"""
17$ CAreq2="""req2CA.ss""" ! temp
18$
19$ Uconf="""Uss.cnf"""
20$ Ukey="""keyU.ss"""
21$ Ureq="""reqU.ss"""
22$ Ucert="""certU.ss"""
23$
24$ write sys$output ""
25$ write sys$output "make a certificate request using 'req'"
26$ 'reqcmd' -config 'CAconf' -out 'CAreq' -keyout 'CAkey' -new ! -out err.ss
27$ if $severity .ne. 1
28$ then
29$ write sys$output "error using 'req' to generate a certificate request"
30$ exit 3
31$ endif
32$ write sys$output ""
33$ write sys$output "convert the certificate request into a self signed certificate using 'x509'"
34$ define /user sys$output err.ss
35$ 'x509cmd' "-CAcreateserial" -in 'CAreq' -days 30 -req -out 'CAcert' -signkey 'CAkey'
36$ if $severity .ne. 1
37$ then
38$ write sys$output "error using 'x509' to self sign a certificate request"
39$ exit 3
40$ endif
41$
42$ write sys$output ""
43$ write sys$output "convert a certificate into a certificate request using 'x509'"
44$ define /user sys$output err.ss
45$ 'x509cmd' -in 'CAcert' -x509toreq -signkey 'CAkey' -out 'CAreq2'
46$ if $severity .ne. 1
47$ then
48$ write sys$output "error using 'x509' convert a certificate to a certificate request"
49$ exit 3
50$ endif
51$
52$ 'reqcmd' -config 'dummycnf' -verify -in 'CAreq' -noout
53$ if $severity .ne. 1
54$ then
55$ write sys$output "first generated request is invalid"
56$ exit 3
57$ endif
58$
59$ 'reqcmd' -config 'dummycnf' -verify -in 'CAreq2' -noout
60$ if $severity .ne. 1
61$ then
62$ write sys$output "second generated request is invalid"
63$ exit 3
64$ endif
65$
66$ 'verifycmd' "-CAfile" 'CAcert' 'CAcert'
67$ if $severity .ne. 1
68$ then
69$ write sys$output "first generated cert is invalid"
70$ exit 3
71$ endif
72$
73$ write sys$output ""
74$ write sys$output "make another certificate request using 'req'"
75$ define /user sys$output err.ss
76$ 'reqcmd' -config 'Uconf' -out 'Ureq' -keyout 'Ukey' -new
77$ if $severity .ne. 1
78$ then
79$ write sys$output "error using 'req' to generate a certificate request"
80$ exit 3
81$ endif
82$
83$ write sys$output ""
84$ write sys$output "sign certificate request with the just created CA via 'x509'"
85$ define /user sys$output err.ss
86$ 'x509cmd' "-CAcreateserial" -in 'Ureq' -days 30 -req -out 'Ucert' "-CA" 'CAcert' "-CAkey" 'CAkey'
87$ if $severity .ne. 1
88$ then
89$ write sys$output "error using 'x509' to sign a certificate request"
90$ exit 3
91$ endif
92$
93$ 'verifycmd' "-CAfile" 'CAcert' 'Ucert'
94$ write sys$output ""
95$ write sys$output "Certificate details"
96$ 'x509cmd' -subject -issuer -startdate -enddate -noout -in 'Ucert'
97$
98$ write sys$output ""
99$ write sys$output "The generated CA certificate is ",CAcert
100$ write sys$output "The generated CA private key is ",CAkey
101$
102$ write sys$output "The generated user certificate is ",Ucert
103$ write sys$output "The generated user private key is ",Ukey
104$
105$ if f$search("err.ss;*") .nes. "" then delete err.ss;*
diff --git a/src/lib/libssl/src/test/testssl.com b/src/lib/libssl/src/test/testssl.com
new file mode 100644
index 0000000000..93a9aef802
--- /dev/null
+++ b/src/lib/libssl/src/test/testssl.com
@@ -0,0 +1,111 @@
1$! TESTSSL.COM
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.test]
6$
7$ copy/concatenate [-.certs]*.pem certs.tmp
8$
9$ write sys$output "test sslv2"
10$ mcr 'exe_dir'ssltest -ssl2
11$ if $severity .ne. 1 then goto exit3
12$
13$ write sys$output "test sslv2 with server authentication"
14$ mcr 'exe_dir'ssltest -ssl2 -server_auth "-CAfile" certs.tmp
15$ if $severity .ne. 1 then goto exit3
16$
17$ write sys$output "test sslv2 with client authentication"
18$ mcr 'exe_dir'ssltest -ssl2 -client_auth "-CAfile" certs.tmp
19$ if $severity .ne. 1 then goto exit3
20$
21$ write sys$output "test sslv2 with both client and server authentication"
22$ mcr 'exe_dir'ssltest -ssl2 -server_auth -client_auth "-CAfile" certs.tmp
23$ if $severity .ne. 1 then goto exit3
24$
25$ write sys$output "test sslv3"
26$ mcr 'exe_dir'ssltest -ssl3
27$ if $severity .ne. 1 then goto exit3
28$
29$ write sys$output "test sslv3 with server authentication"
30$ mcr 'exe_dir'ssltest -ssl3 -server_auth "-CAfile" certs.tmp
31$ if $severity .ne. 1 then goto exit3
32$
33$ write sys$output "test sslv3 with client authentication"
34$ mcr 'exe_dir'ssltest -ssl3 -client_auth "-CAfile" certs.tmp
35$ if $severity .ne. 1 then goto exit3
36$
37$ write sys$output "test sslv3 with both client and server authentication"
38$ mcr 'exe_dir'ssltest -ssl3 -server_auth -client_auth "-CAfile" certs.tmp
39$ if $severity .ne. 1 then goto exit3
40$
41$ write sys$output "test sslv2/sslv3"
42$ mcr 'exe_dir'ssltest
43$ if $severity .ne. 1 then goto exit3
44$
45$ write sys$output "test sslv2/sslv3 with server authentication"
46$ mcr 'exe_dir'ssltest -server_auth "-CAfile" certs.tmp
47$ if $severity .ne. 1 then goto exit3
48$
49$ write sys$output "test sslv2/sslv3 with client authentication"
50$ mcr 'exe_dir'ssltest -client_auth "-CAfile" certs.tmp
51$ if $severity .ne. 1 then goto exit3
52$
53$ write sys$output "test sslv2/sslv3 with both client and server authentication"
54$ mcr 'exe_dir'ssltest -server_auth -client_auth "-CAfile" certs.tmp
55$ if $severity .ne. 1 then goto exit3
56$
57$ write sys$output "test sslv2 via BIO pair"
58$ mcr 'exe_dir'ssltest -bio_pair -ssl2
59$ if $severity .ne. 1 then goto exit3
60$
61$ write sys$output "test sslv2 with server authentication via BIO pair"
62$ mcr 'exe_dir'ssltest -bio_pair -ssl2 -server_auth "-CAfile" certs.tmp
63$ if $severity .ne. 1 then goto exit3
64$
65$ write sys$output "test sslv2 with client authentication via BIO pair"
66$ mcr 'exe_dir'ssltest -bio_pair -ssl2 -client_auth "-CAfile" certs.tmp
67$ if $severity .ne. 1 then goto exit3
68$
69$ write sys$output "test sslv2 with both client and server authentication via BIO pair"
70$ mcr 'exe_dir'ssltest -bio_pair -ssl2 -server_auth -client_auth "-CAfile" certs.tmp
71$ if $severity .ne. 1 then goto exit3
72$
73$ write sys$output "test sslv3 via BIO pair"
74$ mcr 'exe_dir'ssltest -bio_pair -ssl3
75$ if $severity .ne. 1 then goto exit3
76$
77$ write sys$output "test sslv3 with server authentication via BIO pair"
78$ mcr 'exe_dir'ssltest -bio_pair -ssl3 -server_auth "-CAfile" certs.tmp
79$ if $severity .ne. 1 then goto exit3
80$
81$ write sys$output "test sslv3 with client authentication via BIO pair"
82$ mcr 'exe_dir'ssltest -bio_pair -ssl3 -client_auth "-CAfile" certs.tmp
83$ if $severity .ne. 1 then goto exit3
84
85$ write sys$output "test sslv3 with both client and server authentication via BIO pair"
86$ mcr 'exe_dir'ssltest -bio_pair -ssl3 -server_auth -client_auth "-CAfile" certs.tmp
87$ if $severity .ne. 1 then goto exit3
88$
89$ write sys$output "test sslv2/sslv3 via BIO pair"
90$ mcr 'exe_dir'ssltest
91$ if $severity .ne. 1 then goto exit3
92$
93$ write sys$output "test sslv2/sslv3 with server authentication"
94$ mcr 'exe_dir'ssltest -bio_pair -server_auth "-CAfile" certs.tmp
95$ if $severity .ne. 1 then goto exit3
96$
97$ write sys$output "test sslv2/sslv3 with client authentication via BIO pair"
98$ mcr 'exe_dir'ssltest -bio_pair -client_auth "-CAfile" certs.tmp
99$ if $severity .ne. 1 then goto exit3
100$
101$ write sys$output "test sslv2/sslv3 with both client and server authentication via BIO pair"
102$ mcr 'exe_dir'ssltest -bio_pair -server_auth -client_auth "-CAfile" certs.tmp
103$ if $severity .ne. 1 then goto exit3
104$
105$ RET = 1
106$ goto exit
107$ exit3:
108$ RET = 3
109$ exit:
110$ delete certs.tmp;*
111$ exit 'RET'
diff --git a/src/lib/libssl/src/test/tpkcs7.com b/src/lib/libssl/src/test/tpkcs7.com
new file mode 100644
index 0000000000..5ed920ac34
--- /dev/null
+++ b/src/lib/libssl/src/test/tpkcs7.com
@@ -0,0 +1,49 @@
1$! TPKCS7.COM -- Tests pkcs7 keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl pkcs7
8$
9$ t := testp7.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing PKCS7 conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$ write sys$output "p -> p"
19$ 'cmd' -in fff.p -inform p -outform p -out f.p
20$ if $severity .ne. 1 then exit 3
21$
22$ write sys$output "d -> d"
23$ 'cmd' -in f.d -inform d -outform d -out ff.d1
24$ if $severity .ne. 1 then exit 3
25$ write sys$output "p -> d"
26$ 'cmd' -in f.p -inform p -outform d -out ff.d3
27$ if $severity .ne. 1 then exit 3
28$
29$
30$ write sys$output "d -> p"
31$ 'cmd' -in f.d -inform d -outform p -out ff.p1
32$ if $severity .ne. 1 then exit 3
33$ write sys$output "p -> p"
34$ 'cmd' -in f.p -inform p -outform p -out ff.p3
35$ if $severity .ne. 1 then exit 3
36$
37$ difference/output=nl: fff.p f.p
38$ if $severity .ne. 1 then exit 3
39$ difference/output=nl: fff.p ff.p1
40$ if $severity .ne. 1 then exit 3
41$ difference/output=nl: fff.p ff.p3
42$ if $severity .ne. 1 then exit 3
43$
44$ difference/output=nl: f.p ff.p1
45$ if $severity .ne. 1 then exit 3
46$ difference/output=nl: f.p ff.p3
47$ if $severity .ne. 1 then exit 3
48$
49$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/tpkcs7d.com b/src/lib/libssl/src/test/tpkcs7d.com
new file mode 100644
index 0000000000..08d33eaa69
--- /dev/null
+++ b/src/lib/libssl/src/test/tpkcs7d.com
@@ -0,0 +1,42 @@
1$! TPKCS7.COM -- Tests pkcs7 keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl pkcs7
8$
9$ t := pkcs7-1.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing PKCS7 conversions (2)"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$ write sys$output "p -> p"
19$ 'cmd' -in fff.p -inform p -outform p -out f.p
20$ if $severity .ne. 1 then exit 3
21$
22$ write sys$output "d -> d"
23$ 'cmd' -in f.d -inform d -outform d -out ff.d1
24$ if $severity .ne. 1 then exit 3
25$ write sys$output "p -> d"
26$ 'cmd' -in f.p -inform p -outform d -out ff.d3
27$ if $severity .ne. 1 then exit 3
28$
29$
30$ write sys$output "d -> p"
31$ 'cmd' -in f.d -inform d -outform p -out ff.p1
32$ if $severity .ne. 1 then exit 3
33$ write sys$output "p -> p"
34$ 'cmd' -in f.p -inform p -outform p -out ff.p3
35$ if $severity .ne. 1 then exit 3
36$
37$ difference/output=nl: f.p ff.p1
38$ if $severity .ne. 1 then exit 3
39$ difference/output=nl: f.p ff.p3
40$ if $severity .ne. 1 then exit 3
41$
42$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/treq.com b/src/lib/libssl/src/test/treq.com
new file mode 100644
index 0000000000..9eb1d26f6e
--- /dev/null
+++ b/src/lib/libssl/src/test/treq.com
@@ -0,0 +1,78 @@
1$! TREQ.COM -- Tests req keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl req -config [-.apps]openssl-vms.cnf
8$
9$ t := testreq.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing req conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$! write sys$output "p -> t"
19$! 'cmd' -in fff.p -inform p -outform t -out f.t
20$! if $severity .ne. 1 then exit 3
21$ write sys$output "p -> p"
22$ 'cmd' -in fff.p -inform p -outform p -out f.p
23$ if $severity .ne. 1 then exit 3
24$
25$ write sys$output "d -> d"
26$ 'cmd' -verify -in f.d -inform d -outform d -out ff.d1
27$ if $severity .ne. 1 then exit 3
28$! write sys$output "t -> d"
29$! 'cmd' -verify -in f.t -inform t -outform d -out ff.d2
30$! if $severity .ne. 1 then exit 3
31$ write sys$output "p -> d"
32$ 'cmd' -verify -in f.p -inform p -outform d -out ff.d3
33$ if $severity .ne. 1 then exit 3
34$
35$! write sys$output "d -> t"
36$! 'cmd' -in f.d -inform d -outform t -out ff.t1
37$! if $severity .ne. 1 then exit 3
38$! write sys$output "t -> t"
39$! 'cmd' -in f.t -inform t -outform t -out ff.t2
40$! if $severity .ne. 1 then exit 3
41$! write sys$output "p -> t"
42$! 'cmd' -in f.p -inform p -outform t -out ff.t3
43$! if $severity .ne. 1 then exit 3
44$
45$ write sys$output "d -> p"
46$ 'cmd' -in f.d -inform d -outform p -out ff.p1
47$ if $severity .ne. 1 then exit 3
48$! write sys$output "t -> p"
49$! 'cmd' -in f.t -inform t -outform p -out ff.p2
50$! if $severity .ne. 1 then exit 3
51$ write sys$output "p -> p"
52$ 'cmd' -in f.p -inform p -outform p -out ff.p3
53$ if $severity .ne. 1 then exit 3
54$
55$ difference/output=nl: fff.p f.p
56$ if $severity .ne. 1 then exit 3
57$ difference/output=nl: fff.p ff.p1
58$ if $severity .ne. 1 then exit 3
59$! difference/output=nl: fff.p ff.p2
60$! if $severity .ne. 1 then exit 3
61$ difference/output=nl: fff.p ff.p3
62$ if $severity .ne. 1 then exit 3
63$
64$! difference/output=nl: f.t ff.t1
65$! if $severity .ne. 1 then exit 3
66$! difference/output=nl: f.t ff.t2
67$! if $severity .ne. 1 then exit 3
68$! difference/output=nl: f.t ff.t3
69$! if $severity .ne. 1 then exit 3
70$
71$ difference/output=nl: f.p ff.p1
72$ if $severity .ne. 1 then exit 3
73$! difference/output=nl: f.p ff.p2
74$! if $severity .ne. 1 then exit 3
75$ difference/output=nl: f.p ff.p3
76$ if $severity .ne. 1 then exit 3
77$
78$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/trsa.com b/src/lib/libssl/src/test/trsa.com
new file mode 100644
index 0000000000..9c9083d02b
--- /dev/null
+++ b/src/lib/libssl/src/test/trsa.com
@@ -0,0 +1,78 @@
1$! TRSA.COM -- Tests rsa keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl rsa
8$
9$ t := testrsa.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing RSA conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$! write sys$output "p -> t"
19$! 'cmd' -in fff.p -inform p -outform t -out f.t
20$! if $severity .ne. 1 then exit 3
21$ write sys$output "p -> p"
22$ 'cmd' -in fff.p -inform p -outform p -out f.p
23$ if $severity .ne. 1 then exit 3
24$
25$ write sys$output "d -> d"
26$ 'cmd' -in f.d -inform d -outform d -out ff.d1
27$ if $severity .ne. 1 then exit 3
28$! write sys$output "t -> d"
29$! 'cmd' -in f.t -inform t -outform d -out ff.d2
30$! if $severity .ne. 1 then exit 3
31$ write sys$output "p -> d"
32$ 'cmd' -in f.p -inform p -outform d -out ff.d3
33$ if $severity .ne. 1 then exit 3
34$
35$! write sys$output "d -> t"
36$! 'cmd' -in f.d -inform d -outform t -out ff.t1
37$! if $severity .ne. 1 then exit 3
38$! write sys$output "t -> t"
39$! 'cmd' -in f.t -inform t -outform t -out ff.t2
40$! if $severity .ne. 1 then exit 3
41$! write sys$output "p -> t"
42$! 'cmd' -in f.p -inform p -outform t -out ff.t3
43$! if $severity .ne. 1 then exit 3
44$
45$ write sys$output "d -> p"
46$ 'cmd' -in f.d -inform d -outform p -out ff.p1
47$ if $severity .ne. 1 then exit 3
48$! write sys$output "t -> p"
49$! 'cmd' -in f.t -inform t -outform p -out ff.p2
50$! if $severity .ne. 1 then exit 3
51$ write sys$output "p -> p"
52$ 'cmd' -in f.p -inform p -outform p -out ff.p3
53$ if $severity .ne. 1 then exit 3
54$
55$ difference/output=nl: fff.p f.p
56$ if $severity .ne. 1 then exit 3
57$ difference/output=nl: fff.p ff.p1
58$ if $severity .ne. 1 then exit 3
59$! difference/output=nl: fff.p ff.p2
60$! if $severity .ne. 1 then exit 3
61$ difference/output=nl: fff.p ff.p3
62$ if $severity .ne. 1 then exit 3
63$
64$! difference/output=nl: f.t ff.t1
65$! if $severity .ne. 1 then exit 3
66$! difference/output=nl: f.t ff.t2
67$! if $severity .ne. 1 then exit 3
68$! difference/output=nl: f.t ff.t3
69$! if $severity .ne. 1 then exit 3
70$
71$ difference/output=nl: f.p ff.p1
72$ if $severity .ne. 1 then exit 3
73$! difference/output=nl: f.p ff.p2
74$! if $severity .ne. 1 then exit 3
75$ difference/output=nl: f.p ff.p3
76$ if $severity .ne. 1 then exit 3
77$
78$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/tsid.com b/src/lib/libssl/src/test/tsid.com
new file mode 100644
index 0000000000..28d83e5c4e
--- /dev/null
+++ b/src/lib/libssl/src/test/tsid.com
@@ -0,0 +1,78 @@
1$! TSID.COM -- Tests sid keys
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl sess_id
8$
9$ t := testsid.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing session-id conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$! write sys$output "p -> t"
19$! 'cmd' -in fff.p -inform p -outform t -out f.t
20$! if $severity .ne. 1 then exit 3
21$ write sys$output "p -> p"
22$ 'cmd' -in fff.p -inform p -outform p -out f.p
23$ if $severity .ne. 1 then exit 3
24$
25$ write sys$output "d -> d"
26$ 'cmd' -in f.d -inform d -outform d -out ff.d1
27$ if $severity .ne. 1 then exit 3
28$! write sys$output "t -> d"
29$! 'cmd' -in f.t -inform t -outform d -out ff.d2
30$! if $severity .ne. 1 then exit 3
31$ write sys$output "p -> d"
32$ 'cmd' -in f.p -inform p -outform d -out ff.d3
33$ if $severity .ne. 1 then exit 3
34$
35$! write sys$output "d -> t"
36$! 'cmd' -in f.d -inform d -outform t -out ff.t1
37$! if $severity .ne. 1 then exit 3
38$! write sys$output "t -> t"
39$! 'cmd' -in f.t -inform t -outform t -out ff.t2
40$! if $severity .ne. 1 then exit 3
41$! write sys$output "p -> t"
42$! 'cmd' -in f.p -inform p -outform t -out ff.t3
43$! if $severity .ne. 1 then exit 3
44$
45$ write sys$output "d -> p"
46$ 'cmd' -in f.d -inform d -outform p -out ff.p1
47$ if $severity .ne. 1 then exit 3
48$! write sys$output "t -> p"
49$! 'cmd' -in f.t -inform t -outform p -out ff.p2
50$! if $severity .ne. 1 then exit 3
51$ write sys$output "p -> p"
52$ 'cmd' -in f.p -inform p -outform p -out ff.p3
53$ if $severity .ne. 1 then exit 3
54$
55$ difference/output=nl: fff.p f.p
56$ if $severity .ne. 1 then exit 3
57$ difference/output=nl: fff.p ff.p1
58$ if $severity .ne. 1 then exit 3
59$! difference/output=nl: fff.p ff.p2
60$! if $severity .ne. 1 then exit 3
61$ difference/output=nl: fff.p ff.p3
62$ if $severity .ne. 1 then exit 3
63$
64$! difference/output=nl: f.t ff.t1
65$! if $severity .ne. 1 then exit 3
66$! difference/output=nl: f.t ff.t2
67$! if $severity .ne. 1 then exit 3
68$! difference/output=nl: f.t ff.t3
69$! if $severity .ne. 1 then exit 3
70$
71$ difference/output=nl: f.p ff.p1
72$ if $severity .ne. 1 then exit 3
73$! difference/output=nl: f.p ff.p2
74$! if $severity .ne. 1 then exit 3
75$ difference/output=nl: f.p ff.p3
76$ if $severity .ne. 1 then exit 3
77$
78$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/test/tverify.com b/src/lib/libssl/src/test/tverify.com
new file mode 100644
index 0000000000..f97e71478f
--- /dev/null
+++ b/src/lib/libssl/src/test/tverify.com
@@ -0,0 +1,26 @@
1$! TVERIFY.COM
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ copy/concatenate [-.certs]*.pem certs.tmp
8$
9$ old_f :=
10$ loop_certs:
11$ c := NO
12$ certs :=
13$ loop_certs2:
14$ f = f$search("[-.certs]*.pem")
15$ if f .nes. "" .and. f .nes. old_f
16$ then
17$ certs = certs + " [-.certs]" + f$parse(f,,,"NAME") + ".pem"
18$ if f$length(certs) .lt. 180 then goto loop_certs2
19$ c := YES
20$ endif
21$ certs = certs - " "
22$
23$ mcr 'exe_dir'openssl verify "-CAfile" certs.tmp 'certs'
24$ if c then goto loop_certs
25$
26$ delete certs.tmp;*
diff --git a/src/lib/libssl/src/test/tx509.com b/src/lib/libssl/src/test/tx509.com
new file mode 100644
index 0000000000..bbcf0a384b
--- /dev/null
+++ b/src/lib/libssl/src/test/tx509.com
@@ -0,0 +1,78 @@
1$! TX509.COM -- Tests x509 certificates
2$
3$ __arch := VAX
4$ if f$getsyi("cpu") .ge. 128 then __arch := AXP
5$ exe_dir := sys$disk:[-.'__arch'.exe.apps]
6$
7$ cmd := mcr 'exe_dir'openssl x509
8$
9$ t := testx509.pem
10$ if p1 .nes. "" then t = p1
11$
12$ write sys$output "testing X509 conversions"
13$ copy 't' fff.p
14$
15$ write sys$output "p -> d"
16$ 'cmd' -in fff.p -inform p -outform d -out f.d
17$ if $severity .ne. 1 then exit 3
18$ write sys$output "p -> n"
19$ 'cmd' -in fff.p -inform p -outform n -out f.n
20$ if $severity .ne. 1 then exit 3
21$ write sys$output "p -> p"
22$ 'cmd' -in fff.p -inform p -outform p -out f.p
23$ if $severity .ne. 1 then exit 3
24$
25$ write sys$output "d -> d"
26$ 'cmd' -in f.d -inform d -outform d -out ff.d1
27$ if $severity .ne. 1 then exit 3
28$ write sys$output "n -> d"
29$ 'cmd' -in f.n -inform n -outform d -out ff.d2
30$ if $severity .ne. 1 then exit 3
31$ write sys$output "p -> d"
32$ 'cmd' -in f.p -inform p -outform d -out ff.d3
33$ if $severity .ne. 1 then exit 3
34$
35$ write sys$output "d -> n"
36$ 'cmd' -in f.d -inform d -outform n -out ff.n1
37$ if $severity .ne. 1 then exit 3
38$ write sys$output "n -> n"
39$ 'cmd' -in f.n -inform n -outform n -out ff.n2
40$ if $severity .ne. 1 then exit 3
41$ write sys$output "p -> n"
42$ 'cmd' -in f.p -inform p -outform n -out ff.n3
43$ if $severity .ne. 1 then exit 3
44$
45$ write sys$output "d -> p"
46$ 'cmd' -in f.d -inform d -outform p -out ff.p1
47$ if $severity .ne. 1 then exit 3
48$ write sys$output "n -> p"
49$ 'cmd' -in f.n -inform n -outform p -out ff.p2
50$ if $severity .ne. 1 then exit 3
51$ write sys$output "p -> p"
52$ 'cmd' -in f.p -inform p -outform p -out ff.p3
53$ if $severity .ne. 1 then exit 3
54$
55$ difference/output=nl: fff.p f.p
56$ if $severity .ne. 1 then exit 3
57$ difference/output=nl: fff.p ff.p1
58$ if $severity .ne. 1 then exit 3
59$ difference/output=nl: fff.p ff.p2
60$ if $severity .ne. 1 then exit 3
61$ difference/output=nl: fff.p ff.p3
62$ if $severity .ne. 1 then exit 3
63$
64$ difference/output=nl: f.n ff.n1
65$ if $severity .ne. 1 then exit 3
66$ difference/output=nl: f.n ff.n2
67$ if $severity .ne. 1 then exit 3
68$ difference/output=nl: f.n ff.n3
69$ if $severity .ne. 1 then exit 3
70$
71$ difference/output=nl: f.p ff.p1
72$ if $severity .ne. 1 then exit 3
73$ difference/output=nl: f.p ff.p2
74$ if $severity .ne. 1 then exit 3
75$ difference/output=nl: f.p ff.p3
76$ if $severity .ne. 1 then exit 3
77$
78$ delete f.*;*,ff.*;*,fff.*;*
diff --git a/src/lib/libssl/src/times/091/486-50.nt b/src/lib/libssl/src/times/091/486-50.nt
new file mode 100644
index 0000000000..84820d9c65
--- /dev/null
+++ b/src/lib/libssl/src/times/091/486-50.nt
@@ -0,0 +1,30 @@
1486-50 NT 4.0
2
3SSLeay 0.9.1a 06-Jul-1998
4built on Sat Jul 18 18:03:20 EST 1998
5options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
6C 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
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 28.77k 80.30k 108.50k 118.98k 122.47k
10mdc2 51.52k 54.06k 54.54k 54.65k 54.62k
11md5 304.39k 1565.04k 3061.54k 3996.10k 4240.10k
12hmac(md5) 119.53k 793.23k 2061.29k 3454.95k 4121.76k
13sha1 127.51k 596.93k 1055.54k 1313.84k 1413.18k
14rmd160 128.50k 572.49k 1001.03k 1248.01k 1323.63k
15rc4 1224.40k 1545.11k 1590.29k 1600.20k 1576.90k
16des cbc 448.19k 503.45k 512.30k 513.30k 508.23k
17des ede3 148.66k 162.48k 163.68k 163.94k 164.24k
18idea cbc 194.18k 211.10k 212.99k 213.18k 212.64k
19rc2 cbc 245.78k 271.01k 274.12k 274.38k 273.52k
20rc5-32/12 cbc 1252.48k 1625.20k 1700.03k 1711.12k 1677.18k
21blowfish cbc 725.16k 828.26k 850.01k 846.99k 833.79k
22cast cbc 643.30k 717.22k 739.48k 741.57k 735.33k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0904s 0.0104s 11.1 96.2
25rsa 1024 bits 0.5968s 0.0352s 1.7 28.4
26rsa 2048 bits 3.8860s 0.1017s 0.3 9.8
27 sign verify sign/s verify/s
28dsa 512 bits 0.1006s 0.1249s 9.9 8.0
29dsa 1024 bits 0.3306s 0.4093s 3.0 2.4
30dsa 2048 bits 0.9454s 1.1707s 1.1 0.9
diff --git a/src/lib/libssl/src/times/091/586-100.lnx b/src/lib/libssl/src/times/091/586-100.lnx
new file mode 100644
index 0000000000..92892a672d
--- /dev/null
+++ b/src/lib/libssl/src/times/091/586-100.lnx
@@ -0,0 +1,32 @@
1Pentium 100mhz, linux
2
3SSLeay 0.9.0a 14-Apr-1998
4built on Fri Apr 17 08:47:07 EST 1998
5options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
6C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 56.65k 153.88k 208.47k 229.03k 237.57k
10mdc2 189.59k 204.95k 206.93k 208.90k 209.56k
11md5 1019.48k 5882.41k 12085.42k 16376.49k 18295.47k
12hmac(md5) 415.86k 2887.85k 7891.29k 13894.66k 17446.23k
13sha1 540.68k 2791.96k 5289.30k 6813.01k 7432.87k
14rmd160 298.37k 1846.87k 3869.10k 5273.94k 5892.78k
15rc4 7870.87k 10438.10k 10857.13k 10729.47k 10788.86k
16des cbc 1960.60k 2226.37k 2241.88k 2054.83k 2181.80k
17des ede3 734.44k 739.69k 779.43k 750.25k 772.78k
18idea cbc 654.07k 711.00k 716.89k 718.51k 720.90k
19rc2 cbc 648.83k 701.91k 708.61k 708.95k 709.97k
20rc5-32/12 cbc 3504.71k 4054.76k 4131.41k 4105.56k 4134.23k
21blowfish cbc 3762.25k 4313.79k 4460.54k 4356.78k 4317.18k
22cast cbc 2755.01k 3038.91k 3076.44k 3027.63k 2998.27k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0195s 0.0019s 51.4 519.9
25rsa 1024 bits 0.1000s 0.0059s 10.0 168.2
26rsa 2048 bits 0.6406s 0.0209s 1.6 47.8
27rsa 4096 bits 4.6100s 0.0787s 0.2 12.7
28 sign verify sign/s verify/s
29dsa 512 bits 0.0188s 0.0360s 53.1 27.8
30dsa 1024 bits 0.0570s 0.1126s 17.5 8.9
31dsa 2048 bits 0.1990s 0.3954s 5.0 2.5
32
diff --git a/src/lib/libssl/src/times/091/68000.bsd b/src/lib/libssl/src/times/091/68000.bsd
new file mode 100644
index 0000000000..a3a14e8087
--- /dev/null
+++ b/src/lib/libssl/src/times/091/68000.bsd
@@ -0,0 +1,32 @@
1Motorolla 68020 20mhz, NetBSD
2
3SSLeay 0.9.0t 29-May-1998
4built on Fri Jun 5 12:42:23 EST 1998
5options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,16,long) idea(int) blowfish(idx)
6C flags:gcc -DTERMIOS -O3 -fomit-frame-pointer -Wall -DB_ENDIAN
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 2176.00 5994.67 8079.73 8845.18 9077.01
10mdc2 5730.67 6122.67 6167.66 6176.51 6174.87
11md5 29.10k 127.31k 209.66k 250.50k 263.99k
12hmac(md5) 12.33k 73.02k 160.17k 228.04k 261.15k
13sha1 11.27k 49.37k 84.31k 102.40k 109.23k
14rmd160 11.69k 48.62k 78.76k 93.15k 98.41k
15rc4 117.96k 148.94k 152.57k 153.09k 152.92k
16des cbc 27.13k 30.06k 30.38k 30.38k 30.53k
17des ede3 10.51k 10.94k 11.01k 11.01k 11.01k
18idea cbc 26.74k 29.23k 29.45k 29.60k 29.74k
19rc2 cbc 34.27k 39.39k 40.03k 40.07k 40.16k
20rc5-32/12 cbc 64.31k 83.18k 85.70k 86.70k 87.09k
21blowfish cbc 48.86k 59.18k 60.07k 60.42k 60.78k
22cast cbc 42.67k 50.01k 50.86k 51.20k 51.37k
23 sign verify sign/s verify/s
24rsa 512 bits 0.7738s 0.0774s 1.3 12.9
25rsa 1024 bits 4.3967s 0.2615s 0.2 3.8
26rsa 2048 bits 29.5200s 0.9664s 0.0 1.0
27 sign verify sign/s verify/s
28dsa 512 bits 0.7862s 0.9709s 1.3 1.0
29dsa 1024 bits 2.5375s 3.1625s 0.4 0.3
30dsa 2048 bits 9.2150s 11.8200s 0.1 0.1
31
32
diff --git a/src/lib/libssl/src/times/091/686-200.lnx b/src/lib/libssl/src/times/091/686-200.lnx
new file mode 100644
index 0000000000..bb857d48d0
--- /dev/null
+++ b/src/lib/libssl/src/times/091/686-200.lnx
@@ -0,0 +1,32 @@
1Pentium Pro 200mhz, linux
2
3SSLeay 0.9.0d 26-Apr-1998
4built on Sun Apr 26 10:25:33 EST 1998
5options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
6C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 130.58k 364.54k 499.24k 545.79k 561.66k
10mdc2 526.68k 579.72k 588.37k 588.80k 589.82k
11md5 1917.71k 11434.69k 22512.21k 29495.30k 32677.89k
12hmac(md5) 749.18k 5264.83k 14227.20k 25018.71k 31760.38k
13sha1 1343.83k 6436.29k 11702.78k 14664.70k 15829.67k
14rmd160 1038.05k 5138.77k 8985.51k 10985.13k 11799.21k
15rc4 14891.04k 21334.06k 22376.79k 22579.54k 22574.42k
16des cbc 4131.97k 4568.31k 4645.29k 4631.21k 4572.73k
17des ede3 1567.17k 1631.13k 1657.32k 1653.08k 1643.86k
18idea cbc 2427.23k 2671.21k 2716.67k 2723.84k 2733.40k
19rc2 cbc 1629.90k 1767.38k 1788.50k 1797.12k 1799.51k
20rc5-32/12 cbc 10290.55k 13161.60k 13744.55k 14011.73k 14123.01k
21blowfish cbc 5896.42k 6920.77k 7122.01k 7151.62k 7146.15k
22cast cbc 6037.71k 6935.19k 7101.35k 7145.81k 7116.12k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0070s 0.0007s 142.6 1502.9
25rsa 1024 bits 0.0340s 0.0019s 29.4 513.3
26rsa 2048 bits 0.2087s 0.0066s 4.8 151.3
27rsa 4096 bits 1.4700s 0.0242s 0.7 41.2
28 sign verify sign/s verify/s
29dsa 512 bits 0.0064s 0.0121s 156.1 82.9
30dsa 1024 bits 0.0184s 0.0363s 54.4 27.5
31dsa 2048 bits 0.0629s 0.1250s 15.9 8.0
32
diff --git a/src/lib/libssl/src/times/091/alpha064.osf b/src/lib/libssl/src/times/091/alpha064.osf
new file mode 100644
index 0000000000..a8e7fdfd61
--- /dev/null
+++ b/src/lib/libssl/src/times/091/alpha064.osf
@@ -0,0 +1,32 @@
1Alpha EV4.5 (21064) 275mhz, OSF1 V4.0
2SSLeay 0.9.0g 01-May-1998
3built on Mon May 4 17:26:09 CST 1998
4options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(idx)
5C flags:cc -tune host -O4 -readonly_strings
6The 'numbers' are in 1000s of bytes per second processed.
7type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
8md2 119.58k 327.48k 443.28k 480.09k 495.16k
9mdc2 436.67k 456.35k 465.42k 466.57k 469.01k
10md5 1459.34k 6566.46k 11111.91k 13375.30k 14072.60k
11hmac(md5) 597.90k 3595.45k 8180.88k 12099.49k 13884.46k
12sha1 707.01k 3253.09k 6131.73k 7798.23k 8439.67k
13rmd160 618.57k 2729.07k 4711.33k 5825.16k 6119.23k
14rc4 8796.43k 9393.62k 9548.88k 9378.77k 9472.57k
15des cbc 2165.97k 2514.90k 2586.27k 2572.93k 2639.08k
16des ede3 945.44k 1004.03k 1005.96k 1017.33k 1020.85k
17idea cbc 1498.81k 1629.11k 1637.28k 1625.50k 1641.11k
18rc2 cbc 1866.00k 2044.92k 2067.12k 2064.00k 2068.96k
19rc5-32/12 cbc 4366.97k 5521.32k 5687.50k 5729.16k 5736.96k
20blowfish cbc 3997.31k 4790.60k 4937.84k 4954.56k 5024.85k
21cast cbc 2900.19k 3673.30k 3803.73k 3823.93k 3890.25k
22 sign verify sign/s verify/s
23rsa 512 bits 0.0069s 0.0006s 144.2 1545.8
24rsa 1024 bits 0.0304s 0.0018s 32.9 552.6
25rsa 2048 bits 0.1887s 0.0062s 5.3 161.4
26rsa 4096 bits 1.3667s 0.0233s 0.7 42.9
27 sign verify sign/s verify/s
28dsa 512 bits 0.0067s 0.0123s 149.6 81.1
29dsa 1024 bits 0.0177s 0.0332s 56.6 30.1
30dsa 2048 bits 0.0590s 0.1162s 16.9 8.6
31
32
diff --git a/src/lib/libssl/src/times/091/alpha164.lnx b/src/lib/libssl/src/times/091/alpha164.lnx
new file mode 100644
index 0000000000..c994662698
--- /dev/null
+++ b/src/lib/libssl/src/times/091/alpha164.lnx
@@ -0,0 +1,32 @@
1Alpha EV5.6 (21164A) 533mhz, Linux 2.0.32
2
3SSLeay 0.9.0p 22-May-1998
4built on Sun May 27 14:23:38 GMT 2018
5options:bn(64,64) md2(int) rc4(ptr,int) des(idx,risc1,16,long) idea(int) blowfish(idx)
6C flags:gcc -O3
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 295.78k 825.34k 1116.42k 1225.10k 1262.65k
10mdc2 918.16k 1017.55k 1032.18k 1034.24k 1035.60k
11md5 3574.93k 15517.05k 25482.67k 30434.31k 32210.51k
12hmac(md5) 1261.54k 7757.15k 18025.46k 27081.21k 31653.27k
13sha1 2251.89k 10056.84k 16990.19k 20651.04k 21973.29k
14rmd160 1615.49k 7017.13k 11601.11k 13875.62k 14690.31k
15rc4 22435.16k 24476.40k 24349.95k 23042.36k 24581.53k
16des cbc 5198.38k 6559.04k 6775.43k 6827.87k 6875.82k
17des ede3 2257.73k 2602.18k 2645.60k 2657.12k 2670.59k
18idea cbc 3694.42k 4125.61k 4180.74k 4193.28k 4192.94k
19rc2 cbc 4642.47k 5323.85k 5415.42k 5435.86k 5434.03k
20rc5-32/12 cbc 9705.26k 13277.79k 13843.46k 13989.66k 13987.57k
21blowfish cbc 7861.28k 10852.34k 11447.98k 11616.97k 11667.54k
22cast cbc 6718.13k 8599.98k 8967.17k 9070.81k 9099.28k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0018s 0.0002s 555.9 6299.5
25rsa 1024 bits 0.0081s 0.0005s 123.3 2208.7
26rsa 2048 bits 0.0489s 0.0015s 20.4 648.5
27rsa 4096 bits 0.3402s 0.0057s 2.9 174.7
28 sign verify sign/s verify/s
29dsa 512 bits 0.0019s 0.0032s 529.0 310.2
30dsa 1024 bits 0.0047s 0.0086s 214.1 115.7
31dsa 2048 bits 0.0150s 0.0289s 66.7 34.6
32
diff --git a/src/lib/libssl/src/times/091/alpha164.osf b/src/lib/libssl/src/times/091/alpha164.osf
new file mode 100644
index 0000000000..df712c689f
--- /dev/null
+++ b/src/lib/libssl/src/times/091/alpha164.osf
@@ -0,0 +1,31 @@
1Alpha EV5.6 (21164A) 400mhz, OSF1 V4.0
2
3SSLeay 0.9.0 10-Apr-1998
4built on Sun Apr 19 07:54:37 EST 1998
5options:bn(64,64) md2(int) rc4(ptr,int) des(ptr,risc2,4,int) idea(int) blowfish(idx)
6C flags:cc -O4 -tune host -fast
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 276.30k 762.07k 1034.35k 1134.07k 1160.53k
10mdc2 814.99k 845.83k 849.09k 850.33k 849.24k
11md5 2468.43k 10945.27k 17963.48k 21430.89k 22544.38k
12hmac(md5) 1002.48k 6023.98k 13430.99k 19344.17k 22351.80k
13sha1 1984.93k 8882.47k 14856.47k 17878.70k 18955.10k
14rmd160 1286.96k 5595.52k 9167.00k 10957.74k 11582.30k
15rc4 15948.15k 16710.29k 16793.20k 17929.50k 18474.56k
16des cbc 3416.04k 4149.37k 4296.25k 4328.89k 4327.57k
17des ede3 1540.14k 1683.36k 1691.14k 1705.90k 1705.22k
18idea cbc 2795.87k 3192.93k 3238.13k 3238.17k 3256.66k
19rc2 cbc 3529.00k 4069.93k 4135.79k 4135.25k 4160.07k
20rc5-32/12 cbc 7212.35k 9849.71k 10260.91k 10423.38k 10439.99k
21blowfish cbc 6061.75k 8363.50k 8706.80k 8779.40k 8784.55k
22cast cbc 5401.75k 6433.31k 6638.18k 6662.40k 6702.80k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0022s 0.0002s 449.6 4916.2
25rsa 1024 bits 0.0105s 0.0006s 95.3 1661.2
26rsa 2048 bits 0.0637s 0.0020s 15.7 495.6
27rsa 4096 bits 0.4457s 0.0075s 2.2 132.7
28 sign verify sign/s verify/s
29dsa 512 bits 0.0028s 0.0048s 362.2 210.4
30dsa 1024 bits 0.0064s 0.0123s 155.2 81.6
31dsa 2048 bits 0.0201s 0.0394s 49.7 25.4
diff --git a/src/lib/libssl/src/times/091/mips-rel.pl b/src/lib/libssl/src/times/091/mips-rel.pl
new file mode 100644
index 0000000000..4b2509315a
--- /dev/null
+++ b/src/lib/libssl/src/times/091/mips-rel.pl
@@ -0,0 +1,21 @@
1#!/usr/local/bin/perl
2
3&doit(100,"Pentium 100 32",0.0195,0.1000,0.6406,4.6100); # pentium-100
4&doit(200,"PPro 200 32",0.0070,0.0340,0.2087,1.4700); # pentium-100
5&doit( 25,"R3000 25 32",0.0860,0.4825,3.2417,23.8833); # R3000-25
6&doit(200,"R4400 200 32",0.0137,0.0717,0.4730,3.4367); # R4400 32bit
7&doit(180,"R10000 180 32",0.0061,0.0311,0.1955,1.3871); # R10000 32bit
8&doit(180,"R10000 180 64",0.0034,0.0149,0.0880,0.5933); # R10000 64bit
9&doit(400,"DEC 21164 400 64",0.0022,0.0105,0.0637,0.4457); # R10000 64bit
10
11sub doit
12 {
13 local($mhz,$label,@data)=@_;
14
15 for ($i=0; $i <= $#data; $i++)
16 {
17 $data[$i]=1/$data[$i]*200/$mhz;
18 }
19 printf("%s %6.1f %6.1f %6.1f %6.1f\n",$label,@data);
20 }
21
diff --git a/src/lib/libssl/src/times/091/r10000.irx b/src/lib/libssl/src/times/091/r10000.irx
new file mode 100644
index 0000000000..237ee5d192
--- /dev/null
+++ b/src/lib/libssl/src/times/091/r10000.irx
@@ -0,0 +1,37 @@
1MIPS R10000 32kI+32kD 180mhz, IRIX 6.4
2
3Using crypto/bn/mips3.s
4
5This is built for n32, which is faster for all benchmarks than the n64
6compilation model
7
8SSLeay 0.9.0b 19-Apr-1998
9built on Sat Apr 25 12:43:14 EST 1998
10options:bn(64,64) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(ptr)
11C flags:cc -use_readonly_const -O2 -DTERMIOS -DB_ENDIAN
12The 'numbers' are in 1000s of bytes per second processed.
13type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
14md2 126.38k 349.38k 472.67k 517.01k 529.81k
15mdc2 501.64k 545.87k 551.80k 553.64k 554.41k
16md5 1825.77k 7623.64k 12630.47k 15111.74k 16012.09k
17hmac(md5) 780.81k 4472.86k 9667.22k 13802.67k 15777.89k
18sha1 1375.52k 6213.91k 11037.30k 13682.01k 14714.09k
19rmd160 856.72k 3454.40k 5598.33k 6689.94k 7073.48k
20rc4 11260.93k 13311.50k 13360.05k 13322.17k 13364.39k
21des cbc 2770.78k 3055.42k 3095.18k 3092.48k 3103.03k
22des ede3 1023.22k 1060.58k 1063.81k 1070.37k 1064.54k
23idea cbc 3029.09k 3334.30k 3375.29k 3375.65k 3380.64k
24rc2 cbc 2307.45k 2470.72k 2501.25k 2500.68k 2500.55k
25rc5-32/12 cbc 6770.91k 8629.89k 8909.58k 9009.64k 9044.95k
26blowfish cbc 4796.53k 5598.20k 5717.14k 5755.11k 5749.86k
27cast cbc 3986.20k 4426.17k 4465.04k 4476.84k 4475.08k
28 sign verify sign/s verify/s
29rsa 512 bits 0.0034s 0.0003s 296.1 3225.4
30rsa 1024 bits 0.0139s 0.0008s 71.8 1221.8
31rsa 2048 bits 0.0815s 0.0026s 12.3 380.3
32rsa 4096 bits 0.5656s 0.0096s 1.8 103.7
33 sign verify sign/s verify/s
34dsa 512 bits 0.0034s 0.0061s 290.8 164.9
35dsa 1024 bits 0.0084s 0.0161s 119.1 62.3
36dsa 2048 bits 0.0260s 0.0515s 38.5 19.4
37
diff --git a/src/lib/libssl/src/times/091/r3000.ult b/src/lib/libssl/src/times/091/r3000.ult
new file mode 100644
index 0000000000..ecd33908bb
--- /dev/null
+++ b/src/lib/libssl/src/times/091/r3000.ult
@@ -0,0 +1,32 @@
1MIPS R3000 64kI+64kD 25mhz, ultrix 4.3
2
3SSLeay 0.9.0b 19-Apr-1998
4built on Thu Apr 23 07:22:31 EST 1998
5options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(idx)
6C flags:cc -O2 -DL_ENDIAN -DNOPROTO -DNOCONST
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 14.63k 40.65k 54.70k 60.07k 61.78k
10mdc2 29.43k 37.27k 38.23k 38.57k 38.60k
11md5 140.04k 676.59k 1283.84k 1654.10k 1802.24k
12hmac(md5) 60.51k 378.90k 937.82k 1470.46k 1766.74k
13sha1 60.77k 296.79k 525.40k 649.90k 699.05k
14rmd160 48.82k 227.16k 417.19k 530.31k 572.05k
15rc4 904.76k 996.20k 1007.53k 1015.65k 1010.35k
16des cbc 178.87k 209.39k 213.42k 215.55k 214.53k
17des ede3 74.25k 79.30k 80.40k 80.21k 80.14k
18idea cbc 181.02k 209.37k 214.44k 214.36k 213.83k
19rc2 cbc 161.52k 184.98k 187.99k 188.76k 189.05k
20rc5-32/12 cbc 398.99k 582.91k 614.66k 626.07k 621.87k
21blowfish cbc 296.38k 387.69k 405.50k 412.57k 410.05k
22cast cbc 214.76k 260.63k 266.92k 268.63k 258.26k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0870s 0.0089s 11.5 112.4
25rsa 1024 bits 0.4881s 0.0295s 2.0 33.9
26rsa 2048 bits 3.2750s 0.1072s 0.3 9.3
27rsa 4096 bits 23.9833s 0.4093s 0.0 2.4
28 sign verify sign/s verify/s
29dsa 512 bits 0.0898s 0.1706s 11.1 5.9
30dsa 1024 bits 0.2847s 0.5565s 3.5 1.8
31dsa 2048 bits 1.0267s 2.0433s 1.0 0.5
32
diff --git a/src/lib/libssl/src/times/091/r4400.irx b/src/lib/libssl/src/times/091/r4400.irx
new file mode 100644
index 0000000000..9b96ca110a
--- /dev/null
+++ b/src/lib/libssl/src/times/091/r4400.irx
@@ -0,0 +1,32 @@
1R4400 16kI+16kD 200mhz, Irix 5.3
2
3SSLeay 0.9.0e 27-Apr-1998
4built on Sun Apr 26 07:26:05 PDT 1998
5options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(ptr)
6C flags:cc -O2 -use_readonly_const -DTERMIOS -DB_ENDIAN
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 79.80k 220.59k 298.01k 327.06k 338.60k
10mdc2 262.74k 285.30k 289.16k 288.36k 288.49k
11md5 930.35k 4167.13k 7167.91k 8678.23k 9235.86k
12hmac(md5) 399.44k 2367.57k 5370.74k 7884.28k 9076.98k
13sha1 550.96k 2488.17k 4342.76k 5362.50k 5745.40k
14rmd160 424.58k 1752.83k 2909.67k 3486.08k 3702.89k
15rc4 6687.79k 7834.63k 7962.61k 8035.65k 7915.28k
16des cbc 1544.20k 1725.94k 1748.35k 1758.17k 1745.61k
17des ede3 587.29k 637.75k 645.93k 643.17k 646.01k
18idea cbc 1575.52k 1719.75k 1732.41k 1736.69k 1740.11k
19rc2 cbc 1496.21k 1629.90k 1643.19k 1652.14k 1646.62k
20rc5-32/12 cbc 3452.48k 4276.47k 4390.74k 4405.25k 4400.12k
21blowfish cbc 2354.58k 3242.36k 3401.11k 3433.65k 3383.65k
22cast cbc 1942.22k 2152.28k 2187.51k 2185.67k 2177.20k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0130s 0.0014s 76.9 729.8
25rsa 1024 bits 0.0697s 0.0043s 14.4 233.9
26rsa 2048 bits 0.4664s 0.0156s 2.1 64.0
27rsa 4096 bits 3.4067s 0.0586s 0.3 17.1
28 sign verify sign/s verify/s
29dsa 512 bits 0.0140s 0.0261s 71.4 38.4
30dsa 1024 bits 0.0417s 0.0794s 24.0 12.6
31dsa 2048 bits 0.1478s 0.2929s 6.8 3.4
32
diff --git a/src/lib/libssl/src/times/x86/md4s.cpp b/src/lib/libssl/src/times/x86/md4s.cpp
new file mode 100644
index 0000000000..c0ec97fc9f
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/md4s.cpp
@@ -0,0 +1,78 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/md4.h>
36
37extern "C" {
38void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD4_CTX ctx;
45 unsigned long s1,s2,e1,e2;
46 unsigned char k[16];
47 unsigned long data[2];
48 unsigned char iv[8];
49 int i,num=0,numm;
50 int j=0;
51
52 if (argc >= 2)
53 num=atoi(argv[1]);
54
55 if (num == 0) num=16;
56 if (num > 250) num=16;
57 numm=num+2;
58 num*=64;
59 numm*=64;
60
61 for (j=0; j<6; j++)
62 {
63 for (i=0; i<10; i++) /**/
64 {
65 md4_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md4_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md4_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md4_block_x86(&ctx,buffer,num);
73 }
74 printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 }
77 }
78
diff --git a/src/lib/libssl/src/tools/c89.sh b/src/lib/libssl/src/tools/c89.sh
new file mode 100644
index 0000000000..b25c9fda2d
--- /dev/null
+++ b/src/lib/libssl/src/tools/c89.sh
@@ -0,0 +1,15 @@
1#!/bin/sh -k
2#
3# Re-order arguments so that -L comes first
4#
5opts=""
6lopts=""
7
8for arg in $* ; do
9 case $arg in
10 -L*) lopts="$lopts $arg" ;;
11 *) opts="$opts $arg" ;;
12 esac
13done
14
15c89 $lopts $opts
diff --git a/src/lib/libssl/src/tools/c_rehash.in b/src/lib/libssl/src/tools/c_rehash.in
new file mode 100644
index 0000000000..cc3b65871f
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_rehash.in
@@ -0,0 +1,61 @@
1#!/bin/sh
2#
3# redo the hashes for the certificates in your cert path or the ones passed
4# on the command line.
5#
6
7if [ "$OPENSSL"x = "x" -o ! -x "$OPENSSL" ]; then
8 OPENSSL='openssl'
9 export OPENSSL
10fi
11DIR=/usr/local/ssl
12PATH=$DIR/bin:$PATH
13
14if [ ! -f "$OPENSSL" ]; then
15 found=0
16 for dir in . `echo $PATH | sed -e 's/:/ /g'`; do
17 if [ -f "$dir/$OPENSSL" ]; then
18 found=1
19 break
20 fi
21 done
22 if [ $found = 0 ]; then
23 echo "c_rehash: rehashing skipped ('openssl' program not available)" 1>&2
24 exit 0
25 fi
26fi
27
28SSL_DIR=$DIR/certs
29
30if [ "$*" = "" ]; then
31 CERTS=${*:-${SSL_CERT_DIR:-$SSL_DIR}}
32else
33 CERTS=$*
34fi
35
36IFS=': '
37for i in $CERTS
38do
39 (
40 IFS=' '
41 if [ -d $i -a -w $i ]; then
42 cd $i
43 echo "Doing $i"
44 for i in *.pem
45 do
46 if [ $i != '*.pem' ]; then
47 h=`$OPENSSL x509 -hash -noout -in $i`
48 if [ "x$h" = "x" ]; then
49 echo $i does not contain a certificate
50 else
51 if [ -f $h.0 ]; then
52 /bin/rm -f $h.0
53 fi
54 echo "$i => $h.0"
55 ln -s $i $h.0
56 fi
57 fi
58 done
59 fi
60 )
61done
diff --git a/src/lib/libssl/src/util/clean-depend.pl b/src/lib/libssl/src/util/clean-depend.pl
new file mode 100644
index 0000000000..af676af751
--- /dev/null
+++ b/src/lib/libssl/src/util/clean-depend.pl
@@ -0,0 +1,38 @@
1#!/usr/local/bin/perl -w
2# Clean the dependency list in a makefile of standard includes...
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5use strict;
6
7while(<STDIN>) {
8 print;
9 last if /^# DO NOT DELETE THIS LINE/;
10}
11
12my %files;
13
14while(<STDIN>) {
15 my ($file,$deps)=/^(.*): (.*)$/;
16 next if !defined $deps;
17 my @deps=split ' ',$deps;
18 @deps=grep(!/^\/usr\/include/,@deps);
19 @deps=grep(!/^\/usr\/lib\/gcc-lib/,@deps);
20 push @{$files{$file}},@deps;
21}
22
23my $file;
24foreach $file (sort keys %files) {
25 my $len=0;
26 my $dep;
27 foreach $dep (sort @{$files{$file}}) {
28 $len=0 if $len+length($dep)+1 >= 80;
29 if($len == 0) {
30 print "\n$file:";
31 $len=length($file)+1;
32 }
33 print " $dep";
34 $len+=length($dep)+1;
35 }
36}
37
38print "\n";
diff --git a/src/lib/libssl/src/util/cygwin.sh b/src/lib/libssl/src/util/cygwin.sh
new file mode 100644
index 0000000000..b607399b02
--- /dev/null
+++ b/src/lib/libssl/src/util/cygwin.sh
@@ -0,0 +1,125 @@
1#!/bin/bash
2#
3# This script configures, builds and packs the binary package for
4# the Cygwin net distribution version of OpenSSL
5#
6
7# Uncomment when debugging
8#set -x
9
10CONFIG_OPTIONS="--prefix=/usr shared no-idea no-rc5 no-mdc2"
11INSTALL_PREFIX=/tmp/install
12
13VERSION=
14SUBVERSION=$1
15
16function cleanup()
17{
18 rm -rf ${INSTALL_PREFIX}/etc
19 rm -rf ${INSTALL_PREFIX}/usr
20}
21
22function get_openssl_version()
23{
24 eval `grep '^VERSION=' Makefile.ssl`
25 if [ -z "${VERSION}" ]
26 then
27 echo "Error: Couldn't retrieve OpenSSL version from Makefile.ssl."
28 echo " Check value of variable VERSION in Makefile.ssl."
29 exit 1
30 fi
31}
32
33function base_install()
34{
35 mkdir -p ${INSTALL_PREFIX}
36 cleanup
37 make install INSTALL_PREFIX="${INSTALL_PREFIX}"
38}
39
40function doc_install()
41{
42 DOC_DIR=${INSTALL_PREFIX}/usr/doc/openssl
43
44 mkdir -p ${DOC_DIR}
45 cp CHANGES CHANGES.SSLeay INSTALL LICENSE NEWS README ${DOC_DIR}
46
47 create_cygwin_readme
48}
49
50function create_cygwin_readme()
51{
52 README_DIR=${INSTALL_PREFIX}/usr/doc/Cygwin
53 README_FILE=${README_DIR}/openssl-${VERSION}.README
54
55 mkdir -p ${README_DIR}
56 cat > ${README_FILE} <<- EOF
57 The Cygwin version has been built using the following configure:
58
59 ./config ${CONFIG_OPTIONS}
60
61 The IDEA, RC5 and MDC2 algorithms are disabled due to patent and/or
62 licensing issues.
63 EOF
64}
65
66function create_profile_files()
67{
68 PROFILE_DIR=${INSTALL_PREFIX}/etc/profile.d
69
70 mkdir -p $PROFILE_DIR
71 cat > ${PROFILE_DIR}/openssl.sh <<- "EOF"
72 export MANPATH="${MANPATH}:/usr/ssl/man"
73 EOF
74 cat > ${PROFILE_DIR}/openssl.csh <<- "EOF"
75 if ( $?MANPATH ) then
76 setenv MANPATH "${MANPATH}:/usr/ssl/man"
77 else
78 setenv MANPATH ":/usr/ssl/man"
79 endif
80 EOF
81}
82
83if [ -z "${SUBVERSION}" ]
84then
85 echo "Usage: $0 subversion"
86 exit 1
87fi
88
89if [ ! -f config ]
90then
91 echo "You must start this script in the OpenSSL toplevel source dir."
92 exit 1
93fi
94
95./config ${CONFIG_OPTIONS}
96
97get_openssl_version
98
99make || exit 1
100
101base_install
102
103doc_install
104
105create_cygwin_readme
106
107create_profile_files
108
109cd ${INSTALL_PREFIX}
110strip usr/bin/*.exe usr/bin/*.dll
111
112# Runtime package
113find etc usr/bin usr/doc usr/ssl/certs usr/ssl/man/man[157] usr/ssl/misc \
114 usr/ssl/openssl.cnf usr/ssl/private -empty -o \! -type d |
115tar cjfT openssl-${VERSION}-${SUBVERSION}.tar.bz2 -
116# Development package
117find usr/include usr/lib usr/ssl/man/man3 -empty -o \! -type d |
118tar cjfT openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2 -
119
120ls -l openssl-${VERSION}-${SUBVERSION}.tar.bz2
121ls -l openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2
122
123cleanup
124
125exit 0
diff --git a/src/lib/libssl/src/util/domd b/src/lib/libssl/src/util/domd
new file mode 100644
index 0000000000..324051f60b
--- /dev/null
+++ b/src/lib/libssl/src/util/domd
@@ -0,0 +1,11 @@
1#!/bin/sh
2# Do a makedepend, only leave out the standard headers
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5TOP=$1
6shift
7
8cp Makefile.ssl Makefile.save
9makedepend -f Makefile.ssl $@
10$TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new
11mv Makefile.new Makefile.ssl
diff --git a/src/lib/libssl/src/util/mkdir-p.pl b/src/lib/libssl/src/util/mkdir-p.pl
new file mode 100644
index 0000000000..6c69c2daa4
--- /dev/null
+++ b/src/lib/libssl/src/util/mkdir-p.pl
@@ -0,0 +1,33 @@
1#!/usr/local/bin/perl
2
3# mkdir-p.pl
4
5# On some systems, the -p option to mkdir (= also create any missing parent
6# directories) is not available.
7
8my $arg;
9
10foreach $arg (@ARGV) {
11 &do_mkdir_p($arg);
12}
13
14
15sub do_mkdir_p {
16 local($dir) = @_;
17
18 $dir =~ s|/*\Z(?!\n)||s;
19
20 if (-d $dir) {
21 return;
22 }
23
24 if ($dir =~ m|[^/]/|s) {
25 local($parent) = $dir;
26 $parent =~ s|[^/]*\Z(?!\n)||s;
27
28 do_mkdir_p($parent);
29 }
30
31 mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
32 print "created directory `$dir'\n";
33}
diff --git a/src/lib/libssl/src/util/mkerr.pl b/src/lib/libssl/src/util/mkerr.pl
new file mode 100644
index 0000000000..4b3bccb13e
--- /dev/null
+++ b/src/lib/libssl/src/util/mkerr.pl
@@ -0,0 +1,503 @@
1#!/usr/local/bin/perl -w
2
3my $config = "crypto/err/openssl.ec";
4my $debug = 0;
5my $rebuild = 0;
6my $static = 1;
7my $recurse = 0;
8my $reindex = 0;
9my $dowrite = 0;
10
11
12while (@ARGV) {
13 my $arg = $ARGV[0];
14 if($arg eq "-conf") {
15 shift @ARGV;
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
18 $debug = 1;
19 shift @ARGV;
20 } elsif($arg eq "-rebuild") {
21 $rebuild = 1;
22 shift @ARGV;
23 } elsif($arg eq "-recurse") {
24 $recurse = 1;
25 shift @ARGV;
26 } elsif($arg eq "-reindex") {
27 $reindex = 1;
28 shift @ARGV;
29 } elsif($arg eq "-nostatic") {
30 $static = 0;
31 shift @ARGV;
32 } elsif($arg eq "-write") {
33 $dowrite = 1;
34 shift @ARGV;
35 } else {
36 last;
37 }
38}
39
40if($recurse) {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
42} else {
43 @source = @ARGV;
44}
45
46# Read in the config file
47
48open(IN, "<$config") || die "Can't open config file $config";
49
50# Parse config file
51
52while(<IN>)
53{
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
55 $hinc{$1} = $2;
56 $cskip{$3} = $1;
57 if($3 ne "NONE") {
58 $csrc{$1} = $3;
59 $fmax{$1} = 99;
60 $rmax{$1} = 99;
61 $fnew{$1} = 0;
62 $rnew{$1} = 0;
63 }
64 } elsif (/^F\s+(\S+)/) {
65 # Add extra function with $1
66 } elsif (/^R\s+(\S+)\s+(\S+)/) {
67 $rextra{$1} = $2;
68 $rcodes{$1} = $2;
69 }
70}
71
72close IN;
73
74# Scan each header file in turn and make a list of error codes
75# and function names
76
77while (($lib, $hdr) = each %hinc)
78{
79 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
82 my $line = "", $def= "";
83 while(<IN>) {
84 last if(/BEGIN\s+ERROR\s+CODES/);
85 if ($line ne '') {
86 $_ = $line . $_;
87 $line = '';
88 }
89
90 if (/\\$/) {
91 $line = $_;
92 next;
93 }
94
95 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
96 if ($cpp) {
97 $cpp = 0 if /^#.*endif/;
98 next;
99 }
100
101 next if (/^#/); # skip preprocessor directives
102
103 s/\/\*.*?\*\///gs; # ignore comments
104 s/{[^{}]*}//gs; # ignore {} blocks
105
106 if (/{|\/\*/) { # Add a } so editor works...
107 $line = $_;
108 } else {
109 $def .= $_;
110 }
111 }
112
113 foreach (split /;/, $def) {
114 s/^[\n\s]*//g;
115 s/[\n\s]*$//g;
116 next if(/typedef\W/);
117 if (/\(\*(\w*)\([^\)]+/) {
118 my $name = $1;
119 $name =~ tr/[a-z]/[A-Z]/;
120 $ftrans{$name} = $1;
121 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
122 # K&R C
123 next ;
124 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
125 while (not /\(\)$/s) {
126 s/[^\(\)]*\)$/\)/s;
127 s/\([^\(\)]*\)\)$/\)/s;
128 }
129 s/\(void\)//;
130 /(\w+)\W*\(\)/s;
131 my $name = $1;
132 $name =~ tr/[a-z]/[A-Z]/;
133 $ftrans{$name} = $1;
134 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
135 print STDERR "Header $hdr: cannot parse: $_;\n";
136 }
137 }
138
139 next if $reindex;
140
141 # Scan function and reason codes and store them: keep a note of the
142 # maximum code used.
143
144 while(<IN>) {
145 if(/^#define\s+(\S+)\s+(\S+)/) {
146 $name = $1;
147 $code = $2;
148 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
149 print STDERR "Invalid error code $name\n";
150 next;
151 }
152 if($1 eq "R") {
153 $rcodes{$name} = $code;
154 if(!(exists $rextra{$name}) &&
155 ($code > $rmax{$lib}) ) {
156 $rmax{$lib} = $code;
157 }
158 } else {
159 if($code > $fmax{$lib}) {
160 $fmax{$lib} = $code;
161 }
162 $fcodes{$name} = $code;
163 }
164 }
165 }
166 close IN;
167}
168
169# Scan each C source file and look for function and reason codes
170# This is done by looking for strings that "look like" function or
171# reason codes: basically anything consisting of all upper case and
172# numerics which has _F_ or _R_ in it and which has the name of an
173# error library at the start. This seems to work fine except for the
174# oddly named structure BIO_F_CTX which needs to be ignored.
175# If a code doesn't exist in list compiled from headers then mark it
176# with the value "X" as a place holder to give it a value later.
177# Store all function and reason codes found in %ufcodes and %urcodes
178# so all those unreferenced can be printed out.
179
180
181foreach $file (@source) {
182 # Don't parse the error source file.
183 next if exists $cskip{$file};
184 open(IN, "<$file") || die "Can't open source file $file\n";
185 while(<IN>) {
186 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
187 next unless exists $csrc{$2};
188 next if($1 eq "BIO_F_BUFFER_CTX");
189 $ufcodes{$1} = 1;
190 if(!exists $fcodes{$1}) {
191 $fcodes{$1} = "X";
192 $fnew{$2}++;
193 }
194 $notrans{$1} = 1 unless exists $ftrans{$3};
195 }
196 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
197 next unless exists $csrc{$2};
198 $urcodes{$1} = 1;
199 if(!exists $rcodes{$1}) {
200 $rcodes{$1} = "X";
201 $rnew{$2}++;
202 }
203 }
204 }
205 close IN;
206}
207
208# Now process each library in turn.
209
210foreach $lib (keys %csrc)
211{
212 my $hfile = $hinc{$lib};
213 my $cfile = $csrc{$lib};
214 if(!$fnew{$lib} && !$rnew{$lib}) {
215 print STDERR "$lib:\t\tNo new error codes\n";
216 next unless $rebuild;
217 } else {
218 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
219 print STDERR " $rnew{$lib} New Reasons.\n";
220 next unless $dowrite;
221 }
222
223 # If we get here then we have some new error codes so we
224 # need to rebuild the header file and C file.
225
226 # Make a sorted list of error and reason codes for later use.
227
228 my @function = sort grep(/^${lib}_/,keys %fcodes);
229 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
230
231 # Rewrite the header file
232
233 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
234
235 # Copy across the old file
236 while(<IN>) {
237 push @out, $_;
238 last if (/BEGIN ERROR CODES/);
239 }
240 close IN;
241
242 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
243
244 print OUT @out;
245 undef @out;
246 print OUT <<"EOF";
247/* The following lines are auto generated by the script mkerr.pl. Any changes
248 * made after this point may be overwritten when the script is next run.
249 */
250
251/* Error codes for the $lib functions. */
252
253/* Function codes. */
254EOF
255
256 foreach $i (@function) {
257 $z=6-int(length($i)/8);
258 if($fcodes{$i} eq "X") {
259 $fcodes{$i} = ++$fmax{$lib};
260 print STDERR "New Function code $i\n" if $debug;
261 }
262 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
263 }
264
265 print OUT "\n/* Reason codes. */\n";
266
267 foreach $i (@reasons) {
268 $z=6-int(length($i)/8);
269 if($rcodes{$i} eq "X") {
270 $rcodes{$i} = ++$rmax{$lib};
271 print STDERR "New Reason code $i\n" if $debug;
272 }
273 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
274 }
275 print OUT <<"EOF";
276
277#ifdef __cplusplus
278}
279#endif
280#endif
281
282EOF
283 close OUT;
284
285 # Rewrite the C source file containing the error details.
286
287 my $hincf;
288 if($static) {
289 $hfile =~ /([^\/]+)$/;
290 $hincf = "<openssl/$1>";
291 } else {
292 $hincf = "\"$hfile\"";
293 }
294
295
296 open (OUT,">$cfile") || die "Can't open $cfile for writing";
297
298 print OUT <<"EOF";
299/* $cfile */
300/* ====================================================================
301 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
302 *
303 * Redistribution and use in source and binary forms, with or without
304 * modification, are permitted provided that the following conditions
305 * are met:
306 *
307 * 1. Redistributions of source code must retain the above copyright
308 * notice, this list of conditions and the following disclaimer.
309 *
310 * 2. Redistributions in binary form must reproduce the above copyright
311 * notice, this list of conditions and the following disclaimer in
312 * the documentation and/or other materials provided with the
313 * distribution.
314 *
315 * 3. All advertising materials mentioning features or use of this
316 * software must display the following acknowledgment:
317 * "This product includes software developed by the OpenSSL Project
318 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
319 *
320 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
321 * endorse or promote products derived from this software without
322 * prior written permission. For written permission, please contact
323 * openssl-core\@OpenSSL.org.
324 *
325 * 5. Products derived from this software may not be called "OpenSSL"
326 * nor may "OpenSSL" appear in their names without prior written
327 * permission of the OpenSSL Project.
328 *
329 * 6. Redistributions of any form whatsoever must retain the following
330 * acknowledgment:
331 * "This product includes software developed by the OpenSSL Project
332 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
333 *
334 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
335 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
336 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
337 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
338 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
339 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
340 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
341 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
342 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
343 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
344 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
345 * OF THE POSSIBILITY OF SUCH DAMAGE.
346 * ====================================================================
347 *
348 * This product includes cryptographic software written by Eric Young
349 * (eay\@cryptsoft.com). This product includes software written by Tim
350 * Hudson (tjh\@cryptsoft.com).
351 *
352 */
353
354/* NOTE: this file was auto generated by the mkerr.pl script: any changes
355 * made to it will be overwritten when the script next updates this file.
356 */
357
358#include <stdio.h>
359#include <openssl/err.h>
360#include $hincf
361
362/* BEGIN ERROR CODES */
363#ifndef NO_ERR
364static ERR_STRING_DATA ${lib}_str_functs[]=
365 {
366EOF
367 # Add each function code: if a function name is found then use it.
368 foreach $i (@function) {
369 my $fn;
370 $i =~ /^${lib}_F_(\S+)$/;
371 $fn = $1;
372 if(exists $ftrans{$fn}) {
373 $fn = $ftrans{$fn};
374 }
375 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
376 }
377 print OUT <<"EOF";
378{0,NULL}
379 };
380
381static ERR_STRING_DATA ${lib}_str_reasons[]=
382 {
383EOF
384 # Add each reason code.
385 foreach $i (@reasons) {
386 my $rn;
387 my $nspc = 0;
388 $i =~ /^${lib}_R_(\S+)$/;
389 $rn = $1;
390 $rn =~ tr/_[A-Z]/ [a-z]/;
391 $nspc = 40 - length($i) unless length($i) > 40;
392 $nspc = " " x $nspc;
393 print OUT "{${i}${nspc},\"$rn\"},\n";
394 }
395if($static) {
396 print OUT <<"EOF";
397{0,NULL}
398 };
399
400#endif
401
402void ERR_load_${lib}_strings(void)
403 {
404 static int init=1;
405
406 if (init)
407 {
408 init=0;
409#ifndef NO_ERR
410 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
411 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
412#endif
413
414 }
415 }
416EOF
417} else {
418 print OUT <<"EOF";
419{0,NULL}
420 };
421
422#endif
423
424#ifdef ${lib}_LIB_NAME
425static ERR_STRING_DATA ${lib}_lib_name[]=
426 {
427{0 ,${lib}_LIB_NAME},
428{0,NULL}
429 };
430#endif
431
432
433int ${lib}_lib_error_code=0;
434
435void ERR_load_${lib}_strings(void)
436 {
437 static int init=1;
438
439 if (${lib}_lib_error_code == 0)
440 ${lib}_lib_error_code=ERR_get_next_error_library();
441
442 if (init)
443 {
444 init=0;
445#ifndef NO_ERR
446 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
447 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
448#endif
449
450#ifdef ${lib}_LIB_NAME
451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
452 ERR_load_strings(0,${lib}_lib_name);
453#endif;
454 }
455 }
456
457void ERR_${lib}_error(int function, int reason, char *file, int line)
458 {
459 if (${lib}_lib_error_code == 0)
460 ${lib}_lib_error_code=ERR_get_next_error_library();
461 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
462 }
463EOF
464
465}
466
467 close OUT;
468
469}
470
471if($debug && defined(%notrans)) {
472 print STDERR "The following function codes were not translated:\n";
473 foreach(sort keys %notrans)
474 {
475 print STDERR "$_\n";
476 }
477}
478
479# Make a list of unreferenced function and reason codes
480
481foreach (keys %fcodes) {
482 push (@funref, $_) unless exists $ufcodes{$_};
483}
484
485foreach (keys %rcodes) {
486 push (@runref, $_) unless exists $urcodes{$_};
487}
488
489if($debug && defined(@funref) ) {
490 print STDERR "The following function codes were not referenced:\n";
491 foreach(sort @funref)
492 {
493 print STDERR "$_\n";
494 }
495}
496
497if($debug && defined(@runref) ) {
498 print STDERR "The following reason codes were not referenced:\n";
499 foreach(sort @runref)
500 {
501 print STDERR "$_\n";
502 }
503}
diff --git a/src/lib/libssl/src/util/mkfiles.pl b/src/lib/libssl/src/util/mkfiles.pl
new file mode 100644
index 0000000000..6fa424bd19
--- /dev/null
+++ b/src/lib/libssl/src/util/mkfiles.pl
@@ -0,0 +1,110 @@
1#!/usr/local/bin/perl
2#
3# This is a hacked version of files.pl for systems that can't do a 'make files'.
4# Do a perl util/mkminfo.pl >MINFO to build MINFO
5# Written by Steve Henson 1999.
6
7# List of directories to process
8
9my @dirs = (
10".",
11"crypto",
12"crypto/md2",
13"crypto/md5",
14"crypto/sha",
15"crypto/mdc2",
16"crypto/hmac",
17"crypto/ripemd",
18"crypto/des",
19"crypto/rc2",
20"crypto/rc4",
21"crypto/rc5",
22"crypto/idea",
23"crypto/bf",
24"crypto/cast",
25"crypto/bn",
26"crypto/rsa",
27"crypto/dsa",
28"crypto/dh",
29"crypto/buffer",
30"crypto/bio",
31"crypto/stack",
32"crypto/lhash",
33"crypto/rand",
34"crypto/err",
35"crypto/objects",
36"crypto/evp",
37"crypto/asn1",
38"crypto/pem",
39"crypto/x509",
40"crypto/x509v3",
41"crypto/conf",
42"crypto/txt_db",
43"crypto/pkcs7",
44"crypto/pkcs12",
45"crypto/comp",
46"ssl",
47"rsaref",
48"apps",
49"test",
50"tools"
51);
52
53foreach (@dirs) {
54 &files_dir ($_, "Makefile.ssl");
55}
56
57exit(0);
58
59sub files_dir
60{
61my ($dir, $makefile) = @_;
62
63my %sym;
64
65open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile";
66
67my $s="";
68
69while (<IN>)
70 {
71 chop;
72 s/#.*//;
73 if (/^(\S+)\s*=\s*(.*)$/)
74 {
75 $o="";
76 ($s,$b)=($1,$2);
77 for (;;)
78 {
79 if ($b =~ /\\$/)
80 {
81 chop($b);
82 $o.=$b." ";
83 $b=<IN>;
84 chop($b);
85 }
86 else
87 {
88 $o.=$b." ";
89 last;
90 }
91 }
92 $o =~ s/^\s+//;
93 $o =~ s/\s+$//;
94 $o =~ s/\s+/ /g;
95
96 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
97 $sym{$s}=$o;
98 }
99 }
100
101print "RELATIVE_DIRECTORY=$dir\n";
102
103foreach (sort keys %sym)
104 {
105 print "$_=$sym{$_}\n";
106 }
107print "RELATIVE_DIRECTORY=\n";
108
109close (IN);
110}
diff --git a/src/lib/libssl/src/util/mklink.pl b/src/lib/libssl/src/util/mklink.pl
new file mode 100644
index 0000000000..de555820ec
--- /dev/null
+++ b/src/lib/libssl/src/util/mklink.pl
@@ -0,0 +1,55 @@
1#!/usr/local/bin/perl
2
3# mklink.pl
4
5# The first command line argument is a non-empty relative path
6# specifying the "from" directory.
7# Each other argument is a file name not containing / and
8# names a file in the current directory.
9#
10# For each of these files, we create in the "from" directory a link
11# of the same name pointing to the local file.
12#
13# We assume that the directory structure is a tree, i.e. that it does
14# not contain symbolic links and that the parent of / is never referenced.
15# Apart from this, this script should be able to handle even the most
16# pathological cases.
17
18my $from = shift;
19my @files = @ARGV;
20
21my @from_path = split(/\//, $from);
22my $pwd = `pwd`;
23chop($pwd);
24my @pwd_path = split(/\//, $pwd);
25
26my @to_path = ();
27
28my $dirname;
29foreach $dirname (@from_path) {
30
31 # In this loop, @to_path always is a relative path from
32 # @pwd_path (interpreted is an absolute path) to the original pwd.
33
34 # At the end, @from_path (as a relative path from the original pwd)
35 # designates the same directory as the absolute path @pwd_path,
36 # which means that @to_path then is a path from there to the original pwd.
37
38 next if ($dirname eq "" || $dirname eq ".");
39
40 if ($dirname eq "..") {
41 @to_path = (pop(@pwd_path), @to_path);
42 } else {
43 @to_path = ("..", @to_path);
44 push(@pwd_path, $dirname);
45 }
46}
47
48my $to = join('/', @to_path);
49
50my $file;
51foreach $file (@files) {
52# print "ln -s $to/$file $from/$file\n";
53 symlink("$to/$file", "$from/$file");
54 print $file . " => $from/$file\n";
55}
diff --git a/src/lib/libssl/src/util/mkstack.pl b/src/lib/libssl/src/util/mkstack.pl
new file mode 100644
index 0000000000..3ee13fe7c9
--- /dev/null
+++ b/src/lib/libssl/src/util/mkstack.pl
@@ -0,0 +1,124 @@
1#!/usr/local/bin/perl -w
2
3# This is a utility that searches out "DECLARE_STACK_OF()"
4# declarations in .h and .c files, and updates/creates/replaces
5# the corresponding macro declarations in crypto/stack/safestack.h.
6# As it's not generally possible to have macros that generate macros,
7# we need to control this from the "outside", here in this script.
8#
9# Geoff Thorpe, June, 2000 (with massive Perl-hacking
10# help from Steve Robb)
11
12my $safestack = "crypto/stack/safestack";
13
14my $do_write;
15while (@ARGV) {
16 my $arg = $ARGV[0];
17 if($arg eq "-write") {
18 $do_write = 1;
19 }
20 shift @ARGV;
21}
22
23
24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <rsaref/*.[ch]>, <ssl/*.[ch]>);
25foreach $file (@source) {
26 next if -l $file;
27
28 # Open the .c/.h file for reading
29 open(IN, "< $file") || die "Can't open $file for reading: $!";
30
31 while(<IN>) {
32 if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
33 push @stacklst, $1;
34 } if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) {
35 push @asn1setlst, $1;
36 } if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) {
37 push @p12stklst, $1;
38 }
39 }
40 close(IN);
41}
42
43
44
45my $old_stackfile = "";
46my $new_stackfile = "";
47my $inside_block = 0;
48my $type_thing;
49
50open(IN, "< $safestack.h") || die "Can't open input file: $!";
51while(<IN>) {
52 $old_stackfile .= $_;
53
54 if (m|^/\* This block of defines is updated by util/mkstack.pl, please do not touch! \*/|) {
55 $inside_block = 1;
56 }
57 if (m|^/\* End of util/mkstack.pl block, you may now edit :-\) \*/|) {
58 $inside_block = 0;
59 } elsif ($inside_block == 0) {
60 $new_stackfile .= $_;
61 }
62 next if($inside_block != 1);
63 $new_stackfile .= "/* This block of defines is updated by util/mkstack.pl, please do not touch! */";
64
65 foreach $type_thing (sort @stacklst) {
66 $new_stackfile .= <<EOF;
67
68#define sk_${type_thing}_new(st) SKM_sk_new($type_thing, (st))
69#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing)
70#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st))
71#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st))
72#define sk_${type_thing}_value(st, i) SKM_sk_value($type_thing, (st), (i))
73#define sk_${type_thing}_set(st, i, val) SKM_sk_set($type_thing, (st), (i), (val))
74#define sk_${type_thing}_zero(st) SKM_sk_zero($type_thing, (st))
75#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val))
76#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val))
77#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val))
78#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i))
79#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr))
80#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i))
81#define sk_${type_thing}_set_cmp_func(st, cmp) SKM_sk_set_cmp_func($type_thing, (st), (cmp))
82#define sk_${type_thing}_dup(st) SKM_sk_dup($type_thing, st)
83#define sk_${type_thing}_pop_free(st, free_func) SKM_sk_pop_free($type_thing, (st), (free_func))
84#define sk_${type_thing}_shift(st) SKM_sk_shift($type_thing, (st))
85#define sk_${type_thing}_pop(st) SKM_sk_pop($type_thing, (st))
86#define sk_${type_thing}_sort(st) SKM_sk_sort($type_thing, (st))
87EOF
88 }
89 foreach $type_thing (sort @asn1setlst) {
90 $new_stackfile .= <<EOF;
91
92#define d2i_ASN1_SET_OF_${type_thing}(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\
93 SKM_ASN1_SET_OF_d2i($type_thing, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
94#define i2d_ASN1_SET_OF_${type_thing}(st, pp, i2d_func, ex_tag, ex_class, is_set) \\
95 SKM_ASN1_SET_OF_i2d($type_thing, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
96#define ASN1_seq_pack_${type_thing}(st, i2d_func, buf, len) \\
97 SKM_ASN1_seq_pack($type_thing, (st), (i2d_func), (buf), (len))
98#define ASN1_seq_unpack_${type_thing}(buf, len, d2i_func, free_func) \\
99 SKM_ASN1_seq_unpack($type_thing, (buf), (len), (d2i_func), (free_func))
100EOF
101 }
102 foreach $type_thing (sort @p12stklst) {
103 $new_stackfile .= <<EOF;
104
105#define PKCS12_decrypt_d2i_${type_thing}(algor, d2i_func, free_func, pass, passlen, oct, seq) \\
106 SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
107EOF
108 }
109 $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n";
110 $inside_block = 2;
111}
112
113
114if ($new_stackfile eq $old_stackfile) {
115 print "No changes to $safestack.h.\n";
116 exit 0; # avoid unnecessary rebuild
117}
118
119if ($do_write) {
120 print "Writing new $safestack.h.\n";
121 open OUT, ">$safestack.h" || die "Can't open output file";
122 print OUT $new_stackfile;
123 close OUT;
124}
diff --git a/src/lib/libssl/src/util/pl/Mingw32.pl b/src/lib/libssl/src/util/pl/Mingw32.pl
new file mode 100644
index 0000000000..84c2a22db3
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/Mingw32.pl
@@ -0,0 +1,79 @@
1#!/usr/local/bin/perl
2#
3# Mingw32.pl -- Mingw32 with GNU cp (Mingw32f.pl uses DOS tools)
4#
5
6$o='/';
7$cp='cp';
8$rm='rem'; # use 'rm -f' if using GNU file utilities
9$mkdir='gmkdir';
10
11# gcc wouldn't accept backslashes in paths
12#$o='\\';
13#$cp='copy';
14#$rm='del';
15
16# C compiler stuff
17
18$cc='gcc';
19if ($debug)
20 { $cflags="-g2 -ggdb"; }
21else
22 { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; }
23
24$obj='.o';
25$ofile='-o ';
26
27# EXE linking stuff
28$link='${CC}';
29$lflags='${CFLAGS}';
30$efile='-o ';
31$exep='';
32$ex_libs="-lwsock32 -lgdi32";
33
34# static library stuff
35$mklib='ar r';
36$mlflags='';
37$ranlib='ranlib';
38$plib='lib';
39$libp=".a";
40$shlibp=".a";
41$lfile='';
42
43$asm='as';
44$afile='-o ';
45$bn_asm_obj="";
46$bn_asm_src="";
47$des_enc_obj="";
48$des_enc_src="";
49$bf_enc_obj="";
50$bf_enc_src="";
51
52sub do_lib_rule
53 {
54 local($obj,$target,$name,$shlib)=@_;
55 local($ret,$_,$Name);
56
57 $target =~ s/\//$o/g if $o ne '/';
58 $target="$target";
59 ($Name=$name) =~ tr/a-z/A-Z/;
60
61 $ret.="$target: \$(${Name}OBJ)\n";
62 $ret.="\t\$(RM) $target\n";
63 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
64 $ret.="\t\$(RANLIB) $target\n\n";
65 }
66
67sub do_link_rule
68 {
69 local($target,$files,$dep_libs,$libs)=@_;
70 local($ret,$_);
71
72 $file =~ s/\//$o/g if $o ne '/';
73 $n=&bname($target);
74 $ret.="$target: $files $dep_libs\n";
75 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
76 return($ret);
77 }
781;
79
diff --git a/src/lib/libssl/src/util/pl/OS2-EMX.pl b/src/lib/libssl/src/util/pl/OS2-EMX.pl
new file mode 100644
index 0000000000..57180556ca
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/OS2-EMX.pl
@@ -0,0 +1,96 @@
1#!/usr/local/bin/perl
2#
3# OS2-EMX.pl - for EMX GCC on OS/2
4#
5
6$o='\\';
7$cp='copy';
8$rm='rm -f';
9
10# C compiler stuff
11
12$cc='gcc';
13$cflags="-DL_ENDIAN -O3 -fomit-frame-pointer -m486 -Zmt -Wall ";
14
15if ($debug) {
16 $cflags.="-g ";
17}
18
19$obj='.o';
20$ofile='-o ';
21
22# EXE linking stuff
23$link='${CC}';
24$lflags='${CFLAGS} -Zbsd-signals';
25$efile='-o ';
26$exep='.exe';
27$ex_libs="-lsocket";
28
29# static library stuff
30$mklib='ar r';
31$mlflags='';
32$ranlib="ar s";
33$plib='lib';
34$libp=".a";
35$shlibp=".a";
36$lfile='';
37
38$asm='as';
39$afile='-o ';
40$bn_asm_obj="";
41$bn_asm_src="";
42$des_enc_obj="";
43$des_enc_src="";
44$bf_enc_obj="";
45$bf_enc_src="";
46
47if (!$no_asm)
48 {
49 $bn_asm_obj='crypto\bn\asm\bn-os2.o crypto\bn\asm\co-os2.o';
50 $bn_asm_src='crypto\bn\asm\bn-os2.asm crypto\bn\asm\co-os2.asm';
51 $des_enc_obj='crypto\des\asm\d-os2.o crypto\des\asm\y-os2.o';
52 $des_enc_src='crypto\des\asm\d-os2.asm crypto\des\asm\y-os2.asm';
53 $bf_enc_obj='crypto\bf\asm\b-os2.o';
54 $bf_enc_src='crypto\bf\asm\b-os2.asm';
55 $cast_enc_obj='crypto\cast\asm\c-os2.o';
56 $cast_enc_src='crypto\cast\asm\c-os2.asm';
57 $rc4_enc_obj='crypto\rc4\asm\r4-os2.o';
58 $rc4_enc_src='crypto\rc4\asm\r4-os2.asm';
59 $rc5_enc_obj='crypto\rc5\asm\r5-os2.o';
60 $rc5_enc_src='crypto\rc5\asm\r5-os2.asm';
61 $md5_asm_obj='crypto\md5\asm\m5-os2.o';
62 $md5_asm_src='crypto\md5\asm\m5-os2.asm';
63 $sha1_asm_obj='crypto\sha\asm\s1-os2.o';
64 $sha1_asm_src='crypto\sha\asm\s1-os2.asm';
65 $rmd160_asm_obj='crypto\ripemd\asm\rm-os2.o';
66 $rmd160_asm_src='crypto\ripemd\asm\rm-os2.asm';
67 }
68
69sub do_lib_rule
70 {
71 local($obj,$target,$name,$shlib)=@_;
72 local($ret,$_,$Name);
73
74 $target =~ s/\//$o/g if $o ne '/';
75 $target="$target";
76 ($Name=$name) =~ tr/a-z/A-Z/;
77
78 $ret.="$target: \$(${Name}OBJ)\n";
79 $ret.="\t\$(RM) $target\n";
80 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
81 $ret.="\t\$(RANLIB) $target\n\n";
82 }
83
84sub do_link_rule
85 {
86 local($target,$files,$dep_libs,$libs)=@_;
87 local($ret,$_);
88
89 $file =~ s/\//$o/g if $o ne '/';
90 $n=&bname($target);
91 $ret.="$target: $files $dep_libs\n";
92 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
93 return($ret);
94 }
95
961;
diff --git a/src/lib/libssl/src/util/pl/ultrix.pl b/src/lib/libssl/src/util/pl/ultrix.pl
new file mode 100644
index 0000000000..ea370c71f9
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/ultrix.pl
@@ -0,0 +1,38 @@
1#!/usr/local/bin/perl
2#
3# linux.pl - the standard unix makefile stuff.
4#
5
6$o='/';
7$cp='/bin/cp';
8$rm='/bin/rm -f';
9
10# C compiler stuff
11
12$cc='cc';
13if ($debug)
14 { $cflags="-g -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O2"; }
17
18$cflags.=" -std1 -DL_ENDIAN";
19
20if (!$no_asm)
21 {
22 $bn_asm_obj='$(OBJ_D)/mips1.o';
23 $bn_asm_src='crypto/bn/asm/mips1.s';
24 }
25
26sub do_link_rule
27 {
28 local($target,$files,$dep_libs,$libs)=@_;
29 local($ret,$_);
30
31 $file =~ s/\//$o/g if $o ne '/';
32 $n=&bname($target);
33 $ret.="$target: $files $dep_libs\n";
34 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
35 return($ret);
36 }
37
381;
diff --git a/src/lib/libssl/src/util/pod2man.pl b/src/lib/libssl/src/util/pod2man.pl
new file mode 100644
index 0000000000..f5ec0767ed
--- /dev/null
+++ b/src/lib/libssl/src/util/pod2man.pl
@@ -0,0 +1,1181 @@
1: #!/usr/bin/perl-5.005
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5$DEF_PM_SECTION = '3pm' || '3';
6
7=head1 NAME
8
9pod2man - translate embedded Perl pod directives into man pages
10
11=head1 SYNOPSIS
12
13B<pod2man>
14[ B<--section=>I<manext> ]
15[ B<--release=>I<relpatch> ]
16[ B<--center=>I<string> ]
17[ B<--date=>I<string> ]
18[ B<--fixed=>I<font> ]
19[ B<--official> ]
20[ B<--lax> ]
21I<inputfile>
22
23=head1 DESCRIPTION
24
25B<pod2man> converts its input file containing embedded pod directives (see
26L<perlpod>) into nroff source suitable for viewing with nroff(1) or
27troff(1) using the man(7) macro set.
28
29Besides the obvious pod conversions, B<pod2man> also takes care of
30func(), func(n), and simple variable references like $foo or @bar so
31you don't have to use code escapes for them; complex expressions like
32C<$fred{'stuff'}> will still need to be escaped, though. Other nagging
33little roffish things that it catches include translating the minus in
34something like foo-bar, making a long dash--like this--into a real em
35dash, fixing up "paired quotes", putting a little space after the
36parens in something like func(), making C++ and PI look right, making
37double underbars have a little tiny space between them, making ALLCAPS
38a teeny bit smaller in troff(1), and escaping backslashes so you don't
39have to.
40
41=head1 OPTIONS
42
43=over 8
44
45=item center
46
47Set the centered header to a specific string. The default is
48"User Contributed Perl Documentation", unless the C<--official> flag is
49given, in which case the default is "Perl Programmers Reference Guide".
50
51=item date
52
53Set the left-hand footer string to this value. By default,
54the modification date of the input file will be used.
55
56=item fixed
57
58The fixed font to use for code refs. Defaults to CW.
59
60=item official
61
62Set the default header to indicate that this page is of
63the standard release in case C<--center> is not given.
64
65=item release
66
67Set the centered footer. By default, this is the current
68perl release.
69
70=item section
71
72Set the section for the C<.TH> macro. The standard conventions on
73sections are to use 1 for user commands, 2 for system calls, 3 for
74functions, 4 for devices, 5 for file formats, 6 for games, 7 for
75miscellaneous information, and 8 for administrator commands. This works
76best if you put your Perl man pages in a separate tree, like
77F</usr/local/perl/man/>. By default, section 1 will be used
78unless the file ends in F<.pm> in which case section 3 will be selected.
79
80=item lax
81
82Don't complain when required sections aren't present.
83
84=back
85
86=head1 Anatomy of a Proper Man Page
87
88For those not sure of the proper layout of a man page, here's
89an example of the skeleton of a proper man page. Head of the
90major headers should be setout as a C<=head1> directive, and
91are historically written in the rather startling ALL UPPER CASE
92format, although this is not mandatory.
93Minor headers may be included using C<=head2>, and are
94typically in mixed case.
95
96=over 10
97
98=item NAME
99
100Mandatory section; should be a comma-separated list of programs or
101functions documented by this podpage, such as:
102
103 foo, bar - programs to do something
104
105=item SYNOPSIS
106
107A short usage summary for programs and functions, which
108may someday be deemed mandatory.
109
110=item DESCRIPTION
111
112Long drawn out discussion of the program. It's a good idea to break this
113up into subsections using the C<=head2> directives, like
114
115 =head2 A Sample Subection
116
117 =head2 Yet Another Sample Subection
118
119=item OPTIONS
120
121Some people make this separate from the description.
122
123=item RETURN VALUE
124
125What the program or function returns if successful.
126
127=item ERRORS
128
129Exceptions, return codes, exit stati, and errno settings.
130
131=item EXAMPLES
132
133Give some example uses of the program.
134
135=item ENVIRONMENT
136
137Envariables this program might care about.
138
139=item FILES
140
141All files used by the program. You should probably use the FE<lt>E<gt>
142for these.
143
144=item SEE ALSO
145
146Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
147
148=item NOTES
149
150Miscellaneous commentary.
151
152=item CAVEATS
153
154Things to take special care with; sometimes called WARNINGS.
155
156=item DIAGNOSTICS
157
158All possible messages the program can print out--and
159what they mean.
160
161=item BUGS
162
163Things that are broken or just don't work quite right.
164
165=item RESTRICTIONS
166
167Bugs you don't plan to fix :-)
168
169=item AUTHOR
170
171Who wrote it (or AUTHORS if multiple).
172
173=item HISTORY
174
175Programs derived from other sources sometimes have this, or
176you might keep a modification log here.
177
178=back
179
180=head1 EXAMPLES
181
182 pod2man program > program.1
183 pod2man some_module.pm > /usr/perl/man/man3/some_module.3
184 pod2man --section=7 note.pod > note.7
185
186=head1 DIAGNOSTICS
187
188The following diagnostics are generated by B<pod2man>. Items
189marked "(W)" are non-fatal, whereas the "(F)" errors will cause
190B<pod2man> to immediately exit with a non-zero status.
191
192=over 4
193
194=item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
195
196(W) If you start include an option, you should set it off
197as bold, italic, or code.
198
199=item can't open %s: %s
200
201(F) The input file wasn't available for the given reason.
202
203=item Improper man page - no dash in NAME header in paragraph %d of %s
204
205(W) The NAME header did not have an isolated dash in it. This is
206considered important.
207
208=item Invalid man page - no NAME line in %s
209
210(F) You did not include a NAME header, which is essential.
211
212=item roff font should be 1 or 2 chars, not `%s' (F)
213
214(F) The font specified with the C<--fixed> option was not
215a one- or two-digit roff font.
216
217=item %s is missing required section: %s
218
219(W) Required sections include NAME, DESCRIPTION, and if you're
220using a section starting with a 3, also a SYNOPSIS. Actually,
221not having a NAME is a fatal.
222
223=item Unknown escape: %s in %s
224
225(W) An unknown HTML entity (probably for an 8-bit character) was given via
226a C<EE<lt>E<gt>> directive. Besides amp, lt, gt, and quot, recognized
227entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
228Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
229Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
230icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
231ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
232THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
233Yacute, yacute, and yuml.
234
235=item Unmatched =back
236
237(W) You have a C<=back> without a corresponding C<=over>.
238
239=item Unrecognized pod directive: %s
240
241(W) You specified a pod directive that isn't in the known list of
242C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
243
244
245=back
246
247=head1 NOTES
248
249If you would like to print out a lot of man page continuously, you
250probably want to set the C and D registers to set contiguous page
251numbering and even/odd paging, at least on some versions of man(7).
252Settting the F register will get you some additional experimental
253indexing:
254
255 troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
256
257The indexing merely outputs messages via C<.tm> for each
258major page, section, subsection, item, and any C<XE<lt>E<gt>>
259directives.
260
261
262=head1 RESTRICTIONS
263
264None at this time.
265
266=head1 BUGS
267
268The =over and =back directives don't really work right. They
269take absolute positions instead of offsets, don't nest well, and
270making people count is suboptimal in any event.
271
272=head1 AUTHORS
273
274Original prototype by Larry Wall, but so massively hacked over by
275Tom Christiansen such that Larry probably doesn't recognize it anymore.
276
277=cut
278
279$/ = "";
280$cutting = 1;
281@Indices = ();
282
283# We try first to get the version number from a local binary, in case we're
284# running an installed version of Perl to produce documentation from an
285# uninstalled newer version's pod files.
286if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
287 my $perl = (-x './perl' && -f './perl' ) ?
288 './perl' :
289 ((-x '../perl' && -f '../perl') ?
290 '../perl' :
291 '');
292 ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
293}
294# No luck; we'll just go with the running Perl's version
295($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
296$DEF_RELEASE = "perl $version";
297$DEF_RELEASE .= ", patch $patch" if $patch;
298
299
300sub makedate {
301 my $secs = shift;
302 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
303 my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
304 $year += 1900;
305 return "$mday/$mname/$year";
306}
307
308use Getopt::Long;
309
310$DEF_SECTION = 1;
311$DEF_CENTER = "User Contributed Perl Documentation";
312$STD_CENTER = "Perl Programmers Reference Guide";
313$DEF_FIXED = 'CW';
314$DEF_LAX = 0;
315
316sub usage {
317 warn "$0: @_\n" if @_;
318 die <<EOF;
319usage: $0 [options] podpage
320Options are:
321 --section=manext (default "$DEF_SECTION")
322 --release=relpatch (default "$DEF_RELEASE")
323 --center=string (default "$DEF_CENTER")
324 --date=string (default "$DEF_DATE")
325 --fixed=font (default "$DEF_FIXED")
326 --official (default NOT)
327 --lax (default NOT)
328EOF
329}
330
331$uok = GetOptions( qw(
332 section=s
333 release=s
334 center=s
335 date=s
336 fixed=s
337 official
338 lax
339 help));
340
341$DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
342
343usage("Usage error!") unless $uok;
344usage() if $opt_help;
345usage("Need one and only one podpage argument") unless @ARGV == 1;
346
347$section = $opt_section || ($ARGV[0] =~ /\.pm$/
348 ? $DEF_PM_SECTION : $DEF_SECTION);
349$RP = $opt_release || $DEF_RELEASE;
350$center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
351$lax = $opt_lax || $DEF_LAX;
352
353$CFont = $opt_fixed || $DEF_FIXED;
354
355if (length($CFont) == 2) {
356 $CFont_embed = "\\f($CFont";
357}
358elsif (length($CFont) == 1) {
359 $CFont_embed = "\\f$CFont";
360}
361else {
362 die "roff font should be 1 or 2 chars, not `$CFont_embed'";
363}
364
365$date = $opt_date || $DEF_DATE;
366
367for (qw{NAME DESCRIPTION}) {
368# for (qw{NAME DESCRIPTION AUTHOR}) {
369 $wanna_see{$_}++;
370}
371$wanna_see{SYNOPSIS}++ if $section =~ /^3/;
372
373
374$name = @ARGV ? $ARGV[0] : "<STDIN>";
375$Filename = $name;
376if ($section =~ /^1/) {
377 require File::Basename;
378 $name = uc File::Basename::basename($name);
379}
380$name =~ s/\.(pod|p[lm])$//i;
381
382# Lose everything up to the first of
383# */lib/*perl* standard or site_perl module
384# */*perl*/lib from -D prefix=/opt/perl
385# */*perl*/ random module hierarchy
386# which works.
387$name =~ s-//+-/-g;
388if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
389 or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
390 or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
391 # Lose ^site(_perl)?/.
392 $name =~ s-^site(_perl)?/--;
393 # Lose ^arch/. (XXX should we use Config? Just for archname?)
394 $name =~ s~^(.*-$^O|$^O-.*)/~~o;
395 # Lose ^version/.
396 $name =~ s-^\d+\.\d+/--;
397}
398
399# Translate Getopt/Long to Getopt::Long, etc.
400$name =~ s(/)(::)g;
401
402if ($name ne 'something') {
403 FCHECK: {
404 open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
405 while (<F>) {
406 next unless /^=\b/;
407 if (/^=head1\s+NAME\s*$/) { # an /m would forgive mistakes
408 $_ = <F>;
409 unless (/\s*-+\s+/) {
410 $oops++;
411 warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
412 } else {
413 my @n = split /\s+-+\s+/;
414 if (@n != 2) {
415 $oops++;
416 warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
417 }
418 else {
419 %namedesc = @n;
420 }
421 }
422 last FCHECK;
423 }
424 next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME
425 next if /^=pod\b/; # It is OK to have =pod before NAME
426 die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
427 }
428 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
429 }
430 close F;
431}
432
433print <<"END";
434.rn '' }`
435''' \$RCSfile\$\$Revision\$\$Date\$
436'''
437''' \$Log\$
438'''
439.de Sh
440.br
441.if t .Sp
442.ne 5
443.PP
444\\fB\\\\\$1\\fR
445.PP
446..
447.de Sp
448.if t .sp .5v
449.if n .sp
450..
451.de Ip
452.br
453.ie \\\\n(.\$>=3 .ne \\\\\$3
454.el .ne 3
455.IP "\\\\\$1" \\\\\$2
456..
457.de Vb
458.ft $CFont
459.nf
460.ne \\\\\$1
461..
462.de Ve
463.ft R
464
465.fi
466..
467'''
468'''
469''' Set up \\*(-- to give an unbreakable dash;
470''' string Tr holds user defined translation string.
471''' Bell System Logo is used as a dummy character.
472'''
473.tr \\(*W-|\\(bv\\*(Tr
474.ie n \\{\\
475.ds -- \\(*W-
476.ds PI pi
477.if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
478.if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
479.ds L" ""
480.ds R" ""
481''' \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
482''' \\*(L" and \\*(R", except that they are used on ".xx" lines,
483''' such as .IP and .SH, which do another additional levels of
484''' double-quote interpretation
485.ds M" """
486.ds S" """
487.ds N" """""
488.ds T" """""
489.ds L' '
490.ds R' '
491.ds M' '
492.ds S' '
493.ds N' '
494.ds T' '
495'br\\}
496.el\\{\\
497.ds -- \\(em\\|
498.tr \\*(Tr
499.ds L" ``
500.ds R" ''
501.ds M" ``
502.ds S" ''
503.ds N" ``
504.ds T" ''
505.ds L' `
506.ds R' '
507.ds M' `
508.ds S' '
509.ds N' `
510.ds T' '
511.ds PI \\(*p
512'br\\}
513END
514
515print <<'END';
516.\" If the F register is turned on, we'll generate
517.\" index entries out stderr for the following things:
518.\" TH Title
519.\" SH Header
520.\" Sh Subsection
521.\" Ip Item
522.\" X<> Xref (embedded
523.\" Of course, you have to process the output yourself
524.\" in some meaninful fashion.
525.if \nF \{
526.de IX
527.tm Index:\\$1\t\\n%\t"\\$2"
528..
529.nr % 0
530.rr F
531.\}
532END
533
534print <<"END";
535.TH $name $section "$RP" "$date" "$center"
536.UC
537END
538
539push(@Indices, qq{.IX Title "$name $section"});
540
541while (($name, $desc) = each %namedesc) {
542 for ($name, $desc) { s/^\s+//; s/\s+$//; }
543 push(@Indices, qq(.IX Name "$name - $desc"\n));
544}
545
546print <<'END';
547.if n .hy 0
548.if n .na
549.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
550.de CQ \" put $1 in typewriter font
551END
552print ".ft $CFont\n";
553print <<'END';
554'if n "\c
555'if t \\&\\$1\c
556'if n \\&\\$1\c
557'if n \&"
558\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
559'.ft R
560..
561.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
562. \" AM - accent mark definitions
563.bd B 3
564. \" fudge factors for nroff and troff
565.if n \{\
566. ds #H 0
567. ds #V .8m
568. ds #F .3m
569. ds #[ \f1
570. ds #] \fP
571.\}
572.if t \{\
573. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
574. ds #V .6m
575. ds #F 0
576. ds #[ \&
577. ds #] \&
578.\}
579. \" simple accents for nroff and troff
580.if n \{\
581. ds ' \&
582. ds ` \&
583. ds ^ \&
584. ds , \&
585. ds ~ ~
586. ds ? ?
587. ds ! !
588. ds /
589. ds q
590.\}
591.if t \{\
592. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
593. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
594. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
595. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
596. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
597. ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
598. ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
599. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
600. 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'
601.\}
602. \" troff and (daisy-wheel) nroff accents
603.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
604.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
605.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
606.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
607.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
608.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
609.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
610.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
611.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
612.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
613.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
614.ds ae a\h'-(\w'a'u*4/10)'e
615.ds Ae A\h'-(\w'A'u*4/10)'E
616.ds oe o\h'-(\w'o'u*4/10)'e
617.ds Oe O\h'-(\w'O'u*4/10)'E
618. \" corrections for vroff
619.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
620.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
621. \" for low resolution devices (crt and lpr)
622.if \n(.H>23 .if \n(.V>19 \
623\{\
624. ds : e
625. ds 8 ss
626. ds v \h'-1'\o'\(aa\(ga'
627. ds _ \h'-1'^
628. ds . \h'-1'.
629. ds 3 3
630. ds o a
631. ds d- d\h'-1'\(ga
632. ds D- D\h'-1'\(hy
633. ds th \o'bp'
634. ds Th \o'LP'
635. ds ae ae
636. ds Ae AE
637. ds oe oe
638. ds Oe OE
639.\}
640.rm #[ #] #H #V #F C
641END
642
643$indent = 0;
644
645$begun = "";
646
647# Unrolling [^A-Z>]|[A-Z](?!<) gives: // MRE pp 165.
648my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
649
650while (<>) {
651 if ($cutting) {
652 next unless /^=/;
653 $cutting = 0;
654 }
655 if ($begun) {
656 if (/^=end\s+$begun/) {
657 $begun = "";
658 }
659 elsif ($begun =~ /^(roff|man)$/) {
660 print STDOUT $_;
661 }
662 next;
663 }
664 chomp;
665
666 # Translate verbatim paragraph
667
668 if (/^\s/) {
669 @lines = split(/\n/);
670 for (@lines) {
671 1 while s
672 {^( [^\t]* ) \t ( \t* ) }
673 { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
674 s/\\/\\e/g;
675 s/\A/\\&/s;
676 }
677 $lines = @lines;
678 makespace() unless $verbatim++;
679 print ".Vb $lines\n";
680 print join("\n", @lines), "\n";
681 print ".Ve\n";
682 $needspace = 0;
683 next;
684 }
685
686 $verbatim = 0;
687
688 if (/^=for\s+(\S+)\s*/s) {
689 if ($1 eq "man" or $1 eq "roff") {
690 print STDOUT $',"\n\n";
691 } else {
692 # ignore unknown for
693 }
694 next;
695 }
696 elsif (/^=begin\s+(\S+)\s*/s) {
697 $begun = $1;
698 if ($1 eq "man" or $1 eq "roff") {
699 print STDOUT $'."\n\n";
700 }
701 next;
702 }
703
704 # check for things that'll hosed our noremap scheme; affects $_
705 init_noremap();
706
707 if (!/^=item/) {
708
709 # trofficate backslashes; must do it before what happens below
710 s/\\/noremap('\\e')/ge;
711
712 # protect leading periods and quotes against *roff
713 # mistaking them for directives
714 s/^(?:[A-Z]<)?[.']/\\&$&/gm;
715
716 # first hide the escapes in case we need to
717 # intuit something and get it wrong due to fmting
718
719 1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
720
721 # func() is a reference to a perl function
722 s{
723 \b
724 (
725 [:\w]+ \(\)
726 )
727 } {I<$1>}gx;
728
729 # func(n) is a reference to a perl function or a man page
730 s{
731 ([:\w]+)
732 (
733 \( [^\051]+ \)
734 )
735 } {I<$1>\\|$2}gx;
736
737 # convert simple variable references
738 s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
739
740 if (m{ (
741 [\-\w]+
742 \(
743 [^\051]*?
744 [\@\$,]
745 [^\051]*?
746 \)
747 )
748 }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
749 {
750 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
751 $oops++;
752 }
753
754 while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
755 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
756 $oops++;
757 }
758
759 # put it back so we get the <> processed again;
760 clear_noremap(0); # 0 means leave the E's
761
762 } else {
763 # trofficate backslashes
764 s/\\/noremap('\\e')/ge;
765
766 }
767
768 # need to hide E<> first; they're processed in clear_noremap
769 s/(E<[^<>]+>)/noremap($1)/ge;
770
771
772 $maxnest = 10;
773 while ($maxnest-- && /[A-Z]</) {
774
775 # can't do C font here
776 s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
777
778 # files and filelike refs in italics
779 s/F<($nonest)>/I<$1>/g;
780
781 # no break -- usually we want C<> for this
782 s/S<($nonest)>/nobreak($1)/eg;
783
784 # LREF: a la HREF L<show this text|man/section>
785 s:L<([^|>]+)\|[^>]+>:$1:g;
786
787 # LREF: a manpage(3f)
788 s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
789
790 # LREF: an =item on another manpage
791 s{
792 L<
793 ([^/]+)
794 /
795 (
796 [:\w]+
797 (\(\))?
798 )
799 >
800 } {the C<$2> entry in the I<$1> manpage}gx;
801
802 # LREF: an =item on this manpage
803 s{
804 ((?:
805 L<
806 /
807 (
808 [:\w]+
809 (\(\))?
810 )
811 >
812 (,?\s+(and\s+)?)?
813 )+)
814 } { internal_lrefs($1) }gex;
815
816 # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
817 # the "func" can disambiguate
818 s{
819 L<
820 (?:
821 ([a-zA-Z]\S+?) /
822 )?
823 "?(.*?)"?
824 >
825 }{
826 do {
827 $1 # if no $1, assume it means on this page.
828 ? "the section on I<$2> in the I<$1> manpage"
829 : "the section on I<$2>"
830 }
831 }gesx; # s in case it goes over multiple lines, so . matches \n
832
833 s/Z<>/\\&/g;
834
835 # comes last because not subject to reprocessing
836 s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
837 }
838
839 if (s/^=//) {
840 $needspace = 0; # Assume this.
841
842 s/\n/ /g;
843
844 ($Cmd, $_) = split(' ', $_, 2);
845
846 $dotlevel = 1;
847 if ($Cmd eq 'head1') {
848 $dotlevel = 1;
849 }
850 elsif ($Cmd eq 'head2') {
851 $dotlevel = 1;
852 }
853 elsif ($Cmd eq 'item') {
854 $dotlevel = 2;
855 }
856
857 if (defined $_) {
858 &escapes($dotlevel);
859 s/"/""/g;
860 }
861
862 clear_noremap(1);
863
864 if ($Cmd eq 'cut') {
865 $cutting = 1;
866 }
867 elsif ($Cmd eq 'head1') {
868 s/\s+$//;
869 delete $wanna_see{$_} if exists $wanna_see{$_};
870 print qq{.SH "$_"\n};
871 push(@Indices, qq{.IX Header "$_"\n});
872 }
873 elsif ($Cmd eq 'head2') {
874 print qq{.Sh "$_"\n};
875 push(@Indices, qq{.IX Subsection "$_"\n});
876 }
877 elsif ($Cmd eq 'over') {
878 push(@indent,$indent);
879 $indent += ($_ + 0) || 5;
880 }
881 elsif ($Cmd eq 'back') {
882 $indent = pop(@indent);
883 warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
884 $needspace = 1;
885 }
886 elsif ($Cmd eq 'item') {
887 s/^\*( |$)/\\(bu$1/g;
888 # if you know how to get ":s please do
889 s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
890 s/\\\*\(L"([^"]+?)""/'$1'/g;
891 s/[^"]""([^"]+?)""[^"]/'$1'/g;
892 # here do something about the $" in perlvar?
893 print STDOUT qq{.Ip "$_" $indent\n};
894 push(@Indices, qq{.IX Item "$_"\n});
895 }
896 elsif ($Cmd eq 'pod') {
897 # this is just a comment
898 }
899 else {
900 warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
901 }
902 }
903 else {
904 if ($needspace) {
905 &makespace;
906 }
907 &escapes(0);
908 clear_noremap(1);
909 print $_, "\n";
910 $needspace = 1;
911 }
912}
913
914print <<"END";
915
916.rn }` ''
917END
918
919if (%wanna_see && !$lax) {
920 @missing = keys %wanna_see;
921 warn "$0: $Filename is missing required section"
922 . (@missing > 1 && "s")
923 . ": @missing\n";
924 $oops++;
925}
926
927foreach (@Indices) { print "$_\n"; }
928
929exit;
930#exit ($oops != 0);
931
932#########################################################################
933
934sub nobreak {
935 my $string = shift;
936 $string =~ s/ /\\ /g;
937 $string;
938}
939
940sub escapes {
941 my $indot = shift;
942
943 s/X<(.*?)>/mkindex($1)/ge;
944
945 # translate the minus in foo-bar into foo\-bar for roff
946 s/([^0-9a-z-])-([^-])/$1\\-$2/g;
947
948 # make -- into the string version \*(-- (defined above)
949 s/\b--\b/\\*(--/g;
950 s/"--([^"])/"\\*(--$1/g; # should be a better way
951 s/([^"])--"/$1\\*(--"/g;
952
953 # fix up quotes; this is somewhat tricky
954 my $dotmacroL = 'L';
955 my $dotmacroR = 'R';
956 if ( $indot == 1 ) {
957 $dotmacroL = 'M';
958 $dotmacroR = 'S';
959 }
960 elsif ( $indot >= 2 ) {
961 $dotmacroL = 'N';
962 $dotmacroR = 'T';
963 }
964 if (!/""/) {
965 s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
966 s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
967 }
968
969 #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
970 #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
971
972
973 # make sure that func() keeps a bit a space tween the parens
974 ### s/\b\(\)/\\|()/g;
975 ### s/\b\(\)/(\\|)/g;
976
977 # make C++ into \*C+, which is a squinched version (defined above)
978 s/\bC\+\+/\\*(C+/g;
979
980 # make double underbars have a little tiny space between them
981 s/__/_\\|_/g;
982
983 # PI goes to \*(PI (defined above)
984 s/\bPI\b/noremap('\\*(PI')/ge;
985
986 # make all caps a teeny bit smaller, but don't muck with embedded code literals
987 my $hidCFont = font('C');
988 if ($Cmd !~ /^head1/) { # SH already makes smaller
989 # /g isn't enough; 1 while or we'll be off
990
991# 1 while s{
992# (?!$hidCFont)(..|^.|^)
993# \b
994# (
995# [A-Z][\/A-Z+:\-\d_$.]+
996# )
997# (s?)
998# \b
999# } {$1\\s-1$2\\s0}gmox;
1000
1001 1 while s{
1002 (?!$hidCFont)(..|^.|^)
1003 (
1004 \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
1005 )
1006 } {
1007 $1 . noremap( '\\s-1' . $2 . '\\s0' )
1008 }egmox;
1009
1010 }
1011}
1012
1013# make troff just be normal, but make small nroff get quoted
1014# decided to just put the quotes in the text; sigh;
1015sub ccvt {
1016 local($_,$prev) = @_;
1017 noremap(qq{.CQ "$_" \n\\&});
1018}
1019
1020sub makespace {
1021 if ($indent) {
1022 print ".Sp\n";
1023 }
1024 else {
1025 print ".PP\n";
1026 }
1027}
1028
1029sub mkindex {
1030 my ($entry) = @_;
1031 my @entries = split m:\s*/\s*:, $entry;
1032 push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
1033 return '';
1034}
1035
1036sub font {
1037 local($font) = shift;
1038 return '\\f' . noremap($font);
1039}
1040
1041sub noremap {
1042 local($thing_to_hide) = shift;
1043 $thing_to_hide =~ tr/\000-\177/\200-\377/;
1044 return $thing_to_hide;
1045}
1046
1047sub init_noremap {
1048 # escape high bit characters in input stream
1049 s/([\200-\377])/"E<".ord($1).">"/ge;
1050}
1051
1052sub clear_noremap {
1053 my $ready_to_print = $_[0];
1054
1055 tr/\200-\377/\000-\177/;
1056
1057 # trofficate backslashes
1058 # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
1059
1060 # now for the E<>s, which have been hidden until now
1061 # otherwise the interative \w<> processing would have
1062 # been hosed by the E<gt>
1063 s {
1064 E<
1065 (
1066 ( \d + )
1067 | ( [A-Za-z]+ )
1068 )
1069 >
1070 } {
1071 do {
1072 defined $2
1073 ? chr($2)
1074 :
1075 exists $HTML_Escapes{$3}
1076 ? do { $HTML_Escapes{$3} }
1077 : do {
1078 warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
1079 "E<$1>";
1080 }
1081 }
1082 }egx if $ready_to_print;
1083}
1084
1085sub internal_lrefs {
1086 local($_) = shift;
1087 local $trailing_and = s/and\s+$// ? "and " : "";
1088
1089 s{L</([^>]+)>}{$1}g;
1090 my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
1091 my $retstr = "the ";
1092 my $i;
1093 for ($i = 0; $i <= $#items; $i++) {
1094 $retstr .= "C<$items[$i]>";
1095 $retstr .= ", " if @items > 2 && $i != $#items;
1096 $retstr .= " and " if $i+2 == @items;
1097 }
1098
1099 $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
1100 . " elsewhere in this document";
1101 # terminal space to avoid words running together (pattern used
1102 # strips terminal spaces)
1103 $retstr .= " " if length $trailing_and;
1104 $retstr .= $trailing_and;
1105
1106 return $retstr;
1107
1108}
1109
1110BEGIN {
1111%HTML_Escapes = (
1112 'amp' => '&', # ampersand
1113 'lt' => '<', # left chevron, less-than
1114 'gt' => '>', # right chevron, greater-than
1115 'quot' => '"', # double quote
1116
1117 "Aacute" => "A\\*'", # capital A, acute accent
1118 "aacute" => "a\\*'", # small a, acute accent
1119 "Acirc" => "A\\*^", # capital A, circumflex accent
1120 "acirc" => "a\\*^", # small a, circumflex accent
1121 "AElig" => '\*(AE', # capital AE diphthong (ligature)
1122 "aelig" => '\*(ae', # small ae diphthong (ligature)
1123 "Agrave" => "A\\*`", # capital A, grave accent
1124 "agrave" => "A\\*`", # small a, grave accent
1125 "Aring" => 'A\\*o', # capital A, ring
1126 "aring" => 'a\\*o', # small a, ring
1127 "Atilde" => 'A\\*~', # capital A, tilde
1128 "atilde" => 'a\\*~', # small a, tilde
1129 "Auml" => 'A\\*:', # capital A, dieresis or umlaut mark
1130 "auml" => 'a\\*:', # small a, dieresis or umlaut mark
1131 "Ccedil" => 'C\\*,', # capital C, cedilla
1132 "ccedil" => 'c\\*,', # small c, cedilla
1133 "Eacute" => "E\\*'", # capital E, acute accent
1134 "eacute" => "e\\*'", # small e, acute accent
1135 "Ecirc" => "E\\*^", # capital E, circumflex accent
1136 "ecirc" => "e\\*^", # small e, circumflex accent
1137 "Egrave" => "E\\*`", # capital E, grave accent
1138 "egrave" => "e\\*`", # small e, grave accent
1139 "ETH" => '\\*(D-', # capital Eth, Icelandic
1140 "eth" => '\\*(d-', # small eth, Icelandic
1141 "Euml" => "E\\*:", # capital E, dieresis or umlaut mark
1142 "euml" => "e\\*:", # small e, dieresis or umlaut mark
1143 "Iacute" => "I\\*'", # capital I, acute accent
1144 "iacute" => "i\\*'", # small i, acute accent
1145 "Icirc" => "I\\*^", # capital I, circumflex accent
1146 "icirc" => "i\\*^", # small i, circumflex accent
1147 "Igrave" => "I\\*`", # capital I, grave accent
1148 "igrave" => "i\\*`", # small i, grave accent
1149 "Iuml" => "I\\*:", # capital I, dieresis or umlaut mark
1150 "iuml" => "i\\*:", # small i, dieresis or umlaut mark
1151 "Ntilde" => 'N\*~', # capital N, tilde
1152 "ntilde" => 'n\*~', # small n, tilde
1153 "Oacute" => "O\\*'", # capital O, acute accent
1154 "oacute" => "o\\*'", # small o, acute accent
1155 "Ocirc" => "O\\*^", # capital O, circumflex accent
1156 "ocirc" => "o\\*^", # small o, circumflex accent
1157 "Ograve" => "O\\*`", # capital O, grave accent
1158 "ograve" => "o\\*`", # small o, grave accent
1159 "Oslash" => "O\\*/", # capital O, slash
1160 "oslash" => "o\\*/", # small o, slash
1161 "Otilde" => "O\\*~", # capital O, tilde
1162 "otilde" => "o\\*~", # small o, tilde
1163 "Ouml" => "O\\*:", # capital O, dieresis or umlaut mark
1164 "ouml" => "o\\*:", # small o, dieresis or umlaut mark
1165 "szlig" => '\*8', # small sharp s, German (sz ligature)
1166 "THORN" => '\\*(Th', # capital THORN, Icelandic
1167 "thorn" => '\\*(th',, # small thorn, Icelandic
1168 "Uacute" => "U\\*'", # capital U, acute accent
1169 "uacute" => "u\\*'", # small u, acute accent
1170 "Ucirc" => "U\\*^", # capital U, circumflex accent
1171 "ucirc" => "u\\*^", # small u, circumflex accent
1172 "Ugrave" => "U\\*`", # capital U, grave accent
1173 "ugrave" => "u\\*`", # small u, grave accent
1174 "Uuml" => "U\\*:", # capital U, dieresis or umlaut mark
1175 "uuml" => "u\\*:", # small u, dieresis or umlaut mark
1176 "Yacute" => "Y\\*'", # capital Y, acute accent
1177 "yacute" => "y\\*'", # small y, acute accent
1178 "yuml" => "y\\*:", # small y, dieresis or umlaut mark
1179);
1180}
1181
diff --git a/src/lib/libssl/src/util/selftest.pl b/src/lib/libssl/src/util/selftest.pl
new file mode 100644
index 0000000000..91e962a312
--- /dev/null
+++ b/src/lib/libssl/src/util/selftest.pl
@@ -0,0 +1,174 @@
1#!/usr/local/bin/perl -w
2#
3# Run the test suite and generate a report
4#
5
6if (! -f "Configure") {
7 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
8 exit 1;
9}
10
11my $report="testlog";
12my $os="??";
13my $version="??";
14my $platform0="??";
15my $platform="??";
16my $options="??";
17my $last="??";
18my $ok=0;
19my $cc="cc";
20my $cversion="??";
21my $sep="-----------------------------------------------------------------------------\n";
22
23open(OUT,">$report") or die;
24
25print OUT "OpenSSL self-test report:\n\n";
26
27$uname=`uname -a`;
28$uname="??" if $uname eq "";
29
30$c=`sh config -t`;
31foreach $_ (split("\n",$c)) {
32 $os=$1 if (/Operating system: (.*)$/);
33 $platform0=$1 if (/Configuring for (.*)$/);
34}
35
36system "sh config" if (! -f "Makefile.ssl");
37
38if (open(IN,"<Makefile.ssl")) {
39 while (<IN>) {
40 $version=$1 if (/^VERSION=(.*)$/);
41 $platform=$1 if (/^PLATFORM=(.*)$/);
42 $options=$1 if (/^OPTIONS=(.*)$/);
43 $cc=$1 if (/^CC= *(.*)$/);
44 }
45 close(IN);
46} else {
47 print OUT "Error running config!\n";
48}
49
50$cversion=`$cc -v 2>&1`;
51$cversion=`$cc -V 2>&1` if $cversion =~ "usage";
52$cversion=`$cc --version` if $cversion eq "";
53$cversion =~ s/Reading specs.*\n//;
54$cversion =~ s/usage.*\n//;
55chomp $cversion;
56
57if (open(IN,"<CHANGES")) {
58 while(<IN>) {
59 if (/\*\) (.{0,55})/) {
60 $last=$1;
61 last;
62 }
63 }
64 close(IN);
65}
66
67print OUT "OpenSSL version: $version\n";
68print OUT "Last change: $last...\n";
69print OUT "Options: $options\n" if $options ne "";
70print OUT "OS (uname): $uname";
71print OUT "OS (config): $os\n";
72print OUT "Target (default): $platform0\n";
73print OUT "Target: $platform\n";
74print OUT "Compiler: $cversion\n";
75print OUT "\n";
76
77print "Checking compiler...\n";
78if (open(TEST,">cctest.c")) {
79 print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
80 close(TEST);
81 system("$cc -o cctest cctest.c");
82 if (`./cctest` !~ /Hello world/) {
83 print OUT "Compiler doesn't work.\n";
84 goto err;
85 }
86} else {
87 print OUT "Can't create cctest.c\n";
88}
89if (open(TEST,">cctest.c")) {
90 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
91 close(TEST);
92 system("$cc -o cctest -Iinclude cctest.c");
93 $cctest = `./cctest`;
94 if ($cctest !~ /OpenSSL $version/) {
95 if ($cctest =~ /OpenSSL/) {
96 print OUT "#include uses headers from different OpenSSL version!\n";
97 } else {
98 print OUT "Can't compile test program!\n";
99 }
100 goto err;
101 }
102} else {
103 print OUT "Can't create cctest.c\n";
104}
105
106print "Running make...\n";
107if (system("make 2>&1 | tee make.log") > 255) {
108
109 print OUT "make failed!\n";
110 if (open(IN,"<make.log")) {
111 print OUT $sep;
112 while (<IN>) {
113 print OUT;
114 }
115 close(IN);
116 print OUT $sep;
117 } else {
118 print OUT "make.log not found!\n";
119 }
120 goto err;
121}
122
123$_=$options;
124s/no-asm//;
125if (/no-/)
126{
127 print OUT "Test skipped.\n";
128 goto err;
129}
130
131print "Running make test...\n";
132if (system("make test 2>&1 | tee make.log") > 255)
133 {
134 print OUT "make test failed!\n";
135} else {
136 $ok=1;
137}
138
139if ($ok and open(IN,"<make.log")) {
140 while (<IN>) {
141 $ok=2 if /^platform: $platform/;
142 }
143 close(IN);
144}
145
146if ($ok != 2) {
147 print OUT "Failure!\n";
148 if (open(IN,"<make.log")) {
149 print OUT $sep;
150 while (<IN>) {
151 print OUT;
152 }
153 close(IN);
154 print OUT $sep;
155 } else {
156 print OUT "make.log not found!\n";
157 }
158} else {
159 print OUT "Test passed.\n";
160}
161err:
162close(OUT);
163
164print "\n";
165open(IN,"<$report") or die;
166while (<IN>) {
167 if (/$sep/) {
168 print "[...]\n";
169 last;
170 }
171 print;
172}
173print "\nTest report in file $report\n";
174